| 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 part of unittest; | 5 part of unittest; |
| 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 |
| 11 * this class. | 11 * this class. |
| 12 */ | 12 */ |
| 13 | 13 |
| 14 class Configuration { | 14 class Configuration { |
| 15 // The VM won't shut down if a receive port is open. Use this to make sure | 15 // The VM won't shut down if a receive port is open. Use this to make sure |
| 16 // we correctly wait for asynchronous tests. | 16 // we correctly wait for asynchronous tests. |
| 17 ReceivePort _receivePort; | 17 ReceivePort _receivePort; |
| 18 TestCase _currentTestCase; | |
| 19 | |
| 20 TestCase get currentTestCase => _currentTestCase; | |
| 21 | 18 |
| 22 /** | 19 /** |
| 23 * Subclasses can override this with something useful for diagnostics. | 20 * Subclasses can override this with something useful for diagnostics. |
| 24 * Particularly useful in cases where we have parent/child configurations | 21 * Particularly useful in cases where we have parent/child configurations |
| 25 * such as layout tests. | 22 * such as layout tests. |
| 26 */ | 23 */ |
| 27 String get name => 'Configuration'; | 24 String get name => 'Configuration'; |
| 28 | 25 |
| 29 /** | 26 /** |
| 30 * If true, then tests are started automatically (otherwise [runTests] | 27 * If true, then tests are started automatically (otherwise [runTests] |
| (...skipping 15 matching lines...) Expand all Loading... |
| 46 | 43 |
| 47 /** Called as soon as the unittest framework starts running. */ | 44 /** Called as soon as the unittest framework starts running. */ |
| 48 void onStart() {} | 45 void onStart() {} |
| 49 | 46 |
| 50 /** | 47 /** |
| 51 * Called when each test starts. Useful to show intermediate progress on | 48 * Called when each test starts. Useful to show intermediate progress on |
| 52 * a test suite. | 49 * a test suite. |
| 53 */ | 50 */ |
| 54 void onTestStart(TestCase testCase) { | 51 void onTestStart(TestCase testCase) { |
| 55 assert(testCase != null); | 52 assert(testCase != null); |
| 56 assert(_currentTestCase == null); | |
| 57 _currentTestCase = testCase; | |
| 58 } | 53 } |
| 59 | 54 |
| 60 /** | 55 /** |
| 61 * Called when each test is completed. Useful to show intermediate progress on | 56 * Called when each test is first completed. Useful to show intermediate |
| 62 * a test suite. | 57 * progress on a test suite. |
| 63 */ | 58 */ |
| 64 void onTestResult(TestCase testCase) { | 59 void onTestResult(TestCase testCase) { |
| 65 assert(testCase != null); | 60 assert(testCase != null); |
| 66 assert(_currentTestCase == null || _currentTestCase == testCase); | 61 } |
| 67 _currentTestCase = null; | 62 |
| 63 /** |
| 64 * Called when an already completed test changes state; for example a test |
| 65 * that was marked as passing may later be marked as being in error because |
| 66 * it still had callbacks being invoked. |
| 67 */ |
| 68 void onTestResultChanged(TestCase testCase) { |
| 69 assert(testCase != null); |
| 68 } | 70 } |
| 69 | 71 |
| 70 /** | 72 /** |
| 71 * Can be called by tests to log status. Tests should use this | 73 * Can be called by tests to log status. Tests should use this |
| 72 * instead of print. Subclasses should not override this; they | 74 * instead of print. Subclasses should not override this; they |
| 73 * should instead override logMessage which is passed the test case. | 75 * should instead override logMessage which is passed the test case. |
| 74 */ | 76 */ |
| 75 void logMessage(String message) { | 77 void logMessage(String message) { |
| 76 if (currentTestCase == null || _currentTest >= _tests.length || | 78 if (currentTestCase == null) { |
| 77 currentTestCase.id != _tests[_currentTest].id) { | 79 // Before or after tests run. In this case we pass null for the test |
| 78 // Before or after tests run, or with a mismatch between what the | 80 // case reference and let the config decide what to do with this. |
| 79 // config and the test harness think is the current test. In this | |
| 80 // case we pass null for the test case reference and let the config | |
| 81 // decide what to do with this. | |
| 82 logTestCaseMessage(null, message); | 81 logTestCaseMessage(null, message); |
| 83 } else { | 82 } else { |
| 84 logTestCaseMessage(currentTestCase, message); | 83 logTestCaseMessage(currentTestCase, message); |
| 85 } | 84 } |
| 86 } | 85 } |
| 87 | 86 |
| 88 /** | 87 /** |
| 89 * Handles the logging of messages by a test case. The default in | 88 * Handles the logging of messages by a test case. The default in |
| 90 * this base configuration is to call print(); | 89 * this base configuration is to call print(); |
| 91 */ | 90 */ |
| (...skipping 69 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 161 // Currently e.message works in dartium, but not in dartc. | 160 // Currently e.message works in dartium, but not in dartc. |
| 162 handleExternalError(e, String message) => | 161 handleExternalError(e, String message) => |
| 163 _reportTestError('$message\nCaught $e', ''); | 162 _reportTestError('$message\nCaught $e', ''); |
| 164 | 163 |
| 165 _postMessage(String message) { | 164 _postMessage(String message) { |
| 166 // In dart2js browser tests, the JavaScript-based test controller | 165 // In dart2js browser tests, the JavaScript-based test controller |
| 167 // intercepts calls to print and listens for "secret" messages. | 166 // intercepts calls to print and listens for "secret" messages. |
| 168 print(message); | 167 print(message); |
| 169 } | 168 } |
| 170 } | 169 } |
| OLD | NEW |