OLD | NEW |
(Empty) | |
| 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 |
| 3 // BSD-style license that can be found in the LICENSE file. |
| 4 |
| 5 library barback.test.package_graph.transform_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("gets a transformed asset with a different path", () { |
| 15 initGraph(["app|foo.blub"], {"app": [ |
| 16 [new RewriteTransformer("blub", "blab")] |
| 17 ]}); |
| 18 updateSources(["app|foo.blub"]); |
| 19 expectAsset("app|foo.blab", "foo.blab"); |
| 20 buildShouldSucceed(); |
| 21 }); |
| 22 |
| 23 test("gets a transformed asset with the same path", () { |
| 24 initGraph(["app|foo.blub"], {"app": [ |
| 25 [new RewriteTransformer("blub", "blub")] |
| 26 ]}); |
| 27 updateSources(["app|foo.blub"]); |
| 28 expectAsset("app|foo.blub", "foo.blub"); |
| 29 buildShouldSucceed(); |
| 30 }); |
| 31 |
| 32 test("doesn't find an output from a later phase", () { |
| 33 initGraph(["app|foo.a"], {"app": [ |
| 34 [new RewriteTransformer("b", "c")], |
| 35 [new RewriteTransformer("a", "b")] |
| 36 ]}); |
| 37 updateSources(["app|foo.a"]); |
| 38 expectNoAsset("app|foo.c"); |
| 39 buildShouldSucceed(); |
| 40 }); |
| 41 |
| 42 test("doesn't find an output from the same phase", () { |
| 43 initGraph(["app|foo.a"], {"app": [ |
| 44 [ |
| 45 new RewriteTransformer("a", "b"), |
| 46 new RewriteTransformer("b", "c") |
| 47 ] |
| 48 ]}); |
| 49 updateSources(["app|foo.a"]); |
| 50 expectAsset("app|foo.b", "foo.b"); |
| 51 expectNoAsset("app|foo.c"); |
| 52 buildShouldSucceed(); |
| 53 }); |
| 54 |
| 55 test("finds the latest output before the transformer's phase", () { |
| 56 initGraph(["app|foo.blub"], {"app": [ |
| 57 [new RewriteTransformer("blub", "blub")], |
| 58 [ |
| 59 new RewriteTransformer("blub", "blub"), |
| 60 new RewriteTransformer("blub", "done") |
| 61 ], |
| 62 [new RewriteTransformer("blub", "blub")] |
| 63 ]}); |
| 64 updateSources(["app|foo.blub"]); |
| 65 expectAsset("app|foo.done", "foo.blub.done"); |
| 66 buildShouldSucceed(); |
| 67 }); |
| 68 |
| 69 test("applies multiple transformations to an asset", () { |
| 70 initGraph(["app|foo.a"], {"app": [ |
| 71 [new RewriteTransformer("a", "b")], |
| 72 [new RewriteTransformer("b", "c")], |
| 73 [new RewriteTransformer("c", "d")], |
| 74 [new RewriteTransformer("d", "e")], |
| 75 [new RewriteTransformer("e", "f")], |
| 76 [new RewriteTransformer("f", "g")], |
| 77 [new RewriteTransformer("g", "h")], |
| 78 [new RewriteTransformer("h", "i")], |
| 79 [new RewriteTransformer("i", "j")], |
| 80 [new RewriteTransformer("j", "k")], |
| 81 ]}); |
| 82 updateSources(["app|foo.a"]); |
| 83 expectAsset("app|foo.k", "foo.b.c.d.e.f.g.h.i.j.k"); |
| 84 buildShouldSucceed(); |
| 85 }); |
| 86 |
| 87 test("only runs a transform once for all of its outputs", () { |
| 88 var transformer = new RewriteTransformer("blub", "a b c"); |
| 89 initGraph(["app|foo.blub"], {"app": [[transformer]]}); |
| 90 updateSources(["app|foo.blub"]); |
| 91 expectAsset("app|foo.a", "foo.a"); |
| 92 expectAsset("app|foo.b", "foo.b"); |
| 93 expectAsset("app|foo.c", "foo.c"); |
| 94 buildShouldSucceed(); |
| 95 expect(transformer.numRuns, completion(equals(1))); |
| 96 }); |
| 97 |
| 98 test("runs transforms in the same phase in parallel", () { |
| 99 var transformerA = new RewriteTransformer("txt", "a"); |
| 100 var transformerB = new RewriteTransformer("txt", "b"); |
| 101 initGraph(["app|foo.txt"], {"app": [[transformerA, transformerB]]}); |
| 102 |
| 103 transformerA.pauseApply(); |
| 104 transformerB.pauseApply(); |
| 105 |
| 106 updateSources(["app|foo.txt"]); |
| 107 |
| 108 transformerA.waitUntilStarted(); |
| 109 transformerB.waitUntilStarted(); |
| 110 |
| 111 // They should both still be running. |
| 112 expect(transformerA.isRunning, completion(isTrue)); |
| 113 expect(transformerB.isRunning, completion(isTrue)); |
| 114 |
| 115 transformerA.resumeApply(); |
| 116 transformerB.resumeApply(); |
| 117 |
| 118 expectAsset("app|foo.a", "foo.a"); |
| 119 expectAsset("app|foo.b", "foo.b"); |
| 120 buildShouldSucceed(); |
| 121 }); |
| 122 |
| 123 test("outputs are inaccessible once used", () { |
| 124 initGraph(["app|foo.a"], {"app": [ |
| 125 [new RewriteTransformer("a", "b")], |
| 126 [new RewriteTransformer("a", "c")] |
| 127 ]}); |
| 128 updateSources(["app|foo.a"]); |
| 129 expectAsset("app|foo.b", "foo.b"); |
| 130 expectNoAsset("app|foo.a"); |
| 131 expectNoAsset("app|foo.c"); |
| 132 buildShouldSucceed(); |
| 133 }); |
| 134 |
| 135 test("does not reapply transform when inputs are not modified", () { |
| 136 var transformer = new RewriteTransformer("blub", "blab"); |
| 137 initGraph(["app|foo.blub"], {"app": [[transformer]]}); |
| 138 updateSources(["app|foo.blub"]); |
| 139 expectAsset("app|foo.blab", "foo.blab"); |
| 140 expectAsset("app|foo.blab", "foo.blab"); |
| 141 expectAsset("app|foo.blab", "foo.blab"); |
| 142 buildShouldSucceed(); |
| 143 |
| 144 expect(transformer.numRuns, completion(equals(1))); |
| 145 }); |
| 146 |
| 147 test("reapplies a transform when its input is modified", () { |
| 148 var transformer = new RewriteTransformer("blub", "blab"); |
| 149 initGraph(["app|foo.blub"], {"app": [[transformer]]}); |
| 150 |
| 151 updateSources(["app|foo.blub"]); |
| 152 expectAsset("app|foo.blab", "foo.blab"); |
| 153 buildShouldSucceed(); |
| 154 |
| 155 updateSources(["app|foo.blub"]); |
| 156 expectAsset("app|foo.blab", "foo.blab"); |
| 157 buildShouldSucceed(); |
| 158 |
| 159 updateSources(["app|foo.blub"]); |
| 160 expectAsset("app|foo.blab", "foo.blab"); |
| 161 buildShouldSucceed(); |
| 162 |
| 163 expect(transformer.numRuns, completion(equals(3))); |
| 164 }); |
| 165 |
| 166 test("does not reapply transform when a removed input is modified", () { |
| 167 var transformer = new ManyToOneTransformer("txt"); |
| 168 initGraph({ |
| 169 "app|a.txt": "a.inc,b.inc", |
| 170 "app|a.inc": "a", |
| 171 "app|b.inc": "b" |
| 172 }, {"app": [[transformer]]}); |
| 173 |
| 174 updateSources(["app|a.txt", "app|a.inc", "app|b.inc"]); |
| 175 |
| 176 expectAsset("app|a.out", "ab"); |
| 177 buildShouldSucceed(); |
| 178 |
| 179 // Remove the dependency on the non-primary input. |
| 180 modifyAsset("app|a.txt", "a.inc"); |
| 181 updateSources(["app|a.txt"]); |
| 182 |
| 183 // Process it again. |
| 184 expectAsset("app|a.out", "a"); |
| 185 buildShouldSucceed(); |
| 186 |
| 187 // Now touch the removed input. It should not trigger another build. |
| 188 updateSources(["app|b.inc"]); |
| 189 expectAsset("app|a.out", "a"); |
| 190 buildShouldSucceed(); |
| 191 |
| 192 expect(transformer.numRuns, completion(equals(2))); |
| 193 }); |
| 194 |
| 195 test("allows a transform to generate multiple outputs", () { |
| 196 initGraph({"app|foo.txt": "a.out,b.out"}, {"app": [ |
| 197 [new OneToManyTransformer("txt")] |
| 198 ]}); |
| 199 |
| 200 updateSources(["app|foo.txt"]); |
| 201 |
| 202 expectAsset("app|a.out", "spread txt"); |
| 203 expectAsset("app|b.out", "spread txt"); |
| 204 buildShouldSucceed(); |
| 205 }); |
| 206 |
| 207 test("does not rebuild transforms that don't use modified source", () { |
| 208 var a = new RewriteTransformer("a", "aa"); |
| 209 var aa = new RewriteTransformer("aa", "aaa"); |
| 210 var b = new RewriteTransformer("b", "bb"); |
| 211 var bb = new RewriteTransformer("bb", "bbb"); |
| 212 initGraph(["app|foo.a", "app|foo.b"], {"app": [ |
| 213 [a, b], |
| 214 [aa, bb], |
| 215 ]}); |
| 216 |
| 217 updateSources(["app|foo.a"]); |
| 218 updateSources(["app|foo.b"]); |
| 219 |
| 220 expectAsset("app|foo.aaa", "foo.aa.aaa"); |
| 221 expectAsset("app|foo.bbb", "foo.bb.bbb"); |
| 222 buildShouldSucceed(); |
| 223 |
| 224 updateSources(["app|foo.a"]); |
| 225 expectAsset("app|foo.aaa", "foo.aa.aaa"); |
| 226 expectAsset("app|foo.bbb", "foo.bb.bbb"); |
| 227 buildShouldSucceed(); |
| 228 |
| 229 expect(aa.numRuns, completion(equals(2))); |
| 230 expect(bb.numRuns, completion(equals(1))); |
| 231 }); |
| 232 |
| 233 test("doesn't get an output from a transform whose primary input is removed", |
| 234 () { |
| 235 initGraph(["app|foo.txt"], {"app": [ |
| 236 [new RewriteTransformer("txt", "out")] |
| 237 ]}); |
| 238 |
| 239 updateSources(["app|foo.txt"]); |
| 240 expectAsset("app|foo.out", "foo.out"); |
| 241 buildShouldSucceed(); |
| 242 |
| 243 removeSources(["app|foo.txt"]); |
| 244 expectNoAsset("app|foo.out"); |
| 245 buildShouldSucceed(); |
| 246 }); |
| 247 |
| 248 test("discards outputs from a transform whose primary input is removed " |
| 249 "during processing", () { |
| 250 var rewrite = new RewriteTransformer("txt", "out"); |
| 251 initGraph(["app|foo.txt"], {"app": [[rewrite]]}); |
| 252 |
| 253 rewrite.pauseApply(); |
| 254 updateSources(["app|foo.txt"]); |
| 255 rewrite.waitUntilStarted(); |
| 256 |
| 257 removeSources(["app|foo.txt"]); |
| 258 rewrite.resumeApply(); |
| 259 expectNoAsset("app|foo.out"); |
| 260 buildShouldSucceed(); |
| 261 }); |
| 262 |
| 263 test("reapplies a transform when a non-primary input changes", () { |
| 264 initGraph({ |
| 265 "app|a.txt": "a.inc", |
| 266 "app|a.inc": "a" |
| 267 }, {"app": [[new ManyToOneTransformer("txt")]]}); |
| 268 |
| 269 updateSources(["app|a.txt", "app|a.inc"]); |
| 270 expectAsset("app|a.out", "a"); |
| 271 buildShouldSucceed(); |
| 272 |
| 273 modifyAsset("app|a.inc", "after"); |
| 274 updateSources(["app|a.inc"]); |
| 275 |
| 276 expectAsset("app|a.out", "after"); |
| 277 buildShouldSucceed(); |
| 278 }); |
| 279 |
| 280 test("applies a transform when it becomes newly primary", () { |
| 281 initGraph({ |
| 282 "app|foo.txt": "this", |
| 283 }, {"app": [[new CheckContentTransformer("that", " and the other")]]}); |
| 284 |
| 285 updateSources(["app|foo.txt"]); |
| 286 expectAsset("app|foo.txt", "this"); |
| 287 buildShouldSucceed(); |
| 288 |
| 289 modifyAsset("app|foo.txt", "that"); |
| 290 updateSources(["app|foo.txt"]); |
| 291 |
| 292 expectAsset("app|foo.txt", "that and the other"); |
| 293 buildShouldSucceed(); |
| 294 }); |
| 295 |
| 296 test("applies the correct transform if an asset is modified during isPrimary", |
| 297 () { |
| 298 var check1 = new CheckContentTransformer("first", "#1"); |
| 299 var check2 = new CheckContentTransformer("second", "#2"); |
| 300 initGraph({ |
| 301 "app|foo.txt": "first", |
| 302 }, {"app": [[check1, check2]]}); |
| 303 |
| 304 check1.pauseIsPrimary("app|foo.txt"); |
| 305 updateSources(["app|foo.txt"]); |
| 306 // Ensure that we're waiting on check1's isPrimary. |
| 307 schedule(pumpEventQueue); |
| 308 |
| 309 modifyAsset("app|foo.txt", "second"); |
| 310 updateSources(["app|foo.txt"]); |
| 311 check1.resumeIsPrimary("app|foo.txt"); |
| 312 |
| 313 expectAsset("app|foo.txt", "second#2"); |
| 314 buildShouldSucceed(); |
| 315 }); |
| 316 |
| 317 test("applies the correct transform if an asset is removed and added during " |
| 318 "isPrimary", () { |
| 319 var check1 = new CheckContentTransformer("first", "#1"); |
| 320 var check2 = new CheckContentTransformer("second", "#2"); |
| 321 initGraph({ |
| 322 "app|foo.txt": "first", |
| 323 }, {"app": [[check1, check2]]}); |
| 324 |
| 325 check1.pauseIsPrimary("app|foo.txt"); |
| 326 updateSources(["app|foo.txt"]); |
| 327 // Ensure that we're waiting on check1's isPrimary. |
| 328 schedule(pumpEventQueue); |
| 329 |
| 330 removeSources(["app|foo.txt"]); |
| 331 modifyAsset("app|foo.txt", "second"); |
| 332 updateSources(["app|foo.txt"]); |
| 333 check1.resumeIsPrimary("app|foo.txt"); |
| 334 |
| 335 expectAsset("app|foo.txt", "second#2"); |
| 336 buildShouldSucceed(); |
| 337 }); |
| 338 |
| 339 test("restarts processing if a change occurs during processing", () { |
| 340 var transformer = new RewriteTransformer("txt", "out"); |
| 341 initGraph(["app|foo.txt"], {"app": [[transformer]]}); |
| 342 |
| 343 transformer.pauseApply(); |
| 344 |
| 345 updateSources(["app|foo.txt"]); |
| 346 transformer.waitUntilStarted(); |
| 347 |
| 348 // Now update the graph during it. |
| 349 updateSources(["app|foo.txt"]); |
| 350 transformer.resumeApply(); |
| 351 |
| 352 expectAsset("app|foo.out", "foo.out"); |
| 353 buildShouldSucceed(); |
| 354 |
| 355 expect(transformer.numRuns, completion(equals(2))); |
| 356 }); |
| 357 |
| 358 test("aborts processing if the primary input is removed during processing", |
| 359 () { |
| 360 var transformer = new RewriteTransformer("txt", "out"); |
| 361 initGraph(["app|foo.txt"], {"app": [[transformer]]}); |
| 362 |
| 363 transformer.pauseApply(); |
| 364 |
| 365 updateSources(["app|foo.txt"]); |
| 366 transformer.waitUntilStarted(); |
| 367 |
| 368 // Now remove its primary input while it's running. |
| 369 removeSources(["app|foo.txt"]); |
| 370 transformer.resumeApply(); |
| 371 |
| 372 expectNoAsset("app|foo.out"); |
| 373 buildShouldSucceed(); |
| 374 |
| 375 expect(transformer.numRuns, completion(equals(1))); |
| 376 }); |
| 377 |
| 378 test("restarts processing if a change to a new secondary input occurs during " |
| 379 "processing", () { |
| 380 var transformer = new ManyToOneTransformer("txt"); |
| 381 initGraph({ |
| 382 "app|foo.txt": "bar.inc", |
| 383 "app|bar.inc": "bar" |
| 384 }, {"app": [[transformer]]}); |
| 385 |
| 386 transformer.pauseApply(); |
| 387 |
| 388 updateSources(["app|foo.txt", "app|bar.inc"]); |
| 389 transformer.waitUntilStarted(); |
| 390 |
| 391 // Give the transform time to load bar.inc the first time. |
| 392 schedule(pumpEventQueue); |
| 393 |
| 394 // Now update the secondary input before the transform finishes. |
| 395 modifyAsset("app|bar.inc", "baz"); |
| 396 updateSources(["app|bar.inc"]); |
| 397 // Give bar.inc enough time to be loaded and marked available before the |
| 398 // transformer completes. |
| 399 schedule(pumpEventQueue); |
| 400 |
| 401 transformer.resumeApply(); |
| 402 |
| 403 expectAsset("app|foo.out", "baz"); |
| 404 buildShouldSucceed(); |
| 405 |
| 406 expect(transformer.numRuns, completion(equals(2))); |
| 407 }); |
| 408 |
| 409 test("doesn't restart processing if a change to an old secondary input " |
| 410 "occurs during processing", () { |
| 411 var transformer = new ManyToOneTransformer("txt"); |
| 412 initGraph({ |
| 413 "app|foo.txt": "bar.inc", |
| 414 "app|bar.inc": "bar", |
| 415 "app|baz.inc": "baz" |
| 416 }, {"app": [[transformer]]}); |
| 417 |
| 418 updateSources(["app|foo.txt", "app|bar.inc", "app|baz.inc"]); |
| 419 expectAsset("app|foo.out", "bar"); |
| 420 buildShouldSucceed(); |
| 421 |
| 422 transformer.pauseApply(); |
| 423 modifyAsset("app|foo.txt", "baz.inc"); |
| 424 updateSources(["app|foo.txt"]); |
| 425 transformer.waitUntilStarted(); |
| 426 |
| 427 // Now update the old secondary input before the transform finishes. |
| 428 modifyAsset("app|bar.inc", "new bar"); |
| 429 updateSources(["app|bar.inc"]); |
| 430 // Give bar.inc enough time to be loaded and marked available before the |
| 431 // transformer completes. |
| 432 schedule(pumpEventQueue); |
| 433 |
| 434 transformer.resumeApply(); |
| 435 expectAsset("app|foo.out", "baz"); |
| 436 buildShouldSucceed(); |
| 437 |
| 438 // Should have run once the first time, then again when switching to |
| 439 // baz.inc. Should not run a third time because of bar.inc being modified. |
| 440 expect(transformer.numRuns, completion(equals(2))); |
| 441 }); |
| 442 |
| 443 test("handles an output moving from one transformer to another", () { |
| 444 // In the first run, "shared.out" is created by the "a.a" transformer. |
| 445 initGraph({ |
| 446 "app|a.a": "a.out,shared.out", |
| 447 "app|b.b": "b.out" |
| 448 }, {"app": [ |
| 449 [new OneToManyTransformer("a"), new OneToManyTransformer("b")] |
| 450 ]}); |
| 451 |
| 452 updateSources(["app|a.a", "app|b.b"]); |
| 453 |
| 454 expectAsset("app|a.out", "spread a"); |
| 455 expectAsset("app|b.out", "spread b"); |
| 456 expectAsset("app|shared.out", "spread a"); |
| 457 buildShouldSucceed(); |
| 458 |
| 459 // Now switch their contents so that "shared.out" will be output by "b.b"'s |
| 460 // transformer. |
| 461 modifyAsset("app|a.a", "a.out"); |
| 462 modifyAsset("app|b.b", "b.out,shared.out"); |
| 463 updateSources(["app|a.a", "app|b.b"]); |
| 464 |
| 465 expectAsset("app|a.out", "spread a"); |
| 466 expectAsset("app|b.out", "spread b"); |
| 467 expectAsset("app|shared.out", "spread b"); |
| 468 buildShouldSucceed(); |
| 469 }); |
| 470 |
| 471 test("restarts before finishing later phases when a change occurs", () { |
| 472 var txtToInt = new RewriteTransformer("txt", "int"); |
| 473 var intToOut = new RewriteTransformer("int", "out"); |
| 474 initGraph(["app|foo.txt", "app|bar.txt"], |
| 475 {"app": [[txtToInt], [intToOut]]}); |
| 476 |
| 477 txtToInt.pauseApply(); |
| 478 |
| 479 updateSources(["app|foo.txt"]); |
| 480 txtToInt.waitUntilStarted(); |
| 481 |
| 482 // Now update the graph during it. |
| 483 updateSources(["app|bar.txt"]); |
| 484 txtToInt.resumeApply(); |
| 485 |
| 486 expectAsset("app|foo.out", "foo.int.out"); |
| 487 expectAsset("app|bar.out", "bar.int.out"); |
| 488 buildShouldSucceed(); |
| 489 |
| 490 // Should only have run each transform once for each primary. |
| 491 expect(txtToInt.numRuns, completion(equals(2))); |
| 492 expect(intToOut.numRuns, completion(equals(2))); |
| 493 }); |
| 494 |
| 495 test("applies transforms to the correct packages", () { |
| 496 var rewrite1 = new RewriteTransformer("txt", "out1"); |
| 497 var rewrite2 = new RewriteTransformer("txt", "out2"); |
| 498 initGraph([ |
| 499 "pkg1|foo.txt", |
| 500 "pkg2|foo.txt" |
| 501 ], {"pkg1": [[rewrite1]], "pkg2": [[rewrite2]]}); |
| 502 |
| 503 updateSources(["pkg1|foo.txt", "pkg2|foo.txt"]); |
| 504 expectAsset("pkg1|foo.out1", "foo.out1"); |
| 505 expectAsset("pkg2|foo.out2", "foo.out2"); |
| 506 buildShouldSucceed(); |
| 507 }); |
| 508 |
| 509 test("transforms don't see generated assets in other packages", () { |
| 510 var fooToBar = new RewriteTransformer("foo", "bar"); |
| 511 var barToBaz = new RewriteTransformer("bar", "baz"); |
| 512 initGraph(["pkg1|file.foo"], {"pkg1": [[fooToBar]], "pkg2": [[barToBaz]]}); |
| 513 |
| 514 updateSources(["pkg1|file.foo"]); |
| 515 expectAsset("pkg1|file.bar", "file.bar"); |
| 516 expectNoAsset("pkg2|file.baz"); |
| 517 buildShouldSucceed(); |
| 518 }); |
| 519 |
| 520 test("doesn't return an asset until it's finished rebuilding", () { |
| 521 initGraph(["app|foo.in"], {"app": [ |
| 522 [new RewriteTransformer("in", "mid")], |
| 523 [new RewriteTransformer("mid", "out")] |
| 524 ]}); |
| 525 |
| 526 updateSources(["app|foo.in"]); |
| 527 expectAsset("app|foo.out", "foo.mid.out"); |
| 528 buildShouldSucceed(); |
| 529 |
| 530 pauseProvider(); |
| 531 modifyAsset("app|foo.in", "new"); |
| 532 updateSources(["app|foo.in"]); |
| 533 expectAssetDoesNotComplete("app|foo.out"); |
| 534 buildShouldNotBeDone(); |
| 535 |
| 536 resumeProvider(); |
| 537 expectAsset("app|foo.out", "new.mid.out"); |
| 538 buildShouldSucceed(); |
| 539 }); |
| 540 |
| 541 test("doesn't return an asset until its in-place transform is done", () { |
| 542 var rewrite = new RewriteTransformer("txt", "txt"); |
| 543 initGraph(["app|foo.txt"], {"app": [[rewrite]]}); |
| 544 |
| 545 rewrite.pauseApply(); |
| 546 updateSources(["app|foo.txt"]); |
| 547 expectAssetDoesNotComplete("app|foo.txt"); |
| 548 |
| 549 rewrite.resumeApply(); |
| 550 expectAsset("app|foo.txt", "foo.txt"); |
| 551 buildShouldSucceed(); |
| 552 }); |
| 553 |
| 554 test("doesn't return an asset until we know it won't be transformed", |
| 555 () { |
| 556 var rewrite = new RewriteTransformer("txt", "txt"); |
| 557 initGraph(["app|foo.a"], {"app": [[rewrite]]}); |
| 558 |
| 559 rewrite.pauseIsPrimary("app|foo.a"); |
| 560 updateSources(["app|foo.a"]); |
| 561 expectAssetDoesNotComplete("app|foo.a"); |
| 562 |
| 563 rewrite.resumeIsPrimary("app|foo.a"); |
| 564 expectAsset("app|foo.a", "foo"); |
| 565 buildShouldSucceed(); |
| 566 }); |
| 567 |
| 568 test("doesn't return a modified asset until we know it will still be " |
| 569 "transformed", () { |
| 570 var rewrite = new RewriteTransformer("txt", "txt"); |
| 571 initGraph(["app|foo.txt"], {"app": [[rewrite]]}); |
| 572 |
| 573 updateSources(["app|foo.txt"]); |
| 574 expectAsset("app|foo.txt", "foo.txt"); |
| 575 buildShouldSucceed(); |
| 576 |
| 577 rewrite.pauseIsPrimary("app|foo.txt"); |
| 578 updateSources(["app|foo.txt"]); |
| 579 expectAssetDoesNotComplete("app|foo.txt"); |
| 580 |
| 581 rewrite.resumeIsPrimary("app|foo.txt"); |
| 582 expectAsset("app|foo.txt", "foo.txt"); |
| 583 buildShouldSucceed(); |
| 584 }); |
| 585 |
| 586 test("doesn't return an asset that's removed during isPrimary", () { |
| 587 var rewrite = new RewriteTransformer("txt", "txt"); |
| 588 initGraph(["app|foo.txt"], {"app": [[rewrite]]}); |
| 589 |
| 590 rewrite.pauseIsPrimary("app|foo.txt"); |
| 591 updateSources(["app|foo.txt"]); |
| 592 // Make sure we're waiting on isPrimary. |
| 593 schedule(pumpEventQueue); |
| 594 |
| 595 removeSources(["app|foo.txt"]); |
| 596 rewrite.resumeIsPrimary("app|foo.txt"); |
| 597 expectNoAsset("app|foo.txt"); |
| 598 buildShouldSucceed(); |
| 599 }); |
| 600 |
| 601 test("doesn't transform an asset that goes from primary to non-primary " |
| 602 "during isPrimary", () { |
| 603 var check = new CheckContentTransformer(new RegExp(r"^do$"), "ne"); |
| 604 initGraph({ |
| 605 "app|foo.txt": "do" |
| 606 }, {"app": [[check]]}); |
| 607 |
| 608 check.pauseIsPrimary("app|foo.txt"); |
| 609 updateSources(["app|foo.txt"]); |
| 610 // Make sure we're waiting on isPrimary. |
| 611 schedule(pumpEventQueue); |
| 612 |
| 613 modifyAsset("app|foo.txt", "don't"); |
| 614 updateSources(["app|foo.txt"]); |
| 615 check.resumeIsPrimary("app|foo.txt"); |
| 616 |
| 617 expectAsset("app|foo.txt", "don't"); |
| 618 buildShouldSucceed(); |
| 619 }); |
| 620 |
| 621 test("transforms an asset that goes from non-primary to primary " |
| 622 "during isPrimary", () { |
| 623 var check = new CheckContentTransformer("do", "ne"); |
| 624 initGraph({ |
| 625 "app|foo.txt": "don't" |
| 626 }, {"app": [[check]]}); |
| 627 |
| 628 check.pauseIsPrimary("app|foo.txt"); |
| 629 updateSources(["app|foo.txt"]); |
| 630 // Make sure we're waiting on isPrimary. |
| 631 schedule(pumpEventQueue); |
| 632 |
| 633 modifyAsset("app|foo.txt", "do"); |
| 634 updateSources(["app|foo.txt"]); |
| 635 check.resumeIsPrimary("app|foo.txt"); |
| 636 |
| 637 expectAsset("app|foo.txt", "done"); |
| 638 buildShouldSucceed(); |
| 639 }); |
| 640 |
| 641 test("doesn't return an asset that's removed during another transformer's " |
| 642 "isPrimary", () { |
| 643 var rewrite1 = new RewriteTransformer("txt", "txt"); |
| 644 var rewrite2 = new RewriteTransformer("md", "md"); |
| 645 initGraph(["app|foo.txt", "app|foo.md"], {"app": [[rewrite1, rewrite2]]}); |
| 646 |
| 647 rewrite2.pauseIsPrimary("app|foo.md"); |
| 648 updateSources(["app|foo.txt", "app|foo.md"]); |
| 649 // Make sure we're waiting on the correct isPrimary. |
| 650 schedule(pumpEventQueue); |
| 651 |
| 652 removeSources(["app|foo.txt"]); |
| 653 rewrite2.resumeIsPrimary("app|foo.md"); |
| 654 expectNoAsset("app|foo.txt"); |
| 655 expectAsset("app|foo.md", "foo.md"); |
| 656 buildShouldSucceed(); |
| 657 }); |
| 658 |
| 659 test("doesn't transform an asset that goes from primary to non-primary " |
| 660 "during another transformer's isPrimary", () { |
| 661 var rewrite = new RewriteTransformer("md", "md"); |
| 662 var check = new CheckContentTransformer(new RegExp(r"^do$"), "ne"); |
| 663 initGraph({ |
| 664 "app|foo.txt": "do", |
| 665 "app|foo.md": "foo" |
| 666 }, {"app": [[rewrite, check]]}); |
| 667 |
| 668 rewrite.pauseIsPrimary("app|foo.md"); |
| 669 updateSources(["app|foo.txt", "app|foo.md"]); |
| 670 // Make sure we're waiting on the correct isPrimary. |
| 671 schedule(pumpEventQueue); |
| 672 |
| 673 modifyAsset("app|foo.txt", "don't"); |
| 674 updateSources(["app|foo.txt"]); |
| 675 rewrite.resumeIsPrimary("app|foo.md"); |
| 676 |
| 677 expectAsset("app|foo.txt", "don't"); |
| 678 expectAsset("app|foo.md", "foo.md"); |
| 679 buildShouldSucceed(); |
| 680 }); |
| 681 |
| 682 test("transforms an asset that goes from non-primary to primary " |
| 683 "during another transformer's isPrimary", () { |
| 684 var rewrite = new RewriteTransformer("md", "md"); |
| 685 var check = new CheckContentTransformer("do", "ne"); |
| 686 initGraph({ |
| 687 "app|foo.txt": "don't", |
| 688 "app|foo.md": "foo" |
| 689 }, {"app": [[rewrite, check]]}); |
| 690 |
| 691 rewrite.pauseIsPrimary("app|foo.md"); |
| 692 updateSources(["app|foo.txt", "app|foo.md"]); |
| 693 // Make sure we're waiting on the correct isPrimary. |
| 694 schedule(pumpEventQueue); |
| 695 |
| 696 modifyAsset("app|foo.txt", "do"); |
| 697 updateSources(["app|foo.txt"]); |
| 698 rewrite.resumeIsPrimary("app|foo.md"); |
| 699 |
| 700 expectAsset("app|foo.txt", "done"); |
| 701 expectAsset("app|foo.md", "foo.md"); |
| 702 buildShouldSucceed(); |
| 703 }); |
| 704 |
| 705 test("removes pipelined transforms when the root primary input is removed", |
| 706 () { |
| 707 initGraph(["app|foo.txt"], {"app": [ |
| 708 [new RewriteTransformer("txt", "mid")], |
| 709 [new RewriteTransformer("mid", "out")] |
| 710 ]}); |
| 711 |
| 712 updateSources(["app|foo.txt"]); |
| 713 expectAsset("app|foo.out", "foo.mid.out"); |
| 714 buildShouldSucceed(); |
| 715 |
| 716 removeSources(["app|foo.txt"]); |
| 717 expectNoAsset("app|foo.out"); |
| 718 buildShouldSucceed(); |
| 719 }); |
| 720 |
| 721 test("removes pipelined transforms when the parent ceases to generate the " |
| 722 "primary input", () { |
| 723 initGraph({"app|foo.txt": "foo.mid"}, {'app': [ |
| 724 [new OneToManyTransformer('txt')], |
| 725 [new RewriteTransformer('mid', 'out')] |
| 726 ]}); |
| 727 |
| 728 updateSources(['app|foo.txt']); |
| 729 expectAsset('app|foo.out', 'spread txt.out'); |
| 730 buildShouldSucceed(); |
| 731 |
| 732 modifyAsset("app|foo.txt", "bar.mid"); |
| 733 updateSources(["app|foo.txt"]); |
| 734 expectNoAsset('app|foo.out'); |
| 735 expectAsset('app|bar.out', 'spread txt.out'); |
| 736 buildShouldSucceed(); |
| 737 }); |
| 738 |
| 739 test("returns an asset even if an unrelated build is running", () { |
| 740 initGraph([ |
| 741 "app|foo.in", |
| 742 "app|bar.in", |
| 743 ], {"app": [[new RewriteTransformer("in", "out")]]}); |
| 744 |
| 745 updateSources(["app|foo.in", "app|bar.in"]); |
| 746 expectAsset("app|foo.out", "foo.out"); |
| 747 expectAsset("app|bar.out", "bar.out"); |
| 748 buildShouldSucceed(); |
| 749 |
| 750 pauseProvider(); |
| 751 modifyAsset("app|foo.in", "new"); |
| 752 updateSources(["app|foo.in"]); |
| 753 expectAssetDoesNotComplete("app|foo.out"); |
| 754 expectAsset("app|bar.out", "bar.out"); |
| 755 buildShouldNotBeDone(); |
| 756 |
| 757 resumeProvider(); |
| 758 expectAsset("app|foo.out", "new.out"); |
| 759 buildShouldSucceed(); |
| 760 }); |
| 761 |
| 762 test("doesn't report AssetNotFound until all builds are finished", () { |
| 763 initGraph([ |
| 764 "app|foo.in", |
| 765 ], {"app": [[new RewriteTransformer("in", "out")]]}); |
| 766 |
| 767 updateSources(["app|foo.in"]); |
| 768 expectAsset("app|foo.out", "foo.out"); |
| 769 buildShouldSucceed(); |
| 770 |
| 771 pauseProvider(); |
| 772 updateSources(["app|foo.in"]); |
| 773 expectAssetDoesNotComplete("app|foo.out"); |
| 774 expectAssetDoesNotComplete("app|non-existent.out"); |
| 775 buildShouldNotBeDone(); |
| 776 |
| 777 resumeProvider(); |
| 778 expectAsset("app|foo.out", "foo.out"); |
| 779 expectNoAsset("app|non-existent.out"); |
| 780 buildShouldSucceed(); |
| 781 }); |
| 782 |
| 783 test("doesn't emit a result until all builds are finished", () { |
| 784 var rewrite = new RewriteTransformer("txt", "out"); |
| 785 initGraph([ |
| 786 "pkg1|foo.txt", |
| 787 "pkg2|foo.txt" |
| 788 ], {"pkg1": [[rewrite]], "pkg2": [[rewrite]]}); |
| 789 |
| 790 // First, run both packages' transformers so both packages are successful. |
| 791 updateSources(["pkg1|foo.txt", "pkg2|foo.txt"]); |
| 792 expectAsset("pkg1|foo.out", "foo.out"); |
| 793 expectAsset("pkg2|foo.out", "foo.out"); |
| 794 buildShouldSucceed(); |
| 795 |
| 796 // pkg1 is still successful, but pkg2 is waiting on the provider, so the |
| 797 // overall build shouldn't finish. |
| 798 pauseProvider(); |
| 799 updateSources(["pkg2|foo.txt"]); |
| 800 expectAsset("pkg1|foo.out", "foo.out"); |
| 801 buildShouldNotBeDone(); |
| 802 |
| 803 // Now that the provider is unpaused, pkg2's transforms finish and the |
| 804 // overall build succeeds. |
| 805 resumeProvider(); |
| 806 buildShouldSucceed(); |
| 807 }); |
| 808 |
| 809 test("one transformer takes a long time while the other finishes, then " |
| 810 "the input is removed", () { |
| 811 var rewrite1 = new RewriteTransformer("txt", "out1"); |
| 812 var rewrite2 = new RewriteTransformer("txt", "out2"); |
| 813 initGraph(["app|foo.txt"], {"app": [[rewrite1, rewrite2]]}); |
| 814 |
| 815 rewrite1.pauseApply(); |
| 816 |
| 817 updateSources(["app|foo.txt"]); |
| 818 |
| 819 // Wait for rewrite1 to pause and rewrite2 to finish. |
| 820 schedule(pumpEventQueue); |
| 821 |
| 822 removeSources(["app|foo.txt"]); |
| 823 |
| 824 // Make sure the removal is processed completely before we restart rewrite2. |
| 825 schedule(pumpEventQueue); |
| 826 rewrite1.resumeApply(); |
| 827 |
| 828 buildShouldSucceed(); |
| 829 expectNoAsset("app|foo.out1"); |
| 830 expectNoAsset("app|foo.out2"); |
| 831 }); |
| 832 |
| 833 group("pass-through", () { |
| 834 test("passes an asset through a phase in which no transforms apply", () { |
| 835 initGraph([ |
| 836 "app|foo.in", |
| 837 "app|bar.zip", |
| 838 ], {"app": [ |
| 839 [new RewriteTransformer("in", "mid")], |
| 840 [new RewriteTransformer("zip", "zap")], |
| 841 [new RewriteTransformer("mid", "out")], |
| 842 ]}); |
| 843 |
| 844 updateSources(["app|foo.in", "app|bar.zip"]); |
| 845 expectAsset("app|foo.out", "foo.mid.out"); |
| 846 expectAsset("app|bar.zap", "bar.zap"); |
| 847 buildShouldSucceed(); |
| 848 }); |
| 849 |
| 850 test("doesn't pass an asset through a phase in which a transform consumes " |
| 851 "it", () { |
| 852 initGraph([ |
| 853 "app|foo.in", |
| 854 ], {"app": [ |
| 855 [new RewriteTransformer("in", "mid")], |
| 856 [new RewriteTransformer("mid", "phase2")], |
| 857 [new RewriteTransformer("mid", "phase3")], |
| 858 ]}); |
| 859 |
| 860 updateSources(["app|foo.in"]); |
| 861 expectAsset("app|foo.phase2", "foo.mid.phase2"); |
| 862 expectNoAsset("app|foo.phase3"); |
| 863 buildShouldSucceed(); |
| 864 }); |
| 865 |
| 866 test("removes a pass-through asset when the source is removed", () { |
| 867 initGraph([ |
| 868 "app|foo.in", |
| 869 "app|bar.zip", |
| 870 ], {"app": [ |
| 871 [new RewriteTransformer("zip", "zap")], |
| 872 [new RewriteTransformer("in", "out")], |
| 873 ]}); |
| 874 |
| 875 updateSources(["app|foo.in", "app|bar.zip"]); |
| 876 expectAsset("app|foo.out", "foo.out"); |
| 877 buildShouldSucceed(); |
| 878 |
| 879 removeSources(["app|foo.in"]); |
| 880 expectNoAsset("app|foo.in"); |
| 881 expectNoAsset("app|foo.out"); |
| 882 buildShouldSucceed(); |
| 883 }); |
| 884 |
| 885 test("updates a pass-through asset when the source is updated", () { |
| 886 initGraph([ |
| 887 "app|foo.in", |
| 888 "app|bar.zip", |
| 889 ], {"app": [ |
| 890 [new RewriteTransformer("zip", "zap")], |
| 891 [new RewriteTransformer("in", "out")], |
| 892 ]}); |
| 893 |
| 894 updateSources(["app|foo.in", "app|bar.zip"]); |
| 895 expectAsset("app|foo.out", "foo.out"); |
| 896 buildShouldSucceed(); |
| 897 |
| 898 modifyAsset("app|foo.in", "boo"); |
| 899 updateSources(["app|foo.in"]); |
| 900 expectAsset("app|foo.out", "boo.out"); |
| 901 buildShouldSucceed(); |
| 902 }); |
| 903 |
| 904 test("passes an asset through a phase in which transforms have ceased to " |
| 905 "apply", () { |
| 906 initGraph([ |
| 907 "app|foo.in", |
| 908 ], {"app": [ |
| 909 [new RewriteTransformer("in", "mid")], |
| 910 [new CheckContentTransformer("foo.mid", ".phase2")], |
| 911 [new CheckContentTransformer(new RegExp(r"\.mid$"), ".phase3")], |
| 912 ]}); |
| 913 |
| 914 updateSources(["app|foo.in"]); |
| 915 expectAsset("app|foo.mid", "foo.mid.phase2"); |
| 916 buildShouldSucceed(); |
| 917 |
| 918 modifyAsset("app|foo.in", "bar"); |
| 919 updateSources(["app|foo.in"]); |
| 920 expectAsset("app|foo.mid", "bar.mid.phase3"); |
| 921 buildShouldSucceed(); |
| 922 }); |
| 923 |
| 924 test("doesn't pass an asset through a phase in which transforms have " |
| 925 "started to apply", () { |
| 926 initGraph([ |
| 927 "app|foo.in", |
| 928 ], {"app": [ |
| 929 [new RewriteTransformer("in", "mid")], |
| 930 [new CheckContentTransformer("bar.mid", ".phase2")], |
| 931 [new CheckContentTransformer(new RegExp(r"\.mid$"), ".phase3")], |
| 932 ]}); |
| 933 |
| 934 updateSources(["app|foo.in"]); |
| 935 expectAsset("app|foo.mid", "foo.mid.phase3"); |
| 936 buildShouldSucceed(); |
| 937 |
| 938 modifyAsset("app|foo.in", "bar"); |
| 939 updateSources(["app|foo.in"]); |
| 940 expectAsset("app|foo.mid", "bar.mid.phase2"); |
| 941 buildShouldSucceed(); |
| 942 }); |
| 943 |
| 944 test("doesn't pass an asset through if it's removed during isPrimary", () { |
| 945 var check = new CheckContentTransformer("bar", " modified"); |
| 946 initGraph(["app|foo.txt"], {"app": [[check]]}); |
| 947 |
| 948 updateSources(["app|foo.txt"]); |
| 949 expectAsset("app|foo.txt", "foo"); |
| 950 buildShouldSucceed(); |
| 951 |
| 952 check.pauseIsPrimary("app|foo.txt"); |
| 953 modifyAsset("app|foo.txt", "bar"); |
| 954 updateSources(["app|foo.txt"]); |
| 955 // Ensure we're waiting on [check.isPrimary] |
| 956 schedule(pumpEventQueue); |
| 957 |
| 958 removeSources(["app|foo.txt"]); |
| 959 check.resumeIsPrimary("app|foo.txt"); |
| 960 expectNoAsset("app|foo.txt"); |
| 961 buildShouldSucceed(); |
| 962 }); |
| 963 }); |
| 964 |
| 965 group('cross-package transforms', () { |
| 966 test("can access other packages' source assets", () { |
| 967 initGraph({ |
| 968 "pkg1|a.txt": "pkg2|a.inc", |
| 969 "pkg2|a.inc": "a" |
| 970 }, {"pkg1": [[new ManyToOneTransformer("txt")]]}); |
| 971 |
| 972 updateSources(["pkg1|a.txt", "pkg2|a.inc"]); |
| 973 expectAsset("pkg1|a.out", "a"); |
| 974 buildShouldSucceed(); |
| 975 }); |
| 976 |
| 977 test("can access other packages' transformed assets", () { |
| 978 initGraph({ |
| 979 "pkg1|a.txt": "pkg2|a.inc", |
| 980 "pkg2|a.txt": "a" |
| 981 }, { |
| 982 "pkg1": [[new ManyToOneTransformer("txt")]], |
| 983 "pkg2": [[new RewriteTransformer("txt", "inc")]] |
| 984 }); |
| 985 |
| 986 updateSources(["pkg1|a.txt", "pkg2|a.txt"]); |
| 987 expectAsset("pkg1|a.out", "a.inc"); |
| 988 buildShouldSucceed(); |
| 989 }); |
| 990 |
| 991 test("re-runs a transform when an input from another package changes", () { |
| 992 initGraph({ |
| 993 "pkg1|a.txt": "pkg2|a.inc", |
| 994 "pkg2|a.inc": "a" |
| 995 }, { |
| 996 "pkg1": [[new ManyToOneTransformer("txt")]] |
| 997 }); |
| 998 |
| 999 updateSources(["pkg1|a.txt", "pkg2|a.inc"]); |
| 1000 expectAsset("pkg1|a.out", "a"); |
| 1001 buildShouldSucceed(); |
| 1002 |
| 1003 modifyAsset("pkg2|a.inc", "new a"); |
| 1004 updateSources(["pkg2|a.inc"]); |
| 1005 expectAsset("pkg1|a.out", "new a"); |
| 1006 buildShouldSucceed(); |
| 1007 }); |
| 1008 |
| 1009 test("re-runs a transform when a transformed input from another package " |
| 1010 "changes", () { |
| 1011 initGraph({ |
| 1012 "pkg1|a.txt": "pkg2|a.inc", |
| 1013 "pkg2|a.txt": "a" |
| 1014 }, { |
| 1015 "pkg1": [[new ManyToOneTransformer("txt")]], |
| 1016 "pkg2": [[new RewriteTransformer("txt", "inc")]] |
| 1017 }); |
| 1018 |
| 1019 updateSources(["pkg1|a.txt", "pkg2|a.txt"]); |
| 1020 expectAsset("pkg1|a.out", "a.inc"); |
| 1021 buildShouldSucceed(); |
| 1022 |
| 1023 modifyAsset("pkg2|a.txt", "new a"); |
| 1024 updateSources(["pkg2|a.txt"]); |
| 1025 expectAsset("pkg1|a.out", "new a.inc"); |
| 1026 buildShouldSucceed(); |
| 1027 }); |
| 1028 |
| 1029 test("doesn't complete the build until all packages' transforms are " |
| 1030 "finished running", () { |
| 1031 var transformer = new ManyToOneTransformer("txt"); |
| 1032 initGraph({ |
| 1033 "pkg1|a.txt": "pkg2|a.inc", |
| 1034 "pkg2|a.inc": "a" |
| 1035 }, { |
| 1036 "pkg1": [[transformer]] |
| 1037 }); |
| 1038 |
| 1039 updateSources(["pkg1|a.txt", "pkg2|a.inc"]); |
| 1040 expectAsset("pkg1|a.out", "a"); |
| 1041 buildShouldSucceed(); |
| 1042 |
| 1043 transformer.pauseApply(); |
| 1044 modifyAsset("pkg2|a.inc", "new a"); |
| 1045 updateSources(["pkg2|a.inc"]); |
| 1046 buildShouldNotBeDone(); |
| 1047 |
| 1048 transformer.resumeApply(); |
| 1049 buildShouldSucceed(); |
| 1050 }); |
| 1051 |
| 1052 test("runs a transform that's added because of a change in another package", |
| 1053 () { |
| 1054 initGraph({ |
| 1055 "pkg1|a.txt": "pkg2|a.inc", |
| 1056 "pkg2|a.inc": "b" |
| 1057 }, { |
| 1058 "pkg1": [ |
| 1059 [new ManyToOneTransformer("txt")], |
| 1060 [new OneToManyTransformer("out")], |
| 1061 [new RewriteTransformer("md", "done")] |
| 1062 ], |
| 1063 }); |
| 1064 |
| 1065 // pkg1|a.txt generates outputs based on the contents of pkg2|a.inc. At |
| 1066 // first pkg2|a.inc only includes "b", which is not transformed. Then |
| 1067 // pkg2|a.inc is updated to include "b,c.md". pkg1|c.md triggers the |
| 1068 // md->done rewrite transformer, producing pkg1|c.done. |
| 1069 |
| 1070 updateSources(["pkg1|a.txt", "pkg2|a.inc"]); |
| 1071 expectAsset("pkg1|b", "spread out"); |
| 1072 buildShouldSucceed(); |
| 1073 |
| 1074 modifyAsset("pkg2|a.inc", "b,c.md"); |
| 1075 updateSources(["pkg2|a.inc"]); |
| 1076 expectAsset("pkg1|b", "spread out"); |
| 1077 expectAsset("pkg1|c.done", "spread out.done"); |
| 1078 buildShouldSucceed(); |
| 1079 }); |
| 1080 |
| 1081 test("doesn't run a transform that's removed because of a change in " |
| 1082 "another package", () { |
| 1083 initGraph({ |
| 1084 "pkg1|a.txt": "pkg2|a.inc", |
| 1085 "pkg2|a.inc": "b,c.md" |
| 1086 }, { |
| 1087 "pkg1": [ |
| 1088 [new ManyToOneTransformer("txt")], |
| 1089 [new OneToManyTransformer("out")], |
| 1090 [new RewriteTransformer("md", "done")] |
| 1091 ], |
| 1092 }); |
| 1093 |
| 1094 updateSources(["pkg1|a.txt", "pkg2|a.inc"]); |
| 1095 expectAsset("pkg1|b", "spread out"); |
| 1096 expectAsset("pkg1|c.done", "spread out.done"); |
| 1097 buildShouldSucceed(); |
| 1098 |
| 1099 modifyAsset("pkg2|a.inc", "b"); |
| 1100 updateSources(["pkg2|a.inc"]); |
| 1101 expectAsset("pkg1|b", "spread out"); |
| 1102 expectNoAsset("pkg1|c.done"); |
| 1103 buildShouldSucceed(); |
| 1104 }); |
| 1105 |
| 1106 test("sees a transformer that's newly applied to a cross-package " |
| 1107 "dependency", () { |
| 1108 initGraph({ |
| 1109 "pkg1|a.txt": "pkg2|a.inc", |
| 1110 "pkg2|a.inc": "a" |
| 1111 }, { |
| 1112 "pkg1": [[new ManyToOneTransformer("txt")]], |
| 1113 "pkg2": [[new CheckContentTransformer("b", " transformed")]] |
| 1114 }); |
| 1115 |
| 1116 updateSources(["pkg1|a.txt", "pkg2|a.inc"]); |
| 1117 expectAsset("pkg1|a.out", "a"); |
| 1118 buildShouldSucceed(); |
| 1119 |
| 1120 modifyAsset("pkg2|a.inc", "b"); |
| 1121 updateSources(["pkg2|a.inc"]); |
| 1122 expectAsset("pkg1|a.out", "b transformed"); |
| 1123 buildShouldSucceed(); |
| 1124 }); |
| 1125 |
| 1126 test("doesn't see a transformer that's newly not applied to a " |
| 1127 "cross-package dependency", () { |
| 1128 initGraph({ |
| 1129 "pkg1|a.txt": "pkg2|a.inc", |
| 1130 "pkg2|a.inc": "a" |
| 1131 }, { |
| 1132 "pkg1": [[new ManyToOneTransformer("txt")]], |
| 1133 "pkg2": [[new CheckContentTransformer("a", " transformed")]] |
| 1134 }); |
| 1135 |
| 1136 updateSources(["pkg1|a.txt", "pkg2|a.inc"]); |
| 1137 expectAsset("pkg1|a.out", "a transformed"); |
| 1138 buildShouldSucceed(); |
| 1139 |
| 1140 modifyAsset("pkg2|a.inc", "b"); |
| 1141 updateSources(["pkg2|a.inc"]); |
| 1142 expectAsset("pkg1|a.out", "b"); |
| 1143 buildShouldSucceed(); |
| 1144 }); |
| 1145 |
| 1146 test("re-runs if the primary input is invalidated before accessing", () { |
| 1147 var transformer1 = new RewriteTransformer("txt", "mid"); |
| 1148 var transformer2 = new RewriteTransformer("mid", "out"); |
| 1149 |
| 1150 initGraph([ |
| 1151 "app|foo.txt" |
| 1152 ], {"app": [ |
| 1153 [transformer1], |
| 1154 [transformer2] |
| 1155 ]}); |
| 1156 |
| 1157 transformer2.pausePrimaryInput(); |
| 1158 updateSources(["app|foo.txt"]); |
| 1159 |
| 1160 // Wait long enough to ensure that transformer1 has completed and |
| 1161 // transformer2 has started. |
| 1162 schedule(pumpEventQueue); |
| 1163 |
| 1164 // Update the source again so that transformer1 invalidates the primary |
| 1165 // input of transformer2. |
| 1166 transformer1.pauseApply(); |
| 1167 updateSources(["app|foo.txt"]); |
| 1168 |
| 1169 transformer2.resumePrimaryInput(); |
| 1170 transformer1.resumeApply(); |
| 1171 |
| 1172 expectAsset("app|foo.out", "foo.mid.out"); |
| 1173 buildShouldSucceed(); |
| 1174 |
| 1175 expect(transformer1.numRuns, completion(equals(2))); |
| 1176 expect(transformer2.numRuns, completion(equals(2))); |
| 1177 }); |
| 1178 }); |
| 1179 } |
OLD | NEW |