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