OLD | NEW |
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 'invoker.dart'; |
(...skipping 56 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
67 } | 67 } |
68 | 68 |
69 return Future.forEach(setUps, (setUp) => setUp()); | 69 return Future.forEach(setUps, (setUp) => setUp()); |
70 } | 70 } |
71 | 71 |
72 /// Run the tear-up functions for this and any parent groups. | 72 /// Run the tear-up functions for this and any parent groups. |
73 /// | 73 /// |
74 /// If no set-up functions are declared, this returns a [Future] that | 74 /// If no set-up functions are declared, this returns a [Future] that |
75 /// completes immediately. | 75 /// completes immediately. |
76 Future runTearDowns() { | 76 Future runTearDowns() { |
77 // TODO(nweiz): Use async/await here once issue 23497 has been fixed in two | 77 return Invoker.current.unclosable(() { |
78 // stable versions. | 78 var tearDowns = []; |
79 if (parent == null) { | 79 for (var group = this; group != null; group = group.parent) { |
80 return Future.forEach(tearDowns.reversed, _errorsDontStopTest); | 80 tearDowns.addAll(group.tearDowns.reversed); |
81 } | 81 } |
82 | 82 |
83 return Future.forEach(tearDowns.reversed, _errorsDontStopTest) | 83 return Future.forEach(tearDowns, _errorsDontStopTest); |
84 .then((_) => parent.runTearDowns()); | 84 }); |
85 } | 85 } |
86 | 86 |
87 /// Runs [body] with special error-handling behavior. | 87 /// Runs [body] with special error-handling behavior. |
88 /// | 88 /// |
89 /// Errors emitted [body] will still cause be the test to fail, but they won't | 89 /// Errors emitted [body] will still cause be the test to fail, but they won't |
90 /// cause it to *stop*. In particular, they won't remove any outstanding | 90 /// cause it to *stop*. In particular, they won't remove any outstanding |
91 /// callbacks registered outside of [body]. | 91 /// callbacks registered outside of [body]. |
92 Future _errorsDontStopTest(body()) { | 92 Future _errorsDontStopTest(body()) { |
93 var completer = new Completer(); | 93 var completer = new Completer(); |
94 | 94 |
95 Invoker.current.addOutstandingCallback(); | 95 Invoker.current.addOutstandingCallback(); |
96 Invoker.current.waitForOutstandingCallbacks(() { | 96 Invoker.current.waitForOutstandingCallbacks(() { |
97 new Future.sync(body).whenComplete(completer.complete); | 97 new Future.sync(body).whenComplete(completer.complete); |
98 }).then((_) => Invoker.current.removeOutstandingCallback()); | 98 }).then((_) => Invoker.current.removeOutstandingCallback()); |
99 | 99 |
100 return completer.future; | 100 return completer.future; |
101 } | 101 } |
102 } | 102 } |
OLD | NEW |