OLD | NEW |
1 // Copyright (c) 2012, the Dart project authors. Please see the AUTHORS file | 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 | 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 part of unittestTests; | 5 part of unittestTests; |
6 | 6 |
7 int errorCount; | 7 int errorCount; |
8 String errorString; | 8 String errorString; |
9 var _testHandler = null; | 9 var _testHandler = null; |
10 | 10 |
11 class MyFailureHandler extends DefaultFailureHandler { | 11 class MyFailureHandler extends DefaultFailureHandler { |
12 void fail(String reason) { | 12 void fail(String reason) { |
13 ++errorCount; | 13 ++errorCount; |
14 errorString = reason; | 14 errorString = reason; |
15 } | 15 } |
16 } | 16 } |
17 | 17 |
18 void initUtils() { | 18 void initUtils() { |
19 if (_testHandler == null) { | 19 if (_testHandler == null) { |
20 _testHandler = new MyFailureHandler(); | 20 _testHandler = new MyFailureHandler(); |
21 } | 21 } |
22 } | 22 } |
23 | 23 |
24 void shouldFail(value, Matcher matcher, expected, {bool isAsync: false}) { | 24 void shouldFail(value, Matcher matcher, expected, {bool isAsync: false}) { |
25 configureExpectFailureHandler(_testHandler); | 25 configureExpectFailureHandler(_testHandler); |
26 errorCount = 0; | 26 errorCount = 0; |
27 errorString = ''; | 27 errorString = ''; |
28 expect(value, matcher); | 28 expect(value, matcher); |
29 afterTest(_) { | 29 afterTest() { |
30 configureExpectFailureHandler(null); | 30 configureExpectFailureHandler(null); |
31 expect(errorCount, equals(1)); | 31 expect(errorCount, equals(1)); |
32 if (expected is String) { | 32 if (expected is String) { |
33 expect(errorString, equalsIgnoringWhitespace(expected)); | 33 expect(errorString, equalsIgnoringWhitespace(expected)); |
34 } else { | 34 } else { |
35 expect(errorString, expected); | 35 expect(errorString, expected); |
36 } | 36 } |
37 } | 37 } |
38 | 38 |
39 if (isAsync) { | 39 if (isAsync) { |
40 new Timer(0, expectAsync1(afterTest)); | 40 Timer.run(expectAsync0(afterTest)); |
41 } else { | 41 } else { |
42 afterTest(null); | 42 afterTest(); |
43 } | 43 } |
44 } | 44 } |
45 | 45 |
46 void shouldPass(value, Matcher matcher, {bool isAsync: false}) { | 46 void shouldPass(value, Matcher matcher, {bool isAsync: false}) { |
47 configureExpectFailureHandler(_testHandler); | 47 configureExpectFailureHandler(_testHandler); |
48 errorCount = 0; | 48 errorCount = 0; |
49 errorString = ''; | 49 errorString = ''; |
50 expect(value, matcher); | 50 expect(value, matcher); |
51 afterTest(_) { | 51 afterTest() { |
52 configureExpectFailureHandler(null); | 52 configureExpectFailureHandler(null); |
53 expect(errorCount, equals(0)); | 53 expect(errorCount, equals(0)); |
54 } | 54 } |
55 if (isAsync) { | 55 if (isAsync) { |
56 new Timer(0, expectAsync1(afterTest)); | 56 Timer.run(expectAsync0(afterTest)); |
57 } else { | 57 } else { |
58 afterTest(null); | 58 afterTest(); |
59 } | 59 } |
60 } | 60 } |
OLD | NEW |