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

Side by Side Diff: pkg/barback/test/package_graph/transform/declaring_aggregate_test.dart

Issue 299833003: Expose aggregate transformers in barback. (Closed) Base URL: https://dart.googlecode.com/svn/branches/bleeding_edge/dart
Patch Set: Created 6 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 unified diff | Download patch | Annotate | Revision Log
OLDNEW
(Empty)
1 // Copyright (c) 2014, the Dart project authors. Please see the AUTHORS file
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.
4
5 library barback.test.package_graph.transform.declaring_aggregate_test;
6
7 import 'package:barback/src/utils.dart';
8 import 'package:scheduled_test/scheduled_test.dart';
9
10 import '../../utils.dart';
11
12 main() {
13 initConfig();
14 group("a declaring aggregate transformer", () {
15 test("is eager by default", () {
16 var transformer = new DeclaringAggregateManyToOneTransformer(
17 "txt", "out.txt");
18 initGraph(["app|foo.txt"], {"app": [[transformer]]});
19
20 updateSources(["app|foo.txt"]);
21 buildShouldSucceed();
22
23 expect(transformer.numRuns, completion(equals(1)));
24 });
25
26 test("is deferred if any primary input is deferred", () {
27 var rewrite = new LazyRewriteTransformer("in", "txt");
28 var aggregate = new DeclaringAggregateManyToOneTransformer(
29 "txt", "out.txt");
30 initGraph(["app|foo.in", "app|bar.txt", "app|baz.txt"], {"app": [
31 [rewrite]
32 ]});
33
34 updateSources(["app|foo.in", "app|bar.txt", "app|baz.txt"]);
35 buildShouldSucceed();
36
37 // Add [aggregate] to the graph after a build has been completed so that
38 // all its inputs are available immediately. Otherwise it could start
39 // applying eagerly before receiving its lazy input.
40 updateTransformers("app", [[rewrite], [aggregate]]);
41 buildShouldSucceed();
42 expect(aggregate.numRuns, completion(equals(0)));
43
44 expectAsset("app|out.txt", "bar\nbaz\nfoo.txt");
45 buildShouldSucceed();
46 expect(aggregate.numRuns, completion(equals(1)));
47 });
48
49 test("switches from eager to deferred if a deferred primary input is added",
50 () {
51 var transformer = new DeclaringAggregateManyToOneTransformer(
52 "txt", "out.txt");
53 initGraph(["app|foo.in", "app|bar.txt", "app|baz.txt"], {"app": [
54 [new LazyRewriteTransformer("in", "txt")],
55 [transformer]
56 ]});
57
58 updateSources(["app|bar.txt", "app|baz.txt"]);
59 buildShouldSucceed();
60 expect(transformer.numRuns, completion(equals(1)));
61
62 updateSources(["app|foo.in"]);
63 buildShouldSucceed();
64 expect(transformer.numRuns, completion(equals(1)));
65
66 expectAsset("app|out.txt", "bar\nbaz\nfoo.txt");
67 buildShouldSucceed();
68 expect(transformer.numRuns, completion(equals(2)));
69 });
70
71 test("switches from deferred to eager if its last deferred primary input "
72 "is removed", () {
73 var rewrite = new LazyRewriteTransformer("in", "txt");
74 var aggregate = new DeclaringAggregateManyToOneTransformer(
75 "txt", "out.txt");
76 initGraph(["app|foo.in", "app|bar.txt", "app|baz.txt"], {"app": [
77 [rewrite]
78 ]});
79
80 updateSources(["app|foo.in", "app|bar.txt", "app|baz.txt"]);
81 buildShouldSucceed();
82
83 // Add [aggregate] to the graph after a build has been completed so that
84 // all its inputs are available immediately. Otherwise it could start
85 // applying eagerly before receiving its lazy input.
86 updateTransformers("app", [[rewrite], [aggregate]]);
87 buildShouldSucceed();
88 expect(aggregate.numRuns, completion(equals(0)));
89
90 removeSources(["app|foo.in"]);
91 buildShouldSucceed();
92 expect(aggregate.numRuns, completion(equals(1)));
93 });
94
95 test("begins running eagerly when all its deferred primary inputs become "
96 "available", () {
97 var lazyPhase = [
98 new LazyAssetsTransformer(["app|foo.txt", "app|foo.x"],
99 input: "app|foo.in"),
100 new LazyAssetsTransformer(["app|bar.txt", "app|bar.x"],
101 input: "app|bar.in")
102 ];
103 var transformer = new DeclaringAggregateManyToOneTransformer(
104 "txt", "out.txt");
105 initGraph(["app|foo.in", "app|bar.in", "app|baz.txt"], {"app": [
106 lazyPhase,
107 ]});
108
109 updateSources(["app|foo.in", "app|bar.in", "app|baz.txt"]);
110 buildShouldSucceed();
111
112 // Add [transformer] to the graph after a build has been completed so that
113 // all its inputs are available immediately. Otherwise it could start
114 // applying eagerly before receiving its lazy inputs.
115 updateTransformers("app", [lazyPhase, [transformer]]);
116 buildShouldSucceed();
117 expect(transformer.numRuns, completion(equals(0)));
118
119 // Now "app|foo.txt" will be available, but "app|bar.txt" won't, so the
120 // [transformer] shouldn't run.
121 expectAsset("app|foo.x", "app|foo.x");
122 buildShouldSucceed();
123 expect(transformer.numRuns, completion(equals(0)));
124
125 // Now "app|foo.txt" and "app|bar.txt" will both be available, so the
126 // [transformer] should run.
127 expectAsset("app|bar.x", "app|bar.x");
128 buildShouldSucceed();
129 expect(transformer.numRuns, completion(equals(1)));
130 });
131
132 test("stops running eagerly when any of its deferred primary inputs become "
133 "unavailable", () {
134 var lazyPhase = [
135 new LazyAssetsTransformer(["app|foo.txt", "app|foo.x"],
136 input: "app|foo.in"),
137 new LazyAssetsTransformer(["app|bar.txt", "app|bar.x"],
138 input: "app|bar.in")
139 ];
140 var transformer = new DeclaringAggregateManyToOneTransformer(
141 "txt", "out.txt");
142 initGraph(["app|foo.in", "app|bar.in", "app|baz.txt"], {"app": [
143 lazyPhase
144 ]});
145
146 updateSources(["app|foo.in", "app|bar.in", "app|baz.txt"]);
147 expectAsset("app|foo.x", "app|foo.x");
148 expectAsset("app|bar.x", "app|bar.x");
149 buildShouldSucceed();
150
151
152 // Add [transformer] to the graph after a build has been completed so that
153 // all its inputs are available immediately. Otherwise it could start
154 // applying eagerly before receiving its lazy inputs.
155 updateTransformers("app", [lazyPhase, [transformer]]);
156 buildShouldSucceed();
157 expect(transformer.numRuns, completion(equals(1)));
158
159 // Now "app|foo.txt" is unavailable, so the [transformer] shouldn't run.
160 updateSources(["app|foo.in"]);
161 buildShouldSucceed();
162 expect(transformer.numRuns, completion(equals(1)));
163 });
164
165 test("re-declares its outputs for a new primary input", () {
166 initGraph(["app|foo.in", "app|bar.txt", "app|baz.txt"], {"app": [
167 [new LazyRewriteTransformer("in", "txt")],
168 [new DeclaringAggregateManyToManyTransformer("txt")]
169 ]});
170
171 updateSources(["app|foo.in", "app|bar.txt"]);
172 buildShouldSucceed();
173
174 updateSources(["app|baz.txt"]);
175 buildShouldSucceed();
176 expectAsset("app|baz.txt", "modified baz");
Bob Nystrom 2014/05/27 17:20:18 How does this test that the outputs are re-declare
nweiz 2014/05/27 21:03:10 Since one of its inputs is deferred, it's deferred
Bob Nystrom 2014/05/28 21:03:58 Ah, so this relies on requests for undeclared outp
nweiz 2014/05/28 23:32:12 Done.
177 });
178
179 test("re-declares its outputs for a new primary input received while "
180 "applying", () {
181 var transformer = new DeclaringAggregateManyToManyTransformer("txt");
182 initGraph(["app|foo.in", "app|bar.txt", "app|baz.txt"], {"app": [
183 [new LazyRewriteTransformer("in", "txt")],
184 [transformer]
185 ]});
186
187 transformer.pauseApply();
188 updateSources(["app|foo.in", "app|bar.txt"]);
189
190 // Ensure we're waiting on `apply()`.
191 schedule(pumpEventQueue);
192
193 updateSources(["app|baz.txt"]);
194 transformer.resumeApply();
195 buildShouldSucceed();
196
197 expectAsset("app|baz.txt", "modified baz");
198 });
199
200 test("re-declares its outputs for a new primary input received while "
201 "applying after a primary input was modified", () {
202 var transformer = new DeclaringAggregateManyToManyTransformer("txt");
203 initGraph(["app|foo.in", "app|bar.txt", "app|baz.txt"], {"app": [
204 [new LazyRewriteTransformer("in", "txt")],
205 [transformer]
206 ]});
207
208 transformer.pauseApply();
209 updateSources(["app|foo.in", "app|bar.txt"]);
210
211 // Ensure we're waiting on `apply()`.
212 schedule(pumpEventQueue);
213
214 updateSources(["app|bar.txt"]);
215
216 // Make sure the change to "bar.txt" is fully processed.
217 schedule(pumpEventQueue);
218
219 updateSources(["app|baz.txt"]);
220 transformer.resumeApply();
221 buildShouldSucceed();
222
223 expectAsset("app|baz.txt", "modified baz");
224 });
225 });
226
227 group("a lazy aggregate transformer", () {
228 test("doesn't run eagerly", () {
229 var transformer = new LazyAggregateManyToOneTransformer("txt", "out.txt");
230 initGraph(["app|foo.txt"], {"app": [[transformer]]});
231
232 updateSources(["app|foo.txt"]);
233 buildShouldSucceed();
234
235 expect(transformer.numRuns, completion(equals(0)));
236 });
237
238 test("runs when an output is requested", () {
239 initGraph(["app|foo.txt"], {"app": [[
240 new LazyAggregateManyToOneTransformer("txt", "out.txt")
241 ]]});
242
243 updateSources(["app|foo.txt"]);
244 buildShouldSucceed();
245 expectAsset("app|out.txt", "foo");
246 });
247 });
248 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698