| 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 19 matching lines...) Expand all Loading... |
| 30 * even before tests are added to the test framework. It might be used to | 30 * even before tests are added to the test framework. It might be used to |
| 31 * determine/debug errors that occur before the test harness starts executing. | 31 * determine/debug errors that occur before the test harness starts executing. |
| 32 */ | 32 */ |
| 33 void onInit() {} | 33 void onInit() {} |
| 34 | 34 |
| 35 /** | 35 /** |
| 36 * Called as soon as the unittest framework starts running. Used commonly to | 36 * Called as soon as the unittest framework starts running. Used commonly to |
| 37 * tell the vm or browser that tests are still running and the process should | 37 * tell the vm or browser that tests are still running and the process should |
| 38 * wait until they are done. | 38 * wait until they are done. |
| 39 */ | 39 */ |
| 40 void onStart() {} | 40 void onStart() { |
| 41 _postMessage('unittest-suite-wait-for-done'); |
| 42 } |
| 41 | 43 |
| 42 /** | 44 /** |
| 43 * Called when each test starts. Useful to show intermediate progress on | 45 * Called when each test starts. Useful to show intermediate progress on |
| 44 * a test suite. | 46 * a test suite. |
| 45 */ | 47 */ |
| 46 void onTestStart(TestCase testCase) { | 48 void onTestStart(TestCase testCase) { |
| 47 currentTestCase = testCase; | 49 currentTestCase = testCase; |
| 48 } | 50 } |
| 49 | 51 |
| 50 /** | 52 /** |
| (...skipping 63 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 114 } else if (failed == 0 && errors == 0 && uncaughtError == null) { | 116 } else if (failed == 0 && errors == 0 && uncaughtError == null) { |
| 115 print('All $passed tests passed.'); | 117 print('All $passed tests passed.'); |
| 116 success = true; | 118 success = true; |
| 117 } else { | 119 } else { |
| 118 if (uncaughtError != null) { | 120 if (uncaughtError != null) { |
| 119 print('Top-level uncaught error: $uncaughtError'); | 121 print('Top-level uncaught error: $uncaughtError'); |
| 120 } | 122 } |
| 121 print('$passed PASSED, $failed FAILED, $errors ERRORS'); | 123 print('$passed PASSED, $failed FAILED, $errors ERRORS'); |
| 122 } | 124 } |
| 123 | 125 |
| 124 // An exception is used by the test infrastructure to detect failure. | 126 if (success) { |
| 125 if (!success) throw new Exception("Some tests failed."); | 127 _postMessage('unittest-suite-success'); |
| 128 } else { |
| 129 throw new Exception('Some tests failed.'); |
| 130 } |
| 126 } | 131 } |
| 127 | 132 |
| 128 String _indent(String str) { | 133 String _indent(String str) { |
| 129 // TODO(nweiz): Use this simpler code once issue 2980 is fixed. | 134 // TODO(nweiz): Use this simpler code once issue 2980 is fixed. |
| 130 // return str.replaceAll(const RegExp("^", multiLine: true), " "); | 135 // return str.replaceAll(const RegExp("^", multiLine: true), " "); |
| 131 | 136 |
| 132 return Strings.join(str.split("\n").map((line) => " $line"), "\n"); | 137 return Strings.join(str.split("\n").map((line) => " $line"), "\n"); |
| 133 } | 138 } |
| 134 | 139 |
| 135 /** Handle errors that happen outside the tests. */ | 140 /** Handle errors that happen outside the tests. */ |
| 136 // TODO(vsm): figure out how to expose the stack trace here | 141 // TODO(vsm): figure out how to expose the stack trace here |
| 137 // Currently e.message works in dartium, but not in dartc. | 142 // Currently e.message works in dartium, but not in dartc. |
| 138 handleExternalError(e, String message) => | 143 handleExternalError(e, String message) => |
| 139 _reportTestError('$message\nCaught $e', ''); | 144 _reportTestError('$message\nCaught $e', ''); |
| 145 |
| 146 _postMessage(String message) { |
| 147 // In dart2js browser tests, the JavaScript-based test controller |
| 148 // intercepts calls to print and listens for "secret" messages. |
| 149 print(message); |
| 150 } |
| 140 } | 151 } |
| OLD | NEW |