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

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

Issue 14600029: Add pretty-printing to unittest and more thoroughly print values. (Closed) Base URL: https://dart.googlecode.com/svn/branches/bleeding_edge/dart
Patch Set: Code review changes. Created 7 years, 7 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/core_matchers.dart
diff --git a/pkg/unittest/lib/src/core_matchers.dart b/pkg/unittest/lib/src/core_matchers.dart
index 980e7a098b8905e2ba9eb594efb268e93de18dc4..1c8d2f6a337b0cf329d843b4a33a4a759700d62a 100644
--- a/pkg/unittest/lib/src/core_matchers.dart
+++ b/pkg/unittest/lib/src/core_matchers.dart
@@ -173,26 +173,14 @@ class _DeepMatcher extends BaseMatcher {
}
} else {
reason = new StringDescription();
- var eType = typeName(expected);
- var aType = typeName(actual);
- var includeTypes = eType != aType;
// If we have recursed, show the expected value too; if not,
// expect() will show it for us.
if (depth > 0) {
reason.add('expected ');
- if (includeTypes) {
- reason.add(eType).add(':');
- }
reason.addDescriptionOf(expected).add(' but ');
}
reason.add('was ');
- if (includeTypes) {
- reason.add(aType).add(':');
- }
reason.addDescriptionOf(actual);
- if (includeTypes && depth == 0) {
- reason.add(' (not type ').add(eType).add(')');
- }
}
}
if (reason != null && location.length > 0) {
@@ -201,17 +189,6 @@ class _DeepMatcher extends BaseMatcher {
return reason;
}
- String typeName(x) {
- // dart2js blows up on some objects (e.g. window.navigator).
- // So we play safe here.
- try {
- if (x == null) return "null";
- return x.runtimeType.toString();
- } catch (e) {
- return "Unknown";
- }
- }
-
String _match(expected, actual) {
Description reason = _recursiveMatch(expected, actual, '', 0);
return reason == null ? null : reason.toString();
@@ -583,17 +560,16 @@ class _HasLength extends BaseMatcher {
Description describeMismatch(item, Description mismatchDescription,
MatchState matchState, bool verbose) {
- super.describeMismatch(item, mismatchDescription, matchState, verbose);
try {
// We want to generate a different description if there is no length
// property. This is harmless code that will throw if no length property
// but subtle enough that an optimizer shouldn't strip it out.
if (item.length * item.length >= 0) {
- return mismatchDescription.add(' with length of ').
+ return mismatchDescription.add('had length of ').
addDescriptionOf(item.length);
}
} catch (e) {
- return mismatchDescription.add(' has no length property');
+ return mismatchDescription.add('had no length property');
}
}
}

Powered by Google App Engine
This is Rietveld 408576698