Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(82)

Unified Diff: lib/unittest/expect.dart

Issue 10544167: Some unit test fixes (Closed) Base URL: http://dart.googlecode.com/svn/branches/bleeding_edge/dart/
Patch Set: Created 8 years, 6 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
« no previous file with comments | « lib/unittest/core_matchers.dart ('k') | lib/unittest/unittest.dart » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: lib/unittest/expect.dart
===================================================================
--- lib/unittest/expect.dart (revision 8732)
+++ lib/unittest/expect.dart (working copy)
@@ -15,7 +15,7 @@
* implements the [IFailureHandler] interface.
*
* [expect] allows an alternative call format, providing a Boolean
- * predicate as the first argument and an optional reason as the
+ * predicate as the first argument and an optional reason as a named
* second argument. This supports brevity at the expense of detailed
* error messages. For example, these are equivalent, but the first
* form will give a detailed error message, while the second form will
@@ -24,6 +24,10 @@
* expect(foo, isLessThanOrEqual(bar));
* expect(foo <= bar);
*
+ * A better way of doing the second form is:
+ *
+ * expect(foo <= bar, reason: "foo not less than bar");
eub 2012/06/15 22:30:43 Utter nitpick: "foo not less than or equal to bar"
gram 2012/06/15 22:40:42 Done.
+ *
* expect() is a 3rd generation assertion mechanism, drawing
* inspiration from [Hamcrest] and Ladislav Thon's [dart-matchers]
* library.
@@ -32,11 +36,25 @@
* [Hamcrest] http://http://code.google.com/p/hamcrest/
* [dart-matchers] https://github.com/Ladicek/dart-matchers
*/
-void expect(actual, [matcherOrReason = null, String reason = '']) {
- if (matcherOrReason is Matcher) {
+void expect(actual, [matcher = null, String reason = '']) {
eub 2012/06/15 22:30:43 How do you like null instead of ''?
gram 2012/06/15 22:40:42 Done.
gram 2012/06/15 22:40:42 Done.
+ if (matcher == null) {
+ // Treat this as an assert(predicate, reason).
eub 2012/06/15 22:30:43 [reason]
gram 2012/06/15 22:40:42 Done.
+ if (!actual) {
+ if (reason == '') {
+ reason = 'Assertion failed';
+ }
+ // Make sure we have a failure handler configured.
+ configureExpectHandler(_assertFailureHandler);
+ _assertFailureHandler.fail(reason);
+ }
+ } else {
+ // Treat this as an expect(value, matcher, [reason]).
+ if (matcher is! Matcher) {
eub 2012/06/15 22:30:43 This is a duplicate "is" check w/ the one in wrapM
gram 2012/06/15 22:40:42 Done.
+ matcher = wrapMatcher(matcher);
+ }
var doesMatch;
try {
- doesMatch = matcherOrReason.matches(actual);
+ doesMatch = matcher.matches(actual);
} catch (var e, var trace) {
doesMatch = false;
if (reason == '') {
@@ -46,15 +64,8 @@
if (!doesMatch) {
// Make sure we have a failure handler configured.
configureExpectHandler(_assertFailureHandler);
- _assertFailureHandler.failMatch(actual, matcherOrReason, reason);
+ _assertFailureHandler.failMatch(actual, matcher, reason);
}
- } else {
- if (!actual) {
- reason = (matcherOrReason == null) ? 'Assertion failed' : matcherOrReason;
- // Make sure we have a failure handler configured.
- configureExpectHandler(_assertFailureHandler);
- _assertFailureHandler.fail(reason);
- }
}
}
« no previous file with comments | « lib/unittest/core_matchers.dart ('k') | lib/unittest/unittest.dart » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698