| 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 39 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 50 | 50 |
| 51 /** The group (or groups) under which this test is running. */ | 51 /** The group (or groups) under which this test is running. */ |
| 52 final String currentGroup; | 52 final String currentGroup; |
| 53 | 53 |
| 54 DateTime _startTime; | 54 DateTime _startTime; |
| 55 DateTime get startTime => _startTime; | 55 DateTime get startTime => _startTime; |
| 56 | 56 |
| 57 Duration _runningTime; | 57 Duration _runningTime; |
| 58 Duration get runningTime => _runningTime; | 58 Duration get runningTime => _runningTime; |
| 59 | 59 |
| 60 bool enabled = true; | 60 bool _enabled = true; |
| 61 |
| 62 bool get enabled => _enabled; |
| 61 | 63 |
| 62 bool _doneTeardown = false; | 64 bool _doneTeardown = false; |
| 63 | 65 |
| 64 Completer _testComplete; | 66 Completer _testComplete; |
| 65 | 67 |
| 66 TestCase._internal(this.id, this.description, this._testFunction) | 68 TestCase._internal(this.id, this.description, this._testFunction) |
| 67 : currentGroup = _currentContext.fullName, | 69 : currentGroup = _currentContext.fullName, |
| 68 _setUp = _currentContext.testSetup, | 70 _setUp = _currentContext.testSetup, |
| 69 _tearDown = _currentContext.testTeardown; | 71 _tearDown = _currentContext.testTeardown; |
| 70 | 72 |
| 71 bool get isComplete => !enabled || result != null; | 73 bool get isComplete => !enabled || result != null; |
| 72 | 74 |
| 73 Function _errorHandler(String stage) => (e, stack) { | 75 Function _errorHandler(String stage) => (e, stack) { |
| 74 if (stack == null && e is Error) { | 76 if (stack == null && e is Error) { |
| 75 stack = e.stackTrace; | 77 stack = e.stackTrace; |
| 76 } | 78 } |
| 77 if (result == null || result == PASS) { | 79 if (result == null || result == PASS) { |
| 78 if (e is TestFailure) { | 80 if (e is TestFailure) { |
| 79 fail("$e", stack); | 81 _fail("$e", stack); |
| 80 } else { | 82 } else { |
| 81 error("$stage failed: Caught $e", stack); | 83 _error("$stage failed: Caught $e", stack); |
| 82 } | 84 } |
| 83 } | 85 } |
| 84 }; | 86 }; |
| 85 | 87 |
| 86 /** | 88 /** |
| 87 * Perform any associated [_setUp] function and run the test. Returns | 89 * Perform any associated [_setUp] function and run the test. Returns |
| 88 * a [Future] that can be used to schedule the next test. If the test runs | 90 * a [Future] that can be used to schedule the next test. If the test runs |
| 89 * to completion synchronously, or is disabled, null is returned, to | 91 * to completion synchronously, or is disabled, null is returned, to |
| 90 * tell unittest to schedule the next test immediately. | 92 * tell unittest to schedule the next test immediately. |
| 91 */ | 93 */ |
| (...skipping 61 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 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, [StackTrace 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, [StackTrace 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 |
| 189 String toString() => _result != null ? "$description: $result" : description; | 191 String toString() => _result != null ? "$description: $result" : description; |
| 190 } | 192 } |
| OLD | NEW |