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

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

Issue 21275003: Move barback to a more event-based model. (Closed) Base URL: https://dart.googlecode.com/svn/branches/bleeding_edge/dart
Patch Set: Code review changes. Created 7 years, 4 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/source_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
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.package_graph.transform_test; 5 library barback.test.package_graph.transform_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/utils.dart'; 10 import 'package:barback/src/utils.dart';
(...skipping 111 matching lines...) Expand 10 before | Expand all | Expand 10 after
122 122
123 transformerA.resumeApply(); 123 transformerA.resumeApply();
124 transformerB.resumeApply(); 124 transformerB.resumeApply();
125 }); 125 });
126 126
127 expectAsset("app|foo.a", "foo.a"); 127 expectAsset("app|foo.a", "foo.a");
128 expectAsset("app|foo.b", "foo.b"); 128 expectAsset("app|foo.b", "foo.b");
129 buildShouldSucceed(); 129 buildShouldSucceed();
130 }); 130 });
131 131
132 test("outputs are inaccessible once used", () {
133 initGraph(["app|foo.a"], {"app": [
134 [new RewriteTransformer("a", "b")],
135 [new RewriteTransformer("a", "c")]
136 ]});
137 updateSources(["app|foo.a"]);
138 expectAsset("app|foo.b", "foo.b");
139 expectNoAsset("app|foo.a");
140 expectNoAsset("app|foo.c");
141 buildShouldSucceed();
142 });
143
132 test("does not reapply transform when inputs are not modified", () { 144 test("does not reapply transform when inputs are not modified", () {
133 var transformer = new RewriteTransformer("blub", "blab"); 145 var transformer = new RewriteTransformer("blub", "blab");
134 initGraph(["app|foo.blub"], {"app": [[transformer]]}); 146 initGraph(["app|foo.blub"], {"app": [[transformer]]});
135 updateSources(["app|foo.blub"]); 147 updateSources(["app|foo.blub"]);
136 expectAsset("app|foo.blab", "foo.blab"); 148 expectAsset("app|foo.blab", "foo.blab");
137 expectAsset("app|foo.blab", "foo.blab"); 149 expectAsset("app|foo.blab", "foo.blab");
138 expectAsset("app|foo.blab", "foo.blab"); 150 expectAsset("app|foo.blab", "foo.blab");
139 buildShouldSucceed(); 151 buildShouldSucceed();
140 152
141 schedule(() { 153 schedule(() {
(...skipping 119 matching lines...) Expand 10 before | Expand all | Expand 10 after
261 buildShouldSucceed(); 273 buildShouldSucceed();
262 274
263 schedule(() { 275 schedule(() {
264 removeSources(["app|foo.txt"]); 276 removeSources(["app|foo.txt"]);
265 }); 277 });
266 278
267 expectNoAsset("app|foo.out"); 279 expectNoAsset("app|foo.out");
268 buildShouldSucceed(); 280 buildShouldSucceed();
269 }); 281 });
270 282
283 test("discards outputs from a transform whose primary input is removed "
284 "during processing", () {
285 var rewrite = new RewriteTransformer("txt", "out");
286 initGraph(["app|foo.txt"], {"app": [[rewrite]]});
287
288 rewrite.pauseApply();
289 updateSources(["app|foo.txt"]);
290 schedule(() => rewrite.started);
291 schedule(() {
292 removeSources(["app|foo.txt"]);
293 rewrite.resumeApply();
294 });
295
296 expectNoAsset("app|foo.out");
297 buildShouldSucceed();
298 });
299
271 test("reapplies a transform when a non-primary input changes", () { 300 test("reapplies a transform when a non-primary input changes", () {
272 initGraph({ 301 initGraph({
273 "app|a.txt": "a.inc", 302 "app|a.txt": "a.inc",
274 "app|a.inc": "a" 303 "app|a.inc": "a"
275 }, {"app": [[new ManyToOneTransformer("txt")]]}); 304 }, {"app": [[new ManyToOneTransformer("txt")]]});
276 305
277 updateSources(["app|a.txt", "app|a.inc"]); 306 updateSources(["app|a.txt", "app|a.inc"]);
278 expectAsset("app|a.out", "a"); 307 expectAsset("app|a.out", "a");
279 buildShouldSucceed(); 308 buildShouldSucceed();
280 309
281 modifyAsset("app|a.inc", "after"); 310 modifyAsset("app|a.inc", "after");
282 schedule(() => updateSources(["app|a.inc"])); 311 schedule(() => updateSources(["app|a.inc"]));
283 312
284 expectAsset("app|a.out", "after"); 313 expectAsset("app|a.out", "after");
285 buildShouldSucceed(); 314 buildShouldSucceed();
286 }); 315 });
287 316
317 test("applies a transform when it becomes newly primary", () {
318 initGraph({
319 "app|foo.txt": "this",
320 }, {"app": [[new CheckContentTransformer("that", " and the other")]]});
321
322 updateSources(["app|foo.txt"]);
323 expectAsset("app|foo.txt", "this");
324 buildShouldSucceed();
325
326 modifyAsset("app|foo.txt", "that");
327 schedule(() => updateSources(["app|foo.txt"]));
328
329 expectAsset("app|foo.txt", "that and the other");
330 buildShouldSucceed();
331 });
332
333 test("applies the correct transform if an asset is modified during isPrimary",
334 () {
335 var check1 = new CheckContentTransformer("first", "#1");
336 var check2 = new CheckContentTransformer("second", "#2");
337 initGraph({
338 "app|foo.txt": "first",
339 }, {"app": [[check1, check2]]});
340
341 check1.pauseIsPrimary("app|foo.txt");
342 updateSources(["app|foo.txt"]);
343 // Ensure that we're waiting on check1's isPrimary.
344 schedule(pumpEventQueue);
345
346 modifyAsset("app|foo.txt", "second");
347 schedule(() {
348 updateSources(["app|foo.txt"]);
349 check1.resumeIsPrimary("app|foo.txt");
350 });
351
352 expectAsset("app|foo.txt", "second#2");
353 buildShouldSucceed();
354 });
355
356 test("applies the correct transform if an asset is removed and added during "
357 "isPrimary", () {
358 var check1 = new CheckContentTransformer("first", "#1");
359 var check2 = new CheckContentTransformer("second", "#2");
360 initGraph({
361 "app|foo.txt": "first",
362 }, {"app": [[check1, check2]]});
363
364 check1.pauseIsPrimary("app|foo.txt");
365 updateSources(["app|foo.txt"]);
366 // Ensure that we're waiting on check1's isPrimary.
367 schedule(pumpEventQueue);
368
369 schedule(() => removeSources(["app|foo.txt"]));
370 modifyAsset("app|foo.txt", "second");
371 schedule(() {
372 updateSources(["app|foo.txt"]);
373 check1.resumeIsPrimary("app|foo.txt");
374 });
375
376 expectAsset("app|foo.txt", "second#2");
377 buildShouldSucceed();
378 });
379
288 test("restarts processing if a change occurs during processing", () { 380 test("restarts processing if a change occurs during processing", () {
289 var transformer = new RewriteTransformer("txt", "out"); 381 var transformer = new RewriteTransformer("txt", "out");
290 initGraph(["app|foo.txt"], {"app": [[transformer]]}); 382 initGraph(["app|foo.txt"], {"app": [[transformer]]});
291 383
292 transformer.pauseApply(); 384 transformer.pauseApply();
293 385
294 schedule(() { 386 schedule(() {
295 updateSources(["app|foo.txt"]); 387 updateSources(["app|foo.txt"]);
296 388
297 // Wait for the transform to start. 389 // Wait for the transform to start.
298 return transformer.started; 390 return transformer.started;
299 }); 391 });
300 392
301 schedule(() { 393 schedule(() {
302 // Now update the graph during it. 394 // Now update the graph during it.
303 updateSources(["app|foo.txt"]); 395 updateSources(["app|foo.txt"]);
304 transformer.resumeApply(); 396 transformer.resumeApply();
305 }); 397 });
306 398
307 expectAsset("app|foo.out", "foo.out"); 399 expectAsset("app|foo.out", "foo.out");
308 buildShouldSucceed(); 400 buildShouldSucceed();
309 401
310 schedule(() { 402 schedule(() {
311 expect(transformer.numRuns, equals(2)); 403 expect(transformer.numRuns, equals(2));
312 }); 404 });
313 }); 405 });
314 406
407 test("aborts processing if the primary input is removed during processing",
408 () {
409 var transformer = new RewriteTransformer("txt", "out");
410 initGraph(["app|foo.txt"], {"app": [[transformer]]});
411
412 transformer.pauseApply();
413
414 schedule(() {
415 updateSources(["app|foo.txt"]);
416
417 // Wait for the transform to start.
418 return transformer.started;
419 });
420
421 schedule(() {
422 // Now remove its primary input while it's running.
423 removeSources(["app|foo.txt"]);
424 transformer.resumeApply();
425 });
426
427 expectNoAsset("app|foo.out");
428 buildShouldSucceed();
429
430 schedule(() {
431 expect(transformer.numRuns, equals(1));
432 });
433 });
434
315 test("handles an output moving from one transformer to another", () { 435 test("handles an output moving from one transformer to another", () {
316 // In the first run, "shared.out" is created by the "a.a" transformer. 436 // In the first run, "shared.out" is created by the "a.a" transformer.
317 initGraph({ 437 initGraph({
318 "app|a.a": "a.out,shared.out", 438 "app|a.a": "a.out,shared.out",
319 "app|b.b": "b.out" 439 "app|b.b": "b.out"
320 }, {"app": [ 440 }, {"app": [
321 [new OneToManyTransformer("a"), new OneToManyTransformer("b")] 441 [new OneToManyTransformer("a"), new OneToManyTransformer("b")]
322 ]}); 442 ]});
323 443
324 updateSources(["app|a.a", "app|b.b"]); 444 updateSources(["app|a.a", "app|b.b"]);
(...skipping 68 matching lines...) Expand 10 before | Expand all | Expand 10 after
393 var fooToBar = new RewriteTransformer("foo", "bar"); 513 var fooToBar = new RewriteTransformer("foo", "bar");
394 var barToBaz = new RewriteTransformer("bar", "baz"); 514 var barToBaz = new RewriteTransformer("bar", "baz");
395 initGraph(["pkg1|file.foo"], {"pkg1": [[fooToBar]], "pkg2": [[barToBaz]]}); 515 initGraph(["pkg1|file.foo"], {"pkg1": [[fooToBar]], "pkg2": [[barToBaz]]});
396 516
397 updateSources(["pkg1|file.foo"]); 517 updateSources(["pkg1|file.foo"]);
398 expectAsset("pkg1|file.bar", "file.bar"); 518 expectAsset("pkg1|file.bar", "file.bar");
399 expectNoAsset("pkg2|file.baz"); 519 expectNoAsset("pkg2|file.baz");
400 buildShouldSucceed(); 520 buildShouldSucceed();
401 }); 521 });
402 522
523 test("doesn't return an asset until it's finished rebuilding", () {
524 initGraph(["app|foo.in"], {"app": [
525 [new RewriteTransformer("in", "mid")],
526 [new RewriteTransformer("mid", "out")]
527 ]});
528
529 updateSources(["app|foo.in"]);
530 expectAsset("app|foo.out", "foo.mid.out");
531 buildShouldSucceed();
532
533 pauseProvider();
534 modifyAsset("app|foo.in", "new");
535 schedule(() => updateSources(["app|foo.in"]));
536 expectAssetDoesNotComplete("app|foo.out");
537 buildShouldNotBeDone();
538
539 resumeProvider();
540 expectAsset("app|foo.out", "new.mid.out");
541 buildShouldSucceed();
542 });
543
544 test("doesn't return an asset until its in-place transform is done", () {
545 var rewrite = new RewriteTransformer("txt", "txt");
546 initGraph(["app|foo.txt"], {"app": [[rewrite]]});
547
548 rewrite.pauseApply();
549 updateSources(["app|foo.txt"]);
550 expectAssetDoesNotComplete("app|foo.txt");
551
552 schedule(rewrite.resumeApply);
553 expectAsset("app|foo.txt", "foo.txt");
554 buildShouldSucceed();
555 });
556
557 test("doesn't return an asset until we know it won't be transformed",
558 () {
559 var rewrite = new RewriteTransformer("txt", "txt");
560 initGraph(["app|foo.a"], {"app": [[rewrite]]});
561
562 rewrite.pauseIsPrimary("app|foo.a");
563 updateSources(["app|foo.a"]);
564 expectAssetDoesNotComplete("app|foo.a");
565
566 schedule(() => rewrite.resumeIsPrimary("app|foo.a"));
567 expectAsset("app|foo.a", "foo");
568 buildShouldSucceed();
569 });
570
571 test("doesn't return a modified asset until we know it will still be "
572 "transformed", () {
573 var rewrite = new RewriteTransformer("txt", "txt");
574 initGraph(["app|foo.txt"], {"app": [[rewrite]]});
575
576 updateSources(["app|foo.txt"]);
577 expectAsset("app|foo.txt", "foo.txt");
578 buildShouldSucceed();
579
580 schedule(() => rewrite.pauseIsPrimary("app|foo.txt"));
581 schedule(() => updateSources(["app|foo.txt"]));
582 expectAssetDoesNotComplete("app|foo.txt");
583
584 schedule(() => rewrite.resumeIsPrimary("app|foo.txt"));
585 expectAsset("app|foo.txt", "foo.txt");
586 buildShouldSucceed();
587 });
588
589 test("doesn't return an asset that's removed during isPrimary", () {
590 var rewrite = new RewriteTransformer("txt", "txt");
591 initGraph(["app|foo.txt"], {"app": [[rewrite]]});
592
593 rewrite.pauseIsPrimary("app|foo.txt");
594 updateSources(["app|foo.txt"]);
595 // Make sure we're waiting on isPrimary.
596 schedule(pumpEventQueue);
597
598 schedule(() {
599 removeSources(["app|foo.txt"]);
600 rewrite.resumeIsPrimary("app|foo.txt");
601 });
602 expectNoAsset("app|foo.txt");
603 buildShouldSucceed();
604 });
605
606 test("doesn't transform an asset that goes from primary to non-primary "
607 "during isPrimary", () {
608 var check = new CheckContentTransformer("do", "ne");
609 initGraph({
610 "app|foo.txt": "do"
611 }, {"app": [[check]]});
612
613 check.pauseIsPrimary("app|foo.txt");
614 updateSources(["app|foo.txt"]);
615 // Make sure we're waiting on isPrimary.
616 schedule(pumpEventQueue);
617
618 modifyAsset("app|foo.txt", "don't");
619 schedule(() {
620 updateSources(["app|foo.txt"]);
621 check.resumeIsPrimary("app|foo.txt");
622 });
623
624 expectAsset("app|foo.txt", "don't");
625 buildShouldSucceed();
626 });
627
628 test("transforms an asset that goes from non-primary to primary "
629 "during isPrimary", () {
630 var check = new CheckContentTransformer("do", "ne");
631 initGraph({
632 "app|foo.txt": "don't"
633 }, {"app": [[check]]});
634
635 check.pauseIsPrimary("app|foo.txt");
636 updateSources(["app|foo.txt"]);
637 // Make sure we're waiting on isPrimary.
638 schedule(pumpEventQueue);
639
640 modifyAsset("app|foo.txt", "do");
641 schedule(() {
642 updateSources(["app|foo.txt"]);
643 check.resumeIsPrimary("app|foo.txt");
644 });
645
646 expectAsset("app|foo.txt", "done");
647 buildShouldSucceed();
648 });
649
650 test("doesn't return an asset that's removed during another transformer's "
651 "isPrimary", () {
652 var rewrite1 = new RewriteTransformer("txt", "txt");
653 var rewrite2 = new RewriteTransformer("md", "md");
654 initGraph(["app|foo.txt", "app|foo.md"], {"app": [[rewrite1, rewrite2]]});
655
656 rewrite2.pauseIsPrimary("app|foo.md");
657 updateSources(["app|foo.txt", "app|foo.md"]);
658 // Make sure we're waiting on the correct isPrimary.
659 schedule(pumpEventQueue);
660
661 schedule(() {
662 removeSources(["app|foo.txt"]);
663 rewrite2.resumeIsPrimary("app|foo.md");
664 });
665 expectNoAsset("app|foo.txt");
666 expectAsset("app|foo.md", "foo.md");
667 buildShouldSucceed();
668 });
669
670 test("doesn't transform an asset that goes from primary to non-primary "
671 "during another transformer's isPrimary", () {
672 var rewrite = new RewriteTransformer("md", "md");
673 var check = new CheckContentTransformer("do", "ne");
674 initGraph({
675 "app|foo.txt": "do",
676 "app|foo.md": "foo"
677 }, {"app": [[rewrite, check]]});
678
679 rewrite.pauseIsPrimary("app|foo.md");
680 updateSources(["app|foo.txt", "app|foo.md"]);
681 // Make sure we're waiting on the correct isPrimary.
682 schedule(pumpEventQueue);
683
684 modifyAsset("app|foo.txt", "don't");
685 schedule(() {
686 updateSources(["app|foo.txt"]);
687 rewrite.resumeIsPrimary("app|foo.md");
688 });
689
690 expectAsset("app|foo.txt", "don't");
691 expectAsset("app|foo.md", "foo.md");
692 buildShouldSucceed();
693 });
694
695 test("transforms an asset that goes from non-primary to primary "
696 "during another transformer's isPrimary", () {
697 var rewrite = new RewriteTransformer("md", "md");
698 var check = new CheckContentTransformer("do", "ne");
699 initGraph({
700 "app|foo.txt": "don't",
701 "app|foo.md": "foo"
702 }, {"app": [[rewrite, check]]});
703
704 rewrite.pauseIsPrimary("app|foo.md");
705 updateSources(["app|foo.txt", "app|foo.md"]);
706 // Make sure we're waiting on the correct isPrimary.
707 schedule(pumpEventQueue);
708
709 modifyAsset("app|foo.txt", "do");
710 schedule(() {
711 updateSources(["app|foo.txt"]);
712 rewrite.resumeIsPrimary("app|foo.md");
713 });
714
715 expectAsset("app|foo.txt", "done");
716 expectAsset("app|foo.md", "foo.md");
717 buildShouldSucceed();
718 });
719
720 test("removes pipelined transforms when the root primary input is removed",
721 () {
722 initGraph(["app|foo.txt"], {"app": [
723 [new RewriteTransformer("txt", "mid")],
724 [new RewriteTransformer("mid", "out")]
725 ]});
726
727 updateSources(["app|foo.txt"]);
728 expectAsset("app|foo.out", "foo.mid.out");
729 buildShouldSucceed();
730
731 schedule(() => removeSources(["app|foo.txt"]));
732 expectNoAsset("app|foo.out");
733 buildShouldSucceed();
734 });
735
736 test("removes pipelined transforms when the parent ceases to generate the "
737 "primary input", () {
738 initGraph({"app|foo.txt": "foo.mid"}, {'app': [
739 [new OneToManyTransformer('txt')],
740 [new RewriteTransformer('mid', 'out')]
741 ]});
742
743 updateSources(['app|foo.txt']);
744 expectAsset('app|foo.out', 'spread txt.out');
745 buildShouldSucceed();
746
747 modifyAsset("app|foo.txt", "bar.mid");
748 schedule(() => updateSources(["app|foo.txt"]));
749 expectNoAsset('app|foo.out');
750 expectAsset('app|bar.out', 'spread txt.out');
751 buildShouldSucceed();
752 });
753
754 test("returns an asset even if an unrelated build is running", () {
755 initGraph([
756 "app|foo.in",
757 "app|bar.in",
758 ], {"app": [[new RewriteTransformer("in", "out")]]});
759
760 updateSources(["app|foo.in", "app|bar.in"]);
761 expectAsset("app|foo.out", "foo.out");
762 expectAsset("app|bar.out", "bar.out");
763 buildShouldSucceed();
764
765 pauseProvider();
766 modifyAsset("app|foo.in", "new");
767 schedule(() => updateSources(["app|foo.in"]));
768 expectAssetDoesNotComplete("app|foo.out");
769 expectAsset("app|bar.out", "bar.out");
770 buildShouldNotBeDone();
771
772 resumeProvider();
773 expectAsset("app|foo.out", "new.out");
774 buildShouldSucceed();
775 });
776
777 test("doesn't report AssetNotFound until all builds are finished", () {
778 initGraph([
779 "app|foo.in",
780 ], {"app": [[new RewriteTransformer("in", "out")]]});
781
782 updateSources(["app|foo.in"]);
783 expectAsset("app|foo.out", "foo.out");
784 buildShouldSucceed();
785
786 pauseProvider();
787 schedule(() => updateSources(["app|foo.in"]));
788 expectAssetDoesNotComplete("app|foo.out");
789 expectAssetDoesNotComplete("app|non-existent.out");
790 buildShouldNotBeDone();
791
792 resumeProvider();
793 expectAsset("app|foo.out", "foo.out");
794 expectNoAsset("app|non-existent.out");
795 buildShouldSucceed();
796 });
797
403 test("doesn't emit a result until all builds are finished", () { 798 test("doesn't emit a result until all builds are finished", () {
404 var rewrite = new RewriteTransformer("txt", "out"); 799 var rewrite = new RewriteTransformer("txt", "out");
405 initGraph([ 800 initGraph([
406 "pkg1|foo.txt", 801 "pkg1|foo.txt",
407 "pkg2|foo.txt" 802 "pkg2|foo.txt"
408 ], {"pkg1": [[rewrite]], "pkg2": [[rewrite]]}); 803 ], {"pkg1": [[rewrite]], "pkg2": [[rewrite]]});
409 804
410 // First, run both packages' transformers so both packages are successful. 805 // First, run both packages' transformers so both packages are successful.
411 updateSources(["pkg1|foo.txt", "pkg2|foo.txt"]); 806 updateSources(["pkg1|foo.txt", "pkg2|foo.txt"]);
412 expectAsset("pkg1|foo.out", "foo.out"); 807 expectAsset("pkg1|foo.out", "foo.out");
413 expectAsset("pkg2|foo.out", "foo.out"); 808 expectAsset("pkg2|foo.out", "foo.out");
414 buildShouldSucceed(); 809 buildShouldSucceed();
415 810
416 // pkg1 is still successful, but pkg2 is waiting on the provider, so the 811 // pkg1 is still successful, but pkg2 is waiting on the provider, so the
417 // overall build shouldn't finish. 812 // overall build shouldn't finish.
418 pauseProvider(); 813 pauseProvider();
419 schedule(() => updateSources(["pkg2|foo.txt"])); 814 schedule(() => updateSources(["pkg2|foo.txt"]));
420 expectAsset("pkg1|foo.out", "foo.out"); 815 expectAsset("pkg1|foo.out", "foo.out");
421 buildShouldNotBeDone(); 816 buildShouldNotBeDone();
422 817
423 // Now that the provider is unpaused, pkg2's transforms finish and the 818 // Now that the provider is unpaused, pkg2's transforms finish and the
424 // overall build succeeds. 819 // overall build succeeds.
425 resumeProvider(); 820 resumeProvider();
426 buildShouldSucceed(); 821 buildShouldSucceed();
427 }); 822 });
428 } 823 }
OLDNEW
« no previous file with comments | « pkg/barback/test/package_graph/source_test.dart ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698