Chromium Code Reviews| Index: lib/src/backend/group.dart |
| diff --git a/lib/src/backend/group.dart b/lib/src/backend/group.dart |
| index d1bc67a390a07ed39c45e04fc13001e6c7945b4a..d64b584849de59a9f2aa91dd5498916dc5e17539 100644 |
| --- a/lib/src/backend/group.dart |
| +++ b/lib/src/backend/group.dart |
| @@ -6,6 +6,7 @@ library test.backend.group; |
| import 'dart:async'; |
| +import '../../test.dart'; |
|
kevmoo
2015/09/24 21:33:29
unused import?
nweiz
2015/09/24 22:25:47
Done.
|
| import '../utils.dart'; |
| import 'invoker.dart'; |
| import 'metadata.dart'; |
| @@ -30,11 +31,11 @@ class Group { |
| } |
| final Metadata _metadata; |
| - /// The set-up function for this group, or `null`. |
| - AsyncFunction setUp; |
| + /// The set-up functions for this group. |
| + final setUps = new List<AsyncFunction>(); |
| - /// The tear-down function for this group, or `null`. |
| - AsyncFunction tearDown; |
| + /// The tear-down functions for this group. |
| + final tearDowns = new List<AsyncFunction>(); |
| /// Returns the description for this group, including the description of any |
| /// parent groups. |
| @@ -57,33 +58,31 @@ class Group { |
| /// |
| /// If no set-up functions are declared, this returns a [Future] that |
| /// completes immediately. |
| - Future runSetUp() { |
| + Future runSetUps() { |
| // TODO(nweiz): Use async/await here once issue 23497 has been fixed in two |
| // stable versions. |
| if (parent != null) { |
| - return parent.runSetUp().then((_) { |
| - if (setUp != null) return setUp(); |
| + return parent.runSetUps().then((_) { |
| + return Future.forEach(setUps, (setUp) => setUp()); |
| }); |
| } |
| - if (setUp != null) return new Future.sync(setUp); |
| - return new Future.value(); |
| + return Future.forEach(setUps, (setUp) => setUp()); |
| } |
| /// Run the tear-up functions for this and any parent groups. |
| /// |
| /// If no set-up functions are declared, this returns a [Future] that |
| /// completes immediately. |
| - Future runTearDown() { |
| + Future runTearDowns() { |
| // TODO(nweiz): Use async/await here once issue 23497 has been fixed in two |
| // stable versions. |
| if (parent == null) { |
| - return tearDown == null ? new Future.value() : new Future.sync(tearDown); |
| + return Future.forEach(tearDowns.reversed, _errorsDontStopTest); |
| } |
| - return _errorsDontStopTest(() { |
| - if (tearDown != null) return tearDown(); |
| - }).then((_) => parent.runTearDown()); |
| + return Future.forEach(tearDowns.reversed, _errorsDontStopTest) |
| + .then((_) => parent.runTearDowns()); |
| } |
| /// Runs [body] with special error-handling behavior. |
| @@ -93,9 +92,12 @@ class Group { |
| /// callbacks registered outside of [body]. |
| Future _errorsDontStopTest(body()) { |
| var completer = new Completer(); |
| + |
| + Invoker.current.addOutstandingCallback(); |
| Invoker.current.waitForOutstandingCallbacks(() { |
| new Future.sync(body).whenComplete(completer.complete); |
| - }); |
| + }).then((_) => Invoker.current.removeOutstandingCallback()); |
| + |
| return completer.future; |
| } |
| } |