OLD | NEW |
1 // Copyright (c) 2013, the Dart project authors. Please see the AUTHORS file | 1 // Copyright (c) 2013, 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 library barback.test.transformer.declaring_bad; | 5 library barback.test.transformer.declaring_bad; |
6 | 6 |
7 import 'package:barback/barback.dart'; | 7 import 'package:barback/barback.dart'; |
8 | 8 |
9 import 'bad.dart'; | 9 import 'bad.dart'; |
10 import 'mock.dart'; | 10 import 'mock.dart'; |
11 | 11 |
12 /// A transformer that throws an exception when run, after generating the | 12 /// A transformer that throws an exception when run, after generating the |
13 /// given outputs. | 13 /// given outputs. |
14 class DeclaringBadTransformer extends MockTransformer | 14 class DeclaringBadTransformer extends MockTransformer |
15 implements DeclaringTransformer { | 15 implements DeclaringTransformer { |
16 /// Whether this should throw an error in [declareOutputs]. | 16 /// Whether this should throw an error in [declareOutputs]. |
17 final bool declareError; | 17 final bool declareError; |
18 | 18 |
19 /// Whether this should throw an error in [apply]. | 19 /// Whether this should throw an error in [apply]. |
20 final bool applyError; | 20 final bool applyError; |
21 | 21 |
22 /// The id of the output asset to emit. | 22 /// The id of the output asset to emit. |
23 final AssetId output; | 23 final AssetId output; |
24 | 24 |
25 DeclaringBadTransformer(String output, {bool declareError: true, | 25 DeclaringBadTransformer(String output, |
26 bool applyError: false}) | 26 {bool declareError: true, bool applyError: false}) |
27 : this.output = new AssetId.parse(output), | 27 : this.output = new AssetId.parse(output), |
28 this.declareError = declareError, | 28 this.declareError = declareError, |
29 this.applyError = applyError; | 29 this.applyError = applyError; |
30 | 30 |
31 bool doIsPrimary(AssetId id) => true; | 31 bool doIsPrimary(AssetId id) => true; |
32 | 32 |
33 void doApply(Transform transform) { | 33 void doApply(Transform transform) { |
34 transform.addOutput(new Asset.fromString(output, "bad out")); | 34 transform.addOutput(new Asset.fromString(output, "bad out")); |
35 if (applyError) throw BadTransformer.ERROR; | 35 if (applyError) throw BadTransformer.ERROR; |
36 } | 36 } |
37 | 37 |
38 void declareOutputs(DeclaringTransform transform) { | 38 void declareOutputs(DeclaringTransform transform) { |
39 if (consumePrimary) transform.consumePrimary(); | 39 if (consumePrimary) transform.consumePrimary(); |
40 transform.declareOutput(output); | 40 transform.declareOutput(output); |
41 if (declareError) throw BadTransformer.ERROR; | 41 if (declareError) throw BadTransformer.ERROR; |
42 } | 42 } |
43 } | 43 } |
OLD | NEW |