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 /// Represents the state for an individual unit test. | 7 /// Represents the state for an individual unit test. |
8 /// | 8 /// |
9 /// Create by calling [test] or [solo_test]. | 9 /// Create by calling [test] or [solo_test]. |
10 class TestCase { | 10 class TestCase { |
(...skipping 86 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
97 if (result != null) return new Future.value(); | 97 if (result != null) return new Future.value(); |
98 _config.onTestStart(this); | 98 _config.onTestStart(this); |
99 _startTime = new DateTime.now(); | 99 _startTime = new DateTime.now(); |
100 _runningTime = null; | 100 _runningTime = null; |
101 ++_callbackFunctionsOutstanding; | 101 ++_callbackFunctionsOutstanding; |
102 var testReturn = _testFunction(); | 102 var testReturn = _testFunction(); |
103 // If _testFunction() returned a future, we want to wait for it like we | 103 // If _testFunction() returned a future, we want to wait for it like we |
104 // would a callback, so if a failure occurs while waiting, we can abort. | 104 // would a callback, so if a failure occurs while waiting, we can abort. |
105 if (testReturn is Future) { | 105 if (testReturn is Future) { |
106 ++_callbackFunctionsOutstanding; | 106 ++_callbackFunctionsOutstanding; |
107 testReturn.catchError(_errorHandler('Test')) | 107 testReturn |
| 108 .catchError(_errorHandler('Test')) |
108 .whenComplete(_markCallbackComplete); | 109 .whenComplete(_markCallbackComplete); |
109 } | 110 } |
110 }).catchError(_errorHandler('Test')).then((_) { | 111 }).catchError(_errorHandler('Test')).then((_) { |
111 _markCallbackComplete(); | 112 _markCallbackComplete(); |
112 if (result == null) { | 113 if (result == null) { |
113 // Outstanding callbacks exist; we need to return a Future. | 114 // Outstanding callbacks exist; we need to return a Future. |
114 _testComplete = new Completer(); | 115 _testComplete = new Completer(); |
115 return _testComplete.future.whenComplete(() { | 116 return _testComplete.future.whenComplete(() { |
116 if (_tearDown != null) { | 117 if (_tearDown != null) { |
117 return _tearDown(); | 118 return _tearDown(); |
(...skipping 17 matching lines...) Expand all Loading... |
135 if (_stackTrace == null) _stackTrace = 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 = '', | 146 void _complete(String testResult, |
146 StackTrace stack]) { | 147 [String messageText = '', StackTrace stack]) { |
147 if (runningTime == null) { | 148 if (runningTime == null) { |
148 // 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 |
149 // case we simply report a running time of 0. | 150 // case we simply report a running time of 0. |
150 if (startTime != null) { | 151 if (startTime != null) { |
151 _runningTime = new DateTime.now().difference(startTime); | 152 _runningTime = new DateTime.now().difference(startTime); |
152 } else { | 153 } else { |
153 _runningTime = const Duration(seconds: 0); | 154 _runningTime = const Duration(seconds: 0); |
154 } | 155 } |
155 } | 156 } |
156 _setResult(testResult, messageText, stack); | 157 _setResult(testResult, messageText, stack); |
(...skipping 25 matching lines...) Expand all Loading... |
182 } | 183 } |
183 | 184 |
184 void _markCallbackComplete() { | 185 void _markCallbackComplete() { |
185 if (--_callbackFunctionsOutstanding == 0 && !isComplete) { | 186 if (--_callbackFunctionsOutstanding == 0 && !isComplete) { |
186 _pass(); | 187 _pass(); |
187 } | 188 } |
188 } | 189 } |
189 | 190 |
190 String toString() => _result != null ? "$description: $result" : description; | 191 String toString() => _result != null ? "$description: $result" : description; |
191 } | 192 } |
OLD | NEW |