Index: pkg/unittest/lib/unittest.dart |
=================================================================== |
--- pkg/unittest/lib/unittest.dart (revision 33351) |
+++ pkg/unittest/lib/unittest.dart (working copy) |
@@ -325,9 +325,23 @@ |
* bound. |
*/ |
Function expectAsync(Function callback, |
- {int count: 1, int max: 0, String id}) => |
- new _SpreadArgsHelper(callback, count, max, id); |
+ {int count: 1, int max: 0, String id}) { |
+ var minArgs = _minArgs(callback); |
+ switch(minArgs) { |
+ case 0: |
+ return new _SpreadArgsHelper(callback, count, max, null, id).invoke0; |
+ case 1: |
+ return new _SpreadArgsHelper(callback, count, max, null, id).invoke1; |
+ case 2: |
+ return new _SpreadArgsHelper(callback, count, max, null, id).invoke2; |
+ default: |
+ // _minArgs throws an argument exception if the arg count is > 2. |
+ // this is just for paranoia |
+ throw new StateError('Should never get here'); |
+ } |
+} |
+ |
/** |
* *Deprecated* |
* |
@@ -368,9 +382,23 @@ |
* identify the callback in error messages (for example if it is called |
* after the test case is complete). |
*/ |
-Function expectAsyncUntil(Function callback, bool isDone(), {String id}) => |
- new _SpreadArgsHelper(callback, 0, -1, id, isDone: isDone); |
+Function expectAsyncUntil(Function callback, Function isDone, {String id}) { |
+ var minArgs = _minArgs(callback); |
+ switch(minArgs) { |
+ case 0: |
+ return new _SpreadArgsHelper(callback, 0, -1, isDone, id).invoke0; |
+ case 1: |
+ return new _SpreadArgsHelper(callback, 0, -1, isDone, id).invoke1; |
+ case 2: |
+ return new _SpreadArgsHelper(callback, 0, -1, isDone, id).invoke2; |
+ default: |
+ // _minArgs throws an argument exception if the arg count is > 2. |
+ // this is just for paranoia |
+ throw new StateError('Should never get here'); |
+ } |
+} |
+ |
/** |
* *Deprecated* |
* |
@@ -742,3 +770,18 @@ |
return frame.package != 'unittest' || frame.member != 'TestCase._runTest'; |
})).terse.foldFrames((frame) => frame.package == 'unittest' || frame.isCore); |
} |
+ |
+typedef _Func0(); |
+typedef _Func1(a); |
+typedef _Func2(a, b); |
+ |
+/** |
+ * Throws an [ArgumentError] if the callback has more than 2 required arguments. |
+ */ |
+int _minArgs(Function callback) { |
+ if (callback is _Func0) return 0; |
+ if (callback is _Func1) return 1; |
+ if (callback is _Func2) return 2; |
+ throw new ArgumentError( |
+ 'The callback argument has more than 2 required arguments.'); |
+} |