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