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..ff9764b90832b9c5ea0c4032500a2426abd7a6d8 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); |
| } |
| // Don't add additional code to this method. Instead add it to |
| @@ -303,6 +310,31 @@ 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); |
| + // There is only one way to separate summary and stack-trace - newline |
| + // character. It will work wrong when newline is used in the CHECK/DCHECK |
| + // message like this: |
| + // DCHECK(foo) << "bar\nbuzz"; |
|
dcheng
2017/01/20 08:26:23
If it helps, we could change the output to be frie
alex-ac
2017/01/20 12:11:17
Done.
|
| + size_t line_end = message.find_first_of("\r\n"); |
| + std::string summary; |
| + if (line_end == std::string::npos) { |
| + summary = message; |
| + } else { |
| + summary = message.substr(0, line_end); |
| + } |
| + g_test_suite->printer_->OnAssert(file, line, summary, message); |
| + } |
| + return false; |
| +} |
| + |
| void TestSuite::SuppressErrorDialogs() { |
| #if defined(OS_WIN) |
| UINT new_flags = SEM_FAILCRITICALERRORS | |