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

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

Issue 183993003: Revert commits r33138, r33135, and r33134. (Closed) Base URL: https://dart.googlecode.com/svn/branches/bleeding_edge/dart
Patch Set: Created 6 years, 9 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 // This library contains tests for transformer behavior that relates to actions
6 // happening concurrently or other complex asynchronous timing behavior.
7 library barback.test.package_graph.transform.transform_test;
8
9 import 'package:barback/src/utils.dart';
10 import 'package:scheduled_test/scheduled_test.dart';
11
12 import '../../utils.dart';
13
14 main() {
15 initConfig();
16 test("gets a transformed asset with a different path", () {
17 initGraph(["app|foo.blub"], {"app": [
18 [new RewriteTransformer("blub", "blab")]
19 ]});
20 updateSources(["app|foo.blub"]);
21 expectAsset("app|foo.blab", "foo.blab");
22 buildShouldSucceed();
23 });
24
25 test("gets a transformed asset with the same path", () {
26 initGraph(["app|foo.blub"], {"app": [
27 [new RewriteTransformer("blub", "blub")]
28 ]});
29 updateSources(["app|foo.blub"]);
30 expectAsset("app|foo.blub", "foo.blub");
31 buildShouldSucceed();
32 });
33
34 test("doesn't find an output from a later phase", () {
35 initGraph(["app|foo.a"], {"app": [
36 [new RewriteTransformer("b", "c")],
37 [new RewriteTransformer("a", "b")]
38 ]});
39 updateSources(["app|foo.a"]);
40 expectNoAsset("app|foo.c");
41 buildShouldSucceed();
42 });
43
44 test("doesn't find an output from the same phase", () {
45 initGraph(["app|foo.a"], {"app": [
46 [
47 new RewriteTransformer("a", "b"),
48 new RewriteTransformer("b", "c")
49 ]
50 ]});
51 updateSources(["app|foo.a"]);
52 expectAsset("app|foo.b", "foo.b");
53 expectNoAsset("app|foo.c");
54 buildShouldSucceed();
55 });
56
57 test("finds the latest output before the transformer's phase", () {
58 initGraph(["app|foo.blub"], {"app": [
59 [new RewriteTransformer("blub", "blub")],
60 [
61 new RewriteTransformer("blub", "blub"),
62 new RewriteTransformer("blub", "done")
63 ],
64 [new RewriteTransformer("blub", "blub")]
65 ]});
66 updateSources(["app|foo.blub"]);
67 expectAsset("app|foo.done", "foo.blub.done");
68 buildShouldSucceed();
69 });
70
71 test("applies multiple transformations to an asset", () {
72 initGraph(["app|foo.a"], {"app": [
73 [new RewriteTransformer("a", "b")],
74 [new RewriteTransformer("b", "c")],
75 [new RewriteTransformer("c", "d")],
76 [new RewriteTransformer("d", "e")],
77 [new RewriteTransformer("e", "f")],
78 [new RewriteTransformer("f", "g")],
79 [new RewriteTransformer("g", "h")],
80 [new RewriteTransformer("h", "i")],
81 [new RewriteTransformer("i", "j")],
82 [new RewriteTransformer("j", "k")],
83 ]});
84 updateSources(["app|foo.a"]);
85 expectAsset("app|foo.k", "foo.b.c.d.e.f.g.h.i.j.k");
86 buildShouldSucceed();
87 });
88
89 test("only runs a transform once for all of its outputs", () {
90 var transformer = new RewriteTransformer("blub", "a b c");
91 initGraph(["app|foo.blub"], {"app": [[transformer]]});
92 updateSources(["app|foo.blub"]);
93 expectAsset("app|foo.a", "foo.a");
94 expectAsset("app|foo.b", "foo.b");
95 expectAsset("app|foo.c", "foo.c");
96 buildShouldSucceed();
97 expect(transformer.numRuns, completion(equals(1)));
98 });
99
100 test("outputs are passed through transformers by default", () {
101 initGraph(["app|foo.a"], {"app": [
102 [new RewriteTransformer("a", "b")],
103 [new RewriteTransformer("a", "c")]
104 ]});
105 updateSources(["app|foo.a"]);
106 expectAsset("app|foo.a", "foo");
107 expectAsset("app|foo.b", "foo.b");
108 expectAsset("app|foo.c", "foo.c");
109 buildShouldSucceed();
110 });
111
112 test("does not reapply transform when inputs are not modified", () {
113 var transformer = new RewriteTransformer("blub", "blab");
114 initGraph(["app|foo.blub"], {"app": [[transformer]]});
115 updateSources(["app|foo.blub"]);
116 expectAsset("app|foo.blab", "foo.blab");
117 expectAsset("app|foo.blab", "foo.blab");
118 expectAsset("app|foo.blab", "foo.blab");
119 buildShouldSucceed();
120
121 expect(transformer.numRuns, completion(equals(1)));
122 });
123
124 test("reapplies a transform when its input is modified", () {
125 var transformer = new RewriteTransformer("blub", "blab");
126 initGraph(["app|foo.blub"], {"app": [[transformer]]});
127
128 updateSources(["app|foo.blub"]);
129 expectAsset("app|foo.blab", "foo.blab");
130 buildShouldSucceed();
131
132 updateSources(["app|foo.blub"]);
133 expectAsset("app|foo.blab", "foo.blab");
134 buildShouldSucceed();
135
136 updateSources(["app|foo.blub"]);
137 expectAsset("app|foo.blab", "foo.blab");
138 buildShouldSucceed();
139
140 expect(transformer.numRuns, completion(equals(3)));
141 });
142
143 test("does not reapply transform when a removed input is modified", () {
144 var transformer = new ManyToOneTransformer("txt");
145 initGraph({
146 "app|a.txt": "a.inc,b.inc",
147 "app|a.inc": "a",
148 "app|b.inc": "b"
149 }, {"app": [[transformer]]});
150
151 updateSources(["app|a.txt", "app|a.inc", "app|b.inc"]);
152
153 expectAsset("app|a.out", "ab");
154 buildShouldSucceed();
155
156 // Remove the dependency on the non-primary input.
157 modifyAsset("app|a.txt", "a.inc");
158 updateSources(["app|a.txt"]);
159
160 // Process it again.
161 expectAsset("app|a.out", "a");
162 buildShouldSucceed();
163
164 // Now touch the removed input. It should not trigger another build.
165 updateSources(["app|b.inc"]);
166 expectAsset("app|a.out", "a");
167 buildShouldSucceed();
168
169 expect(transformer.numRuns, completion(equals(2)));
170 });
171
172 test("allows a transform to generate multiple outputs", () {
173 initGraph({"app|foo.txt": "a.out,b.out"}, {"app": [
174 [new OneToManyTransformer("txt")]
175 ]});
176
177 updateSources(["app|foo.txt"]);
178
179 expectAsset("app|a.out", "spread txt");
180 expectAsset("app|b.out", "spread txt");
181 buildShouldSucceed();
182 });
183
184 test("does not rebuild transforms that don't use modified source", () {
185 var a = new RewriteTransformer("a", "aa");
186 var aa = new RewriteTransformer("aa", "aaa");
187 var b = new RewriteTransformer("b", "bb");
188 var bb = new RewriteTransformer("bb", "bbb");
189 initGraph(["app|foo.a", "app|foo.b"], {"app": [
190 [a, b],
191 [aa, bb],
192 ]});
193
194 updateSources(["app|foo.a"]);
195 updateSources(["app|foo.b"]);
196
197 expectAsset("app|foo.aaa", "foo.aa.aaa");
198 expectAsset("app|foo.bbb", "foo.bb.bbb");
199 buildShouldSucceed();
200
201 updateSources(["app|foo.a"]);
202 expectAsset("app|foo.aaa", "foo.aa.aaa");
203 expectAsset("app|foo.bbb", "foo.bb.bbb");
204 buildShouldSucceed();
205
206 expect(aa.numRuns, completion(equals(2)));
207 expect(bb.numRuns, completion(equals(1)));
208 });
209
210 test("doesn't get an output from a transform whose primary input is removed",
211 () {
212 initGraph(["app|foo.txt"], {"app": [
213 [new RewriteTransformer("txt", "out")]
214 ]});
215
216 updateSources(["app|foo.txt"]);
217 expectAsset("app|foo.out", "foo.out");
218 buildShouldSucceed();
219
220 removeSources(["app|foo.txt"]);
221 expectNoAsset("app|foo.out");
222 buildShouldSucceed();
223 });
224
225 test("reapplies a transform when a non-primary input changes", () {
226 initGraph({
227 "app|a.txt": "a.inc",
228 "app|a.inc": "a"
229 }, {"app": [[new ManyToOneTransformer("txt")]]});
230
231 updateSources(["app|a.txt", "app|a.inc"]);
232 expectAsset("app|a.out", "a");
233 buildShouldSucceed();
234
235 modifyAsset("app|a.inc", "after");
236 updateSources(["app|a.inc"]);
237
238 expectAsset("app|a.out", "after");
239 buildShouldSucceed();
240 });
241
242 test("applies a transform when it becomes newly primary", () {
243 initGraph({
244 "app|foo.txt": "this",
245 }, {"app": [[new CheckContentTransformer("that", " and the other")]]});
246
247 updateSources(["app|foo.txt"]);
248 expectAsset("app|foo.txt", "this");
249 buildShouldSucceed();
250
251 modifyAsset("app|foo.txt", "that");
252 updateSources(["app|foo.txt"]);
253
254 expectAsset("app|foo.txt", "that and the other");
255 buildShouldSucceed();
256 });
257
258 test("handles an output moving from one transformer to another", () {
259 // In the first run, "shared.out" is created by the "a.a" transformer.
260 initGraph({
261 "app|a.a": "a.out,shared.out",
262 "app|b.b": "b.out"
263 }, {"app": [
264 [new OneToManyTransformer("a"), new OneToManyTransformer("b")]
265 ]});
266
267 updateSources(["app|a.a", "app|b.b"]);
268
269 expectAsset("app|a.out", "spread a");
270 expectAsset("app|b.out", "spread b");
271 expectAsset("app|shared.out", "spread a");
272 buildShouldSucceed();
273
274 // Now switch their contents so that "shared.out" will be output by "b.b"'s
275 // transformer.
276 modifyAsset("app|a.a", "a.out");
277 modifyAsset("app|b.b", "b.out,shared.out");
278 updateSources(["app|a.a", "app|b.b"]);
279
280 expectAsset("app|a.out", "spread a");
281 expectAsset("app|b.out", "spread b");
282 expectAsset("app|shared.out", "spread b");
283 buildShouldSucceed();
284 });
285
286 test("applies transforms to the correct packages", () {
287 var rewrite1 = new RewriteTransformer("txt", "out1");
288 var rewrite2 = new RewriteTransformer("txt", "out2");
289 initGraph([
290 "pkg1|foo.txt",
291 "pkg2|foo.txt"
292 ], {"pkg1": [[rewrite1]], "pkg2": [[rewrite2]]});
293
294 updateSources(["pkg1|foo.txt", "pkg2|foo.txt"]);
295 expectAsset("pkg1|foo.out1", "foo.out1");
296 expectAsset("pkg2|foo.out2", "foo.out2");
297 buildShouldSucceed();
298 });
299
300 test("transforms don't see generated assets in other packages", () {
301 var fooToBar = new RewriteTransformer("foo", "bar");
302 var barToBaz = new RewriteTransformer("bar", "baz");
303 initGraph(["pkg1|file.foo"], {"pkg1": [[fooToBar]], "pkg2": [[barToBaz]]});
304
305 updateSources(["pkg1|file.foo"]);
306 expectAsset("pkg1|file.bar", "file.bar");
307 expectNoAsset("pkg2|file.baz");
308 buildShouldSucceed();
309 });
310
311 test("removes pipelined transforms when the root primary input is removed",
312 () {
313 initGraph(["app|foo.txt"], {"app": [
314 [new RewriteTransformer("txt", "mid")],
315 [new RewriteTransformer("mid", "out")]
316 ]});
317
318 updateSources(["app|foo.txt"]);
319 expectAsset("app|foo.out", "foo.mid.out");
320 buildShouldSucceed();
321
322 removeSources(["app|foo.txt"]);
323 expectNoAsset("app|foo.out");
324 buildShouldSucceed();
325 });
326
327 test("removes pipelined transforms when the parent ceases to generate the "
328 "primary input", () {
329 initGraph({"app|foo.txt": "foo.mid"}, {'app': [
330 [new OneToManyTransformer('txt')],
331 [new RewriteTransformer('mid', 'out')]
332 ]});
333
334 updateSources(['app|foo.txt']);
335 expectAsset('app|foo.out', 'spread txt.out');
336 buildShouldSucceed();
337
338 modifyAsset("app|foo.txt", "bar.mid");
339 updateSources(["app|foo.txt"]);
340 expectNoAsset('app|foo.out');
341 expectAsset('app|bar.out', 'spread txt.out');
342 buildShouldSucceed();
343 });
344 }
OLDNEW
« no previous file with comments | « pkg/barback/test/package_graph/transform/pass_through_test.dart ('k') | pkg/barback/test/package_graph/transform_test.dart » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698