| 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.lazy_asset_test; | |
| 6 | |
| 7 import 'package:barback/barback.dart'; | |
| 8 import 'package:barback/src/utils.dart'; | |
| 9 import 'package:scheduled_test/scheduled_test.dart'; | |
| 10 | |
| 11 import '../utils.dart'; | |
| 12 | |
| 13 main() { | |
| 14 initConfig(); | |
| 15 test("requesting a lazy asset should cause it to be generated", () { | |
| 16 initGraph(["app|foo.blub"], {"app": [ | |
| 17 [new LazyRewriteTransformer("blub", "blab")] | |
| 18 ]}); | |
| 19 updateSources(["app|foo.blub"]); | |
| 20 expectAsset("app|foo.blab", "foo.blab"); | |
| 21 buildShouldSucceed(); | |
| 22 }); | |
| 23 | |
| 24 test("calling getAllAssets should cause a lazy asset to be generated", () { | |
| 25 var transformer = new LazyRewriteTransformer("blub", "blab"); | |
| 26 initGraph(["app|foo.blub"], {"app": [[transformer]]}); | |
| 27 updateSources(["app|foo.blub"]); | |
| 28 expectAllAssets(["app|foo.blub", "app|foo.blab"]); | |
| 29 buildShouldSucceed(); | |
| 30 expect(transformer.numRuns, completion(equals(1))); | |
| 31 }); | |
| 32 | |
| 33 test("requesting a lazy asset multiple times should only cause it to be " | |
| 34 "generated once", () { | |
| 35 var transformer = new LazyRewriteTransformer("blub", "blab"); | |
| 36 initGraph(["app|foo.blub"], {"app": [[transformer]]}); | |
| 37 updateSources(["app|foo.blub"]); | |
| 38 expectAsset("app|foo.blab", "foo.blab"); | |
| 39 expectAsset("app|foo.blab", "foo.blab"); | |
| 40 expectAsset("app|foo.blab", "foo.blab"); | |
| 41 buildShouldSucceed(); | |
| 42 expect(transformer.numRuns, completion(equals(1))); | |
| 43 }); | |
| 44 | |
| 45 test("a lazy asset can be consumed by a non-lazy transformer", () { | |
| 46 initGraph(["app|foo.blub"], {"app": [ | |
| 47 [new LazyRewriteTransformer("blub", "blab")], | |
| 48 [new RewriteTransformer("blab", "blib")] | |
| 49 ]}); | |
| 50 updateSources(["app|foo.blub"]); | |
| 51 expectAsset("app|foo.blib", "foo.blab.blib"); | |
| 52 buildShouldSucceed(); | |
| 53 }); | |
| 54 | |
| 55 test("a lazy asset isn't eagerly compiled", () { | |
| 56 var transformer = new LazyRewriteTransformer("blub", "blab"); | |
| 57 initGraph(["app|foo.blub"], {"app": [[transformer]]}); | |
| 58 updateSources(["app|foo.blub"]); | |
| 59 buildShouldSucceed(); | |
| 60 expect(transformer.numRuns, completion(equals(0))); | |
| 61 }); | |
| 62 | |
| 63 test("a lazy asset emitted by a group isn't eagerly compiled", () { | |
| 64 var transformer = new LazyRewriteTransformer("blub", "blab"); | |
| 65 initGraph(["app|foo.blub"], {"app": [ | |
| 66 [new TransformerGroup([[transformer]])] | |
| 67 ]}); | |
| 68 updateSources(["app|foo.blub"]); | |
| 69 buildShouldSucceed(); | |
| 70 expect(transformer.numRuns, completion(equals(0))); | |
| 71 }); | |
| 72 | |
| 73 test("a lazy asset piped into a non-lazy transformer is eagerly compiled", | |
| 74 () { | |
| 75 var transformer = new LazyRewriteTransformer("blub", "blab"); | |
| 76 initGraph(["app|foo.blub"], {"app": [ | |
| 77 [transformer], | |
| 78 [new RewriteTransformer("blab", "blib")] | |
| 79 ]}); | |
| 80 updateSources(["app|foo.blub"]); | |
| 81 buildShouldSucceed(); | |
| 82 expect(transformer.numRuns, completion(equals(1))); | |
| 83 }); | |
| 84 | |
| 85 test("a lazy asset piped into a declaring transformer isn't eagerly " | |
| 86 "compiled", () { | |
| 87 var transformer1 = new LazyRewriteTransformer("blub", "blab"); | |
| 88 var transformer2 = new DeclaringRewriteTransformer("blab", "blib"); | |
| 89 initGraph(["app|foo.blub"], {"app": [ | |
| 90 [transformer1], [transformer2] | |
| 91 ]}); | |
| 92 updateSources(["app|foo.blub"]); | |
| 93 buildShouldSucceed(); | |
| 94 expect(transformer1.numRuns, completion(equals(0))); | |
| 95 expect(transformer2.numRuns, completion(equals(0))); | |
| 96 }); | |
| 97 | |
| 98 test("a lazy asset piped into a declaring transformer is compiled " | |
| 99 "on-demand", () { | |
| 100 initGraph(["app|foo.blub"], {"app": [ | |
| 101 [new LazyRewriteTransformer("blub", "blab")], | |
| 102 [new DeclaringRewriteTransformer("blab", "blib")] | |
| 103 ]}); | |
| 104 updateSources(["app|foo.blub"]); | |
| 105 expectAsset("app|foo.blib", "foo.blab.blib"); | |
| 106 buildShouldSucceed(); | |
| 107 }); | |
| 108 | |
| 109 test("a lazy asset piped through many declaring transformers isn't eagerly " | |
| 110 "compiled", () { | |
| 111 var transformer1 = new LazyRewriteTransformer("one", "two"); | |
| 112 var transformer2 = new DeclaringRewriteTransformer("two", "three"); | |
| 113 var transformer3 = new DeclaringRewriteTransformer("three", "four"); | |
| 114 var transformer4 = new DeclaringRewriteTransformer("four", "five"); | |
| 115 initGraph(["app|foo.one"], {"app": [ | |
| 116 [transformer1], [transformer2], [transformer3], [transformer4] | |
| 117 ]}); | |
| 118 updateSources(["app|foo.one"]); | |
| 119 buildShouldSucceed(); | |
| 120 expect(transformer1.numRuns, completion(equals(0))); | |
| 121 expect(transformer2.numRuns, completion(equals(0))); | |
| 122 expect(transformer3.numRuns, completion(equals(0))); | |
| 123 expect(transformer4.numRuns, completion(equals(0))); | |
| 124 }); | |
| 125 | |
| 126 test("a lazy asset piped through many declaring transformers is compiled " | |
| 127 "on-demand", () { | |
| 128 initGraph(["app|foo.one"], {"app": [ | |
| 129 [new LazyRewriteTransformer("one", "two")], | |
| 130 [new DeclaringRewriteTransformer("two", "three")], | |
| 131 [new DeclaringRewriteTransformer("three", "four")], | |
| 132 [new DeclaringRewriteTransformer("four", "five")] | |
| 133 ]}); | |
| 134 updateSources(["app|foo.one"]); | |
| 135 expectAsset("app|foo.five", "foo.two.three.four.five"); | |
| 136 buildShouldSucceed(); | |
| 137 }); | |
| 138 | |
| 139 test("a lazy asset piped into a non-lazy transformer that doesn't use its " | |
| 140 "outputs isn't eagerly compiled", () { | |
| 141 var transformer = new LazyRewriteTransformer("blub", "blab"); | |
| 142 initGraph(["app|foo.blub"], {"app": [ | |
| 143 [transformer], | |
| 144 [new RewriteTransformer("txt", "out")] | |
| 145 ]}); | |
| 146 updateSources(["app|foo.blub"]); | |
| 147 buildShouldSucceed(); | |
| 148 expect(transformer.numRuns, completion(equals(0))); | |
| 149 }); | |
| 150 | |
| 151 test("a lazy asset piped into a non-lazy transformer that doesn't use its " | |
| 152 "outputs is compiled on-demand", () { | |
| 153 initGraph(["app|foo.blub"], {"app": [ | |
| 154 [new LazyRewriteTransformer("blub", "blab")], | |
| 155 [new RewriteTransformer("txt", "out")] | |
| 156 ]}); | |
| 157 updateSources(["app|foo.blub"]); | |
| 158 expectAsset("app|foo.blab", "foo.blab"); | |
| 159 buildShouldSucceed(); | |
| 160 }); | |
| 161 | |
| 162 test("a lazy transformer followed by a non-lazy transformer is re-run " | |
| 163 "eagerly", () { | |
| 164 var rewrite = new LazyRewriteTransformer("one", "two"); | |
| 165 initGraph(["app|foo.one"], {"app": [ | |
| 166 [rewrite], | |
| 167 [new RewriteTransformer("two", "three")] | |
| 168 ]}); | |
| 169 | |
| 170 updateSources(["app|foo.one"]); | |
| 171 expectAsset("app|foo.three", "foo.two.three"); | |
| 172 buildShouldSucceed(); | |
| 173 | |
| 174 updateSources(["app|foo.one"]); | |
| 175 buildShouldSucceed(); | |
| 176 | |
| 177 expect(rewrite.numRuns, completion(equals(2))); | |
| 178 }); | |
| 179 | |
| 180 test("a lazy transformer followed by a declaring transformer isn't re-run " | |
| 181 "eagerly", () { | |
| 182 var rewrite = new LazyRewriteTransformer("one", "two"); | |
| 183 initGraph(["app|foo.one"], {"app": [ | |
| 184 [rewrite], | |
| 185 [new DeclaringRewriteTransformer("two", "three")] | |
| 186 ]}); | |
| 187 | |
| 188 updateSources(["app|foo.one"]); | |
| 189 expectAsset("app|foo.three", "foo.two.three"); | |
| 190 buildShouldSucceed(); | |
| 191 | |
| 192 updateSources(["app|foo.one"]); | |
| 193 buildShouldSucceed(); | |
| 194 | |
| 195 expect(rewrite.numRuns, completion(equals(1))); | |
| 196 }); | |
| 197 | |
| 198 test("a declaring transformer added after a materialized lazy transformer " | |
| 199 "is still deferred", () { | |
| 200 var lazy = new LazyRewriteTransformer("one", "two"); | |
| 201 var declaring = new DeclaringRewriteTransformer("two", "three"); | |
| 202 initGraph(["app|foo.one"], {"app": [[lazy]]}); | |
| 203 | |
| 204 updateSources(["app|foo.one"]); | |
| 205 expectAsset("app|foo.two", "foo.two"); | |
| 206 buildShouldSucceed(); | |
| 207 | |
| 208 updateTransformers("app", [[lazy], [declaring]]); | |
| 209 expectAsset("app|foo.three", "foo.two.three"); | |
| 210 buildShouldSucceed(); | |
| 211 | |
| 212 updateSources(["app|foo.one"]); | |
| 213 buildShouldSucceed(); | |
| 214 | |
| 215 expect(lazy.numRuns, completion(equals(1))); | |
| 216 expect(declaring.numRuns, completion(equals(1))); | |
| 217 }); | |
| 218 | |
| 219 test("a lazy asset works as a cross-package input", () { | |
| 220 initGraph({ | |
| 221 "pkg1|foo.blub": "foo", | |
| 222 "pkg2|a.txt": "pkg1|foo.blab" | |
| 223 }, {"pkg1": [ | |
| 224 [new LazyRewriteTransformer("blub", "blab")], | |
| 225 ], "pkg2": [ | |
| 226 [new ManyToOneTransformer("txt")] | |
| 227 ]}); | |
| 228 | |
| 229 updateSources(["pkg1|foo.blub", "pkg2|a.txt"]); | |
| 230 expectAsset("pkg2|a.out", "foo.blab"); | |
| 231 buildShouldSucceed(); | |
| 232 }); | |
| 233 | |
| 234 test("a lazy transformer can consume secondary inputs lazily", () { | |
| 235 initGraph({ | |
| 236 "app|a.inc": "a", | |
| 237 "app|a.txt": "a.inc" | |
| 238 }, {"app": [ | |
| 239 [new LazyManyToOneTransformer("txt")] | |
| 240 ]}); | |
| 241 | |
| 242 updateSources(["app|a.inc", "app|a.txt"]); | |
| 243 expectAsset("app|a.out", "a"); | |
| 244 buildShouldSucceed(); | |
| 245 }); | |
| 246 | |
| 247 test("after being materialized a lazy transformer is still lazy", () { | |
| 248 var transformer = new LazyRewriteTransformer("blub", "blab"); | |
| 249 initGraph(["app|foo.blub"], {"app": [[transformer]]}); | |
| 250 | |
| 251 updateSources(["app|foo.blub"]); | |
| 252 buildShouldSucceed(); | |
| 253 | |
| 254 // Request the asset once to force it to be materialized. | |
| 255 expectAsset("app|foo.blab", "foo.blab"); | |
| 256 buildShouldSucceed(); | |
| 257 | |
| 258 updateSources(["app|foo.blub"]); | |
| 259 buildShouldSucceed(); | |
| 260 | |
| 261 expect(transformer.numRuns, completion(equals(1))); | |
| 262 }); | |
| 263 | |
| 264 test("after being materialized a lazy transformer can be materialized again", | |
| 265 () { | |
| 266 var transformer = new LazyRewriteTransformer("blub", "blab"); | |
| 267 initGraph(["app|foo.blub"], {"app": [[transformer]]}); | |
| 268 | |
| 269 updateSources(["app|foo.blub"]); | |
| 270 buildShouldSucceed(); | |
| 271 | |
| 272 // Request the asset once to force it to be materialized. | |
| 273 expectAsset("app|foo.blab", "foo.blab"); | |
| 274 buildShouldSucceed(); | |
| 275 | |
| 276 modifyAsset("app|foo.blub", "bar"); | |
| 277 updateSources(["app|foo.blub"]); | |
| 278 expectAsset("app|foo.blab", "bar.blab"); | |
| 279 buildShouldSucceed(); | |
| 280 }); | |
| 281 | |
| 282 test("an error emitted in a lazy transformer's declareOutputs method is " | |
| 283 "caught and reported", () { | |
| 284 initGraph(["app|foo.txt"], {"app": [ | |
| 285 [new LazyBadTransformer("app|foo.out")] | |
| 286 ]}); | |
| 287 | |
| 288 updateSources(["app|foo.txt"]); | |
| 289 buildShouldFail([isTransformerException(equals(LazyBadTransformer.ERROR))]); | |
| 290 }); | |
| 291 | |
| 292 test("an error emitted in a lazy transformer's declareOuputs method prevents " | |
| 293 "it from being materialized", () { | |
| 294 var transformer = new LazyBadTransformer("app|foo.out"); | |
| 295 initGraph(["app|foo.txt"], {"app": [[transformer]]}); | |
| 296 | |
| 297 updateSources(["app|foo.txt"]); | |
| 298 expectNoAsset("app|foo.out"); | |
| 299 buildShouldFail([isTransformerException(equals(LazyBadTransformer.ERROR))]); | |
| 300 expect(transformer.numRuns, completion(equals(0))); | |
| 301 }); | |
| 302 | |
| 303 test("a lazy transformer passes through inputs it doesn't apply to", () { | |
| 304 initGraph(["app|foo.txt"], {"app": [ | |
| 305 [new LazyRewriteTransformer("blub", "blab")] | |
| 306 ]}); | |
| 307 | |
| 308 updateSources(["app|foo.txt"]); | |
| 309 expectAsset("app|foo.txt"); | |
| 310 buildShouldSucceed(); | |
| 311 }); | |
| 312 | |
| 313 test("a lazy transformer passes through inputs it doesn't overwrite", () { | |
| 314 initGraph(["app|foo.txt"], {"app": [ | |
| 315 [new LazyRewriteTransformer("txt", "out")] | |
| 316 ]}); | |
| 317 | |
| 318 updateSources(["app|foo.txt"]); | |
| 319 expectAsset("app|foo.txt"); | |
| 320 buildShouldSucceed(); | |
| 321 }); | |
| 322 | |
| 323 test("a lazy transformer doesn't pass through inputs it overwrites", () { | |
| 324 initGraph(["app|foo.txt"], {"app": [ | |
| 325 [new LazyRewriteTransformer("txt", "txt")] | |
| 326 ]}); | |
| 327 | |
| 328 updateSources(["app|foo.txt"]); | |
| 329 expectAsset("app|foo.txt", "foo.txt"); | |
| 330 buildShouldSucceed(); | |
| 331 }); | |
| 332 | |
| 333 test("a lazy transformer doesn't pass through inputs it consumes", () { | |
| 334 initGraph(["app|foo.txt"], {"app": [ | |
| 335 [new LazyRewriteTransformer("txt", "out")..consumePrimary = true] | |
| 336 ]}); | |
| 337 | |
| 338 updateSources(["app|foo.txt"]); | |
| 339 expectNoAsset("app|foo.txt"); | |
| 340 buildShouldSucceed(); | |
| 341 }); | |
| 342 | |
| 343 test("a lazy transformer that doesn't apply does nothing when forced", () { | |
| 344 initGraph(["app|foo.txt"], {"app": [ | |
| 345 [new LazyRewriteTransformer("blub", "blab")] | |
| 346 ]}); | |
| 347 | |
| 348 updateSources(["app|foo.txt"]); | |
| 349 expectNoAsset("app|foo.blab"); | |
| 350 | |
| 351 // Getting all assets will force every lazy transformer. This shouldn't | |
| 352 // cause the rewrite to apply, because foo.txt isn't primary. | |
| 353 expectAllAssets(["app|foo.txt"]); | |
| 354 buildShouldSucceed(); | |
| 355 }); | |
| 356 | |
| 357 test("a lazy transformer that generates fewer outputs than it declares is " | |
| 358 "forced when a declared but ungenerated output is requested", () { | |
| 359 initGraph({"app|foo.txt": "no"}, {"app": [ | |
| 360 [new LazyCheckContentAndRenameTransformer( | |
| 361 oldExtension: "txt", oldContent: "yes", | |
| 362 newExtension: "out", newContent: "done")] | |
| 363 ]}); | |
| 364 | |
| 365 updateSources(["app|foo.txt"]); | |
| 366 expectNoAsset("app|foo.out"); | |
| 367 buildShouldSucceed(); | |
| 368 | |
| 369 modifyAsset("app|foo.txt", "yes"); | |
| 370 updateSources(["app|foo.txt"]); | |
| 371 expectAsset("app|foo.out", "done"); | |
| 372 buildShouldSucceed(); | |
| 373 }); | |
| 374 | |
| 375 // Regression tests. | |
| 376 | |
| 377 test("a lazy transformer that doesn't apply updates its passed-through asset", | |
| 378 () { | |
| 379 initGraph(["app|foo.txt"], {"app": [ | |
| 380 [new LazyRewriteTransformer("blub", "blab")] | |
| 381 ]}); | |
| 382 | |
| 383 // Pause the provider so that the transformer will start forwarding the | |
| 384 // asset while it's dirty. | |
| 385 pauseProvider(); | |
| 386 updateSources(["app|foo.txt"]); | |
| 387 expectAssetDoesNotComplete("app|foo.txt"); | |
| 388 | |
| 389 resumeProvider(); | |
| 390 expectAsset("app|foo.txt", "foo"); | |
| 391 buildShouldSucceed(); | |
| 392 | |
| 393 modifyAsset("app|foo.txt", "bar"); | |
| 394 updateSources(["app|foo.txt"]); | |
| 395 expectAsset("app|foo.txt", "bar"); | |
| 396 buildShouldSucceed(); | |
| 397 }); | |
| 398 | |
| 399 test("a lazy transformer is forced while the previous lazy transformer is " | |
| 400 "available, then the previous transformer becomes unavailable", () { | |
| 401 var assets = new LazyAssetsTransformer(["app|out.one", "app|out.two"]); | |
| 402 var rewrite = new LazyRewriteTransformer("two", "three"); | |
| 403 initGraph(["app|foo.in"], {"app": [[assets], [rewrite]]}); | |
| 404 | |
| 405 updateSources(["app|foo.in"]); | |
| 406 // Request out.one so that [assets] runs but the second does not. | |
| 407 expectAsset("app|out.one", "app|out.one"); | |
| 408 buildShouldSucceed(); | |
| 409 | |
| 410 // Start the [rewrite] running. The output from [assets] should still be | |
| 411 // available. | |
| 412 rewrite.pauseApply(); | |
| 413 expectAssetDoesNotComplete("app|out.three"); | |
| 414 | |
| 415 // Mark [assets] as dirty. It should re-run, since [rewrite] still needs its | |
| 416 // input. | |
| 417 updateSources(["app|foo.in"]); | |
| 418 rewrite.resumeApply(); | |
| 419 | |
| 420 expectAsset("app|out.three", "app|out.two.three"); | |
| 421 buildShouldSucceed(); | |
| 422 | |
| 423 // [assets] should run once for each time foo.in was updated. | |
| 424 expect(assets.numRuns, completion(equals(2))); | |
| 425 | |
| 426 // [rewrite] should run once against [assets]'s original output and once | |
| 427 // against its new output. | |
| 428 expect(rewrite.numRuns, completion(equals(2))); | |
| 429 }); | |
| 430 } | |
| OLD | NEW |