| 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 /** | 7 /** |
| 8 * Represents the state for an individual unit test. | 8 * Represents the state for an individual unit test. |
| 9 * | 9 * |
| 10 * Create by calling [test] or [solo_test]. | 10 * Create by calling [test] or [solo_test]. |
| (...skipping 23 matching lines...) Expand all Loading... |
| 34 String _message = ''; | 34 String _message = ''; |
| 35 /** Error or failure message. */ | 35 /** Error or failure message. */ |
| 36 String get message => _message; | 36 String get message => _message; |
| 37 | 37 |
| 38 String _result; | 38 String _result; |
| 39 /** | 39 /** |
| 40 * One of [PASS], [FAIL], [ERROR], or [null] if the test hasn't run yet. | 40 * One of [PASS], [FAIL], [ERROR], or [null] if the test hasn't run yet. |
| 41 */ | 41 */ |
| 42 String get result => _result; | 42 String get result => _result; |
| 43 | 43 |
| 44 Trace _stackTrace; | 44 StackTrace _stackTrace; |
| 45 /** Stack trace associated with this test, or [null] if it succeeded. */ | 45 /** Stack trace associated with this test, or [null] if it succeeded. */ |
| 46 Trace get stackTrace => _stackTrace; | 46 StackTrace get stackTrace => _stackTrace; |
| 47 | 47 |
| 48 /** The group (or groups) under which this test is running. */ | 48 /** The group (or groups) under which this test is running. */ |
| 49 final String currentGroup; | 49 final String currentGroup; |
| 50 | 50 |
| 51 DateTime _startTime; | 51 DateTime _startTime; |
| 52 DateTime get startTime => _startTime; | 52 DateTime get startTime => _startTime; |
| 53 | 53 |
| 54 Duration _runningTime; | 54 Duration _runningTime; |
| 55 Duration get runningTime => _runningTime; | 55 Duration get runningTime => _runningTime; |
| 56 | 56 |
| (...skipping 66 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 123 }).catchError(_errorHandler('Teardown')); | 123 }).catchError(_errorHandler('Teardown')); |
| 124 } else if (tearDown != null) { | 124 } else if (tearDown != null) { |
| 125 return tearDown(); | 125 return tearDown(); |
| 126 } | 126 } |
| 127 }) | 127 }) |
| 128 .catchError(_errorHandler('Teardown')); | 128 .catchError(_errorHandler('Teardown')); |
| 129 } | 129 } |
| 130 | 130 |
| 131 // Set the results, notify the config, and return true if this | 131 // Set the results, notify the config, and return true if this |
| 132 // is the first time the result is being set. | 132 // is the first time the result is being set. |
| 133 void _setResult(String testResult, String messageText, stack) { | 133 void _setResult(String testResult, String messageText, StackTrace stack) { |
| 134 _message = messageText; | 134 _message = messageText; |
| 135 _stackTrace = _getTrace(stack); | 135 _stackTrace = _getTrace(stack); |
| 136 if (_stackTrace == null) _stackTrace = stack; |
| 136 if (result == null) { | 137 if (result == null) { |
| 137 _result = testResult; | 138 _result = testResult; |
| 138 _config.onTestResult(this); | 139 _config.onTestResult(this); |
| 139 } else { | 140 } else { |
| 140 _result = testResult; | 141 _result = testResult; |
| 141 _config.onTestResultChanged(this); | 142 _config.onTestResultChanged(this); |
| 142 } | 143 } |
| 143 } | 144 } |
| 144 | 145 |
| 145 void _complete(String testResult, [String messageText = '', stack]) { | 146 void _complete(String testResult, [String messageText = '', |
| 147 StackTrace stack]) { |
| 146 if (runningTime == null) { | 148 if (runningTime == null) { |
| 147 // The startTime can be `null` if an error happened during setup. In this | 149 // The startTime can be `null` if an error happened during setup. In this |
| 148 // case we simply report a running time of 0. | 150 // case we simply report a running time of 0. |
| 149 if (startTime != null) { | 151 if (startTime != null) { |
| 150 _runningTime = new DateTime.now().difference(startTime); | 152 _runningTime = new DateTime.now().difference(startTime); |
| 151 } else { | 153 } else { |
| 152 _runningTime = const Duration(seconds: 0); | 154 _runningTime = const Duration(seconds: 0); |
| 153 } | 155 } |
| 154 } | 156 } |
| 155 _setResult(testResult, messageText, stack); | 157 _setResult(testResult, messageText, stack); |
| 156 if (_testComplete != null) { | 158 if (_testComplete != null) { |
| 157 var t = _testComplete; | 159 var t = _testComplete; |
| 158 _testComplete = null; | 160 _testComplete = null; |
| 159 t.complete(this); | 161 t.complete(this); |
| 160 } | 162 } |
| 161 } | 163 } |
| 162 | 164 |
| 163 void pass() { | 165 void pass() { |
| 164 _complete(PASS); | 166 _complete(PASS); |
| 165 } | 167 } |
| 166 | 168 |
| 167 void fail(String messageText, [stack]) { | 169 void fail(String messageText, [StackTrace stack]) { |
| 168 if (result != null) { | 170 if (result != null) { |
| 169 String newMessage = (result == PASS) | 171 String newMessage = (result == PASS) |
| 170 ? 'Test failed after initially passing: $messageText' | 172 ? 'Test failed after initially passing: $messageText' |
| 171 : 'Test failed more than once: $messageText'; | 173 : 'Test failed more than once: $messageText'; |
| 172 // TODO(gram): Should we combine the stack with the old one? | 174 // TODO(gram): Should we combine the stack with the old one? |
| 173 _complete(ERROR, newMessage, stack); | 175 _complete(ERROR, newMessage, stack); |
| 174 } else { | 176 } else { |
| 175 _complete(FAIL, messageText, stack); | 177 _complete(FAIL, messageText, stack); |
| 176 } | 178 } |
| 177 } | 179 } |
| 178 | 180 |
| 179 void error(String messageText, [stack]) { | 181 void error(String messageText, [StackTrace stack]) { |
| 180 _complete(ERROR, messageText, stack); | 182 _complete(ERROR, messageText, stack); |
| 181 } | 183 } |
| 182 | 184 |
| 183 void _markCallbackComplete() { | 185 void _markCallbackComplete() { |
| 184 if (--_callbackFunctionsOutstanding == 0 && !isComplete) { | 186 if (--_callbackFunctionsOutstanding == 0 && !isComplete) { |
| 185 pass(); | 187 pass(); |
| 186 } | 188 } |
| 187 } | 189 } |
| 188 } | 190 } |
| OLD | NEW |