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

Side by Side Diff: lib/src/backend/group.dart

Issue 1364893004: Run outer tearDown()s even if inner ones fail. (Closed) Base URL: git@github.com:dart-lang/test@master
Patch Set: More robust 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 unified diff | Download patch
« no previous file with comments | « CHANGELOG.md ('k') | pubspec.yaml » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 // Copyright (c) 2015, the Dart project authors. Please see the AUTHORS file 1 // Copyright (c) 2015, the Dart project authors. Please see the AUTHORS file
2 // for details. All rights reserved. Use of this source code is governed by a 2 // for details. All rights reserved. Use of this source code is governed by a
3 // BSD-style license that can be found in the LICENSE file. 3 // BSD-style license that can be found in the LICENSE file.
4 4
5 library test.backend.group; 5 library test.backend.group;
6 6
7 import 'dart:async'; 7 import 'dart:async';
8 8
9 import '../utils.dart'; 9 import '../utils.dart';
10 import 'invoker.dart';
10 import 'metadata.dart'; 11 import 'metadata.dart';
11 12
12 /// A group contains multiple tests and subgroups. 13 /// A group contains multiple tests and subgroups.
13 /// 14 ///
14 /// A group has a description that is prepended to that of all nested tests and 15 /// A group has a description that is prepended to that of all nested tests and
15 /// subgroups. It also has [setUp] and [tearDown] functions which are scoped to 16 /// subgroups. It also has [setUp] and [tearDown] functions which are scoped to
16 /// the tests and groups it contains. 17 /// the tests and groups it contains.
17 class Group { 18 class Group {
18 /// The parent group, or `null` if this is the root group. 19 /// The parent group, or `null` if this is the root group.
19 final Group parent; 20 final Group parent;
(...skipping 49 matching lines...) Expand 10 before | Expand all | Expand 10 after
69 return new Future.value(); 70 return new Future.value();
70 } 71 }
71 72
72 /// Run the tear-up functions for this and any parent groups. 73 /// Run the tear-up functions for this and any parent groups.
73 /// 74 ///
74 /// If no set-up functions are declared, this returns a [Future] that 75 /// If no set-up functions are declared, this returns a [Future] that
75 /// completes immediately. 76 /// completes immediately.
76 Future runTearDown() { 77 Future runTearDown() {
77 // TODO(nweiz): Use async/await here once issue 23497 has been fixed in two 78 // TODO(nweiz): Use async/await here once issue 23497 has been fixed in two
78 // stable versions. 79 // stable versions.
79 if (parent != null) { 80 if (parent == null) {
80 return new Future.sync(() { 81 return tearDown == null ? new Future.value() : new Future.sync(tearDown);
81 if (tearDown != null) return tearDown();
82 }).then((_) => parent.runTearDown());
83 } 82 }
84 83
85 if (tearDown != null) return new Future.sync(tearDown); 84 return _errorsDontStopTest(() {
86 return new Future.value(); 85 if (tearDown != null) return tearDown();
86 }).then((_) => parent.runTearDown());
87 }
88
89 /// Runs [body] with special error-handling behavior.
kevmoo 2015/09/24 21:07:30 Is the case this addresses already covered in the
nweiz 2015/09/24 21:13:07 Yeah; the test coincidentally passed because of th
90 ///
91 /// Errors emitted [body] will still cause be the test to fail, but they won't
92 /// cause it to *stop*. In particular, they won't remove any outstanding
93 /// callbacks registered outside of [body].
94 Future _errorsDontStopTest(body()) {
95 var completer = new Completer();
96 Invoker.current.waitForOutstandingCallbacks(() {
97 new Future.sync(body).whenComplete(completer.complete);
98 });
99 return completer.future;
87 } 100 }
88 } 101 }
OLDNEW
« no previous file with comments | « CHANGELOG.md ('k') | pubspec.yaml » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698