OLD | NEW |
1 // Copyright (c) 2013, the Dart project authors. Please see the AUTHORS file | 1 // Copyright (c) 2013, the Dart project authors. Please see the AUTHORS file |
2 // for details. All rights reserved. Use of this source code is governed by a | 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. | 3 // BSD-style license that can be found in the LICENSE file. |
4 | 4 |
5 /// A light-weight replacement for package:unittest. This library runs tests | 5 /// A light-weight replacement for package:unittest. This library runs tests |
6 /// synchronously, and avoids using reflection. | 6 /// synchronously, and avoids using reflection. |
7 library light_unittest; | 7 library light_unittest; |
8 | 8 |
9 import 'dart:async'; | 9 import 'dart:async'; |
10 | 10 |
11 import 'package:async_helper/async_helper.dart'; | 11 import 'package:async_helper/async_helper.dart'; |
12 import '../pkg/expect/lib/expect.dart'; | 12 import '../pkg/expect/lib/expect.dart'; |
13 | 13 |
14 test(name, f) { | 14 test(name, f) { |
15 print('Testing $name'); | 15 print('Testing $name'); |
16 try { | 16 try { |
17 f(); | 17 f(); |
18 print('PASS: $name'); | 18 print('PASS: $name'); |
19 } catch (e, trace) { | 19 } catch (e, trace) { |
20 print('FAIL: $name.'); | 20 print('FAIL: $name.'); |
21 print(e); | 21 print(e); |
22 print(trace); | 22 print(trace); |
23 asyncStart(); | 23 asyncStart(); |
24 Timer.run(() { throw new StateError('FAILED: $name.\n$e\n$trace'); }); | 24 Timer.run(() { |
| 25 throw new StateError('FAILED: $name.\n$e\n$trace'); |
| 26 }); |
25 } | 27 } |
26 } | 28 } |
27 | 29 |
28 expect(actual, expected) { | 30 expect(actual, expected) { |
29 if (expected is Expectation) { | 31 if (expected is Expectation) { |
30 expected.check(actual); | 32 expected.check(actual); |
31 } else { | 33 } else { |
32 Expect.equals(expected, actual); | 34 Expect.equals(expected, actual); |
33 } | 35 } |
34 } | 36 } |
(...skipping 13 matching lines...) Expand all Loading... |
48 } else if (expected is String) { | 50 } else if (expected is String) { |
49 return new Expectation((actual) => Expect.stringEquals(expected, actual)); | 51 return new Expectation((actual) => Expect.stringEquals(expected, actual)); |
50 } else { | 52 } else { |
51 return new Expectation((actual) => Expect.equals(expected, actual)); | 53 return new Expectation((actual) => Expect.equals(expected, actual)); |
52 } | 54 } |
53 } | 55 } |
54 | 56 |
55 get throws => new Expectation((actual) => Expect.throws(actual)); | 57 get throws => new Expectation((actual) => Expect.throws(actual)); |
56 | 58 |
57 get isTrue => new Expectation((actual) => Expect.isTrue(actual)); | 59 get isTrue => new Expectation((actual) => Expect.isTrue(actual)); |
OLD | NEW |