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

Unified Diff: pkg/unittest/lib/src/expect.dart

Issue 16408019: Improved error messages from unittest. (Closed) Base URL: http://dart.googlecode.com/svn/branches/bleeding_edge/dart/
Patch Set: Created 7 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
Index: pkg/unittest/lib/src/expect.dart
===================================================================
--- pkg/unittest/lib/src/expect.dart (revision 24002)
+++ pkg/unittest/lib/src/expect.dart (working copy)
@@ -17,6 +17,19 @@
}
/**
+ * Useful utility for nesting match states.
+ */
+
+void addStateInfo(Map matchState, Map values) {
+ var innerState = new Map.from(matchState);
+ matchState.clear();
+ matchState['state'] = innerState;
+ for (var key in values.keys) {
Siggi Cherem (dart-lang) 2013/06/14 01:20:56 I believe now you can do matchState.addAll(values)
+ matchState[key] = values[key];
+ }
+}
+
+/**
* Some matchers, like those for Futures and exception testing,
* can fail in asynchronous sections, and throw exceptions.
* A user of this library will typically want to catch and handle
@@ -51,7 +64,7 @@
bool verbose : false}) {
matcher = wrapMatcher(matcher);
bool doesMatch;
- var matchState = new MatchState();
+ var matchState = {};
try {
doesMatch = matcher.matches(actual, matchState);
} catch (e, trace) {
@@ -105,7 +118,7 @@
throw new TestFailure(reason);
}
void failMatch(actual, Matcher matcher, String reason,
- MatchState matchState, bool verbose) {
+ Map matchState, bool verbose) {
fail(_assertErrorFormatter(actual, matcher, reason, matchState, verbose));
}
}
@@ -135,16 +148,17 @@
// The default error formatter implementation.
String _defaultErrorFormatter(actual, Matcher matcher, String reason,
- MatchState matchState, bool verbose) {
+ Map matchState, bool verbose) {
var description = new StringDescription();
description.add('Expected: ').addDescriptionOf(matcher).add('\n');
+ description.add(' Actual: ').addDescriptionOf(actual);
var mismatchDescription = new StringDescription();
matcher.describeMismatch(actual, mismatchDescription, matchState, verbose);
- description.add(' But: ')
- .add(mismatchDescription.toString()).add('.\n');
- description.add('Actual: ').addDescriptionOf(actual);
+ if (mismatchDescription.length > 0) {
+ description.add(' Which: ${mismatchDescription}\n');
+ }
if (reason != null) {
description.add(reason).add('\n');
}

Powered by Google App Engine
This is Rietveld 408576698