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

Side by Side Diff: test/frontend/matcher/completion_test.dart

Issue 1158463003: Don't wrap exceptions in complete or completes(). (Closed) Base URL: git@github.com:dart-lang/test@master
Patch Set: Created 5 years, 6 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/src/frontend/future_matchers.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/test.dart'; 7 import 'package:test/test.dart';
8 import 'package:test/src/backend/state.dart';
8 9
9 import '../../utils.dart'; 10 import '../../utils.dart';
10 11
11 void main() { 12 void main() {
12 group("[completes]", () { 13 group("[completes]", () {
13 test("blocks the test until the Future completes", () { 14 test("blocks the test until the Future completes", () {
14 return expectTestBlocks(() { 15 return expectTestBlocks(() {
15 var completer = new Completer(); 16 var completer = new Completer();
16 expect(completer.future, completes); 17 expect(completer.future, completes);
17 return completer; 18 return completer;
18 }, (completer) => completer.complete()); 19 }, (completer) => completer.complete());
19 }); 20 });
20 21
21 test("with an error", () async { 22 test("with an error", () async {
22 var liveTest = await runTestBody(() { 23 var liveTest = await runTestBody(() {
23 expect(new Future.error('X'), completes); 24 expect(new Future.error('X'), completes);
24 }); 25 });
25 26
26 expectTestFailed(liveTest, startsWith( 27 expect(liveTest.state.status, equals(Status.complete));
27 "Expected future to complete successfully, but it failed with X")); 28 expect(liveTest.state.result, equals(Result.error));
29 expect(liveTest.errors, hasLength(1));
30 expect(liveTest.errors.first.error, equals('X'));
28 }); 31 });
29 32
30 test("with a failure", () async { 33 test("with a failure", () async {
31 var liveTest = await runTestBody(() { 34 var liveTest = await runTestBody(() {
32 expect(new Future.error(new TestFailure('oh no')), completes); 35 expect(new Future.error(new TestFailure('oh no')), completes);
33 }); 36 });
34 37
35 expectTestFailed(liveTest, "oh no"); 38 expectTestFailed(liveTest, "oh no");
36 }); 39 });
37 40
(...skipping 19 matching lines...) Expand all
57 expect(completer.future, completion(isNull)); 60 expect(completer.future, completion(isNull));
58 return completer; 61 return completer;
59 }, (completer) => completer.complete()); 62 }, (completer) => completer.complete());
60 }); 63 });
61 64
62 test("with an error", () async { 65 test("with an error", () async {
63 var liveTest = await runTestBody(() { 66 var liveTest = await runTestBody(() {
64 expect(new Future.error('X'), completion(isNull)); 67 expect(new Future.error('X'), completion(isNull));
65 }); 68 });
66 69
67 expectTestFailed(liveTest, startsWith( 70 expect(liveTest.state.status, equals(Status.complete));
68 "Expected future to complete successfully, but it failed with X")); 71 expect(liveTest.state.result, equals(Result.error));
72 expect(liveTest.errors, hasLength(1));
73 expect(liveTest.errors.first.error, equals('X'));
69 }); 74 });
70 75
71 test("with a failure", () async { 76 test("with a failure", () async {
72 var liveTest = await runTestBody(() { 77 var liveTest = await runTestBody(() {
73 expect(new Future.error(new TestFailure('oh no')), completion(isNull)); 78 expect(new Future.error(new TestFailure('oh no')), completion(isNull));
74 }); 79 });
75 80
76 expectTestFailed(liveTest, "oh no"); 81 expectTestFailed(liveTest, "oh no");
77 }); 82 });
78 83
(...skipping 12 matching lines...) Expand all
91 expect(new Future.value('a'), completion(equals('b'))); 96 expect(new Future.value('a'), completion(equals('b')));
92 }); 97 });
93 98
94 expectTestFailed(liveTest, startsWith( 99 expectTestFailed(liveTest, startsWith(
95 "Expected: 'b'\n" 100 "Expected: 'b'\n"
96 " Actual: 'a'\n" 101 " Actual: 'a'\n"
97 " Which: is different."));; 102 " Which: is different."));;
98 }); 103 });
99 }); 104 });
100 } 105 }
OLDNEW
« no previous file with comments | « lib/src/frontend/future_matchers.dart ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698