Chromium Code Reviews| Index: lib/unittest/expect.dart |
| =================================================================== |
| --- lib/unittest/expect.dart (revision 8732) |
| +++ lib/unittest/expect.dart (working copy) |
| @@ -33,7 +33,20 @@ |
| * [dart-matchers] https://github.com/Ladicek/dart-matchers |
| */ |
| void expect(actual, [matcherOrReason = null, String reason = '']) { |
|
eub
2012/06/15 21:02:49
BTW, I imagine you had prior review discussion of
gram
2012/06/15 21:25:55
Yes - the aim is to have just one expect(), but to
|
| - if (matcherOrReason is Matcher) { |
| + if (actual is bool && |
| + (matcherOrReason == null || matcherOrReason is String)) { |
| + // Treat this as an assert(predicate, reason). |
| + if (!actual) { |
| + reason = (matcherOrReason == null) ? 'Assertion failed' : matcherOrReason; |
| + // Make sure we have a failure handler configured. |
| + configureExpectHandler(_assertFailureHandler); |
| + _assertFailureHandler.fail(reason); |
| + } |
| + } else { |
| + // Treat this as an expect(value, matcher, [reason]). |
| + if (matcherOrReason is! Matcher) { |
| + matcherOrReason = wrapMatcher(matcherOrReason); |
| + } |
| var doesMatch; |
| try { |
| doesMatch = matcherOrReason.matches(actual); |
| @@ -48,13 +61,6 @@ |
| configureExpectHandler(_assertFailureHandler); |
| _assertFailureHandler.failMatch(actual, matcherOrReason, reason); |
| } |
| - } else { |
| - if (!actual) { |
| - reason = (matcherOrReason == null) ? 'Assertion failed' : matcherOrReason; |
| - // Make sure we have a failure handler configured. |
| - configureExpectHandler(_assertFailureHandler); |
| - _assertFailureHandler.fail(reason); |
| - } |
| } |
| } |