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

Unified Diff: lib/src/backend/group.dart

Issue 1369613002: setUp/tearDown may be called repeatedly in a group. (Closed) Base URL: git@github.com:dart-lang/test@master
Patch Set: Code review changes Created 5 years, 3 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/src/backend/declarer.dart ('k') | lib/test.dart » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: lib/src/backend/group.dart
diff --git a/lib/src/backend/group.dart b/lib/src/backend/group.dart
index d1bc67a390a07ed39c45e04fc13001e6c7945b4a..47e06e3aa1eabb6ca6eeb0336d971242a4e730b8 100644
--- a/lib/src/backend/group.dart
+++ b/lib/src/backend/group.dart
@@ -30,11 +30,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 +57,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 +91,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;
}
}
« no previous file with comments | « lib/src/backend/declarer.dart ('k') | lib/test.dart » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698