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

Unified Diff: pkg/scheduled_test/lib/scheduled_test.dart

Issue 229453002: Support returning a Future from a setUp or test body in scheduled_test. (Closed) Base URL: https://dart.googlecode.com/svn/branches/bleeding_edge/dart
Patch Set: Created 6 years, 8 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 | « pkg/scheduled_test/CHANGELOG.md ('k') | pkg/scheduled_test/test/scheduled_test/set_up_test.dart » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: pkg/scheduled_test/lib/scheduled_test.dart
diff --git a/pkg/scheduled_test/lib/scheduled_test.dart b/pkg/scheduled_test/lib/scheduled_test.dart
index b6ba30d7e2d9513c6b8aabf8da510d93d0c750ed..e522394009222a4ce1754a2d62163ff6fd69f43f 100644
--- a/pkg/scheduled_test/lib/scheduled_test.dart
+++ b/pkg/scheduled_test/lib/scheduled_test.dart
@@ -196,6 +196,7 @@ import 'package:unittest/unittest.dart' as unittest;
import 'src/schedule.dart';
import 'src/schedule_error.dart';
+import 'src/utils.dart';
export 'package:unittest/unittest.dart' hide
test, solo_test, group, setUp, tearDown, completes, completion;
@@ -216,18 +217,30 @@ Schedule _currentSchedule;
/// `unittest.setUp`.
Function _setUpFn;
-/// Creates a new test case with the given description and body. This has the
-/// same semantics as [unittest.test].
-void test(String description, void body()) =>
+/// Creates a new test case with the given description and body.
+///
+/// This has the same semantics as [unittest.test].
+///
+/// If [body] returns a [Future], that future will automatically be wrapped with
+/// [wrapFuture].
+void test(String description, Future body()) =>
_test(description, body, unittest.test);
/// Creates a new test case with the given description and body that will be the
-/// only test run in this file. This has the same semantics as
-/// [unittest.solo_test].
-void solo_test(String description, void body()) =>
+/// only test run in this file.
+///
+/// This has the same semantics as [unittest.solo_test].
+///
+/// If [body] returns a [Future], that future will automatically be wrapped with
+/// [wrapFuture].
+void solo_test(String description, Future body()) =>
_test(description, body, unittest.solo_test);
-void _test(String description, void body(), Function testFn) {
+void _test(String description, Future body(), Function testFn) {
+ maybeWrapFuture(future, description) {
+ if (future != null) wrapFuture(future, description);
+ }
+
unittest.ensureInitialized();
_ensureSetUpForTopLevel();
testFn(description, () {
@@ -236,8 +249,8 @@ void _test(String description, void body(), Function testFn) {
Chain.capture(() {
_currentSchedule = new Schedule();
return currentSchedule.run(() {
- if (_setUpFn != null) _setUpFn();
- body();
+ if (_setUpFn != null) maybeWrapFuture(_setUpFn(), "set up");
+ maybeWrapFuture(body(), "test body");
}).catchError((error, stackTrace) {
if (error is ScheduleError) {
assert(error.schedule.errors.contains(error));
« no previous file with comments | « pkg/scheduled_test/CHANGELOG.md ('k') | pkg/scheduled_test/test/scheduled_test/set_up_test.dart » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698