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

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

Issue 1088453004: Move browser tests that require installation into their own files. (Closed) Base URL: git@github.com:dart-lang/test@master
Patch Set: Created 5 years, 8 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') | test/frontend/matcher/throws_type_test.dart » ('j') | 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", () { 18 test("with a function that doesn't throw", () {
19 return runTest(() { 19 return runTestBody(() {
20 expect(() {}, throws); 20 expect(() {}, throws);
21 }).then((liveTest) { 21 }).then((liveTest) {
22 expectTestFailed(liveTest, 22 expectTestFailed(liveTest,
23 "Expected: throws\n" 23 "Expected: throws\n"
24 " Actual: <$closureString>\n" 24 " Actual: <$closureString>\n"
25 " Which: did not throw\n"); 25 " Which: did not throw\n");
26 }); 26 });
27 }); 27 });
28 28
29 test("with a non-function", () { 29 test("with a non-function", () {
30 return runTest(() { 30 return runTestBody(() {
31 expect(10, throws); 31 expect(10, throws);
32 }).then((liveTest) { 32 }).then((liveTest) {
33 expectTestFailed(liveTest, 33 expectTestFailed(liveTest,
34 "Expected: throws\n" 34 "Expected: throws\n"
35 " Actual: <10>\n" 35 " Actual: <10>\n"
36 " Which: is not a Function or Future\n"); 36 " Which: is not a Function or Future\n");
37 }); 37 });
38 }); 38 });
39 }); 39 });
40 40
41 group("[throwsA]", () { 41 group("[throwsA]", () {
42 test("with a function that throws an identical error", () { 42 test("with a function that throws an identical error", () {
43 expect(() => throw 'oh no', throwsA('oh no')); 43 expect(() => throw 'oh no', throwsA('oh no'));
44 }); 44 });
45 45
46 test("with a function that throws a matching error", () { 46 test("with a function that throws a matching error", () {
47 expect(() => throw new FormatException("bad"), 47 expect(() => throw new FormatException("bad"),
48 throwsA(isFormatException)); 48 throwsA(isFormatException));
49 }); 49 });
50 50
51 test("with a function that doesn't throw", () { 51 test("with a function that doesn't throw", () {
52 return runTest(() { 52 return runTestBody(() {
53 expect(() {}, throwsA('oh no')); 53 expect(() {}, throwsA('oh no'));
54 }).then((liveTest) { 54 }).then((liveTest) {
55 expectTestFailed(liveTest, 55 expectTestFailed(liveTest,
56 "Expected: throws 'oh no'\n" 56 "Expected: throws 'oh no'\n"
57 " Actual: <$closureString>\n" 57 " Actual: <$closureString>\n"
58 " Which: did not throw\n"); 58 " Which: did not throw\n");
59 }); 59 });
60 }); 60 });
61 61
62 test("with a non-function", () { 62 test("with a non-function", () {
63 return runTest(() { 63 return runTestBody(() {
64 expect(10, throwsA('oh no')); 64 expect(10, throwsA('oh no'));
65 }).then((liveTest) { 65 }).then((liveTest) {
66 expectTestFailed(liveTest, 66 expectTestFailed(liveTest,
67 "Expected: throws 'oh no'\n" 67 "Expected: throws 'oh no'\n"
68 " Actual: <10>\n" 68 " Actual: <10>\n"
69 " Which: is not a Function or Future\n"); 69 " Which: is not a Function or Future\n");
70 }); 70 });
71 }); 71 });
72 72
73 test("with a function that throws the wrong error", () { 73 test("with a function that throws the wrong error", () {
74 return runTest(() { 74 return runTestBody(() {
75 expect(() => throw 'aw dang', throwsA('oh no')); 75 expect(() => throw 'aw dang', throwsA('oh no'));
76 }).then((liveTest) { 76 }).then((liveTest) {
77 expectTestFailed(liveTest, 77 expectTestFailed(liveTest,
78 "Expected: throws 'oh no'\n" 78 "Expected: throws 'oh no'\n"
79 " Actual: <$closureString>\n" 79 " Actual: <$closureString>\n"
80 " Which: threw 'aw dang'\n"); 80 " Which: threw 'aw dang'\n");
81 }); 81 });
82 }); 82 });
83 }); 83 });
84 }); 84 });
85 85
86 group("asynchronous", () { 86 group("asynchronous", () {
87 group("[throws]", () { 87 group("[throws]", () {
88 test("with a Future that throws an error", () { 88 test("with a Future that throws an error", () {
89 expect(new Future.error('oh no'), throws); 89 expect(new Future.error('oh no'), throws);
90 }); 90 });
91 91
92 test("with a Future that doesn't throw", () { 92 test("with a Future that doesn't throw", () {
93 return runTest(() { 93 return runTestBody(() {
94 expect(new Future.value(), throws); 94 expect(new Future.value(), throws);
95 }).then((liveTest) { 95 }).then((liveTest) {
96 expectTestFailed(liveTest, 96 expectTestFailed(liveTest,
97 "Expected future to fail, but succeeded with 'null'."); 97 "Expected future to fail, but succeeded with 'null'.");
98 }); 98 });
99 }); 99 });
100 100
101 test("won't let the test end until the Future completes", () { 101 test("won't let the test end until the Future completes", () {
102 return expectTestBlocks(() { 102 return expectTestBlocks(() {
103 var completer = new Completer(); 103 var completer = new Completer();
104 expect(completer.future, throws); 104 expect(completer.future, throws);
105 return completer; 105 return completer;
106 }, (completer) => completer.completeError('oh no')); 106 }, (completer) => completer.completeError('oh no'));
107 }); 107 });
108 }); 108 });
109 109
110 group("[throwsA]", () { 110 group("[throwsA]", () {
111 test("with a Future that throws an identical error", () { 111 test("with a Future that throws an identical error", () {
112 expect(new Future.error('oh no'), throwsA('oh no')); 112 expect(new Future.error('oh no'), throwsA('oh no'));
113 }); 113 });
114 114
115 test("with a Future that throws a matching error", () { 115 test("with a Future that throws a matching error", () {
116 expect(new Future.error(new FormatException("bad")), 116 expect(new Future.error(new FormatException("bad")),
117 throwsA(isFormatException)); 117 throwsA(isFormatException));
118 }); 118 });
119 119
120 test("with a Future that doesn't throw", () { 120 test("with a Future that doesn't throw", () {
121 return runTest(() { 121 return runTestBody(() {
122 expect(new Future.value(), throwsA('oh no')); 122 expect(new Future.value(), throwsA('oh no'));
123 }).then((liveTest) { 123 }).then((liveTest) {
124 expectTestFailed(liveTest, 124 expectTestFailed(liveTest,
125 "Expected future to fail, but succeeded with 'null'."); 125 "Expected future to fail, but succeeded with 'null'.");
126 }); 126 });
127 }); 127 });
128 128
129 test("with a Future that throws the wrong error", () { 129 test("with a Future that throws the wrong error", () {
130 return runTest(() { 130 return runTestBody(() {
131 expect(new Future.error('aw dang'), throwsA('oh no')); 131 expect(new Future.error('aw dang'), throwsA('oh no'));
132 }).then((liveTest) { 132 }).then((liveTest) {
133 expectTestFailed(liveTest, startsWith( 133 expectTestFailed(liveTest, startsWith(
134 "Expected: throws 'oh no'\n" 134 "Expected: throws 'oh no'\n"
135 " Actual: <$closureString>\n" 135 " Actual: <$closureString>\n"
136 " Which: threw 'aw dang'\n")); 136 " Which: threw 'aw dang'\n"));
137 }); 137 });
138 }); 138 });
139 139
140 test("won't let the test end until the Future completes", () { 140 test("won't let the test end until the Future completes", () {
141 return expectTestBlocks(() { 141 return expectTestBlocks(() {
142 var completer = new Completer(); 142 var completer = new Completer();
143 expect(completer.future, throwsA('oh no')); 143 expect(completer.future, throwsA('oh no'));
144 return completer; 144 return completer;
145 }, (completer) => completer.completeError('oh no')); 145 }, (completer) => completer.completeError('oh no'));
146 }); 146 });
147 }); 147 });
148 }); 148 });
149 } 149 }
OLDNEW
« no previous file with comments | « test/frontend/matcher/prints_test.dart ('k') | test/frontend/matcher/throws_type_test.dart » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698