OLD | NEW |
| (Empty) |
1 // Copyright (c) 2012, 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 library matcher.core_matchers_test; | |
6 | |
7 import 'package:matcher/matcher.dart'; | |
8 import 'package:unittest/unittest.dart' show test, group; | |
9 | |
10 import 'test_utils.dart'; | |
11 | |
12 void main() { | |
13 initUtils(); | |
14 | |
15 test('throws', () { | |
16 shouldFail(doesNotThrow, throws, matches(r"Expected: throws" | |
17 r" Actual: <Closure(: \(\) => dynamic " | |
18 r"from Function 'doesNotThrow': static\.)?>" | |
19 r" Which: did not throw")); | |
20 shouldPass(doesThrow, throws); | |
21 shouldFail(true, throws, "Expected: throws" | |
22 " Actual: <true>" | |
23 " Which: is not a Function or Future"); | |
24 }); | |
25 | |
26 test('throwsA', () { | |
27 shouldPass(doesThrow, throwsA(equals('X'))); | |
28 shouldFail(doesThrow, throwsA(equals('Y')), matches(r"Expected: throws 'Y'" | |
29 r" Actual: <Closure(: \(\) => dynamic " | |
30 r"from Function 'doesThrow': static\.)?>" | |
31 r" Which: threw 'X'")); | |
32 }); | |
33 | |
34 test('throwsA', () { | |
35 shouldPass(doesThrow, throwsA(equals('X'))); | |
36 shouldFail(doesThrow, throwsA(equals('Y')), matches("Expected: throws 'Y'.*" | |
37 "Actual: <Closure.*" | |
38 "Which: threw 'X'")); | |
39 }); | |
40 | |
41 group('exception/error matchers', () { | |
42 test('throwsCyclicInitializationError', () { | |
43 expect(() => _Bicycle.foo, throwsCyclicInitializationError); | |
44 }); | |
45 | |
46 test('throwsConcurrentModificationError', () { | |
47 expect(() { | |
48 var a = {'foo': 'bar'}; | |
49 for (var k in a.keys) { | |
50 a.remove(k); | |
51 } | |
52 }, throwsConcurrentModificationError); | |
53 }); | |
54 | |
55 test('throwsNullThrownError', () { | |
56 expect(() => throw null, throwsNullThrownError); | |
57 }); | |
58 }); | |
59 } | |
60 | |
61 class _Bicycle { | |
62 static final foo = bar(); | |
63 | |
64 static bar() { | |
65 return foo + 1; | |
66 } | |
67 } | |
OLD | NEW |