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