Chromium Code Reviews| Index: tests/lib/unittest/testers.dart |
| =================================================================== |
| --- tests/lib/unittest/testers.dart (revision 0) |
| +++ tests/lib/unittest/testers.dart (revision 0) |
| @@ -0,0 +1,43 @@ |
| +// Copyright (c) 2012, the Dart project authors. Please see the AUTHORS file |
| +// for details. All rights reserved. Use of this source code is governed by a |
| +// BSD-style license that can be found in the LICENSE file. |
| + |
|
Siggi Cherem (dart-lang)
2012/06/13 23:43:53
let's rename this file, ideas:
- test_utils.dart
-
gram
2012/06/14 00:50:58
Done.
|
| +int errorCount; |
| +String errorString; |
| +var _testHandler = null; |
| + |
| +class MyFailureHandler extends DefaultFailureHandler { |
| + void fail(String reason) { |
| + ++errorCount; |
| + errorString = reason; |
| + } |
| +} |
| + |
| +void initTesters() { |
|
Siggi Cherem (dart-lang)
2012/06/13 23:43:53
rename according to file rename...
gram
2012/06/14 00:50:58
Done.
|
| + if (_testHandler == null) { |
| + _testHandler = new MyFailureHandler(); |
| + } |
| +} |
| + |
| +void shouldFail(var value, Matcher matcher, expected) { |
|
Bob Nystrom
2012/06/13 23:52:29
Don't need "var" here.
gram
2012/06/14 00:50:58
Done.
|
| + configureExpectHandler(_testHandler); |
| + errorCount = 0; |
| + errorString = ''; |
| + expect(value, matcher); |
| + configureExpectHandler(null); |
| + expect(errorCount, equals(1)); |
| + if (expected is String) |
|
Bob Nystrom
2012/06/13 23:52:29
Multi-line ifs should use curlies.
gram
2012/06/14 00:50:58
Done.
|
| + expect(errorString, equalsIgnoringWhitespace(expected)); |
| + else |
| + expect(errorString, expected); |
| +} |
| + |
| +void shouldPass(var value, Matcher matcher) { |
| + configureExpectHandler(_testHandler); |
| + errorCount = 0; |
| + errorString = ''; |
| + expect(value, matcher); |
| + configureExpectHandler(null); |
| + expect(errorCount, equals(0)); |
| +} |
| + |
|
Siggi Cherem (dart-lang)
2012/06/13 23:43:53
empty line
|