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 20 matching lines...) Expand all Loading... | |
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 // static |
286 void TestSuite::UnitTestAssertHandler(const std::string& str) { | 286 void TestSuite::UnitTestAssertHandler(const char* file, |
287 int line, | |
288 const std::string& summary, | |
289 const std::string& stack_trace) { | |
287 #if defined(OS_ANDROID) | 290 #if defined(OS_ANDROID) |
288 // Correlating test stdio with logcat can be difficult, so we emit this | 291 // 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 | 292 // 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 | 293 // because other platforms don't separate out the relevant logs in the same |
291 // way. | 294 // way. |
292 const ::testing::TestInfo* const test_info = | 295 const ::testing::TestInfo* const test_info = |
293 ::testing::UnitTest::GetInstance()->current_test_info(); | 296 ::testing::UnitTest::GetInstance()->current_test_info(); |
294 if (test_info) { | 297 if (test_info) { |
295 LOG(ERROR) << "Currently running: " << test_info->test_case_name() << "." | 298 LOG(ERROR) << "Currently running: " << test_info->test_case_name() << "." |
296 << test_info->name(); | 299 << test_info->name(); |
297 fflush(stderr); | 300 fflush(stderr); |
298 } | 301 } |
299 #endif // defined(OS_ANDROID) | 302 #endif // defined(OS_ANDROID) |
300 | 303 |
304 printer_->OnAssert(file, line, summary, summary + stack_trace); | |
Paweł Hajdan Jr.
2017/02/13 17:17:24
Why do we pass "summary + stack_trace" instead of
alex-ac
2017/02/14 10:34:28
XmlUnitTestResultPrinter inherits gtest format, wh
Paweł Hajdan Jr.
2017/02/14 19:23:26
Okay. Since this is not obvious, could you add a c
alex-ac
2017/03/09 14:15:52
Done.
| |
305 | |
301 // The logging system actually prints the message before calling the assert | 306 // The logging system actually prints the message before calling the assert |
302 // handler. Just exit now to avoid printing too many stack traces. | 307 // handler. Just exit now to avoid printing too many stack traces. |
303 _exit(1); | 308 _exit(1); |
304 } | 309 } |
305 | 310 |
306 void TestSuite::SuppressErrorDialogs() { | 311 void TestSuite::SuppressErrorDialogs() { |
307 #if defined(OS_WIN) | 312 #if defined(OS_WIN) |
308 UINT new_flags = SEM_FAILCRITICALERRORS | | 313 UINT new_flags = SEM_FAILCRITICALERRORS | |
309 SEM_NOGPFAULTERRORBOX | | 314 SEM_NOGPFAULTERRORBOX | |
310 SEM_NOOPENFILEERRORBOX; | 315 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 | 357 // Make sure we run with high resolution timer to minimize differences |
353 // between production code and test code. | 358 // between production code and test code. |
354 Time::EnableHighResolutionTimer(true); | 359 Time::EnableHighResolutionTimer(true); |
355 #endif // defined(OS_WIN) | 360 #endif // defined(OS_WIN) |
356 | 361 |
357 // In some cases, we do not want to see standard error dialogs. | 362 // In some cases, we do not want to see standard error dialogs. |
358 if (!debug::BeingDebugged() && | 363 if (!debug::BeingDebugged() && |
359 !CommandLine::ForCurrentProcess()->HasSwitch("show-error-dialogs")) { | 364 !CommandLine::ForCurrentProcess()->HasSwitch("show-error-dialogs")) { |
360 SuppressErrorDialogs(); | 365 SuppressErrorDialogs(); |
361 debug::SetSuppressDebugUI(true); | 366 debug::SetSuppressDebugUI(true); |
362 logging::SetLogAssertHandler(UnitTestAssertHandler); | 367 assert_handler_ = logging::ScopedLogAssertHandler( |
368 base::Bind(&TestSuite::UnitTestAssertHandler, base::Unretained(this))); | |
363 } | 369 } |
364 | 370 |
365 base::test::InitializeICUForTesting(); | 371 base::test::InitializeICUForTesting(); |
366 | 372 |
367 // On the Mac OS X command line, the default locale is *_POSIX. In Chromium, | 373 // 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. | 374 // 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 | 375 // 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 | 376 // 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. | 377 // does not affect tests that explicitly overrides the locale for testing. |
372 // This can be an issue on all platforms other than Windows. | 378 // This can be an issue on all platforms other than Windows. |
(...skipping 26 matching lines...) Expand all Loading... | |
399 | 405 |
400 void TestSuite::Shutdown() { | 406 void TestSuite::Shutdown() { |
401 base::debug::StopProfiling(); | 407 base::debug::StopProfiling(); |
402 | 408 |
403 // Clear the FeatureList that was created by Initialize(). | 409 // Clear the FeatureList that was created by Initialize(). |
404 if (created_feature_list_) | 410 if (created_feature_list_) |
405 FeatureList::ClearInstanceForTesting(); | 411 FeatureList::ClearInstanceForTesting(); |
406 } | 412 } |
407 | 413 |
408 } // namespace base | 414 } // namespace base |
OLD | NEW |