| OLD | NEW |
| 1 // Copyright (c) 2014, the Dart project authors. Please see the AUTHORS file | 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 | 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.lazy_asset_test; | 5 library barback.test.package_graph.lazy_asset_test; |
| 6 | 6 |
| 7 import 'package:barback/barback.dart'; | 7 import 'package:barback/barback.dart'; |
| 8 import 'package:barback/src/utils.dart'; | |
| 9 import 'package:scheduled_test/scheduled_test.dart'; | 8 import 'package:scheduled_test/scheduled_test.dart'; |
| 10 | 9 |
| 11 import '../utils.dart'; | 10 import '../utils.dart'; |
| 12 | 11 |
| 13 main() { | 12 main() { |
| 14 initConfig(); | 13 initConfig(); |
| 15 test("requesting a lazy asset should cause it to be generated", () { | 14 test("requesting a lazy asset should cause it to be generated", () { |
| 16 initGraph(["app|foo.blub"], {"app": [ | 15 initGraph([ |
| 17 [new LazyRewriteTransformer("blub", "blab")] | 16 "app|foo.blub" |
| 18 ]}); | 17 ], { |
| 18 "app": [ |
| 19 [new LazyRewriteTransformer("blub", "blab")] |
| 20 ] |
| 21 }); |
| 19 updateSources(["app|foo.blub"]); | 22 updateSources(["app|foo.blub"]); |
| 20 expectAsset("app|foo.blab", "foo.blab"); | 23 expectAsset("app|foo.blab", "foo.blab"); |
| 21 buildShouldSucceed(); | 24 buildShouldSucceed(); |
| 22 }); | 25 }); |
| 23 | 26 |
| 24 test("calling getAllAssets should cause a lazy asset to be generated", () { | 27 test("calling getAllAssets should cause a lazy asset to be generated", () { |
| 25 var transformer = new LazyRewriteTransformer("blub", "blab"); | 28 var transformer = new LazyRewriteTransformer("blub", "blab"); |
| 26 initGraph(["app|foo.blub"], {"app": [[transformer]]}); | 29 initGraph([ |
| 30 "app|foo.blub" |
| 31 ], { |
| 32 "app": [ |
| 33 [transformer] |
| 34 ] |
| 35 }); |
| 27 updateSources(["app|foo.blub"]); | 36 updateSources(["app|foo.blub"]); |
| 28 expectAllAssets(["app|foo.blub", "app|foo.blab"]); | 37 expectAllAssets(["app|foo.blub", "app|foo.blab"]); |
| 29 buildShouldSucceed(); | 38 buildShouldSucceed(); |
| 30 expect(transformer.numRuns, completion(equals(1))); | 39 expect(transformer.numRuns, completion(equals(1))); |
| 31 }); | 40 }); |
| 32 | 41 |
| 33 test("requesting a lazy asset multiple times should only cause it to be " | 42 test( |
| 43 "requesting a lazy asset multiple times should only cause it to be " |
| 34 "generated once", () { | 44 "generated once", () { |
| 35 var transformer = new LazyRewriteTransformer("blub", "blab"); | 45 var transformer = new LazyRewriteTransformer("blub", "blab"); |
| 36 initGraph(["app|foo.blub"], {"app": [[transformer]]}); | 46 initGraph([ |
| 47 "app|foo.blub" |
| 48 ], { |
| 49 "app": [ |
| 50 [transformer] |
| 51 ] |
| 52 }); |
| 37 updateSources(["app|foo.blub"]); | 53 updateSources(["app|foo.blub"]); |
| 38 expectAsset("app|foo.blab", "foo.blab"); | 54 expectAsset("app|foo.blab", "foo.blab"); |
| 39 expectAsset("app|foo.blab", "foo.blab"); | 55 expectAsset("app|foo.blab", "foo.blab"); |
| 40 expectAsset("app|foo.blab", "foo.blab"); | 56 expectAsset("app|foo.blab", "foo.blab"); |
| 41 buildShouldSucceed(); | 57 buildShouldSucceed(); |
| 42 expect(transformer.numRuns, completion(equals(1))); | 58 expect(transformer.numRuns, completion(equals(1))); |
| 43 }); | 59 }); |
| 44 | 60 |
| 45 test("a lazy asset can be consumed by a non-lazy transformer", () { | 61 test("a lazy asset can be consumed by a non-lazy transformer", () { |
| 46 initGraph(["app|foo.blub"], {"app": [ | 62 initGraph([ |
| 47 [new LazyRewriteTransformer("blub", "blab")], | 63 "app|foo.blub" |
| 48 [new RewriteTransformer("blab", "blib")] | 64 ], { |
| 49 ]}); | 65 "app": [ |
| 66 [new LazyRewriteTransformer("blub", "blab")], |
| 67 [new RewriteTransformer("blab", "blib")] |
| 68 ] |
| 69 }); |
| 50 updateSources(["app|foo.blub"]); | 70 updateSources(["app|foo.blub"]); |
| 51 expectAsset("app|foo.blib", "foo.blab.blib"); | 71 expectAsset("app|foo.blib", "foo.blab.blib"); |
| 52 buildShouldSucceed(); | 72 buildShouldSucceed(); |
| 53 }); | 73 }); |
| 54 | 74 |
| 55 test("a lazy asset isn't eagerly compiled", () { | 75 test("a lazy asset isn't eagerly compiled", () { |
| 56 var transformer = new LazyRewriteTransformer("blub", "blab"); | 76 var transformer = new LazyRewriteTransformer("blub", "blab"); |
| 57 initGraph(["app|foo.blub"], {"app": [[transformer]]}); | 77 initGraph([ |
| 78 "app|foo.blub" |
| 79 ], { |
| 80 "app": [ |
| 81 [transformer] |
| 82 ] |
| 83 }); |
| 58 updateSources(["app|foo.blub"]); | 84 updateSources(["app|foo.blub"]); |
| 59 buildShouldSucceed(); | 85 buildShouldSucceed(); |
| 60 expect(transformer.numRuns, completion(equals(0))); | 86 expect(transformer.numRuns, completion(equals(0))); |
| 61 }); | 87 }); |
| 62 | 88 |
| 63 test("a lazy asset emitted by a group isn't eagerly compiled", () { | 89 test("a lazy asset emitted by a group isn't eagerly compiled", () { |
| 64 var transformer = new LazyRewriteTransformer("blub", "blab"); | 90 var transformer = new LazyRewriteTransformer("blub", "blab"); |
| 65 initGraph(["app|foo.blub"], {"app": [ | 91 initGraph([ |
| 66 [new TransformerGroup([[transformer]])] | 92 "app|foo.blub" |
| 67 ]}); | 93 ], { |
| 94 "app": [ |
| 95 [ |
| 96 new TransformerGroup([ |
| 97 [transformer] |
| 98 ]) |
| 99 ] |
| 100 ] |
| 101 }); |
| 68 updateSources(["app|foo.blub"]); | 102 updateSources(["app|foo.blub"]); |
| 69 buildShouldSucceed(); | 103 buildShouldSucceed(); |
| 70 expect(transformer.numRuns, completion(equals(0))); | 104 expect(transformer.numRuns, completion(equals(0))); |
| 71 }); | 105 }); |
| 72 | 106 |
| 73 test("a lazy asset piped into a non-lazy transformer is eagerly compiled", | 107 test("a lazy asset piped into a non-lazy transformer is eagerly compiled", |
| 74 () { | 108 () { |
| 75 var transformer = new LazyRewriteTransformer("blub", "blab"); | 109 var transformer = new LazyRewriteTransformer("blub", "blab"); |
| 76 initGraph(["app|foo.blub"], {"app": [ | 110 initGraph([ |
| 77 [transformer], | 111 "app|foo.blub" |
| 78 [new RewriteTransformer("blab", "blib")] | 112 ], { |
| 79 ]}); | 113 "app": [ |
| 114 [transformer], |
| 115 [new RewriteTransformer("blab", "blib")] |
| 116 ] |
| 117 }); |
| 80 updateSources(["app|foo.blub"]); | 118 updateSources(["app|foo.blub"]); |
| 81 buildShouldSucceed(); | 119 buildShouldSucceed(); |
| 82 expect(transformer.numRuns, completion(equals(1))); | 120 expect(transformer.numRuns, completion(equals(1))); |
| 83 }); | 121 }); |
| 84 | 122 |
| 85 test("a lazy asset piped into a declaring transformer isn't eagerly " | 123 test( |
| 124 "a lazy asset piped into a declaring transformer isn't eagerly " |
| 86 "compiled", () { | 125 "compiled", () { |
| 87 var transformer1 = new LazyRewriteTransformer("blub", "blab"); | 126 var transformer1 = new LazyRewriteTransformer("blub", "blab"); |
| 88 var transformer2 = new DeclaringRewriteTransformer("blab", "blib"); | 127 var transformer2 = new DeclaringRewriteTransformer("blab", "blib"); |
| 89 initGraph(["app|foo.blub"], {"app": [ | 128 initGraph([ |
| 90 [transformer1], [transformer2] | 129 "app|foo.blub" |
| 91 ]}); | 130 ], { |
| 131 "app": [ |
| 132 [transformer1], |
| 133 [transformer2] |
| 134 ] |
| 135 }); |
| 92 updateSources(["app|foo.blub"]); | 136 updateSources(["app|foo.blub"]); |
| 93 buildShouldSucceed(); | 137 buildShouldSucceed(); |
| 94 expect(transformer1.numRuns, completion(equals(0))); | 138 expect(transformer1.numRuns, completion(equals(0))); |
| 95 expect(transformer2.numRuns, completion(equals(0))); | 139 expect(transformer2.numRuns, completion(equals(0))); |
| 96 }); | 140 }); |
| 97 | 141 |
| 98 test("a lazy asset piped into a declaring transformer is compiled " | 142 test( |
| 143 "a lazy asset piped into a declaring transformer is compiled " |
| 99 "on-demand", () { | 144 "on-demand", () { |
| 100 initGraph(["app|foo.blub"], {"app": [ | 145 initGraph([ |
| 101 [new LazyRewriteTransformer("blub", "blab")], | 146 "app|foo.blub" |
| 102 [new DeclaringRewriteTransformer("blab", "blib")] | 147 ], { |
| 103 ]}); | 148 "app": [ |
| 149 [new LazyRewriteTransformer("blub", "blab")], |
| 150 [new DeclaringRewriteTransformer("blab", "blib")] |
| 151 ] |
| 152 }); |
| 104 updateSources(["app|foo.blub"]); | 153 updateSources(["app|foo.blub"]); |
| 105 expectAsset("app|foo.blib", "foo.blab.blib"); | 154 expectAsset("app|foo.blib", "foo.blab.blib"); |
| 106 buildShouldSucceed(); | 155 buildShouldSucceed(); |
| 107 }); | 156 }); |
| 108 | 157 |
| 109 test("a lazy asset piped through many declaring transformers isn't eagerly " | 158 test( |
| 159 "a lazy asset piped through many declaring transformers isn't eagerly " |
| 110 "compiled", () { | 160 "compiled", () { |
| 111 var transformer1 = new LazyRewriteTransformer("one", "two"); | 161 var transformer1 = new LazyRewriteTransformer("one", "two"); |
| 112 var transformer2 = new DeclaringRewriteTransformer("two", "three"); | 162 var transformer2 = new DeclaringRewriteTransformer("two", "three"); |
| 113 var transformer3 = new DeclaringRewriteTransformer("three", "four"); | 163 var transformer3 = new DeclaringRewriteTransformer("three", "four"); |
| 114 var transformer4 = new DeclaringRewriteTransformer("four", "five"); | 164 var transformer4 = new DeclaringRewriteTransformer("four", "five"); |
| 115 initGraph(["app|foo.one"], {"app": [ | 165 initGraph([ |
| 116 [transformer1], [transformer2], [transformer3], [transformer4] | 166 "app|foo.one" |
| 117 ]}); | 167 ], { |
| 168 "app": [ |
| 169 [transformer1], |
| 170 [transformer2], |
| 171 [transformer3], |
| 172 [transformer4] |
| 173 ] |
| 174 }); |
| 118 updateSources(["app|foo.one"]); | 175 updateSources(["app|foo.one"]); |
| 119 buildShouldSucceed(); | 176 buildShouldSucceed(); |
| 120 expect(transformer1.numRuns, completion(equals(0))); | 177 expect(transformer1.numRuns, completion(equals(0))); |
| 121 expect(transformer2.numRuns, completion(equals(0))); | 178 expect(transformer2.numRuns, completion(equals(0))); |
| 122 expect(transformer3.numRuns, completion(equals(0))); | 179 expect(transformer3.numRuns, completion(equals(0))); |
| 123 expect(transformer4.numRuns, completion(equals(0))); | 180 expect(transformer4.numRuns, completion(equals(0))); |
| 124 }); | 181 }); |
| 125 | 182 |
| 126 test("a lazy asset piped through many declaring transformers is compiled " | 183 test( |
| 184 "a lazy asset piped through many declaring transformers is compiled " |
| 127 "on-demand", () { | 185 "on-demand", () { |
| 128 initGraph(["app|foo.one"], {"app": [ | 186 initGraph([ |
| 129 [new LazyRewriteTransformer("one", "two")], | 187 "app|foo.one" |
| 130 [new DeclaringRewriteTransformer("two", "three")], | 188 ], { |
| 131 [new DeclaringRewriteTransformer("three", "four")], | 189 "app": [ |
| 132 [new DeclaringRewriteTransformer("four", "five")] | 190 [new LazyRewriteTransformer("one", "two")], |
| 133 ]}); | 191 [new DeclaringRewriteTransformer("two", "three")], |
| 192 [new DeclaringRewriteTransformer("three", "four")], |
| 193 [new DeclaringRewriteTransformer("four", "five")] |
| 194 ] |
| 195 }); |
| 134 updateSources(["app|foo.one"]); | 196 updateSources(["app|foo.one"]); |
| 135 expectAsset("app|foo.five", "foo.two.three.four.five"); | 197 expectAsset("app|foo.five", "foo.two.three.four.five"); |
| 136 buildShouldSucceed(); | 198 buildShouldSucceed(); |
| 137 }); | 199 }); |
| 138 | 200 |
| 139 test("a lazy asset piped into a non-lazy transformer that doesn't use its " | 201 test( |
| 202 "a lazy asset piped into a non-lazy transformer that doesn't use its " |
| 140 "outputs isn't eagerly compiled", () { | 203 "outputs isn't eagerly compiled", () { |
| 141 var transformer = new LazyRewriteTransformer("blub", "blab"); | 204 var transformer = new LazyRewriteTransformer("blub", "blab"); |
| 142 initGraph(["app|foo.blub"], {"app": [ | 205 initGraph([ |
| 143 [transformer], | 206 "app|foo.blub" |
| 144 [new RewriteTransformer("txt", "out")] | 207 ], { |
| 145 ]}); | 208 "app": [ |
| 209 [transformer], |
| 210 [new RewriteTransformer("txt", "out")] |
| 211 ] |
| 212 }); |
| 146 updateSources(["app|foo.blub"]); | 213 updateSources(["app|foo.blub"]); |
| 147 buildShouldSucceed(); | 214 buildShouldSucceed(); |
| 148 expect(transformer.numRuns, completion(equals(0))); | 215 expect(transformer.numRuns, completion(equals(0))); |
| 149 }); | 216 }); |
| 150 | 217 |
| 151 test("a lazy asset piped into a non-lazy transformer that doesn't use its " | 218 test( |
| 219 "a lazy asset piped into a non-lazy transformer that doesn't use its " |
| 152 "outputs is compiled on-demand", () { | 220 "outputs is compiled on-demand", () { |
| 153 initGraph(["app|foo.blub"], {"app": [ | 221 initGraph([ |
| 154 [new LazyRewriteTransformer("blub", "blab")], | 222 "app|foo.blub" |
| 155 [new RewriteTransformer("txt", "out")] | 223 ], { |
| 156 ]}); | 224 "app": [ |
| 225 [new LazyRewriteTransformer("blub", "blab")], |
| 226 [new RewriteTransformer("txt", "out")] |
| 227 ] |
| 228 }); |
| 157 updateSources(["app|foo.blub"]); | 229 updateSources(["app|foo.blub"]); |
| 158 expectAsset("app|foo.blab", "foo.blab"); | 230 expectAsset("app|foo.blab", "foo.blab"); |
| 159 buildShouldSucceed(); | 231 buildShouldSucceed(); |
| 160 }); | 232 }); |
| 161 | 233 |
| 162 test("a lazy transformer followed by a non-lazy transformer is re-run " | 234 test( |
| 235 "a lazy transformer followed by a non-lazy transformer is re-run " |
| 163 "eagerly", () { | 236 "eagerly", () { |
| 164 var rewrite = new LazyRewriteTransformer("one", "two"); | 237 var rewrite = new LazyRewriteTransformer("one", "two"); |
| 165 initGraph(["app|foo.one"], {"app": [ | 238 initGraph([ |
| 166 [rewrite], | 239 "app|foo.one" |
| 167 [new RewriteTransformer("two", "three")] | 240 ], { |
| 168 ]}); | 241 "app": [ |
| 242 [rewrite], |
| 243 [new RewriteTransformer("two", "three")] |
| 244 ] |
| 245 }); |
| 169 | 246 |
| 170 updateSources(["app|foo.one"]); | 247 updateSources(["app|foo.one"]); |
| 171 expectAsset("app|foo.three", "foo.two.three"); | 248 expectAsset("app|foo.three", "foo.two.three"); |
| 172 buildShouldSucceed(); | 249 buildShouldSucceed(); |
| 173 | 250 |
| 174 updateSources(["app|foo.one"]); | 251 updateSources(["app|foo.one"]); |
| 175 buildShouldSucceed(); | 252 buildShouldSucceed(); |
| 176 | 253 |
| 177 expect(rewrite.numRuns, completion(equals(2))); | 254 expect(rewrite.numRuns, completion(equals(2))); |
| 178 }); | 255 }); |
| 179 | 256 |
| 180 test("a lazy transformer followed by a declaring transformer isn't re-run " | 257 test( |
| 258 "a lazy transformer followed by a declaring transformer isn't re-run " |
| 181 "eagerly", () { | 259 "eagerly", () { |
| 182 var rewrite = new LazyRewriteTransformer("one", "two"); | 260 var rewrite = new LazyRewriteTransformer("one", "two"); |
| 183 initGraph(["app|foo.one"], {"app": [ | 261 initGraph([ |
| 184 [rewrite], | 262 "app|foo.one" |
| 185 [new DeclaringRewriteTransformer("two", "three")] | 263 ], { |
| 186 ]}); | 264 "app": [ |
| 265 [rewrite], |
| 266 [new DeclaringRewriteTransformer("two", "three")] |
| 267 ] |
| 268 }); |
| 187 | 269 |
| 188 updateSources(["app|foo.one"]); | 270 updateSources(["app|foo.one"]); |
| 189 expectAsset("app|foo.three", "foo.two.three"); | 271 expectAsset("app|foo.three", "foo.two.three"); |
| 190 buildShouldSucceed(); | 272 buildShouldSucceed(); |
| 191 | 273 |
| 192 updateSources(["app|foo.one"]); | 274 updateSources(["app|foo.one"]); |
| 193 buildShouldSucceed(); | 275 buildShouldSucceed(); |
| 194 | 276 |
| 195 expect(rewrite.numRuns, completion(equals(1))); | 277 expect(rewrite.numRuns, completion(equals(1))); |
| 196 }); | 278 }); |
| 197 | 279 |
| 198 test("a declaring transformer added after a materialized lazy transformer " | 280 test( |
| 281 "a declaring transformer added after a materialized lazy transformer " |
| 199 "is still deferred", () { | 282 "is still deferred", () { |
| 200 var lazy = new LazyRewriteTransformer("one", "two"); | 283 var lazy = new LazyRewriteTransformer("one", "two"); |
| 201 var declaring = new DeclaringRewriteTransformer("two", "three"); | 284 var declaring = new DeclaringRewriteTransformer("two", "three"); |
| 202 initGraph(["app|foo.one"], {"app": [[lazy]]}); | 285 initGraph([ |
| 286 "app|foo.one" |
| 287 ], { |
| 288 "app": [ |
| 289 [lazy] |
| 290 ] |
| 291 }); |
| 203 | 292 |
| 204 updateSources(["app|foo.one"]); | 293 updateSources(["app|foo.one"]); |
| 205 expectAsset("app|foo.two", "foo.two"); | 294 expectAsset("app|foo.two", "foo.two"); |
| 206 buildShouldSucceed(); | 295 buildShouldSucceed(); |
| 207 | 296 |
| 208 updateTransformers("app", [[lazy], [declaring]]); | 297 updateTransformers("app", [ |
| 298 [lazy], |
| 299 [declaring] |
| 300 ]); |
| 209 expectAsset("app|foo.three", "foo.two.three"); | 301 expectAsset("app|foo.three", "foo.two.three"); |
| 210 buildShouldSucceed(); | 302 buildShouldSucceed(); |
| 211 | 303 |
| 212 updateSources(["app|foo.one"]); | 304 updateSources(["app|foo.one"]); |
| 213 buildShouldSucceed(); | 305 buildShouldSucceed(); |
| 214 | 306 |
| 215 expect(lazy.numRuns, completion(equals(1))); | 307 expect(lazy.numRuns, completion(equals(1))); |
| 216 expect(declaring.numRuns, completion(equals(1))); | 308 expect(declaring.numRuns, completion(equals(1))); |
| 217 }); | 309 }); |
| 218 | 310 |
| 219 test("a lazy asset works as a cross-package input", () { | 311 test("a lazy asset works as a cross-package input", () { |
| 220 initGraph({ | 312 initGraph({ |
| 221 "pkg1|foo.blub": "foo", | 313 "pkg1|foo.blub": "foo", |
| 222 "pkg2|a.txt": "pkg1|foo.blab" | 314 "pkg2|a.txt": "pkg1|foo.blab" |
| 223 }, {"pkg1": [ | 315 }, { |
| 224 [new LazyRewriteTransformer("blub", "blab")], | 316 "pkg1": [ |
| 225 ], "pkg2": [ | 317 [new LazyRewriteTransformer("blub", "blab")], |
| 226 [new ManyToOneTransformer("txt")] | 318 ], |
| 227 ]}); | 319 "pkg2": [ |
| 320 [new ManyToOneTransformer("txt")] |
| 321 ] |
| 322 }); |
| 228 | 323 |
| 229 updateSources(["pkg1|foo.blub", "pkg2|a.txt"]); | 324 updateSources(["pkg1|foo.blub", "pkg2|a.txt"]); |
| 230 expectAsset("pkg2|a.out", "foo.blab"); | 325 expectAsset("pkg2|a.out", "foo.blab"); |
| 231 buildShouldSucceed(); | 326 buildShouldSucceed(); |
| 232 }); | 327 }); |
| 233 | 328 |
| 234 test("a lazy transformer can consume secondary inputs lazily", () { | 329 test("a lazy transformer can consume secondary inputs lazily", () { |
| 235 initGraph({ | 330 initGraph({ |
| 236 "app|a.inc": "a", | 331 "app|a.inc": "a", |
| 237 "app|a.txt": "a.inc" | 332 "app|a.txt": "a.inc" |
| 238 }, {"app": [ | 333 }, { |
| 239 [new LazyManyToOneTransformer("txt")] | 334 "app": [ |
| 240 ]}); | 335 [new LazyManyToOneTransformer("txt")] |
| 336 ] |
| 337 }); |
| 241 | 338 |
| 242 updateSources(["app|a.inc", "app|a.txt"]); | 339 updateSources(["app|a.inc", "app|a.txt"]); |
| 243 expectAsset("app|a.out", "a"); | 340 expectAsset("app|a.out", "a"); |
| 244 buildShouldSucceed(); | 341 buildShouldSucceed(); |
| 245 }); | 342 }); |
| 246 | 343 |
| 247 test("after being materialized a lazy transformer is still lazy", () { | 344 test("after being materialized a lazy transformer is still lazy", () { |
| 248 var transformer = new LazyRewriteTransformer("blub", "blab"); | 345 var transformer = new LazyRewriteTransformer("blub", "blab"); |
| 249 initGraph(["app|foo.blub"], {"app": [[transformer]]}); | 346 initGraph([ |
| 347 "app|foo.blub" |
| 348 ], { |
| 349 "app": [ |
| 350 [transformer] |
| 351 ] |
| 352 }); |
| 250 | 353 |
| 251 updateSources(["app|foo.blub"]); | 354 updateSources(["app|foo.blub"]); |
| 252 buildShouldSucceed(); | 355 buildShouldSucceed(); |
| 253 | 356 |
| 254 // Request the asset once to force it to be materialized. | 357 // Request the asset once to force it to be materialized. |
| 255 expectAsset("app|foo.blab", "foo.blab"); | 358 expectAsset("app|foo.blab", "foo.blab"); |
| 256 buildShouldSucceed(); | 359 buildShouldSucceed(); |
| 257 | 360 |
| 258 updateSources(["app|foo.blub"]); | 361 updateSources(["app|foo.blub"]); |
| 259 buildShouldSucceed(); | 362 buildShouldSucceed(); |
| 260 | 363 |
| 261 expect(transformer.numRuns, completion(equals(1))); | 364 expect(transformer.numRuns, completion(equals(1))); |
| 262 }); | 365 }); |
| 263 | 366 |
| 264 test("after being materialized a lazy transformer can be materialized again", | 367 test("after being materialized a lazy transformer can be materialized again", |
| 265 () { | 368 () { |
| 266 var transformer = new LazyRewriteTransformer("blub", "blab"); | 369 var transformer = new LazyRewriteTransformer("blub", "blab"); |
| 267 initGraph(["app|foo.blub"], {"app": [[transformer]]}); | 370 initGraph([ |
| 371 "app|foo.blub" |
| 372 ], { |
| 373 "app": [ |
| 374 [transformer] |
| 375 ] |
| 376 }); |
| 268 | 377 |
| 269 updateSources(["app|foo.blub"]); | 378 updateSources(["app|foo.blub"]); |
| 270 buildShouldSucceed(); | 379 buildShouldSucceed(); |
| 271 | 380 |
| 272 // Request the asset once to force it to be materialized. | 381 // Request the asset once to force it to be materialized. |
| 273 expectAsset("app|foo.blab", "foo.blab"); | 382 expectAsset("app|foo.blab", "foo.blab"); |
| 274 buildShouldSucceed(); | 383 buildShouldSucceed(); |
| 275 | 384 |
| 276 modifyAsset("app|foo.blub", "bar"); | 385 modifyAsset("app|foo.blub", "bar"); |
| 277 updateSources(["app|foo.blub"]); | 386 updateSources(["app|foo.blub"]); |
| 278 expectAsset("app|foo.blab", "bar.blab"); | 387 expectAsset("app|foo.blab", "bar.blab"); |
| 279 buildShouldSucceed(); | 388 buildShouldSucceed(); |
| 280 }); | 389 }); |
| 281 | 390 |
| 282 test("an error emitted in a lazy transformer's declareOutputs method is " | 391 test( |
| 392 "an error emitted in a lazy transformer's declareOutputs method is " |
| 283 "caught and reported", () { | 393 "caught and reported", () { |
| 284 initGraph(["app|foo.txt"], {"app": [ | 394 initGraph([ |
| 285 [new LazyBadTransformer("app|foo.out")] | 395 "app|foo.txt" |
| 286 ]}); | 396 ], { |
| 397 "app": [ |
| 398 [new LazyBadTransformer("app|foo.out")] |
| 399 ] |
| 400 }); |
| 287 | 401 |
| 288 updateSources(["app|foo.txt"]); | 402 updateSources(["app|foo.txt"]); |
| 289 buildShouldFail([isTransformerException(equals(LazyBadTransformer.ERROR))]); | 403 buildShouldFail([isTransformerException(equals(LazyBadTransformer.ERROR))]); |
| 290 }); | 404 }); |
| 291 | 405 |
| 292 test("an error emitted in a lazy transformer's declareOuputs method prevents " | 406 test( |
| 407 "an error emitted in a lazy transformer's declareOuputs method prevents " |
| 293 "it from being materialized", () { | 408 "it from being materialized", () { |
| 294 var transformer = new LazyBadTransformer("app|foo.out"); | 409 var transformer = new LazyBadTransformer("app|foo.out"); |
| 295 initGraph(["app|foo.txt"], {"app": [[transformer]]}); | 410 initGraph([ |
| 411 "app|foo.txt" |
| 412 ], { |
| 413 "app": [ |
| 414 [transformer] |
| 415 ] |
| 416 }); |
| 296 | 417 |
| 297 updateSources(["app|foo.txt"]); | 418 updateSources(["app|foo.txt"]); |
| 298 expectNoAsset("app|foo.out"); | 419 expectNoAsset("app|foo.out"); |
| 299 buildShouldFail([isTransformerException(equals(LazyBadTransformer.ERROR))]); | 420 buildShouldFail([isTransformerException(equals(LazyBadTransformer.ERROR))]); |
| 300 expect(transformer.numRuns, completion(equals(0))); | 421 expect(transformer.numRuns, completion(equals(0))); |
| 301 }); | 422 }); |
| 302 | 423 |
| 303 test("a lazy transformer passes through inputs it doesn't apply to", () { | 424 test("a lazy transformer passes through inputs it doesn't apply to", () { |
| 304 initGraph(["app|foo.txt"], {"app": [ | 425 initGraph([ |
| 305 [new LazyRewriteTransformer("blub", "blab")] | 426 "app|foo.txt" |
| 306 ]}); | 427 ], { |
| 428 "app": [ |
| 429 [new LazyRewriteTransformer("blub", "blab")] |
| 430 ] |
| 431 }); |
| 307 | 432 |
| 308 updateSources(["app|foo.txt"]); | 433 updateSources(["app|foo.txt"]); |
| 309 expectAsset("app|foo.txt"); | 434 expectAsset("app|foo.txt"); |
| 310 buildShouldSucceed(); | 435 buildShouldSucceed(); |
| 311 }); | 436 }); |
| 312 | 437 |
| 313 test("a lazy transformer passes through inputs it doesn't overwrite", () { | 438 test("a lazy transformer passes through inputs it doesn't overwrite", () { |
| 314 initGraph(["app|foo.txt"], {"app": [ | 439 initGraph([ |
| 315 [new LazyRewriteTransformer("txt", "out")] | 440 "app|foo.txt" |
| 316 ]}); | 441 ], { |
| 442 "app": [ |
| 443 [new LazyRewriteTransformer("txt", "out")] |
| 444 ] |
| 445 }); |
| 317 | 446 |
| 318 updateSources(["app|foo.txt"]); | 447 updateSources(["app|foo.txt"]); |
| 319 expectAsset("app|foo.txt"); | 448 expectAsset("app|foo.txt"); |
| 320 buildShouldSucceed(); | 449 buildShouldSucceed(); |
| 321 }); | 450 }); |
| 322 | 451 |
| 323 test("a lazy transformer doesn't pass through inputs it overwrites", () { | 452 test("a lazy transformer doesn't pass through inputs it overwrites", () { |
| 324 initGraph(["app|foo.txt"], {"app": [ | 453 initGraph([ |
| 325 [new LazyRewriteTransformer("txt", "txt")] | 454 "app|foo.txt" |
| 326 ]}); | 455 ], { |
| 456 "app": [ |
| 457 [new LazyRewriteTransformer("txt", "txt")] |
| 458 ] |
| 459 }); |
| 327 | 460 |
| 328 updateSources(["app|foo.txt"]); | 461 updateSources(["app|foo.txt"]); |
| 329 expectAsset("app|foo.txt", "foo.txt"); | 462 expectAsset("app|foo.txt", "foo.txt"); |
| 330 buildShouldSucceed(); | 463 buildShouldSucceed(); |
| 331 }); | 464 }); |
| 332 | 465 |
| 333 test("a lazy transformer doesn't pass through inputs it consumes", () { | 466 test("a lazy transformer doesn't pass through inputs it consumes", () { |
| 334 initGraph(["app|foo.txt"], {"app": [ | 467 initGraph([ |
| 335 [new LazyRewriteTransformer("txt", "out")..consumePrimary = true] | 468 "app|foo.txt" |
| 336 ]}); | 469 ], { |
| 470 "app": [ |
| 471 [new LazyRewriteTransformer("txt", "out")..consumePrimary = true] |
| 472 ] |
| 473 }); |
| 337 | 474 |
| 338 updateSources(["app|foo.txt"]); | 475 updateSources(["app|foo.txt"]); |
| 339 expectNoAsset("app|foo.txt"); | 476 expectNoAsset("app|foo.txt"); |
| 340 buildShouldSucceed(); | 477 buildShouldSucceed(); |
| 341 }); | 478 }); |
| 342 | 479 |
| 343 test("a lazy transformer that doesn't apply does nothing when forced", () { | 480 test("a lazy transformer that doesn't apply does nothing when forced", () { |
| 344 initGraph(["app|foo.txt"], {"app": [ | 481 initGraph([ |
| 345 [new LazyRewriteTransformer("blub", "blab")] | 482 "app|foo.txt" |
| 346 ]}); | 483 ], { |
| 484 "app": [ |
| 485 [new LazyRewriteTransformer("blub", "blab")] |
| 486 ] |
| 487 }); |
| 347 | 488 |
| 348 updateSources(["app|foo.txt"]); | 489 updateSources(["app|foo.txt"]); |
| 349 expectNoAsset("app|foo.blab"); | 490 expectNoAsset("app|foo.blab"); |
| 350 | 491 |
| 351 // Getting all assets will force every lazy transformer. This shouldn't | 492 // Getting all assets will force every lazy transformer. This shouldn't |
| 352 // cause the rewrite to apply, because foo.txt isn't primary. | 493 // cause the rewrite to apply, because foo.txt isn't primary. |
| 353 expectAllAssets(["app|foo.txt"]); | 494 expectAllAssets(["app|foo.txt"]); |
| 354 buildShouldSucceed(); | 495 buildShouldSucceed(); |
| 355 }); | 496 }); |
| 356 | 497 |
| 357 test("a lazy transformer that generates fewer outputs than it declares is " | 498 test( |
| 499 "a lazy transformer that generates fewer outputs than it declares is " |
| 358 "forced when a declared but ungenerated output is requested", () { | 500 "forced when a declared but ungenerated output is requested", () { |
| 359 initGraph({"app|foo.txt": "no"}, {"app": [ | 501 initGraph({ |
| 360 [new LazyCheckContentAndRenameTransformer( | 502 "app|foo.txt": "no" |
| 361 oldExtension: "txt", oldContent: "yes", | 503 }, { |
| 362 newExtension: "out", newContent: "done")] | 504 "app": [ |
| 363 ]}); | 505 [ |
| 506 new LazyCheckContentAndRenameTransformer( |
| 507 oldExtension: "txt", |
| 508 oldContent: "yes", |
| 509 newExtension: "out", |
| 510 newContent: "done") |
| 511 ] |
| 512 ] |
| 513 }); |
| 364 | 514 |
| 365 updateSources(["app|foo.txt"]); | 515 updateSources(["app|foo.txt"]); |
| 366 expectNoAsset("app|foo.out"); | 516 expectNoAsset("app|foo.out"); |
| 367 buildShouldSucceed(); | 517 buildShouldSucceed(); |
| 368 | 518 |
| 369 modifyAsset("app|foo.txt", "yes"); | 519 modifyAsset("app|foo.txt", "yes"); |
| 370 updateSources(["app|foo.txt"]); | 520 updateSources(["app|foo.txt"]); |
| 371 expectAsset("app|foo.out", "done"); | 521 expectAsset("app|foo.out", "done"); |
| 372 buildShouldSucceed(); | 522 buildShouldSucceed(); |
| 373 }); | 523 }); |
| 374 | 524 |
| 375 // Regression tests. | 525 // Regression tests. |
| 376 | 526 |
| 377 test("a lazy transformer that doesn't apply updates its passed-through asset", | 527 test("a lazy transformer that doesn't apply updates its passed-through asset", |
| 378 () { | 528 () { |
| 379 initGraph(["app|foo.txt"], {"app": [ | 529 initGraph([ |
| 380 [new LazyRewriteTransformer("blub", "blab")] | 530 "app|foo.txt" |
| 381 ]}); | 531 ], { |
| 532 "app": [ |
| 533 [new LazyRewriteTransformer("blub", "blab")] |
| 534 ] |
| 535 }); |
| 382 | 536 |
| 383 // Pause the provider so that the transformer will start forwarding the | 537 // Pause the provider so that the transformer will start forwarding the |
| 384 // asset while it's dirty. | 538 // asset while it's dirty. |
| 385 pauseProvider(); | 539 pauseProvider(); |
| 386 updateSources(["app|foo.txt"]); | 540 updateSources(["app|foo.txt"]); |
| 387 expectAssetDoesNotComplete("app|foo.txt"); | 541 expectAssetDoesNotComplete("app|foo.txt"); |
| 388 | 542 |
| 389 resumeProvider(); | 543 resumeProvider(); |
| 390 expectAsset("app|foo.txt", "foo"); | 544 expectAsset("app|foo.txt", "foo"); |
| 391 buildShouldSucceed(); | 545 buildShouldSucceed(); |
| 392 | 546 |
| 393 modifyAsset("app|foo.txt", "bar"); | 547 modifyAsset("app|foo.txt", "bar"); |
| 394 updateSources(["app|foo.txt"]); | 548 updateSources(["app|foo.txt"]); |
| 395 expectAsset("app|foo.txt", "bar"); | 549 expectAsset("app|foo.txt", "bar"); |
| 396 buildShouldSucceed(); | 550 buildShouldSucceed(); |
| 397 }); | 551 }); |
| 398 | 552 |
| 399 test("a lazy transformer is forced while the previous lazy transformer is " | 553 test( |
| 554 "a lazy transformer is forced while the previous lazy transformer is " |
| 400 "available, then the previous transformer becomes unavailable", () { | 555 "available, then the previous transformer becomes unavailable", () { |
| 401 var assets = new LazyAssetsTransformer(["app|out.one", "app|out.two"]); | 556 var assets = new LazyAssetsTransformer(["app|out.one", "app|out.two"]); |
| 402 var rewrite = new LazyRewriteTransformer("two", "three"); | 557 var rewrite = new LazyRewriteTransformer("two", "three"); |
| 403 initGraph(["app|foo.in"], {"app": [[assets], [rewrite]]}); | 558 initGraph([ |
| 559 "app|foo.in" |
| 560 ], { |
| 561 "app": [ |
| 562 [assets], |
| 563 [rewrite] |
| 564 ] |
| 565 }); |
| 404 | 566 |
| 405 updateSources(["app|foo.in"]); | 567 updateSources(["app|foo.in"]); |
| 406 // Request out.one so that [assets] runs but the second does not. | 568 // Request out.one so that [assets] runs but the second does not. |
| 407 expectAsset("app|out.one", "app|out.one"); | 569 expectAsset("app|out.one", "app|out.one"); |
| 408 buildShouldSucceed(); | 570 buildShouldSucceed(); |
| 409 | 571 |
| 410 // Start the [rewrite] running. The output from [assets] should still be | 572 // Start the [rewrite] running. The output from [assets] should still be |
| 411 // available. | 573 // available. |
| 412 rewrite.pauseApply(); | 574 rewrite.pauseApply(); |
| 413 expectAssetDoesNotComplete("app|out.three"); | 575 expectAssetDoesNotComplete("app|out.three"); |
| 414 | 576 |
| 415 // Mark [assets] as dirty. It should re-run, since [rewrite] still needs its | 577 // Mark [assets] as dirty. It should re-run, since [rewrite] still needs its |
| 416 // input. | 578 // input. |
| 417 updateSources(["app|foo.in"]); | 579 updateSources(["app|foo.in"]); |
| 418 rewrite.resumeApply(); | 580 rewrite.resumeApply(); |
| 419 | 581 |
| 420 expectAsset("app|out.three", "app|out.two.three"); | 582 expectAsset("app|out.three", "app|out.two.three"); |
| 421 buildShouldSucceed(); | 583 buildShouldSucceed(); |
| 422 | 584 |
| 423 // [assets] should run once for each time foo.in was updated. | 585 // [assets] should run once for each time foo.in was updated. |
| 424 expect(assets.numRuns, completion(equals(2))); | 586 expect(assets.numRuns, completion(equals(2))); |
| 425 | 587 |
| 426 // [rewrite] should run once against [assets]'s original output and once | 588 // [rewrite] should run once against [assets]'s original output and once |
| 427 // against its new output. | 589 // against its new output. |
| 428 expect(rewrite.numRuns, completion(equals(2))); | 590 expect(rewrite.numRuns, completion(equals(2))); |
| 429 }); | 591 }); |
| 430 } | 592 } |
| OLD | NEW |