Chromium Code Reviews| OLD | NEW |
|---|---|
| 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 'package:barback/src/utils.dart'; | 7 import 'package:barback/src/utils.dart'; |
| 8 import 'package:scheduled_test/scheduled_test.dart'; | 8 import 'package:scheduled_test/scheduled_test.dart'; |
| 9 | 9 |
| 10 import '../utils.dart'; | 10 import '../utils.dart'; |
| (...skipping 102 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 113 expect(transformerB.isRunning, completion(isTrue)); | 113 expect(transformerB.isRunning, completion(isTrue)); |
| 114 | 114 |
| 115 transformerA.resumeApply(); | 115 transformerA.resumeApply(); |
| 116 transformerB.resumeApply(); | 116 transformerB.resumeApply(); |
| 117 | 117 |
| 118 expectAsset("app|foo.a", "foo.a"); | 118 expectAsset("app|foo.a", "foo.a"); |
| 119 expectAsset("app|foo.b", "foo.b"); | 119 expectAsset("app|foo.b", "foo.b"); |
| 120 buildShouldSucceed(); | 120 buildShouldSucceed(); |
| 121 }); | 121 }); |
| 122 | 122 |
| 123 test("outputs are inaccessible once used", () { | 123 test("outputs are passed through transformers by default", () { |
| 124 initGraph(["app|foo.a"], {"app": [ | 124 initGraph(["app|foo.a"], {"app": [ |
| 125 [new RewriteTransformer("a", "b")], | 125 [new RewriteTransformer("a", "b")], |
| 126 [new RewriteTransformer("a", "c")] | 126 [new RewriteTransformer("a", "c")] |
| 127 ]}); | 127 ]}); |
| 128 updateSources(["app|foo.a"]); | 128 updateSources(["app|foo.a"]); |
| 129 expectAsset("app|foo.a", "foo"); | |
| 129 expectAsset("app|foo.b", "foo.b"); | 130 expectAsset("app|foo.b", "foo.b"); |
| 130 expectNoAsset("app|foo.a"); | 131 expectAsset("app|foo.c", "foo.c"); |
| 131 expectNoAsset("app|foo.c"); | |
| 132 buildShouldSucceed(); | 132 buildShouldSucceed(); |
| 133 }); | 133 }); |
| 134 | 134 |
| 135 test("does not reapply transform when inputs are not modified", () { | 135 test("does not reapply transform when inputs are not modified", () { |
| 136 var transformer = new RewriteTransformer("blub", "blab"); | 136 var transformer = new RewriteTransformer("blub", "blab"); |
| 137 initGraph(["app|foo.blub"], {"app": [[transformer]]}); | 137 initGraph(["app|foo.blub"], {"app": [[transformer]]}); |
| 138 updateSources(["app|foo.blub"]); | 138 updateSources(["app|foo.blub"]); |
| 139 expectAsset("app|foo.blab", "foo.blab"); | 139 expectAsset("app|foo.blab", "foo.blab"); |
| 140 expectAsset("app|foo.blab", "foo.blab"); | 140 expectAsset("app|foo.blab", "foo.blab"); |
| 141 expectAsset("app|foo.blab", "foo.blab"); | 141 expectAsset("app|foo.blab", "foo.blab"); |
| (...skipping 402 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 544 | 544 |
| 545 rewrite.pauseApply(); | 545 rewrite.pauseApply(); |
| 546 updateSources(["app|foo.txt"]); | 546 updateSources(["app|foo.txt"]); |
| 547 expectAssetDoesNotComplete("app|foo.txt"); | 547 expectAssetDoesNotComplete("app|foo.txt"); |
| 548 | 548 |
| 549 rewrite.resumeApply(); | 549 rewrite.resumeApply(); |
| 550 expectAsset("app|foo.txt", "foo.txt"); | 550 expectAsset("app|foo.txt", "foo.txt"); |
| 551 buildShouldSucceed(); | 551 buildShouldSucceed(); |
| 552 }); | 552 }); |
| 553 | 553 |
| 554 test("doesn't return an asset until we know it won't be transformed", | 554 test("doesn't return a pass-through asset until we know it won't be " |
| 555 () { | 555 "overwritten", () { |
| 556 var rewrite = new RewriteTransformer("txt", "txt"); | 556 var rewrite = new RewriteTransformer("txt", "txt"); |
| 557 initGraph(["app|foo.a"], {"app": [[rewrite]]}); | 557 initGraph(["app|foo.a"], {"app": [[rewrite]]}); |
| 558 | 558 |
| 559 rewrite.pauseIsPrimary("app|foo.a"); | 559 rewrite.pauseIsPrimary("app|foo.a"); |
| 560 updateSources(["app|foo.a"]); | 560 updateSources(["app|foo.a"]); |
| 561 expectAssetDoesNotComplete("app|foo.a"); | 561 expectAssetDoesNotComplete("app|foo.a"); |
| 562 | 562 |
| 563 rewrite.resumeIsPrimary("app|foo.a"); | 563 rewrite.resumeIsPrimary("app|foo.a"); |
| 564 expectAsset("app|foo.a", "foo"); | 564 expectAsset("app|foo.a", "foo"); |
| 565 buildShouldSucceed(); | 565 buildShouldSucceed(); |
| 566 }); | 566 }); |
| 567 | 567 |
| 568 test("doesn't return a modified asset until we know it will still be " | 568 test("doesn't return a pass-through asset until we know it won't be " |
| 569 "transformed", () { | 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", () { | |
| 570 var rewrite = new RewriteTransformer("txt", "txt"); | 591 var rewrite = new RewriteTransformer("txt", "txt"); |
| 571 initGraph(["app|foo.txt"], {"app": [[rewrite]]}); | 592 initGraph(["app|foo.txt"], {"app": [[rewrite]]}); |
| 572 | 593 |
| 573 updateSources(["app|foo.txt"]); | 594 updateSources(["app|foo.txt"]); |
| 574 expectAsset("app|foo.txt", "foo.txt"); | 595 expectAsset("app|foo.txt", "foo.txt"); |
| 575 buildShouldSucceed(); | 596 buildShouldSucceed(); |
| 576 | 597 |
| 577 rewrite.pauseIsPrimary("app|foo.txt"); | 598 rewrite.pauseIsPrimary("app|foo.txt"); |
| 578 updateSources(["app|foo.txt"]); | 599 updateSources(["app|foo.txt"]); |
| 579 expectAssetDoesNotComplete("app|foo.txt"); | 600 expectAssetDoesNotComplete("app|foo.txt"); |
| (...skipping 260 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 840 [new RewriteTransformer("zip", "zap")], | 861 [new RewriteTransformer("zip", "zap")], |
| 841 [new RewriteTransformer("mid", "out")], | 862 [new RewriteTransformer("mid", "out")], |
| 842 ]}); | 863 ]}); |
| 843 | 864 |
| 844 updateSources(["app|foo.in", "app|bar.zip"]); | 865 updateSources(["app|foo.in", "app|bar.zip"]); |
| 845 expectAsset("app|foo.out", "foo.mid.out"); | 866 expectAsset("app|foo.out", "foo.mid.out"); |
| 846 expectAsset("app|bar.zap", "bar.zap"); | 867 expectAsset("app|bar.zap", "bar.zap"); |
| 847 buildShouldSucceed(); | 868 buildShouldSucceed(); |
| 848 }); | 869 }); |
| 849 | 870 |
| 850 test("doesn't pass an asset through a phase in which a transform consumes " | 871 test("passes an asset through a phase in which a transform uses it", () { |
| 851 "it", () { | |
| 852 initGraph([ | 872 initGraph([ |
| 853 "app|foo.in", | 873 "app|foo.in", |
| 854 ], {"app": [ | 874 ], {"app": [ |
| 855 [new RewriteTransformer("in", "mid")], | 875 [new RewriteTransformer("in", "mid")], |
| 856 [new RewriteTransformer("mid", "phase2")], | 876 [new RewriteTransformer("mid", "phase2")], |
| 857 [new RewriteTransformer("mid", "phase3")], | 877 [new RewriteTransformer("mid", "phase3")], |
| 858 ]}); | 878 ]}); |
| 859 | 879 |
| 860 updateSources(["app|foo.in"]); | 880 updateSources(["app|foo.in"]); |
| 881 expectAsset("app|foo.in", "foo"); | |
| 882 expectAsset("app|foo.mid", "foo.mid"); | |
| 861 expectAsset("app|foo.phase2", "foo.mid.phase2"); | 883 expectAsset("app|foo.phase2", "foo.mid.phase2"); |
| 862 expectNoAsset("app|foo.phase3"); | 884 expectAsset("app|foo.phase3", "foo.mid.phase3"); |
| 863 buildShouldSucceed(); | 885 buildShouldSucceed(); |
| 864 }); | 886 }); |
| 865 | 887 |
| 888 test("doesn't pass an asset through a phase in which a transform overwrites " | |
|
Bob Nystrom
2014/02/26 01:09:15
Long line.
nweiz
2014/02/26 19:37:14
Done.
| |
| 889 "it", () { | |
| 890 initGraph([ | |
| 891 "app|foo.txt" | |
| 892 ], {"app": [[new RewriteTransformer("txt", "txt")]]}); | |
| 893 | |
| 894 updateSources(["app|foo.txt"]); | |
| 895 expectAsset("app|foo.txt", "foo.txt"); | |
| 896 buildShouldSucceed(); | |
| 897 }); | |
| 898 | |
| 866 test("removes a pass-through asset when the source is removed", () { | 899 test("removes a pass-through asset when the source is removed", () { |
| 867 initGraph([ | 900 initGraph([ |
| 868 "app|foo.in", | 901 "app|foo.in", |
| 869 "app|bar.zip", | 902 "app|bar.zip", |
| 870 ], {"app": [ | 903 ], {"app": [ |
| 871 [new RewriteTransformer("zip", "zap")], | 904 [new RewriteTransformer("zip", "zap")], |
| 872 [new RewriteTransformer("in", "out")], | 905 [new RewriteTransformer("in", "out")], |
| 873 ]}); | 906 ]}); |
| 874 | 907 |
| 875 updateSources(["app|foo.in", "app|bar.zip"]); | 908 updateSources(["app|foo.in", "app|bar.zip"]); |
| (...skipping 77 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 953 modifyAsset("app|foo.txt", "bar"); | 986 modifyAsset("app|foo.txt", "bar"); |
| 954 updateSources(["app|foo.txt"]); | 987 updateSources(["app|foo.txt"]); |
| 955 // Ensure we're waiting on [check.isPrimary] | 988 // Ensure we're waiting on [check.isPrimary] |
| 956 schedule(pumpEventQueue); | 989 schedule(pumpEventQueue); |
| 957 | 990 |
| 958 removeSources(["app|foo.txt"]); | 991 removeSources(["app|foo.txt"]); |
| 959 check.resumeIsPrimary("app|foo.txt"); | 992 check.resumeIsPrimary("app|foo.txt"); |
| 960 expectNoAsset("app|foo.txt"); | 993 expectNoAsset("app|foo.txt"); |
| 961 buildShouldSucceed(); | 994 buildShouldSucceed(); |
| 962 }); | 995 }); |
| 996 | |
| 997 test("passes an asset through when its overwriting transform becomes " | |
| 998 "non-primary during apply", () { | |
| 999 var check = new CheckContentTransformer("yes", " modified"); | |
| 1000 initGraph({"app|foo.txt": "yes"}, {"app": [[check]]}); | |
| 1001 | |
| 1002 check.pauseApply(); | |
| 1003 updateSources(["app|foo.txt"]); | |
| 1004 expectAssetDoesNotComplete("app|foo.txt"); | |
| 1005 | |
| 1006 modifyAsset("app|foo.txt", "no"); | |
| 1007 updateSources(["app|foo.txt"]); | |
| 1008 check.resumeApply(); | |
| 1009 | |
| 1010 expectAsset("app|foo.txt", "no"); | |
| 1011 buildShouldSucceed(); | |
| 1012 }); | |
| 1013 | |
| 1014 test("doesn't pass an asset through when its overwriting transform becomes " | |
| 1015 "non-primary during apply if another transform overwrites it", () { | |
| 1016 var check = new CheckContentTransformer("yes", " modified"); | |
| 1017 initGraph({ | |
| 1018 "app|foo.txt": "yes" | |
| 1019 }, { | |
| 1020 "app": [[check, new RewriteTransformer("txt", "txt")]] | |
| 1021 }); | |
| 1022 | |
| 1023 check.pauseApply(); | |
| 1024 updateSources(["app|foo.txt"]); | |
| 1025 // Ensure we're waiting on [check.apply] | |
| 1026 schedule(pumpEventQueue); | |
| 1027 | |
| 1028 modifyAsset("app|foo.txt", "no"); | |
| 1029 updateSources(["app|foo.txt"]); | |
| 1030 check.resumeApply(); | |
| 1031 | |
| 1032 expectAsset("app|foo.txt", "no.txt"); | |
| 1033 buildShouldSucceed(); | |
| 1034 }); | |
| 1035 | |
| 1036 test("doesn't pass an asset through when one overwriting transform becomes " | |
| 1037 "non-primary if another transform still overwrites it", () { | |
| 1038 initGraph({ | |
| 1039 "app|foo.txt": "yes" | |
| 1040 }, { | |
| 1041 "app": [[ | |
| 1042 new CheckContentTransformer("yes", " modified"), | |
| 1043 new RewriteTransformer("txt", "txt") | |
| 1044 ]] | |
| 1045 }); | |
| 1046 | |
| 1047 updateSources(["app|foo.txt"]); | |
| 1048 // This could be either the output of [CheckContentTransformer] or | |
| 1049 // [RewriteTransformer], depending which completes first. | |
| 1050 expectAsset("app|foo.txt", anything); | |
| 1051 buildShouldFail([isAssetCollisionException("app|foo.txt")]); | |
| 1052 | |
| 1053 modifyAsset("app|foo.txt", "no"); | |
| 1054 updateSources(["app|foo.txt"]); | |
| 1055 expectAsset("app|foo.txt", "no.txt"); | |
| 1056 buildShouldSucceed(); | |
| 1057 }); | |
| 963 }); | 1058 }); |
| 964 | 1059 |
| 965 group('cross-package transforms', () { | 1060 group('cross-package transforms', () { |
| 966 test("can access other packages' source assets", () { | 1061 test("can access other packages' source assets", () { |
| 967 initGraph({ | 1062 initGraph({ |
| 968 "pkg1|a.txt": "pkg2|a.inc", | 1063 "pkg1|a.txt": "pkg2|a.inc", |
| 969 "pkg2|a.inc": "a" | 1064 "pkg2|a.inc": "a" |
| 970 }, {"pkg1": [[new ManyToOneTransformer("txt")]]}); | 1065 }, {"pkg1": [[new ManyToOneTransformer("txt")]]}); |
| 971 | 1066 |
| 972 updateSources(["pkg1|a.txt", "pkg2|a.inc"]); | 1067 updateSources(["pkg1|a.txt", "pkg2|a.inc"]); |
| (...skipping 195 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 1168 | 1263 |
| 1169 transformer2.resumePrimaryInput(); | 1264 transformer2.resumePrimaryInput(); |
| 1170 transformer1.resumeApply(); | 1265 transformer1.resumeApply(); |
| 1171 | 1266 |
| 1172 expectAsset("app|foo.out", "foo.mid.out"); | 1267 expectAsset("app|foo.out", "foo.mid.out"); |
| 1173 buildShouldSucceed(); | 1268 buildShouldSucceed(); |
| 1174 | 1269 |
| 1175 expect(transformer1.numRuns, completion(equals(2))); | 1270 expect(transformer1.numRuns, completion(equals(2))); |
| 1176 expect(transformer2.numRuns, completion(equals(2))); | 1271 expect(transformer2.numRuns, completion(equals(2))); |
| 1177 }); | 1272 }); |
| 1178 }); | 1273 }); |
|
Bob Nystrom
2014/02/26 01:09:15
This file is a beast. In a separate patch, how abo
nweiz
2014/02/26 19:37:14
Sure.
| |
| 1179 } | 1274 } |
| OLD | NEW |