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

Unified Diff: pkg/barback/test/asset_graph/source_test.dart

Issue 17507003: Clean up barback tests. (Closed) Base URL: https://dart.googlecode.com/svn/branches/bleeding_edge/dart
Patch Set: Revise. 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/barback/test/asset_graph/source_test.dart
diff --git a/pkg/barback/test/asset_graph/source_test.dart b/pkg/barback/test/asset_graph/source_test.dart
index 32d7f3d0f0f3696f68e0c092639b1b3f1b39ebb9..59ec62dfee8f4f28cbd4573ea995f69e9f166b5c 100644
--- a/pkg/barback/test/asset_graph/source_test.dart
+++ b/pkg/barback/test/asset_graph/source_test.dart
@@ -15,31 +15,24 @@ import '../utils.dart';
main() {
initConfig();
test("gets a source asset", () {
- var provider = new MockProvider(["app|foo.txt"]);
- var graph = new AssetGraph(provider, []);
- graph.updateSources([new AssetId.parse("app|foo.txt")]);
-
- expectAsset(graph, "app|foo.txt");
+ initGraph(["app|foo.txt"]);
+ updateSources(["app|foo.txt"]);
+ expectAsset("app|foo.txt");
});
test("doesn't get an unknown source", () {
- var provider = new MockProvider([]);
- var graph = new AssetGraph(provider, []);
-
- expectNoAsset(graph, "app|unknown.txt");
+ initGraph();
+ expectNoAsset("app|unknown.txt");
});
test("doesn't get an unprovided source", () {
- var provider = new MockProvider([]);
- var graph = new AssetGraph(provider, []);
-
- graph.updateSources([new AssetId.parse("app|unknown.txt")]);
- expectNoAsset(graph, "app|unknown.txt");
+ initGraph();
+ updateSources(["app|unknown.txt"]);
+ expectNoAsset("app|unknown.txt");
});
test("doesn't get an asset that isn't an updated source", () {
- var provider = new MockProvider(["app|foo.txt"]);
- var graph = new AssetGraph(provider, []);
+ initGraph(["app|foo.txt"]);
// Sources must be explicitly made visible to barback by calling
// updateSources() on them. It isn't enough for the provider to be able
@@ -47,47 +40,44 @@ main() {
//
// This lets you distinguish between sources that you want to be primaries
// and the larger set of inputs that those primaries are allowed to pull in.
- expectNoAsset(graph, "app|foo.txt");
+ expectNoAsset("app|foo.txt");
});
test("gets a source asset if not transformed", () {
- var provider = new MockProvider(["app|foo.txt"]);
- var graph = new AssetGraph(provider, [
+ initGraph(["app|foo.txt"], [
[new RewriteTransformer("nottxt", "whatever")]
]);
- graph.updateSources([new AssetId.parse("app|foo.txt")]);
- expectAsset(graph, "app|foo.txt");
+ updateSources(["app|foo.txt"]);
+ expectAsset("app|foo.txt");
});
test("doesn't get a removed source", () {
- var provider = new MockProvider(["app|foo.txt"]);
- var graph = new AssetGraph(provider, [[]]);
- graph.updateSources([new AssetId.parse("app|foo.txt")]);
+ initGraph(["app|foo.txt"]);
- expectAsset(graph, "app|foo.txt");
+ updateSources(["app|foo.txt"]);
+ expectAsset("app|foo.txt");
schedule(() {
- graph.removeSources([new AssetId.parse("app|foo.txt")]);
+ removeSources(["app|foo.txt"]);
});
- expectNoAsset(graph, "app|foo.txt");
+ expectNoAsset("app|foo.txt");
});
test("collapses redundant updates", () {
- var provider = new MockProvider(["app|foo.blub"]);
var transformer = new RewriteTransformer("blub", "blab");
- var graph = new AssetGraph(provider, [[transformer]]);
+ initGraph(["app|foo.blub"], [[transformer]]);
schedule(() {
// Make a bunch of synchronous update calls.
- graph.updateSources([new AssetId.parse("app|foo.blub")]);
- graph.updateSources([new AssetId.parse("app|foo.blub")]);
- graph.updateSources([new AssetId.parse("app|foo.blub")]);
- graph.updateSources([new AssetId.parse("app|foo.blub")]);
+ updateSources(["app|foo.blub"]);
+ updateSources(["app|foo.blub"]);
+ updateSources(["app|foo.blub"]);
+ updateSources(["app|foo.blub"]);
});
- expectAsset(graph, "app|foo.blab", "foo.blab");
+ expectAsset("app|foo.blab", "foo.blab");
schedule(() {
expect(transformer.numRuns, equals(1));
@@ -95,73 +85,53 @@ main() {
});
test("a removal cancels out an update", () {
- var provider = new MockProvider(["app|foo.txt"]);
- var graph = new AssetGraph(provider, [[]]);
+ initGraph(["app|foo.txt"]);
schedule(() {
- graph.updateSources([new AssetId.parse("app|foo.txt")]);
- graph.removeSources([new AssetId.parse("app|foo.txt")]);
+ updateSources(["app|foo.txt"]);
+ removeSources(["app|foo.txt"]);
});
- expectNoAsset(graph, "app|foo.txt");
+ expectNoAsset("app|foo.txt");
});
test("an update cancels out a removal", () {
- var provider = new MockProvider(["app|foo.txt"]);
- var graph = new AssetGraph(provider, [[]]);
+ initGraph(["app|foo.txt"]);
schedule(() {
- graph.removeSources([new AssetId.parse("app|foo.txt")]);
- graph.updateSources([new AssetId.parse("app|foo.txt")]);
+ removeSources(["app|foo.txt"]);
+ updateSources(["app|foo.txt"]);
});
- expectAsset(graph, "app|foo.txt");
+ expectAsset("app|foo.txt");
});
test("restarts a build if a source is updated while sources are loading", () {
- var provider = new MockProvider(["app|foo.txt", "app|other.bar"]);
var transformer = new RewriteTransformer("txt", "out");
- var graph = new AssetGraph(provider, [[transformer]]);
+ initGraph(["app|foo.txt", "app|other.bar"], [[transformer]]);
- var numBuilds = 0;
- var buildCompleter = new Completer();
- graph.results.listen(wrapAsync((result) {
- expect(result.error, isNull);
- numBuilds++;
+ // Run the whole graph so all nodes are clean.
+ updateSources(["app|foo.txt", "app|other.bar"]);
+ expectAsset("app|foo.out", "foo.out");
+ expectAsset("app|other.bar");
- // There should be two builds, one for each update call.
- if (numBuilds == 2) buildCompleter.complete();
- }));
+ buildShouldSucceed();
- // Run the whole graph so all nodes are clean.
- graph.updateSources([
- new AssetId.parse("app|foo.txt"),
- new AssetId.parse("app|other.bar")
- ]);
- expectAsset(graph, "app|foo.out", "foo.out");
- expectAsset(graph, "app|other.bar");
+ // Make the provider slow to load a source.
+ pauseProvider();
schedule(() {
- // Make the provider slow to load a source.
- provider.wait();
-
// Update an asset that doesn't trigger any transformers.
- graph.updateSources([new AssetId.parse("app|other.bar")]);
+ updateSources(["app|other.bar"]);
});
schedule(() {
// Now update an asset that does trigger a transformer.
- graph.updateSources([new AssetId.parse("app|foo.txt")]);
- });
-
- schedule(() {
- provider.complete();
+ updateSources(["app|foo.txt"]);
});
- schedule(() {
- // Wait until the build has completed.
- return buildCompleter.future;
- });
+ resumeProvider();
+ buildShouldSucceed();
schedule(() {
expect(transformer.numRuns, equals(2));

Powered by Google App Engine
This is Rietveld 408576698