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

Side by Side Diff: test/backend/declarer_test.dart

Issue 1379203002: Refactor groups to pipe them through to the runner. (Closed) Base URL: git@github.com:dart-lang/test@master
Patch Set: Code review changes Created 5 years, 2 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 | « lib/test.dart ('k') | test/runner/browser/loader_test.dart » ('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 import 'dart:async'; 5 import 'dart:async';
6 6
7 import 'package:test/src/backend/declarer.dart'; 7 import 'package:test/src/backend/declarer.dart';
8 import 'package:test/src/backend/group.dart';
8 import 'package:test/src/backend/invoker.dart'; 9 import 'package:test/src/backend/invoker.dart';
9 import 'package:test/src/backend/suite.dart'; 10 import 'package:test/src/backend/suite.dart';
11 import 'package:test/src/backend/test.dart';
10 import 'package:test/src/frontend/timeout.dart'; 12 import 'package:test/src/frontend/timeout.dart';
11 import 'package:test/test.dart'; 13 import 'package:test/test.dart';
12 14
13 import '../utils.dart'; 15 import '../utils.dart';
14 16
15 Declarer _declarer;
16 Suite _suite; 17 Suite _suite;
17 18
18 void main() { 19 void main() {
19 setUp(() { 20 setUp(() {
20 _declarer = new Declarer();
21 _suite = new Suite([]); 21 _suite = new Suite([]);
22 }); 22 });
23 23
24 group(".test()", () { 24 group(".test()", () {
25 test("declares a test with a description and body", () async { 25 test("declares a test with a description and body", () async {
26 var bodyRun = false; 26 var bodyRun = false;
27 _declarer.test("description", () { 27 var tests = declare(() {
28 bodyRun = true; 28 test("description", () {
29 }); 29 bodyRun = true;
30 30 });
31 expect(_declarer.tests, hasLength(1)); 31 });
32 expect(_declarer.tests.single.name, equals("description")); 32
33 33 expect(tests, hasLength(1));
34 await _runTest(0); 34 expect(tests.single.name, equals("description"));
35
36 await _runTest(tests[0]);
35 expect(bodyRun, isTrue); 37 expect(bodyRun, isTrue);
36 }); 38 });
37 39
38 test("declares multiple tests", () { 40 test("declares multiple tests", () {
39 _declarer.test("description 1", () {}); 41 var tests = declare(() {
40 _declarer.test("description 2", () {}); 42 test("description 1", () {});
41 _declarer.test("description 3", () {}); 43 test("description 2", () {});
42 44 test("description 3", () {});
43 expect(_declarer.tests, hasLength(3)); 45 });
44 expect(_declarer.tests[0].name, equals("description 1")); 46
45 expect(_declarer.tests[1].name, equals("description 2")); 47 expect(tests, hasLength(3));
46 expect(_declarer.tests[2].name, equals("description 3")); 48 expect(tests[0].name, equals("description 1"));
49 expect(tests[1].name, equals("description 2"));
50 expect(tests[2].name, equals("description 3"));
47 }); 51 });
48 }); 52 });
49 53
50 group(".setUp()", () { 54 group(".setUp()", () {
51 test("is run before all tests", () async { 55 test("is run before all tests", () async {
52 var setUpRun = false; 56 var setUpRun = false;
53 _declarer.setUp(() => setUpRun = true); 57 var tests = declare(() {
54 58 setUp(() => setUpRun = true);
55 _declarer.test("description 1", expectAsync(() { 59
56 expect(setUpRun, isTrue); 60 test("description 1", expectAsync(() {
57 setUpRun = false; 61 expect(setUpRun, isTrue);
58 }, max: 1)); 62 setUpRun = false;
59 63 }, max: 1));
60 _declarer.test("description 2", expectAsync(() { 64
61 expect(setUpRun, isTrue); 65 test("description 2", expectAsync(() {
62 setUpRun = false; 66 expect(setUpRun, isTrue);
63 }, max: 1)); 67 setUpRun = false;
64 68 }, max: 1));
65 await _runTest(0); 69 });
66 await _runTest(1); 70
71 await _runTest(tests[0]);
72 await _runTest(tests[1]);
67 }); 73 });
68 74
69 test("can return a Future", () { 75 test("can return a Future", () {
70 var setUpRun = false; 76 var setUpRun = false;
71 _declarer.setUp(() { 77 var tests = declare(() {
72 return new Future(() => setUpRun = true); 78 setUp(() {
73 }); 79 return new Future(() => setUpRun = true);
74 80 });
75 _declarer.test("description", expectAsync(() { 81
76 expect(setUpRun, isTrue); 82 test("description", expectAsync(() {
77 }, max: 1)); 83 expect(setUpRun, isTrue);
78 84 }, max: 1));
79 return _runTest(0); 85 });
86
87 return _runTest(tests.single);
80 }); 88 });
81 89
82 test("runs in call order within a group", () async { 90 test("runs in call order within a group", () async {
83 var firstSetUpRun = false; 91 var firstSetUpRun = false;
84 var secondSetUpRun = false; 92 var secondSetUpRun = false;
85 var thirdSetUpRun = false; 93 var thirdSetUpRun = false;
86 _declarer.setUp(expectAsync(() async { 94 var tests = declare(() {
87 expect(secondSetUpRun, isFalse); 95 setUp(expectAsync(() async {
88 expect(thirdSetUpRun, isFalse); 96 expect(secondSetUpRun, isFalse);
89 firstSetUpRun = true; 97 expect(thirdSetUpRun, isFalse);
90 })); 98 firstSetUpRun = true;
91 99 }));
92 _declarer.setUp(expectAsync(() async { 100
93 expect(firstSetUpRun, isTrue); 101 setUp(expectAsync(() async {
94 expect(thirdSetUpRun, isFalse); 102 expect(firstSetUpRun, isTrue);
95 secondSetUpRun = true; 103 expect(thirdSetUpRun, isFalse);
96 })); 104 secondSetUpRun = true;
97 105 }));
98 _declarer.setUp(expectAsync(() async { 106
99 expect(firstSetUpRun, isTrue); 107 setUp(expectAsync(() async {
100 expect(secondSetUpRun, isTrue); 108 expect(firstSetUpRun, isTrue);
101 thirdSetUpRun = true; 109 expect(secondSetUpRun, isTrue);
102 })); 110 thirdSetUpRun = true;
103 111 }));
104 _declarer.test("description", expectAsync(() { 112
105 expect(firstSetUpRun, isTrue); 113 test("description", expectAsync(() {
106 expect(secondSetUpRun, isTrue); 114 expect(firstSetUpRun, isTrue);
107 expect(thirdSetUpRun, isTrue); 115 expect(secondSetUpRun, isTrue);
108 })); 116 expect(thirdSetUpRun, isTrue);
109 117 }));
110 await _runTest(0); 118 });
119
120 await _runTest(tests.single);
111 }); 121 });
112 }); 122 });
113 123
114 group(".tearDown()", () { 124 group(".tearDown()", () {
115 test("is run after all tests", () async { 125 test("is run after all tests", () async {
116 var tearDownRun; 126 var tearDownRun;
117 _declarer.setUp(() => tearDownRun = false); 127 var tests = declare(() {
118 _declarer.tearDown(() => tearDownRun = true); 128 setUp(() => tearDownRun = false);
119 129 tearDown(() => tearDownRun = true);
120 _declarer.test("description 1", expectAsync(() { 130
121 expect(tearDownRun, isFalse); 131 test("description 1", expectAsync(() {
122 }, max: 1)); 132 expect(tearDownRun, isFalse);
123 133 }, max: 1));
124 _declarer.test("description 2", expectAsync(() { 134
125 expect(tearDownRun, isFalse); 135 test("description 2", expectAsync(() {
126 }, max: 1)); 136 expect(tearDownRun, isFalse);
127 137 }, max: 1));
128 await _runTest(0); 138 });
129 expect(tearDownRun, isTrue); 139
130 await _runTest(1); 140 await _runTest(tests[0]);
141 expect(tearDownRun, isTrue);
142 await _runTest(tests[1]);
131 expect(tearDownRun, isTrue); 143 expect(tearDownRun, isTrue);
132 }); 144 });
133 145
134 test("is run after an out-of-band failure", () async { 146 test("is run after an out-of-band failure", () async {
135 var tearDownRun; 147 var tearDownRun;
136 _declarer.setUp(() => tearDownRun = false); 148 var tests = declare(() {
137 _declarer.tearDown(() => tearDownRun = true); 149 setUp(() => tearDownRun = false);
138 150 tearDown(() => tearDownRun = true);
139 _declarer.test("description 1", expectAsync(() { 151
140 Invoker.current.addOutstandingCallback(); 152 test("description 1", expectAsync(() {
141 new Future(() => throw new TestFailure("oh no")); 153 Invoker.current.addOutstandingCallback();
142 }, max: 1)); 154 new Future(() => throw new TestFailure("oh no"));
143 155 }, max: 1));
144 await _runTest(0, shouldFail: true); 156 });
157
158 await _runTest(tests.single, shouldFail: true);
145 expect(tearDownRun, isTrue); 159 expect(tearDownRun, isTrue);
146 }); 160 });
147 161
148 test("can return a Future", () async { 162 test("can return a Future", () async {
149 var tearDownRun = false; 163 var tearDownRun = false;
150 _declarer.tearDown(() { 164 var tests = declare(() {
151 return new Future(() => tearDownRun = true); 165 tearDown(() {
152 }); 166 return new Future(() => tearDownRun = true);
153 167 });
154 _declarer.test("description", expectAsync(() { 168
155 expect(tearDownRun, isFalse); 169 test("description", expectAsync(() {
156 }, max: 1)); 170 expect(tearDownRun, isFalse);
157 171 }, max: 1));
158 await _runTest(0); 172 });
173
174 await _runTest(tests.single);
159 expect(tearDownRun, isTrue); 175 expect(tearDownRun, isTrue);
160 }); 176 });
161 177
162 test("isn't run until there are no outstanding callbacks", () async { 178 test("isn't run until there are no outstanding callbacks", () async {
163 var outstandingCallbackRemoved = false; 179 var outstandingCallbackRemoved = false;
164 var outstandingCallbackRemovedBeforeTeardown = false; 180 var outstandingCallbackRemovedBeforeTeardown = false;
165 _declarer.tearDown(() { 181 var tests = declare(() {
166 outstandingCallbackRemovedBeforeTeardown = outstandingCallbackRemoved; 182 tearDown(() {
167 }); 183 outstandingCallbackRemovedBeforeTeardown = outstandingCallbackRemoved;
168 184 });
169 _declarer.test("description", () { 185
170 Invoker.current.addOutstandingCallback(); 186 test("description", () {
171 pumpEventQueue().then((_) { 187 Invoker.current.addOutstandingCallback();
172 outstandingCallbackRemoved = true; 188 pumpEventQueue().then((_) {
173 Invoker.current.removeOutstandingCallback(); 189 outstandingCallbackRemoved = true;
174 }); 190 Invoker.current.removeOutstandingCallback();
175 }); 191 });
176 192 });
177 await _runTest(0); 193 });
194
195 await _runTest(tests.single);
178 expect(outstandingCallbackRemovedBeforeTeardown, isTrue); 196 expect(outstandingCallbackRemovedBeforeTeardown, isTrue);
179 }); 197 });
180 198
181 test("doesn't complete until there are no outstanding callbacks", () async { 199 test("doesn't complete until there are no outstanding callbacks", () async {
182 var outstandingCallbackRemoved = false; 200 var outstandingCallbackRemoved = false;
183 _declarer.tearDown(() { 201 var tests = declare(() {
184 Invoker.current.addOutstandingCallback(); 202 tearDown(() {
185 pumpEventQueue().then((_) { 203 Invoker.current.addOutstandingCallback();
186 outstandingCallbackRemoved = true; 204 pumpEventQueue().then((_) {
187 Invoker.current.removeOutstandingCallback(); 205 outstandingCallbackRemoved = true;
188 }); 206 Invoker.current.removeOutstandingCallback();
189 }); 207 });
190 208 });
191 _declarer.test("description", () {}); 209
192 210 test("description", () {});
193 await _runTest(0); 211 });
212
213 await _runTest(tests.single);
194 expect(outstandingCallbackRemoved, isTrue); 214 expect(outstandingCallbackRemoved, isTrue);
195 }); 215 });
196 216
197 test("runs in reverse call order within a group", () async { 217 test("runs in reverse call order within a group", () async {
198 var firstTearDownRun = false; 218 var firstTearDownRun = false;
199 var secondTearDownRun = false; 219 var secondTearDownRun = false;
200 var thirdTearDownRun = false; 220 var thirdTearDownRun = false;
201 _declarer.tearDown(expectAsync(() async { 221 var tests = declare(() {
202 expect(secondTearDownRun, isTrue); 222 tearDown(expectAsync(() async {
203 expect(thirdTearDownRun, isTrue); 223 expect(secondTearDownRun, isTrue);
204 firstTearDownRun = true; 224 expect(thirdTearDownRun, isTrue);
205 })); 225 firstTearDownRun = true;
206 226 }));
207 _declarer.tearDown(expectAsync(() async { 227
208 expect(firstTearDownRun, isFalse); 228 tearDown(expectAsync(() async {
209 expect(thirdTearDownRun, isTrue); 229 expect(firstTearDownRun, isFalse);
210 secondTearDownRun = true; 230 expect(thirdTearDownRun, isTrue);
211 })); 231 secondTearDownRun = true;
212 232 }));
213 _declarer.tearDown(expectAsync(() async { 233
214 expect(firstTearDownRun, isFalse); 234 tearDown(expectAsync(() async {
215 expect(secondTearDownRun, isFalse); 235 expect(firstTearDownRun, isFalse);
216 thirdTearDownRun = true; 236 expect(secondTearDownRun, isFalse);
217 })); 237 thirdTearDownRun = true;
218 238 }));
219 _declarer.test("description", expectAsync(() { 239
220 expect(firstTearDownRun, isFalse); 240 test("description", expectAsync(() {
221 expect(secondTearDownRun, isFalse); 241 expect(firstTearDownRun, isFalse);
222 expect(thirdTearDownRun, isFalse); 242 expect(secondTearDownRun, isFalse);
223 }, max: 1)); 243 expect(thirdTearDownRun, isFalse);
224 244 }, max: 1));
225 await _runTest(0); 245 });
246
247 await _runTest(tests.single);
226 }); 248 });
227 249
228 test("runs further tearDowns in a group even if one fails", () async { 250 test("runs further tearDowns in a group even if one fails", () async {
229 _declarer.tearDown(expectAsync(() {})); 251 var tests = declare(() {
230 252 tearDown(expectAsync(() {}));
231 _declarer.tearDown(() async { 253
232 throw 'error'; 254 tearDown(() async {
233 }); 255 throw 'error';
234 256 });
235 _declarer.test("description", expectAsync(() {})); 257
236 258 test("description", expectAsync(() {}));
237 await _runTest(0, shouldFail: true); 259 });
260
261 await _runTest(tests.single, shouldFail: true);
238 }); 262 });
239 }); 263 });
240 264
241 group("in a group,", () { 265 group("in a group,", () {
242 test("tests inherit the group's description", () { 266 test("tests inherit the group's description", () {
243 _declarer.group("group", () { 267 var entries = declare(() {
244 _declarer.test("description", () {}); 268 group("group", () {
245 }); 269 test("description", () {});
246 270 });
247 expect(_declarer.tests, hasLength(1)); 271 });
248 expect(_declarer.tests.single.name, "group description"); 272
273 expect(entries, hasLength(1));
274 expect(entries.single, new isInstanceOf<Group>());
275 expect(entries.single.name, equals("group"));
276 expect(entries.single.entries, hasLength(1));
277 expect(entries.single.entries.single, new isInstanceOf<Test>());
278 expect(entries.single.entries.single.name, "group description");
249 }); 279 });
250 280
251 test("a test's timeout factor is applied to the group's", () { 281 test("a test's timeout factor is applied to the group's", () {
252 _declarer.group("group", () { 282 var entries = declare(() {
253 _declarer.test("test", () {}, 283 group("group", () {
254 timeout: new Timeout.factor(3)); 284 test("test", () {},
255 }, timeout: new Timeout.factor(2)); 285 timeout: new Timeout.factor(3));
256 286 }, timeout: new Timeout.factor(2));
257 expect(_declarer.tests, hasLength(1)); 287 });
258 expect(_declarer.tests.single.metadata.timeout.scaleFactor, equals(6)); 288
289 expect(entries, hasLength(1));
290 expect(entries.single, new isInstanceOf<Group>());
291 expect(entries.single.metadata.timeout.scaleFactor, equals(2));
292 expect(entries.single.entries, hasLength(1));
293 expect(entries.single.entries.single, new isInstanceOf<Test>());
294 expect(entries.single.entries.single.metadata.timeout.scaleFactor,
295 equals(6));
259 }); 296 });
260 297
261 test("a test's timeout factor is applied to the group's duration", () { 298 test("a test's timeout factor is applied to the group's duration", () {
262 _declarer.group("group", () { 299 var entries = declare(() {
263 _declarer.test("test", () {}, 300 group("group", () {
264 timeout: new Timeout.factor(2)); 301 test("test", () {},
265 }, timeout: new Timeout(new Duration(seconds: 10))); 302 timeout: new Timeout.factor(2));
266 303 }, timeout: new Timeout(new Duration(seconds: 10)));
267 expect(_declarer.tests, hasLength(1)); 304 });
268 expect(_declarer.tests.single.metadata.timeout.duration, 305
306 expect(entries, hasLength(1));
307 expect(entries.single, new isInstanceOf<Group>());
308 expect(entries.single.metadata.timeout.duration,
309 equals(new Duration(seconds: 10)));
310 expect(entries.single.entries, hasLength(1));
311 expect(entries.single.entries.single, new isInstanceOf<Test>());
312 expect(entries.single.entries.single.metadata.timeout.duration,
269 equals(new Duration(seconds: 20))); 313 equals(new Duration(seconds: 20)));
270 }); 314 });
271 315
272 test("a test's timeout duration is applied over the group's", () { 316 test("a test's timeout duration is applied over the group's", () {
273 _declarer.group("group", () { 317 var entries = declare(() {
274 _declarer.test("test", () {}, 318 group("group", () {
275 timeout: new Timeout(new Duration(seconds: 15))); 319 test("test", () {},
276 }, timeout: new Timeout(new Duration(seconds: 10))); 320 timeout: new Timeout(new Duration(seconds: 15)));
277 321 }, timeout: new Timeout(new Duration(seconds: 10)));
278 expect(_declarer.tests, hasLength(1)); 322 });
279 expect(_declarer.tests.single.metadata.timeout.duration, 323
324 expect(entries, hasLength(1));
325 expect(entries.single, new isInstanceOf<Group>());
326 expect(entries.single.metadata.timeout.duration,
327 equals(new Duration(seconds: 10)));
328 expect(entries.single.entries, hasLength(1));
329 expect(entries.single.entries.single, new isInstanceOf<Test>());
330 expect(entries.single.entries.single.metadata.timeout.duration,
280 equals(new Duration(seconds: 15))); 331 equals(new Duration(seconds: 15)));
281 }); 332 });
282 333
283 group(".setUp()", () { 334 group(".setUp()", () {
284 test("is scoped to the group", () async { 335 test("is scoped to the group", () async {
285 var setUpRun = false; 336 var setUpRun = false;
286 _declarer.group("group", () { 337 var entries = declare(() {
287 _declarer.setUp(() => setUpRun = true); 338 group("group", () {
288 339 setUp(() => setUpRun = true);
289 _declarer.test("description 1", expectAsync(() { 340
290 expect(setUpRun, isTrue); 341 test("description 1", expectAsync(() {
342 expect(setUpRun, isTrue);
343 setUpRun = false;
344 }, max: 1));
345 });
346
347 test("description 2", expectAsync(() {
348 expect(setUpRun, isFalse);
291 setUpRun = false; 349 setUpRun = false;
292 }, max: 1)); 350 }, max: 1));
293 }); 351 });
294 352
295 _declarer.test("description 2", expectAsync(() { 353 await _runTest(entries[0].entries.single);
296 expect(setUpRun, isFalse); 354 await _runTest(entries[1]);
297 setUpRun = false;
298 }, max: 1));
299
300 await _runTest(0);
301 await _runTest(1);
302 }); 355 });
303 356
304 test("runs from the outside in", () { 357 test("runs from the outside in", () {
305 var outerSetUpRun = false; 358 var outerSetUpRun = false;
306 var middleSetUpRun = false; 359 var middleSetUpRun = false;
307 var innerSetUpRun = false; 360 var innerSetUpRun = false;
308 _declarer.setUp(expectAsync(() { 361 var entries = declare(() {
309 expect(middleSetUpRun, isFalse); 362 setUp(expectAsync(() {
310 expect(innerSetUpRun, isFalse); 363 expect(middleSetUpRun, isFalse);
311 outerSetUpRun = true;
312 }, max: 1));
313
314 _declarer.group("middle", () {
315 _declarer.setUp(expectAsync(() {
316 expect(outerSetUpRun, isTrue);
317 expect(innerSetUpRun, isFalse); 364 expect(innerSetUpRun, isFalse);
318 middleSetUpRun = true; 365 outerSetUpRun = true;
319 }, max: 1)); 366 }, max: 1));
320 367
321 _declarer.group("inner", () { 368 group("middle", () {
322 _declarer.setUp(expectAsync(() { 369 setUp(expectAsync(() {
323 expect(outerSetUpRun, isTrue); 370 expect(outerSetUpRun, isTrue);
324 expect(middleSetUpRun, isTrue); 371 expect(innerSetUpRun, isFalse);
325 innerSetUpRun = true; 372 middleSetUpRun = true;
326 }, max: 1)); 373 }, max: 1));
327 374
328 _declarer.test("description", expectAsync(() { 375 group("inner", () {
329 expect(outerSetUpRun, isTrue); 376 setUp(expectAsync(() {
330 expect(middleSetUpRun, isTrue); 377 expect(outerSetUpRun, isTrue);
331 expect(innerSetUpRun, isTrue); 378 expect(middleSetUpRun, isTrue);
332 }, max: 1)); 379 innerSetUpRun = true;
333 }); 380 }, max: 1));
334 }); 381
335 382 test("description", expectAsync(() {
336 return _runTest(0); 383 expect(outerSetUpRun, isTrue);
384 expect(middleSetUpRun, isTrue);
385 expect(innerSetUpRun, isTrue);
386 }, max: 1));
387 });
388 });
389 });
390
391 return _runTest(entries.single.entries.single.entries.single);
337 }); 392 });
338 393
339 test("handles Futures when chained", () { 394 test("handles Futures when chained", () {
340 var outerSetUpRun = false; 395 var outerSetUpRun = false;
341 var innerSetUpRun = false; 396 var innerSetUpRun = false;
342 _declarer.setUp(expectAsync(() { 397 var entries = declare(() {
343 expect(innerSetUpRun, isFalse); 398 setUp(expectAsync(() {
344 return new Future(() => outerSetUpRun = true); 399 expect(innerSetUpRun, isFalse);
345 }, max: 1)); 400 return new Future(() => outerSetUpRun = true);
346 401 }, max: 1));
347 _declarer.group("inner", () { 402
348 _declarer.setUp(expectAsync(() { 403 group("inner", () {
349 expect(outerSetUpRun, isTrue); 404 setUp(expectAsync(() {
350 return new Future(() => innerSetUpRun = true); 405 expect(outerSetUpRun, isTrue);
351 }, max: 1)); 406 return new Future(() => innerSetUpRun = true);
352 407 }, max: 1));
353 _declarer.test("description", expectAsync(() { 408
354 expect(outerSetUpRun, isTrue); 409 test("description", expectAsync(() {
355 expect(innerSetUpRun, isTrue); 410 expect(outerSetUpRun, isTrue);
356 }, max: 1)); 411 expect(innerSetUpRun, isTrue);
357 }); 412 }, max: 1));
358 413 });
359 return _runTest(0); 414 });
415
416 return _runTest(entries.single.entries.single);
360 }); 417 });
361 }); 418 });
362 419
363 group(".tearDown()", () { 420 group(".tearDown()", () {
364 test("is scoped to the group", () async { 421 test("is scoped to the group", () async {
365 var tearDownRun; 422 var tearDownRun;
366 _declarer.setUp(() => tearDownRun = false); 423 var entries = declare(() {
367 424 setUp(() => tearDownRun = false);
368 _declarer.group("group", () { 425
369 _declarer.tearDown(() => tearDownRun = true); 426 group("group", () {
370 427 tearDown(() => tearDownRun = true);
371 _declarer.test("description 1", expectAsync(() { 428
429 test("description 1", expectAsync(() {
430 expect(tearDownRun, isFalse);
431 }, max: 1));
432 });
433
434 test("description 2", expectAsync(() {
372 expect(tearDownRun, isFalse); 435 expect(tearDownRun, isFalse);
373 }, max: 1)); 436 }, max: 1));
374 }); 437 });
375 438
376 _declarer.test("description 2", expectAsync(() { 439 await _runTest(entries[0].entries.single);
377 expect(tearDownRun, isFalse);
378 }, max: 1));
379
380 await _runTest(0);
381 expect(tearDownRun, isTrue); 440 expect(tearDownRun, isTrue);
382 await _runTest(1); 441 await _runTest(entries[1]);
383 expect(tearDownRun, isFalse); 442 expect(tearDownRun, isFalse);
384 }); 443 });
385 444
386 test("runs from the inside out", () async { 445 test("runs from the inside out", () async {
387 var innerTearDownRun = false; 446 var innerTearDownRun = false;
388 var middleTearDownRun = false; 447 var middleTearDownRun = false;
389 var outerTearDownRun = false; 448 var outerTearDownRun = false;
390 _declarer.tearDown(expectAsync(() { 449 var entries = declare(() {
391 expect(innerTearDownRun, isTrue); 450 tearDown(expectAsync(() {
392 expect(middleTearDownRun, isTrue);
393 outerTearDownRun = true;
394 }, max: 1));
395
396 _declarer.group("middle", () {
397 _declarer.tearDown(expectAsync(() {
398 expect(innerTearDownRun, isTrue); 451 expect(innerTearDownRun, isTrue);
399 expect(outerTearDownRun, isFalse); 452 expect(middleTearDownRun, isTrue);
400 middleTearDownRun = true; 453 outerTearDownRun = true;
401 }, max: 1)); 454 }, max: 1));
402 455
403 _declarer.group("inner", () { 456 group("middle", () {
404 _declarer.tearDown(expectAsync(() { 457 tearDown(expectAsync(() {
458 expect(innerTearDownRun, isTrue);
405 expect(outerTearDownRun, isFalse); 459 expect(outerTearDownRun, isFalse);
406 expect(middleTearDownRun, isFalse); 460 middleTearDownRun = true;
407 innerTearDownRun = true;
408 }, max: 1)); 461 }, max: 1));
409 462
410 _declarer.test("description", expectAsync(() { 463 group("inner", () {
411 expect(outerTearDownRun, isFalse); 464 tearDown(expectAsync(() {
412 expect(middleTearDownRun, isFalse); 465 expect(outerTearDownRun, isFalse);
413 expect(innerTearDownRun, isFalse); 466 expect(middleTearDownRun, isFalse);
414 }, max: 1)); 467 innerTearDownRun = true;
468 }, max: 1));
469
470 test("description", expectAsync(() {
471 expect(outerTearDownRun, isFalse);
472 expect(middleTearDownRun, isFalse);
473 expect(innerTearDownRun, isFalse);
474 }, max: 1));
475 });
415 }); 476 });
416 }); 477 });
417 478
418 await _runTest(0); 479 await _runTest(entries.single.entries.single.entries.single);
419 expect(innerTearDownRun, isTrue); 480 expect(innerTearDownRun, isTrue);
420 expect(middleTearDownRun, isTrue); 481 expect(middleTearDownRun, isTrue);
421 expect(outerTearDownRun, isTrue); 482 expect(outerTearDownRun, isTrue);
422 }); 483 });
423 484
424 test("handles Futures when chained", () async { 485 test("handles Futures when chained", () async {
425 var outerTearDownRun = false; 486 var outerTearDownRun = false;
426 var innerTearDownRun = false; 487 var innerTearDownRun = false;
427 _declarer.tearDown(expectAsync(() { 488 var entries = declare(() {
428 expect(innerTearDownRun, isTrue); 489 tearDown(expectAsync(() {
429 return new Future(() => outerTearDownRun = true); 490 expect(innerTearDownRun, isTrue);
430 }, max: 1)); 491 return new Future(() => outerTearDownRun = true);
431
432 _declarer.group("inner", () {
433 _declarer.tearDown(expectAsync(() {
434 expect(outerTearDownRun, isFalse);
435 return new Future(() => innerTearDownRun = true);
436 }, max: 1)); 492 }, max: 1));
437 493
438 _declarer.test("description", expectAsync(() { 494 group("inner", () {
439 expect(outerTearDownRun, isFalse); 495 tearDown(expectAsync(() {
440 expect(innerTearDownRun, isFalse); 496 expect(outerTearDownRun, isFalse);
441 }, max: 1)); 497 return new Future(() => innerTearDownRun = true);
498 }, max: 1));
499
500 test("description", expectAsync(() {
501 expect(outerTearDownRun, isFalse);
502 expect(innerTearDownRun, isFalse);
503 }, max: 1));
504 });
442 }); 505 });
443 506
444 await _runTest(0); 507 await _runTest(entries.single.entries.single);
445 expect(innerTearDownRun, isTrue); 508 expect(innerTearDownRun, isTrue);
446 expect(outerTearDownRun, isTrue); 509 expect(outerTearDownRun, isTrue);
447 }); 510 });
448 511
449 test("runs outer callbacks even when inner ones fail", () async { 512 test("runs outer callbacks even when inner ones fail", () async {
450 var outerTearDownRun = false; 513 var outerTearDownRun = false;
451 _declarer.tearDown(() { 514 var entries = declare(() {
452 return new Future(() => outerTearDownRun = true); 515 tearDown(() {
516 return new Future(() => outerTearDownRun = true);
517 });
518
519 group("inner", () {
520 tearDown(() {
521 throw 'inner error';
522 });
523
524 test("description", expectAsync(() {
525 expect(outerTearDownRun, isFalse);
526 }, max: 1));
527 });
453 }); 528 });
454 529
455 _declarer.group("inner", () { 530 await _runTest(entries.single.entries.single, shouldFail: true);
456 _declarer.tearDown(() {
457 throw 'inner error';
458 });
459
460 _declarer.test("description", expectAsync(() {
461 expect(outerTearDownRun, isFalse);
462 }, max: 1));
463 });
464
465 await _runTest(0, shouldFail: true);
466 expect(outerTearDownRun, isTrue); 531 expect(outerTearDownRun, isTrue);
467 }); 532 });
468 }); 533 });
469 }); 534 });
470 } 535 }
471 536
472 /// Runs the test at [index] defined on [_declarer]. 537 /// Runs [test].
473 /// 538 ///
474 /// This automatically sets up an `onError` listener to ensure that the test 539 /// This automatically sets up an `onError` listener to ensure that the test
475 /// doesn't throw any invisible exceptions. 540 /// doesn't throw any invisible exceptions.
476 Future _runTest(int index, {bool shouldFail: false}) { 541 Future _runTest(Test test, {bool shouldFail: false}) {
477 var liveTest = _declarer.tests[index].load(_suite); 542 var liveTest = test.load(_suite);
478 543
479 liveTest.onError.listen(shouldFail 544 liveTest.onError.listen(shouldFail
480 ? expectAsync((_) {}) 545 ? expectAsync((_) {})
481 : (error) => registerException(error.error, error.stackTrace)); 546 : (error) => registerException(error.error, error.stackTrace));
482 547
483 return liveTest.run(); 548 return liveTest.run();
484 } 549 }
OLDNEW
« no previous file with comments | « lib/test.dart ('k') | test/runner/browser/loader_test.dart » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698