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 |
| 16 test('throws', () { |
| 17 shouldFail(doesNotThrow, throws, |
| 18 matches( |
| 19 r"Expected: throws" |
| 20 r" Actual: <Closure(: \(\) => dynamic " |
| 21 r"from Function 'doesNotThrow': static\.)?>" |
| 22 r" Which: did not throw")); |
| 23 shouldPass(doesThrow, throws); |
| 24 shouldFail(true, throws, |
| 25 "Expected: throws" |
| 26 " Actual: <true>" |
| 27 " Which: is not a Function or Future"); |
| 28 }); |
| 29 |
| 30 test('throwsA', () { |
| 31 shouldPass(doesThrow, throwsA(equals('X'))); |
| 32 shouldFail(doesThrow, throwsA(equals('Y')), |
| 33 matches( |
| 34 r"Expected: throws 'Y'" |
| 35 r" Actual: <Closure(: \(\) => dynamic " |
| 36 r"from Function 'doesThrow': static\.)?>" |
| 37 r" Which: threw 'X'")); |
| 38 }); |
| 39 |
| 40 test('throwsA', () { |
| 41 shouldPass(doesThrow, throwsA(equals('X'))); |
| 42 shouldFail(doesThrow, throwsA(equals('Y')), |
| 43 matches("Expected: throws 'Y'.*" |
| 44 "Actual: <Closure.*" |
| 45 "Which: threw 'X'")); |
| 46 }); |
| 47 |
| 48 |
| 49 group('exception/error matchers', () { |
| 50 test('throwsCyclicInitializationError', () { |
| 51 expect(() => _Bicycle.foo, throwsCyclicInitializationError); |
| 52 }); |
| 53 |
| 54 test('throwsConcurrentModificationError', () { |
| 55 expect(() { |
| 56 var a = { 'foo': 'bar' }; |
| 57 for (var k in a.keys) { |
| 58 a.remove(k); |
| 59 } |
| 60 }, throwsConcurrentModificationError); |
| 61 }); |
| 62 |
| 63 test('throwsNullThrownError', () { |
| 64 expect(() => throw null, throwsNullThrownError); |
| 65 }); |
| 66 }); |
| 67 } |
| 68 |
| 69 class _Bicycle { |
| 70 static final foo = bar(); |
| 71 |
| 72 static bar() { |
| 73 return foo + 1; |
| 74 } |
| 75 } |
| 76 |
OLD | NEW |