| 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 import '../descriptor.dart' as d; | 5 import '../descriptor.dart' as d; |
| 6 import '../test_pub.dart'; | 6 import '../test_pub.dart'; |
| 7 | 7 |
| 8 const TRANSFORMER = """ | 8 const TRANSFORMER = """ |
| 9 import 'dart:async'; | 9 import 'dart:async'; |
| 10 | 10 |
| 11 import 'package:barback/barback.dart'; | 11 import 'package:barback/barback.dart'; |
| 12 | 12 |
| 13 class DartTransformer extends Transformer { | 13 class DartTransformer extends Transformer { |
| 14 final BarbackSettings _settings; | 14 final BarbackSettings _settings; |
| 15 | 15 |
| 16 DartTransformer.asPlugin(this._settings); | 16 DartTransformer.asPlugin(this._settings); |
| 17 | 17 |
| 18 String get allowedExtensions => '.in'; | 18 String get allowedExtensions => '.in'; |
| 19 | 19 |
| 20 void apply(Transform transform) { | 20 void apply(Transform transform) { |
| 21 transform.addOutput(new Asset.fromString( | 21 transform.addOutput(new Asset.fromString( |
| 22 new AssetId(transform.primaryInput.id.package, "bin/script.dart"), | 22 new AssetId(transform.primaryInput.id.package, "bin/script.dart"), |
| 23 "void main() => print('\${_settings.mode.name}');")); | 23 "void main() => print('\${_settings.mode.name}');")); |
| 24 } | 24 } |
| 25 } | 25 } |
| 26 """; | 26 """; |
| 27 | 27 |
| 28 main() { | 28 main() { |
| 29 integration('runs a local script with customizable modes', () { | 29 integration('runs a local script with customizable modes', () { |
| 30 serveBarback(); |
| 31 |
| 30 d.dir(appPath, [ | 32 d.dir(appPath, [ |
| 31 d.pubspec({ | 33 d.pubspec({ |
| 32 "name": "myapp", | 34 "name": "myapp", |
| 33 "transformers": ["myapp/src/transformer"] | 35 "transformers": ["myapp/src/transformer"], |
| 36 "dependencies": {"barback": "any"} |
| 34 }), | 37 }), |
| 35 d.dir("lib", [d.dir("src", [ | 38 d.dir("lib", [d.dir("src", [ |
| 36 d.file("transformer.dart", TRANSFORMER), | 39 d.file("transformer.dart", TRANSFORMER), |
| 37 d.file("primary.in", "") | 40 d.file("primary.in", "") |
| 38 ])]) | 41 ])]) |
| 39 ]).create(); | 42 ]).create(); |
| 40 | 43 |
| 41 createLockFile('myapp', pkg: ['barback']); | 44 pubGet(); |
| 42 | 45 |
| 43 // By default it should run in debug mode. | 46 // By default it should run in debug mode. |
| 44 var pub = pubRun(args: ["bin/script"]); | 47 var pub = pubRun(args: ["bin/script"]); |
| 45 pub.stdout.expect("debug"); | 48 pub.stdout.expect("debug"); |
| 46 pub.shouldExit(); | 49 pub.shouldExit(); |
| 47 | 50 |
| 48 // A custom mode should be specifiable. | 51 // A custom mode should be specifiable. |
| 49 pub = pubRun(args: ["--mode", "custom-mode", "bin/script"]); | 52 pub = pubRun(args: ["--mode", "custom-mode", "bin/script"]); |
| 50 pub.stdout.expect("custom-mode"); | 53 pub.stdout.expect("custom-mode"); |
| 51 pub.shouldExit(); | 54 pub.shouldExit(); |
| 52 }); | 55 }); |
| 53 | 56 |
| 54 integration('runs a dependency script with customizable modes', () { | 57 integration('runs a dependency script with customizable modes', () { |
| 58 serveBarback(); |
| 59 |
| 55 d.dir("foo", [ | 60 d.dir("foo", [ |
| 56 d.pubspec({ | 61 d.pubspec({ |
| 57 "name": "foo", | 62 "name": "foo", |
| 58 "version": "1.2.3", | 63 "version": "1.2.3", |
| 59 "transformers": ["foo/src/transformer"] | 64 "transformers": ["foo/src/transformer"], |
| 65 "dependencies": {"barback": "any"} |
| 60 }), | 66 }), |
| 61 d.dir("lib", [d.dir("src", [ | 67 d.dir("lib", [d.dir("src", [ |
| 62 d.file("transformer.dart", TRANSFORMER), | 68 d.file("transformer.dart", TRANSFORMER), |
| 63 d.file("primary.in", "") | 69 d.file("primary.in", "") |
| 64 ])]) | 70 ])]) |
| 65 ]).create(); | 71 ]).create(); |
| 66 | 72 |
| 67 d.appDir({"foo": {"path": "../foo"}}).create(); | 73 d.appDir({"foo": {"path": "../foo"}}).create(); |
| 68 | 74 |
| 69 createLockFile('myapp', sandbox: ['foo'], pkg: ['barback']); | 75 pubGet(); |
| 70 | 76 |
| 71 // By default it should run in release mode. | 77 // By default it should run in release mode. |
| 72 var pub = pubRun(args: ["foo:script"]); | 78 var pub = pubRun(args: ["foo:script"]); |
| 73 pub.stdout.expect("release"); | 79 pub.stdout.expect("release"); |
| 74 pub.shouldExit(); | 80 pub.shouldExit(); |
| 75 | 81 |
| 76 // A custom mode should be specifiable. | 82 // A custom mode should be specifiable. |
| 77 pub = pubRun(args: ["--mode", "custom-mode", "foo:script"]); | 83 pub = pubRun(args: ["--mode", "custom-mode", "foo:script"]); |
| 78 pub.stdout.expect("custom-mode"); | 84 pub.stdout.expect("custom-mode"); |
| 79 pub.shouldExit(); | 85 pub.shouldExit(); |
| 80 }); | 86 }); |
| 81 } | 87 } |
| OLD | NEW |