| 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 import 'dart:async'; | 5 import 'dart:async'; |
| 6 | 6 |
| 7 import '../frontend/timeout.dart'; | 7 import '../frontend/timeout.dart'; |
| 8 import '../utils.dart'; | 8 import '../utils.dart'; |
| 9 import 'group.dart'; | 9 import 'group.dart'; |
| 10 import 'group_entry.dart'; | 10 import 'group_entry.dart'; |
| (...skipping 60 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 71 | 71 |
| 72 /// Defines a test case with the given name and body. | 72 /// Defines a test case with the given name and body. |
| 73 void test(String name, body(), {String testOn, Timeout timeout, skip, | 73 void test(String name, body(), {String testOn, Timeout timeout, skip, |
| 74 Map<String, dynamic> onPlatform, tags}) { | 74 Map<String, dynamic> onPlatform, tags}) { |
| 75 _checkNotBuilt("test"); | 75 _checkNotBuilt("test"); |
| 76 | 76 |
| 77 var metadata = _metadata.merge(new Metadata.parse( | 77 var metadata = _metadata.merge(new Metadata.parse( |
| 78 testOn: testOn, timeout: timeout, skip: skip, onPlatform: onPlatform, | 78 testOn: testOn, timeout: timeout, skip: skip, onPlatform: onPlatform, |
| 79 tags: tags)); | 79 tags: tags)); |
| 80 | 80 |
| 81 _entries.add(new LocalTest(_prefix(name), metadata, () { | 81 _entries.add(new LocalTest(_prefix(name), metadata, () async { |
| 82 // TODO(nweiz): It might be useful to throw an error here if a test starts | 82 // TODO(nweiz): It might be useful to throw an error here if a test starts |
| 83 // running while other tests from the same declarer are also running, | 83 // running while other tests from the same declarer are also running, |
| 84 // since they might share closurized state. | 84 // since they might share closurized state. |
| 85 | 85 |
| 86 // TODO(nweiz): Use async/await here once issue 23497 has been fixed in | 86 await Invoker.current.waitForOutstandingCallbacks(() async { |
| 87 // two stable versions. | 87 await _runSetUps(); |
| 88 return Invoker.current.waitForOutstandingCallbacks(() { | 88 await body(); |
| 89 return _runSetUps().then((_) => body()); | 89 }); |
| 90 }).then((_) => _runTearDowns()); | 90 await _runTearDowns(); |
| 91 })); | 91 })); |
| 92 } | 92 } |
| 93 | 93 |
| 94 /// Creates a group of tests. | 94 /// Creates a group of tests. |
| 95 void group(String name, void body(), {String testOn, Timeout timeout, skip, | 95 void group(String name, void body(), {String testOn, Timeout timeout, skip, |
| 96 Map<String, dynamic> onPlatform, tags}) { | 96 Map<String, dynamic> onPlatform, tags}) { |
| 97 _checkNotBuilt("group"); | 97 _checkNotBuilt("group"); |
| 98 | 98 |
| 99 var metadata = _metadata.merge(new Metadata.parse( | 99 var metadata = _metadata.merge(new Metadata.parse( |
| 100 testOn: testOn, timeout: timeout, skip: skip, onPlatform: onPlatform, | 100 testOn: testOn, timeout: timeout, skip: skip, onPlatform: onPlatform, |
| (...skipping 53 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 154 /// [name] should be the name of the method being called. | 154 /// [name] should be the name of the method being called. |
| 155 void _checkNotBuilt(String name) { | 155 void _checkNotBuilt(String name) { |
| 156 if (!_built) return; | 156 if (!_built) return; |
| 157 throw new StateError("Can't call $name() once tests have begun running."); | 157 throw new StateError("Can't call $name() once tests have begun running."); |
| 158 } | 158 } |
| 159 | 159 |
| 160 /// Run the set-up functions for this and any parent groups. | 160 /// Run the set-up functions for this and any parent groups. |
| 161 /// | 161 /// |
| 162 /// If no set-up functions are declared, this returns a [Future] that | 162 /// If no set-up functions are declared, this returns a [Future] that |
| 163 /// completes immediately. | 163 /// completes immediately. |
| 164 Future _runSetUps() { | 164 Future _runSetUps() async { |
| 165 // TODO(nweiz): Use async/await here once issue 23497 has been fixed in two | 165 if (_parent != null) await _parent._runSetUps(); |
| 166 // stable versions. | 166 await Future.forEach(_setUps, (setUp) => setUp()); |
| 167 if (_parent != null) { | |
| 168 return _parent._runSetUps().then((_) { | |
| 169 return Future.forEach(_setUps, (setUp) => setUp()); | |
| 170 }); | |
| 171 } | |
| 172 | |
| 173 return Future.forEach(_setUps, (setUp) => setUp()); | |
| 174 } | 167 } |
| 175 | 168 |
| 176 /// Run the tear-up functions for this and any parent groups. | 169 /// Run the tear-up functions for this and any parent groups. |
| 177 /// | 170 /// |
| 178 /// If no set-up functions are declared, this returns a [Future] that | 171 /// If no set-up functions are declared, this returns a [Future] that |
| 179 /// completes immediately. | 172 /// completes immediately. |
| 180 /// | 173 /// |
| 181 /// This should only be called within a test. | 174 /// This should only be called within a test. |
| 182 Future _runTearDowns() { | 175 Future _runTearDowns() { |
| 183 return Invoker.current.unclosable(() { | 176 return Invoker.current.unclosable(() { |
| (...skipping 35 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 219 var completer = new Completer(); | 212 var completer = new Completer(); |
| 220 | 213 |
| 221 Invoker.current.addOutstandingCallback(); | 214 Invoker.current.addOutstandingCallback(); |
| 222 Invoker.current.waitForOutstandingCallbacks(() { | 215 Invoker.current.waitForOutstandingCallbacks(() { |
| 223 new Future.sync(body).whenComplete(completer.complete); | 216 new Future.sync(body).whenComplete(completer.complete); |
| 224 }).then((_) => Invoker.current.removeOutstandingCallback()); | 217 }).then((_) => Invoker.current.removeOutstandingCallback()); |
| 225 | 218 |
| 226 return completer.future; | 219 return completer.future; |
| 227 } | 220 } |
| 228 } | 221 } |
| OLD | NEW |