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.group_test; | 5 library barback.test.package_graph.group_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:scheduled_test/scheduled_test.dart'; | 10 import 'package:scheduled_test/scheduled_test.dart'; |
11 | 11 |
12 import '../utils.dart'; | 12 import '../utils.dart'; |
13 | 13 |
14 main() { | 14 main() { |
15 initConfig(); | 15 initConfig(); |
16 test("runs transforms in a group", () { | 16 test("runs transforms in a group", () { |
17 initGraph(["app|foo.a"], {"app": [ | 17 initGraph(["app|foo.a"], {"app": [ |
18 [new TransformerGroup([ | 18 [new TransformerGroup([ |
19 [new RewriteTransformer("a", "b")], | 19 [new RewriteTransformer("a", "b")], |
20 [new RewriteTransformer("b", "c")] | 20 [new RewriteTransformer("b", "c")] |
21 ])] | 21 ])] |
22 ]}); | 22 ]}); |
23 updateSources(["app|foo.a"]); | 23 updateSources(["app|foo.a"]); |
24 expectNoAsset("app|foo.b"); | |
25 expectAsset("app|foo.c", "foo.b.c"); | 24 expectAsset("app|foo.c", "foo.b.c"); |
26 buildShouldSucceed(); | 25 buildShouldSucceed(); |
27 }); | 26 }); |
28 | 27 |
29 test("passes the output of a group to the next phase", () { | 28 test("passes the output of a group to the next phase", () { |
30 initGraph(["app|foo.a"], {"app": [ | 29 initGraph(["app|foo.a"], {"app": [ |
31 [new TransformerGroup([ | 30 [new TransformerGroup([ |
32 [new RewriteTransformer("a", "b")], | 31 [new RewriteTransformer("a", "b")], |
33 [new RewriteTransformer("b", "c")] | 32 [new RewriteTransformer("b", "c")] |
34 ])], | 33 ])], |
35 [new RewriteTransformer("c", "d")] | 34 [new RewriteTransformer("c", "d")] |
36 ]}); | 35 ]}); |
37 updateSources(["app|foo.a"]); | 36 updateSources(["app|foo.a"]); |
38 expectNoAsset("app|foo.c"); | |
39 expectAsset("app|foo.d", "foo.b.c.d"); | 37 expectAsset("app|foo.d", "foo.b.c.d"); |
40 buildShouldSucceed(); | 38 buildShouldSucceed(); |
41 }); | 39 }); |
42 | 40 |
43 test("passes the output of a previous phase to a group", () { | 41 test("passes the output of a previous phase to a group", () { |
44 initGraph(["app|foo.a"], {"app": [ | 42 initGraph(["app|foo.a"], {"app": [ |
45 [new RewriteTransformer("a", "b")], | 43 [new RewriteTransformer("a", "b")], |
46 [new TransformerGroup([ | 44 [new TransformerGroup([ |
47 [new RewriteTransformer("b", "c")], | 45 [new RewriteTransformer("b", "c")], |
48 [new RewriteTransformer("c", "d")] | 46 [new RewriteTransformer("c", "d")] |
49 ])] | 47 ])] |
50 ]}); | 48 ]}); |
51 updateSources(["app|foo.a"]); | 49 updateSources(["app|foo.a"]); |
52 expectNoAsset("app|foo.b"); | |
53 expectAsset("app|foo.d", "foo.b.c.d"); | 50 expectAsset("app|foo.d", "foo.b.c.d"); |
54 buildShouldSucceed(); | 51 buildShouldSucceed(); |
55 }); | 52 }); |
56 | 53 |
57 test("intermediate assets in a group are usable as secondary inputs within " | 54 test("intermediate assets in a group are usable as secondary inputs within " |
58 "that group", () { | 55 "that group", () { |
59 initGraph({ | 56 initGraph({ |
60 "app|foo.a": "contents", | 57 "app|foo.a": "contents", |
61 "app|bar.txt": "foo.inc" | 58 "app|bar.txt": "foo.inc" |
62 }, {"app": [ | 59 }, {"app": [ |
(...skipping 30 matching lines...) Expand all Loading... |
93 | 90 |
94 test("an updated asset is propagated through a group", () { | 91 test("an updated asset is propagated through a group", () { |
95 initGraph(["app|foo.a"], {"app": [ | 92 initGraph(["app|foo.a"], {"app": [ |
96 [new TransformerGroup([ | 93 [new TransformerGroup([ |
97 [new RewriteTransformer("a", "b")], | 94 [new RewriteTransformer("a", "b")], |
98 [new RewriteTransformer("b", "c")] | 95 [new RewriteTransformer("b", "c")] |
99 ])] | 96 ])] |
100 ]}); | 97 ]}); |
101 | 98 |
102 updateSources(["app|foo.a"]); | 99 updateSources(["app|foo.a"]); |
103 expectNoAsset("app|foo.b"); | |
104 expectAsset("app|foo.c", "foo.b.c"); | 100 expectAsset("app|foo.c", "foo.b.c"); |
105 buildShouldSucceed(); | 101 buildShouldSucceed(); |
106 | 102 |
107 modifyAsset("app|foo.a", "new foo"); | 103 modifyAsset("app|foo.a", "new foo"); |
108 updateSources(["app|foo.a"]); | 104 updateSources(["app|foo.a"]); |
109 expectAsset("app|foo.c", "new foo.b.c"); | 105 expectAsset("app|foo.c", "new foo.b.c"); |
110 buildShouldSucceed(); | 106 buildShouldSucceed(); |
111 }); | 107 }); |
112 | 108 |
113 test("an updated asset only runs the necessary transforms in a group", () { | 109 test("an updated asset only runs the necessary transforms in a group", () { |
114 var rewriteA = new RewriteTransformer("a", "b"); | 110 var rewriteA = new RewriteTransformer("a", "b"); |
115 var rewriteX = new RewriteTransformer("x", "b"); | 111 var rewriteX = new RewriteTransformer("x", "b"); |
116 initGraph(["app|foo.a", "app|bar.x"], {"app": [ | 112 initGraph(["app|foo.a", "app|bar.x"], {"app": [ |
117 [new TransformerGroup([ | 113 [new TransformerGroup([ |
118 [rewriteA, rewriteX], | 114 [rewriteA, rewriteX], |
119 [new RewriteTransformer("b", "c")] | 115 [new RewriteTransformer("b", "c")] |
120 ])] | 116 ])] |
121 ]}); | 117 ]}); |
122 | 118 |
123 updateSources(["app|foo.a", "app|bar.x"]); | 119 updateSources(["app|foo.a", "app|bar.x"]); |
124 expectNoAsset("app|foo.b"); | |
125 expectAsset("app|foo.c", "foo.b.c"); | 120 expectAsset("app|foo.c", "foo.b.c"); |
126 expectAsset("app|bar.c", "bar.b.c"); | 121 expectAsset("app|bar.c", "bar.b.c"); |
127 buildShouldSucceed(); | 122 buildShouldSucceed(); |
128 | 123 |
129 modifyAsset("app|foo.a", "new foo"); | 124 modifyAsset("app|foo.a", "new foo"); |
130 updateSources(["app|foo.a"]); | 125 updateSources(["app|foo.a"]); |
131 expectAsset("app|foo.c", "new foo.b.c"); | 126 expectAsset("app|foo.c", "new foo.b.c"); |
132 buildShouldSucceed(); | 127 buildShouldSucceed(); |
133 | 128 |
134 expect(rewriteA.numRuns, completion(equals(2))); | 129 expect(rewriteA.numRuns, completion(equals(2))); |
(...skipping 54 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
189 ])] | 184 ])] |
190 ]}); | 185 ]}); |
191 updateSources(["app|foo.a", "app|bar.x"]); | 186 updateSources(["app|foo.a", "app|bar.x"]); |
192 expectAsset("app|foo.c", "foo.b.c"); | 187 expectAsset("app|foo.c", "foo.b.c"); |
193 expectAsset("app|bar.z", "bar.b.z"); | 188 expectAsset("app|bar.z", "bar.b.z"); |
194 expectNoAsset("app|foo.z"); | 189 expectNoAsset("app|foo.z"); |
195 expectNoAsset("app|bar.c"); | 190 expectNoAsset("app|bar.c"); |
196 buildShouldSucceed(); | 191 buildShouldSucceed(); |
197 }); | 192 }); |
198 | 193 |
199 test("parallel groups' intermediate assets can't collide", () { | 194 // TODO(nweiz): re-enable this test when a transformer can consume its |
200 initGraph(["app|foo.a", "app|foo.x"], {"app": [ | 195 // primary input (issue 16612). |
201 [new TransformerGroup([ | 196 // test("parallel groups' intermediate assets can't collide", () { |
202 [new RewriteTransformer("a", "b")], | 197 // initGraph(["app|foo.a", "app|foo.x"], {"app": [ |
203 [new RewriteTransformer("b", "c")] | 198 // [new TransformerGroup([ |
204 ]), new TransformerGroup([ | 199 // [new RewriteTransformer("a", "b")], |
205 [new RewriteTransformer("x", "b")], | 200 // [new RewriteTransformer("b", "c")] |
206 [new RewriteTransformer("b", "z")] | 201 // ]), new TransformerGroup([ |
207 ])] | 202 // [new RewriteTransformer("x", "b")], |
208 ]}); | 203 // [new RewriteTransformer("b", "z")] |
209 updateSources(["app|foo.a", "app|foo.x"]); | 204 // ])] |
210 expectAsset("app|foo.c", "foo.b.c"); | 205 // ]}); |
211 expectAsset("app|foo.z", "foo.b.z"); | 206 // updateSources(["app|foo.a", "app|foo.x"]); |
212 buildShouldSucceed(); | 207 // expectAsset("app|foo.c", "foo.b.c"); |
213 }); | 208 // expectAsset("app|foo.z", "foo.b.z"); |
| 209 // buildShouldSucceed(); |
| 210 // }); |
214 }); | 211 }); |
215 | 212 |
216 group("pass-through", () { | 213 group("pass-through", () { |
217 test("passes an unused input through a group", () { | 214 test("passes an unused input through a group", () { |
218 initGraph(["app|foo.x"], {"app": [ | 215 initGraph(["app|foo.x"], {"app": [ |
219 [new TransformerGroup([ | 216 [new TransformerGroup([ |
220 [new RewriteTransformer("a", "b")], | 217 [new RewriteTransformer("a", "b")], |
221 [new RewriteTransformer("b", "c")] | 218 [new RewriteTransformer("b", "c")] |
222 ])] | 219 ])] |
223 ]}); | 220 ]}); |
224 updateSources(["app|foo.x"]); | 221 updateSources(["app|foo.x"]); |
225 expectNoAsset("app|foo.c"); | 222 expectNoAsset("app|foo.c"); |
226 expectAsset("app|foo.x", "foo"); | 223 expectAsset("app|foo.x", "foo"); |
227 buildShouldSucceed(); | 224 buildShouldSucceed(); |
228 }); | 225 }); |
229 | 226 |
| 227 test("passes non-overwritten inputs through a group", () { |
| 228 initGraph(["app|foo.a"], {"app": [ |
| 229 [new TransformerGroup([ |
| 230 [new RewriteTransformer("a", "b")], |
| 231 [new RewriteTransformer("b", "c")] |
| 232 ])] |
| 233 ]}); |
| 234 updateSources(["app|foo.a"]); |
| 235 expectAsset("app|foo.a", "foo"); |
| 236 expectAsset("app|foo.b", "foo.b"); |
| 237 expectAsset("app|foo.c", "foo.b.c"); |
| 238 buildShouldSucceed(); |
| 239 }); |
| 240 |
230 test("passes an unused input through parallel groups", () { | 241 test("passes an unused input through parallel groups", () { |
231 initGraph(["app|foo.x"], {"app": [ | 242 initGraph(["app|foo.x"], {"app": [ |
232 [new TransformerGroup([ | 243 [new TransformerGroup([ |
233 [new RewriteTransformer("a", "b")], | 244 [new RewriteTransformer("a", "b")], |
234 [new RewriteTransformer("b", "c")] | 245 [new RewriteTransformer("b", "c")] |
235 ]), new TransformerGroup([ | 246 ]), new TransformerGroup([ |
236 [new RewriteTransformer("1", "2")], | 247 [new RewriteTransformer("1", "2")], |
237 [new RewriteTransformer("2", "3")] | 248 [new RewriteTransformer("2", "3")] |
238 ])] | 249 ])] |
239 ]}); | 250 ]}); |
(...skipping 12 matching lines...) Expand all Loading... |
252 ]), | 263 ]), |
253 new RewriteTransformer("1", "2") | 264 new RewriteTransformer("1", "2") |
254 ]]}); | 265 ]]}); |
255 updateSources(["app|foo.x"]); | 266 updateSources(["app|foo.x"]); |
256 expectNoAsset("app|foo.c"); | 267 expectNoAsset("app|foo.c"); |
257 expectNoAsset("app|foo.2"); | 268 expectNoAsset("app|foo.2"); |
258 expectAsset("app|foo.x", "foo"); | 269 expectAsset("app|foo.x", "foo"); |
259 buildShouldSucceed(); | 270 buildShouldSucceed(); |
260 }); | 271 }); |
261 | 272 |
262 test("doesn't pass through an input that's used by a group but not by " | 273 test("doesn't pass through an input that's overwritten by a group but not " |
263 "transformers", () { | 274 "by transformers", () { |
264 initGraph(["app|foo.a"], {"app": [[ | 275 initGraph(["app|foo.a"], {"app": [[ |
265 new TransformerGroup([ | 276 new TransformerGroup([ |
266 [new RewriteTransformer("a", "b")], | 277 [new RewriteTransformer("a", "a")], |
267 [new RewriteTransformer("b", "c")] | |
268 ]), | 278 ]), |
269 new RewriteTransformer("x", "y") | 279 new RewriteTransformer("x", "y") |
270 ]]}); | 280 ]]}); |
271 updateSources(["app|foo.a"]); | 281 updateSources(["app|foo.a"]); |
272 expectNoAsset("app|foo.a"); | |
273 expectNoAsset("app|foo.y"); | 282 expectNoAsset("app|foo.y"); |
274 expectAsset("app|foo.c", "foo.b.c"); | 283 expectAsset("app|foo.a", "foo.a"); |
275 buildShouldSucceed(); | 284 buildShouldSucceed(); |
276 }); | 285 }); |
277 | 286 |
278 test("doesn't pass through an input that's used by transformers but not by " | 287 test("doesn't pass through an input that's overwritten by transformers but " |
279 "a group", () { | 288 "not by a group", () { |
280 initGraph(["app|foo.x"], {"app": [[ | 289 initGraph(["app|foo.x"], {"app": [[ |
281 new TransformerGroup([ | 290 new TransformerGroup([ |
282 [new RewriteTransformer("a", "b")], | 291 [new RewriteTransformer("a", "b")], |
283 [new RewriteTransformer("b", "c")] | 292 [new RewriteTransformer("b", "c")] |
284 ]), | 293 ]), |
285 new RewriteTransformer("x", "y") | 294 new RewriteTransformer("x", "x") |
286 ]]}); | 295 ]]}); |
287 updateSources(["app|foo.x"]); | 296 updateSources(["app|foo.x"]); |
288 expectNoAsset("app|foo.x"); | |
289 expectNoAsset("app|foo.c"); | 297 expectNoAsset("app|foo.c"); |
290 expectAsset("app|foo.y", "foo.y"); | 298 expectAsset("app|foo.x", "foo.x"); |
291 buildShouldSucceed(); | 299 buildShouldSucceed(); |
292 }); | 300 }); |
293 | 301 |
294 test("doesn't detect a collision for an input that's modified in-place by " | 302 test("doesn't detect a collision for an input that's modified in-place by " |
295 "a transformer", () { | 303 "a transformer", () { |
296 initGraph(["app|foo.x"], {"app": [[ | 304 initGraph(["app|foo.x"], {"app": [[ |
297 new TransformerGroup([ | 305 new TransformerGroup([ |
298 [new RewriteTransformer("a", "b")], | 306 [new RewriteTransformer("a", "b")], |
299 [new RewriteTransformer("b", "c")] | 307 [new RewriteTransformer("b", "c")] |
300 ]), | 308 ]), |
301 new RewriteTransformer("x", "x") | 309 new RewriteTransformer("x", "x") |
302 ]]}); | 310 ]]}); |
303 updateSources(["app|foo.x"]); | 311 updateSources(["app|foo.x"]); |
304 expectAsset("app|foo.x", "foo.x"); | 312 expectAsset("app|foo.x", "foo.x"); |
305 buildShouldSucceed(); | 313 buildShouldSucceed(); |
306 }); | 314 }); |
307 | 315 |
308 test("doesn't detect a collision for an input that's modified in-place by " | 316 test("doesn't detect a collision for an input that's modified in-place by " |
309 "a group", () { | 317 "a group", () { |
310 initGraph(["app|foo.a"], {"app": [[ | 318 initGraph(["app|foo.a"], {"app": [[ |
311 new TransformerGroup([[new RewriteTransformer("a", "a")]]), | 319 new TransformerGroup([[new RewriteTransformer("a", "a")]]), |
312 new RewriteTransformer("x", "y") | 320 new RewriteTransformer("x", "y") |
313 ]]}); | 321 ]]}); |
314 updateSources(["app|foo.a"]); | 322 updateSources(["app|foo.a"]); |
315 expectAsset("app|foo.a", "foo.a"); | 323 expectAsset("app|foo.a", "foo.a"); |
316 buildShouldSucceed(); | 324 buildShouldSucceed(); |
317 }); | 325 }); |
318 | |
319 test("doesn't pass-through an asset that ceases to be forwarded due to a " | |
320 "resolved collision", () { | |
321 initGraph({ | |
322 "app|foo.a": "foo.a", | |
323 "app|foo.x": "foo.x" | |
324 }, {"app": [ | |
325 [new TransformerGroup([[ | |
326 new CheckContentAndRenameTransformer( | |
327 "a", "new foo.a", "z", "modified foo.a"), | |
328 new RewriteTransformer('x', 'a') | |
329 ]])] | |
330 ]}); | |
331 | |
332 updateSources(["app|foo.a", "app|foo.x"]); | |
333 expectAsset("app|foo.a", "foo.a"); | |
334 expectNoAsset("app|foo.z"); | |
335 buildShouldFail([isAssetCollisionException("app|foo.a")]); | |
336 | |
337 modifyAsset('app|foo.a', 'new foo.a'); | |
338 updateSources(["app|foo.a"]); | |
339 expectAsset("app|foo.a", "foo.x.a"); | |
340 expectAsset("app|foo.z", "modified foo.a"); | |
341 buildShouldSucceed(); | |
342 }); | |
343 }); | 326 }); |
344 | 327 |
345 test("runs transforms in an added group", () { | 328 test("runs transforms in an added group", () { |
346 var rewrite = new RewriteTransformer("a", "z"); | 329 var rewrite = new RewriteTransformer("a", "z"); |
347 initGraph(["app|foo.a"], {"app": [[rewrite]]}); | 330 initGraph(["app|foo.a"], {"app": [[rewrite]]}); |
348 | 331 |
349 updateSources(["app|foo.a"]); | 332 updateSources(["app|foo.a"]); |
350 expectAsset("app|foo.z", "foo.z"); | 333 expectAsset("app|foo.z", "foo.z"); |
351 buildShouldSucceed(); | 334 buildShouldSucceed(); |
352 | 335 |
(...skipping 23 matching lines...) Expand all Loading... |
376 [group, new RewriteTransformer("a", "z")] | 359 [group, new RewriteTransformer("a", "z")] |
377 ]); | 360 ]); |
378 expectAsset("app|foo.c", "foo.b.c"); | 361 expectAsset("app|foo.c", "foo.b.c"); |
379 expectAsset("app|foo.z", "foo.z"); | 362 expectAsset("app|foo.z", "foo.z"); |
380 buildShouldSucceed(); | 363 buildShouldSucceed(); |
381 | 364 |
382 expect(rewrite1.numRuns, completion(equals(1))); | 365 expect(rewrite1.numRuns, completion(equals(1))); |
383 expect(rewrite2.numRuns, completion(equals(1))); | 366 expect(rewrite2.numRuns, completion(equals(1))); |
384 }); | 367 }); |
385 | 368 |
386 test("doesn't pass through an input that's used by an added group", () { | 369 test("doesn't pass through an input that's overwritten by an added group", |
| 370 () { |
387 var rewrite = new RewriteTransformer("x", "z"); | 371 var rewrite = new RewriteTransformer("x", "z"); |
388 initGraph(["app|foo.a"], {"app": [[rewrite]]}); | 372 initGraph(["app|foo.a"], {"app": [[rewrite]]}); |
389 | 373 |
390 updateSources(["app|foo.a"]); | 374 updateSources(["app|foo.a"]); |
391 expectAsset("app|foo.a", "foo"); | 375 expectAsset("app|foo.a", "foo"); |
392 buildShouldSucceed(); | 376 buildShouldSucceed(); |
393 | 377 |
394 updateTransformers("app", [ | 378 updateTransformers("app", [ |
395 [rewrite, new TransformerGroup([ | 379 [rewrite, new TransformerGroup([[new RewriteTransformer("a", "a")]])] |
396 [new RewriteTransformer("a", "b")], | |
397 [new RewriteTransformer("b", "c")] | |
398 ])] | |
399 ]); | 380 ]); |
400 expectNoAsset("app|foo.a"); | 381 expectAsset("app|foo.a", "foo.a"); |
401 expectAsset("app|foo.c", "foo.b.c"); | |
402 buildShouldSucceed(); | 382 buildShouldSucceed(); |
403 }); | 383 }); |
404 | 384 |
405 // TODO(nweiz): make the collision error message nice | 385 // TODO(nweiz): make the collision error message nice |
406 test("reports collisions within a group", () { | 386 test("reports collisions within a group", () { |
407 initGraph(["app|foo.a", "app|foo.x"], {"app": [ | 387 initGraph(["app|foo.a", "app|foo.x"], {"app": [ |
408 [new TransformerGroup([ | 388 [new TransformerGroup([ |
409 [new RewriteTransformer("a", "b")], | 389 [new RewriteTransformer("a", "b")], |
410 [new RewriteTransformer("x", "b")] | 390 [new RewriteTransformer("x", "b")] |
411 ])] | 391 ])] |
412 ]}); | 392 ]}); |
413 updateSources(["app|foo.a", "app|foo.x"]); | 393 updateSources(["app|foo.a", "app|foo.x"]); |
414 buildShouldFail([isAssetCollisionException("app|foo.b")]); | 394 buildShouldFail([isAssetCollisionException("app|foo.b")]); |
415 }); | 395 }); |
416 | 396 |
417 test("reports collisions between a group and a non-grouped transform", () { | 397 test("reports collisions between a group and a non-grouped transform", () { |
418 initGraph(["app|foo.a", "app|foo.x"], {"app": [[ | 398 initGraph(["app|foo.a", "app|foo.x"], {"app": [[ |
419 new TransformerGroup([ | 399 new TransformerGroup([ |
420 [new RewriteTransformer("a", "b")], | 400 [new RewriteTransformer("a", "b")], |
421 [new RewriteTransformer("b", "c")] | 401 [new RewriteTransformer("b", "c")] |
422 ]), | 402 ]), |
423 new RewriteTransformer("x", "c") | 403 new RewriteTransformer("x", "c") |
424 ]]}); | 404 ]]}); |
425 updateSources(["app|foo.a", "app|foo.x"]); | 405 updateSources(["app|foo.a", "app|foo.x"]); |
426 buildShouldFail([isAssetCollisionException("app|foo.c")]); | 406 buildShouldFail([isAssetCollisionException("app|foo.c")]); |
427 }); | 407 }); |
428 } | 408 } |
OLD | NEW |