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

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

Issue 1364893004: Run outer tearDown()s even if inner ones fail. (Closed) Base URL: git@github.com:dart-lang/test@master
Patch Set: More robust Created 5 years, 3 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
« lib/src/backend/group.dart ('K') | « pubspec.yaml ('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 371 matching lines...) Expand 10 before | Expand all | Expand 10 after
382 expect(outerTearDownRun, isFalse); 382 expect(outerTearDownRun, isFalse);
383 expect(innerTearDownRun, isFalse); 383 expect(innerTearDownRun, isFalse);
384 }, max: 1)); 384 }, max: 1));
385 }); 385 });
386 386
387 await _runTest(0); 387 await _runTest(0);
388 expect(innerTearDownRun, isTrue); 388 expect(innerTearDownRun, isTrue);
389 expect(outerTearDownRun, isTrue); 389 expect(outerTearDownRun, isTrue);
390 }); 390 });
391 391
392 test("runs outer callbacks even when inner ones fail", () async {
393 var outerTearDownRun = false;
394 _declarer.tearDown(() {
395 return new Future(() => outerTearDownRun = true);
396 });
397
398 _declarer.group("inner", () {
399 _declarer.tearDown(() {
400 throw 'inner error';
401 });
402
403 _declarer.test("description", expectAsync(() {
404 expect(outerTearDownRun, isFalse);
405 }, max: 1));
406 });
407
408 await _runTest(0, shouldFail: true);
409 expect(outerTearDownRun, isTrue);
410 });
411
392 test("can't be called multiple times", () { 412 test("can't be called multiple times", () {
393 _declarer.group("group", () { 413 _declarer.group("group", () {
394 _declarer.tearDown(() {}); 414 _declarer.tearDown(() {});
395 expect(() => _declarer.tearDown(() {}), throwsStateError); 415 expect(() => _declarer.tearDown(() {}), throwsStateError);
396 }); 416 });
397 }); 417 });
398 }); 418 });
399 }); 419 });
400 } 420 }
401 421
402 /// Runs the test at [index] defined on [_declarer]. 422 /// Runs the test at [index] defined on [_declarer].
403 /// 423 ///
404 /// This automatically sets up an `onError` listener to ensure that the test 424 /// This automatically sets up an `onError` listener to ensure that the test
405 /// doesn't throw any invisible exceptions. 425 /// doesn't throw any invisible exceptions.
406 Future _runTest(int index, {bool shouldFail: false}) { 426 Future _runTest(int index, {bool shouldFail: false}) {
407 var liveTest = _declarer.tests[index].load(_suite); 427 var liveTest = _declarer.tests[index].load(_suite);
408 428
409 liveTest.onError.listen(shouldFail 429 liveTest.onError.listen(shouldFail
410 ? expectAsync((_) {}) 430 ? expectAsync((_) {})
411 : expectAsync((_) {}, 431 : expectAsync((_) {},
412 count: 0, reason: "No errors expected for test #$index.")); 432 count: 0, reason: "No errors expected for test #$index."));
413 433
414 return liveTest.run(); 434 return liveTest.run();
415 } 435 }
OLDNEW
« lib/src/backend/group.dart ('K') | « pubspec.yaml ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698