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

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

Issue 182313012: Split barback's transform_test into multiple smaller test files. (Closed) Base URL: https://dart.googlecode.com/svn/branches/bleeding_edge/dart
Patch Set: code review 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
« no previous file with comments | « pkg/barback/test/package_graph/transform/transform_test.dart ('k') | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
(Empty)
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
3 // BSD-style license that can be found in the LICENSE file.
4
5 library barback.test.package_graph.transform_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 test("gets a transformed asset with a different path", () {
15 initGraph(["app|foo.blub"], {"app": [
16 [new RewriteTransformer("blub", "blab")]
17 ]});
18 updateSources(["app|foo.blub"]);
19 expectAsset("app|foo.blab", "foo.blab");
20 buildShouldSucceed();
21 });
22
23 test("gets a transformed asset with the same path", () {
24 initGraph(["app|foo.blub"], {"app": [
25 [new RewriteTransformer("blub", "blub")]
26 ]});
27 updateSources(["app|foo.blub"]);
28 expectAsset("app|foo.blub", "foo.blub");
29 buildShouldSucceed();
30 });
31
32 test("doesn't find an output from a later phase", () {
33 initGraph(["app|foo.a"], {"app": [
34 [new RewriteTransformer("b", "c")],
35 [new RewriteTransformer("a", "b")]
36 ]});
37 updateSources(["app|foo.a"]);
38 expectNoAsset("app|foo.c");
39 buildShouldSucceed();
40 });
41
42 test("doesn't find an output from the same phase", () {
43 initGraph(["app|foo.a"], {"app": [
44 [
45 new RewriteTransformer("a", "b"),
46 new RewriteTransformer("b", "c")
47 ]
48 ]});
49 updateSources(["app|foo.a"]);
50 expectAsset("app|foo.b", "foo.b");
51 expectNoAsset("app|foo.c");
52 buildShouldSucceed();
53 });
54
55 test("finds the latest output before the transformer's phase", () {
56 initGraph(["app|foo.blub"], {"app": [
57 [new RewriteTransformer("blub", "blub")],
58 [
59 new RewriteTransformer("blub", "blub"),
60 new RewriteTransformer("blub", "done")
61 ],
62 [new RewriteTransformer("blub", "blub")]
63 ]});
64 updateSources(["app|foo.blub"]);
65 expectAsset("app|foo.done", "foo.blub.done");
66 buildShouldSucceed();
67 });
68
69 test("applies multiple transformations to an asset", () {
70 initGraph(["app|foo.a"], {"app": [
71 [new RewriteTransformer("a", "b")],
72 [new RewriteTransformer("b", "c")],
73 [new RewriteTransformer("c", "d")],
74 [new RewriteTransformer("d", "e")],
75 [new RewriteTransformer("e", "f")],
76 [new RewriteTransformer("f", "g")],
77 [new RewriteTransformer("g", "h")],
78 [new RewriteTransformer("h", "i")],
79 [new RewriteTransformer("i", "j")],
80 [new RewriteTransformer("j", "k")],
81 ]});
82 updateSources(["app|foo.a"]);
83 expectAsset("app|foo.k", "foo.b.c.d.e.f.g.h.i.j.k");
84 buildShouldSucceed();
85 });
86
87 test("only runs a transform once for all of its outputs", () {
88 var transformer = new RewriteTransformer("blub", "a b c");
89 initGraph(["app|foo.blub"], {"app": [[transformer]]});
90 updateSources(["app|foo.blub"]);
91 expectAsset("app|foo.a", "foo.a");
92 expectAsset("app|foo.b", "foo.b");
93 expectAsset("app|foo.c", "foo.c");
94 buildShouldSucceed();
95 expect(transformer.numRuns, completion(equals(1)));
96 });
97
98 test("runs transforms in the same phase in parallel", () {
99 var transformerA = new RewriteTransformer("txt", "a");
100 var transformerB = new RewriteTransformer("txt", "b");
101 initGraph(["app|foo.txt"], {"app": [[transformerA, transformerB]]});
102
103 transformerA.pauseApply();
104 transformerB.pauseApply();
105
106 updateSources(["app|foo.txt"]);
107
108 transformerA.waitUntilStarted();
109 transformerB.waitUntilStarted();
110
111 // They should both still be running.
112 expect(transformerA.isRunning, completion(isTrue));
113 expect(transformerB.isRunning, completion(isTrue));
114
115 transformerA.resumeApply();
116 transformerB.resumeApply();
117
118 expectAsset("app|foo.a", "foo.a");
119 expectAsset("app|foo.b", "foo.b");
120 buildShouldSucceed();
121 });
122
123 test("outputs are passed through transformers by default", () {
124 initGraph(["app|foo.a"], {"app": [
125 [new RewriteTransformer("a", "b")],
126 [new RewriteTransformer("a", "c")]
127 ]});
128 updateSources(["app|foo.a"]);
129 expectAsset("app|foo.a", "foo");
130 expectAsset("app|foo.b", "foo.b");
131 expectAsset("app|foo.c", "foo.c");
132 buildShouldSucceed();
133 });
134
135 test("does not reapply transform when inputs are not modified", () {
136 var transformer = new RewriteTransformer("blub", "blab");
137 initGraph(["app|foo.blub"], {"app": [[transformer]]});
138 updateSources(["app|foo.blub"]);
139 expectAsset("app|foo.blab", "foo.blab");
140 expectAsset("app|foo.blab", "foo.blab");
141 expectAsset("app|foo.blab", "foo.blab");
142 buildShouldSucceed();
143
144 expect(transformer.numRuns, completion(equals(1)));
145 });
146
147 test("reapplies a transform when its input is modified", () {
148 var transformer = new RewriteTransformer("blub", "blab");
149 initGraph(["app|foo.blub"], {"app": [[transformer]]});
150
151 updateSources(["app|foo.blub"]);
152 expectAsset("app|foo.blab", "foo.blab");
153 buildShouldSucceed();
154
155 updateSources(["app|foo.blub"]);
156 expectAsset("app|foo.blab", "foo.blab");
157 buildShouldSucceed();
158
159 updateSources(["app|foo.blub"]);
160 expectAsset("app|foo.blab", "foo.blab");
161 buildShouldSucceed();
162
163 expect(transformer.numRuns, completion(equals(3)));
164 });
165
166 test("does not reapply transform when a removed input is modified", () {
167 var transformer = new ManyToOneTransformer("txt");
168 initGraph({
169 "app|a.txt": "a.inc,b.inc",
170 "app|a.inc": "a",
171 "app|b.inc": "b"
172 }, {"app": [[transformer]]});
173
174 updateSources(["app|a.txt", "app|a.inc", "app|b.inc"]);
175
176 expectAsset("app|a.out", "ab");
177 buildShouldSucceed();
178
179 // Remove the dependency on the non-primary input.
180 modifyAsset("app|a.txt", "a.inc");
181 updateSources(["app|a.txt"]);
182
183 // Process it again.
184 expectAsset("app|a.out", "a");
185 buildShouldSucceed();
186
187 // Now touch the removed input. It should not trigger another build.
188 updateSources(["app|b.inc"]);
189 expectAsset("app|a.out", "a");
190 buildShouldSucceed();
191
192 expect(transformer.numRuns, completion(equals(2)));
193 });
194
195 test("allows a transform to generate multiple outputs", () {
196 initGraph({"app|foo.txt": "a.out,b.out"}, {"app": [
197 [new OneToManyTransformer("txt")]
198 ]});
199
200 updateSources(["app|foo.txt"]);
201
202 expectAsset("app|a.out", "spread txt");
203 expectAsset("app|b.out", "spread txt");
204 buildShouldSucceed();
205 });
206
207 test("does not rebuild transforms that don't use modified source", () {
208 var a = new RewriteTransformer("a", "aa");
209 var aa = new RewriteTransformer("aa", "aaa");
210 var b = new RewriteTransformer("b", "bb");
211 var bb = new RewriteTransformer("bb", "bbb");
212 initGraph(["app|foo.a", "app|foo.b"], {"app": [
213 [a, b],
214 [aa, bb],
215 ]});
216
217 updateSources(["app|foo.a"]);
218 updateSources(["app|foo.b"]);
219
220 expectAsset("app|foo.aaa", "foo.aa.aaa");
221 expectAsset("app|foo.bbb", "foo.bb.bbb");
222 buildShouldSucceed();
223
224 updateSources(["app|foo.a"]);
225 expectAsset("app|foo.aaa", "foo.aa.aaa");
226 expectAsset("app|foo.bbb", "foo.bb.bbb");
227 buildShouldSucceed();
228
229 expect(aa.numRuns, completion(equals(2)));
230 expect(bb.numRuns, completion(equals(1)));
231 });
232
233 test("doesn't get an output from a transform whose primary input is removed",
234 () {
235 initGraph(["app|foo.txt"], {"app": [
236 [new RewriteTransformer("txt", "out")]
237 ]});
238
239 updateSources(["app|foo.txt"]);
240 expectAsset("app|foo.out", "foo.out");
241 buildShouldSucceed();
242
243 removeSources(["app|foo.txt"]);
244 expectNoAsset("app|foo.out");
245 buildShouldSucceed();
246 });
247
248 test("discards outputs from a transform whose primary input is removed "
249 "during processing", () {
250 var rewrite = new RewriteTransformer("txt", "out");
251 initGraph(["app|foo.txt"], {"app": [[rewrite]]});
252
253 rewrite.pauseApply();
254 updateSources(["app|foo.txt"]);
255 rewrite.waitUntilStarted();
256
257 removeSources(["app|foo.txt"]);
258 rewrite.resumeApply();
259 expectNoAsset("app|foo.out");
260 buildShouldSucceed();
261 });
262
263 test("reapplies a transform when a non-primary input changes", () {
264 initGraph({
265 "app|a.txt": "a.inc",
266 "app|a.inc": "a"
267 }, {"app": [[new ManyToOneTransformer("txt")]]});
268
269 updateSources(["app|a.txt", "app|a.inc"]);
270 expectAsset("app|a.out", "a");
271 buildShouldSucceed();
272
273 modifyAsset("app|a.inc", "after");
274 updateSources(["app|a.inc"]);
275
276 expectAsset("app|a.out", "after");
277 buildShouldSucceed();
278 });
279
280 test("applies a transform when it becomes newly primary", () {
281 initGraph({
282 "app|foo.txt": "this",
283 }, {"app": [[new CheckContentTransformer("that", " and the other")]]});
284
285 updateSources(["app|foo.txt"]);
286 expectAsset("app|foo.txt", "this");
287 buildShouldSucceed();
288
289 modifyAsset("app|foo.txt", "that");
290 updateSources(["app|foo.txt"]);
291
292 expectAsset("app|foo.txt", "that and the other");
293 buildShouldSucceed();
294 });
295
296 test("applies the correct transform if an asset is modified during isPrimary",
297 () {
298 var check1 = new CheckContentTransformer("first", "#1");
299 var check2 = new CheckContentTransformer("second", "#2");
300 initGraph({
301 "app|foo.txt": "first",
302 }, {"app": [[check1, check2]]});
303
304 check1.pauseIsPrimary("app|foo.txt");
305 updateSources(["app|foo.txt"]);
306 // Ensure that we're waiting on check1's isPrimary.
307 schedule(pumpEventQueue);
308
309 modifyAsset("app|foo.txt", "second");
310 updateSources(["app|foo.txt"]);
311 check1.resumeIsPrimary("app|foo.txt");
312
313 expectAsset("app|foo.txt", "second#2");
314 buildShouldSucceed();
315 });
316
317 test("applies the correct transform if an asset is removed and added during "
318 "isPrimary", () {
319 var check1 = new CheckContentTransformer("first", "#1");
320 var check2 = new CheckContentTransformer("second", "#2");
321 initGraph({
322 "app|foo.txt": "first",
323 }, {"app": [[check1, check2]]});
324
325 check1.pauseIsPrimary("app|foo.txt");
326 updateSources(["app|foo.txt"]);
327 // Ensure that we're waiting on check1's isPrimary.
328 schedule(pumpEventQueue);
329
330 removeSources(["app|foo.txt"]);
331 modifyAsset("app|foo.txt", "second");
332 updateSources(["app|foo.txt"]);
333 check1.resumeIsPrimary("app|foo.txt");
334
335 expectAsset("app|foo.txt", "second#2");
336 buildShouldSucceed();
337 });
338
339 test("restarts processing if a change occurs during processing", () {
340 var transformer = new RewriteTransformer("txt", "out");
341 initGraph(["app|foo.txt"], {"app": [[transformer]]});
342
343 transformer.pauseApply();
344
345 updateSources(["app|foo.txt"]);
346 transformer.waitUntilStarted();
347
348 // Now update the graph during it.
349 updateSources(["app|foo.txt"]);
350 transformer.resumeApply();
351
352 expectAsset("app|foo.out", "foo.out");
353 buildShouldSucceed();
354
355 expect(transformer.numRuns, completion(equals(2)));
356 });
357
358 test("aborts processing if the primary input is removed during processing",
359 () {
360 var transformer = new RewriteTransformer("txt", "out");
361 initGraph(["app|foo.txt"], {"app": [[transformer]]});
362
363 transformer.pauseApply();
364
365 updateSources(["app|foo.txt"]);
366 transformer.waitUntilStarted();
367
368 // Now remove its primary input while it's running.
369 removeSources(["app|foo.txt"]);
370 transformer.resumeApply();
371
372 expectNoAsset("app|foo.out");
373 buildShouldSucceed();
374
375 expect(transformer.numRuns, completion(equals(1)));
376 });
377
378 test("restarts processing if a change to a new secondary input occurs during "
379 "processing", () {
380 var transformer = new ManyToOneTransformer("txt");
381 initGraph({
382 "app|foo.txt": "bar.inc",
383 "app|bar.inc": "bar"
384 }, {"app": [[transformer]]});
385
386 transformer.pauseApply();
387
388 updateSources(["app|foo.txt", "app|bar.inc"]);
389 transformer.waitUntilStarted();
390
391 // Give the transform time to load bar.inc the first time.
392 schedule(pumpEventQueue);
393
394 // Now update the secondary input before the transform finishes.
395 modifyAsset("app|bar.inc", "baz");
396 updateSources(["app|bar.inc"]);
397 // Give bar.inc enough time to be loaded and marked available before the
398 // transformer completes.
399 schedule(pumpEventQueue);
400
401 transformer.resumeApply();
402
403 expectAsset("app|foo.out", "baz");
404 buildShouldSucceed();
405
406 expect(transformer.numRuns, completion(equals(2)));
407 });
408
409 test("doesn't restart processing if a change to an old secondary input "
410 "occurs during processing", () {
411 var transformer = new ManyToOneTransformer("txt");
412 initGraph({
413 "app|foo.txt": "bar.inc",
414 "app|bar.inc": "bar",
415 "app|baz.inc": "baz"
416 }, {"app": [[transformer]]});
417
418 updateSources(["app|foo.txt", "app|bar.inc", "app|baz.inc"]);
419 expectAsset("app|foo.out", "bar");
420 buildShouldSucceed();
421
422 transformer.pauseApply();
423 modifyAsset("app|foo.txt", "baz.inc");
424 updateSources(["app|foo.txt"]);
425 transformer.waitUntilStarted();
426
427 // Now update the old secondary input before the transform finishes.
428 modifyAsset("app|bar.inc", "new bar");
429 updateSources(["app|bar.inc"]);
430 // Give bar.inc enough time to be loaded and marked available before the
431 // transformer completes.
432 schedule(pumpEventQueue);
433
434 transformer.resumeApply();
435 expectAsset("app|foo.out", "baz");
436 buildShouldSucceed();
437
438 // Should have run once the first time, then again when switching to
439 // baz.inc. Should not run a third time because of bar.inc being modified.
440 expect(transformer.numRuns, completion(equals(2)));
441 });
442
443 test("handles an output moving from one transformer to another", () {
444 // In the first run, "shared.out" is created by the "a.a" transformer.
445 initGraph({
446 "app|a.a": "a.out,shared.out",
447 "app|b.b": "b.out"
448 }, {"app": [
449 [new OneToManyTransformer("a"), new OneToManyTransformer("b")]
450 ]});
451
452 updateSources(["app|a.a", "app|b.b"]);
453
454 expectAsset("app|a.out", "spread a");
455 expectAsset("app|b.out", "spread b");
456 expectAsset("app|shared.out", "spread a");
457 buildShouldSucceed();
458
459 // Now switch their contents so that "shared.out" will be output by "b.b"'s
460 // transformer.
461 modifyAsset("app|a.a", "a.out");
462 modifyAsset("app|b.b", "b.out,shared.out");
463 updateSources(["app|a.a", "app|b.b"]);
464
465 expectAsset("app|a.out", "spread a");
466 expectAsset("app|b.out", "spread b");
467 expectAsset("app|shared.out", "spread b");
468 buildShouldSucceed();
469 });
470
471 test("restarts before finishing later phases when a change occurs", () {
472 var txtToInt = new RewriteTransformer("txt", "int");
473 var intToOut = new RewriteTransformer("int", "out");
474 initGraph(["app|foo.txt", "app|bar.txt"],
475 {"app": [[txtToInt], [intToOut]]});
476
477 txtToInt.pauseApply();
478
479 updateSources(["app|foo.txt"]);
480 txtToInt.waitUntilStarted();
481
482 // Now update the graph during it.
483 updateSources(["app|bar.txt"]);
484 txtToInt.resumeApply();
485
486 expectAsset("app|foo.out", "foo.int.out");
487 expectAsset("app|bar.out", "bar.int.out");
488 buildShouldSucceed();
489
490 // Should only have run each transform once for each primary.
491 expect(txtToInt.numRuns, completion(equals(2)));
492 expect(intToOut.numRuns, completion(equals(2)));
493 });
494
495 test("applies transforms to the correct packages", () {
496 var rewrite1 = new RewriteTransformer("txt", "out1");
497 var rewrite2 = new RewriteTransformer("txt", "out2");
498 initGraph([
499 "pkg1|foo.txt",
500 "pkg2|foo.txt"
501 ], {"pkg1": [[rewrite1]], "pkg2": [[rewrite2]]});
502
503 updateSources(["pkg1|foo.txt", "pkg2|foo.txt"]);
504 expectAsset("pkg1|foo.out1", "foo.out1");
505 expectAsset("pkg2|foo.out2", "foo.out2");
506 buildShouldSucceed();
507 });
508
509 test("transforms don't see generated assets in other packages", () {
510 var fooToBar = new RewriteTransformer("foo", "bar");
511 var barToBaz = new RewriteTransformer("bar", "baz");
512 initGraph(["pkg1|file.foo"], {"pkg1": [[fooToBar]], "pkg2": [[barToBaz]]});
513
514 updateSources(["pkg1|file.foo"]);
515 expectAsset("pkg1|file.bar", "file.bar");
516 expectNoAsset("pkg2|file.baz");
517 buildShouldSucceed();
518 });
519
520 test("doesn't return an asset until it's finished rebuilding", () {
521 initGraph(["app|foo.in"], {"app": [
522 [new RewriteTransformer("in", "mid")],
523 [new RewriteTransformer("mid", "out")]
524 ]});
525
526 updateSources(["app|foo.in"]);
527 expectAsset("app|foo.out", "foo.mid.out");
528 buildShouldSucceed();
529
530 pauseProvider();
531 modifyAsset("app|foo.in", "new");
532 updateSources(["app|foo.in"]);
533 expectAssetDoesNotComplete("app|foo.out");
534 buildShouldNotBeDone();
535
536 resumeProvider();
537 expectAsset("app|foo.out", "new.mid.out");
538 buildShouldSucceed();
539 });
540
541 test("doesn't return an asset until its in-place transform is done", () {
542 var rewrite = new RewriteTransformer("txt", "txt");
543 initGraph(["app|foo.txt"], {"app": [[rewrite]]});
544
545 rewrite.pauseApply();
546 updateSources(["app|foo.txt"]);
547 expectAssetDoesNotComplete("app|foo.txt");
548
549 rewrite.resumeApply();
550 expectAsset("app|foo.txt", "foo.txt");
551 buildShouldSucceed();
552 });
553
554 test("doesn't return a pass-through asset until we know it won't be "
555 "overwritten", () {
556 var rewrite = new RewriteTransformer("txt", "txt");
557 initGraph(["app|foo.a"], {"app": [[rewrite]]});
558
559 rewrite.pauseIsPrimary("app|foo.a");
560 updateSources(["app|foo.a"]);
561 expectAssetDoesNotComplete("app|foo.a");
562
563 rewrite.resumeIsPrimary("app|foo.a");
564 expectAsset("app|foo.a", "foo");
565 buildShouldSucceed();
566 });
567
568 test("doesn't return a pass-through asset until we know it won't be "
569 "overwritten when secondary inputs change", () {
570 var manyToOne = new ManyToOneTransformer("txt");
571 initGraph({
572 "app|foo.txt": "bar.in",
573 "app|bar.in": "bar"
574 }, {"app": [[manyToOne]]});
575
576 updateSources(["app|foo.txt", "app|bar.in"]);
577 expectAsset("app|foo.txt", "bar.in");
578 expectAsset("app|foo.out", "bar");
579
580 manyToOne.pauseApply();
581 updateSources(["app|bar.in"]);
582 expectAssetDoesNotComplete("app|foo.txt");
583
584 manyToOne.resumeApply();
585 expectAsset("app|foo.txt", "bar.in");
586 buildShouldSucceed();
587 });
588
589 test("doesn't return an overwritten asset until we know it will still "
590 "be overwritten", () {
591 var rewrite = new RewriteTransformer("txt", "txt");
592 initGraph(["app|foo.txt"], {"app": [[rewrite]]});
593
594 updateSources(["app|foo.txt"]);
595 expectAsset("app|foo.txt", "foo.txt");
596 buildShouldSucceed();
597
598 rewrite.pauseIsPrimary("app|foo.txt");
599 updateSources(["app|foo.txt"]);
600 expectAssetDoesNotComplete("app|foo.txt");
601
602 rewrite.resumeIsPrimary("app|foo.txt");
603 expectAsset("app|foo.txt", "foo.txt");
604 buildShouldSucceed();
605 });
606
607 test("doesn't return an asset that's removed during isPrimary", () {
608 var rewrite = new RewriteTransformer("txt", "txt");
609 initGraph(["app|foo.txt"], {"app": [[rewrite]]});
610
611 rewrite.pauseIsPrimary("app|foo.txt");
612 updateSources(["app|foo.txt"]);
613 // Make sure we're waiting on isPrimary.
614 schedule(pumpEventQueue);
615
616 removeSources(["app|foo.txt"]);
617 rewrite.resumeIsPrimary("app|foo.txt");
618 expectNoAsset("app|foo.txt");
619 buildShouldSucceed();
620 });
621
622 test("doesn't transform an asset that goes from primary to non-primary "
623 "during isPrimary", () {
624 var check = new CheckContentTransformer(new RegExp(r"^do$"), "ne");
625 initGraph({
626 "app|foo.txt": "do"
627 }, {"app": [[check]]});
628
629 check.pauseIsPrimary("app|foo.txt");
630 updateSources(["app|foo.txt"]);
631 // Make sure we're waiting on isPrimary.
632 schedule(pumpEventQueue);
633
634 modifyAsset("app|foo.txt", "don't");
635 updateSources(["app|foo.txt"]);
636 check.resumeIsPrimary("app|foo.txt");
637
638 expectAsset("app|foo.txt", "don't");
639 buildShouldSucceed();
640 });
641
642 test("transforms an asset that goes from non-primary to primary "
643 "during isPrimary", () {
644 var check = new CheckContentTransformer("do", "ne");
645 initGraph({
646 "app|foo.txt": "don't"
647 }, {"app": [[check]]});
648
649 check.pauseIsPrimary("app|foo.txt");
650 updateSources(["app|foo.txt"]);
651 // Make sure we're waiting on isPrimary.
652 schedule(pumpEventQueue);
653
654 modifyAsset("app|foo.txt", "do");
655 updateSources(["app|foo.txt"]);
656 check.resumeIsPrimary("app|foo.txt");
657
658 expectAsset("app|foo.txt", "done");
659 buildShouldSucceed();
660 });
661
662 test("doesn't return an asset that's removed during another transformer's "
663 "isPrimary", () {
664 var rewrite1 = new RewriteTransformer("txt", "txt");
665 var rewrite2 = new RewriteTransformer("md", "md");
666 initGraph(["app|foo.txt", "app|foo.md"], {"app": [[rewrite1, rewrite2]]});
667
668 rewrite2.pauseIsPrimary("app|foo.md");
669 updateSources(["app|foo.txt", "app|foo.md"]);
670 // Make sure we're waiting on the correct isPrimary.
671 schedule(pumpEventQueue);
672
673 removeSources(["app|foo.txt"]);
674 rewrite2.resumeIsPrimary("app|foo.md");
675 expectNoAsset("app|foo.txt");
676 expectAsset("app|foo.md", "foo.md");
677 buildShouldSucceed();
678 });
679
680 test("doesn't transform an asset that goes from primary to non-primary "
681 "during another transformer's isPrimary", () {
682 var rewrite = new RewriteTransformer("md", "md");
683 var check = new CheckContentTransformer(new RegExp(r"^do$"), "ne");
684 initGraph({
685 "app|foo.txt": "do",
686 "app|foo.md": "foo"
687 }, {"app": [[rewrite, check]]});
688
689 rewrite.pauseIsPrimary("app|foo.md");
690 updateSources(["app|foo.txt", "app|foo.md"]);
691 // Make sure we're waiting on the correct isPrimary.
692 schedule(pumpEventQueue);
693
694 modifyAsset("app|foo.txt", "don't");
695 updateSources(["app|foo.txt"]);
696 rewrite.resumeIsPrimary("app|foo.md");
697
698 expectAsset("app|foo.txt", "don't");
699 expectAsset("app|foo.md", "foo.md");
700 buildShouldSucceed();
701 });
702
703 test("transforms an asset that goes from non-primary to primary "
704 "during another transformer's isPrimary", () {
705 var rewrite = new RewriteTransformer("md", "md");
706 var check = new CheckContentTransformer("do", "ne");
707 initGraph({
708 "app|foo.txt": "don't",
709 "app|foo.md": "foo"
710 }, {"app": [[rewrite, check]]});
711
712 rewrite.pauseIsPrimary("app|foo.md");
713 updateSources(["app|foo.txt", "app|foo.md"]);
714 // Make sure we're waiting on the correct isPrimary.
715 schedule(pumpEventQueue);
716
717 modifyAsset("app|foo.txt", "do");
718 updateSources(["app|foo.txt"]);
719 rewrite.resumeIsPrimary("app|foo.md");
720
721 expectAsset("app|foo.txt", "done");
722 expectAsset("app|foo.md", "foo.md");
723 buildShouldSucceed();
724 });
725
726 test("removes pipelined transforms when the root primary input is removed",
727 () {
728 initGraph(["app|foo.txt"], {"app": [
729 [new RewriteTransformer("txt", "mid")],
730 [new RewriteTransformer("mid", "out")]
731 ]});
732
733 updateSources(["app|foo.txt"]);
734 expectAsset("app|foo.out", "foo.mid.out");
735 buildShouldSucceed();
736
737 removeSources(["app|foo.txt"]);
738 expectNoAsset("app|foo.out");
739 buildShouldSucceed();
740 });
741
742 test("removes pipelined transforms when the parent ceases to generate the "
743 "primary input", () {
744 initGraph({"app|foo.txt": "foo.mid"}, {'app': [
745 [new OneToManyTransformer('txt')],
746 [new RewriteTransformer('mid', 'out')]
747 ]});
748
749 updateSources(['app|foo.txt']);
750 expectAsset('app|foo.out', 'spread txt.out');
751 buildShouldSucceed();
752
753 modifyAsset("app|foo.txt", "bar.mid");
754 updateSources(["app|foo.txt"]);
755 expectNoAsset('app|foo.out');
756 expectAsset('app|bar.out', 'spread txt.out');
757 buildShouldSucceed();
758 });
759
760 test("returns an asset even if an unrelated build is running", () {
761 initGraph([
762 "app|foo.in",
763 "app|bar.in",
764 ], {"app": [[new RewriteTransformer("in", "out")]]});
765
766 updateSources(["app|foo.in", "app|bar.in"]);
767 expectAsset("app|foo.out", "foo.out");
768 expectAsset("app|bar.out", "bar.out");
769 buildShouldSucceed();
770
771 pauseProvider();
772 modifyAsset("app|foo.in", "new");
773 updateSources(["app|foo.in"]);
774 expectAssetDoesNotComplete("app|foo.out");
775 expectAsset("app|bar.out", "bar.out");
776 buildShouldNotBeDone();
777
778 resumeProvider();
779 expectAsset("app|foo.out", "new.out");
780 buildShouldSucceed();
781 });
782
783 test("doesn't report AssetNotFound until all builds are finished", () {
784 initGraph([
785 "app|foo.in",
786 ], {"app": [[new RewriteTransformer("in", "out")]]});
787
788 updateSources(["app|foo.in"]);
789 expectAsset("app|foo.out", "foo.out");
790 buildShouldSucceed();
791
792 pauseProvider();
793 updateSources(["app|foo.in"]);
794 expectAssetDoesNotComplete("app|foo.out");
795 expectAssetDoesNotComplete("app|non-existent.out");
796 buildShouldNotBeDone();
797
798 resumeProvider();
799 expectAsset("app|foo.out", "foo.out");
800 expectNoAsset("app|non-existent.out");
801 buildShouldSucceed();
802 });
803
804 test("doesn't emit a result until all builds are finished", () {
805 var rewrite = new RewriteTransformer("txt", "out");
806 initGraph([
807 "pkg1|foo.txt",
808 "pkg2|foo.txt"
809 ], {"pkg1": [[rewrite]], "pkg2": [[rewrite]]});
810
811 // First, run both packages' transformers so both packages are successful.
812 updateSources(["pkg1|foo.txt", "pkg2|foo.txt"]);
813 expectAsset("pkg1|foo.out", "foo.out");
814 expectAsset("pkg2|foo.out", "foo.out");
815 buildShouldSucceed();
816
817 // pkg1 is still successful, but pkg2 is waiting on the provider, so the
818 // overall build shouldn't finish.
819 pauseProvider();
820 updateSources(["pkg2|foo.txt"]);
821 expectAsset("pkg1|foo.out", "foo.out");
822 buildShouldNotBeDone();
823
824 // Now that the provider is unpaused, pkg2's transforms finish and the
825 // overall build succeeds.
826 resumeProvider();
827 buildShouldSucceed();
828 });
829
830 test("one transformer takes a long time while the other finishes, then "
831 "the input is removed", () {
832 var rewrite1 = new RewriteTransformer("txt", "out1");
833 var rewrite2 = new RewriteTransformer("txt", "out2");
834 initGraph(["app|foo.txt"], {"app": [[rewrite1, rewrite2]]});
835
836 rewrite1.pauseApply();
837
838 updateSources(["app|foo.txt"]);
839
840 // Wait for rewrite1 to pause and rewrite2 to finish.
841 schedule(pumpEventQueue);
842
843 removeSources(["app|foo.txt"]);
844
845 // Make sure the removal is processed completely before we restart rewrite2.
846 schedule(pumpEventQueue);
847 rewrite1.resumeApply();
848
849 buildShouldSucceed();
850 expectNoAsset("app|foo.out1");
851 expectNoAsset("app|foo.out2");
852 });
853
854 group("pass-through", () {
855 test("passes an asset through a phase in which no transforms apply", () {
856 initGraph([
857 "app|foo.in",
858 "app|bar.zip",
859 ], {"app": [
860 [new RewriteTransformer("in", "mid")],
861 [new RewriteTransformer("zip", "zap")],
862 [new RewriteTransformer("mid", "out")],
863 ]});
864
865 updateSources(["app|foo.in", "app|bar.zip"]);
866 expectAsset("app|foo.out", "foo.mid.out");
867 expectAsset("app|bar.zap", "bar.zap");
868 buildShouldSucceed();
869 });
870
871 test("passes an asset through a phase in which a transform uses it", () {
872 initGraph([
873 "app|foo.in",
874 ], {"app": [
875 [new RewriteTransformer("in", "mid")],
876 [new RewriteTransformer("mid", "phase2")],
877 [new RewriteTransformer("mid", "phase3")],
878 ]});
879
880 updateSources(["app|foo.in"]);
881 expectAsset("app|foo.in", "foo");
882 expectAsset("app|foo.mid", "foo.mid");
883 expectAsset("app|foo.phase2", "foo.mid.phase2");
884 expectAsset("app|foo.phase3", "foo.mid.phase3");
885 buildShouldSucceed();
886 });
887
888 // If the asset were to get passed through, it might either cause a
889 // collision or silently supersede the overwriting asset. We want to assert
890 // that that doesn't happen.
891 test("doesn't pass an asset through a phase in which a transform "
892 "overwrites it", () {
893 initGraph([
894 "app|foo.txt"
895 ], {"app": [[new RewriteTransformer("txt", "txt")]]});
896
897 updateSources(["app|foo.txt"]);
898 expectAsset("app|foo.txt", "foo.txt");
899 buildShouldSucceed();
900 });
901
902 test("removes a pass-through asset when the source is removed", () {
903 initGraph([
904 "app|foo.in",
905 "app|bar.zip",
906 ], {"app": [
907 [new RewriteTransformer("zip", "zap")],
908 [new RewriteTransformer("in", "out")],
909 ]});
910
911 updateSources(["app|foo.in", "app|bar.zip"]);
912 expectAsset("app|foo.out", "foo.out");
913 buildShouldSucceed();
914
915 removeSources(["app|foo.in"]);
916 expectNoAsset("app|foo.in");
917 expectNoAsset("app|foo.out");
918 buildShouldSucceed();
919 });
920
921 test("updates a pass-through asset when the source is updated", () {
922 initGraph([
923 "app|foo.in",
924 "app|bar.zip",
925 ], {"app": [
926 [new RewriteTransformer("zip", "zap")],
927 [new RewriteTransformer("in", "out")],
928 ]});
929
930 updateSources(["app|foo.in", "app|bar.zip"]);
931 expectAsset("app|foo.out", "foo.out");
932 buildShouldSucceed();
933
934 modifyAsset("app|foo.in", "boo");
935 updateSources(["app|foo.in"]);
936 expectAsset("app|foo.out", "boo.out");
937 buildShouldSucceed();
938 });
939
940 test("passes an asset through a phase in which transforms have ceased to "
941 "apply", () {
942 initGraph([
943 "app|foo.in",
944 ], {"app": [
945 [new RewriteTransformer("in", "mid")],
946 [new CheckContentTransformer("foo.mid", ".phase2")],
947 [new CheckContentTransformer(new RegExp(r"\.mid$"), ".phase3")],
948 ]});
949
950 updateSources(["app|foo.in"]);
951 expectAsset("app|foo.mid", "foo.mid.phase2");
952 buildShouldSucceed();
953
954 modifyAsset("app|foo.in", "bar");
955 updateSources(["app|foo.in"]);
956 expectAsset("app|foo.mid", "bar.mid.phase3");
957 buildShouldSucceed();
958 });
959
960 test("doesn't pass an asset through a phase in which transforms have "
961 "started to apply", () {
962 initGraph([
963 "app|foo.in",
964 ], {"app": [
965 [new RewriteTransformer("in", "mid")],
966 [new CheckContentTransformer("bar.mid", ".phase2")],
967 [new CheckContentTransformer(new RegExp(r"\.mid$"), ".phase3")],
968 ]});
969
970 updateSources(["app|foo.in"]);
971 expectAsset("app|foo.mid", "foo.mid.phase3");
972 buildShouldSucceed();
973
974 modifyAsset("app|foo.in", "bar");
975 updateSources(["app|foo.in"]);
976 expectAsset("app|foo.mid", "bar.mid.phase2");
977 buildShouldSucceed();
978 });
979
980 test("doesn't pass an asset through if it's removed during isPrimary", () {
981 var check = new CheckContentTransformer("bar", " modified");
982 initGraph(["app|foo.txt"], {"app": [[check]]});
983
984 updateSources(["app|foo.txt"]);
985 expectAsset("app|foo.txt", "foo");
986 buildShouldSucceed();
987
988 check.pauseIsPrimary("app|foo.txt");
989 modifyAsset("app|foo.txt", "bar");
990 updateSources(["app|foo.txt"]);
991 // Ensure we're waiting on [check.isPrimary]
992 schedule(pumpEventQueue);
993
994 removeSources(["app|foo.txt"]);
995 check.resumeIsPrimary("app|foo.txt");
996 expectNoAsset("app|foo.txt");
997 buildShouldSucceed();
998 });
999
1000 test("passes an asset through when its overwriting transform becomes "
1001 "non-primary during apply", () {
1002 var check = new CheckContentTransformer("yes", " modified");
1003 initGraph({"app|foo.txt": "yes"}, {"app": [[check]]});
1004
1005 check.pauseApply();
1006 updateSources(["app|foo.txt"]);
1007 expectAssetDoesNotComplete("app|foo.txt");
1008
1009 modifyAsset("app|foo.txt", "no");
1010 updateSources(["app|foo.txt"]);
1011 check.resumeApply();
1012
1013 expectAsset("app|foo.txt", "no");
1014 buildShouldSucceed();
1015 });
1016
1017 test("doesn't pass an asset through when its overwriting transform becomes "
1018 "non-primary during apply if another transform overwrites it", () {
1019 var check = new CheckContentTransformer("yes", " modified");
1020 initGraph({
1021 "app|foo.txt": "yes"
1022 }, {
1023 "app": [[check, new RewriteTransformer("txt", "txt")]]
1024 });
1025
1026 check.pauseApply();
1027 updateSources(["app|foo.txt"]);
1028 // Ensure we're waiting on [check.apply]
1029 schedule(pumpEventQueue);
1030
1031 modifyAsset("app|foo.txt", "no");
1032 updateSources(["app|foo.txt"]);
1033 check.resumeApply();
1034
1035 expectAsset("app|foo.txt", "no.txt");
1036 buildShouldSucceed();
1037 });
1038
1039 test("doesn't pass an asset through when one overwriting transform becomes "
1040 "non-primary if another transform still overwrites it", () {
1041 initGraph({
1042 "app|foo.txt": "yes"
1043 }, {
1044 "app": [[
1045 new CheckContentTransformer("yes", " modified"),
1046 new RewriteTransformer("txt", "txt")
1047 ]]
1048 });
1049
1050 updateSources(["app|foo.txt"]);
1051 // This could be either the output of [CheckContentTransformer] or
1052 // [RewriteTransformer], depending which completes first.
1053 expectAsset("app|foo.txt", anything);
1054 buildShouldFail([isAssetCollisionException("app|foo.txt")]);
1055
1056 modifyAsset("app|foo.txt", "no");
1057 updateSources(["app|foo.txt"]);
1058 expectAsset("app|foo.txt", "no.txt");
1059 buildShouldSucceed();
1060 });
1061 });
1062
1063 group('cross-package transforms', () {
1064 test("can access other packages' source assets", () {
1065 initGraph({
1066 "pkg1|a.txt": "pkg2|a.inc",
1067 "pkg2|a.inc": "a"
1068 }, {"pkg1": [[new ManyToOneTransformer("txt")]]});
1069
1070 updateSources(["pkg1|a.txt", "pkg2|a.inc"]);
1071 expectAsset("pkg1|a.out", "a");
1072 buildShouldSucceed();
1073 });
1074
1075 test("can access other packages' transformed assets", () {
1076 initGraph({
1077 "pkg1|a.txt": "pkg2|a.inc",
1078 "pkg2|a.txt": "a"
1079 }, {
1080 "pkg1": [[new ManyToOneTransformer("txt")]],
1081 "pkg2": [[new RewriteTransformer("txt", "inc")]]
1082 });
1083
1084 updateSources(["pkg1|a.txt", "pkg2|a.txt"]);
1085 expectAsset("pkg1|a.out", "a.inc");
1086 buildShouldSucceed();
1087 });
1088
1089 test("re-runs a transform when an input from another package changes", () {
1090 initGraph({
1091 "pkg1|a.txt": "pkg2|a.inc",
1092 "pkg2|a.inc": "a"
1093 }, {
1094 "pkg1": [[new ManyToOneTransformer("txt")]]
1095 });
1096
1097 updateSources(["pkg1|a.txt", "pkg2|a.inc"]);
1098 expectAsset("pkg1|a.out", "a");
1099 buildShouldSucceed();
1100
1101 modifyAsset("pkg2|a.inc", "new a");
1102 updateSources(["pkg2|a.inc"]);
1103 expectAsset("pkg1|a.out", "new a");
1104 buildShouldSucceed();
1105 });
1106
1107 test("re-runs a transform when a transformed input from another package "
1108 "changes", () {
1109 initGraph({
1110 "pkg1|a.txt": "pkg2|a.inc",
1111 "pkg2|a.txt": "a"
1112 }, {
1113 "pkg1": [[new ManyToOneTransformer("txt")]],
1114 "pkg2": [[new RewriteTransformer("txt", "inc")]]
1115 });
1116
1117 updateSources(["pkg1|a.txt", "pkg2|a.txt"]);
1118 expectAsset("pkg1|a.out", "a.inc");
1119 buildShouldSucceed();
1120
1121 modifyAsset("pkg2|a.txt", "new a");
1122 updateSources(["pkg2|a.txt"]);
1123 expectAsset("pkg1|a.out", "new a.inc");
1124 buildShouldSucceed();
1125 });
1126
1127 test("doesn't complete the build until all packages' transforms are "
1128 "finished running", () {
1129 var transformer = new ManyToOneTransformer("txt");
1130 initGraph({
1131 "pkg1|a.txt": "pkg2|a.inc",
1132 "pkg2|a.inc": "a"
1133 }, {
1134 "pkg1": [[transformer]]
1135 });
1136
1137 updateSources(["pkg1|a.txt", "pkg2|a.inc"]);
1138 expectAsset("pkg1|a.out", "a");
1139 buildShouldSucceed();
1140
1141 transformer.pauseApply();
1142 modifyAsset("pkg2|a.inc", "new a");
1143 updateSources(["pkg2|a.inc"]);
1144 buildShouldNotBeDone();
1145
1146 transformer.resumeApply();
1147 buildShouldSucceed();
1148 });
1149
1150 test("runs a transform that's added because of a change in another package",
1151 () {
1152 initGraph({
1153 "pkg1|a.txt": "pkg2|a.inc",
1154 "pkg2|a.inc": "b"
1155 }, {
1156 "pkg1": [
1157 [new ManyToOneTransformer("txt")],
1158 [new OneToManyTransformer("out")],
1159 [new RewriteTransformer("md", "done")]
1160 ],
1161 });
1162
1163 // pkg1|a.txt generates outputs based on the contents of pkg2|a.inc. At
1164 // first pkg2|a.inc only includes "b", which is not transformed. Then
1165 // pkg2|a.inc is updated to include "b,c.md". pkg1|c.md triggers the
1166 // md->done rewrite transformer, producing pkg1|c.done.
1167
1168 updateSources(["pkg1|a.txt", "pkg2|a.inc"]);
1169 expectAsset("pkg1|b", "spread out");
1170 buildShouldSucceed();
1171
1172 modifyAsset("pkg2|a.inc", "b,c.md");
1173 updateSources(["pkg2|a.inc"]);
1174 expectAsset("pkg1|b", "spread out");
1175 expectAsset("pkg1|c.done", "spread out.done");
1176 buildShouldSucceed();
1177 });
1178
1179 test("doesn't run a transform that's removed because of a change in "
1180 "another package", () {
1181 initGraph({
1182 "pkg1|a.txt": "pkg2|a.inc",
1183 "pkg2|a.inc": "b,c.md"
1184 }, {
1185 "pkg1": [
1186 [new ManyToOneTransformer("txt")],
1187 [new OneToManyTransformer("out")],
1188 [new RewriteTransformer("md", "done")]
1189 ],
1190 });
1191
1192 updateSources(["pkg1|a.txt", "pkg2|a.inc"]);
1193 expectAsset("pkg1|b", "spread out");
1194 expectAsset("pkg1|c.done", "spread out.done");
1195 buildShouldSucceed();
1196
1197 modifyAsset("pkg2|a.inc", "b");
1198 updateSources(["pkg2|a.inc"]);
1199 expectAsset("pkg1|b", "spread out");
1200 expectNoAsset("pkg1|c.done");
1201 buildShouldSucceed();
1202 });
1203
1204 test("sees a transformer that's newly applied to a cross-package "
1205 "dependency", () {
1206 initGraph({
1207 "pkg1|a.txt": "pkg2|a.inc",
1208 "pkg2|a.inc": "a"
1209 }, {
1210 "pkg1": [[new ManyToOneTransformer("txt")]],
1211 "pkg2": [[new CheckContentTransformer("b", " transformed")]]
1212 });
1213
1214 updateSources(["pkg1|a.txt", "pkg2|a.inc"]);
1215 expectAsset("pkg1|a.out", "a");
1216 buildShouldSucceed();
1217
1218 modifyAsset("pkg2|a.inc", "b");
1219 updateSources(["pkg2|a.inc"]);
1220 expectAsset("pkg1|a.out", "b transformed");
1221 buildShouldSucceed();
1222 });
1223
1224 test("doesn't see a transformer that's newly not applied to a "
1225 "cross-package dependency", () {
1226 initGraph({
1227 "pkg1|a.txt": "pkg2|a.inc",
1228 "pkg2|a.inc": "a"
1229 }, {
1230 "pkg1": [[new ManyToOneTransformer("txt")]],
1231 "pkg2": [[new CheckContentTransformer("a", " transformed")]]
1232 });
1233
1234 updateSources(["pkg1|a.txt", "pkg2|a.inc"]);
1235 expectAsset("pkg1|a.out", "a transformed");
1236 buildShouldSucceed();
1237
1238 modifyAsset("pkg2|a.inc", "b");
1239 updateSources(["pkg2|a.inc"]);
1240 expectAsset("pkg1|a.out", "b");
1241 buildShouldSucceed();
1242 });
1243
1244 test("re-runs if the primary input is invalidated before accessing", () {
1245 var transformer1 = new RewriteTransformer("txt", "mid");
1246 var transformer2 = new RewriteTransformer("mid", "out");
1247
1248 initGraph([
1249 "app|foo.txt"
1250 ], {"app": [
1251 [transformer1],
1252 [transformer2]
1253 ]});
1254
1255 transformer2.pausePrimaryInput();
1256 updateSources(["app|foo.txt"]);
1257
1258 // Wait long enough to ensure that transformer1 has completed and
1259 // transformer2 has started.
1260 schedule(pumpEventQueue);
1261
1262 // Update the source again so that transformer1 invalidates the primary
1263 // input of transformer2.
1264 transformer1.pauseApply();
1265 updateSources(["app|foo.txt"]);
1266
1267 transformer2.resumePrimaryInput();
1268 transformer1.resumeApply();
1269
1270 expectAsset("app|foo.out", "foo.mid.out");
1271 buildShouldSucceed();
1272
1273 expect(transformer1.numRuns, completion(equals(2)));
1274 expect(transformer2.numRuns, completion(equals(2)));
1275 });
1276 });
1277 }
OLDNEW
« no previous file with comments | « pkg/barback/test/package_graph/transform/transform_test.dart ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698