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

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

Issue 1180613008: Fix prints/throws tests on the latest dart2js. (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 | « test/frontend/matcher/prints_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/test.dart'; 7 import 'package:test/test.dart';
8 8
9 import '../../utils.dart'; 9 import '../../utils.dart';
10 10
11 void main() { 11 void main() {
12 group("synchronous", () { 12 group("synchronous", () {
13 group("[throws]", () { 13 group("[throws]", () {
14 test("with a function that throws an error", () { 14 test("with a function that throws an error", () {
15 expect(() => throw 'oh no', throws); 15 expect(() => throw 'oh no', throws);
16 }); 16 });
17 17
18 test("with a function that doesn't throw", () async { 18 test("with a function that doesn't throw", () async {
19 var closure = () {};
19 var liveTest = await runTestBody(() { 20 var liveTest = await runTestBody(() {
20 expect(() {}, throws); 21 expect(closure, throws);
21 }); 22 });
22 23
23 expectTestFailed(liveTest, 24 expectTestFailed(liveTest, allOf([
24 "Expected: throws\n" 25 startsWith(
25 " Actual: <$closureString>\n" 26 "Expected: throws\n"
26 " Which: did not throw\n"); 27 " Actual: <"),
28 endsWith(">\n"
29 " Which: did not throw\n")
30 ]));
27 }); 31 });
28 32
29 test("with a non-function", () async { 33 test("with a non-function", () async {
30 var liveTest = await runTestBody(() { 34 var liveTest = await runTestBody(() {
31 expect(10, throws); 35 expect(10, throws);
32 }); 36 });
33 37
34 expectTestFailed(liveTest, 38 expectTestFailed(liveTest,
35 "Expected: throws\n" 39 "Expected: throws\n"
36 " Actual: <10>\n" 40 " Actual: <10>\n"
37 " Which: is not a Function or Future\n"); 41 " Which: is not a Function or Future\n");
38 }); 42 });
39 }); 43 });
40 44
41 group("[throwsA]", () { 45 group("[throwsA]", () {
42 test("with a function that throws an identical error", () { 46 test("with a function that throws an identical error", () {
43 expect(() => throw 'oh no', throwsA('oh no')); 47 expect(() => throw 'oh no', throwsA('oh no'));
44 }); 48 });
45 49
46 test("with a function that throws a matching error", () { 50 test("with a function that throws a matching error", () {
47 expect(() => throw new FormatException("bad"), 51 expect(() => throw new FormatException("bad"),
48 throwsA(isFormatException)); 52 throwsA(isFormatException));
49 }); 53 });
50 54
51 test("with a function that doesn't throw", () async { 55 test("with a function that doesn't throw", () async {
56 var closure = () {};
52 var liveTest = await runTestBody(() { 57 var liveTest = await runTestBody(() {
53 expect(() {}, throwsA('oh no')); 58 expect(closure, throwsA('oh no'));
54 }); 59 });
55 60
56 expectTestFailed(liveTest, 61 expectTestFailed(liveTest, allOf([
57 "Expected: throws 'oh no'\n" 62 startsWith(
58 " Actual: <$closureString>\n" 63 "Expected: throws 'oh no'\n"
59 " Which: did not throw\n"); 64 " Actual: <"),
65 endsWith(">\n"
66 " Which: did not throw\n")
67 ]));
60 }); 68 });
61 69
62 test("with a non-function", () async { 70 test("with a non-function", () async {
63 var liveTest = await runTestBody(() { 71 var liveTest = await runTestBody(() {
64 expect(10, throwsA('oh no')); 72 expect(10, throwsA('oh no'));
65 }); 73 });
66 74
67 expectTestFailed(liveTest, 75 expectTestFailed(liveTest,
68 "Expected: throws 'oh no'\n" 76 "Expected: throws 'oh no'\n"
69 " Actual: <10>\n" 77 " Actual: <10>\n"
70 " Which: is not a Function or Future\n"); 78 " Which: is not a Function or Future\n");
71 }); 79 });
72 80
73 test("with a function that throws the wrong error", () async { 81 test("with a function that throws the wrong error", () async {
74 var liveTest = await runTestBody(() { 82 var liveTest = await runTestBody(() {
75 expect(() => throw 'aw dang', throwsA('oh no')); 83 expect(() => throw 'aw dang', throwsA('oh no'));
76 }); 84 });
77 85
78 expectTestFailed(liveTest, 86 expectTestFailed(liveTest, allOf([
79 "Expected: throws 'oh no'\n" 87 startsWith(
80 " Actual: <$closureString>\n" 88 "Expected: throws 'oh no'\n"
81 " Which: threw 'aw dang'\n"); 89 " Actual: <"),
90 endsWith(">\n"
91 " Which: threw 'aw dang'\n")
92 ]));
82 }); 93 });
83 }); 94 });
84 }); 95 });
85 96
86 group("asynchronous", () { 97 group("asynchronous", () {
87 group("[throws]", () { 98 group("[throws]", () {
88 test("with a Future that throws an error", () { 99 test("with a Future that throws an error", () {
89 expect(new Future.error('oh no'), throws); 100 expect(new Future.error('oh no'), throws);
90 }); 101 });
91 102
(...skipping 32 matching lines...) Expand 10 before | Expand all | Expand 10 after
124 135
125 expectTestFailed(liveTest, 136 expectTestFailed(liveTest,
126 "Expected future to fail, but succeeded with 'null'."); 137 "Expected future to fail, but succeeded with 'null'.");
127 }); 138 });
128 139
129 test("with a Future that throws the wrong error", () async { 140 test("with a Future that throws the wrong error", () async {
130 var liveTest = await runTestBody(() { 141 var liveTest = await runTestBody(() {
131 expect(new Future.error('aw dang'), throwsA('oh no')); 142 expect(new Future.error('aw dang'), throwsA('oh no'));
132 }); 143 });
133 144
134 expectTestFailed(liveTest, startsWith( 145 expectTestFailed(liveTest, allOf([
135 "Expected: throws 'oh no'\n" 146 startsWith(
136 " Actual: <$closureString>\n" 147 "Expected: throws 'oh no'\n"
137 " Which: threw 'aw dang'\n")); 148 " Actual: <"),
149 contains(">\n"
150 " Which: threw 'aw dang'\n")
151 ]));
138 }); 152 });
139 153
140 test("won't let the test end until the Future completes", () { 154 test("won't let the test end until the Future completes", () {
141 return expectTestBlocks(() { 155 return expectTestBlocks(() {
142 var completer = new Completer(); 156 var completer = new Completer();
143 expect(completer.future, throwsA('oh no')); 157 expect(completer.future, throwsA('oh no'));
144 return completer; 158 return completer;
145 }, (completer) => completer.completeError('oh no')); 159 }, (completer) => completer.completeError('oh no'));
146 }); 160 });
147 }); 161 });
148 }); 162 });
149 } 163 }
OLDNEW
« no previous file with comments | « test/frontend/matcher/prints_test.dart ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698