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

Unified Diff: test/backend/declarer_test.dart

Issue 1361303002: Get rid of LocalTest.tearDown. (Closed) Base URL: git@github.com:dart-lang/test@master
Patch Set: Code review changes 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 side-by-side diff with in-line comments
Download patch
« no previous file with comments | « lib/src/backend/invoker.dart ('k') | test/backend/invoker_test.dart » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: test/backend/declarer_test.dart
diff --git a/test/backend/declarer_test.dart b/test/backend/declarer_test.dart
index 91a806ece5e958edb9627754c6d02da981825ad0..4873b6151c9e23a7e031a981f6b3ed8abb50ebf1 100644
--- a/test/backend/declarer_test.dart
+++ b/test/backend/declarer_test.dart
@@ -5,10 +5,13 @@
import 'dart:async';
import 'package:test/src/backend/declarer.dart';
+import 'package:test/src/backend/invoker.dart';
import 'package:test/src/backend/suite.dart';
import 'package:test/src/frontend/timeout.dart';
import 'package:test/test.dart';
+import '../utils.dart';
+
Declarer _declarer;
Suite _suite;
@@ -102,6 +105,20 @@ void main() {
expect(tearDownRun, isTrue);
});
+ test("is run after an out-of-band failure", () async {
+ var tearDownRun;
+ _declarer.setUp(() => tearDownRun = false);
+ _declarer.tearDown(() => tearDownRun = true);
+
+ _declarer.test("description 1", expectAsync(() {
+ Invoker.current.addOutstandingCallback();
+ new Future(() => throw new TestFailure("oh no"));
+ }, max: 1));
+
+ await _runTest(0, shouldFail: true);
+ expect(tearDownRun, isTrue);
+ });
+
test("can return a Future", () async {
var tearDownRun = false;
_declarer.tearDown(() {
@@ -116,6 +133,41 @@ void main() {
expect(tearDownRun, isTrue);
});
+ test("isn't run until there are no outstanding callbacks", () async {
+ var outstandingCallbackRemoved = false;
+ var outstandingCallbackRemovedBeforeTeardown = false;
+ _declarer.tearDown(() {
+ outstandingCallbackRemovedBeforeTeardown = outstandingCallbackRemoved;
+ });
+
+ _declarer.test("description", () {
+ Invoker.current.addOutstandingCallback();
+ pumpEventQueue().then((_) {
+ outstandingCallbackRemoved = true;
+ Invoker.current.removeOutstandingCallback();
+ });
+ });
+
+ await _runTest(0);
+ expect(outstandingCallbackRemovedBeforeTeardown, isTrue);
+ });
+
+ test("doesn't complete until there are no outstanding callbacks", () async {
+ var outstandingCallbackRemoved = false;
+ _declarer.tearDown(() {
+ Invoker.current.addOutstandingCallback();
+ pumpEventQueue().then((_) {
+ outstandingCallbackRemoved = true;
+ Invoker.current.removeOutstandingCallback();
+ });
+ });
+
+ _declarer.test("description", () {});
+
+ await _runTest(0);
+ expect(outstandingCallbackRemoved, isTrue);
+ });
+
test("can't be called multiple times", () {
_declarer.tearDown(() {});
expect(() => _declarer.tearDown(() {}), throwsStateError);
@@ -351,9 +403,13 @@ void main() {
///
/// This automatically sets up an `onError` listener to ensure that the test
/// doesn't throw any invisible exceptions.
-Future _runTest(int index) {
+Future _runTest(int index, {bool shouldFail: false}) {
var liveTest = _declarer.tests[index].load(_suite);
- liveTest.onError.listen(expectAsync((_) {},
- count: 0, reason: "No errors expected for test #$index."));
+
+ liveTest.onError.listen(shouldFail
+ ? expectAsync((_) {})
+ : expectAsync((_) {},
+ count: 0, reason: "No errors expected for test #$index."));
+
return liveTest.run();
}
« no previous file with comments | « lib/src/backend/invoker.dart ('k') | test/backend/invoker_test.dart » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698