| 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:scheduled_test/scheduled_test.dart'; | 11 import 'package:scheduled_test/scheduled_test.dart'; |
| 11 | 12 |
| 12 import '../utils.dart'; | 13 import '../utils.dart'; |
| 13 | 14 |
| 14 main() { | 15 main() { |
| 15 initConfig(); | 16 initConfig(); |
| 16 test("gets a transformed asset with a different path", () { | 17 test("gets a transformed asset with a different path", () { |
| 17 initGraph(["app|foo.blub"], {"app": [ | 18 initGraph(["app|foo.blub"], {"app": [ |
| 18 [new RewriteTransformer("blub", "blab")] | 19 [new RewriteTransformer("blub", "blab")] |
| 19 ]}); | 20 ]}); |
| (...skipping 77 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 97 schedule(() { | 98 schedule(() { |
| 98 expect(transformer.numRuns, equals(1)); | 99 expect(transformer.numRuns, equals(1)); |
| 99 }); | 100 }); |
| 100 }); | 101 }); |
| 101 | 102 |
| 102 test("runs transforms in the same phase in parallel", () { | 103 test("runs transforms in the same phase in parallel", () { |
| 103 var transformerA = new RewriteTransformer("txt", "a"); | 104 var transformerA = new RewriteTransformer("txt", "a"); |
| 104 var transformerB = new RewriteTransformer("txt", "b"); | 105 var transformerB = new RewriteTransformer("txt", "b"); |
| 105 initGraph(["app|foo.txt"], {"app": [[transformerA, transformerB]]}); | 106 initGraph(["app|foo.txt"], {"app": [[transformerA, transformerB]]}); |
| 106 | 107 |
| 107 transformerA.wait(); | 108 transformerA.pauseApply(); |
| 108 transformerB.wait(); | 109 transformerB.pauseApply(); |
| 109 | 110 |
| 110 schedule(() { | 111 schedule(() { |
| 111 updateSources(["app|foo.txt"]); | 112 updateSources(["app|foo.txt"]); |
| 112 | 113 |
| 113 // Wait for them both to start. | 114 // Wait for them both to start. |
| 114 return Future.wait([transformerA.started, transformerB.started]); | 115 return Future.wait([transformerA.started, transformerB.started]); |
| 115 }); | 116 }); |
| 116 | 117 |
| 117 schedule(() { | 118 schedule(() { |
| 118 // They should both still be running. | 119 // They should both still be running. |
| 119 expect(transformerA.isRunning, isTrue); | 120 expect(transformerA.isRunning, isTrue); |
| 120 expect(transformerB.isRunning, isTrue); | 121 expect(transformerB.isRunning, isTrue); |
| 121 | 122 |
| 122 transformerA.complete(); | 123 transformerA.resumeApply(); |
| 123 transformerB.complete(); | 124 transformerB.resumeApply(); |
| 124 }); | 125 }); |
| 125 | 126 |
| 126 expectAsset("app|foo.a", "foo.a"); | 127 expectAsset("app|foo.a", "foo.a"); |
| 127 expectAsset("app|foo.b", "foo.b"); | 128 expectAsset("app|foo.b", "foo.b"); |
| 128 buildShouldSucceed(); | 129 buildShouldSucceed(); |
| 129 }); | 130 }); |
| 130 | 131 |
| 131 test("does not reapply transform when inputs are not modified", () { | 132 test("does not reapply transform when inputs are not modified", () { |
| 132 var transformer = new RewriteTransformer("blub", "blab"); | 133 var transformer = new RewriteTransformer("blub", "blab"); |
| 133 initGraph(["app|foo.blub"], {"app": [[transformer]]}); | 134 initGraph(["app|foo.blub"], {"app": [[transformer]]}); |
| (...skipping 45 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 179 "app|a.inc": "a", | 180 "app|a.inc": "a", |
| 180 "app|b.inc": "b" | 181 "app|b.inc": "b" |
| 181 }, {"app": [[transformer]]}); | 182 }, {"app": [[transformer]]}); |
| 182 | 183 |
| 183 updateSources(["app|a.txt", "app|a.inc", "app|b.inc"]); | 184 updateSources(["app|a.txt", "app|a.inc", "app|b.inc"]); |
| 184 | 185 |
| 185 expectAsset("app|a.out", "ab"); | 186 expectAsset("app|a.out", "ab"); |
| 186 buildShouldSucceed(); | 187 buildShouldSucceed(); |
| 187 | 188 |
| 188 // Remove the dependency on the non-primary input. | 189 // Remove the dependency on the non-primary input. |
| 189 schedule(() { | 190 modifyAsset("app|a.txt", "a.inc"); |
| 190 modifyAsset("app|a.txt", "a.inc"); | 191 schedule(() => updateSources(["app|a.txt"])); |
| 191 updateSources(["app|a.txt"]); | |
| 192 }); | |
| 193 | 192 |
| 194 // Process it again. | 193 // Process it again. |
| 195 expectAsset("app|a.out", "a"); | 194 expectAsset("app|a.out", "a"); |
| 196 buildShouldSucceed(); | 195 buildShouldSucceed(); |
| 197 | 196 |
| 198 // Now touch the removed input. It should not trigger another build. | 197 // Now touch the removed input. It should not trigger another build. |
| 199 schedule(() { | 198 schedule(() { |
| 200 updateSources(["app|b.inc"]); | 199 updateSources(["app|b.inc"]); |
| 201 }); | 200 }); |
| 202 | 201 |
| (...skipping 60 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 263 | 262 |
| 264 schedule(() { | 263 schedule(() { |
| 265 removeSources(["app|foo.txt"]); | 264 removeSources(["app|foo.txt"]); |
| 266 }); | 265 }); |
| 267 | 266 |
| 268 expectNoAsset("app|foo.out"); | 267 expectNoAsset("app|foo.out"); |
| 269 buildShouldSucceed(); | 268 buildShouldSucceed(); |
| 270 }); | 269 }); |
| 271 | 270 |
| 272 test("reapplies a transform when a non-primary input changes", () { | 271 test("reapplies a transform when a non-primary input changes", () { |
| 273 initGraph({ | 272 initGraph({ |
| 274 "app|a.txt": "a.inc", | 273 "app|a.txt": "a.inc", |
| 275 "app|a.inc": "a" | 274 "app|a.inc": "a" |
| 276 }, {"app": [[new ManyToOneTransformer("txt")]]}); | 275 }, {"app": [[new ManyToOneTransformer("txt")]]}); |
| 277 | 276 |
| 278 updateSources(["app|a.txt", "app|a.inc"]); | 277 updateSources(["app|a.txt", "app|a.inc"]); |
| 279 expectAsset("app|a.out", "a"); | 278 expectAsset("app|a.out", "a"); |
| 280 buildShouldSucceed(); | 279 buildShouldSucceed(); |
| 281 | 280 |
| 282 schedule(() { | 281 modifyAsset("app|a.inc", "after"); |
| 283 modifyAsset("app|a.inc", "after"); | 282 schedule(() => updateSources(["app|a.inc"])); |
| 284 updateSources(["app|a.inc"]); | |
| 285 }); | |
| 286 | 283 |
| 287 expectAsset("app|a.out", "after"); | 284 expectAsset("app|a.out", "after"); |
| 288 buildShouldSucceed(); | 285 buildShouldSucceed(); |
| 289 }); | 286 }); |
| 290 | 287 |
| 291 test("restarts processing if a change occurs during processing", () { | 288 test("restarts processing if a change occurs during processing", () { |
| 292 var transformer = new RewriteTransformer("txt", "out"); | 289 var transformer = new RewriteTransformer("txt", "out"); |
| 293 initGraph(["app|foo.txt"], {"app": [[transformer]]}); | 290 initGraph(["app|foo.txt"], {"app": [[transformer]]}); |
| 294 | 291 |
| 295 transformer.wait(); | 292 transformer.pauseApply(); |
| 296 | 293 |
| 297 schedule(() { | 294 schedule(() { |
| 298 updateSources(["app|foo.txt"]); | 295 updateSources(["app|foo.txt"]); |
| 299 | 296 |
| 300 // Wait for the transform to start. | 297 // Wait for the transform to start. |
| 301 return transformer.started; | 298 return transformer.started; |
| 302 }); | 299 }); |
| 303 | 300 |
| 304 schedule(() { | 301 schedule(() { |
| 305 // Now update the graph during it. | 302 // Now update the graph during it. |
| 306 updateSources(["app|foo.txt"]); | 303 updateSources(["app|foo.txt"]); |
| 307 }); | 304 transformer.resumeApply(); |
| 308 | |
| 309 schedule(() { | |
| 310 transformer.complete(); | |
| 311 }); | 305 }); |
| 312 | 306 |
| 313 expectAsset("app|foo.out", "foo.out"); | 307 expectAsset("app|foo.out", "foo.out"); |
| 314 buildShouldSucceed(); | 308 buildShouldSucceed(); |
| 315 | 309 |
| 316 schedule(() { | 310 schedule(() { |
| 317 expect(transformer.numRuns, equals(2)); | 311 expect(transformer.numRuns, equals(2)); |
| 318 }); | 312 }); |
| 319 }); | 313 }); |
| 320 | 314 |
| 321 test("handles an output moving from one transformer to another", () { | 315 test("handles an output moving from one transformer to another", () { |
| 322 // In the first run, "shared.out" is created by the "a.a" transformer. | 316 // In the first run, "shared.out" is created by the "a.a" transformer. |
| 323 initGraph({ | 317 initGraph({ |
| 324 "app|a.a": "a.out,shared.out", | 318 "app|a.a": "a.out,shared.out", |
| 325 "app|b.b": "b.out" | 319 "app|b.b": "b.out" |
| 326 }, {"app": [ | 320 }, {"app": [ |
| 327 [new OneToManyTransformer("a"), new OneToManyTransformer("b")] | 321 [new OneToManyTransformer("a"), new OneToManyTransformer("b")] |
| 328 ]}); | 322 ]}); |
| 329 | 323 |
| 330 updateSources(["app|a.a", "app|b.b"]); | 324 updateSources(["app|a.a", "app|b.b"]); |
| 331 | 325 |
| 332 expectAsset("app|a.out", "spread a"); | 326 expectAsset("app|a.out", "spread a"); |
| 333 expectAsset("app|b.out", "spread b"); | 327 expectAsset("app|b.out", "spread b"); |
| 334 expectAsset("app|shared.out", "spread a"); | 328 expectAsset("app|shared.out", "spread a"); |
| 335 buildShouldSucceed(); | 329 buildShouldSucceed(); |
| 336 | 330 |
| 337 // Now switch their contents so that "shared.out" will be output by "b.b"'s | 331 // Now switch their contents so that "shared.out" will be output by "b.b"'s |
| 338 // transformer. | 332 // transformer. |
| 339 schedule(() { | 333 modifyAsset("app|a.a", "a.out"); |
| 340 modifyAsset("app|a.a", "a.out"); | 334 modifyAsset("app|b.b", "b.out,shared.out"); |
| 341 modifyAsset("app|b.b", "b.out,shared.out"); | 335 schedule(() => updateSources(["app|a.a", "app|b.b"])); |
| 342 updateSources(["app|a.a", "app|b.b"]); | |
| 343 }); | |
| 344 | 336 |
| 345 expectAsset("app|a.out", "spread a"); | 337 expectAsset("app|a.out", "spread a"); |
| 346 expectAsset("app|b.out", "spread b"); | 338 expectAsset("app|b.out", "spread b"); |
| 347 expectAsset("app|shared.out", "spread b"); | 339 expectAsset("app|shared.out", "spread b"); |
| 348 buildShouldSucceed(); | 340 buildShouldSucceed(); |
| 349 }); | 341 }); |
| 350 | 342 |
| 351 test("restarts before finishing later phases when a change occurs", () { | 343 test("restarts before finishing later phases when a change occurs", () { |
| 352 var txtToInt = new RewriteTransformer("txt", "int"); | 344 var txtToInt = new RewriteTransformer("txt", "int"); |
| 353 var intToOut = new RewriteTransformer("int", "out"); | 345 var intToOut = new RewriteTransformer("int", "out"); |
| 354 initGraph(["app|foo.txt", "app|bar.txt"], | 346 initGraph(["app|foo.txt", "app|bar.txt"], |
| 355 {"app": [[txtToInt], [intToOut]]}); | 347 {"app": [[txtToInt], [intToOut]]}); |
| 356 | 348 |
| 357 txtToInt.wait(); | 349 txtToInt.pauseApply(); |
| 358 | 350 |
| 359 schedule(() { | 351 schedule(() { |
| 360 updateSources(["app|foo.txt"]); | 352 updateSources(["app|foo.txt"]); |
| 361 | 353 |
| 362 // Wait for the first transform to start. | 354 // Wait for the first transform to start. |
| 363 return txtToInt.started; | 355 return txtToInt.started; |
| 364 }); | 356 }); |
| 365 | 357 |
| 366 schedule(() { | 358 schedule(() { |
| 367 // Now update the graph during it. | 359 // Now update the graph during it. |
| 368 updateSources(["app|bar.txt"]); | 360 updateSources(["app|bar.txt"]); |
| 369 }); | 361 }); |
| 370 | 362 |
| 371 schedule(() { | 363 schedule(() { |
| 372 txtToInt.complete(); | 364 txtToInt.resumeApply(); |
| 373 }); | 365 }); |
| 374 | 366 |
| 375 expectAsset("app|foo.out", "foo.int.out"); | 367 expectAsset("app|foo.out", "foo.int.out"); |
| 376 expectAsset("app|bar.out", "bar.int.out"); | 368 expectAsset("app|bar.out", "bar.int.out"); |
| 377 buildShouldSucceed(); | 369 buildShouldSucceed(); |
| 378 | 370 |
| 379 schedule(() { | 371 schedule(() { |
| 380 // Should only have run each transform once for each primary. | 372 // Should only have run each transform once for each primary. |
| 381 expect(txtToInt.numRuns, equals(2)); | 373 expect(txtToInt.numRuns, equals(2)); |
| 382 expect(intToOut.numRuns, equals(2)); | 374 expect(intToOut.numRuns, equals(2)); |
| (...skipping 44 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 427 schedule(() => updateSources(["pkg2|foo.txt"])); | 419 schedule(() => updateSources(["pkg2|foo.txt"])); |
| 428 expectAsset("pkg1|foo.out", "foo.out"); | 420 expectAsset("pkg1|foo.out", "foo.out"); |
| 429 buildShouldNotBeDone(); | 421 buildShouldNotBeDone(); |
| 430 | 422 |
| 431 // Now that the provider is unpaused, pkg2's transforms finish and the | 423 // Now that the provider is unpaused, pkg2's transforms finish and the |
| 432 // overall build succeeds. | 424 // overall build succeeds. |
| 433 resumeProvider(); | 425 resumeProvider(); |
| 434 buildShouldSucceed(); | 426 buildShouldSucceed(); |
| 435 }); | 427 }); |
| 436 } | 428 } |
| OLD | NEW |