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

Side by Side 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: 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 unified diff | Download patch | Annotate | Revision Log
OLDNEW
1 // Copyright (c) 2013, the Dart project authors. Please see the AUTHORS file 1 // Copyright (c) 2013, the Dart project authors. Please see the AUTHORS file
2 // for details. All rights reserved. Use of this source code is governed by a 2 // for details. All rights reserved. Use of this source code is governed by a
3 // BSD-style license that can be found in the LICENSE file. 3 // BSD-style license that can be found in the LICENSE file.
4 4
5 library barback.test.asset_graph.source_test; 5 library barback.test.asset_graph.source_test;
6 6
7 import 'dart:async'; 7 import 'dart:async';
8 8
9 import 'package:barback/barback.dart'; 9 import 'package:barback/barback.dart';
10 import 'package:barback/src/asset_graph.dart'; 10 import 'package:barback/src/asset_graph.dart';
11 import 'package:scheduled_test/scheduled_test.dart'; 11 import 'package:scheduled_test/scheduled_test.dart';
12 12
13 import '../utils.dart'; 13 import '../utils.dart';
14 14
15 main() { 15 main() {
16 initConfig(); 16 initConfig();
17 test("gets a source asset", () { 17 test("gets a source asset", () {
18 var provider = new MockProvider(["app|foo.txt"]); 18 initGraph(["app|foo.txt"]);
19 var graph = new AssetGraph(provider, []); 19 updateSources(["app|foo.txt"]);
20 graph.updateSources([new AssetId.parse("app|foo.txt")]); 20 expectAsset("app|foo.txt");
21
22 expectAsset(graph, "app|foo.txt");
23 }); 21 });
24 22
25 test("doesn't get an unknown source", () { 23 test("doesn't get an unknown source", () {
26 var provider = new MockProvider([]); 24 initGraph();
27 var graph = new AssetGraph(provider, []); 25 expectNoAsset("app|unknown.txt");
28
29 expectNoAsset(graph, "app|unknown.txt");
30 }); 26 });
31 27
32 test("doesn't get an unprovided source", () { 28 test("doesn't get an unprovided source", () {
33 var provider = new MockProvider([]); 29 initGraph();
34 var graph = new AssetGraph(provider, []); 30 updateSources(["app|unknown.txt"]);
35 31 expectNoAsset("app|unknown.txt");
36 graph.updateSources([new AssetId.parse("app|unknown.txt")]);
37 expectNoAsset(graph, "app|unknown.txt");
38 }); 32 });
39 33
40 test("doesn't get an asset that isn't an updated source", () { 34 test("doesn't get an asset that isn't an updated source", () {
41 var provider = new MockProvider(["app|foo.txt"]); 35 initGraph(["app|foo.txt"]);
42 var graph = new AssetGraph(provider, []);
43 36
44 // Sources must be explicitly made visible to barback by calling 37 // Sources must be explicitly made visible to barback by calling
45 // updateSources() on them. It isn't enough for the provider to be able 38 // updateSources() on them. It isn't enough for the provider to be able
46 // to provide it. 39 // to provide it.
47 // 40 //
48 // This lets you distinguish between sources that you want to be primaries 41 // This lets you distinguish between sources that you want to be primaries
49 // and the larger set of inputs that those primaries are allowed to pull in. 42 // and the larger set of inputs that those primaries are allowed to pull in.
50 expectNoAsset(graph, "app|foo.txt"); 43 expectNoAsset("app|foo.txt");
51 }); 44 });
52 45
53 test("gets a source asset if not transformed", () { 46 test("gets a source asset if not transformed", () {
54 var provider = new MockProvider(["app|foo.txt"]); 47 initGraph(["app|foo.txt"], [
55 var graph = new AssetGraph(provider, [
56 [new RewriteTransformer("nottxt", "whatever")] 48 [new RewriteTransformer("nottxt", "whatever")]
57 ]); 49 ]);
58 graph.updateSources([new AssetId.parse("app|foo.txt")]);
59 50
60 expectAsset(graph, "app|foo.txt"); 51 updateSources(["app|foo.txt"]);
52 expectAsset("app|foo.txt");
61 }); 53 });
62 54
63 test("doesn't get a removed source", () { 55 test("doesn't get a removed source", () {
64 var provider = new MockProvider(["app|foo.txt"]); 56 initGraph(["app|foo.txt"]);
65 var graph = new AssetGraph(provider, [[]]);
66 graph.updateSources([new AssetId.parse("app|foo.txt")]);
67 57
68 expectAsset(graph, "app|foo.txt"); 58 updateSources(["app|foo.txt"]);
59 expectAsset("app|foo.txt");
69 60
70 schedule(() { 61 schedule(() {
71 graph.removeSources([new AssetId.parse("app|foo.txt")]); 62 removeSources(["app|foo.txt"]);
72 }); 63 });
73 64
74 expectNoAsset(graph, "app|foo.txt"); 65 expectNoAsset("app|foo.txt");
75 }); 66 });
76 67
77 test("collapses redundant updates", () { 68 test("collapses redundant updates", () {
78 var provider = new MockProvider(["app|foo.blub"]);
79 var transformer = new RewriteTransformer("blub", "blab"); 69 var transformer = new RewriteTransformer("blub", "blab");
80 var graph = new AssetGraph(provider, [[transformer]]); 70 initGraph(["app|foo.blub"], [[transformer]]);
81 71
82 schedule(() { 72 schedule(() {
83 // Make a bunch of synchronous update calls. 73 // Make a bunch of synchronous update calls.
84 graph.updateSources([new AssetId.parse("app|foo.blub")]); 74 updateSources(["app|foo.blub"]);
85 graph.updateSources([new AssetId.parse("app|foo.blub")]); 75 updateSources(["app|foo.blub"]);
86 graph.updateSources([new AssetId.parse("app|foo.blub")]); 76 updateSources(["app|foo.blub"]);
87 graph.updateSources([new AssetId.parse("app|foo.blub")]); 77 updateSources(["app|foo.blub"]);
88 }); 78 });
89 79
90 expectAsset(graph, "app|foo.blab", "foo.blab"); 80 expectAsset("app|foo.blab", "foo.blab");
91 81
92 schedule(() { 82 schedule(() {
93 expect(transformer.numRuns, equals(1)); 83 expect(transformer.numRuns, equals(1));
94 }); 84 });
95 }); 85 });
96 86
97 test("a removal cancels out an update", () { 87 test("a removal cancels out an update", () {
98 var provider = new MockProvider(["app|foo.txt"]); 88 initGraph(["app|foo.txt"]);
99 var graph = new AssetGraph(provider, [[]]);
100 89
101 schedule(() { 90 schedule(() {
102 graph.updateSources([new AssetId.parse("app|foo.txt")]); 91 updateSources(["app|foo.txt"]);
103 graph.removeSources([new AssetId.parse("app|foo.txt")]); 92 removeSources(["app|foo.txt"]);
104 }); 93 });
105 94
106 expectNoAsset(graph, "app|foo.txt"); 95 expectNoAsset("app|foo.txt");
107 }); 96 });
108 97
109 test("an update cancels out a removal", () { 98 test("an update cancels out a removal", () {
110 var provider = new MockProvider(["app|foo.txt"]); 99 initGraph(["app|foo.txt"]);
111 var graph = new AssetGraph(provider, [[]]);
112 100
113 schedule(() { 101 schedule(() {
114 graph.removeSources([new AssetId.parse("app|foo.txt")]); 102 removeSources(["app|foo.txt"]);
115 graph.updateSources([new AssetId.parse("app|foo.txt")]); 103 updateSources(["app|foo.txt"]);
116 }); 104 });
117 105
118 expectAsset(graph, "app|foo.txt"); 106 expectAsset("app|foo.txt");
119 }); 107 });
120 108
121 test("restarts a build if a source is updated while sources are loading", () { 109 test("restarts a build if a source is updated while sources are loading", () {
122 var provider = new MockProvider(["app|foo.txt", "app|other.bar"]);
123 var transformer = new RewriteTransformer("txt", "out"); 110 var transformer = new RewriteTransformer("txt", "out");
124 var graph = new AssetGraph(provider, [[transformer]]); 111 initGraph(["app|foo.txt", "app|other.bar"], [[transformer]]);
125
126 var numBuilds = 0;
127 var buildCompleter = new Completer();
128 graph.results.listen(wrapAsync((result) {
129 expect(result.error, isNull);
130 numBuilds++;
131
132 // There should be two builds, one for each update call.
133 if (numBuilds == 2) buildCompleter.complete();
134 }));
135 112
136 // Run the whole graph so all nodes are clean. 113 // Run the whole graph so all nodes are clean.
137 graph.updateSources([ 114 updateSources(["app|foo.txt", "app|other.bar"]);
138 new AssetId.parse("app|foo.txt"), 115 expectAsset("app|foo.out", "foo.out");
139 new AssetId.parse("app|other.bar") 116 expectAsset("app|other.bar");
140 ]); 117
141 expectAsset(graph, "app|foo.out", "foo.out"); 118 buildShouldSucceed();
142 expectAsset(graph, "app|other.bar"); 119
120 // Make the provider slow to load a source.
121 pauseProvider();
143 122
144 schedule(() { 123 schedule(() {
145 // Make the provider slow to load a source.
146 provider.wait();
147
148 // Update an asset that doesn't trigger any transformers. 124 // Update an asset that doesn't trigger any transformers.
149 graph.updateSources([new AssetId.parse("app|other.bar")]); 125 updateSources(["app|other.bar"]);
150 }); 126 });
151 127
152 schedule(() { 128 schedule(() {
153 // Now update an asset that does trigger a transformer. 129 // Now update an asset that does trigger a transformer.
154 graph.updateSources([new AssetId.parse("app|foo.txt")]); 130 updateSources(["app|foo.txt"]);
155 }); 131 });
156 132
157 schedule(() { 133 resumeProvider();
158 provider.complete(); 134 buildShouldSucceed();
159 });
160
161 schedule(() {
162 // Wait until the build has completed.
163 return buildCompleter.future;
164 });
165 135
166 schedule(() { 136 schedule(() {
167 expect(transformer.numRuns, equals(2)); 137 expect(transformer.numRuns, equals(2));
168 }); 138 });
169 }); 139 });
170 } 140 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698