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 /** | 7 /** |
8 * testcase.dart: this file is sourced by unittest.dart. It defines [TestCase] | 8 * testcase.dart: this file is sourced by unittest.dart. It defines [TestCase] |
9 * and assumes unittest defines the type [TestFunction]. | 9 * and assumes unittest defines the type [TestFunction]. |
10 */ | 10 */ |
(...skipping 60 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
71 bool get isComplete => !enabled || result != null; | 71 bool get isComplete => !enabled || result != null; |
72 | 72 |
73 void _prepTest() { | 73 void _prepTest() { |
74 _config.onTestStart(this); | 74 _config.onTestStart(this); |
75 startTime = new DateTime.now(); | 75 startTime = new DateTime.now(); |
76 runningTime = null; | 76 runningTime = null; |
77 } | 77 } |
78 | 78 |
79 Future _runTest() { | 79 Future _runTest() { |
80 _prepTest(); | 80 _prepTest(); |
| 81 // Increment/decrement callbackFunctionsOutstanding to prevent |
| 82 // synchronous 'async' callbacks from causing the test to be |
| 83 // marked as complete before the body is completely executed. |
| 84 ++callbackFunctionsOutstanding; |
81 var f = test(); | 85 var f = test(); |
| 86 --callbackFunctionsOutstanding; |
82 if (f is Future) { | 87 if (f is Future) { |
83 f.then((_) => _finishTest()) | 88 f.then((_) => _finishTest()) |
84 .catchError((e) => fail("${e.error}")); | 89 .catchError((e) => fail("${e.error}")); |
85 return f; | 90 return f; |
86 } else { | 91 } else { |
87 _finishTest(); | 92 _finishTest(); |
88 return null; | 93 return null; |
89 } | 94 } |
90 } | 95 } |
91 | 96 |
(...skipping 105 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
197 // TODO(gram): Should we combine the stack with the old one? | 202 // TODO(gram): Should we combine the stack with the old one? |
198 _complete(ERROR, newMessage, stack); | 203 _complete(ERROR, newMessage, stack); |
199 } else { | 204 } else { |
200 _complete(FAIL, messageText, stack); | 205 _complete(FAIL, messageText, stack); |
201 } | 206 } |
202 } | 207 } |
203 | 208 |
204 void error(String messageText, [String stack = '']) { | 209 void error(String messageText, [String stack = '']) { |
205 _complete(ERROR, messageText, stack); | 210 _complete(ERROR, messageText, stack); |
206 } | 211 } |
| 212 |
| 213 void markCallbackComplete() { |
| 214 if (--callbackFunctionsOutstanding == 0 && !isComplete) { |
| 215 pass(); |
| 216 } |
| 217 } |
207 } | 218 } |
OLD | NEW |