Chromium Code Reviews| Index: pkg/barback/test/utils.dart |
| diff --git a/pkg/barback/test/utils.dart b/pkg/barback/test/utils.dart |
| index 99a7ec1d19d776d8101c08aeef52dc25a0a7bba2..7ebf774dd132a2ed1d2e2baab277bf8970475842 100644 |
| --- a/pkg/barback/test/utils.dart |
| +++ b/pkg/barback/test/utils.dart |
| @@ -9,7 +9,6 @@ import 'dart:collection'; |
| import 'dart:io'; |
| import 'package:barback/barback.dart'; |
| -import 'package:barback/src/asset_set.dart'; |
| import 'package:barback/src/cancelable_future.dart'; |
| import 'package:barback/src/utils.dart'; |
| import 'package:path/path.dart' as pathos; |
| @@ -223,6 +222,39 @@ void expectNoAsset(String name) { |
| }, "get asset $name"); |
| } |
| +/// Schedules an expectation that the graph will output all of the given |
| +/// assets, and no others. |
| +/// |
| +/// [assets] is a list of strings that can be parsed to [AssetID]s. |
| +void expectAllAssets(Iterable<String> assets) { |
| + var expected = assets.map((asset) => new AssetId.parse(asset)); |
| + |
| + schedule(() { |
| + return _barback.getAllAssets().then((actualAssets) { |
| + var actualIds = actualAssets.map((asset) => asset.id).toSet(); |
| + |
| + for (var expected in expected) { |
|
nweiz
2013/08/20 22:29:03
I'm not a fan of shadowing this variable name.
Bob Nystrom
2013/08/21 18:10:23
Done. Mistake.
|
| + expect(actualIds, contains(expected)); |
| + actualIds.remove(expected); |
| + } |
| + |
| + expect(actualIds, isEmpty); |
| + }); |
| + }, "get all assets, expecting ${expected.join(', ')}"); |
| +} |
| + |
| +/// Schedules an expectation that [Barback.getAllAssets] will return a [Future] |
| +/// that completes to a error that matches [matcher]. |
| +/// |
| +/// If [match] is a [List], then it expects the completed error to be an |
| +/// [AggregateException] whose errors match each matcher in the list. Otherwise, |
| +/// [match] should be a single matcher that the error should match. |
| +void expectAllAssetsShouldFail(Matcher matcher) { |
| + schedule(() { |
| + expect(_barback.getAllAssets(), throwsA(matcher)); |
| + }, "get all assets should fail"); |
| +} |
| + |
| /// Schedules an expectation that a [getAssetById] call for the given asset |
| /// won't terminate at this point in the schedule. |
| void expectAssetDoesNotComplete(String name) { |
| @@ -236,6 +268,25 @@ void expectAssetDoesNotComplete(String name) { |
| }, "asset $id should not complete"); |
| } |
| +/// Returns a matcher for an [AggregateException] containing errors that match |
| +/// [matchers]. |
| +Matcher isAggregateException(Iterable<Matcher> errors) { |
| + // Match the aggregate error itself. |
| + var matchers = [ |
| + new isInstanceOf<AggregateException>(), |
| + transform((error) => error.errors, hasLength(errors.length), |
| + 'errors.length == ${errors.length}') |
| + ]; |
| + |
| + // Make sure its contained errors match the matchers. |
| + for (var error in errors) { |
| + matchers.add(transform((error) => error.errors, contains(error), |
| + error.toString())); |
| + } |
| + |
| + return allOf(matchers); |
| +} |
| + |
| /// Returns a matcher for an [AssetNotFoundException] with the given [id]. |
| Matcher isAssetNotFoundException(String name) { |
| var id = new AssetId.parse(name); |