OLD | NEW |
| (Empty) |
1 // Copyright (c) 2014, 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.pass_through_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("can access other packages' source assets", () { | |
15 initGraph({ | |
16 "pkg1|a.txt": "pkg2|a.inc", | |
17 "pkg2|a.inc": "a" | |
18 }, {"pkg1": [[new ManyToOneTransformer("txt")]]}); | |
19 | |
20 updateSources(["pkg1|a.txt", "pkg2|a.inc"]); | |
21 expectAsset("pkg1|a.out", "a"); | |
22 buildShouldSucceed(); | |
23 }); | |
24 | |
25 test("can access other packages' transformed assets", () { | |
26 initGraph({ | |
27 "pkg1|a.txt": "pkg2|a.inc", | |
28 "pkg2|a.txt": "a" | |
29 }, { | |
30 "pkg1": [[new ManyToOneTransformer("txt")]], | |
31 "pkg2": [[new RewriteTransformer("txt", "inc")]] | |
32 }); | |
33 | |
34 updateSources(["pkg1|a.txt", "pkg2|a.txt"]); | |
35 expectAsset("pkg1|a.out", "a.inc"); | |
36 buildShouldSucceed(); | |
37 }); | |
38 | |
39 test("re-runs a transform when an input from another package changes", () { | |
40 initGraph({ | |
41 "pkg1|a.txt": "pkg2|a.inc", | |
42 "pkg2|a.inc": "a" | |
43 }, { | |
44 "pkg1": [[new ManyToOneTransformer("txt")]] | |
45 }); | |
46 | |
47 updateSources(["pkg1|a.txt", "pkg2|a.inc"]); | |
48 expectAsset("pkg1|a.out", "a"); | |
49 buildShouldSucceed(); | |
50 | |
51 modifyAsset("pkg2|a.inc", "new a"); | |
52 updateSources(["pkg2|a.inc"]); | |
53 expectAsset("pkg1|a.out", "new a"); | |
54 buildShouldSucceed(); | |
55 }); | |
56 | |
57 test("re-runs a transform when a transformed input from another package " | |
58 "changes", () { | |
59 initGraph({ | |
60 "pkg1|a.txt": "pkg2|a.inc", | |
61 "pkg2|a.txt": "a" | |
62 }, { | |
63 "pkg1": [[new ManyToOneTransformer("txt")]], | |
64 "pkg2": [[new RewriteTransformer("txt", "inc")]] | |
65 }); | |
66 | |
67 updateSources(["pkg1|a.txt", "pkg2|a.txt"]); | |
68 expectAsset("pkg1|a.out", "a.inc"); | |
69 buildShouldSucceed(); | |
70 | |
71 modifyAsset("pkg2|a.txt", "new a"); | |
72 updateSources(["pkg2|a.txt"]); | |
73 expectAsset("pkg1|a.out", "new a.inc"); | |
74 buildShouldSucceed(); | |
75 }); | |
76 | |
77 test("doesn't complete the build until all packages' transforms are " | |
78 "finished running", () { | |
79 var transformer = new ManyToOneTransformer("txt"); | |
80 initGraph({ | |
81 "pkg1|a.txt": "pkg2|a.inc", | |
82 "pkg2|a.inc": "a" | |
83 }, { | |
84 "pkg1": [[transformer]] | |
85 }); | |
86 | |
87 updateSources(["pkg1|a.txt", "pkg2|a.inc"]); | |
88 expectAsset("pkg1|a.out", "a"); | |
89 buildShouldSucceed(); | |
90 | |
91 transformer.pauseApply(); | |
92 modifyAsset("pkg2|a.inc", "new a"); | |
93 updateSources(["pkg2|a.inc"]); | |
94 buildShouldNotBeDone(); | |
95 | |
96 transformer.resumeApply(); | |
97 buildShouldSucceed(); | |
98 }); | |
99 | |
100 test("runs a transform that's added because of a change in another package", | |
101 () { | |
102 initGraph({ | |
103 "pkg1|a.txt": "pkg2|a.inc", | |
104 "pkg2|a.inc": "b" | |
105 }, { | |
106 "pkg1": [ | |
107 [new ManyToOneTransformer("txt")], | |
108 [new OneToManyTransformer("out")], | |
109 [new RewriteTransformer("md", "done")] | |
110 ], | |
111 }); | |
112 | |
113 // pkg1|a.txt generates outputs based on the contents of pkg2|a.inc. At | |
114 // first pkg2|a.inc only includes "b", which is not transformed. Then | |
115 // pkg2|a.inc is updated to include "b,c.md". pkg1|c.md triggers the | |
116 // md->done rewrite transformer, producing pkg1|c.done. | |
117 | |
118 updateSources(["pkg1|a.txt", "pkg2|a.inc"]); | |
119 expectAsset("pkg1|b", "spread out"); | |
120 buildShouldSucceed(); | |
121 | |
122 modifyAsset("pkg2|a.inc", "b,c.md"); | |
123 updateSources(["pkg2|a.inc"]); | |
124 expectAsset("pkg1|b", "spread out"); | |
125 expectAsset("pkg1|c.done", "spread out.done"); | |
126 buildShouldSucceed(); | |
127 }); | |
128 | |
129 test("doesn't run a transform that's removed because of a change in " | |
130 "another package", () { | |
131 initGraph({ | |
132 "pkg1|a.txt": "pkg2|a.inc", | |
133 "pkg2|a.inc": "b,c.md" | |
134 }, { | |
135 "pkg1": [ | |
136 [new ManyToOneTransformer("txt")], | |
137 [new OneToManyTransformer("out")], | |
138 [new RewriteTransformer("md", "done")] | |
139 ], | |
140 }); | |
141 | |
142 updateSources(["pkg1|a.txt", "pkg2|a.inc"]); | |
143 expectAsset("pkg1|b", "spread out"); | |
144 expectAsset("pkg1|c.done", "spread out.done"); | |
145 buildShouldSucceed(); | |
146 | |
147 modifyAsset("pkg2|a.inc", "b"); | |
148 updateSources(["pkg2|a.inc"]); | |
149 expectAsset("pkg1|b", "spread out"); | |
150 expectNoAsset("pkg1|c.done"); | |
151 buildShouldSucceed(); | |
152 }); | |
153 | |
154 test("sees a transformer that's newly applied to a cross-package " | |
155 "dependency", () { | |
156 initGraph({ | |
157 "pkg1|a.txt": "pkg2|a.inc", | |
158 "pkg2|a.inc": "a" | |
159 }, { | |
160 "pkg1": [[new ManyToOneTransformer("txt")]], | |
161 "pkg2": [[new CheckContentTransformer("b", " transformed")]] | |
162 }); | |
163 | |
164 updateSources(["pkg1|a.txt", "pkg2|a.inc"]); | |
165 expectAsset("pkg1|a.out", "a"); | |
166 buildShouldSucceed(); | |
167 | |
168 modifyAsset("pkg2|a.inc", "b"); | |
169 updateSources(["pkg2|a.inc"]); | |
170 expectAsset("pkg1|a.out", "b transformed"); | |
171 buildShouldSucceed(); | |
172 }); | |
173 | |
174 test("doesn't see a transformer that's newly not applied to a " | |
175 "cross-package dependency", () { | |
176 initGraph({ | |
177 "pkg1|a.txt": "pkg2|a.inc", | |
178 "pkg2|a.inc": "a" | |
179 }, { | |
180 "pkg1": [[new ManyToOneTransformer("txt")]], | |
181 "pkg2": [[new CheckContentTransformer("a", " transformed")]] | |
182 }); | |
183 | |
184 updateSources(["pkg1|a.txt", "pkg2|a.inc"]); | |
185 expectAsset("pkg1|a.out", "a transformed"); | |
186 buildShouldSucceed(); | |
187 | |
188 modifyAsset("pkg2|a.inc", "b"); | |
189 updateSources(["pkg2|a.inc"]); | |
190 expectAsset("pkg1|a.out", "b"); | |
191 buildShouldSucceed(); | |
192 }); | |
193 | |
194 test("re-runs if the primary input is invalidated before accessing", () { | |
195 var transformer1 = new RewriteTransformer("txt", "mid"); | |
196 var transformer2 = new RewriteTransformer("mid", "out"); | |
197 | |
198 initGraph([ | |
199 "app|foo.txt" | |
200 ], {"app": [ | |
201 [transformer1], | |
202 [transformer2] | |
203 ]}); | |
204 | |
205 transformer2.pausePrimaryInput(); | |
206 updateSources(["app|foo.txt"]); | |
207 | |
208 // Wait long enough to ensure that transformer1 has completed and | |
209 // transformer2 has started. | |
210 schedule(pumpEventQueue); | |
211 | |
212 // Update the source again so that transformer1 invalidates the primary | |
213 // input of transformer2. | |
214 transformer1.pauseApply(); | |
215 updateSources(["app|foo.txt"]); | |
216 | |
217 transformer2.resumePrimaryInput(); | |
218 transformer1.resumeApply(); | |
219 | |
220 expectAsset("app|foo.out", "foo.mid.out"); | |
221 buildShouldSucceed(); | |
222 | |
223 expect(transformer1.numRuns, completion(equals(2))); | |
224 expect(transformer2.numRuns, completion(equals(2))); | |
225 }); | |
226 } | |
OLD | NEW |