| 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; |
| (...skipping 32 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 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, StackTrace>>[]; |
| 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() : super.blank() { | 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 // For Dart internal tests, we don't want stack frame filtering. |
| 65 // We turn it off here in the default config, but by default turn |
| 66 // it back on in the vm and html configs. |
| 67 filterStacks = false; |
| 64 _receivePort = new ReceivePort(); | 68 _receivePort = new ReceivePort(); |
| 65 _postMessage('unittest-suite-wait-for-done'); | 69 _postMessage('unittest-suite-wait-for-done'); |
| 66 } | 70 } |
| 67 | 71 |
| 68 /** | 72 /** |
| 69 * Called when each test starts. Useful to show intermediate progress on | 73 * Called when each test starts. Useful to show intermediate progress on |
| 70 * a test suite. Derived classes should call this first before their own | 74 * a test suite. Derived classes should call this first before their own |
| 71 * override code. | 75 * override code. |
| 72 */ | 76 */ |
| 73 void onTestStart(TestCase testCase) { | 77 void onTestStart(TestCase testCase) { |
| (...skipping 54 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 128 * Handles failures from expect(). The default in | 132 * Handles failures from expect(). The default in |
| 129 * this base configuration is to throw an exception; | 133 * this base configuration is to throw an exception; |
| 130 */ | 134 */ |
| 131 void onExpectFailure(String reason) { | 135 void onExpectFailure(String reason) { |
| 132 if (stopTestOnExpectFailure) { | 136 if (stopTestOnExpectFailure) { |
| 133 throw new TestFailure(reason); | 137 throw new TestFailure(reason); |
| 134 } else { | 138 } else { |
| 135 try { | 139 try { |
| 136 throw ''; | 140 throw ''; |
| 137 } catch (_, stack) { | 141 } catch (_, stack) { |
| 138 _testLogBuffer.add( | 142 var trace = _getTrace(stack); |
| 139 new Pair<String, Trace>(reason, new Trace.from(stack))); | 143 if (trace == null) trace = stack; |
| 144 _testLogBuffer.add(new Pair<String, StackTrace>(reason, trace)); |
| 140 } | 145 } |
| 141 } | 146 } |
| 142 } | 147 } |
| 143 | 148 |
| 144 /** | 149 /** |
| 145 * Format a test result. | 150 * Format a test result. |
| 146 */ | 151 */ |
| 147 String formatResult(TestCase testCase) { | 152 String formatResult(TestCase testCase) { |
| 148 var result = new StringBuffer(); | 153 var result = new StringBuffer(); |
| 149 result.write(testCase.result.toUpperCase()); | 154 result.write(testCase.result.toUpperCase()); |
| (...skipping 55 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 205 } | 210 } |
| 206 } | 211 } |
| 207 } | 212 } |
| 208 | 213 |
| 209 void _postMessage(String message) { | 214 void _postMessage(String message) { |
| 210 // In dart2js browser tests, the JavaScript-based test controller | 215 // In dart2js browser tests, the JavaScript-based test controller |
| 211 // intercepts calls to print and listens for "secret" messages. | 216 // intercepts calls to print and listens for "secret" messages. |
| 212 print(message); | 217 print(message); |
| 213 } | 218 } |
| 214 } | 219 } |
| OLD | NEW |