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

Unified 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, 7 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 side-by-side diff with in-line comments
Download patch
« no previous file with comments | « lib/src/frontend/expect.dart ('k') | no next file » | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: lib/src/frontend/expect_async.dart
diff --git a/lib/src/frontend/expect_async.dart b/lib/src/frontend/expect_async.dart
index 05c9c2e7fe65037fc2501f76c48d7b063fdae555..696fae778cd6f2423649b207b345a5e52a646611 100644
--- a/lib/src/frontend/expect_async.dart
+++ b/lib/src/frontend/expect_async.dart
@@ -220,8 +220,14 @@ class _ExpectedFunction {
/// callback when debugging. [id] should be the name of the callback, while
/// [reason] should be the reason the callback is expected to be called.
Function expectAsync(Function callback,
- {int count: 1, int max: 0, String id, String reason}) =>
- new _ExpectedFunction(callback, count, max, id: id, reason: reason).func;
+ {int count: 1, int max: 0, String id, String reason}) {
+ if (Invoker.current == null) {
+ throw new StateError("expectAsync() may only be called within a test.");
+ }
+
+ return new _ExpectedFunction(callback, count, max, id: id, reason: reason)
+ .func;
+}
/// Indicate that [callback] is expected to be called until [isDone] returns
/// true.
@@ -235,5 +241,12 @@ Function expectAsync(Function callback,
/// callback when debugging. [id] should be the name of the callback, while
/// [reason] should be the reason the callback is expected to be called.
Function expectAsyncUntil(Function callback, bool isDone(),
- {String id, String reason}) => new _ExpectedFunction(callback, 0, -1,
- id: id, reason: reason, isDone: isDone).func;
+ {String id, String reason}) {
+ if (Invoker.current == null) {
+ throw new StateError(
+ "expectAsyncUntil() may only be called within a test.");
+ }
+
+ return new _ExpectedFunction(callback, 0, -1,
+ id: id, reason: reason, isDone: isDone).func;
+}
« 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