OLD | NEW |
---|---|
1 // Copyright (c) 2015, the Dart project authors. Please see the AUTHORS file | 1 // Copyright (c) 2015, 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 import 'dart:async'; | 5 import 'dart:async'; |
6 | 6 |
7 import '../backend/invoker.dart'; | 7 import '../backend/invoker.dart'; |
8 import '../backend/state.dart'; | 8 import '../backend/state.dart'; |
kevmoo
2016/06/23 23:33:48
Not not used
nweiz
2016/06/23 23:52:15
Done.
| |
9 import 'expect.dart'; | 9 import 'expect.dart'; |
10 | 10 |
11 /// An object used to detect unpassed arguments. | 11 /// An object used to detect unpassed arguments. |
12 const _PLACEHOLDER = const Object(); | 12 const _PLACEHOLDER = const Object(); |
13 | 13 |
14 // Functions used to check how many arguments a callback takes. | 14 // Functions used to check how many arguments a callback takes. |
15 typedef _Func0(); | 15 typedef _Func0(); |
16 typedef _Func1(a); | 16 typedef _Func1(a); |
17 typedef _Func2(a, b); | 17 typedef _Func2(a, b); |
18 typedef _Func3(a, b, c); | 18 typedef _Func3(a, b, c); |
(...skipping 144 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
163 a3 = _PLACEHOLDER, a4 = _PLACEHOLDER, a5 = _PLACEHOLDER]) => | 163 a3 = _PLACEHOLDER, a4 = _PLACEHOLDER, a5 = _PLACEHOLDER]) => |
164 _run([a0, a1, a2, a3, a4, a5].where((a) => a != _PLACEHOLDER)); | 164 _run([a0, a1, a2, a3, a4, a5].where((a) => a != _PLACEHOLDER)); |
165 | 165 |
166 /// Runs the wrapped function with [args] and returns its return value. | 166 /// Runs the wrapped function with [args] and returns its return value. |
167 _run(Iterable args) { | 167 _run(Iterable args) { |
168 // Note that in the old test, this returned `null` if it encountered an | 168 // Note that in the old test, this returned `null` if it encountered an |
169 // error, where now it just re-throws that error because Zone machinery will | 169 // error, where now it just re-throws that error because Zone machinery will |
170 // pass it to the invoker anyway. | 170 // pass it to the invoker anyway. |
171 try { | 171 try { |
172 _actualCalls++; | 172 _actualCalls++; |
173 if (_invoker.liveTest.isComplete && | 173 if (_invoker.liveTest.state.shouldBeDone) { |
174 _invoker.liveTest.state.result == Result.success) { | |
175 throw 'Callback ${_id}called ($_actualCalls) after test case ' | 174 throw 'Callback ${_id}called ($_actualCalls) after test case ' |
176 '${_invoker.liveTest.test.name} had already completed.$_reason'; | 175 '${_invoker.liveTest.test.name} had already completed.$_reason'; |
177 } else if (_maxExpectedCalls >= 0 && _actualCalls > _maxExpectedCalls) { | 176 } else if (_maxExpectedCalls >= 0 && _actualCalls > _maxExpectedCalls) { |
178 throw new TestFailure('Callback ${_id}called more times than expected ' | 177 throw new TestFailure('Callback ${_id}called more times than expected ' |
179 '($_maxExpectedCalls).$_reason'); | 178 '($_maxExpectedCalls).$_reason'); |
180 } | 179 } |
181 | 180 |
182 return Function.apply(_callback, args.toList()); | 181 return Function.apply(_callback, args.toList()); |
183 } catch (error, stackTrace) { | 182 } catch (error, stackTrace) { |
184 _zone.handleUncaughtError(error, stackTrace); | 183 _zone.handleUncaughtError(error, stackTrace); |
(...skipping 56 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
241 Function expectAsyncUntil(Function callback, bool isDone(), | 240 Function expectAsyncUntil(Function callback, bool isDone(), |
242 {String id, String reason}) { | 241 {String id, String reason}) { |
243 if (Invoker.current == null) { | 242 if (Invoker.current == null) { |
244 throw new StateError( | 243 throw new StateError( |
245 "expectAsyncUntil() may only be called within a test."); | 244 "expectAsyncUntil() may only be called within a test."); |
246 } | 245 } |
247 | 246 |
248 return new _ExpectedFunction(callback, 0, -1, | 247 return new _ExpectedFunction(callback, 0, -1, |
249 id: id, reason: reason, isDone: isDone).func; | 248 id: id, reason: reason, isDone: isDone).func; |
250 } | 249 } |
OLD | NEW |