| OLD | NEW |
| (Empty) | |
| 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 |
| 3 // BSD-style license that can be found in the LICENSE file. |
| 4 |
| 5 /// A light-weight replacement for package:unittest. This library runs tests |
| 6 /// synchronously, and avoids using reflection. |
| 7 library light_unittest; |
| 8 |
| 9 import 'dart:async'; |
| 10 |
| 11 import 'async_helper.dart'; |
| 12 import '../pkg/expect/lib/expect.dart'; |
| 13 |
| 14 test(name, f) { |
| 15 print('Testing $name'); |
| 16 try { |
| 17 f(); |
| 18 print('PASS: $name'); |
| 19 } catch (e, trace) { |
| 20 print('FAIL: $name.'); |
| 21 print(e); |
| 22 print(trace); |
| 23 asyncStart(); |
| 24 Timer.run(() { throw new StateError('FAILED: $name.\n$e\n$trace'); }); |
| 25 } |
| 26 } |
| 27 |
| 28 expect(actual, expected) { |
| 29 if (expected is Expectation) { |
| 30 expected.check(actual); |
| 31 } else { |
| 32 Expect.equals(expected, actual); |
| 33 } |
| 34 } |
| 35 |
| 36 class Expectation { |
| 37 final check; |
| 38 Expectation(this.check); |
| 39 } |
| 40 |
| 41 equals(expected) { |
| 42 if (expected is List) { |
| 43 return new Expectation((actual) => Expect.listEquals(expected, actual)); |
| 44 } else if (expected is Map) { |
| 45 return new Expectation((actual) => Expect.mapEquals(expected, actual)); |
| 46 } else if (expected is Set) { |
| 47 return new Expectation((actual) => Expect.setEquals(expected, actual)); |
| 48 } else if (expected is String) { |
| 49 return new Expectation((actual) => Expect.stringEquals(expected, actual)); |
| 50 } else { |
| 51 return new Expectation((actual) => Expect.equals(expected, actual)); |
| 52 } |
| 53 } |
| 54 |
| 55 get throws => new Expectation((actual) => Expect.throws(actual)); |
| 56 |
| 57 get isTrue => new Expectation((actual) => Expect.isTrue(actual)); |
| 58 |
| 59 expectAsync1(then) { |
| 60 asyncStart(); |
| 61 return (x) { |
| 62 asyncEnd(); |
| 63 return then(x); |
| 64 }; |
| 65 } |
| OLD | NEW |