| 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(_indent(t.message)); | 49 print(' ${t.message}'); |
| 50 } | |
| 51 | |
| 52 if (t.stackTrace != null && t.stackTrace != '') { | |
| 53 print(_indent(t.stackTrace)); | |
| 54 } | 50 } |
| 55 } | 51 } |
| 56 | 52 |
| 57 // Show the summary. | 53 // Show the summary. |
| 58 print(''); | 54 print(''); |
| 59 | 55 |
| 60 var success = false; | 56 var success = false; |
| 61 if (passed == 0 && failed == 0 && errors == 0) { | 57 if (passed == 0 && failed == 0 && errors == 0) { |
| 62 print('No tests found.'); | 58 print('No tests found.'); |
| 63 // This is considered a failure too: if this happens you probably have a | 59 // This is considered a failure too: if this happens you probably have a |
| 64 // bug in your unit tests. | 60 // bug in your unit tests. |
| 65 } else if (failed == 0 && errors == 0 && uncaughtError == null) { | 61 } else if (failed == 0 && errors == 0 && uncaughtError == null) { |
| 66 print('All $passed tests passed.'); | 62 print('All $passed tests passed.'); |
| 67 success = true; | 63 success = true; |
| 68 } else { | 64 } else { |
| 69 if (uncaughtError != null) { | 65 if (uncaughtError != null) { |
| 70 print('Top-level uncaught error: $uncaughtError'); | 66 print('Top-level uncaught error: $uncaughtError'); |
| 71 } | 67 } |
| 72 print('$passed PASSED, $failed FAILED, $errors ERRORS'); | 68 print('$passed PASSED, $failed FAILED, $errors ERRORS'); |
| 73 } | 69 } |
| 74 | 70 |
| 75 // An exception is used by the test infrastructure to detect failure. | 71 // An exception is used by the test infrastructure to detect failure. |
| 76 if (!success) throw new Exception("Some tests failed."); | 72 if (!success) throw new Exception("Some tests failed."); |
| 77 } | 73 } |
| 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 } | |
| 85 } | 74 } |
| OLD | NEW |