Chromium Code Reviews| 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 // 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 Configuration _config; | 10 Configuration _config; |
| (...skipping 37 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 48 | 48 |
| 49 /** | 49 /** |
| 50 * If true (the default), then tests will stop after the first failed | 50 * If true (the default), then tests will stop after the first failed |
| 51 * [expect]. If false, failed [expect]s will not cause the test | 51 * [expect]. If false, failed [expect]s will not cause the test |
| 52 * to stop (other exceptions will still terminate the test). | 52 * to stop (other exceptions will still terminate the test). |
| 53 */ | 53 */ |
| 54 bool stopTestOnExpectFailure = true; | 54 bool stopTestOnExpectFailure = true; |
| 55 | 55 |
| 56 // If stopTestOnExpectFailure is false, we need to capture failures, which | 56 // If stopTestOnExpectFailure is false, we need to capture failures, which |
| 57 // we do with this List. | 57 // we do with this List. |
| 58 final _testLogBuffer = <Pair<String, Trace>>[]; | 58 final _testLogBuffer = <Pair<String, String>>[]; |
|
nweiz
2013/08/15 23:03:25
Trace implements StackTrace, so you can make this
gram
2013/08/16 16:56:45
Done.
gram
2013/08/16 16:56:45
Done.
| |
| 59 | 59 |
| 60 /** | 60 /** |
| 61 * The constructor sets up a failure handler for [expect] that redirects | 61 * The constructor sets up a failure handler for [expect] that redirects |
| 62 * [expect] failures to [onExpectFailure]. | 62 * [expect] failures to [onExpectFailure]. |
| 63 */ | 63 */ |
| 64 Configuration() { | 64 Configuration() { |
| 65 configureExpectFailureHandler(new _ExpectFailureHandler(this)); | 65 configureExpectFailureHandler(new _ExpectFailureHandler(this)); |
| 66 } | 66 } |
| 67 /** | 67 /** |
| 68 * Called as soon as the unittest framework becomes initialized. This is done | 68 * Called as soon as the unittest framework becomes initialized. This is done |
| 69 * even before tests are added to the test framework. It might be used to | 69 * even before tests are added to the test framework. It might be used to |
| 70 * determine/debug errors that occur before the test harness starts executing. | 70 * determine/debug errors that occur before the test harness starts executing. |
| 71 * It is also used to tell the vm or browser that tests are going to be run | 71 * It is also used to tell the vm or browser that tests are going to be run |
| 72 * asynchronously and that the process should wait until they are done. | 72 * asynchronously and that the process should wait until they are done. |
| 73 */ | 73 */ |
| 74 void onInit() { | 74 void onInit() { |
| 75 formatStacks = false; | |
| 75 _receivePort = new ReceivePort(); | 76 _receivePort = new ReceivePort(); |
| 76 _postMessage('unittest-suite-wait-for-done'); | 77 _postMessage('unittest-suite-wait-for-done'); |
| 77 } | 78 } |
| 78 | 79 |
| 79 /** Called as soon as the unittest framework starts running. */ | 80 /** Called as soon as the unittest framework starts running. */ |
| 80 void onStart() {} | 81 void onStart() {} |
| 81 | 82 |
| 82 /** | 83 /** |
| 83 * Called when each test starts. Useful to show intermediate progress on | 84 * Called when each test starts. Useful to show intermediate progress on |
| 84 * a test suite. Derived classes should call this first before their own | 85 * a test suite. Derived classes should call this first before their own |
| (...skipping 62 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 147 * Handles failures from expect(). The default in | 148 * Handles failures from expect(). The default in |
| 148 * this base configuration is to throw an exception; | 149 * this base configuration is to throw an exception; |
| 149 */ | 150 */ |
| 150 void onExpectFailure(String reason) { | 151 void onExpectFailure(String reason) { |
| 151 if (stopTestOnExpectFailure) { | 152 if (stopTestOnExpectFailure) { |
| 152 throw new TestFailure(reason); | 153 throw new TestFailure(reason); |
| 153 } else { | 154 } else { |
| 154 try { | 155 try { |
| 155 throw ''; | 156 throw ''; |
| 156 } catch (_, stack) { | 157 } catch (_, stack) { |
| 157 _testLogBuffer.add( | 158 var trace = _getTrace(stack); |
| 158 new Pair<String, Trace>(reason, new Trace.from(stack))); | 159 if (trace == null) trace = stack; |
| 160 _testLogBuffer.add(new Pair<String, String>(reason, trace.toString())); | |
|
nweiz
2013/08/15 23:03:25
Why are you eagerly converting the stack trace to
gram
2013/08/16 16:56:45
Because I didn't realize Trace <- StackTrace. :-)
| |
| 159 } | 161 } |
| 160 } | 162 } |
| 161 } | 163 } |
| 162 | 164 |
| 163 /** | 165 /** |
| 164 * Format a test result. | 166 * Format a test result. |
| 165 */ | 167 */ |
| 166 String formatResult(TestCase testCase) { | 168 String formatResult(TestCase testCase) { |
| 167 var result = new StringBuffer(); | 169 var result = new StringBuffer(); |
| 168 result.write(testCase.result.toUpperCase()); | 170 result.write(testCase.result.toUpperCase()); |
| (...skipping 65 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 234 // Currently e.message works in dartium, but not in dartc. | 236 // Currently e.message works in dartium, but not in dartc. |
| 235 void handleExternalError(e, String message, [stack]) => | 237 void handleExternalError(e, String message, [stack]) => |
| 236 _reportTestError('$message\nCaught $e', stack); | 238 _reportTestError('$message\nCaught $e', stack); |
| 237 | 239 |
| 238 _postMessage(String message) { | 240 _postMessage(String message) { |
| 239 // In dart2js browser tests, the JavaScript-based test controller | 241 // In dart2js browser tests, the JavaScript-based test controller |
| 240 // intercepts calls to print and listens for "secret" messages. | 242 // intercepts calls to print and listens for "secret" messages. |
| 241 print(message); | 243 print(message); |
| 242 } | 244 } |
| 243 } | 245 } |
| OLD | NEW |