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

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: 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
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", () {
Bob Nystrom 2013/07/31 20:05:41 Nice.
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 removed and added during "
334 "isPrimary", () {
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 schedule(() => removeSources(["app|foo.txt"]));
Bob Nystrom 2013/07/31 20:05:41 What happens if you don't remove first and just mo
nweiz 2013/07/31 22:47:53 Added test.
347 modifyAsset("app|foo.txt", "second");
348 schedule(() {
349 updateSources(["app|foo.txt"]);
350 check1.resumeIsPrimary("app|foo.txt");
351 });
352
353 expectAsset("app|foo.txt", "second#2");
354 buildShouldSucceed();
355 });
356
288 test("restarts processing if a change occurs during processing", () { 357 test("restarts processing if a change occurs during processing", () {
289 var transformer = new RewriteTransformer("txt", "out"); 358 var transformer = new RewriteTransformer("txt", "out");
290 initGraph(["app|foo.txt"], {"app": [[transformer]]}); 359 initGraph(["app|foo.txt"], {"app": [[transformer]]});
291 360
292 transformer.pauseApply(); 361 transformer.pauseApply();
293 362
294 schedule(() { 363 schedule(() {
295 updateSources(["app|foo.txt"]); 364 updateSources(["app|foo.txt"]);
296 365
297 // Wait for the transform to start. 366 // Wait for the transform to start.
298 return transformer.started; 367 return transformer.started;
299 }); 368 });
300 369
301 schedule(() { 370 schedule(() {
302 // Now update the graph during it. 371 // Now update the graph during it.
303 updateSources(["app|foo.txt"]); 372 updateSources(["app|foo.txt"]);
304 transformer.resumeApply(); 373 transformer.resumeApply();
305 }); 374 });
306 375
307 expectAsset("app|foo.out", "foo.out"); 376 expectAsset("app|foo.out", "foo.out");
308 buildShouldSucceed(); 377 buildShouldSucceed();
309 378
310 schedule(() { 379 schedule(() {
311 expect(transformer.numRuns, equals(2)); 380 expect(transformer.numRuns, equals(2));
312 }); 381 });
313 }); 382 });
314 383
384 test("aborts processing if the primary input is removed during processing",
385 () {
386 var transformer = new RewriteTransformer("txt", "out");
387 initGraph(["app|foo.txt"], {"app": [[transformer]]});
388
389 transformer.pauseApply();
390
391 schedule(() {
392 updateSources(["app|foo.txt"]);
393
394 // Wait for the transform to start.
395 return transformer.started;
396 });
397
398 schedule(() {
399 // Now remove its primary input while it's running.
400 removeSources(["app|foo.txt"]);
401 transformer.resumeApply();
402 });
403
404 expectNoAsset("app|foo.out");
405 buildShouldSucceed();
406
407 schedule(() {
408 expect(transformer.numRuns, equals(1));
409 });
410 });
411
315 test("handles an output moving from one transformer to another", () { 412 test("handles an output moving from one transformer to another", () {
316 // In the first run, "shared.out" is created by the "a.a" transformer. 413 // In the first run, "shared.out" is created by the "a.a" transformer.
317 initGraph({ 414 initGraph({
318 "app|a.a": "a.out,shared.out", 415 "app|a.a": "a.out,shared.out",
319 "app|b.b": "b.out" 416 "app|b.b": "b.out"
320 }, {"app": [ 417 }, {"app": [
321 [new OneToManyTransformer("a"), new OneToManyTransformer("b")] 418 [new OneToManyTransformer("a"), new OneToManyTransformer("b")]
322 ]}); 419 ]});
323 420
324 updateSources(["app|a.a", "app|b.b"]); 421 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"); 490 var fooToBar = new RewriteTransformer("foo", "bar");
394 var barToBaz = new RewriteTransformer("bar", "baz"); 491 var barToBaz = new RewriteTransformer("bar", "baz");
395 initGraph(["pkg1|file.foo"], {"pkg1": [[fooToBar]], "pkg2": [[barToBaz]]}); 492 initGraph(["pkg1|file.foo"], {"pkg1": [[fooToBar]], "pkg2": [[barToBaz]]});
396 493
397 updateSources(["pkg1|file.foo"]); 494 updateSources(["pkg1|file.foo"]);
398 expectAsset("pkg1|file.bar", "file.bar"); 495 expectAsset("pkg1|file.bar", "file.bar");
399 expectNoAsset("pkg2|file.baz"); 496 expectNoAsset("pkg2|file.baz");
400 buildShouldSucceed(); 497 buildShouldSucceed();
401 }); 498 });
402 499
500 test("doesn't return an asset until it's finished rebuilding", () {
501 initGraph(["app|foo.in"], {"app": [
502 [new RewriteTransformer("in", "mid")],
503 [new RewriteTransformer("mid", "out")]
504 ]});
505
506 updateSources(["app|foo.in"]);
507 expectAsset("app|foo.out", "foo.mid.out");
508 buildShouldSucceed();
509
510 pauseProvider();
511 modifyAsset("app|foo.in", "new");
512 schedule(() => updateSources(["app|foo.in"]));
513 expectAssetDoesNotComplete("app|foo.out");
514 buildShouldNotBeDone();
515
516 resumeProvider();
517 expectAsset("app|foo.out", "new.mid.out");
518 buildShouldSucceed();
519 });
520
521 test("doesn't return an asset until its in-place transform is done", () {
522 var rewrite = new RewriteTransformer("txt", "txt");
523 initGraph(["app|foo.txt"], {"app": [[rewrite]]});
524
525 rewrite.pauseApply();
526 updateSources(["app|foo.txt"]);
527 expectAssetDoesNotComplete("app|foo.txt");
528
529 schedule(rewrite.resumeApply);
530 expectAsset("app|foo.txt", "foo.txt");
531 buildShouldSucceed();
532 });
533
534 test("doesn't return an asset until we know it won't be transformed",
535 () {
536 var rewrite = new RewriteTransformer("txt", "txt");
537 initGraph(["app|foo.a"], {"app": [[rewrite]]});
538
539 rewrite.pauseIsPrimary("app|foo.a");
540 updateSources(["app|foo.a"]);
541 expectAssetDoesNotComplete("app|foo.a");
542
543 schedule(() => rewrite.resumeIsPrimary("app|foo.a"));
544 expectAsset("app|foo.a", "foo");
545 buildShouldSucceed();
546 });
547
548 test("doesn't return a modified asset until we know it will still be "
549 "transformed", () {
550 var rewrite = new RewriteTransformer("txt", "txt");
551 initGraph(["app|foo.txt"], {"app": [[rewrite]]});
552
553 updateSources(["app|foo.txt"]);
554 expectAsset("app|foo.txt", "foo.txt");
555 buildShouldSucceed();
556
557 schedule(() => rewrite.pauseIsPrimary("app|foo.txt"));
558 schedule(() => updateSources(["app|foo.txt"]));
559 expectAssetDoesNotComplete("app|foo.txt");
560
561 schedule(() => rewrite.resumeIsPrimary("app|foo.txt"));
562 expectAsset("app|foo.txt", "foo.txt");
563 buildShouldSucceed();
564 });
565
566 test("doesn't return an asset that's removed during isPrimary", () {
567 var rewrite = new RewriteTransformer("txt", "txt");
568 initGraph(["app|foo.txt"], {"app": [[rewrite]]});
569
570 rewrite.pauseIsPrimary("app|foo.txt");
571 updateSources(["app|foo.txt"]);
572 // Make sure we're waiting on isPrimary
Bob Nystrom 2013/07/31 20:05:41 "." here and elsewhere.
nweiz 2013/07/31 22:47:53 Done.
573 schedule(pumpEventQueue);
574
575 schedule(() {
576 removeSources(["app|foo.txt"]);
577 rewrite.resumeIsPrimary("app|foo.txt");
578 });
579 expectNoAsset("app|foo.txt");
580 buildShouldSucceed();
581 });
582
583 test("doesn't transform an asset that goes from primary to non-primary "
584 "during isPrimary", () {
585 var check = new CheckContentTransformer("do", "ne");
586 initGraph({
587 "app|foo.txt": "do"
588 }, {"app": [[check]]});
589
590 check.pauseIsPrimary("app|foo.txt");
591 updateSources(["app|foo.txt"]);
592 // Make sure we're waiting on isPrimary
593 schedule(pumpEventQueue);
594
595 modifyAsset("app|foo.txt", "don't");
596 schedule(() {
597 updateSources(["app|foo.txt"]);
598 check.resumeIsPrimary("app|foo.txt");
599 });
600
601 expectAsset("app|foo.txt", "don't");
602 buildShouldSucceed();
603 });
604
605 test("transforms an asset that goes from non-primary to primary "
606 "during isPrimary", () {
607 var check = new CheckContentTransformer("do", "ne");
608 initGraph({
609 "app|foo.txt": "don't"
610 }, {"app": [[check]]});
611
612 check.pauseIsPrimary("app|foo.txt");
613 updateSources(["app|foo.txt"]);
614 // Make sure we're waiting on isPrimary
615 schedule(pumpEventQueue);
616
617 modifyAsset("app|foo.txt", "do");
618 schedule(() {
619 updateSources(["app|foo.txt"]);
620 check.resumeIsPrimary("app|foo.txt");
621 });
622
623 expectAsset("app|foo.txt", "done");
624 buildShouldSucceed();
625 });
626
627 test("doesn't return an asset that's removed during another transformer's "
628 "isPrimary", () {
629 var rewrite1 = new RewriteTransformer("txt", "txt");
630 var rewrite2 = new RewriteTransformer("md", "md");
631 initGraph(["app|foo.txt", "app|foo.md"], {"app": [[rewrite1, rewrite2]]});
632
633 rewrite2.pauseIsPrimary("app|foo.md");
634 updateSources(["app|foo.txt", "app|foo.md"]);
635 // Make sure we're waiting on the correct isPrimary
636 schedule(pumpEventQueue);
637
638 schedule(() {
639 removeSources(["app|foo.txt"]);
640 rewrite2.resumeIsPrimary("app|foo.md");
641 });
642 expectNoAsset("app|foo.txt");
643 expectAsset("app|foo.md", "foo.md");
644 buildShouldSucceed();
645 });
646
647 test("doesn't transform an asset that goes from primary to non-primary "
648 "during another transformer's isPrimary", () {
649 var rewrite = new RewriteTransformer("md", "md");
650 var check = new CheckContentTransformer("do", "ne");
651 initGraph({
652 "app|foo.txt": "do",
653 "app|foo.md": "foo"
654 }, {"app": [[rewrite, check]]});
655
656 rewrite.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 modifyAsset("app|foo.txt", "don't");
662 schedule(() {
663 updateSources(["app|foo.txt"]);
664 rewrite.resumeIsPrimary("app|foo.md");
665 });
666
667 expectAsset("app|foo.txt", "don't");
668 expectAsset("app|foo.md", "foo.md");
669 buildShouldSucceed();
670 });
671
672 test("transforms an asset that goes from non-primary to primary "
673 "during another transformer's isPrimary", () {
674 var rewrite = new RewriteTransformer("md", "md");
675 var check = new CheckContentTransformer("do", "ne");
676 initGraph({
677 "app|foo.txt": "don't",
678 "app|foo.md": "foo"
679 }, {"app": [[rewrite, check]]});
680
681 rewrite.pauseIsPrimary("app|foo.md");
682 updateSources(["app|foo.txt", "app|foo.md"]);
683 // Make sure we're waiting on the correct isPrimary
684 schedule(pumpEventQueue);
685
686 modifyAsset("app|foo.txt", "do");
687 schedule(() {
688 updateSources(["app|foo.txt"]);
689 rewrite.resumeIsPrimary("app|foo.md");
690 });
691
692 expectAsset("app|foo.txt", "done");
693 expectAsset("app|foo.md", "foo.md");
694 buildShouldSucceed();
695 });
696
697 test("removes pipelined transforms when the root primary input is removed",
698 () {
699 initGraph(["app|foo.txt"], {"app": [
700 [new RewriteTransformer("txt", "mid")],
701 [new RewriteTransformer("mid", "out")]
702 ]});
703
704 updateSources(["app|foo.txt"]);
705 expectAsset("app|foo.out", "foo.mid.out");
706 buildShouldSucceed();
707
708 schedule(() => removeSources(["app|foo.txt"]));
709 expectNoAsset("app|foo.out");
710 buildShouldSucceed();
711 });
712
713 test("removes pipelined transforms when the parent ceases to generate the "
714 "primary input", () {
715 initGraph({"app|foo.txt": "foo.mid"}, {'app': [
716 [new OneToManyTransformer('txt')],
717 [new RewriteTransformer('mid', 'out')]
718 ]});
719
720 updateSources(['app|foo.txt']);
721 expectAsset('app|foo.out', 'spread txt.out');
722 buildShouldSucceed();
723
724 modifyAsset("app|foo.txt", "bar.mid");
725 schedule(() => updateSources(["app|foo.txt"]));
726 expectNoAsset('app|foo.out');
727 expectAsset('app|bar.out', 'spread txt.out');
728 buildShouldSucceed();
729 });
730
731 test("returns an asset even if an unrelated build is running", () {
732 initGraph([
733 "app|foo.in",
734 "app|bar.in",
735 ], {"app": [[new RewriteTransformer("in", "out")]]});
736
737 updateSources(["app|foo.in", "app|bar.in"]);
738 expectAsset("app|foo.out", "foo.out");
739 expectAsset("app|bar.out", "bar.out");
740 buildShouldSucceed();
741
742 pauseProvider();
743 modifyAsset("app|foo.in", "new");
744 schedule(() => updateSources(["app|foo.in"]));
745 expectAssetDoesNotComplete("app|foo.out");
746 expectAsset("app|bar.out", "bar.out");
747 buildShouldNotBeDone();
748
749 resumeProvider();
750 expectAsset("app|foo.out", "new.out");
751 buildShouldSucceed();
752 });
753
754 test("doesn't report AssetNotFound until all builds are finished", () {
755 initGraph([
756 "app|foo.in",
757 ], {"app": [[new RewriteTransformer("in", "out")]]});
758
759 updateSources(["app|foo.in"]);
760 expectAsset("app|foo.out", "foo.out");
761 buildShouldSucceed();
762
763 pauseProvider();
764 schedule(() => updateSources(["app|foo.in"]));
765 expectAssetDoesNotComplete("app|foo.out");
766 expectAssetDoesNotComplete("app|non-existent.out");
767 buildShouldNotBeDone();
768
769 resumeProvider();
770 expectAsset("app|foo.out", "foo.out");
771 expectNoAsset("app|non-existent.out");
772 buildShouldSucceed();
773 });
774
403 test("doesn't emit a result until all builds are finished", () { 775 test("doesn't emit a result until all builds are finished", () {
404 var rewrite = new RewriteTransformer("txt", "out"); 776 var rewrite = new RewriteTransformer("txt", "out");
405 initGraph([ 777 initGraph([
406 "pkg1|foo.txt", 778 "pkg1|foo.txt",
407 "pkg2|foo.txt" 779 "pkg2|foo.txt"
408 ], {"pkg1": [[rewrite]], "pkg2": [[rewrite]]}); 780 ], {"pkg1": [[rewrite]], "pkg2": [[rewrite]]});
409 781
410 // First, run both packages' transformers so both packages are successful. 782 // First, run both packages' transformers so both packages are successful.
411 updateSources(["pkg1|foo.txt", "pkg2|foo.txt"]); 783 updateSources(["pkg1|foo.txt", "pkg2|foo.txt"]);
412 expectAsset("pkg1|foo.out", "foo.out"); 784 expectAsset("pkg1|foo.out", "foo.out");
413 expectAsset("pkg2|foo.out", "foo.out"); 785 expectAsset("pkg2|foo.out", "foo.out");
414 buildShouldSucceed(); 786 buildShouldSucceed();
415 787
416 // pkg1 is still successful, but pkg2 is waiting on the provider, so the 788 // pkg1 is still successful, but pkg2 is waiting on the provider, so the
417 // overall build shouldn't finish. 789 // overall build shouldn't finish.
418 pauseProvider(); 790 pauseProvider();
419 schedule(() => updateSources(["pkg2|foo.txt"])); 791 schedule(() => updateSources(["pkg2|foo.txt"]));
420 expectAsset("pkg1|foo.out", "foo.out"); 792 expectAsset("pkg1|foo.out", "foo.out");
421 buildShouldNotBeDone(); 793 buildShouldNotBeDone();
422 794
423 // Now that the provider is unpaused, pkg2's transforms finish and the 795 // Now that the provider is unpaused, pkg2's transforms finish and the
424 // overall build succeeds. 796 // overall build succeeds.
425 resumeProvider(); 797 resumeProvider();
426 buildShouldSucceed(); 798 buildShouldSucceed();
427 }); 799 });
428 } 800 }
OLDNEW
« pkg/barback/lib/src/transform_node.dart ('K') | « 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