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

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

Issue 1369613002: setUp/tearDown may be called repeatedly in a group. (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') | no next file » | 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/invoker.dart'; 8 import 'package:test/src/backend/invoker.dart';
9 import 'package:test/src/backend/suite.dart'; 9 import 'package:test/src/backend/suite.dart';
10 import 'package:test/src/frontend/timeout.dart'; 10 import 'package:test/src/frontend/timeout.dart';
(...skipping 61 matching lines...) Expand 10 before | Expand all | Expand 10 after
72 return new Future(() => setUpRun = true); 72 return new Future(() => setUpRun = true);
73 }); 73 });
74 74
75 _declarer.test("description", expectAsync(() { 75 _declarer.test("description", expectAsync(() {
76 expect(setUpRun, isTrue); 76 expect(setUpRun, isTrue);
77 }, max: 1)); 77 }, max: 1));
78 78
79 return _runTest(0); 79 return _runTest(0);
80 }); 80 });
81 81
82 test("can't be called multiple times", () { 82 test("runs in call order within a group", () async {
83 _declarer.setUp(() {}); 83 var firstSetUpRun = false;
84 expect(() => _declarer.setUp(() {}), throwsStateError); 84 var secondSetUpRun = false;
85 var thirdSetUpRun = false;
86 _declarer.setUp(expectAsync(() async {
87 expect(secondSetUpRun, isFalse);
88 expect(thirdSetUpRun, isFalse);
89 firstSetUpRun = true;
90 }));
91
92 _declarer.setUp(expectAsync(() async {
93 expect(firstSetUpRun, isTrue);
94 expect(thirdSetUpRun, isFalse);
95 secondSetUpRun = true;
96 }));
97
98 _declarer.setUp(expectAsync(() async {
99 expect(firstSetUpRun, isTrue);
100 expect(secondSetUpRun, isTrue);
101 thirdSetUpRun = true;
102 }));
103
104 _declarer.test("description", expectAsync(() {
105 expect(firstSetUpRun, isTrue);
106 expect(secondSetUpRun, isTrue);
107 expect(thirdSetUpRun, isTrue);
108 }));
109
110 await _runTest(0);
85 }); 111 });
86 }); 112 });
87 113
88 group(".tearDown()", () { 114 group(".tearDown()", () {
89 test("is run after all tests", () async { 115 test("is run after all tests", () async {
90 var tearDownRun; 116 var tearDownRun;
91 _declarer.setUp(() => tearDownRun = false); 117 _declarer.setUp(() => tearDownRun = false);
92 _declarer.tearDown(() => tearDownRun = true); 118 _declarer.tearDown(() => tearDownRun = true);
93 119
94 _declarer.test("description 1", expectAsync(() { 120 _declarer.test("description 1", expectAsync(() {
(...skipping 66 matching lines...) Expand 10 before | Expand all | Expand 10 after
161 Invoker.current.removeOutstandingCallback(); 187 Invoker.current.removeOutstandingCallback();
162 }); 188 });
163 }); 189 });
164 190
165 _declarer.test("description", () {}); 191 _declarer.test("description", () {});
166 192
167 await _runTest(0); 193 await _runTest(0);
168 expect(outstandingCallbackRemoved, isTrue); 194 expect(outstandingCallbackRemoved, isTrue);
169 }); 195 });
170 196
171 test("can't be called multiple times", () { 197 test("runs in reverse call order within a group", () async {
172 _declarer.tearDown(() {}); 198 var firstTearDownRun = false;
173 expect(() => _declarer.tearDown(() {}), throwsStateError); 199 var secondTearDownRun = false;
200 var thirdTearDownRun = false;
201 _declarer.tearDown(expectAsync(() async {
202 expect(secondTearDownRun, isTrue);
203 expect(thirdTearDownRun, isTrue);
204 firstTearDownRun = true;
205 }));
206
207 _declarer.tearDown(expectAsync(() async {
208 expect(firstTearDownRun, isFalse);
209 expect(thirdTearDownRun, isTrue);
210 secondTearDownRun = true;
211 }));
212
213 _declarer.tearDown(expectAsync(() async {
214 expect(firstTearDownRun, isFalse);
215 expect(secondTearDownRun, isFalse);
216 thirdTearDownRun = true;
217 }));
218
219 _declarer.test("description", expectAsync(() {
220 expect(firstTearDownRun, isFalse);
221 expect(secondTearDownRun, isFalse);
222 expect(thirdTearDownRun, isFalse);
223 }, max: 1));
224
225 await _runTest(0);
226 });
227
228 test("runs further tearDowns in a group even if one fails", () async {
229 _declarer.tearDown(expectAsync(() {}));
230
231 _declarer.tearDown(() async {
232 throw 'error';
233 });
234
235 _declarer.test("description", expectAsync(() {}));
236
237 await _runTest(0, shouldFail: true);
174 }); 238 });
175 }); 239 });
176 240
177 group("in a group,", () { 241 group("in a group,", () {
178 test("tests inherit the group's description", () { 242 test("tests inherit the group's description", () {
179 _declarer.group("group", () { 243 _declarer.group("group", () {
180 _declarer.test("description", () {}); 244 _declarer.test("description", () {});
181 }); 245 });
182 246
183 expect(_declarer.tests, hasLength(1)); 247 expect(_declarer.tests, hasLength(1));
(...skipping 103 matching lines...) Expand 10 before | Expand all | Expand 10 after
287 }, max: 1)); 351 }, max: 1));
288 352
289 _declarer.test("description", expectAsync(() { 353 _declarer.test("description", expectAsync(() {
290 expect(outerSetUpRun, isTrue); 354 expect(outerSetUpRun, isTrue);
291 expect(innerSetUpRun, isTrue); 355 expect(innerSetUpRun, isTrue);
292 }, max: 1)); 356 }, max: 1));
293 }); 357 });
294 358
295 return _runTest(0); 359 return _runTest(0);
296 }); 360 });
297
298 test("can't be called multiple times", () {
299 _declarer.group("group", () {
300 _declarer.setUp(() {});
301 expect(() => _declarer.setUp(() {}), throwsStateError);
302 });
303 });
304 }); 361 });
305 362
306 group(".tearDown()", () { 363 group(".tearDown()", () {
307 test("is scoped to the group", () async { 364 test("is scoped to the group", () async {
308 var tearDownRun; 365 var tearDownRun;
309 _declarer.setUp(() => tearDownRun = false); 366 _declarer.setUp(() => tearDownRun = false);
310 367
311 _declarer.group("group", () { 368 _declarer.group("group", () {
312 _declarer.tearDown(() => tearDownRun = true); 369 _declarer.tearDown(() => tearDownRun = true);
313 370
(...skipping 87 matching lines...) Expand 10 before | Expand all | Expand 10 after
401 }); 458 });
402 459
403 _declarer.test("description", expectAsync(() { 460 _declarer.test("description", expectAsync(() {
404 expect(outerTearDownRun, isFalse); 461 expect(outerTearDownRun, isFalse);
405 }, max: 1)); 462 }, max: 1));
406 }); 463 });
407 464
408 await _runTest(0, shouldFail: true); 465 await _runTest(0, shouldFail: true);
409 expect(outerTearDownRun, isTrue); 466 expect(outerTearDownRun, isTrue);
410 }); 467 });
411
412 test("can't be called multiple times", () {
413 _declarer.group("group", () {
414 _declarer.tearDown(() {});
415 expect(() => _declarer.tearDown(() {}), throwsStateError);
416 });
417 });
418 }); 468 });
419 }); 469 });
420 } 470 }
421 471
422 /// Runs the test at [index] defined on [_declarer]. 472 /// Runs the test at [index] defined on [_declarer].
423 /// 473 ///
424 /// This automatically sets up an `onError` listener to ensure that the test 474 /// This automatically sets up an `onError` listener to ensure that the test
425 /// doesn't throw any invisible exceptions. 475 /// doesn't throw any invisible exceptions.
426 Future _runTest(int index, {bool shouldFail: false}) { 476 Future _runTest(int index, {bool shouldFail: false}) {
427 var liveTest = _declarer.tests[index].load(_suite); 477 var liveTest = _declarer.tests[index].load(_suite);
428 478
429 liveTest.onError.listen(shouldFail 479 liveTest.onError.listen(shouldFail
430 ? expectAsync((_) {}) 480 ? expectAsync((_) {})
431 : expectAsync((_) {}, 481 : (error) => registerException(error.error, error.stackTrace));
432 count: 0, reason: "No errors expected for test #$index."));
433 482
434 return liveTest.run(); 483 return liveTest.run();
435 } 484 }
OLDNEW
« no previous file with comments | « lib/test.dart ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698