| OLD | NEW |
| 1 // Copyright (c) 2013, the Dart project authors. Please see the AUTHORS d.file | 1 // Copyright (c) 2013, 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 | 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 pub_tests; | 5 library pub_tests; |
| 6 | 6 |
| 7 import '../descriptor.dart' as d; | 7 import '../descriptor.dart' as d; |
| 8 import '../test_pub.dart'; | 8 import '../test_pub.dart'; |
| 9 | 9 |
| 10 final transformer = """ | 10 const TRANSFORMER = """ |
| 11 import 'dart:async'; | 11 import 'dart:async'; |
| 12 | 12 |
| 13 import 'package:barback/barback.dart'; | 13 import 'package:barback/barback.dart'; |
| 14 import 'package:source_maps/source_maps.dart'; |
| 14 | 15 |
| 15 class ModeTransformer extends Transformer { | 16 class ModeTransformer extends Transformer { |
| 16 final BarbackSettings settings; | 17 final BarbackSettings settings; |
| 17 | |
| 18 ModeTransformer.asPlugin(this.settings); | 18 ModeTransformer.asPlugin(this.settings); |
| 19 | 19 |
| 20 String get allowedExtensions => '.txt'; | 20 String get allowedExtensions => '.txt'; |
| 21 | 21 |
| 22 Future apply(Transform transform) { | 22 Future apply(Transform transform) { |
| 23 return transform.primaryInput.readAsString().then((contents) { | 23 return new Future.value().then((_) { |
| 24 transform.addOutput( | 24 var id = transform.primaryInput.id.changeExtension(".out"); |
| 25 new Asset.fromString(transform.primaryInput.id, settings.mode.name)); | 25 transform.addOutput(new Asset.fromString(id, settings.mode.toString())); |
| 26 }); | 26 }); |
| 27 } | 27 } |
| 28 } | 28 } |
| 29 """; | 29 """; |
| 30 | 30 |
| 31 main() { | 31 main() { |
| 32 initConfig(); | 32 initConfig(); |
| 33 integration("mode defaults to 'release' in pub build", () { | 33 integration("allows user-defined mode names", () { |
| 34 d.dir(appPath, [ | 34 d.dir(appPath, [ |
| 35 d.pubspec({ | 35 d.pubspec({ |
| 36 "name": "myapp", | 36 "name": "myapp", |
| 37 "transformers": ["myapp/src/transformer"] | 37 "transformers": ["myapp/src/transformer"] |
| 38 }), | 38 }), |
| 39 d.dir("lib", [d.dir("src", [ | 39 d.dir("lib", [d.dir("src", [ |
| 40 d.file("transformer.dart", transformer) | 40 d.file("transformer.dart", TRANSFORMER) |
| 41 ])]), | 41 ])]), |
| 42 d.dir("web", [ | 42 d.dir("web", [ |
| 43 d.file("foo.txt", "foo") | 43 d.file("foo.txt", "foo") |
| 44 ]) | 44 ]) |
| 45 ]).create(); | 45 ]).create(); |
| 46 | 46 |
| 47 createLockFile('myapp', pkg: ['barback']); | 47 createLockFile('myapp', pkg: ['barback']); |
| 48 | 48 |
| 49 schedulePub(args: ["build"], | 49 schedulePub(args: ["build", "--mode", "depeche"], |
| 50 output: new RegExp(r"Built 1 file!"), | |
| 51 exitCode: 0); | 50 exitCode: 0); |
| 52 | 51 |
| 53 d.dir(appPath, [ | 52 d.dir(appPath, [ |
| 54 d.dir('build', [ | 53 d.dir('build', [ |
| 55 d.file('foo.txt', 'release') | 54 d.file('foo.out', 'depeche') |
| 56 ]) | 55 ]) |
| 57 ]).validate(); | 56 ]).validate(); |
| 58 }); | 57 }); |
| 59 } | 58 } |
| OLD | NEW |