Chromium Code Reviews| Index: base/test/test_suite.cc |
| diff --git a/base/test/test_suite.cc b/base/test/test_suite.cc |
| index 6f4cc372cb86ad73f9388740e5a9f0c05652cc88..a1bc8cbbc38b88f597715674b3aa26c08b347ff5 100644 |
| --- a/base/test/test_suite.cc |
| +++ b/base/test/test_suite.cc |
| @@ -65,6 +65,8 @@ namespace base { |
| namespace { |
| +TestSuite* g_test_suite = nullptr; |
|
Paweł Hajdan Jr.
2017/01/27 17:19:44
This shouldn't be needed now, right?
alex-ac
2017/02/11 20:12:20
Done.
|
| + |
| class MaybeTestDisabler : public testing::EmptyTestEventListener { |
| public: |
| void OnTestStart(const testing::TestInfo& test_info) override { |
| @@ -158,6 +160,8 @@ TestSuite::TestSuite(int argc, wchar_t** argv) |
| TestSuite::~TestSuite() { |
| if (initialized_command_line_) |
| CommandLine::Reset(); |
| + |
| + g_test_suite = nullptr; |
| } |
| void TestSuite::InitializeFromCommandLine(int argc, char** argv) { |
| @@ -180,6 +184,7 @@ void TestSuite::InitializeFromCommandLine(int argc, wchar_t** argv) { |
| #endif // defined(OS_WIN) |
| void TestSuite::PreInitialize() { |
| + g_test_suite = this; |
| #if defined(OS_WIN) |
| testing::GTEST_FLAG(catch_exceptions) = false; |
| #endif |
| @@ -238,11 +243,11 @@ void TestSuite::AddTestLauncherResultPrinter() { |
| return; |
| } |
| - XmlUnitTestResultPrinter* printer = new XmlUnitTestResultPrinter; |
| - CHECK(printer->Initialize(output_path)); |
| + printer_ = new XmlUnitTestResultPrinter; |
| + CHECK(printer_->Initialize(output_path)); |
| testing::TestEventListeners& listeners = |
| testing::UnitTest::GetInstance()->listeners(); |
| - listeners.Append(printer); |
| + listeners.Append(printer_); |
| } |
| // Don't add additional code to this method. Instead add it to |
| @@ -283,7 +288,11 @@ int TestSuite::Run() { |
| } |
| // static |
| -void TestSuite::UnitTestAssertHandler(const std::string& str) { |
| +void TestSuite::UnitTestAssertHandler(const char* file, |
| + int line, |
| + size_t message_start, |
| + size_t stack_start, |
| + const std::string& str) { |
| #if defined(OS_ANDROID) |
| // Correlating test stdio with logcat can be difficult, so we emit this |
| // helpful little hint about what was running. Only do this for Android |
| @@ -298,6 +307,12 @@ void TestSuite::UnitTestAssertHandler(const std::string& str) { |
| } |
| #endif // defined(OS_ANDROID) |
| + std::string message = str.substr(message_start); |
| + std::string summary; |
| + |
| + summary = message.substr(0, stack_start - message_start); |
| + printer_->OnAssert(file, line, summary, message); |
| + |
| // The logging system actually prints the message before calling the assert |
| // handler. Just exit now to avoid printing too many stack traces. |
| _exit(1); |
| @@ -359,7 +374,8 @@ void TestSuite::Initialize() { |
| !CommandLine::ForCurrentProcess()->HasSwitch("show-error-dialogs")) { |
| SuppressErrorDialogs(); |
| debug::SetSuppressDebugUI(true); |
| - logging::SetLogAssertHandler(UnitTestAssertHandler); |
| + assert_handler_ = logging::ScopedLogAssertHandler( |
| + base::Bind(&TestSuite::UnitTestAssertHandler, base::Unretained(this))); |
| } |
| base::test::InitializeICUForTesting(); |