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}) { | 76 Map<String, dynamic> onPlatform, List<String> 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 | 82 |
82 _entries.add(new LocalTest(_prefix(name), metadata, () { | 83 _entries.add(new LocalTest(_prefix(name), metadata, () { |
83 // 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 |
84 // running while other tests from the same declarer are also running, | 85 // running while other tests from the same declarer are also running, |
85 // since they might share closurized state. | 86 // since they might share closurized state. |
86 | 87 |
87 // 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 |
88 // two stable versions. | 89 // two stable versions. |
89 return Invoker.current.waitForOutstandingCallbacks(() { | 90 return Invoker.current.waitForOutstandingCallbacks(() { |
90 return _runSetUps().then((_) => body()); | 91 return _runSetUps().then((_) => body()); |
91 }).then((_) => _runTearDowns()); | 92 }).then((_) => _runTearDowns()); |
92 })); | 93 })); |
93 } | 94 } |
94 | 95 |
95 /// Creates a group of tests. | 96 /// Creates a group of tests. |
96 void group(String name, void body(), {String testOn, Timeout timeout, skip, | 97 void group(String name, void body(), {String testOn, Timeout timeout, skip, |
97 Map<String, dynamic> onPlatform}) { | 98 Map<String, dynamic> onPlatform, List<String> tags}) { |
98 _checkNotBuilt("group"); | 99 _checkNotBuilt("group"); |
99 | 100 |
100 var metadata = _metadata.merge(new Metadata.parse( | 101 var metadata = _metadata.merge(new Metadata.parse( |
101 testOn: testOn, timeout: timeout, skip: skip, onPlatform: onPlatform)); | 102 testOn: testOn, timeout: timeout, skip: skip, onPlatform: onPlatform, |
| 103 tags: tags)); |
102 | 104 |
103 // Don't load the tests for a skipped group. | 105 // Don't load the tests for a skipped group. |
104 if (metadata.skip) { | 106 if (metadata.skip) { |
105 _entries.add(new Group(name, [], metadata: metadata)); | 107 _entries.add(new Group(name, [], metadata: metadata)); |
106 return; | 108 return; |
107 } | 109 } |
108 | 110 |
109 var declarer = new Declarer._(this, _prefix(name), metadata); | 111 var declarer = new Declarer._(this, _prefix(name), metadata); |
110 declarer.declare(body); | 112 declarer.declare(body); |
111 _entries.add(declarer.build()); | 113 _entries.add(declarer.build()); |
(...skipping 107 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
219 var completer = new Completer(); | 221 var completer = new Completer(); |
220 | 222 |
221 Invoker.current.addOutstandingCallback(); | 223 Invoker.current.addOutstandingCallback(); |
222 Invoker.current.waitForOutstandingCallbacks(() { | 224 Invoker.current.waitForOutstandingCallbacks(() { |
223 new Future.sync(body).whenComplete(completer.complete); | 225 new Future.sync(body).whenComplete(completer.complete); |
224 }).then((_) => Invoker.current.removeOutstandingCallback()); | 226 }).then((_) => Invoker.current.removeOutstandingCallback()); |
225 | 227 |
226 return completer.future; | 228 return completer.future; |
227 } | 229 } |
228 } | 230 } |
OLD | NEW |