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 81 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
92 // Avoid calling [new Future] to avoid issue 11911. | 92 // Avoid calling [new Future] to avoid issue 11911. |
93 return new Future.value().then((_) { | 93 return new Future.value().then((_) { |
94 if (_setUp != null) return _setUp(); | 94 if (_setUp != null) return _setUp(); |
95 }).catchError(_errorHandler('Setup')).then((_) { | 95 }).catchError(_errorHandler('Setup')).then((_) { |
96 // Skip the test if setup failed. | 96 // Skip the test if setup failed. |
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 return _testFunction(); | 102 var testReturn = _testFunction(); |
| 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. |
| 105 if (testReturn is Future) { |
| 106 ++_callbackFunctionsOutstanding; |
| 107 testReturn.catchError(_errorHandler('Test')) |
| 108 .whenComplete(_markCallbackComplete); |
| 109 } |
103 }).catchError(_errorHandler('Test')).then((_) { | 110 }).catchError(_errorHandler('Test')).then((_) { |
104 _markCallbackComplete(); | 111 _markCallbackComplete(); |
105 if (result == null) { | 112 if (result == null) { |
106 // Outstanding callbacks exist; we need to return a Future. | 113 // Outstanding callbacks exist; we need to return a Future. |
107 _testComplete = new Completer(); | 114 _testComplete = new Completer(); |
108 return _testComplete.future.whenComplete(() { | 115 return _testComplete.future.whenComplete(() { |
109 if (_tearDown != null) { | 116 if (_tearDown != null) { |
110 return _tearDown(); | 117 return _tearDown(); |
111 } | 118 } |
112 }).catchError(_errorHandler('Teardown')); | 119 }).catchError(_errorHandler('Teardown')); |
(...skipping 58 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
171 } | 178 } |
172 | 179 |
173 void _markCallbackComplete() { | 180 void _markCallbackComplete() { |
174 if (--_callbackFunctionsOutstanding == 0 && !isComplete) { | 181 if (--_callbackFunctionsOutstanding == 0 && !isComplete) { |
175 _pass(); | 182 _pass(); |
176 } | 183 } |
177 } | 184 } |
178 | 185 |
179 String toString() => _result != null ? "$description: $result" : description; | 186 String toString() => _result != null ? "$description: $result" : description; |
180 } | 187 } |
OLD | NEW |