| OLD | NEW |
| 1 // Copyright (c) 2014, the Dart project authors. Please see the AUTHORS d.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 pub_tests; | 1 library pub_tests; |
| 6 | |
| 7 import '../descriptor.dart' as d; | 2 import '../descriptor.dart' as d; |
| 8 import '../test_pub.dart'; | 3 import '../test_pub.dart'; |
| 9 import 'utils.dart'; | 4 import 'utils.dart'; |
| 10 | |
| 11 const DECLARING_TRANSFORMER = """ | 5 const DECLARING_TRANSFORMER = """ |
| 12 import 'dart:async'; | 6 import 'dart:async'; |
| 13 | 7 |
| 14 import 'package:barback/barback.dart'; | 8 import 'package:barback/barback.dart'; |
| 15 | 9 |
| 16 class DeclaringRewriteTransformer extends Transformer | 10 class DeclaringRewriteTransformer extends Transformer |
| 17 implements DeclaringTransformer { | 11 implements DeclaringTransformer { |
| 18 DeclaringRewriteTransformer.asPlugin(); | 12 DeclaringRewriteTransformer.asPlugin(); |
| 19 | 13 |
| 20 String get allowedExtensions => '.out'; | 14 String get allowedExtensions => '.out'; |
| 21 | 15 |
| 22 Future apply(Transform transform) { | 16 Future apply(Transform transform) { |
| 23 transform.logger.info('Rewriting \${transform.primaryInput.id}.'); | 17 transform.logger.info('Rewriting \${transform.primaryInput.id}.'); |
| 24 return transform.primaryInput.readAsString().then((contents) { | 18 return transform.primaryInput.readAsString().then((contents) { |
| 25 var id = transform.primaryInput.id.changeExtension(".final"); | 19 var id = transform.primaryInput.id.changeExtension(".final"); |
| 26 transform.addOutput(new Asset.fromString(id, "\$contents.final")); | 20 transform.addOutput(new Asset.fromString(id, "\$contents.final")); |
| 27 }); | 21 }); |
| 28 } | 22 } |
| 29 | 23 |
| 30 Future declareOutputs(DeclaringTransform transform) { | 24 Future declareOutputs(DeclaringTransform transform) { |
| 31 transform.declareOutput(transform.primaryId.changeExtension(".final")); | 25 transform.declareOutput(transform.primaryId.changeExtension(".final")); |
| 32 return new Future.value(); | 26 return new Future.value(); |
| 33 } | 27 } |
| 34 } | 28 } |
| 35 """; | 29 """; |
| 36 | |
| 37 main() { | 30 main() { |
| 38 initConfig(); | 31 initConfig(); |
| 39 withBarbackVersions("any", () { | 32 withBarbackVersions("any", () { |
| 40 integration("supports a user-defined declaring transformer", () { | 33 integration("supports a user-defined declaring transformer", () { |
| 41 d.dir(appPath, [ | 34 d.dir(appPath, [d.pubspec({ |
| 42 d.pubspec({ | |
| 43 "name": "myapp", | 35 "name": "myapp", |
| 44 "transformers": ["myapp/src/lazy", "myapp/src/declaring"] | 36 "transformers": ["myapp/src/lazy", "myapp/src/declaring"] |
| 45 }), | 37 }), |
| 46 d.dir("lib", [d.dir("src", [ | 38 d.dir( |
| 47 // Include a lazy transformer before the declaring transformer, | 39 "lib", |
| 48 // because otherwise its behavior is indistinguishable from a normal | 40 [ |
| 49 // transformer. | 41 d.dir( |
| 50 d.file("lazy.dart", LAZY_TRANSFORMER), | 42 "src", |
| 51 d.file("declaring.dart", DECLARING_TRANSFORMER) | 43 [ |
| 52 ])]), | 44 d.file("lazy.dart", LAZY_TRANSFORMER), |
| 53 d.dir("web", [ | 45 d.file("declaring.dart", DECLARING_TRANSFORMER)])]), |
| 54 d.file("foo.txt", "foo") | 46 d.dir("web", [d.file("foo.txt", "foo")])]).create(); |
| 55 ]) | |
| 56 ]).create(); | |
| 57 | |
| 58 createLockFile('myapp', pkg: ['barback']); | 47 createLockFile('myapp', pkg: ['barback']); |
| 59 | |
| 60 var server = pubServe(); | 48 var server = pubServe(); |
| 61 // The build should complete without either transformer logging anything. | |
| 62 server.stdout.expect('Build completed successfully'); | 49 server.stdout.expect('Build completed successfully'); |
| 63 | |
| 64 requestShouldSucceed("foo.final", "foo.out.final"); | 50 requestShouldSucceed("foo.final", "foo.out.final"); |
| 65 server.stdout.expect(emitsLines( | 51 server.stdout.expect( |
| 66 '[Info from LazyRewrite]:\n' | 52 emitsLines( |
| 67 'Rewriting myapp|web/foo.txt.\n' | 53 '[Info from LazyRewrite]:\n' 'Rewriting myapp|web/foo.txt.\n' |
| 68 '[Info from DeclaringRewrite]:\n' | 54 '[Info from DeclaringRewrite]:\n' 'Rewriting myapp|web/foo.out
.')); |
| 69 'Rewriting myapp|web/foo.out.')); | |
| 70 endPubServe(); | 55 endPubServe(); |
| 71 }); | 56 }); |
| 72 }); | 57 }); |
| 73 } | 58 } |
| OLD | NEW |