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

Unified Diff: pkg/unittest/lib/src/test_case.dart

Issue 12310123: Added ability for test cases to return Futures. (Closed) Base URL: http://dart.googlecode.com/svn/branches/bleeding_edge/dart/
Patch Set: Created 7 years, 10 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 | pkg/unittest/lib/unittest.dart » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: pkg/unittest/lib/src/test_case.dart
===================================================================
--- pkg/unittest/lib/src/test_case.dart (revision 19080)
+++ pkg/unittest/lib/src/test_case.dart (working copy)
@@ -76,9 +76,20 @@
runningTime = null;
}
- void _runTest() {
+ Future _runTest() {
_prepTest();
- test();
+ var f = test();
+ if (f is Future) {
+ f.then((_) => _finishTest())
+ .catchError((e) => fail("${e.error}"));
+ return f;
+ } else {
+ _finishTest();
+ return null;
+ }
+ }
+
+ void _finishTest() {
if (result == null && callbackFunctionsOutstanding == 0) {
pass();
}
@@ -98,19 +109,21 @@
_doneTeardown = false;
var rtn = _setUp == null ? null : _setUp();
if (rtn is Future) {
- rtn.then(expectAsync1((_) =>_runTest(),
- id: '[Async setUp completion handler]'))
- .catchError((e) {
- _prepTest();
- // Calling error() will result in the tearDown being done.
- // One could debate whether tearDown should be done after
- // a failed setUp. There is no right answer, but doing it
- // seems to be the more conservative approach, because
- // unittest will not stop at a test failure.
- error("$description: Test setup failed: ${e.error}");
- });
+ rtn.then((_) => _runTest())
+ .catchError((e) {
+ _prepTest();
+ // Calling error() will result in the tearDown being done.
+ // One could debate whether tearDown should be done after
+ // a failed setUp. There is no right answer, but doing it
+ // seems to be the more conservative approach, because
+ // unittest will not stop at a test failure.
+ error("$description: Test setup failed: ${e.error}");
+ });
} else {
- _runTest();
+ var f = _runTest();
+ if (f != null) {
+ return f;
+ }
}
if (result == null) { // Not complete.
_testComplete = new Completer();
« no previous file with comments | « no previous file | pkg/unittest/lib/unittest.dart » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698