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.declarer; | 5 library test.backend.declarer; |
6 | 6 |
7 import 'dart:async'; | 7 import 'dart:async'; |
8 | 8 |
9 import '../frontend/timeout.dart'; | 9 import '../frontend/timeout.dart'; |
10 import '../utils.dart'; | 10 import '../utils.dart'; |
(...skipping 55 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
66 | 66 |
67 Declarer._(this._parent, this._name, this._metadata); | 67 Declarer._(this._parent, this._name, this._metadata); |
68 | 68 |
69 /// Runs [body] with this declarer as [Declarer.current]. | 69 /// Runs [body] with this declarer as [Declarer.current]. |
70 /// | 70 /// |
71 /// Returns the return value of [body]. | 71 /// Returns the return value of [body]. |
72 declare(body()) => runZoned(body, zoneValues: {#test.declarer: this}); | 72 declare(body()) => runZoned(body, zoneValues: {#test.declarer: this}); |
73 | 73 |
74 /// Defines a test case with the given name and body. | 74 /// Defines a test case with the given name and body. |
75 void test(String name, body(), {String testOn, Timeout timeout, skip, | 75 void test(String name, body(), {String testOn, Timeout timeout, skip, |
76 Map<String, dynamic> onPlatform, List<String> tags}) { | 76 Map<String, dynamic> onPlatform, tags}) { |
77 _checkNotBuilt("test"); | 77 _checkNotBuilt("test"); |
78 | 78 |
79 var metadata = _metadata.merge(new Metadata.parse( | 79 var metadata = _metadata.merge(new Metadata.parse( |
80 testOn: testOn, timeout: timeout, skip: skip, onPlatform: onPlatform, | 80 testOn: testOn, timeout: timeout, skip: skip, onPlatform: onPlatform, |
81 tags: tags)); | 81 tags: tags)); |
82 | 82 |
83 _entries.add(new LocalTest(_prefix(name), metadata, () { | 83 _entries.add(new LocalTest(_prefix(name), metadata, () { |
84 // TODO(nweiz): It might be useful to throw an error here if a test starts | 84 // TODO(nweiz): It might be useful to throw an error here if a test starts |
85 // running while other tests from the same declarer are also running, | 85 // running while other tests from the same declarer are also running, |
86 // since they might share closurized state. | 86 // since they might share closurized state. |
87 | 87 |
88 // TODO(nweiz): Use async/await here once issue 23497 has been fixed in | 88 // TODO(nweiz): Use async/await here once issue 23497 has been fixed in |
89 // two stable versions. | 89 // two stable versions. |
90 return Invoker.current.waitForOutstandingCallbacks(() { | 90 return Invoker.current.waitForOutstandingCallbacks(() { |
91 return _runSetUps().then((_) => body()); | 91 return _runSetUps().then((_) => body()); |
92 }).then((_) => _runTearDowns()); | 92 }).then((_) => _runTearDowns()); |
93 })); | 93 })); |
94 } | 94 } |
95 | 95 |
96 /// Creates a group of tests. | 96 /// Creates a group of tests. |
97 void group(String name, void body(), {String testOn, Timeout timeout, skip, | 97 void group(String name, void body(), {String testOn, Timeout timeout, skip, |
98 Map<String, dynamic> onPlatform, List<String> tags}) { | 98 Map<String, dynamic> onPlatform, tags}) { |
99 _checkNotBuilt("group"); | 99 _checkNotBuilt("group"); |
100 | 100 |
101 var metadata = _metadata.merge(new Metadata.parse( | 101 var metadata = _metadata.merge(new Metadata.parse( |
102 testOn: testOn, timeout: timeout, skip: skip, onPlatform: onPlatform, | 102 testOn: testOn, timeout: timeout, skip: skip, onPlatform: onPlatform, |
103 tags: tags)); | 103 tags: tags)); |
104 | 104 |
105 // Don't load the tests for a skipped group. | 105 // Don't load the tests for a skipped group. |
106 if (metadata.skip) { | 106 if (metadata.skip) { |
107 _entries.add(new Group(name, [], metadata: metadata)); | 107 _entries.add(new Group(name, [], metadata: metadata)); |
108 return; | 108 return; |
(...skipping 112 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
221 var completer = new Completer(); | 221 var completer = new Completer(); |
222 | 222 |
223 Invoker.current.addOutstandingCallback(); | 223 Invoker.current.addOutstandingCallback(); |
224 Invoker.current.waitForOutstandingCallbacks(() { | 224 Invoker.current.waitForOutstandingCallbacks(() { |
225 new Future.sync(body).whenComplete(completer.complete); | 225 new Future.sync(body).whenComplete(completer.complete); |
226 }).then((_) => Invoker.current.removeOutstandingCallback()); | 226 }).then((_) => Invoker.current.removeOutstandingCallback()); |
227 | 227 |
228 return completer.future; | 228 return completer.future; |
229 } | 229 } |
230 } | 230 } |
OLD | NEW |