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

Unified Diff: pkg/barback/test/utils.dart

Issue 22961002: Add more metadata to non-programmatic barback exceptions. (Closed) Base URL: https://dart.googlecode.com/svn/branches/bleeding_edge/dart
Patch Set: Small fix Created 7 years, 4 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 | « pkg/barback/test/package_graph/errors_test.dart ('k') | no next file » | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: pkg/barback/test/utils.dart
diff --git a/pkg/barback/test/utils.dart b/pkg/barback/test/utils.dart
index 1de4ac9d478836d53c18387a70f911062eadb6b7..99a7ec1d19d776d8101c08aeef52dc25a0a7bba2 100644
--- a/pkg/barback/test/utils.dart
+++ b/pkg/barback/test/utils.dart
@@ -260,16 +260,32 @@ Matcher isMissingInputException(String name) {
predicate((error) => error.id == id, 'id == $name'));
}
-/// Returns a matcher for an [InvalidOutputException] with the given id and
-/// package name.
-Matcher isInvalidOutputException(String package, String name) {
+/// Returns a matcher for an [InvalidOutputException] with the given id.
+Matcher isInvalidOutputException(String name) {
var id = new AssetId.parse(name);
return allOf(
new isInstanceOf<InvalidOutputException>(),
- predicate((error) => error.package == package, 'package is $package'),
predicate((error) => error.id == id, 'id == $name'));
}
+/// Returns a matcher for an [AssetLoadException] with the given id and a
+/// wrapped error that matches [error].
+Matcher isAssetLoadException(String name, error) {
+ var id = new AssetId.parse(name);
+ return allOf(
+ new isInstanceOf<AssetLoadException>(),
+ transform((error) => error.id, equals(id), 'id'),
+ transform((error) => error.error, wrapMatcher(error), 'error'));
+}
+
+/// Returns a matcher for a [TransformerException] with a wrapped error that
+/// matches [error].
+Matcher isTransformerException(error) {
+ return allOf(
+ new isInstanceOf<TransformerException>(),
+ transform((error) => error.error, wrapMatcher(error), 'error'));
+}
+
/// Returns a matcher for a [MockLoadException] with the given [id].
Matcher isMockLoadException(String name) {
var id = new AssetId.parse(name);
@@ -278,6 +294,28 @@ Matcher isMockLoadException(String name) {
predicate((error) => error.id == id, 'id == $name'));
}
+/// Returns a matcher that runs [transformation] on its input, then matches
+/// the output against [matcher].
+///
+/// [description] should be a noun phrase that describes the relation of the
+/// output of [transformation] to its input.
+Matcher transform(transformation(value), matcher, String description) =>
+ new _TransformMatcher(transformation, wrapMatcher(matcher), description);
+
+class _TransformMatcher extends Matcher {
+ final Function _transformation;
+ final Matcher _matcher;
+ final String _description;
+
+ _TransformMatcher(this._transformation, this._matcher, this._description);
+
+ bool matches(item, Map matchState) =>
+ _matcher.matches(_transformation(item), matchState);
+
+ Description describe(Description description) =>
+ description.add(_description).add(' ').addDescriptionOf(_matcher);
+}
+
/// Asserts that [future] shouldn't complete until after [delay] completes.
///
/// Once [delay] completes, the output of [future] is ignored, even if it's an
« no previous file with comments | « pkg/barback/test/package_graph/errors_test.dart ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698