| OLD | NEW |
| 1 // Copyright (c) 2013, the Dart project authors. Please see the AUTHORS file | 1 // Copyright (c) 2013, 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 part of unittest; | 5 part of unittest; |
| 6 | 6 |
| 7 // A custom failure handler for [expect] that routes expect failures | 7 // A custom failure handler for [expect] that routes expect failures |
| 8 // to the config. | 8 // to the config. |
| 9 class _ExpectFailureHandler extends DefaultFailureHandler { | 9 class _ExpectFailureHandler extends DefaultFailureHandler { |
| 10 final SimpleConfiguration _config; | 10 final SimpleConfiguration _config; |
| 11 | 11 |
| 12 _ExpectFailureHandler(this._config); | 12 _ExpectFailureHandler(this._config); |
| 13 | 13 |
| 14 void fail(String reason) { | 14 void fail(String reason) { |
| 15 _config.onExpectFailure(reason); | 15 _config.onExpectFailure(reason); |
| 16 } | 16 } |
| 17 } | 17 } |
| 18 | 18 |
| 19 /** | 19 /** |
| 20 * Hooks to configure the unittest library for different platforms. This class | 20 * Hooks to configure the unittest library for different platforms. This class |
| 21 * implements the API in a platform-independent way. Tests that want to take | 21 * implements the API in a platform-independent way. Tests that want to take |
| 22 * advantage of the platform can create a subclass and override methods from | 22 * advantage of the platform can create a subclass and override methods from |
| 23 * this class. | 23 * this class. |
| 24 */ | 24 */ |
| 25 class SimpleConfiguration implements Configuration { | 25 class SimpleConfiguration extends Configuration { |
| 26 // The VM won't shut down if a receive port is open. Use this to make sure | 26 // The VM won't shut down if a receive port is open. Use this to make sure |
| 27 // we correctly wait for asynchronous tests. | 27 // we correctly wait for asynchronous tests. |
| 28 ReceivePort _receivePort; | 28 ReceivePort _receivePort; |
| 29 | 29 |
| 30 /** | 30 /** |
| 31 * Subclasses can override this with something useful for diagnostics. | 31 * Subclasses can override this with something useful for diagnostics. |
| 32 * Particularly useful in cases where we have parent/child configurations | 32 * Particularly useful in cases where we have parent/child configurations |
| 33 * such as layout tests. | 33 * such as layout tests. |
| 34 */ | 34 */ |
| 35 final String name = 'Configuration'; | 35 String get name => 'Configuration'; |
| 36 | 36 |
| 37 bool get autoStart => true; | 37 bool get autoStart => true; |
| 38 | 38 |
| 39 /** | 39 /** |
| 40 * If true (the default), throw an exception at the end if any tests failed. | 40 * If true (the default), throw an exception at the end if any tests failed. |
| 41 */ | 41 */ |
| 42 bool throwOnTestFailures = true; | 42 bool throwOnTestFailures = true; |
| 43 | 43 |
| 44 /** | 44 /** |
| 45 * If true (the default), then tests will stop after the first failed | 45 * If true (the default), then tests will stop after the first failed |
| 46 * [expect]. If false, failed [expect]s will not cause the test | 46 * [expect]. If false, failed [expect]s will not cause the test |
| 47 * to stop (other exceptions will still terminate the test). | 47 * to stop (other exceptions will still terminate the test). |
| 48 */ | 48 */ |
| 49 bool stopTestOnExpectFailure = true; | 49 bool stopTestOnExpectFailure = true; |
| 50 | 50 |
| 51 // If stopTestOnExpectFailure is false, we need to capture failures, which | 51 // If stopTestOnExpectFailure is false, we need to capture failures, which |
| 52 // we do with this List. | 52 // we do with this List. |
| 53 final _testLogBuffer = <Pair<String, Trace>>[]; | 53 final _testLogBuffer = <Pair<String, Trace>>[]; |
| 54 | 54 |
| 55 /** | 55 /** |
| 56 * The constructor sets up a failure handler for [expect] that redirects | 56 * The constructor sets up a failure handler for [expect] that redirects |
| 57 * [expect] failures to [onExpectFailure]. | 57 * [expect] failures to [onExpectFailure]. |
| 58 */ | 58 */ |
| 59 SimpleConfiguration() { | 59 SimpleConfiguration() : super.blank() { |
| 60 configureExpectFailureHandler(new _ExpectFailureHandler(this)); | 60 configureExpectFailureHandler(new _ExpectFailureHandler(this)); |
| 61 } | 61 } |
| 62 | 62 |
| 63 void onInit() { | 63 void onInit() { |
| 64 _receivePort = new ReceivePort(); | 64 _receivePort = new ReceivePort(); |
| 65 _postMessage('unittest-suite-wait-for-done'); | 65 _postMessage('unittest-suite-wait-for-done'); |
| 66 } | 66 } |
| 67 | 67 |
| 68 void onStart() {} | |
| 69 | |
| 70 /** | 68 /** |
| 71 * Called when each test starts. Useful to show intermediate progress on | 69 * Called when each test starts. Useful to show intermediate progress on |
| 72 * a test suite. Derived classes should call this first before their own | 70 * a test suite. Derived classes should call this first before their own |
| 73 * override code. | 71 * override code. |
| 74 */ | 72 */ |
| 75 void onTestStart(TestCase testCase) { | 73 void onTestStart(TestCase testCase) { |
| 76 assert(testCase != null); | 74 assert(testCase != null); |
| 77 _testLogBuffer.clear(); | 75 _testLogBuffer.clear(); |
| 78 } | 76 } |
| 79 | 77 |
| (...skipping 127 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 207 } | 205 } |
| 208 } | 206 } |
| 209 } | 207 } |
| 210 | 208 |
| 211 void _postMessage(String message) { | 209 void _postMessage(String message) { |
| 212 // In dart2js browser tests, the JavaScript-based test controller | 210 // In dart2js browser tests, the JavaScript-based test controller |
| 213 // intercepts calls to print and listens for "secret" messages. | 211 // intercepts calls to print and listens for "secret" messages. |
| 214 print(message); | 212 print(message); |
| 215 } | 213 } |
| 216 } | 214 } |
| OLD | NEW |