Chromium Code Reviews| Index: lib/unittest/expect.dart |
| =================================================================== |
| --- lib/unittest/expect.dart (revision 9135) |
| +++ lib/unittest/expect.dart (working copy) |
| @@ -17,7 +17,9 @@ |
| * If the assertion fails, then the default behavior is to throw an |
| * [ExpectException], but this behavior can be changed by calling |
| * [configureExpectHandler] and providing an alternative handler that |
| - * implements the [IFailureHandler] interface. |
| + * implements the [IFailureHandler] interface. It is also possible to |
| + * pass a [failureHandler] to [expect] as a final parameter for fine- |
| + * grained control. |
| * |
| * expect() is a 3rd generation assertion mechanism, drawing |
| * inspiration from [Hamcrest] and Ladislav Thon's [dart-matchers] |
| @@ -27,7 +29,8 @@ |
| * [Hamcrest] http://http://code.google.com/p/hamcrest/ |
| * [dart-matchers] https://github.com/Ladicek/dart-matchers |
| */ |
| -void expect(actual, [matcher = isTrue, String reason = null]) { |
| +void expect(actual, [matcher = isTrue, String reason = null, |
| + failureHandler = null]) { |
| matcher = wrapMatcher(matcher); |
| var doesMatch; |
| try { |
| @@ -39,9 +42,14 @@ |
| } |
| } |
| if (!doesMatch) { |
| - // Make sure we have a failure handler configured. |
| - configureExpectHandler(_assertFailureHandler); |
| - _assertFailureHandler.failMatch(actual, matcher, reason); |
| + if (failureHandler == null) { |
| + // Make sure we have a failure handler configured. |
| + if (_assertFailureHandler == null) { |
| + configureExpectHandler(); |
| + } |
| + failureHandler = _assertFailureHandler; |
| + } |
| + failureHandler.failMatch(actual, matcher, reason); |
| } |
| } |
| @@ -92,6 +100,13 @@ |
| _assertFailureHandler = handler; |
| } |
| +FailureHandler getFailureHandler() { |
|
Siggi Cherem (dart-lang)
2012/06/26 21:35:44
please use a getter, or change to getOrCreateFailu
gram
2012/06/26 23:39:59
Done.
|
| + if (_assertFailureHandler == null) { |
| + configureExpectHandler(); |
| + } |
| + return _assertFailureHandler; |
| +} |
| + |
| // The error message formatter for failed asserts. |
| ErrorFormatter _assertErrorFormatter = null; |