| 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) { | 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 configureExpectFailureHandler(null); | 29 afterTest(_) { |
| 30 expect(errorCount, equals(1)); | 30 configureExpectFailureHandler(null); |
| 31 if (expected is String) { | 31 expect(errorCount, equals(1)); |
| 32 expect(errorString, equalsIgnoringWhitespace(expected)); | 32 if (expected is String) { |
| 33 expect(errorString, equalsIgnoringWhitespace(expected)); |
| 34 } else { |
| 35 expect(errorString, expected); |
| 36 } |
| 37 } |
| 38 |
| 39 if (isAsync) { |
| 40 new Timer(0, expectAsync1(afterTest)); |
| 33 } else { | 41 } else { |
| 34 expect(errorString, expected); | 42 afterTest(null); |
| 35 } | 43 } |
| 36 } | 44 } |
| 37 | 45 |
| 38 void shouldPass(value, Matcher matcher) { | 46 void shouldPass(value, Matcher matcher, {bool isAsync: false}) { |
| 39 configureExpectFailureHandler(_testHandler); | 47 configureExpectFailureHandler(_testHandler); |
| 40 errorCount = 0; | 48 errorCount = 0; |
| 41 errorString = ''; | 49 errorString = ''; |
| 42 expect(value, matcher); | 50 expect(value, matcher); |
| 43 configureExpectFailureHandler(null); | 51 afterTest(_) { |
| 44 expect(errorCount, equals(0)); | 52 configureExpectFailureHandler(null); |
| 53 expect(errorCount, equals(0)); |
| 54 } |
| 55 if (isAsync) { |
| 56 new Timer(0, expectAsync1(afterTest)); |
| 57 } else { |
| 58 afterTest(null); |
| 59 } |
| 45 } | 60 } |
| 46 | |
| OLD | NEW |