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 788 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 799 updateSources(["pkg2|foo.txt"]); | 799 updateSources(["pkg2|foo.txt"]); |
| 800 expectAsset("pkg1|foo.out", "foo.out"); | 800 expectAsset("pkg1|foo.out", "foo.out"); |
| 801 buildShouldNotBeDone(); | 801 buildShouldNotBeDone(); |
| 802 | 802 |
| 803 // Now that the provider is unpaused, pkg2's transforms finish and the | 803 // Now that the provider is unpaused, pkg2's transforms finish and the |
| 804 // overall build succeeds. | 804 // overall build succeeds. |
| 805 resumeProvider(); | 805 resumeProvider(); |
| 806 buildShouldSucceed(); | 806 buildShouldSucceed(); |
| 807 }); | 807 }); |
| 808 | 808 |
| 809 group("added/removed transformers", () { | |
|
Bob Nystrom
2013/08/20 19:08:54
Let's move this to a separate test suite. This one
nweiz
2013/08/20 21:39:17
Done.
| |
| 810 test("a new transformer is applied to a matching asset", () { | |
| 811 initGraph(["app|foo.blub"]); | |
| 812 | |
| 813 updateSources(["app|foo.blub"]); | |
| 814 expectAsset("app|foo.blub", "foo"); | |
| 815 buildShouldSucceed(); | |
| 816 | |
| 817 updateTransformers("app", [[new RewriteTransformer("blub", "blab")]]); | |
| 818 expectAsset("app|foo.blab", "foo.blab"); | |
| 819 expectNoAsset("app|foo.blub"); | |
| 820 buildShouldSucceed(); | |
| 821 }); | |
| 822 | |
| 823 test("a new transformer is not applied to a non-matching asset", () { | |
| 824 initGraph(["app|foo.blub"]); | |
| 825 | |
| 826 updateSources(["app|foo.blub"]); | |
| 827 expectAsset("app|foo.blub", "foo"); | |
| 828 buildShouldSucceed(); | |
| 829 | |
| 830 updateTransformers("app", [[new RewriteTransformer("zip", "zap")]]); | |
| 831 expectAsset("app|foo.blub", "foo"); | |
| 832 expectNoAsset("app|foo.zap"); | |
| 833 buildShouldSucceed(); | |
| 834 }); | |
| 835 | |
| 836 test("updateTransformers doesn't re-run an old transformer", () { | |
|
Bob Nystrom
2013/08/20 19:08:54
What if the old transformer is updated to be in a
nweiz
2013/08/20 21:39:17
Barback sees that as two new transformers. A trans
| |
| 837 var rewrite = new RewriteTransformer("blub", "blab"); | |
| 838 initGraph(["app|foo.blub"], {"app": [[rewrite]]}); | |
| 839 | |
| 840 updateSources(["app|foo.blub"]); | |
| 841 expectAsset("app|foo.blab", "foo.blab"); | |
| 842 expectNoAsset("app|foo.blub"); | |
| 843 buildShouldSucceed(); | |
| 844 | |
| 845 updateTransformers("app", [[rewrite]]); | |
| 846 expectAsset("app|foo.blab", "foo.blab"); | |
| 847 expectNoAsset("app|foo.blub"); | |
| 848 buildShouldSucceed(); | |
| 849 | |
| 850 expect(rewrite.numRuns, completion(equals(1))); | |
| 851 }); | |
| 852 | |
| 853 test("a removed transformer is no longer applied", () { | |
| 854 initGraph(["app|foo.blub"], {"app": [ | |
| 855 [new RewriteTransformer("blub", "blab")] | |
| 856 ]}); | |
| 857 | |
| 858 updateSources(["app|foo.blub"]); | |
| 859 expectAsset("app|foo.blab", "foo.blab"); | |
| 860 expectNoAsset("app|foo.blub"); | |
| 861 buildShouldSucceed(); | |
| 862 | |
| 863 updateTransformers("app", []); | |
| 864 expectAsset("app|foo.blub", "foo"); | |
| 865 expectNoAsset("app|foo.blab"); | |
| 866 buildShouldSucceed(); | |
| 867 }); | |
| 868 | |
| 869 test("a new transformer is pipelined", () { | |
| 870 var rewrite1 = new RewriteTransformer("source", "phase1"); | |
| 871 var rewrite3 = new RewriteTransformer("phase2", "phase3"); | |
| 872 initGraph(["app|foo.source"], {"app": [ | |
| 873 [rewrite1], | |
| 874 [rewrite3] | |
| 875 ]}); | |
| 876 | |
| 877 updateSources(["app|foo.source"]); | |
| 878 expectNoAsset("app|foo.phase3"); | |
| 879 buildShouldSucceed(); | |
| 880 | |
| 881 updateTransformers("app", [ | |
| 882 [rewrite1], | |
| 883 [new RewriteTransformer("phase1", "phase2")], | |
| 884 [rewrite3] | |
| 885 ]); | |
| 886 expectAsset("app|foo.phase3", "foo.phase1.phase2.phase3"); | |
| 887 buildShouldSucceed(); | |
| 888 }); | |
| 889 | |
| 890 test("a removed transformer is un-pipelined", () { | |
| 891 var rewrite1 = new RewriteTransformer("source", "phase1"); | |
| 892 var rewrite3 = new RewriteTransformer("phase2", "phase3"); | |
| 893 initGraph(["app|foo.source"], {"app": [ | |
| 894 [rewrite1], | |
| 895 [new RewriteTransformer("phase1", "phase2")], | |
| 896 [rewrite3] | |
| 897 ]}); | |
| 898 | |
| 899 updateSources(["app|foo.source"]); | |
| 900 expectAsset("app|foo.phase3", "foo.phase1.phase2.phase3"); | |
| 901 buildShouldSucceed(); | |
| 902 | |
| 903 updateTransformers("app", [[rewrite1], [rewrite3]]); | |
| 904 expectNoAsset("app|foo.phase3"); | |
| 905 buildShouldSucceed(); | |
| 906 }); | |
| 907 | |
| 908 test("a transformer is removed during isPrimary", () { | |
| 909 var rewrite = new RewriteTransformer("blub", "blab"); | |
| 910 initGraph(["app|foo.blub"], {"app": [[rewrite]]}); | |
| 911 | |
| 912 rewrite.pauseIsPrimary("app|foo.blub"); | |
| 913 updateSources(["app|foo.blub"]); | |
| 914 // Ensure we're waiting on [rewrite.isPrimary]. | |
| 915 schedule(pumpEventQueue); | |
| 916 | |
| 917 updateTransformers("app", []); | |
| 918 rewrite.resumeIsPrimary("app|foo.blub"); | |
| 919 expectAsset("app|foo.blub", "foo"); | |
| 920 expectNoAsset("app|foo.blab"); | |
| 921 buildShouldSucceed(); | |
| 922 }); | |
| 923 | |
| 924 test("a transformer is removed during apply", () { | |
| 925 var rewrite = new RewriteTransformer("blub", "blab"); | |
| 926 initGraph(["app|foo.blub"], {"app": [[rewrite]]}); | |
| 927 | |
| 928 rewrite.pauseApply(); | |
| 929 updateSources(["app|foo.blub"]); | |
| 930 // Ensure we're waiting on [rewrite.apply]. | |
| 931 schedule(pumpEventQueue); | |
| 932 | |
| 933 updateTransformers("app", []); | |
| 934 rewrite.resumeApply(); | |
| 935 expectAsset("app|foo.blub", "foo"); | |
| 936 expectNoAsset("app|foo.blab"); | |
| 937 buildShouldSucceed(); | |
| 938 }); | |
| 939 | |
| 940 test("a new transformer can see pass-through assets", () { | |
| 941 var rewrite = new RewriteTransformer("zip", "zap"); | |
| 942 initGraph(["app|foo.blub"], {"app": [[rewrite]]}); | |
| 943 | |
| 944 updateSources(["app|foo.blub"]); | |
| 945 buildShouldSucceed(); | |
| 946 | |
| 947 updateTransformers("app", [ | |
| 948 [rewrite], | |
| 949 [new RewriteTransformer("blub", "blab")] | |
| 950 ]); | |
| 951 expectAsset("app|foo.blab", "foo.blab"); | |
| 952 expectNoAsset("app|foo.blub"); | |
| 953 buildShouldSucceed(); | |
| 954 }); | |
| 955 | |
| 956 test("a cross-package transform sees a new transformer in a new phase", () { | |
| 957 // TODO(nweiz): make this work. | |
| 958 return; | |
|
Bob Nystrom
2013/08/20 19:08:54
I'd like this to be more visible. How about pullin
nweiz
2013/08/20 21:39:17
It won't be around for more than a week or two; I'
Bob Nystrom
2013/08/20 22:18:12
SGTM.
| |
| 959 | |
| 960 var rewrite = new RewriteTransformer("inc", "inc"); | |
| 961 initGraph({ | |
| 962 "pkg1|foo.txt": "pkg2|foo.inc", | |
| 963 "pkg2|foo.inc": "foo" | |
| 964 }, { | |
| 965 "pkg1": [[new ManyToOneTransformer("txt")]], | |
| 966 "pkg2": [[rewrite]] | |
| 967 }); | |
| 968 | |
| 969 updateSources(["pkg1|foo.txt", "pkg2|foo.inc"]); | |
| 970 expectAsset("pkg1|foo.out", "foo"); | |
| 971 buildShouldSucceed(); | |
| 972 | |
| 973 updateTransformers("pkg2", [ | |
| 974 [rewrite], | |
| 975 [new RewriteTransformer("inc", "inc")] | |
| 976 ]); | |
| 977 expectAsset("pkg1|foo.out", "foo.inc.inc"); | |
| 978 buildShouldSucceed(); | |
| 979 }); | |
| 980 | |
| 981 test("a cross-package transform doesn't see a removed transformer in a " | |
| 982 "removed phase", () { | |
| 983 var rewrite = new RewriteTransformer("inc", "inc"); | |
| 984 initGraph({ | |
| 985 "pkg1|foo.txt": "pkg2|foo.inc", | |
| 986 "pkg2|foo.inc": "foo" | |
| 987 }, { | |
| 988 "pkg1": [[new ManyToOneTransformer("txt")]], | |
| 989 "pkg2": [ | |
| 990 [rewrite], | |
| 991 [new RewriteTransformer("inc", "inc")] | |
| 992 ] | |
| 993 }); | |
| 994 | |
| 995 updateSources(["pkg1|foo.txt", "pkg2|foo.inc"]); | |
| 996 expectAsset("pkg1|foo.out", "foo.inc.inc"); | |
| 997 buildShouldSucceed(); | |
| 998 | |
| 999 updateTransformers("pkg2", [[rewrite]]); | |
| 1000 expectAsset("pkg1|foo.out", "foo.inc"); | |
| 1001 buildShouldSucceed(); | |
| 1002 }); | |
| 1003 }); | |
| 1004 | |
| 809 group("pass-through", () { | 1005 group("pass-through", () { |
| 810 test("passes an asset through a phase in which no transforms apply", () { | 1006 test("passes an asset through a phase in which no transforms apply", () { |
| 811 initGraph([ | 1007 initGraph([ |
| 812 "app|foo.in", | 1008 "app|foo.in", |
| 813 "app|bar.zip", | 1009 "app|bar.zip", |
| 814 ], {"app": [ | 1010 ], {"app": [ |
| 815 [new RewriteTransformer("in", "mid")], | 1011 [new RewriteTransformer("in", "mid")], |
| 816 [new RewriteTransformer("zip", "zap")], | 1012 [new RewriteTransformer("zip", "zap")], |
| 817 [new RewriteTransformer("mid", "out")], | 1013 [new RewriteTransformer("mid", "out")], |
| 818 ]}); | 1014 ]}); |
| (...skipping 229 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 1048 expectAsset("pkg1|b", "spread out"); | 1244 expectAsset("pkg1|b", "spread out"); |
| 1049 expectAsset("pkg1|c.done", "spread out.done"); | 1245 expectAsset("pkg1|c.done", "spread out.done"); |
| 1050 buildShouldSucceed(); | 1246 buildShouldSucceed(); |
| 1051 | 1247 |
| 1052 modifyAsset("pkg2|a.inc", "b"); | 1248 modifyAsset("pkg2|a.inc", "b"); |
| 1053 updateSources(["pkg2|a.inc"]); | 1249 updateSources(["pkg2|a.inc"]); |
| 1054 expectAsset("pkg1|b", "spread out"); | 1250 expectAsset("pkg1|b", "spread out"); |
| 1055 expectNoAsset("pkg1|c.done"); | 1251 expectNoAsset("pkg1|c.done"); |
| 1056 buildShouldSucceed(); | 1252 buildShouldSucceed(); |
| 1057 }); | 1253 }); |
| 1254 | |
| 1255 test("sees a transformer that's newly applied to a cross-package " | |
| 1256 "dependency", () { | |
| 1257 initGraph({ | |
| 1258 "pkg1|a.txt": "pkg2|a.inc", | |
| 1259 "pkg2|a.inc": "a" | |
| 1260 }, { | |
| 1261 "pkg1": [[new ManyToOneTransformer("txt")]], | |
| 1262 "pkg2": [[new CheckContentTransformer("b", " transformed")]] | |
| 1263 }); | |
| 1264 | |
| 1265 updateSources(["pkg1|a.txt", "pkg2|a.inc"]); | |
| 1266 expectAsset("pkg1|a.out", "a"); | |
| 1267 buildShouldSucceed(); | |
| 1268 | |
| 1269 modifyAsset("pkg2|a.inc", "b"); | |
| 1270 updateSources(["pkg2|a.inc"]); | |
| 1271 expectAsset("pkg1|a.out", "b transformed"); | |
| 1272 buildShouldSucceed(); | |
| 1273 }); | |
| 1274 | |
| 1275 test("doesn't see a transformer that's newly not applied to a " | |
| 1276 "cross-package dependency", () { | |
| 1277 initGraph({ | |
| 1278 "pkg1|a.txt": "pkg2|a.inc", | |
| 1279 "pkg2|a.inc": "a" | |
| 1280 }, { | |
| 1281 "pkg1": [[new ManyToOneTransformer("txt")]], | |
| 1282 "pkg2": [[new CheckContentTransformer("a", " transformed")]] | |
| 1283 }); | |
| 1284 | |
| 1285 updateSources(["pkg1|a.txt", "pkg2|a.inc"]); | |
| 1286 expectAsset("pkg1|a.out", "a transformed"); | |
| 1287 buildShouldSucceed(); | |
| 1288 | |
| 1289 modifyAsset("pkg2|a.inc", "b"); | |
| 1290 updateSources(["pkg2|a.inc"]); | |
| 1291 expectAsset("pkg1|a.out", "b"); | |
| 1292 buildShouldSucceed(); | |
| 1293 }); | |
| 1058 }); | 1294 }); |
| 1059 } | 1295 } |
| OLD | NEW |