| OLD | NEW |
| 1 // Copyright (c) 2011, the Dart project authors. Please see the AUTHORS file | 1 // Copyright (c) 2011, the Dart project authors. Please see the AUTHORS file |
| 2 // for details. All rights reserved. Use of this source code is governed by a | 2 // for details. All rights reserved. Use of this source code is governed by a |
| 3 // BSD-style license that can be found in the LICENSE file. | 3 // BSD-style license that can be found in the LICENSE file. |
| 4 | 4 |
| 5 /** This file is sourced by unitest.dart. */ | 5 /** This file is sourced by unitest.dart. */ |
| 6 | 6 |
| 7 /** | 7 /** |
| 8 * Hooks to configure the unittest library for different platforms. This class | 8 * Hooks to configure the unittest library for different platforms. This class |
| 9 * implements the API in a platform-independent way. Tests that want to take | 9 * implements the API in a platform-independent way. Tests that want to take |
| 10 * advantage of the platform can create a subclass and override methods from | 10 * advantage of the platform can create a subclass and override methods from |
| (...skipping 28 matching lines...) Expand all Loading... |
| 39 * When [uncaughtError] is not null, it contains an error that occured outside | 39 * When [uncaughtError] is not null, it contains an error that occured outside |
| 40 * of tests (e.g. setting up the test). | 40 * of tests (e.g. setting up the test). |
| 41 */ | 41 */ |
| 42 void onDone(int passed, int failed, int errors, List<TestCase> results, | 42 void onDone(int passed, int failed, int errors, List<TestCase> results, |
| 43 String uncaughtError) { | 43 String uncaughtError) { |
| 44 // Print each test's result. | 44 // Print each test's result. |
| 45 for (final t in _tests) { | 45 for (final t in _tests) { |
| 46 print('${t.result.toUpperCase()}: ${t.description}'); | 46 print('${t.result.toUpperCase()}: ${t.description}'); |
| 47 | 47 |
| 48 if (t.message != '') { | 48 if (t.message != '') { |
| 49 print(' ${t.message}'); | 49 print(_indent(t.message)); |
| 50 } |
| 51 |
| 52 if (t.stackTrace != null && t.stackTrace != '') { |
| 53 print(_indent(t.stackTrace)); |
| 50 } | 54 } |
| 51 } | 55 } |
| 52 | 56 |
| 53 // Show the summary. | 57 // Show the summary. |
| 54 print(''); | 58 print(''); |
| 55 | 59 |
| 56 var success = false; | 60 var success = false; |
| 57 if (passed == 0 && failed == 0 && errors == 0) { | 61 if (passed == 0 && failed == 0 && errors == 0) { |
| 58 print('No tests found.'); | 62 print('No tests found.'); |
| 59 // This is considered a failure too: if this happens you probably have a | 63 // This is considered a failure too: if this happens you probably have a |
| 60 // bug in your unit tests. | 64 // bug in your unit tests. |
| 61 } else if (failed == 0 && errors == 0 && uncaughtError == null) { | 65 } else if (failed == 0 && errors == 0 && uncaughtError == null) { |
| 62 print('All $passed tests passed.'); | 66 print('All $passed tests passed.'); |
| 63 success = true; | 67 success = true; |
| 64 } else { | 68 } else { |
| 65 if (uncaughtError != null) { | 69 if (uncaughtError != null) { |
| 66 print('Top-level uncaught error: $uncaughtError'); | 70 print('Top-level uncaught error: $uncaughtError'); |
| 67 } | 71 } |
| 68 print('$passed PASSED, $failed FAILED, $errors ERRORS'); | 72 print('$passed PASSED, $failed FAILED, $errors ERRORS'); |
| 69 } | 73 } |
| 70 | 74 |
| 71 // An exception is used by the test infrastructure to detect failure. | 75 // An exception is used by the test infrastructure to detect failure. |
| 72 if (!success) throw new Exception("Some tests failed."); | 76 if (!success) throw new Exception("Some tests failed."); |
| 73 } | 77 } |
| 78 |
| 79 String _indent(String str) { |
| 80 // TODO(nweiz): Use this simpler code once issue 2980 is fixed. |
| 81 // return str.replaceAll(const RegExp("^", multiLine: true), " "); |
| 82 |
| 83 return Strings.join(str.split("\n").map((line) => " $line"), "\n"); |
| 84 } |
| 74 } | 85 } |
| OLD | NEW |