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