| 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 withBarbackVersions("any", () { | 29 integration('runs a local script with customizable modes', () { |
| 30 integration('runs a local script with customizable modes', () { | 30 d.dir(appPath, [ |
| 31 d.dir(appPath, [ | 31 d.pubspec({ |
| 32 d.pubspec({ | 32 "name": "myapp", |
| 33 "name": "myapp", | 33 "transformers": ["myapp/src/transformer"] |
| 34 "transformers": ["myapp/src/transformer"] | 34 }), |
| 35 }), | 35 d.dir("lib", [d.dir("src", [ |
| 36 d.dir("lib", [d.dir("src", [ | 36 d.file("transformer.dart", TRANSFORMER), |
| 37 d.file("transformer.dart", TRANSFORMER), | 37 d.file("primary.in", "") |
| 38 d.file("primary.in", "") | 38 ])]) |
| 39 ])]) | 39 ]).create(); |
| 40 ]).create(); | |
| 41 | 40 |
| 42 createLockFile('myapp', pkg: ['barback']); | 41 createLockFile('myapp', pkg: ['barback']); |
| 43 | 42 |
| 44 // By default it should run in debug mode. | 43 // By default it should run in debug mode. |
| 45 var pub = pubRun(args: ["bin/script"]); | 44 var pub = pubRun(args: ["bin/script"]); |
| 46 pub.stdout.expect("debug"); | 45 pub.stdout.expect("debug"); |
| 47 pub.shouldExit(); | 46 pub.shouldExit(); |
| 48 | 47 |
| 49 // A custom mode should be specifiable. | 48 // A custom mode should be specifiable. |
| 50 pub = pubRun(args: ["--mode", "custom-mode", "bin/script"]); | 49 pub = pubRun(args: ["--mode", "custom-mode", "bin/script"]); |
| 51 pub.stdout.expect("custom-mode"); | 50 pub.stdout.expect("custom-mode"); |
| 52 pub.shouldExit(); | 51 pub.shouldExit(); |
| 53 }); | 52 }); |
| 54 | 53 |
| 55 integration('runs a dependency script with customizable modes', () { | 54 integration('runs a dependency script with customizable modes', () { |
| 56 d.dir("foo", [ | 55 d.dir("foo", [ |
| 57 d.pubspec({ | 56 d.pubspec({ |
| 58 "name": "foo", | 57 "name": "foo", |
| 59 "version": "1.2.3", | 58 "version": "1.2.3", |
| 60 "transformers": ["foo/src/transformer"] | 59 "transformers": ["foo/src/transformer"] |
| 61 }), | 60 }), |
| 62 d.dir("lib", [d.dir("src", [ | 61 d.dir("lib", [d.dir("src", [ |
| 63 d.file("transformer.dart", TRANSFORMER), | 62 d.file("transformer.dart", TRANSFORMER), |
| 64 d.file("primary.in", "") | 63 d.file("primary.in", "") |
| 65 ])]) | 64 ])]) |
| 66 ]).create(); | 65 ]).create(); |
| 67 | 66 |
| 68 d.appDir({"foo": {"path": "../foo"}}).create(); | 67 d.appDir({"foo": {"path": "../foo"}}).create(); |
| 69 | 68 |
| 70 createLockFile('myapp', sandbox: ['foo'], pkg: ['barback']); | 69 createLockFile('myapp', sandbox: ['foo'], pkg: ['barback']); |
| 71 | 70 |
| 72 // By default it should run in release mode. | 71 // By default it should run in release mode. |
| 73 var pub = pubRun(args: ["foo:script"]); | 72 var pub = pubRun(args: ["foo:script"]); |
| 74 pub.stdout.expect("release"); | 73 pub.stdout.expect("release"); |
| 75 pub.shouldExit(); | 74 pub.shouldExit(); |
| 76 | 75 |
| 77 // A custom mode should be specifiable. | 76 // A custom mode should be specifiable. |
| 78 pub = pubRun(args: ["--mode", "custom-mode", "foo:script"]); | 77 pub = pubRun(args: ["--mode", "custom-mode", "foo:script"]); |
| 79 pub.stdout.expect("custom-mode"); | 78 pub.stdout.expect("custom-mode"); |
| 80 pub.shouldExit(); | 79 pub.shouldExit(); |
| 81 }); | 80 }); |
| 82 }); | |
| 83 } | 81 } |
| OLD | NEW |