| OLD | NEW |
| (Empty) |
| 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 | |
| 3 // BSD-style license that can be found in the LICENSE file. | |
| 4 | |
| 5 import 'dart:async'; | |
| 6 | |
| 7 import 'package:unittest/unittest.dart'; | |
| 8 | |
| 9 import '../utils.dart'; | |
| 10 | |
| 11 void main() { | |
| 12 group("synchronous", () { | |
| 13 group("[throws]", () { | |
| 14 test("with a function that throws an error", () { | |
| 15 expect(() => throw 'oh no', throws); | |
| 16 }); | |
| 17 | |
| 18 test("with a function that doesn't throw", () { | |
| 19 return runTest(() { | |
| 20 expect(() {}, throws); | |
| 21 }).then((liveTest) { | |
| 22 expectTestFailed(liveTest, | |
| 23 "Expected: throws\n" | |
| 24 " Actual: <Closure: () => dynamic>\n" | |
| 25 " Which: did not throw\n"); | |
| 26 }); | |
| 27 }); | |
| 28 | |
| 29 test("with a non-function", () { | |
| 30 return runTest(() { | |
| 31 expect(10, throws); | |
| 32 }).then((liveTest) { | |
| 33 expectTestFailed(liveTest, | |
| 34 "Expected: throws\n" | |
| 35 " Actual: <10>\n" | |
| 36 " Which: is not a Function or Future\n"); | |
| 37 }); | |
| 38 }); | |
| 39 }); | |
| 40 | |
| 41 group("[throwsA]", () { | |
| 42 test("with a function that throws an identical error", () { | |
| 43 expect(() => throw 'oh no', throwsA('oh no')); | |
| 44 }); | |
| 45 | |
| 46 test("with a function that throws a matching error", () { | |
| 47 expect(() => throw new FormatException("bad"), | |
| 48 throwsA(isFormatException)); | |
| 49 }); | |
| 50 | |
| 51 test("with a function that doesn't throw", () { | |
| 52 return runTest(() { | |
| 53 expect(() {}, throwsA('oh no')); | |
| 54 }).then((liveTest) { | |
| 55 expectTestFailed(liveTest, | |
| 56 "Expected: throws 'oh no'\n" | |
| 57 " Actual: <Closure: () => dynamic>\n" | |
| 58 " Which: did not throw\n"); | |
| 59 }); | |
| 60 }); | |
| 61 | |
| 62 test("with a non-function", () { | |
| 63 return runTest(() { | |
| 64 expect(10, throwsA('oh no')); | |
| 65 }).then((liveTest) { | |
| 66 expectTestFailed(liveTest, | |
| 67 "Expected: throws 'oh no'\n" | |
| 68 " Actual: <10>\n" | |
| 69 " Which: is not a Function or Future\n"); | |
| 70 }); | |
| 71 }); | |
| 72 | |
| 73 test("with a function that throws the wrong error", () { | |
| 74 return runTest(() { | |
| 75 expect(() => throw 'aw dang', throwsA('oh no')); | |
| 76 }).then((liveTest) { | |
| 77 expectTestFailed(liveTest, | |
| 78 "Expected: throws 'oh no'\n" | |
| 79 " Actual: <Closure: () => dynamic>\n" | |
| 80 " Which: threw 'aw dang'\n"); | |
| 81 }); | |
| 82 }); | |
| 83 }); | |
| 84 }); | |
| 85 | |
| 86 group("asynchronous", () { | |
| 87 group("[throws]", () { | |
| 88 test("with a Future that throws an error", () { | |
| 89 expect(new Future.error('oh no'), throws); | |
| 90 }); | |
| 91 | |
| 92 test("with a Future that doesn't throw", () { | |
| 93 return runTest(() { | |
| 94 expect(new Future.value(), throws); | |
| 95 }).then((liveTest) { | |
| 96 expectTestFailed(liveTest, | |
| 97 "Expected future to fail, but succeeded with 'null'."); | |
| 98 }); | |
| 99 }); | |
| 100 | |
| 101 test("won't let the test end until the Future completes", () { | |
| 102 return expectTestBlocks(() { | |
| 103 var completer = new Completer(); | |
| 104 expect(completer.future, throws); | |
| 105 return completer; | |
| 106 }, (completer) => completer.completeError('oh no')); | |
| 107 }); | |
| 108 }); | |
| 109 | |
| 110 group("[throwsA]", () { | |
| 111 test("with a Future that throws an identical error", () { | |
| 112 expect(new Future.error('oh no'), throwsA('oh no')); | |
| 113 }); | |
| 114 | |
| 115 test("with a Future that throws a matching error", () { | |
| 116 expect(new Future.error(new FormatException("bad")), | |
| 117 throwsA(isFormatException)); | |
| 118 }); | |
| 119 | |
| 120 test("with a Future that doesn't throw", () { | |
| 121 return runTest(() { | |
| 122 expect(new Future.value(), throwsA('oh no')); | |
| 123 }).then((liveTest) { | |
| 124 expectTestFailed(liveTest, | |
| 125 "Expected future to fail, but succeeded with 'null'."); | |
| 126 }); | |
| 127 }); | |
| 128 | |
| 129 test("with a Future that throws the wrong error", () { | |
| 130 return runTest(() { | |
| 131 expect(new Future.error('aw dang'), throwsA('oh no')); | |
| 132 }).then((liveTest) { | |
| 133 expectTestFailed(liveTest, startsWith( | |
| 134 "Expected: throws 'oh no'\n" | |
| 135 " Actual: <Closure: () => dynamic>\n" | |
| 136 " Which: threw 'aw dang'\n")); | |
| 137 }); | |
| 138 }); | |
| 139 | |
| 140 test("won't let the test end until the Future completes", () { | |
| 141 return expectTestBlocks(() { | |
| 142 var completer = new Completer(); | |
| 143 expect(completer.future, throwsA('oh no')); | |
| 144 return completer; | |
| 145 }, (completer) => completer.completeError('oh no')); | |
| 146 }); | |
| 147 }); | |
| 148 }); | |
| 149 } | |
| OLD | NEW |