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

Unified Diff: lib/unittest/unittest.dart

Issue 10539163: Revert 8668 (Closed) Base URL: http://dart.googlecode.com/svn/branches/bleeding_edge/dart/
Patch Set: Created 8 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 side-by-side diff with in-line comments
Download patch
« no previous file with comments | « lib/unittest/core_matchers.dart ('k') | tests/isolate/v2_unresolved_ports_negative_test.dart » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: lib/unittest/unittest.dart
===================================================================
--- lib/unittest/unittest.dart (revision 8672)
+++ lib/unittest/unittest.dart (working copy)
@@ -297,108 +297,65 @@
// arguments inside [_expectAsync], once bug 282 is fixed or frog is replaced by
// dart2js.
class _SpreadArgsHelper {
- Function _callback;
- int _expectedCalls = 0;
- int _calls = 0;
- TestCase _testCase;
- Function _shouldCallBack;
- Function _isDone;
-
- _init(Function callback, Function shouldCallBack, Function isDone,
- [expectedCalls = 0]) {
- assert(_currentTest < _tests.length);
- _callback = callback;
- _shouldCallBack = shouldCallBack;
- _isDone = isDone;
- _expectedCalls = expectedCalls;
- _testCase = _tests[_currentTest];
- _testCase.callbacks++;
+ Function callback;
+ int expectedCalls;
+ int calls = 0;
+ TestCase testCase;
+ _SpreadArgsHelper(this.callback, this.expectedCalls) {
+ Expect.isTrue(_currentTest < _tests.length);
+ testCase = _tests[_currentTest];
+ testCase.callbacks++;
}
- _SpreadArgsHelper(callback, shouldCallBack, isDone) {
- _init(callback, shouldCallBack, isDone);
- }
-
- _SpreadArgsHelper.fixedCallCount(callback, expectedCalls) {
- _init(callback, _checkCallCount, _allCallsDone, expectedCalls);
- }
-
- _SpreadArgsHelper.variableCallCount(callback, isDone) {
- _init(callback, _always, isDone);
- }
-
- _after() {
- if (_isDone()) {
- _handleAllCallbacksDone();
- }
- }
-
- _allCallsDone() => _calls == _expectedCalls;
-
- _always() {
- // Always run except if the test is done.
- if (_testCase.isComplete) {
- _testCase.error(
- 'Callback called after already being marked as done ($_calls)',
- '');
- _state = _UNCAUGHT_ERROR;
- return false;
- } else {
- return true;
- }
- }
-
invoke([arg0 = _sentinel, arg1 = _sentinel, arg2 = _sentinel,
arg3 = _sentinel, arg4 = _sentinel]) {
return guardAsync(() {
- ++_calls;
- if (!_shouldCallBack()) {
+ if (!_incrementCall()) {
return;
} else if (arg0 == _sentinel) {
- return _callback();
+ return callback();
} else if (arg1 == _sentinel) {
- return _callback(arg0);
+ return callback(arg0);
} else if (arg2 == _sentinel) {
- return _callback(arg0, arg1);
+ return callback(arg0, arg1);
} else if (arg3 == _sentinel) {
- return _callback(arg0, arg1, arg2);
+ return callback(arg0, arg1, arg2);
} else if (arg4 == _sentinel) {
- return _callback(arg0, arg1, arg2, arg3);
+ return callback(arg0, arg1, arg2, arg3);
} else {
- _testCase.error(
+ testCase.error(
'unittest lib does not support callbacks with more than 4 arguments',
'');
_state = _UNCAUGHT_ERROR;
}
- },
- _after);
+ }, () { if (calls == expectedCalls) callbackDone(); });
}
invoke0() {
return guardAsync(
- () { if (_shouldCallBack()) _callback(); },
- _after);
+ () => _incrementCall() ? callback() : null,
+ () { if (calls == expectedCalls) callbackDone(); });
}
invoke1(arg1) {
return guardAsync(
- () { if (_shouldCallBack()) _callback(arg1); },
- _after);
+ () => _incrementCall() ? callback(arg1) : null,
+ () { if (calls == expectedCalls) callbackDone(); });
}
invoke2(arg1, arg2) {
return guardAsync(
- () { if (_shouldCallBack()) _callback(arg1, arg2); },
- _after);
+ () => _incrementCall() ? callback(arg1, arg2) : null,
+ () { if (calls == expectedCalls) callbackDone(); });
}
/** Returns false if we exceded the number of expected calls. */
- bool _checkCallCount() {
- if (_calls > _expectedCalls) {
- _testCase.error(
- 'Callback called more times than expected '
- '($_calls > $_expectedCalls)',
- '');
+ bool _incrementCall() {
+ calls++;
+ if (calls > expectedCalls) {
+ testCase.error(
+ 'Callback called more times than expected ($calls > $expectedCalls)',
+ '');
_state = _UNCAUGHT_ERROR;
return false;
}
@@ -415,7 +372,7 @@
* arguments (named arguments are not supported here).
*/
Function _expectAsync(Function callback, [int count = 1]) {
- return new _SpreadArgsHelper.fixedCallCount(callback, count).invoke;
+ return new _SpreadArgsHelper(callback, count).invoke;
}
/**
@@ -428,63 +385,22 @@
*/
// TODO(sigmund): deprecate this API when issue 2706 is fixed.
Function expectAsync0(Function callback, [int count = 1]) {
- return new _SpreadArgsHelper.fixedCallCount(callback, count).invoke0;
+ return new _SpreadArgsHelper(callback, count).invoke0;
}
/** Like [expectAsync0] but [callback] should take 1 positional argument. */
// TODO(sigmund): deprecate this API when issue 2706 is fixed.
Function expectAsync1(Function callback, [int count = 1]) {
- return new _SpreadArgsHelper.fixedCallCount(callback, count).invoke1;
+ return new _SpreadArgsHelper(callback, count).invoke1;
}
/** Like [expectAsync0] but [callback] should take 2 positional arguments. */
// TODO(sigmund): deprecate this API when issue 2706 is fixed.
Function expectAsync2(Function callback, [int count = 1]) {
- return new _SpreadArgsHelper.fixedCallCount(callback, count).invoke2;
+ return new _SpreadArgsHelper(callback, count).invoke2;
}
/**
- * Indicate that [callback] is expected to be called until [isDone] returns
- * true. The unittest framework checks [isDone] after each callback and only
- * when it returns true will it continue with the following test. Using
- * [expectAsyncUntil] will also ensure that errors that occur within
- * [callback] are tracked and reported. [callback] should take between 0 and
- * 4 positional arguments (named arguments are not supported).
- */
-Function _expectAsyncUntil(Function callback, Function isDone) {
- return new _SpreadArgsHelper.variableCallCount(callback, isDone).invoke;
-}
-
-/**
- * Indicate that [callback] is expected to be called until [isDone] returns
- * true. The unittest framework check [isDone] after each callback and only
- * when it returns true will it continue with the following test. Using
- * [expectAsyncUntil0] will also ensure that errors that occur within
- * [callback] are tracked and reported. [callback] should take 0 positional
- * arguments (named arguments are not supported).
- */
-// TODO(sigmund): deprecate this API when issue 2706 is fixed.
-Function expectAsyncUntil0(Function callback, Function isDone) {
- return new _SpreadArgsHelper.variableCallCount(callback, isDone).invoke0;
-}
-
-/**
- * Like [expectAsyncUntil0] but [callback] should take 1 positional argument.
- */
-// TODO(sigmund): deprecate this API when issue 2706 is fixed.
-Function expectAsyncUntil1(Function callback, Function isDone) {
- return new _SpreadArgsHelper.variableCallCount(callback, isDone).invoke1;
-}
-
-/**
- * Like [expectAsyncUntil0] but [callback] should take 2 positional arguments.
- */
-// TODO(sigmund): deprecate this API when issue 2706 is fixed.
-Function expectAsyncUntil2(Function callback, Function isDone) {
- return new _SpreadArgsHelper.variableCallCount(callback, isDone).invoke2;
-}
-
-/**
* Creates a new named group of tests. Calls to group() or test() within the
* body of the function passed to this will inherit this group's description.
*/
@@ -510,7 +426,7 @@
}
/** Called by subclasses to indicate that an asynchronous test completed. */
-void _handleAllCallbacksDone() {
+void callbackDone() {
// TODO (gram): we defer this to give the nextBatch recursive
// stack a chance to unwind. This is a temporary hack but
// really a bunch of code here needs to be fixed. We have a
@@ -626,6 +542,7 @@
guardAsync(() {
_callbacksCalled = 0;
_state = _RUNNING_TEST;
+
testCase.test();
if (_state != _UNCAUGHT_ERROR) {
@@ -679,8 +596,6 @@
if (_state != _UNINITIALIZED) return;
_tests = <TestCase>[];
- _uncaughtErrorMessage = null;
- _currentTest = 0;
_currentGroup = '';
_state = _READY;
_testRunner = _nextBatch;
« no previous file with comments | « lib/unittest/core_matchers.dart ('k') | tests/isolate/v2_unresolved_ports_negative_test.dart » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698