OLD | NEW |
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:unittest/unittest.dart'; | 7 import 'package:unittest/unittest.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 runTest(() { |
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: <Closure: () => dynamic>\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 runTest(() { |
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" |
(...skipping 12 matching lines...) Expand all Loading... |
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 runTest(() { |
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: <Closure: () => dynamic>\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 runTest(() { |
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 runTest(() { |
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: <Closure: () => dynamic>\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); |
(...skipping 35 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
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 runTest(() { |
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: <Closure: () => dynamic>\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 } |
OLD | NEW |