Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(14)

Side by Side Diff: lib/src/frontend/expect_async.dart

Issue 1148723005: Make expect* throw useful errors outside tests. (Closed) Base URL: git@github.com:dart-lang/test@master
Patch Set: Created 5 years, 6 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
« no previous file with comments | « lib/src/frontend/expect.dart ('k') | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
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 library test.frontend.expect_async; 5 library test.frontend.expect_async;
6 6
7 import 'dart:async'; 7 import 'dart:async';
8 8
9 import '../backend/invoker.dart'; 9 import '../backend/invoker.dart';
10 import '../backend/state.dart'; 10 import '../backend/state.dart';
(...skipping 202 matching lines...) Expand 10 before | Expand all | Expand 10 after
213 /// 213 ///
214 /// [max] can be used to specify an upper bound on the number of calls; if this 214 /// [max] can be used to specify an upper bound on the number of calls; if this
215 /// is exceeded the test will fail. If [max] is `0` (the default), the callback 215 /// is exceeded the test will fail. If [max] is `0` (the default), the callback
216 /// is expected to be called exactly [count] times. If [max] is `-1`, the 216 /// is expected to be called exactly [count] times. If [max] is `-1`, the
217 /// callback is allowed to be called any number of times greater than [count]. 217 /// callback is allowed to be called any number of times greater than [count].
218 /// 218 ///
219 /// Both [id] and [reason] are optional and provide extra information about the 219 /// Both [id] and [reason] are optional and provide extra information about the
220 /// callback when debugging. [id] should be the name of the callback, while 220 /// callback when debugging. [id] should be the name of the callback, while
221 /// [reason] should be the reason the callback is expected to be called. 221 /// [reason] should be the reason the callback is expected to be called.
222 Function expectAsync(Function callback, 222 Function expectAsync(Function callback,
223 {int count: 1, int max: 0, String id, String reason}) => 223 {int count: 1, int max: 0, String id, String reason}) {
224 new _ExpectedFunction(callback, count, max, id: id, reason: reason).func; 224 if (Invoker.current == null) {
225 throw new StateError("expectAsync() may only be called within a test.");
226 }
227
228 return new _ExpectedFunction(callback, count, max, id: id, reason: reason)
229 .func;
230 }
225 231
226 /// Indicate that [callback] is expected to be called until [isDone] returns 232 /// Indicate that [callback] is expected to be called until [isDone] returns
227 /// true. 233 /// true.
228 /// 234 ///
229 /// [isDone] is called after each time the function is run. Only when it returns 235 /// [isDone] is called after each time the function is run. Only when it returns
230 /// true will the callback be considered complete. [callback] may take up to six 236 /// true will the callback be considered complete. [callback] may take up to six
231 /// optional or required positional arguments; named arguments are not 237 /// optional or required positional arguments; named arguments are not
232 /// supported. 238 /// supported.
233 /// 239 ///
234 /// Both [id] and [reason] are optional and provide extra information about the 240 /// Both [id] and [reason] are optional and provide extra information about the
235 /// callback when debugging. [id] should be the name of the callback, while 241 /// callback when debugging. [id] should be the name of the callback, while
236 /// [reason] should be the reason the callback is expected to be called. 242 /// [reason] should be the reason the callback is expected to be called.
237 Function expectAsyncUntil(Function callback, bool isDone(), 243 Function expectAsyncUntil(Function callback, bool isDone(),
238 {String id, String reason}) => new _ExpectedFunction(callback, 0, -1, 244 {String id, String reason}) {
239 id: id, reason: reason, isDone: isDone).func; 245 if (Invoker.current == null) {
246 throw new StateError(
247 "expectAsyncUntil() may only be called within a test.");
248 }
249
250 return new _ExpectedFunction(callback, 0, -1,
251 id: id, reason: reason, isDone: isDone).func;
252 }
OLDNEW
« no previous file with comments | « lib/src/frontend/expect.dart ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698