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..5196d85eb85396c7615e78b9ff9f4dc25025d149 100644 |
| --- a/base/test/test_suite.cc |
| +++ b/base/test/test_suite.cc |
| @@ -238,11 +238,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 |
| @@ -282,8 +282,10 @@ int TestSuite::Run() { |
| return result; |
| } |
| -// static |
| -void TestSuite::UnitTestAssertHandler(const std::string& str) { |
| +void TestSuite::UnitTestAssertHandler(const char* file, |
| + int line, |
| + const base::StringPiece& summary, |
| + const base::StringPiece& stack_trace) { |
| #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 +300,13 @@ void TestSuite::UnitTestAssertHandler(const std::string& str) { |
| } |
| #endif // defined(OS_ANDROID) |
| + // XmlUnitTestResultPrinter inherits gtest format, where assert has summary |
| + // and message. In GTest, summary is just a logged text, and message is a |
| + // logged text, concatenated with stack trace of assert. |
| + // Concatenate summary and stack_trace here, to pass it as a message. |
| + printer_->OnAssert(file, line, summary.as_string(), |
|
dcheng
2017/03/15 09:57:24
Please convert the string once in a local and refe
alex-ac
2017/03/21 12:37:12
Done.
|
| + summary.as_string() + stack_trace.as_string()); |
| + |
| // 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 +368,8 @@ void TestSuite::Initialize() { |
| !CommandLine::ForCurrentProcess()->HasSwitch("show-error-dialogs")) { |
| SuppressErrorDialogs(); |
| debug::SetSuppressDebugUI(true); |
| - logging::SetLogAssertHandler(UnitTestAssertHandler); |
| + assert_handler_ = base::MakeUnique<logging::ScopedLogAssertHandler>( |
| + base::Bind(&TestSuite::UnitTestAssertHandler, base::Unretained(this))); |
| } |
| base::test::InitializeICUForTesting(); |