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..895bf77c9e09014679416fa0a02431cbd2948d77 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; |
| + |
| 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,13 @@ 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_); |
| + |
| + logging::SetLogMessageHandler(UnitTestLogMessageHandler); |
|
Paweł Hajdan Jr.
2017/01/23 16:55:06
Is this composable with any other possibly install
alex-ac
2017/01/27 12:55:45
I've changed the way of setting LogAssertMessageHa
|
| } |
| // Don't add additional code to this method. Instead add it to |
| @@ -303,6 +310,28 @@ void TestSuite::UnitTestAssertHandler(const std::string& str) { |
| _exit(1); |
| } |
| +// static |
| +bool TestSuite::UnitTestLogMessageHandler(int severity, |
| + const char* file, |
| + int line, |
| + size_t message_start, |
| + const std::string& str) { |
| + if (severity == logging::LOG_FATAL && g_test_suite && |
| + g_test_suite->printer_) { |
| + std::string message = str.substr(message_start); |
| + std::string summary; |
| + |
| + size_t marker_pos = message.find(logging::kStackTraceMarker); |
| + if (marker_pos == std::string::npos) { |
| + summary = message; |
| + } else { |
| + summary = message.substr(0, marker_pos); |
| + } |
| + g_test_suite->printer_->OnAssert(file, line, summary, message); |
|
Paweł Hajdan Jr.
2017/01/23 16:55:06
This entire thing seems hacky. We use globals, and
alex-ac
2017/01/27 12:55:45
I've changed logging handler API to use base::Call
|
| + } |
| + return false; |
| +} |
| + |
| void TestSuite::SuppressErrorDialogs() { |
| #if defined(OS_WIN) |
| UINT new_flags = SEM_FAILCRITICALERRORS | |