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 'package:unittest/unittest.dart'; |
| 6 |
| 7 import '../utils.dart'; |
| 8 |
| 9 void main() { |
| 10 group('[throwsArgumentError]', () { |
| 11 test("passes when a ArgumentError is thrown", () { |
| 12 expect(() => throw new ArgumentError(''), throwsArgumentError); |
| 13 }); |
| 14 |
| 15 test("fails when a non-ArgumentError is thrown", () { |
| 16 return runTest(() { |
| 17 expect(() => throw new Exception(), throwsArgumentError); |
| 18 }).then((liveTest) { |
| 19 expectTestFailed(liveTest, |
| 20 startsWith("Expected: throws ArgumentError")); |
| 21 }); |
| 22 }); |
| 23 }); |
| 24 |
| 25 group('[throwsConcurrentModificationError]', () { |
| 26 test("passes when a ConcurrentModificationError is thrown", () { |
| 27 expect(() => throw new ConcurrentModificationError(''), |
| 28 throwsConcurrentModificationError); |
| 29 }); |
| 30 |
| 31 test("fails when a non-ConcurrentModificationError is thrown", () { |
| 32 return runTest(() { |
| 33 expect(() => throw new Exception(), throwsConcurrentModificationError); |
| 34 }).then((liveTest) { |
| 35 expectTestFailed(liveTest, |
| 36 startsWith("Expected: throws ConcurrentModificationError")); |
| 37 }); |
| 38 }); |
| 39 }); |
| 40 |
| 41 group('[throwsCyclicInitializationError]', () { |
| 42 test("passes when a CyclicInitializationError is thrown", () { |
| 43 expect(() => throw new CyclicInitializationError(''), |
| 44 throwsCyclicInitializationError); |
| 45 }); |
| 46 |
| 47 test("fails when a non-CyclicInitializationError is thrown", () { |
| 48 return runTest(() { |
| 49 expect(() => throw new Exception(), throwsCyclicInitializationError); |
| 50 }).then((liveTest) { |
| 51 expectTestFailed(liveTest, |
| 52 startsWith("Expected: throws CyclicInitializationError")); |
| 53 }); |
| 54 }); |
| 55 }); |
| 56 |
| 57 group('[throwsException]', () { |
| 58 test("passes when a Exception is thrown", () { |
| 59 expect(() => throw new Exception(''), throwsException); |
| 60 }); |
| 61 |
| 62 test("fails when a non-Exception is thrown", () { |
| 63 return runTest(() { |
| 64 expect(() => throw 'oh no', throwsException); |
| 65 }).then((liveTest) { |
| 66 expectTestFailed(liveTest, |
| 67 startsWith("Expected: throws Exception")); |
| 68 }); |
| 69 }); |
| 70 }); |
| 71 |
| 72 group('[throwsFormatException]', () { |
| 73 test("passes when a FormatException is thrown", () { |
| 74 expect(() => throw new FormatException(''), throwsFormatException); |
| 75 }); |
| 76 |
| 77 test("fails when a non-FormatException is thrown", () { |
| 78 return runTest(() { |
| 79 expect(() => throw new Exception(), throwsFormatException); |
| 80 }).then((liveTest) { |
| 81 expectTestFailed(liveTest, |
| 82 startsWith("Expected: throws FormatException")); |
| 83 }); |
| 84 }); |
| 85 }); |
| 86 |
| 87 group('[throwsNoSuchMethodError]', () { |
| 88 test("passes when a NoSuchMethodError is thrown", () { |
| 89 expect(() { |
| 90 throw new NoSuchMethodError(null, #name, null, null); |
| 91 }, throwsNoSuchMethodError); |
| 92 }); |
| 93 |
| 94 test("fails when a non-NoSuchMethodError is thrown", () { |
| 95 return runTest(() { |
| 96 expect(() => throw new Exception(), throwsNoSuchMethodError); |
| 97 }).then((liveTest) { |
| 98 expectTestFailed(liveTest, |
| 99 startsWith("Expected: throws NoSuchMethodError")); |
| 100 }); |
| 101 }); |
| 102 }); |
| 103 |
| 104 group('[throwsNullThrownError]', () { |
| 105 test("passes when a NullThrownError is thrown", () { |
| 106 expect(() => throw null, throwsNullThrownError); |
| 107 }); |
| 108 |
| 109 test("fails when a non-NullThrownError is thrown", () { |
| 110 return runTest(() { |
| 111 expect(() => throw new Exception(), throwsNullThrownError); |
| 112 }).then((liveTest) { |
| 113 expectTestFailed(liveTest, |
| 114 startsWith("Expected: throws NullThrownError")); |
| 115 }); |
| 116 }); |
| 117 }); |
| 118 |
| 119 group('[throwsRangeError]', () { |
| 120 test("passes when a RangeError is thrown", () { |
| 121 expect(() => throw new RangeError(''), throwsRangeError); |
| 122 }); |
| 123 |
| 124 test("fails when a non-RangeError is thrown", () { |
| 125 return runTest(() { |
| 126 expect(() => throw new Exception(), throwsRangeError); |
| 127 }).then((liveTest) { |
| 128 expectTestFailed(liveTest, |
| 129 startsWith("Expected: throws RangeError")); |
| 130 }); |
| 131 }); |
| 132 }); |
| 133 |
| 134 group('[throwsStateError]', () { |
| 135 test("passes when a StateError is thrown", () { |
| 136 expect(() => throw new StateError(''), throwsStateError); |
| 137 }); |
| 138 |
| 139 test("fails when a non-StateError is thrown", () { |
| 140 return runTest(() { |
| 141 expect(() => throw new Exception(), throwsStateError); |
| 142 }).then((liveTest) { |
| 143 expectTestFailed(liveTest, |
| 144 startsWith("Expected: throws StateError")); |
| 145 }); |
| 146 }); |
| 147 }); |
| 148 |
| 149 group('[throwsUnimplementedError]', () { |
| 150 test("passes when a UnimplementedError is thrown", () { |
| 151 expect(() => throw new UnimplementedError(''), throwsUnimplementedError); |
| 152 }); |
| 153 |
| 154 test("fails when a non-UnimplementedError is thrown", () { |
| 155 return runTest(() { |
| 156 expect(() => throw new Exception(), throwsUnimplementedError); |
| 157 }).then((liveTest) { |
| 158 expectTestFailed(liveTest, |
| 159 startsWith("Expected: throws UnimplementedError")); |
| 160 }); |
| 161 }); |
| 162 }); |
| 163 |
| 164 group('[throwsUnsupportedError]', () { |
| 165 test("passes when a UnsupportedError is thrown", () { |
| 166 expect(() => throw new UnsupportedError(''), throwsUnsupportedError); |
| 167 }); |
| 168 |
| 169 test("fails when a non-UnsupportedError is thrown", () { |
| 170 return runTest(() { |
| 171 expect(() => throw new Exception(), throwsUnsupportedError); |
| 172 }).then((liveTest) { |
| 173 expectTestFailed(liveTest, |
| 174 startsWith("Expected: throws UnsupportedError")); |
| 175 }); |
| 176 }); |
| 177 }); |
| 178 } |
OLD | NEW |