| OLD | NEW |
| 1 // Copyright (c) 2013, the Dart project authors. Please see the AUTHORS file | 1 // Copyright (c) 2013, the Dart project authors. Please see the AUTHORS file |
| 2 // for details. All rights reserved. Use of this source code is governed by a | 2 // for details. All rights reserved. Use of this source code is governed by a |
| 3 // BSD-style license that can be found in the LICENSE file. | 3 // BSD-style license that can be found in the LICENSE file. |
| 4 | 4 |
| 5 library barback.test.package_graph.transform_test; | 5 library barback.test.package_graph.transform_test; |
| 6 | 6 |
| 7 import 'dart:async'; | 7 import 'dart:async'; |
| 8 | 8 |
| 9 import 'package:barback/barback.dart'; | 9 import 'package:barback/barback.dart'; |
| 10 import 'package:barback/src/utils.dart'; | 10 import 'package:barback/src/utils.dart'; |
| (...skipping 77 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 88 }); | 88 }); |
| 89 | 89 |
| 90 test("only runs a transform once for all of its outputs", () { | 90 test("only runs a transform once for all of its outputs", () { |
| 91 var transformer = new RewriteTransformer("blub", "a b c"); | 91 var transformer = new RewriteTransformer("blub", "a b c"); |
| 92 initGraph(["app|foo.blub"], {"app": [[transformer]]}); | 92 initGraph(["app|foo.blub"], {"app": [[transformer]]}); |
| 93 updateSources(["app|foo.blub"]); | 93 updateSources(["app|foo.blub"]); |
| 94 expectAsset("app|foo.a", "foo.a"); | 94 expectAsset("app|foo.a", "foo.a"); |
| 95 expectAsset("app|foo.b", "foo.b"); | 95 expectAsset("app|foo.b", "foo.b"); |
| 96 expectAsset("app|foo.c", "foo.c"); | 96 expectAsset("app|foo.c", "foo.c"); |
| 97 buildShouldSucceed(); | 97 buildShouldSucceed(); |
| 98 schedule(() { | 98 expect(transformer.numRuns, completion(equals(1))); |
| 99 expect(transformer.numRuns, equals(1)); | |
| 100 }); | |
| 101 }); | 99 }); |
| 102 | 100 |
| 103 test("runs transforms in the same phase in parallel", () { | 101 test("runs transforms in the same phase in parallel", () { |
| 104 var transformerA = new RewriteTransformer("txt", "a"); | 102 var transformerA = new RewriteTransformer("txt", "a"); |
| 105 var transformerB = new RewriteTransformer("txt", "b"); | 103 var transformerB = new RewriteTransformer("txt", "b"); |
| 106 initGraph(["app|foo.txt"], {"app": [[transformerA, transformerB]]}); | 104 initGraph(["app|foo.txt"], {"app": [[transformerA, transformerB]]}); |
| 107 | 105 |
| 108 transformerA.pauseApply(); | 106 transformerA.pauseApply(); |
| 109 transformerB.pauseApply(); | 107 transformerB.pauseApply(); |
| 110 | 108 |
| 111 schedule(() { | 109 updateSources(["app|foo.txt"]); |
| 112 updateSources(["app|foo.txt"]); | |
| 113 | 110 |
| 114 // Wait for them both to start. | 111 transformerA.waitUntilStarted(); |
| 115 return Future.wait([transformerA.started, transformerB.started]); | 112 transformerB.waitUntilStarted(); |
| 116 }); | |
| 117 | 113 |
| 118 schedule(() { | 114 // They should both still be running. |
| 119 // They should both still be running. | 115 expect(transformerA.isRunning, completion(isTrue)); |
| 120 expect(transformerA.isRunning, isTrue); | 116 expect(transformerB.isRunning, completion(isTrue)); |
| 121 expect(transformerB.isRunning, isTrue); | |
| 122 | 117 |
| 123 transformerA.resumeApply(); | 118 transformerA.resumeApply(); |
| 124 transformerB.resumeApply(); | 119 transformerB.resumeApply(); |
| 125 }); | |
| 126 | 120 |
| 127 expectAsset("app|foo.a", "foo.a"); | 121 expectAsset("app|foo.a", "foo.a"); |
| 128 expectAsset("app|foo.b", "foo.b"); | 122 expectAsset("app|foo.b", "foo.b"); |
| 129 buildShouldSucceed(); | 123 buildShouldSucceed(); |
| 130 }); | 124 }); |
| 131 | 125 |
| 132 test("outputs are inaccessible once used", () { | 126 test("outputs are inaccessible once used", () { |
| 133 initGraph(["app|foo.a"], {"app": [ | 127 initGraph(["app|foo.a"], {"app": [ |
| 134 [new RewriteTransformer("a", "b")], | 128 [new RewriteTransformer("a", "b")], |
| 135 [new RewriteTransformer("a", "c")] | 129 [new RewriteTransformer("a", "c")] |
| 136 ]}); | 130 ]}); |
| 137 updateSources(["app|foo.a"]); | 131 updateSources(["app|foo.a"]); |
| 138 expectAsset("app|foo.b", "foo.b"); | 132 expectAsset("app|foo.b", "foo.b"); |
| 139 expectNoAsset("app|foo.a"); | 133 expectNoAsset("app|foo.a"); |
| 140 expectNoAsset("app|foo.c"); | 134 expectNoAsset("app|foo.c"); |
| 141 buildShouldSucceed(); | 135 buildShouldSucceed(); |
| 142 }); | 136 }); |
| 143 | 137 |
| 144 test("does not reapply transform when inputs are not modified", () { | 138 test("does not reapply transform when inputs are not modified", () { |
| 145 var transformer = new RewriteTransformer("blub", "blab"); | 139 var transformer = new RewriteTransformer("blub", "blab"); |
| 146 initGraph(["app|foo.blub"], {"app": [[transformer]]}); | 140 initGraph(["app|foo.blub"], {"app": [[transformer]]}); |
| 147 updateSources(["app|foo.blub"]); | 141 updateSources(["app|foo.blub"]); |
| 148 expectAsset("app|foo.blab", "foo.blab"); | 142 expectAsset("app|foo.blab", "foo.blab"); |
| 149 expectAsset("app|foo.blab", "foo.blab"); | 143 expectAsset("app|foo.blab", "foo.blab"); |
| 150 expectAsset("app|foo.blab", "foo.blab"); | 144 expectAsset("app|foo.blab", "foo.blab"); |
| 151 buildShouldSucceed(); | 145 buildShouldSucceed(); |
| 152 | 146 |
| 153 schedule(() { | 147 expect(transformer.numRuns, completion(equals(1))); |
| 154 expect(transformer.numRuns, equals(1)); | |
| 155 }); | |
| 156 }); | 148 }); |
| 157 | 149 |
| 158 test("reapplies a transform when its input is modified", () { | 150 test("reapplies a transform when its input is modified", () { |
| 159 var transformer = new RewriteTransformer("blub", "blab"); | 151 var transformer = new RewriteTransformer("blub", "blab"); |
| 160 initGraph(["app|foo.blub"], {"app": [[transformer]]}); | 152 initGraph(["app|foo.blub"], {"app": [[transformer]]}); |
| 161 | 153 |
| 162 schedule(() { | 154 updateSources(["app|foo.blub"]); |
| 163 updateSources(["app|foo.blub"]); | |
| 164 }); | |
| 165 | |
| 166 expectAsset("app|foo.blab", "foo.blab"); | 155 expectAsset("app|foo.blab", "foo.blab"); |
| 167 buildShouldSucceed(); | 156 buildShouldSucceed(); |
| 168 | 157 |
| 169 schedule(() { | 158 updateSources(["app|foo.blub"]); |
| 170 updateSources(["app|foo.blub"]); | |
| 171 }); | |
| 172 | |
| 173 expectAsset("app|foo.blab", "foo.blab"); | 159 expectAsset("app|foo.blab", "foo.blab"); |
| 174 buildShouldSucceed(); | 160 buildShouldSucceed(); |
| 175 | 161 |
| 176 schedule(() { | 162 updateSources(["app|foo.blub"]); |
| 177 updateSources(["app|foo.blub"]); | |
| 178 }); | |
| 179 | |
| 180 expectAsset("app|foo.blab", "foo.blab"); | 163 expectAsset("app|foo.blab", "foo.blab"); |
| 181 buildShouldSucceed(); | 164 buildShouldSucceed(); |
| 182 | 165 |
| 183 schedule(() { | 166 expect(transformer.numRuns, completion(equals(3))); |
| 184 expect(transformer.numRuns, equals(3)); | |
| 185 }); | |
| 186 }); | 167 }); |
| 187 | 168 |
| 188 test("does not reapply transform when a removed input is modified", () { | 169 test("does not reapply transform when a removed input is modified", () { |
| 189 var transformer = new ManyToOneTransformer("txt"); | 170 var transformer = new ManyToOneTransformer("txt"); |
| 190 initGraph({ | 171 initGraph({ |
| 191 "app|a.txt": "a.inc,b.inc", | 172 "app|a.txt": "a.inc,b.inc", |
| 192 "app|a.inc": "a", | 173 "app|a.inc": "a", |
| 193 "app|b.inc": "b" | 174 "app|b.inc": "b" |
| 194 }, {"app": [[transformer]]}); | 175 }, {"app": [[transformer]]}); |
| 195 | 176 |
| 196 updateSources(["app|a.txt", "app|a.inc", "app|b.inc"]); | 177 updateSources(["app|a.txt", "app|a.inc", "app|b.inc"]); |
| 197 | 178 |
| 198 expectAsset("app|a.out", "ab"); | 179 expectAsset("app|a.out", "ab"); |
| 199 buildShouldSucceed(); | 180 buildShouldSucceed(); |
| 200 | 181 |
| 201 // Remove the dependency on the non-primary input. | 182 // Remove the dependency on the non-primary input. |
| 202 modifyAsset("app|a.txt", "a.inc"); | 183 modifyAsset("app|a.txt", "a.inc"); |
| 203 schedule(() => updateSources(["app|a.txt"])); | 184 updateSources(["app|a.txt"]); |
| 204 | 185 |
| 205 // Process it again. | 186 // Process it again. |
| 206 expectAsset("app|a.out", "a"); | 187 expectAsset("app|a.out", "a"); |
| 207 buildShouldSucceed(); | 188 buildShouldSucceed(); |
| 208 | 189 |
| 209 // Now touch the removed input. It should not trigger another build. | 190 // Now touch the removed input. It should not trigger another build. |
| 210 schedule(() { | 191 updateSources(["app|b.inc"]); |
| 211 updateSources(["app|b.inc"]); | |
| 212 }); | |
| 213 | |
| 214 expectAsset("app|a.out", "a"); | 192 expectAsset("app|a.out", "a"); |
| 215 buildShouldSucceed(); | 193 buildShouldSucceed(); |
| 216 | 194 |
| 217 schedule(() { | 195 expect(transformer.numRuns, completion(equals(2))); |
| 218 expect(transformer.numRuns, equals(2)); | |
| 219 }); | |
| 220 }); | 196 }); |
| 221 | 197 |
| 222 test("allows a transform to generate multiple outputs", () { | 198 test("allows a transform to generate multiple outputs", () { |
| 223 initGraph({"app|foo.txt": "a.out,b.out"}, {"app": [ | 199 initGraph({"app|foo.txt": "a.out,b.out"}, {"app": [ |
| 224 [new OneToManyTransformer("txt")] | 200 [new OneToManyTransformer("txt")] |
| 225 ]}); | 201 ]}); |
| 226 | 202 |
| 227 updateSources(["app|foo.txt"]); | 203 updateSources(["app|foo.txt"]); |
| 228 | 204 |
| 229 expectAsset("app|a.out", "spread txt"); | 205 expectAsset("app|a.out", "spread txt"); |
| (...skipping 11 matching lines...) Expand all Loading... |
| 241 [aa, bb], | 217 [aa, bb], |
| 242 ]}); | 218 ]}); |
| 243 | 219 |
| 244 updateSources(["app|foo.a"]); | 220 updateSources(["app|foo.a"]); |
| 245 updateSources(["app|foo.b"]); | 221 updateSources(["app|foo.b"]); |
| 246 | 222 |
| 247 expectAsset("app|foo.aaa", "foo.aa.aaa"); | 223 expectAsset("app|foo.aaa", "foo.aa.aaa"); |
| 248 expectAsset("app|foo.bbb", "foo.bb.bbb"); | 224 expectAsset("app|foo.bbb", "foo.bb.bbb"); |
| 249 buildShouldSucceed(); | 225 buildShouldSucceed(); |
| 250 | 226 |
| 251 schedule(() { | 227 updateSources(["app|foo.a"]); |
| 252 updateSources(["app|foo.a"]); | |
| 253 }); | |
| 254 | |
| 255 expectAsset("app|foo.aaa", "foo.aa.aaa"); | 228 expectAsset("app|foo.aaa", "foo.aa.aaa"); |
| 256 expectAsset("app|foo.bbb", "foo.bb.bbb"); | 229 expectAsset("app|foo.bbb", "foo.bb.bbb"); |
| 257 buildShouldSucceed(); | 230 buildShouldSucceed(); |
| 258 | 231 |
| 259 schedule(() { | 232 expect(aa.numRuns, completion(equals(2))); |
| 260 expect(aa.numRuns, equals(2)); | 233 expect(bb.numRuns, completion(equals(1))); |
| 261 expect(bb.numRuns, equals(1)); | |
| 262 }); | |
| 263 }); | 234 }); |
| 264 | 235 |
| 265 test("doesn't get an output from a transform whose primary input is removed", | 236 test("doesn't get an output from a transform whose primary input is removed", |
| 266 () { | 237 () { |
| 267 initGraph(["app|foo.txt"], {"app": [ | 238 initGraph(["app|foo.txt"], {"app": [ |
| 268 [new RewriteTransformer("txt", "out")] | 239 [new RewriteTransformer("txt", "out")] |
| 269 ]}); | 240 ]}); |
| 270 | 241 |
| 271 updateSources(["app|foo.txt"]); | 242 updateSources(["app|foo.txt"]); |
| 272 expectAsset("app|foo.out", "foo.out"); | 243 expectAsset("app|foo.out", "foo.out"); |
| 273 buildShouldSucceed(); | 244 buildShouldSucceed(); |
| 274 | 245 |
| 275 schedule(() { | 246 removeSources(["app|foo.txt"]); |
| 276 removeSources(["app|foo.txt"]); | |
| 277 }); | |
| 278 | |
| 279 expectNoAsset("app|foo.out"); | 247 expectNoAsset("app|foo.out"); |
| 280 buildShouldSucceed(); | 248 buildShouldSucceed(); |
| 281 }); | 249 }); |
| 282 | 250 |
| 283 test("discards outputs from a transform whose primary input is removed " | 251 test("discards outputs from a transform whose primary input is removed " |
| 284 "during processing", () { | 252 "during processing", () { |
| 285 var rewrite = new RewriteTransformer("txt", "out"); | 253 var rewrite = new RewriteTransformer("txt", "out"); |
| 286 initGraph(["app|foo.txt"], {"app": [[rewrite]]}); | 254 initGraph(["app|foo.txt"], {"app": [[rewrite]]}); |
| 287 | 255 |
| 288 rewrite.pauseApply(); | 256 rewrite.pauseApply(); |
| 289 updateSources(["app|foo.txt"]); | 257 updateSources(["app|foo.txt"]); |
| 290 schedule(() => rewrite.started); | 258 rewrite.waitUntilStarted(); |
| 291 schedule(() { | |
| 292 removeSources(["app|foo.txt"]); | |
| 293 rewrite.resumeApply(); | |
| 294 }); | |
| 295 | 259 |
| 260 removeSources(["app|foo.txt"]); |
| 261 rewrite.resumeApply(); |
| 296 expectNoAsset("app|foo.out"); | 262 expectNoAsset("app|foo.out"); |
| 297 buildShouldSucceed(); | 263 buildShouldSucceed(); |
| 298 }); | 264 }); |
| 299 | 265 |
| 300 test("reapplies a transform when a non-primary input changes", () { | 266 test("reapplies a transform when a non-primary input changes", () { |
| 301 initGraph({ | 267 initGraph({ |
| 302 "app|a.txt": "a.inc", | 268 "app|a.txt": "a.inc", |
| 303 "app|a.inc": "a" | 269 "app|a.inc": "a" |
| 304 }, {"app": [[new ManyToOneTransformer("txt")]]}); | 270 }, {"app": [[new ManyToOneTransformer("txt")]]}); |
| 305 | 271 |
| 306 updateSources(["app|a.txt", "app|a.inc"]); | 272 updateSources(["app|a.txt", "app|a.inc"]); |
| 307 expectAsset("app|a.out", "a"); | 273 expectAsset("app|a.out", "a"); |
| 308 buildShouldSucceed(); | 274 buildShouldSucceed(); |
| 309 | 275 |
| 310 modifyAsset("app|a.inc", "after"); | 276 modifyAsset("app|a.inc", "after"); |
| 311 schedule(() => updateSources(["app|a.inc"])); | 277 updateSources(["app|a.inc"]); |
| 312 | 278 |
| 313 expectAsset("app|a.out", "after"); | 279 expectAsset("app|a.out", "after"); |
| 314 buildShouldSucceed(); | 280 buildShouldSucceed(); |
| 315 }); | 281 }); |
| 316 | 282 |
| 317 test("applies a transform when it becomes newly primary", () { | 283 test("applies a transform when it becomes newly primary", () { |
| 318 initGraph({ | 284 initGraph({ |
| 319 "app|foo.txt": "this", | 285 "app|foo.txt": "this", |
| 320 }, {"app": [[new CheckContentTransformer("that", " and the other")]]}); | 286 }, {"app": [[new CheckContentTransformer("that", " and the other")]]}); |
| 321 | 287 |
| 322 updateSources(["app|foo.txt"]); | 288 updateSources(["app|foo.txt"]); |
| 323 expectAsset("app|foo.txt", "this"); | 289 expectAsset("app|foo.txt", "this"); |
| 324 buildShouldSucceed(); | 290 buildShouldSucceed(); |
| 325 | 291 |
| 326 modifyAsset("app|foo.txt", "that"); | 292 modifyAsset("app|foo.txt", "that"); |
| 327 schedule(() => updateSources(["app|foo.txt"])); | 293 updateSources(["app|foo.txt"]); |
| 328 | 294 |
| 329 expectAsset("app|foo.txt", "that and the other"); | 295 expectAsset("app|foo.txt", "that and the other"); |
| 330 buildShouldSucceed(); | 296 buildShouldSucceed(); |
| 331 }); | 297 }); |
| 332 | 298 |
| 333 test("applies the correct transform if an asset is modified during isPrimary", | 299 test("applies the correct transform if an asset is modified during isPrimary", |
| 334 () { | 300 () { |
| 335 var check1 = new CheckContentTransformer("first", "#1"); | 301 var check1 = new CheckContentTransformer("first", "#1"); |
| 336 var check2 = new CheckContentTransformer("second", "#2"); | 302 var check2 = new CheckContentTransformer("second", "#2"); |
| 337 initGraph({ | 303 initGraph({ |
| 338 "app|foo.txt": "first", | 304 "app|foo.txt": "first", |
| 339 }, {"app": [[check1, check2]]}); | 305 }, {"app": [[check1, check2]]}); |
| 340 | 306 |
| 341 check1.pauseIsPrimary("app|foo.txt"); | 307 check1.pauseIsPrimary("app|foo.txt"); |
| 342 updateSources(["app|foo.txt"]); | 308 updateSources(["app|foo.txt"]); |
| 343 // Ensure that we're waiting on check1's isPrimary. | 309 // Ensure that we're waiting on check1's isPrimary. |
| 344 schedule(pumpEventQueue); | 310 schedule(pumpEventQueue); |
| 345 | 311 |
| 346 modifyAsset("app|foo.txt", "second"); | 312 modifyAsset("app|foo.txt", "second"); |
| 347 schedule(() { | 313 updateSources(["app|foo.txt"]); |
| 348 updateSources(["app|foo.txt"]); | 314 check1.resumeIsPrimary("app|foo.txt"); |
| 349 check1.resumeIsPrimary("app|foo.txt"); | |
| 350 }); | |
| 351 | 315 |
| 352 expectAsset("app|foo.txt", "second#2"); | 316 expectAsset("app|foo.txt", "second#2"); |
| 353 buildShouldSucceed(); | 317 buildShouldSucceed(); |
| 354 }); | 318 }); |
| 355 | 319 |
| 356 test("applies the correct transform if an asset is removed and added during " | 320 test("applies the correct transform if an asset is removed and added during " |
| 357 "isPrimary", () { | 321 "isPrimary", () { |
| 358 var check1 = new CheckContentTransformer("first", "#1"); | 322 var check1 = new CheckContentTransformer("first", "#1"); |
| 359 var check2 = new CheckContentTransformer("second", "#2"); | 323 var check2 = new CheckContentTransformer("second", "#2"); |
| 360 initGraph({ | 324 initGraph({ |
| 361 "app|foo.txt": "first", | 325 "app|foo.txt": "first", |
| 362 }, {"app": [[check1, check2]]}); | 326 }, {"app": [[check1, check2]]}); |
| 363 | 327 |
| 364 check1.pauseIsPrimary("app|foo.txt"); | 328 check1.pauseIsPrimary("app|foo.txt"); |
| 365 updateSources(["app|foo.txt"]); | 329 updateSources(["app|foo.txt"]); |
| 366 // Ensure that we're waiting on check1's isPrimary. | 330 // Ensure that we're waiting on check1's isPrimary. |
| 367 schedule(pumpEventQueue); | 331 schedule(pumpEventQueue); |
| 368 | 332 |
| 369 schedule(() => removeSources(["app|foo.txt"])); | 333 removeSources(["app|foo.txt"]); |
| 370 modifyAsset("app|foo.txt", "second"); | 334 modifyAsset("app|foo.txt", "second"); |
| 371 schedule(() { | 335 updateSources(["app|foo.txt"]); |
| 372 updateSources(["app|foo.txt"]); | 336 check1.resumeIsPrimary("app|foo.txt"); |
| 373 check1.resumeIsPrimary("app|foo.txt"); | |
| 374 }); | |
| 375 | 337 |
| 376 expectAsset("app|foo.txt", "second#2"); | 338 expectAsset("app|foo.txt", "second#2"); |
| 377 buildShouldSucceed(); | 339 buildShouldSucceed(); |
| 378 }); | 340 }); |
| 379 | 341 |
| 380 test("restarts processing if a change occurs during processing", () { | 342 test("restarts processing if a change occurs during processing", () { |
| 381 var transformer = new RewriteTransformer("txt", "out"); | 343 var transformer = new RewriteTransformer("txt", "out"); |
| 382 initGraph(["app|foo.txt"], {"app": [[transformer]]}); | 344 initGraph(["app|foo.txt"], {"app": [[transformer]]}); |
| 383 | 345 |
| 384 transformer.pauseApply(); | 346 transformer.pauseApply(); |
| 385 | 347 |
| 386 schedule(() { | 348 updateSources(["app|foo.txt"]); |
| 387 updateSources(["app|foo.txt"]); | 349 transformer.waitUntilStarted(); |
| 388 | 350 |
| 389 // Wait for the transform to start. | 351 // Now update the graph during it. |
| 390 return transformer.started; | 352 updateSources(["app|foo.txt"]); |
| 391 }); | 353 transformer.resumeApply(); |
| 392 | |
| 393 schedule(() { | |
| 394 // Now update the graph during it. | |
| 395 updateSources(["app|foo.txt"]); | |
| 396 transformer.resumeApply(); | |
| 397 }); | |
| 398 | 354 |
| 399 expectAsset("app|foo.out", "foo.out"); | 355 expectAsset("app|foo.out", "foo.out"); |
| 400 buildShouldSucceed(); | 356 buildShouldSucceed(); |
| 401 | 357 |
| 402 schedule(() { | 358 expect(transformer.numRuns, completion(equals(2))); |
| 403 expect(transformer.numRuns, equals(2)); | |
| 404 }); | |
| 405 }); | 359 }); |
| 406 | 360 |
| 407 test("aborts processing if the primary input is removed during processing", | 361 test("aborts processing if the primary input is removed during processing", |
| 408 () { | 362 () { |
| 409 var transformer = new RewriteTransformer("txt", "out"); | 363 var transformer = new RewriteTransformer("txt", "out"); |
| 410 initGraph(["app|foo.txt"], {"app": [[transformer]]}); | 364 initGraph(["app|foo.txt"], {"app": [[transformer]]}); |
| 411 | 365 |
| 412 transformer.pauseApply(); | 366 transformer.pauseApply(); |
| 413 | 367 |
| 414 schedule(() { | 368 updateSources(["app|foo.txt"]); |
| 415 updateSources(["app|foo.txt"]); | 369 transformer.waitUntilStarted(); |
| 416 | 370 |
| 417 // Wait for the transform to start. | 371 // Now remove its primary input while it's running. |
| 418 return transformer.started; | 372 removeSources(["app|foo.txt"]); |
| 419 }); | 373 transformer.resumeApply(); |
| 420 | |
| 421 schedule(() { | |
| 422 // Now remove its primary input while it's running. | |
| 423 removeSources(["app|foo.txt"]); | |
| 424 transformer.resumeApply(); | |
| 425 }); | |
| 426 | 374 |
| 427 expectNoAsset("app|foo.out"); | 375 expectNoAsset("app|foo.out"); |
| 428 buildShouldSucceed(); | 376 buildShouldSucceed(); |
| 429 | 377 |
| 430 schedule(() { | 378 expect(transformer.numRuns, completion(equals(1))); |
| 431 expect(transformer.numRuns, equals(1)); | |
| 432 }); | |
| 433 }); | 379 }); |
| 434 | 380 |
| 435 test("restarts processing if a change to a new secondary input occurs during " | 381 test("restarts processing if a change to a new secondary input occurs during " |
| 436 "processing", () { | 382 "processing", () { |
| 437 var transformer = new ManyToOneTransformer("txt"); | 383 var transformer = new ManyToOneTransformer("txt"); |
| 438 initGraph({ | 384 initGraph({ |
| 439 "app|foo.txt": "bar.inc", | 385 "app|foo.txt": "bar.inc", |
| 440 "app|bar.inc": "bar" | 386 "app|bar.inc": "bar" |
| 441 }, {"app": [[transformer]]}); | 387 }, {"app": [[transformer]]}); |
| 442 | 388 |
| 443 transformer.pauseApply(); | 389 transformer.pauseApply(); |
| 444 | 390 |
| 445 updateSources(["app|foo.txt", "app|bar.inc"]); | 391 updateSources(["app|foo.txt", "app|bar.inc"]); |
| 446 // Wait for the transform to start. | 392 transformer.waitUntilStarted(); |
| 447 schedule(() => transformer.started); | |
| 448 | 393 |
| 449 // Give the transform time to load bar.inc the first time. | 394 // Give the transform time to load bar.inc the first time. |
| 450 schedule(pumpEventQueue); | 395 schedule(pumpEventQueue); |
| 451 | 396 |
| 452 // Now update the secondary input before the transform finishes. | 397 // Now update the secondary input before the transform finishes. |
| 453 modifyAsset("app|bar.inc", "baz"); | 398 modifyAsset("app|bar.inc", "baz"); |
| 454 schedule(() => updateSources(["app|bar.inc"])); | 399 updateSources(["app|bar.inc"]); |
| 455 // Give bar.inc enough time to be loaded and marked available before the | 400 // Give bar.inc enough time to be loaded and marked available before the |
| 456 // transformer completes. | 401 // transformer completes. |
| 457 schedule(pumpEventQueue); | 402 schedule(pumpEventQueue); |
| 458 | 403 |
| 459 schedule(transformer.resumeApply); | 404 transformer.resumeApply(); |
| 460 | 405 |
| 461 expectAsset("app|foo.out", "baz"); | 406 expectAsset("app|foo.out", "baz"); |
| 462 buildShouldSucceed(); | 407 buildShouldSucceed(); |
| 463 | 408 |
| 464 schedule(() { | 409 expect(transformer.numRuns, completion(equals(2))); |
| 465 expect(transformer.numRuns, equals(2)); | |
| 466 }); | |
| 467 }); | 410 }); |
| 468 | 411 |
| 469 test("doesn't restart processing if a change to an old secondary input " | 412 test("doesn't restart processing if a change to an old secondary input " |
| 470 "occurs during processing", () { | 413 "occurs during processing", () { |
| 471 var transformer = new ManyToOneTransformer("txt"); | 414 var transformer = new ManyToOneTransformer("txt"); |
| 472 initGraph({ | 415 initGraph({ |
| 473 "app|foo.txt": "bar.inc", | 416 "app|foo.txt": "bar.inc", |
| 474 "app|bar.inc": "bar", | 417 "app|bar.inc": "bar", |
| 475 "app|baz.inc": "baz" | 418 "app|baz.inc": "baz" |
| 476 }, {"app": [[transformer]]}); | 419 }, {"app": [[transformer]]}); |
| 477 | 420 |
| 478 updateSources(["app|foo.txt", "app|bar.inc", "app|baz.inc"]); | 421 updateSources(["app|foo.txt", "app|bar.inc", "app|baz.inc"]); |
| 479 expectAsset("app|foo.out", "bar"); | 422 expectAsset("app|foo.out", "bar"); |
| 480 buildShouldSucceed(); | 423 buildShouldSucceed(); |
| 481 | 424 |
| 482 schedule(transformer.pauseApply); | 425 transformer.pauseApply(); |
| 483 modifyAsset("app|foo.txt", "baz.inc"); | 426 modifyAsset("app|foo.txt", "baz.inc"); |
| 484 schedule(() { | 427 updateSources(["app|foo.txt"]); |
| 485 updateSources(["app|foo.txt"]); | 428 transformer.waitUntilStarted(); |
| 486 // Wait for the transform to start. | |
| 487 return transformer.started; | |
| 488 }); | |
| 489 | 429 |
| 490 // Now update the old secondary input before the transform finishes. | 430 // Now update the old secondary input before the transform finishes. |
| 491 modifyAsset("app|bar.inc", "new bar"); | 431 modifyAsset("app|bar.inc", "new bar"); |
| 492 schedule(() => updateSources(["app|bar.inc"])); | 432 updateSources(["app|bar.inc"]); |
| 493 // Give bar.inc enough time to be loaded and marked available before the | 433 // Give bar.inc enough time to be loaded and marked available before the |
| 494 // transformer completes. | 434 // transformer completes. |
| 495 schedule(pumpEventQueue); | 435 schedule(pumpEventQueue); |
| 496 | 436 |
| 497 schedule(transformer.resumeApply); | 437 transformer.resumeApply(); |
| 498 | |
| 499 expectAsset("app|foo.out", "baz"); | 438 expectAsset("app|foo.out", "baz"); |
| 500 buildShouldSucceed(); | 439 buildShouldSucceed(); |
| 501 | 440 |
| 502 schedule(() { | 441 // Should have run once the first time, then again when switching to |
| 503 // Should have run once the first time, then again when switching to | 442 // baz.inc. Should not run a third time because of bar.inc being modified. |
| 504 // baz.inc. Should not run a third time because of bar.inc being modified. | 443 expect(transformer.numRuns, completion(equals(2))); |
| 505 expect(transformer.numRuns, equals(2)); | |
| 506 }); | |
| 507 }); | 444 }); |
| 508 | 445 |
| 509 test("handles an output moving from one transformer to another", () { | 446 test("handles an output moving from one transformer to another", () { |
| 510 // In the first run, "shared.out" is created by the "a.a" transformer. | 447 // In the first run, "shared.out" is created by the "a.a" transformer. |
| 511 initGraph({ | 448 initGraph({ |
| 512 "app|a.a": "a.out,shared.out", | 449 "app|a.a": "a.out,shared.out", |
| 513 "app|b.b": "b.out" | 450 "app|b.b": "b.out" |
| 514 }, {"app": [ | 451 }, {"app": [ |
| 515 [new OneToManyTransformer("a"), new OneToManyTransformer("b")] | 452 [new OneToManyTransformer("a"), new OneToManyTransformer("b")] |
| 516 ]}); | 453 ]}); |
| 517 | 454 |
| 518 updateSources(["app|a.a", "app|b.b"]); | 455 updateSources(["app|a.a", "app|b.b"]); |
| 519 | 456 |
| 520 expectAsset("app|a.out", "spread a"); | 457 expectAsset("app|a.out", "spread a"); |
| 521 expectAsset("app|b.out", "spread b"); | 458 expectAsset("app|b.out", "spread b"); |
| 522 expectAsset("app|shared.out", "spread a"); | 459 expectAsset("app|shared.out", "spread a"); |
| 523 buildShouldSucceed(); | 460 buildShouldSucceed(); |
| 524 | 461 |
| 525 // Now switch their contents so that "shared.out" will be output by "b.b"'s | 462 // Now switch their contents so that "shared.out" will be output by "b.b"'s |
| 526 // transformer. | 463 // transformer. |
| 527 modifyAsset("app|a.a", "a.out"); | 464 modifyAsset("app|a.a", "a.out"); |
| 528 modifyAsset("app|b.b", "b.out,shared.out"); | 465 modifyAsset("app|b.b", "b.out,shared.out"); |
| 529 schedule(() => updateSources(["app|a.a", "app|b.b"])); | 466 updateSources(["app|a.a", "app|b.b"]); |
| 530 | 467 |
| 531 expectAsset("app|a.out", "spread a"); | 468 expectAsset("app|a.out", "spread a"); |
| 532 expectAsset("app|b.out", "spread b"); | 469 expectAsset("app|b.out", "spread b"); |
| 533 expectAsset("app|shared.out", "spread b"); | 470 expectAsset("app|shared.out", "spread b"); |
| 534 buildShouldSucceed(); | 471 buildShouldSucceed(); |
| 535 }); | 472 }); |
| 536 | 473 |
| 537 test("restarts before finishing later phases when a change occurs", () { | 474 test("restarts before finishing later phases when a change occurs", () { |
| 538 var txtToInt = new RewriteTransformer("txt", "int"); | 475 var txtToInt = new RewriteTransformer("txt", "int"); |
| 539 var intToOut = new RewriteTransformer("int", "out"); | 476 var intToOut = new RewriteTransformer("int", "out"); |
| 540 initGraph(["app|foo.txt", "app|bar.txt"], | 477 initGraph(["app|foo.txt", "app|bar.txt"], |
| 541 {"app": [[txtToInt], [intToOut]]}); | 478 {"app": [[txtToInt], [intToOut]]}); |
| 542 | 479 |
| 543 txtToInt.pauseApply(); | 480 txtToInt.pauseApply(); |
| 544 | 481 |
| 545 schedule(() { | 482 updateSources(["app|foo.txt"]); |
| 546 updateSources(["app|foo.txt"]); | 483 txtToInt.waitUntilStarted(); |
| 547 | 484 |
| 548 // Wait for the first transform to start. | 485 // Now update the graph during it. |
| 549 return txtToInt.started; | 486 updateSources(["app|bar.txt"]); |
| 550 }); | 487 txtToInt.resumeApply(); |
| 551 | |
| 552 schedule(() { | |
| 553 // Now update the graph during it. | |
| 554 updateSources(["app|bar.txt"]); | |
| 555 }); | |
| 556 | |
| 557 schedule(() { | |
| 558 txtToInt.resumeApply(); | |
| 559 }); | |
| 560 | 488 |
| 561 expectAsset("app|foo.out", "foo.int.out"); | 489 expectAsset("app|foo.out", "foo.int.out"); |
| 562 expectAsset("app|bar.out", "bar.int.out"); | 490 expectAsset("app|bar.out", "bar.int.out"); |
| 563 buildShouldSucceed(); | 491 buildShouldSucceed(); |
| 564 | 492 |
| 565 schedule(() { | 493 // Should only have run each transform once for each primary. |
| 566 // Should only have run each transform once for each primary. | 494 expect(txtToInt.numRuns, completion(equals(2))); |
| 567 expect(txtToInt.numRuns, equals(2)); | 495 expect(intToOut.numRuns, completion(equals(2))); |
| 568 expect(intToOut.numRuns, equals(2)); | |
| 569 }); | |
| 570 }); | 496 }); |
| 571 | 497 |
| 572 test("applies transforms to the correct packages", () { | 498 test("applies transforms to the correct packages", () { |
| 573 var rewrite1 = new RewriteTransformer("txt", "out1"); | 499 var rewrite1 = new RewriteTransformer("txt", "out1"); |
| 574 var rewrite2 = new RewriteTransformer("txt", "out2"); | 500 var rewrite2 = new RewriteTransformer("txt", "out2"); |
| 575 initGraph([ | 501 initGraph([ |
| 576 "pkg1|foo.txt", | 502 "pkg1|foo.txt", |
| 577 "pkg2|foo.txt" | 503 "pkg2|foo.txt" |
| 578 ], {"pkg1": [[rewrite1]], "pkg2": [[rewrite2]]}); | 504 ], {"pkg1": [[rewrite1]], "pkg2": [[rewrite2]]}); |
| 579 | 505 |
| (...skipping 19 matching lines...) Expand all Loading... |
| 599 [new RewriteTransformer("in", "mid")], | 525 [new RewriteTransformer("in", "mid")], |
| 600 [new RewriteTransformer("mid", "out")] | 526 [new RewriteTransformer("mid", "out")] |
| 601 ]}); | 527 ]}); |
| 602 | 528 |
| 603 updateSources(["app|foo.in"]); | 529 updateSources(["app|foo.in"]); |
| 604 expectAsset("app|foo.out", "foo.mid.out"); | 530 expectAsset("app|foo.out", "foo.mid.out"); |
| 605 buildShouldSucceed(); | 531 buildShouldSucceed(); |
| 606 | 532 |
| 607 pauseProvider(); | 533 pauseProvider(); |
| 608 modifyAsset("app|foo.in", "new"); | 534 modifyAsset("app|foo.in", "new"); |
| 609 schedule(() => updateSources(["app|foo.in"])); | 535 updateSources(["app|foo.in"]); |
| 610 expectAssetDoesNotComplete("app|foo.out"); | 536 expectAssetDoesNotComplete("app|foo.out"); |
| 611 buildShouldNotBeDone(); | 537 buildShouldNotBeDone(); |
| 612 | 538 |
| 613 resumeProvider(); | 539 resumeProvider(); |
| 614 expectAsset("app|foo.out", "new.mid.out"); | 540 expectAsset("app|foo.out", "new.mid.out"); |
| 615 buildShouldSucceed(); | 541 buildShouldSucceed(); |
| 616 }); | 542 }); |
| 617 | 543 |
| 618 test("doesn't return an asset until its in-place transform is done", () { | 544 test("doesn't return an asset until its in-place transform is done", () { |
| 619 var rewrite = new RewriteTransformer("txt", "txt"); | 545 var rewrite = new RewriteTransformer("txt", "txt"); |
| 620 initGraph(["app|foo.txt"], {"app": [[rewrite]]}); | 546 initGraph(["app|foo.txt"], {"app": [[rewrite]]}); |
| 621 | 547 |
| 622 rewrite.pauseApply(); | 548 rewrite.pauseApply(); |
| 623 updateSources(["app|foo.txt"]); | 549 updateSources(["app|foo.txt"]); |
| 624 expectAssetDoesNotComplete("app|foo.txt"); | 550 expectAssetDoesNotComplete("app|foo.txt"); |
| 625 | 551 |
| 626 schedule(rewrite.resumeApply); | 552 rewrite.resumeApply(); |
| 627 expectAsset("app|foo.txt", "foo.txt"); | 553 expectAsset("app|foo.txt", "foo.txt"); |
| 628 buildShouldSucceed(); | 554 buildShouldSucceed(); |
| 629 }); | 555 }); |
| 630 | 556 |
| 631 test("doesn't return an asset until we know it won't be transformed", | 557 test("doesn't return an asset until we know it won't be transformed", |
| 632 () { | 558 () { |
| 633 var rewrite = new RewriteTransformer("txt", "txt"); | 559 var rewrite = new RewriteTransformer("txt", "txt"); |
| 634 initGraph(["app|foo.a"], {"app": [[rewrite]]}); | 560 initGraph(["app|foo.a"], {"app": [[rewrite]]}); |
| 635 | 561 |
| 636 rewrite.pauseIsPrimary("app|foo.a"); | 562 rewrite.pauseIsPrimary("app|foo.a"); |
| 637 updateSources(["app|foo.a"]); | 563 updateSources(["app|foo.a"]); |
| 638 expectAssetDoesNotComplete("app|foo.a"); | 564 expectAssetDoesNotComplete("app|foo.a"); |
| 639 | 565 |
| 640 schedule(() => rewrite.resumeIsPrimary("app|foo.a")); | 566 rewrite.resumeIsPrimary("app|foo.a"); |
| 641 expectAsset("app|foo.a", "foo"); | 567 expectAsset("app|foo.a", "foo"); |
| 642 buildShouldSucceed(); | 568 buildShouldSucceed(); |
| 643 }); | 569 }); |
| 644 | 570 |
| 645 test("doesn't return a modified asset until we know it will still be " | 571 test("doesn't return a modified asset until we know it will still be " |
| 646 "transformed", () { | 572 "transformed", () { |
| 647 var rewrite = new RewriteTransformer("txt", "txt"); | 573 var rewrite = new RewriteTransformer("txt", "txt"); |
| 648 initGraph(["app|foo.txt"], {"app": [[rewrite]]}); | 574 initGraph(["app|foo.txt"], {"app": [[rewrite]]}); |
| 649 | 575 |
| 650 updateSources(["app|foo.txt"]); | 576 updateSources(["app|foo.txt"]); |
| 651 expectAsset("app|foo.txt", "foo.txt"); | 577 expectAsset("app|foo.txt", "foo.txt"); |
| 652 buildShouldSucceed(); | 578 buildShouldSucceed(); |
| 653 | 579 |
| 654 schedule(() => rewrite.pauseIsPrimary("app|foo.txt")); | 580 rewrite.pauseIsPrimary("app|foo.txt"); |
| 655 schedule(() => updateSources(["app|foo.txt"])); | 581 updateSources(["app|foo.txt"]); |
| 656 expectAssetDoesNotComplete("app|foo.txt"); | 582 expectAssetDoesNotComplete("app|foo.txt"); |
| 657 | 583 |
| 658 schedule(() => rewrite.resumeIsPrimary("app|foo.txt")); | 584 rewrite.resumeIsPrimary("app|foo.txt"); |
| 659 expectAsset("app|foo.txt", "foo.txt"); | 585 expectAsset("app|foo.txt", "foo.txt"); |
| 660 buildShouldSucceed(); | 586 buildShouldSucceed(); |
| 661 }); | 587 }); |
| 662 | 588 |
| 663 test("doesn't return an asset that's removed during isPrimary", () { | 589 test("doesn't return an asset that's removed during isPrimary", () { |
| 664 var rewrite = new RewriteTransformer("txt", "txt"); | 590 var rewrite = new RewriteTransformer("txt", "txt"); |
| 665 initGraph(["app|foo.txt"], {"app": [[rewrite]]}); | 591 initGraph(["app|foo.txt"], {"app": [[rewrite]]}); |
| 666 | 592 |
| 667 rewrite.pauseIsPrimary("app|foo.txt"); | 593 rewrite.pauseIsPrimary("app|foo.txt"); |
| 668 updateSources(["app|foo.txt"]); | 594 updateSources(["app|foo.txt"]); |
| 669 // Make sure we're waiting on isPrimary. | 595 // Make sure we're waiting on isPrimary. |
| 670 schedule(pumpEventQueue); | 596 schedule(pumpEventQueue); |
| 671 | 597 |
| 672 schedule(() { | 598 removeSources(["app|foo.txt"]); |
| 673 removeSources(["app|foo.txt"]); | 599 rewrite.resumeIsPrimary("app|foo.txt"); |
| 674 rewrite.resumeIsPrimary("app|foo.txt"); | |
| 675 }); | |
| 676 expectNoAsset("app|foo.txt"); | 600 expectNoAsset("app|foo.txt"); |
| 677 buildShouldSucceed(); | 601 buildShouldSucceed(); |
| 678 }); | 602 }); |
| 679 | 603 |
| 680 test("doesn't transform an asset that goes from primary to non-primary " | 604 test("doesn't transform an asset that goes from primary to non-primary " |
| 681 "during isPrimary", () { | 605 "during isPrimary", () { |
| 682 var check = new CheckContentTransformer("do", "ne"); | 606 var check = new CheckContentTransformer("do", "ne"); |
| 683 initGraph({ | 607 initGraph({ |
| 684 "app|foo.txt": "do" | 608 "app|foo.txt": "do" |
| 685 }, {"app": [[check]]}); | 609 }, {"app": [[check]]}); |
| 686 | 610 |
| 687 check.pauseIsPrimary("app|foo.txt"); | 611 check.pauseIsPrimary("app|foo.txt"); |
| 688 updateSources(["app|foo.txt"]); | 612 updateSources(["app|foo.txt"]); |
| 689 // Make sure we're waiting on isPrimary. | 613 // Make sure we're waiting on isPrimary. |
| 690 schedule(pumpEventQueue); | 614 schedule(pumpEventQueue); |
| 691 | 615 |
| 692 modifyAsset("app|foo.txt", "don't"); | 616 modifyAsset("app|foo.txt", "don't"); |
| 693 schedule(() { | 617 updateSources(["app|foo.txt"]); |
| 694 updateSources(["app|foo.txt"]); | 618 check.resumeIsPrimary("app|foo.txt"); |
| 695 check.resumeIsPrimary("app|foo.txt"); | |
| 696 }); | |
| 697 | 619 |
| 698 expectAsset("app|foo.txt", "don't"); | 620 expectAsset("app|foo.txt", "don't"); |
| 699 buildShouldSucceed(); | 621 buildShouldSucceed(); |
| 700 }); | 622 }); |
| 701 | 623 |
| 702 test("transforms an asset that goes from non-primary to primary " | 624 test("transforms an asset that goes from non-primary to primary " |
| 703 "during isPrimary", () { | 625 "during isPrimary", () { |
| 704 var check = new CheckContentTransformer("do", "ne"); | 626 var check = new CheckContentTransformer("do", "ne"); |
| 705 initGraph({ | 627 initGraph({ |
| 706 "app|foo.txt": "don't" | 628 "app|foo.txt": "don't" |
| 707 }, {"app": [[check]]}); | 629 }, {"app": [[check]]}); |
| 708 | 630 |
| 709 check.pauseIsPrimary("app|foo.txt"); | 631 check.pauseIsPrimary("app|foo.txt"); |
| 710 updateSources(["app|foo.txt"]); | 632 updateSources(["app|foo.txt"]); |
| 711 // Make sure we're waiting on isPrimary. | 633 // Make sure we're waiting on isPrimary. |
| 712 schedule(pumpEventQueue); | 634 schedule(pumpEventQueue); |
| 713 | 635 |
| 714 modifyAsset("app|foo.txt", "do"); | 636 modifyAsset("app|foo.txt", "do"); |
| 715 schedule(() { | 637 updateSources(["app|foo.txt"]); |
| 716 updateSources(["app|foo.txt"]); | 638 check.resumeIsPrimary("app|foo.txt"); |
| 717 check.resumeIsPrimary("app|foo.txt"); | |
| 718 }); | |
| 719 | 639 |
| 720 expectAsset("app|foo.txt", "done"); | 640 expectAsset("app|foo.txt", "done"); |
| 721 buildShouldSucceed(); | 641 buildShouldSucceed(); |
| 722 }); | 642 }); |
| 723 | 643 |
| 724 test("doesn't return an asset that's removed during another transformer's " | 644 test("doesn't return an asset that's removed during another transformer's " |
| 725 "isPrimary", () { | 645 "isPrimary", () { |
| 726 var rewrite1 = new RewriteTransformer("txt", "txt"); | 646 var rewrite1 = new RewriteTransformer("txt", "txt"); |
| 727 var rewrite2 = new RewriteTransformer("md", "md"); | 647 var rewrite2 = new RewriteTransformer("md", "md"); |
| 728 initGraph(["app|foo.txt", "app|foo.md"], {"app": [[rewrite1, rewrite2]]}); | 648 initGraph(["app|foo.txt", "app|foo.md"], {"app": [[rewrite1, rewrite2]]}); |
| 729 | 649 |
| 730 rewrite2.pauseIsPrimary("app|foo.md"); | 650 rewrite2.pauseIsPrimary("app|foo.md"); |
| 731 updateSources(["app|foo.txt", "app|foo.md"]); | 651 updateSources(["app|foo.txt", "app|foo.md"]); |
| 732 // Make sure we're waiting on the correct isPrimary. | 652 // Make sure we're waiting on the correct isPrimary. |
| 733 schedule(pumpEventQueue); | 653 schedule(pumpEventQueue); |
| 734 | 654 |
| 735 schedule(() { | 655 removeSources(["app|foo.txt"]); |
| 736 removeSources(["app|foo.txt"]); | 656 rewrite2.resumeIsPrimary("app|foo.md"); |
| 737 rewrite2.resumeIsPrimary("app|foo.md"); | |
| 738 }); | |
| 739 expectNoAsset("app|foo.txt"); | 657 expectNoAsset("app|foo.txt"); |
| 740 expectAsset("app|foo.md", "foo.md"); | 658 expectAsset("app|foo.md", "foo.md"); |
| 741 buildShouldSucceed(); | 659 buildShouldSucceed(); |
| 742 }); | 660 }); |
| 743 | 661 |
| 744 test("doesn't transform an asset that goes from primary to non-primary " | 662 test("doesn't transform an asset that goes from primary to non-primary " |
| 745 "during another transformer's isPrimary", () { | 663 "during another transformer's isPrimary", () { |
| 746 var rewrite = new RewriteTransformer("md", "md"); | 664 var rewrite = new RewriteTransformer("md", "md"); |
| 747 var check = new CheckContentTransformer("do", "ne"); | 665 var check = new CheckContentTransformer("do", "ne"); |
| 748 initGraph({ | 666 initGraph({ |
| 749 "app|foo.txt": "do", | 667 "app|foo.txt": "do", |
| 750 "app|foo.md": "foo" | 668 "app|foo.md": "foo" |
| 751 }, {"app": [[rewrite, check]]}); | 669 }, {"app": [[rewrite, check]]}); |
| 752 | 670 |
| 753 rewrite.pauseIsPrimary("app|foo.md"); | 671 rewrite.pauseIsPrimary("app|foo.md"); |
| 754 updateSources(["app|foo.txt", "app|foo.md"]); | 672 updateSources(["app|foo.txt", "app|foo.md"]); |
| 755 // Make sure we're waiting on the correct isPrimary. | 673 // Make sure we're waiting on the correct isPrimary. |
| 756 schedule(pumpEventQueue); | 674 schedule(pumpEventQueue); |
| 757 | 675 |
| 758 modifyAsset("app|foo.txt", "don't"); | 676 modifyAsset("app|foo.txt", "don't"); |
| 759 schedule(() { | 677 updateSources(["app|foo.txt"]); |
| 760 updateSources(["app|foo.txt"]); | 678 rewrite.resumeIsPrimary("app|foo.md"); |
| 761 rewrite.resumeIsPrimary("app|foo.md"); | |
| 762 }); | |
| 763 | 679 |
| 764 expectAsset("app|foo.txt", "don't"); | 680 expectAsset("app|foo.txt", "don't"); |
| 765 expectAsset("app|foo.md", "foo.md"); | 681 expectAsset("app|foo.md", "foo.md"); |
| 766 buildShouldSucceed(); | 682 buildShouldSucceed(); |
| 767 }); | 683 }); |
| 768 | 684 |
| 769 test("transforms an asset that goes from non-primary to primary " | 685 test("transforms an asset that goes from non-primary to primary " |
| 770 "during another transformer's isPrimary", () { | 686 "during another transformer's isPrimary", () { |
| 771 var rewrite = new RewriteTransformer("md", "md"); | 687 var rewrite = new RewriteTransformer("md", "md"); |
| 772 var check = new CheckContentTransformer("do", "ne"); | 688 var check = new CheckContentTransformer("do", "ne"); |
| 773 initGraph({ | 689 initGraph({ |
| 774 "app|foo.txt": "don't", | 690 "app|foo.txt": "don't", |
| 775 "app|foo.md": "foo" | 691 "app|foo.md": "foo" |
| 776 }, {"app": [[rewrite, check]]}); | 692 }, {"app": [[rewrite, check]]}); |
| 777 | 693 |
| 778 rewrite.pauseIsPrimary("app|foo.md"); | 694 rewrite.pauseIsPrimary("app|foo.md"); |
| 779 updateSources(["app|foo.txt", "app|foo.md"]); | 695 updateSources(["app|foo.txt", "app|foo.md"]); |
| 780 // Make sure we're waiting on the correct isPrimary. | 696 // Make sure we're waiting on the correct isPrimary. |
| 781 schedule(pumpEventQueue); | 697 schedule(pumpEventQueue); |
| 782 | 698 |
| 783 modifyAsset("app|foo.txt", "do"); | 699 modifyAsset("app|foo.txt", "do"); |
| 784 schedule(() { | 700 updateSources(["app|foo.txt"]); |
| 785 updateSources(["app|foo.txt"]); | 701 rewrite.resumeIsPrimary("app|foo.md"); |
| 786 rewrite.resumeIsPrimary("app|foo.md"); | |
| 787 }); | |
| 788 | 702 |
| 789 expectAsset("app|foo.txt", "done"); | 703 expectAsset("app|foo.txt", "done"); |
| 790 expectAsset("app|foo.md", "foo.md"); | 704 expectAsset("app|foo.md", "foo.md"); |
| 791 buildShouldSucceed(); | 705 buildShouldSucceed(); |
| 792 }); | 706 }); |
| 793 | 707 |
| 794 test("removes pipelined transforms when the root primary input is removed", | 708 test("removes pipelined transforms when the root primary input is removed", |
| 795 () { | 709 () { |
| 796 initGraph(["app|foo.txt"], {"app": [ | 710 initGraph(["app|foo.txt"], {"app": [ |
| 797 [new RewriteTransformer("txt", "mid")], | 711 [new RewriteTransformer("txt", "mid")], |
| 798 [new RewriteTransformer("mid", "out")] | 712 [new RewriteTransformer("mid", "out")] |
| 799 ]}); | 713 ]}); |
| 800 | 714 |
| 801 updateSources(["app|foo.txt"]); | 715 updateSources(["app|foo.txt"]); |
| 802 expectAsset("app|foo.out", "foo.mid.out"); | 716 expectAsset("app|foo.out", "foo.mid.out"); |
| 803 buildShouldSucceed(); | 717 buildShouldSucceed(); |
| 804 | 718 |
| 805 schedule(() => removeSources(["app|foo.txt"])); | 719 removeSources(["app|foo.txt"]); |
| 806 expectNoAsset("app|foo.out"); | 720 expectNoAsset("app|foo.out"); |
| 807 buildShouldSucceed(); | 721 buildShouldSucceed(); |
| 808 }); | 722 }); |
| 809 | 723 |
| 810 test("removes pipelined transforms when the parent ceases to generate the " | 724 test("removes pipelined transforms when the parent ceases to generate the " |
| 811 "primary input", () { | 725 "primary input", () { |
| 812 initGraph({"app|foo.txt": "foo.mid"}, {'app': [ | 726 initGraph({"app|foo.txt": "foo.mid"}, {'app': [ |
| 813 [new OneToManyTransformer('txt')], | 727 [new OneToManyTransformer('txt')], |
| 814 [new RewriteTransformer('mid', 'out')] | 728 [new RewriteTransformer('mid', 'out')] |
| 815 ]}); | 729 ]}); |
| 816 | 730 |
| 817 updateSources(['app|foo.txt']); | 731 updateSources(['app|foo.txt']); |
| 818 expectAsset('app|foo.out', 'spread txt.out'); | 732 expectAsset('app|foo.out', 'spread txt.out'); |
| 819 buildShouldSucceed(); | 733 buildShouldSucceed(); |
| 820 | 734 |
| 821 modifyAsset("app|foo.txt", "bar.mid"); | 735 modifyAsset("app|foo.txt", "bar.mid"); |
| 822 schedule(() => updateSources(["app|foo.txt"])); | 736 updateSources(["app|foo.txt"]); |
| 823 expectNoAsset('app|foo.out'); | 737 expectNoAsset('app|foo.out'); |
| 824 expectAsset('app|bar.out', 'spread txt.out'); | 738 expectAsset('app|bar.out', 'spread txt.out'); |
| 825 buildShouldSucceed(); | 739 buildShouldSucceed(); |
| 826 }); | 740 }); |
| 827 | 741 |
| 828 test("returns an asset even if an unrelated build is running", () { | 742 test("returns an asset even if an unrelated build is running", () { |
| 829 initGraph([ | 743 initGraph([ |
| 830 "app|foo.in", | 744 "app|foo.in", |
| 831 "app|bar.in", | 745 "app|bar.in", |
| 832 ], {"app": [[new RewriteTransformer("in", "out")]]}); | 746 ], {"app": [[new RewriteTransformer("in", "out")]]}); |
| 833 | 747 |
| 834 updateSources(["app|foo.in", "app|bar.in"]); | 748 updateSources(["app|foo.in", "app|bar.in"]); |
| 835 expectAsset("app|foo.out", "foo.out"); | 749 expectAsset("app|foo.out", "foo.out"); |
| 836 expectAsset("app|bar.out", "bar.out"); | 750 expectAsset("app|bar.out", "bar.out"); |
| 837 buildShouldSucceed(); | 751 buildShouldSucceed(); |
| 838 | 752 |
| 839 pauseProvider(); | 753 pauseProvider(); |
| 840 modifyAsset("app|foo.in", "new"); | 754 modifyAsset("app|foo.in", "new"); |
| 841 schedule(() => updateSources(["app|foo.in"])); | 755 updateSources(["app|foo.in"]); |
| 842 expectAssetDoesNotComplete("app|foo.out"); | 756 expectAssetDoesNotComplete("app|foo.out"); |
| 843 expectAsset("app|bar.out", "bar.out"); | 757 expectAsset("app|bar.out", "bar.out"); |
| 844 buildShouldNotBeDone(); | 758 buildShouldNotBeDone(); |
| 845 | 759 |
| 846 resumeProvider(); | 760 resumeProvider(); |
| 847 expectAsset("app|foo.out", "new.out"); | 761 expectAsset("app|foo.out", "new.out"); |
| 848 buildShouldSucceed(); | 762 buildShouldSucceed(); |
| 849 }); | 763 }); |
| 850 | 764 |
| 851 test("doesn't report AssetNotFound until all builds are finished", () { | 765 test("doesn't report AssetNotFound until all builds are finished", () { |
| 852 initGraph([ | 766 initGraph([ |
| 853 "app|foo.in", | 767 "app|foo.in", |
| 854 ], {"app": [[new RewriteTransformer("in", "out")]]}); | 768 ], {"app": [[new RewriteTransformer("in", "out")]]}); |
| 855 | 769 |
| 856 updateSources(["app|foo.in"]); | 770 updateSources(["app|foo.in"]); |
| 857 expectAsset("app|foo.out", "foo.out"); | 771 expectAsset("app|foo.out", "foo.out"); |
| 858 buildShouldSucceed(); | 772 buildShouldSucceed(); |
| 859 | 773 |
| 860 pauseProvider(); | 774 pauseProvider(); |
| 861 schedule(() => updateSources(["app|foo.in"])); | 775 updateSources(["app|foo.in"]); |
| 862 expectAssetDoesNotComplete("app|foo.out"); | 776 expectAssetDoesNotComplete("app|foo.out"); |
| 863 expectAssetDoesNotComplete("app|non-existent.out"); | 777 expectAssetDoesNotComplete("app|non-existent.out"); |
| 864 buildShouldNotBeDone(); | 778 buildShouldNotBeDone(); |
| 865 | 779 |
| 866 resumeProvider(); | 780 resumeProvider(); |
| 867 expectAsset("app|foo.out", "foo.out"); | 781 expectAsset("app|foo.out", "foo.out"); |
| 868 expectNoAsset("app|non-existent.out"); | 782 expectNoAsset("app|non-existent.out"); |
| 869 buildShouldSucceed(); | 783 buildShouldSucceed(); |
| 870 }); | 784 }); |
| 871 | 785 |
| 872 test("doesn't emit a result until all builds are finished", () { | 786 test("doesn't emit a result until all builds are finished", () { |
| 873 var rewrite = new RewriteTransformer("txt", "out"); | 787 var rewrite = new RewriteTransformer("txt", "out"); |
| 874 initGraph([ | 788 initGraph([ |
| 875 "pkg1|foo.txt", | 789 "pkg1|foo.txt", |
| 876 "pkg2|foo.txt" | 790 "pkg2|foo.txt" |
| 877 ], {"pkg1": [[rewrite]], "pkg2": [[rewrite]]}); | 791 ], {"pkg1": [[rewrite]], "pkg2": [[rewrite]]}); |
| 878 | 792 |
| 879 // First, run both packages' transformers so both packages are successful. | 793 // First, run both packages' transformers so both packages are successful. |
| 880 updateSources(["pkg1|foo.txt", "pkg2|foo.txt"]); | 794 updateSources(["pkg1|foo.txt", "pkg2|foo.txt"]); |
| 881 expectAsset("pkg1|foo.out", "foo.out"); | 795 expectAsset("pkg1|foo.out", "foo.out"); |
| 882 expectAsset("pkg2|foo.out", "foo.out"); | 796 expectAsset("pkg2|foo.out", "foo.out"); |
| 883 buildShouldSucceed(); | 797 buildShouldSucceed(); |
| 884 | 798 |
| 885 // pkg1 is still successful, but pkg2 is waiting on the provider, so the | 799 // pkg1 is still successful, but pkg2 is waiting on the provider, so the |
| 886 // overall build shouldn't finish. | 800 // overall build shouldn't finish. |
| 887 pauseProvider(); | 801 pauseProvider(); |
| 888 schedule(() => updateSources(["pkg2|foo.txt"])); | 802 updateSources(["pkg2|foo.txt"]); |
| 889 expectAsset("pkg1|foo.out", "foo.out"); | 803 expectAsset("pkg1|foo.out", "foo.out"); |
| 890 buildShouldNotBeDone(); | 804 buildShouldNotBeDone(); |
| 891 | 805 |
| 892 // Now that the provider is unpaused, pkg2's transforms finish and the | 806 // Now that the provider is unpaused, pkg2's transforms finish and the |
| 893 // overall build succeeds. | 807 // overall build succeeds. |
| 894 resumeProvider(); | 808 resumeProvider(); |
| 895 buildShouldSucceed(); | 809 buildShouldSucceed(); |
| 896 }); | 810 }); |
| 897 | 811 |
| 898 group('cross-package transforms', () { | 812 group('cross-package transforms', () { |
| (...skipping 28 matching lines...) Expand all Loading... |
| 927 "pkg2|a.inc": "a" | 841 "pkg2|a.inc": "a" |
| 928 }, { | 842 }, { |
| 929 "pkg1": [[new ManyToOneTransformer("txt")]] | 843 "pkg1": [[new ManyToOneTransformer("txt")]] |
| 930 }); | 844 }); |
| 931 | 845 |
| 932 updateSources(["pkg1|a.txt", "pkg2|a.inc"]); | 846 updateSources(["pkg1|a.txt", "pkg2|a.inc"]); |
| 933 expectAsset("pkg1|a.out", "a"); | 847 expectAsset("pkg1|a.out", "a"); |
| 934 buildShouldSucceed(); | 848 buildShouldSucceed(); |
| 935 | 849 |
| 936 modifyAsset("pkg2|a.inc", "new a"); | 850 modifyAsset("pkg2|a.inc", "new a"); |
| 937 schedule(() => updateSources(["pkg2|a.inc"])); | 851 updateSources(["pkg2|a.inc"]); |
| 938 expectAsset("pkg1|a.out", "new a"); | 852 expectAsset("pkg1|a.out", "new a"); |
| 939 buildShouldSucceed(); | 853 buildShouldSucceed(); |
| 940 }); | 854 }); |
| 941 | 855 |
| 942 test("re-runs a transform when a transformed input from another package " | 856 test("re-runs a transform when a transformed input from another package " |
| 943 "changes", () { | 857 "changes", () { |
| 944 initGraph({ | 858 initGraph({ |
| 945 "pkg1|a.txt": "pkg2|a.inc", | 859 "pkg1|a.txt": "pkg2|a.inc", |
| 946 "pkg2|a.txt": "a" | 860 "pkg2|a.txt": "a" |
| 947 }, { | 861 }, { |
| 948 "pkg1": [[new ManyToOneTransformer("txt")]], | 862 "pkg1": [[new ManyToOneTransformer("txt")]], |
| 949 "pkg2": [[new RewriteTransformer("txt", "inc")]] | 863 "pkg2": [[new RewriteTransformer("txt", "inc")]] |
| 950 }); | 864 }); |
| 951 | 865 |
| 952 updateSources(["pkg1|a.txt", "pkg2|a.txt"]); | 866 updateSources(["pkg1|a.txt", "pkg2|a.txt"]); |
| 953 expectAsset("pkg1|a.out", "a.inc"); | 867 expectAsset("pkg1|a.out", "a.inc"); |
| 954 buildShouldSucceed(); | 868 buildShouldSucceed(); |
| 955 | 869 |
| 956 modifyAsset("pkg2|a.txt", "new a"); | 870 modifyAsset("pkg2|a.txt", "new a"); |
| 957 schedule(() => updateSources(["pkg2|a.txt"])); | 871 updateSources(["pkg2|a.txt"]); |
| 958 expectAsset("pkg1|a.out", "new a.inc"); | 872 expectAsset("pkg1|a.out", "new a.inc"); |
| 959 buildShouldSucceed(); | 873 buildShouldSucceed(); |
| 960 }); | 874 }); |
| 961 | 875 |
| 962 test("runs a transform that's added because of a change in another package", | 876 test("runs a transform that's added because of a change in another package", |
| 963 () { | 877 () { |
| 964 initGraph({ | 878 initGraph({ |
| 965 "pkg1|a.txt": "pkg2|a.inc", | 879 "pkg1|a.txt": "pkg2|a.inc", |
| 966 "pkg2|a.inc": "b" | 880 "pkg2|a.inc": "b" |
| 967 }, { | 881 }, { |
| 968 "pkg1": [ | 882 "pkg1": [ |
| 969 [new ManyToOneTransformer("txt")], | 883 [new ManyToOneTransformer("txt")], |
| 970 [new OneToManyTransformer("out")], | 884 [new OneToManyTransformer("out")], |
| 971 [new RewriteTransformer("md", "done")] | 885 [new RewriteTransformer("md", "done")] |
| 972 ], | 886 ], |
| 973 }); | 887 }); |
| 974 | 888 |
| 975 // pkg1|a.txt generates outputs based on the contents of pkg2|a.inc. At | 889 // pkg1|a.txt generates outputs based on the contents of pkg2|a.inc. At |
| 976 // first pkg2|a.inc only includes "b", which is not transformed. Then | 890 // first pkg2|a.inc only includes "b", which is not transformed. Then |
| 977 // pkg2|a.inc is updated to include "b,c.md". pkg1|c.md triggers the | 891 // pkg2|a.inc is updated to include "b,c.md". pkg1|c.md triggers the |
| 978 // md->done rewrite transformer, producing pkg1|c.done. | 892 // md->done rewrite transformer, producing pkg1|c.done. |
| 979 | 893 |
| 980 updateSources(["pkg1|a.txt", "pkg2|a.inc"]); | 894 updateSources(["pkg1|a.txt", "pkg2|a.inc"]); |
| 981 expectAsset("pkg1|b", "spread out"); | 895 expectAsset("pkg1|b", "spread out"); |
| 982 buildShouldSucceed(); | 896 buildShouldSucceed(); |
| 983 | 897 |
| 984 modifyAsset("pkg2|a.inc", "b,c.md"); | 898 modifyAsset("pkg2|a.inc", "b,c.md"); |
| 985 schedule(() => updateSources(["pkg2|a.inc"])); | 899 updateSources(["pkg2|a.inc"]); |
| 986 expectAsset("pkg1|b", "spread out"); | 900 expectAsset("pkg1|b", "spread out"); |
| 987 expectAsset("pkg1|c.done", "spread out.done"); | 901 expectAsset("pkg1|c.done", "spread out.done"); |
| 988 buildShouldSucceed(); | 902 buildShouldSucceed(); |
| 989 }); | 903 }); |
| 990 | 904 |
| 991 test("doesn't run a transform that's removed because of a change in " | 905 test("doesn't run a transform that's removed because of a change in " |
| 992 "another package", () { | 906 "another package", () { |
| 993 initGraph({ | 907 initGraph({ |
| 994 "pkg1|a.txt": "pkg2|a.inc", | 908 "pkg1|a.txt": "pkg2|a.inc", |
| 995 "pkg2|a.inc": "b,c.md" | 909 "pkg2|a.inc": "b,c.md" |
| 996 }, { | 910 }, { |
| 997 "pkg1": [ | 911 "pkg1": [ |
| 998 [new ManyToOneTransformer("txt")], | 912 [new ManyToOneTransformer("txt")], |
| 999 [new OneToManyTransformer("out")], | 913 [new OneToManyTransformer("out")], |
| 1000 [new RewriteTransformer("md", "done")] | 914 [new RewriteTransformer("md", "done")] |
| 1001 ], | 915 ], |
| 1002 }); | 916 }); |
| 1003 | 917 |
| 1004 updateSources(["pkg1|a.txt", "pkg2|a.inc"]); | 918 updateSources(["pkg1|a.txt", "pkg2|a.inc"]); |
| 1005 expectAsset("pkg1|b", "spread out"); | 919 expectAsset("pkg1|b", "spread out"); |
| 1006 expectAsset("pkg1|c.done", "spread out.done"); | 920 expectAsset("pkg1|c.done", "spread out.done"); |
| 1007 buildShouldSucceed(); | 921 buildShouldSucceed(); |
| 1008 | 922 |
| 1009 modifyAsset("pkg2|a.inc", "b"); | 923 modifyAsset("pkg2|a.inc", "b"); |
| 1010 schedule(() => updateSources(["pkg2|a.inc"])); | 924 updateSources(["pkg2|a.inc"]); |
| 1011 expectAsset("pkg1|b", "spread out"); | 925 expectAsset("pkg1|b", "spread out"); |
| 1012 expectNoAsset("pkg1|c.done"); | 926 expectNoAsset("pkg1|c.done"); |
| 1013 buildShouldSucceed(); | 927 buildShouldSucceed(); |
| 1014 }); | 928 }); |
| 1015 }); | 929 }); |
| 1016 } | 930 } |
| OLD | NEW |