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.declaring_transformer_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 |
| 16 test("gets a declared output with a different path", () { |
| 17 initGraph(["app|foo.blub"], {"app": [ |
| 18 [new DeclaringRewriteTransformer("blub", "blab")] |
| 19 ]}); |
| 20 updateSources(["app|foo.blub"]); |
| 21 expectAsset("app|foo.blab", "foo.blab"); |
| 22 buildShouldSucceed(); |
| 23 }); |
| 24 |
| 25 test("gets a declared output with the same path", () { |
| 26 initGraph(["app|foo.blub"], {"app": [ |
| 27 [new DeclaringRewriteTransformer("blub", "blub")] |
| 28 ]}); |
| 29 updateSources(["app|foo.blub"]); |
| 30 expectAsset("app|foo.blub", "foo.blub"); |
| 31 buildShouldSucceed(); |
| 32 }); |
| 33 |
| 34 test("gets a passed-through asset", () { |
| 35 initGraph(["app|foo.blub"], {"app": [ |
| 36 [new DeclaringRewriteTransformer("blub", "blab")] |
| 37 ]}); |
| 38 updateSources(["app|foo.blub"]); |
| 39 expectAsset("app|foo.blub", "foo"); |
| 40 buildShouldSucceed(); |
| 41 }); |
| 42 |
| 43 test("doesn't get a consumed asset", () { |
| 44 initGraph(["app|foo.blub"], {"app": [ |
| 45 [new DeclaringRewriteTransformer("blub", "blab")..consumePrimary = true] |
| 46 ]}); |
| 47 updateSources(["app|foo.blub"]); |
| 48 expectNoAsset("app|foo.blub"); |
| 49 buildShouldSucceed(); |
| 50 }); |
| 51 |
| 52 test("gets a passed-through asset before apply is finished", () { |
| 53 var transformer = new DeclaringRewriteTransformer("blub", "blab"); |
| 54 initGraph(["app|foo.blub"], {"app": [[transformer]]}); |
| 55 |
| 56 transformer.pauseApply(); |
| 57 updateSources(["app|foo.blub"]); |
| 58 expectAsset("app|foo.blub", "foo"); |
| 59 |
| 60 transformer.resumeApply(); |
| 61 buildShouldSucceed(); |
| 62 }); |
| 63 |
| 64 test("fails to get a consumed asset before apply is finished", () { |
| 65 var transformer = new DeclaringRewriteTransformer("blub", "blab") |
| 66 ..consumePrimary = true; |
| 67 initGraph(["app|foo.blub"], {"app": [[transformer]]}); |
| 68 |
| 69 transformer.pauseApply(); |
| 70 updateSources(["app|foo.blub"]); |
| 71 expectNoAsset("app|foo.blub"); |
| 72 |
| 73 transformer.resumeApply(); |
| 74 buildShouldSucceed(); |
| 75 }); |
| 76 |
| 77 test("blocks on getting a declared asset that wasn't generated last run", () { |
| 78 var transformer = new DeclaringCheckContentAndRenameTransformer( |
| 79 oldExtension: "txt", oldContent: "yes", |
| 80 newExtension: "out", newContent: "done"); |
| 81 initGraph({"app|foo.txt": "no"}, {"app": [[transformer]]}); |
| 82 |
| 83 updateSources(["app|foo.txt"]); |
| 84 expectNoAsset("app|foo.out"); |
| 85 buildShouldSucceed(); |
| 86 |
| 87 // The transform should remember that foo.out was declared, so it should |
| 88 // expect that it might still be generated even though it wasn't last time. |
| 89 transformer.pauseApply(); |
| 90 modifyAsset("app|foo.txt", "yes"); |
| 91 updateSources(["app|foo.txt"]); |
| 92 expectAssetDoesNotComplete("app|foo.out"); |
| 93 |
| 94 transformer.resumeApply(); |
| 95 expectAsset("app|foo.out", "done"); |
| 96 buildShouldSucceed(); |
| 97 }); |
| 98 |
| 99 test("doesn't block on on getting an undeclared asset that wasn't generated " |
| 100 "last run", () { |
| 101 var transformer = new DeclaringCheckContentAndRenameTransformer( |
| 102 oldExtension: "txt", oldContent: "yes", |
| 103 newExtension: "out", newContent: "done"); |
| 104 initGraph({"app|foo.txt": "no"}, {"app": [[transformer]]}); |
| 105 |
| 106 updateSources(["app|foo.txt"]); |
| 107 expectNoAsset("app|foo.out"); |
| 108 buildShouldSucceed(); |
| 109 |
| 110 transformer.pauseApply(); |
| 111 modifyAsset("app|foo.txt", "yes"); |
| 112 updateSources(["app|foo.txt"]); |
| 113 expectNoAsset("app|undeclared.out"); |
| 114 |
| 115 transformer.resumeApply(); |
| 116 buildShouldSucceed(); |
| 117 }); |
| 118 |
| 119 test("fails to get a consumed asset before apply is finished when a sibling " |
| 120 "has finished applying", () { |
| 121 var transformer = new DeclaringRewriteTransformer("blub", "blab") |
| 122 ..consumePrimary = true; |
| 123 initGraph(["app|foo.blub", "app|foo.txt"], {"app": [[ |
| 124 transformer, |
| 125 new RewriteTransformer("txt", "out") |
| 126 ]]}); |
| 127 |
| 128 transformer.pauseApply(); |
| 129 updateSources(["app|foo.blub", "app|foo.txt"]); |
| 130 expectAsset("app|foo.out", "foo.out"); |
| 131 expectNoAsset("app|foo.blub"); |
| 132 |
| 133 transformer.resumeApply(); |
| 134 buildShouldSucceed(); |
| 135 }); |
| 136 |
| 137 test("blocks getting a consumed asset before apply is finished when a " |
| 138 "sibling hasn't finished applying", () { |
| 139 var declaring = new DeclaringRewriteTransformer("blub", "blab") |
| 140 ..consumePrimary = true; |
| 141 var eager = new RewriteTransformer("txt", "out"); |
| 142 initGraph(["app|foo.blub", "app|foo.txt"], {"app": [[declaring, eager]]}); |
| 143 |
| 144 declaring.pauseApply(); |
| 145 eager.pauseApply(); |
| 146 updateSources(["app|foo.blub", "app|foo.txt"]); |
| 147 expectAssetDoesNotComplete("app|foo.blub"); |
| 148 |
| 149 declaring.resumeApply(); |
| 150 eager.resumeApply(); |
| 151 expectNoAsset("app|foo.blub"); |
| 152 buildShouldSucceed(); |
| 153 }); |
| 154 |
| 155 test("waits until apply is finished to get an overwritten asset", () { |
| 156 var transformer = new DeclaringRewriteTransformer("blub", "blub"); |
| 157 initGraph(["app|foo.blub"], {"app": [[transformer]]}); |
| 158 |
| 159 transformer.pauseApply(); |
| 160 updateSources(["app|foo.blub"]); |
| 161 expectAssetDoesNotComplete("app|foo.blub"); |
| 162 |
| 163 transformer.resumeApply(); |
| 164 expectAsset("app|foo.blub", "foo.blub"); |
| 165 buildShouldSucceed(); |
| 166 }); |
| 167 |
| 168 // Regression test for #64. |
| 169 test("a declaring transformer's output passes through a lazy transformer", |
| 170 () { |
| 171 var declaring = new DeclaringRewriteTransformer("one", "two"); |
| 172 initGraph(["app|foo.one"], {"app": [ |
| 173 [declaring], |
| 174 [new LazyRewriteTransformer("two", "three")] |
| 175 ]}); |
| 176 |
| 177 updateSources(["app|foo.one"]); |
| 178 // Give the transformers time to declare their assets. |
| 179 schedule(pumpEventQueue); |
| 180 |
| 181 expectAsset("app|foo.one", "foo"); |
| 182 expectAsset("app|foo.two", "foo.two"); |
| 183 expectAsset("app|foo.three", "foo.two.three"); |
| 184 buildShouldSucceed(); |
| 185 |
| 186 modifyAsset("app|foo.one", "bar"); |
| 187 updateSources(["app|foo.one"]); |
| 188 |
| 189 expectAsset("app|foo.one", "bar"); |
| 190 expectAsset("app|foo.two", "bar.two"); |
| 191 expectAsset("app|foo.three", "bar.two.three"); |
| 192 buildShouldSucceed(); |
| 193 |
| 194 expect(declaring.numRuns, completion(equals(2))); |
| 195 }); |
| 196 |
| 197 test("a declaring transformer following a lazy transformer runs eagerly once " |
| 198 "its input is available", () { |
| 199 var declaring = new DeclaringRewriteTransformer("two", "three"); |
| 200 initGraph(["app|foo.in"], {"app": [ |
| 201 [new LazyAssetsTransformer(["app|out.one", "app|out.two"])], |
| 202 [declaring] |
| 203 ]}); |
| 204 |
| 205 updateSources(["app|foo.in"]); |
| 206 // Give the transformers time to declare their assets. |
| 207 schedule(pumpEventQueue); |
| 208 |
| 209 expectAsset("app|out.one", "app|out.one"); |
| 210 buildShouldSucceed(); |
| 211 |
| 212 expect(declaring.numRuns, completion(equals(1))); |
| 213 }); |
| 214 |
| 215 test("a declaring transformer following a lazy transformer doesn't re-run if " |
| 216 "its input becomes available and then unavailable", () { |
| 217 var declaring = new DeclaringRewriteTransformer("two", "three"); |
| 218 initGraph(["app|foo.in"], {"app": [ |
| 219 [new LazyAssetsTransformer(["app|out.one", "app|out.two"])], |
| 220 [declaring] |
| 221 ]}); |
| 222 |
| 223 declaring.pauseApply(); |
| 224 updateSources(["app|foo.in"]); |
| 225 // Give the transformers time to declare their assets. |
| 226 schedule(pumpEventQueue); |
| 227 |
| 228 // Start [declaring] running, because its input became available. |
| 229 expectAsset("app|out.one", "app|out.one"); |
| 230 |
| 231 // Make sure we're blocking on [declaring.apply]. |
| 232 schedule(pumpEventQueue); |
| 233 |
| 234 // Now [declaring]'s input is dirty, so it shouldn't re-run without an |
| 235 // explicit request. |
| 236 updateSources(["app|foo.in"]); |
| 237 declaring.resumeApply(); |
| 238 buildShouldSucceed(); |
| 239 |
| 240 // [declaring] should only have run once, despite its input changing. After |
| 241 // the first run, it should be awaiting a force() call. |
| 242 expect(declaring.numRuns, completion(equals(1))); |
| 243 |
| 244 // Once we make a request, [declaring] should force the lazy transformer and |
| 245 // then run itself. |
| 246 expectAsset("app|out.three", "app|out.two.three"); |
| 247 buildShouldSucceed(); |
| 248 |
| 249 // Now [declaring] should have run twice. This ensures that it didn't use |
| 250 // its original output for some reason. |
| 251 expect(declaring.numRuns, completion(equals(2))); |
| 252 }); |
| 253 |
| 254 test("a declaring transformer following a lazy transformer does re-run if " |
| 255 "its input becomes available, it's forced, and then its input becomes " |
| 256 "unavailable", () { |
| 257 var declaring = new DeclaringRewriteTransformer("two", "three"); |
| 258 initGraph(["app|foo.in"], {"app": [ |
| 259 [new LazyAssetsTransformer(["app|out.one", "app|out.two"])], |
| 260 [declaring] |
| 261 ]}); |
| 262 |
| 263 declaring.pauseApply(); |
| 264 updateSources(["app|foo.in"]); |
| 265 |
| 266 // Give the transformers time to declare their assets. |
| 267 schedule(pumpEventQueue); |
| 268 |
| 269 // Start [declaring] running, because its input became available. |
| 270 expectAsset("app|out.one", "app|out.one"); |
| 271 |
| 272 // This shouldn't complete because [declaring.apply] is paused, but it |
| 273 // should force the transformer. |
| 274 expectAssetDoesNotComplete("app|out.three"); |
| 275 |
| 276 // Make sure we're blocking on [declaring.apply] |
| 277 schedule(pumpEventQueue); |
| 278 |
| 279 // Now [declaring]'s input is dirty, so it shouldn't re-run without an |
| 280 // explicit request. |
| 281 updateSources(["app|foo.in"]); |
| 282 declaring.resumeApply(); |
| 283 buildShouldSucceed(); |
| 284 |
| 285 // [declaring] should have run twice, once for its original input and once |
| 286 // after the input changed because it was forced. |
| 287 expect(declaring.numRuns, completion(equals(2))); |
| 288 }); |
| 289 |
| 290 group("with an error in declareOutputs", () { |
| 291 test("still runs apply", () { |
| 292 initGraph(["app|foo.txt"], {"app": [[ |
| 293 new DeclaringBadTransformer("app|out.txt", |
| 294 declareError: true, applyError: false) |
| 295 ]]}); |
| 296 |
| 297 updateSources(["app|foo.txt"]); |
| 298 expectAsset("app|out.txt", "bad out"); |
| 299 expectAsset("app|foo.txt", "foo"); |
| 300 buildShouldFail([isTransformerException(BadTransformer.ERROR)]); |
| 301 }); |
| 302 |
| 303 test("waits for apply to complete before passing through the input even if " |
| 304 "consumePrimary was called", () { |
| 305 var transformer = new DeclaringBadTransformer("app|out.txt", |
| 306 declareError: true, applyError: false)..consumePrimary = true; |
| 307 initGraph(["app|foo.txt"], {"app": [[transformer]]}); |
| 308 |
| 309 transformer.pauseApply(); |
| 310 updateSources(["app|foo.txt"]); |
| 311 expectAssetDoesNotComplete("app|out.txt"); |
| 312 expectAssetDoesNotComplete("app|foo.txt"); |
| 313 |
| 314 transformer.resumeApply(); |
| 315 expectAsset("app|out.txt", "bad out"); |
| 316 expectNoAsset("app|foo.txt"); |
| 317 buildShouldFail([isTransformerException(BadTransformer.ERROR)]); |
| 318 }); |
| 319 }); |
| 320 |
| 321 test("with an error in apply still passes through the input", () { |
| 322 initGraph(["app|foo.txt"], {"app": [[ |
| 323 new DeclaringBadTransformer("app|out.txt", |
| 324 declareError: false, applyError: true) |
| 325 ]]}); |
| 326 |
| 327 updateSources(["app|foo.txt"]); |
| 328 expectNoAsset("app|out.txt"); |
| 329 expectAsset("app|foo.txt", "foo"); |
| 330 buildShouldFail([isTransformerException(BadTransformer.ERROR)]); |
| 331 }); |
| 332 |
| 333 test("can emit outputs it didn't declare", () { |
| 334 initGraph(["app|foo.txt"], {"app": [ |
| 335 [new DeclareAssetsTransformer([], emitted: ["app|out.txt"])] |
| 336 ]}); |
| 337 |
| 338 updateSources(["app|foo.txt"]); |
| 339 // There's probably going to be some time when "out.txt" is unavailable, |
| 340 // since it was undeclared. |
| 341 schedule(pumpEventQueue); |
| 342 expectAsset("app|out.txt", "app|out.txt"); |
| 343 buildShouldSucceed(); |
| 344 }); |
| 345 |
| 346 test("can overwrite the primary input even if it declared that it wouldn't", |
| 347 () { |
| 348 var transformer = new DeclareAssetsTransformer( |
| 349 [], emitted: ["app|foo.txt"]); |
| 350 initGraph(["app|foo.txt"], {"app": [[transformer]]}); |
| 351 |
| 352 transformer.pauseApply(); |
| 353 updateSources(["app|foo.txt"]); |
| 354 expectAsset("app|foo.txt", "foo"); |
| 355 |
| 356 transformer.resumeApply(); |
| 357 schedule(pumpEventQueue); |
| 358 expectAsset("app|foo.txt", "app|foo.txt"); |
| 359 buildShouldSucceed(); |
| 360 }); |
| 361 |
| 362 test("can declare outputs it doesn't emit", () { |
| 363 initGraph(["app|foo.txt"], {"app": [ |
| 364 [new DeclareAssetsTransformer(["app|out.txt"], emitted: [])] |
| 365 ]}); |
| 366 |
| 367 updateSources(["app|foo.txt"]); |
| 368 expectNoAsset("app|out.txt"); |
| 369 buildShouldSucceed(); |
| 370 }); |
| 371 } |
OLD | NEW |