OLD | NEW |
---|---|
1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. |
2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
4 | 4 |
5 #include "base/test/test_suite.h" | 5 #include "base/test/test_suite.h" |
6 | 6 |
7 #include <memory> | 7 #include <memory> |
8 | 8 |
9 #include "base/at_exit.h" | 9 #include "base/at_exit.h" |
10 #include "base/base_paths.h" | 10 #include "base/base_paths.h" |
(...skipping 220 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
231 | 231 |
232 // Do not add the result printer if output path already exists. It's an | 232 // Do not add the result printer if output path already exists. It's an |
233 // indicator there is a process printing to that file, and we're likely | 233 // indicator there is a process printing to that file, and we're likely |
234 // its child. Do not clobber the results in that case. | 234 // its child. Do not clobber the results in that case. |
235 if (PathExists(output_path)) { | 235 if (PathExists(output_path)) { |
236 LOG(WARNING) << "Test launcher output path " << output_path.AsUTF8Unsafe() | 236 LOG(WARNING) << "Test launcher output path " << output_path.AsUTF8Unsafe() |
237 << " exists. Not adding test launcher result printer."; | 237 << " exists. Not adding test launcher result printer."; |
238 return; | 238 return; |
239 } | 239 } |
240 | 240 |
241 XmlUnitTestResultPrinter* printer = new XmlUnitTestResultPrinter; | 241 printer_ = new XmlUnitTestResultPrinter; |
242 CHECK(printer->Initialize(output_path)); | 242 CHECK(printer_->Initialize(output_path)); |
243 testing::TestEventListeners& listeners = | 243 testing::TestEventListeners& listeners = |
244 testing::UnitTest::GetInstance()->listeners(); | 244 testing::UnitTest::GetInstance()->listeners(); |
245 listeners.Append(printer); | 245 listeners.Append(printer_); |
246 } | 246 } |
247 | 247 |
248 // Don't add additional code to this method. Instead add it to | 248 // Don't add additional code to this method. Instead add it to |
249 // Initialize(). See bug 6436. | 249 // Initialize(). See bug 6436. |
250 int TestSuite::Run() { | 250 int TestSuite::Run() { |
251 #if defined(OS_IOS) | 251 #if defined(OS_IOS) |
252 RunTestsFromIOSApp(); | 252 RunTestsFromIOSApp(); |
253 #endif | 253 #endif |
254 | 254 |
255 #if defined(OS_MACOSX) | 255 #if defined(OS_MACOSX) |
(...skipping 19 matching lines...) Expand all Loading... | |
275 // objects (such as NotificationService::current()) that Cocoa | 275 // objects (such as NotificationService::current()) that Cocoa |
276 // objects use to remove themselves as observers. | 276 // objects use to remove themselves as observers. |
277 scoped_pool.Recycle(); | 277 scoped_pool.Recycle(); |
278 #endif | 278 #endif |
279 | 279 |
280 Shutdown(); | 280 Shutdown(); |
281 | 281 |
282 return result; | 282 return result; |
283 } | 283 } |
284 | 284 |
285 // static | 285 void TestSuite::UnitTestAssertHandler(const char* file, |
286 void TestSuite::UnitTestAssertHandler(const std::string& str) { | 286 int line, |
287 const base::StringPiece& summary, | |
288 const base::StringPiece& stack_trace) { | |
287 #if defined(OS_ANDROID) | 289 #if defined(OS_ANDROID) |
288 // Correlating test stdio with logcat can be difficult, so we emit this | 290 // Correlating test stdio with logcat can be difficult, so we emit this |
289 // helpful little hint about what was running. Only do this for Android | 291 // helpful little hint about what was running. Only do this for Android |
290 // because other platforms don't separate out the relevant logs in the same | 292 // because other platforms don't separate out the relevant logs in the same |
291 // way. | 293 // way. |
292 const ::testing::TestInfo* const test_info = | 294 const ::testing::TestInfo* const test_info = |
293 ::testing::UnitTest::GetInstance()->current_test_info(); | 295 ::testing::UnitTest::GetInstance()->current_test_info(); |
294 if (test_info) { | 296 if (test_info) { |
295 LOG(ERROR) << "Currently running: " << test_info->test_case_name() << "." | 297 LOG(ERROR) << "Currently running: " << test_info->test_case_name() << "." |
296 << test_info->name(); | 298 << test_info->name(); |
297 fflush(stderr); | 299 fflush(stderr); |
298 } | 300 } |
299 #endif // defined(OS_ANDROID) | 301 #endif // defined(OS_ANDROID) |
300 | 302 |
303 // XmlUnitTestResultPrinter inherits gtest format, where assert has summary | |
304 // and message. In GTest, summary is just a logged text, and message is a | |
305 // logged text, concatenated with stack trace of assert. | |
306 // Concatenate summary and stack_trace here, to pass it as a message. | |
307 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.
| |
308 summary.as_string() + stack_trace.as_string()); | |
309 | |
301 // The logging system actually prints the message before calling the assert | 310 // The logging system actually prints the message before calling the assert |
302 // handler. Just exit now to avoid printing too many stack traces. | 311 // handler. Just exit now to avoid printing too many stack traces. |
303 _exit(1); | 312 _exit(1); |
304 } | 313 } |
305 | 314 |
306 void TestSuite::SuppressErrorDialogs() { | 315 void TestSuite::SuppressErrorDialogs() { |
307 #if defined(OS_WIN) | 316 #if defined(OS_WIN) |
308 UINT new_flags = SEM_FAILCRITICALERRORS | | 317 UINT new_flags = SEM_FAILCRITICALERRORS | |
309 SEM_NOGPFAULTERRORBOX | | 318 SEM_NOGPFAULTERRORBOX | |
310 SEM_NOOPENFILEERRORBOX; | 319 SEM_NOOPENFILEERRORBOX; |
(...skipping 41 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
352 // Make sure we run with high resolution timer to minimize differences | 361 // Make sure we run with high resolution timer to minimize differences |
353 // between production code and test code. | 362 // between production code and test code. |
354 Time::EnableHighResolutionTimer(true); | 363 Time::EnableHighResolutionTimer(true); |
355 #endif // defined(OS_WIN) | 364 #endif // defined(OS_WIN) |
356 | 365 |
357 // In some cases, we do not want to see standard error dialogs. | 366 // In some cases, we do not want to see standard error dialogs. |
358 if (!debug::BeingDebugged() && | 367 if (!debug::BeingDebugged() && |
359 !CommandLine::ForCurrentProcess()->HasSwitch("show-error-dialogs")) { | 368 !CommandLine::ForCurrentProcess()->HasSwitch("show-error-dialogs")) { |
360 SuppressErrorDialogs(); | 369 SuppressErrorDialogs(); |
361 debug::SetSuppressDebugUI(true); | 370 debug::SetSuppressDebugUI(true); |
362 logging::SetLogAssertHandler(UnitTestAssertHandler); | 371 assert_handler_ = base::MakeUnique<logging::ScopedLogAssertHandler>( |
372 base::Bind(&TestSuite::UnitTestAssertHandler, base::Unretained(this))); | |
363 } | 373 } |
364 | 374 |
365 base::test::InitializeICUForTesting(); | 375 base::test::InitializeICUForTesting(); |
366 | 376 |
367 // On the Mac OS X command line, the default locale is *_POSIX. In Chromium, | 377 // On the Mac OS X command line, the default locale is *_POSIX. In Chromium, |
368 // the locale is set via an OS X locale API and is never *_POSIX. | 378 // the locale is set via an OS X locale API and is never *_POSIX. |
369 // Some tests (such as those involving word break iterator) will behave | 379 // Some tests (such as those involving word break iterator) will behave |
370 // differently and fail if we use *POSIX locale. Setting it to en_US here | 380 // differently and fail if we use *POSIX locale. Setting it to en_US here |
371 // does not affect tests that explicitly overrides the locale for testing. | 381 // does not affect tests that explicitly overrides the locale for testing. |
372 // This can be an issue on all platforms other than Windows. | 382 // This can be an issue on all platforms other than Windows. |
(...skipping 26 matching lines...) Expand all Loading... | |
399 | 409 |
400 void TestSuite::Shutdown() { | 410 void TestSuite::Shutdown() { |
401 base::debug::StopProfiling(); | 411 base::debug::StopProfiling(); |
402 | 412 |
403 // Clear the FeatureList that was created by Initialize(). | 413 // Clear the FeatureList that was created by Initialize(). |
404 if (created_feature_list_) | 414 if (created_feature_list_) |
405 FeatureList::ClearInstanceForTesting(); | 415 FeatureList::ClearInstanceForTesting(); |
406 } | 416 } |
407 | 417 |
408 } // namespace base | 418 } // namespace base |
OLD | NEW |