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

Unified Diff: lib/unittest/unittest.dart

Issue 10412015: aChange all asyncTest/callbackDone style tests to use the new expectAsync/ (Closed) Base URL: http://dart.googlecode.com/svn/branches/bleeding_edge/dart/
Patch Set: Created 8 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 | « no previous file | tests/benchmark_smoke/benchmark_smoke_test.dart » ('j') | tests/dom/async_window_test.dart » ('J')
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: lib/unittest/unittest.dart
===================================================================
--- lib/unittest/unittest.dart (revision 7823)
+++ lib/unittest/unittest.dart (working copy)
@@ -374,7 +374,7 @@
return new _SpreadArgsHelper(callback, count).invoke1;
}
-/** Like [expectAsync0] but [callback] should take 1 positional argument. */
+/** 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(callback, count).invoke2;
@@ -407,22 +407,30 @@
/** Called by subclasses to indicate that an asynchronous test completed. */
void callbackDone() {
- _callbacksCalled++;
- if (_currentTest < _tests.length) {
- final testCase = _tests[_currentTest];
- if (_callbacksCalled > testCase.callbacks) {
- final expected = testCase.callbacks;
- testCase.error(
- 'More calls to callbackDone() than expected. '
- 'Actual: ${_callbacksCalled}, expected: ${expected}', '');
- _state = _UNCAUGHT_ERROR;
- } else if ((_callbacksCalled == testCase.callbacks) &&
- (_state != _RUNNING_TEST)) {
- if (testCase.result == null) testCase.pass();
- _currentTest++;
- _testRunner();
+ // 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
+ // single array that is being iterated through by a function
+ // that is recursively invoked in the case of async tests.
Siggi Cherem (dart-lang) 2012/05/21 22:20:47 can we clarify here why recursive calls happen. In
gram 2012/05/22 17:36:36 Done.
+ // Bad things can happen.
+ _defer(() {
+ _callbacksCalled++;
+ if (_currentTest < _tests.length) {
+ final testCase = _tests[_currentTest];
+ if (_callbacksCalled > testCase.callbacks) {
+ final expected = testCase.callbacks;
+ testCase.error(
+ 'More calls to callbackDone() than expected. '
+ 'Actual: ${_callbacksCalled}, expected: ${expected}', '');
+ _state = _UNCAUGHT_ERROR;
+ } else if ((_callbacksCalled == testCase.callbacks) &&
+ (_state != _RUNNING_TEST)) {
+ if (testCase.result == null) testCase.pass();
+ _currentTest++;
+ _testRunner();
+ }
}
- }
+ });
}
/** Menchanism to notify that an error was caught outside of this library. */
@@ -476,6 +484,7 @@
try {
return tryBody();
} catch (ExpectException e, var trace) {
+ Expect.isTrue(_currentTest < _tests.length);
if (_state != _UNCAUGHT_ERROR) {
_tests[_currentTest].fail(e.message,
trace == null ? '' : trace.toString());
« no previous file with comments | « no previous file | tests/benchmark_smoke/benchmark_smoke_test.dart » ('j') | tests/dom/async_window_test.dart » ('J')

Powered by Google App Engine
This is Rietveld 408576698