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 library barback.test.package_graph.declaring_transformer_test; | |
6 | |
7 import 'package:barback/barback.dart'; | |
8 import 'package:barback/src/utils.dart'; | |
9 import 'package:scheduled_test/scheduled_test.dart'; | |
10 | |
11 import '../utils.dart'; | |
12 | |
13 main() { | |
14 initConfig(); | |
15 | |
16 test("gets a declared output with a different path", () { | |
17 initGraph(["app|foo.blub"], {"app": [ | |
18 [new DeclaringRewriteTransformer("blub", "blab")] | |
19 ]}); | |
20 updateSources(["app|foo.blub"]); | |
21 expectAsset("app|foo.blab", "foo.blab"); | |
22 buildShouldSucceed(); | |
23 }); | |
24 | |
25 test("gets a declared output with the same path", () { | |
26 initGraph(["app|foo.blub"], {"app": [ | |
27 [new DeclaringRewriteTransformer("blub", "blub")] | |
28 ]}); | |
29 updateSources(["app|foo.blub"]); | |
30 expectAsset("app|foo.blub", "foo.blub"); | |
31 buildShouldSucceed(); | |
32 }); | |
33 | |
34 test("gets a passed-through asset", () { | |
35 initGraph(["app|foo.blub"], {"app": [ | |
36 [new DeclaringRewriteTransformer("blub", "blab")] | |
37 ]}); | |
38 updateSources(["app|foo.blub"]); | |
39 expectAsset("app|foo.blub", "foo"); | |
40 buildShouldSucceed(); | |
41 }); | |
42 | |
43 test("doesn't get a consumed asset", () { | |
44 initGraph(["app|foo.blub"], {"app": [ | |
45 [new DeclaringRewriteTransformer("blub", "blab")..consumePrimary = true] | |
46 ]}); | |
47 updateSources(["app|foo.blub"]); | |
48 expectNoAsset("app|foo.blub"); | |
49 buildShouldSucceed(); | |
50 }); | |
51 | |
52 test("gets a passed-through asset before apply is finished", () { | |
Bob Nystrom
2014/04/08 18:23:44
What if it doesn't declare that it will overwrite
nweiz
2014/04/08 23:42:33
I think we should assume that it won't, but start
| |
53 var transformer = new DeclaringRewriteTransformer("blub", "blab"); | |
54 initGraph(["app|foo.blub"], {"app": [[transformer]]}); | |
55 | |
56 transformer.pauseApply(); | |
57 updateSources(["app|foo.blub"]); | |
58 expectAsset("app|foo.blub", "foo"); | |
59 | |
60 transformer.resumeApply(); | |
61 buildShouldSucceed(); | |
62 }); | |
63 | |
64 test("fails to get a consumed asset before apply is finished", () { | |
65 var transformer = new DeclaringRewriteTransformer("blub", "blab") | |
66 ..consumePrimary = true; | |
67 initGraph(["app|foo.blub"], {"app": [[transformer]]}); | |
68 | |
69 transformer.pauseApply(); | |
70 updateSources(["app|foo.blub"]); | |
71 expectNoAsset("app|foo.blub"); | |
72 | |
73 transformer.resumeApply(); | |
74 buildShouldSucceed(); | |
75 }); | |
76 | |
77 test("waits to get an overwritten asset until apply is finished", () { | |
Bob Nystrom
2014/04/08 18:23:44
The grammar is weird here. How about "waits until
nweiz
2014/04/08 23:42:33
Done.
| |
78 var transformer = new DeclaringRewriteTransformer("blub", "blub"); | |
79 initGraph(["app|foo.blub"], {"app": [[transformer]]}); | |
80 | |
81 transformer.pauseApply(); | |
82 updateSources(["app|foo.blub"]); | |
83 expectAssetDoesNotComplete("app|foo.blub"); | |
84 | |
85 transformer.resumeApply(); | |
86 expectAsset("app|foo.blub", "foo.blub"); | |
87 buildShouldSucceed(); | |
88 }); | |
89 | |
90 group("with an error in declareOutputs", () { | |
91 test("still runs apply", () { | |
92 initGraph(["app|foo.txt"], {"app": [[ | |
93 new DeclaringBadTransformer("app|out.txt", | |
94 declareError: true, applyError: false) | |
95 ]]}); | |
96 | |
97 updateSources(["app|foo.txt"]); | |
98 expectAsset("app|out.txt", "bad out"); | |
99 expectAsset("app|foo.txt", "foo"); | |
100 buildShouldFail([isTransformerException(BadTransformer.ERROR)]); | |
101 }); | |
102 | |
103 test("waits for apply to complete before passing through the input even if " | |
104 "consumePrimary was called", () { | |
105 var transformer = new DeclaringBadTransformer("app|out.txt", | |
106 declareError: true, applyError: false)..consumePrimary = true; | |
107 initGraph(["app|foo.txt"], {"app": [[transformer]]}); | |
108 | |
109 transformer.pauseApply(); | |
110 updateSources(["app|foo.txt"]); | |
111 expectAssetDoesNotComplete("app|out.txt"); | |
112 expectAssetDoesNotComplete("app|foo.txt"); | |
113 | |
114 transformer.resumeApply(); | |
115 expectAsset("app|out.txt", "bad out"); | |
116 expectNoAsset("app|foo.txt"); | |
117 buildShouldFail([isTransformerException(BadTransformer.ERROR)]); | |
118 }); | |
119 }); | |
120 | |
121 test("with an error in apply still passes through the input", () { | |
122 initGraph(["app|foo.txt"], {"app": [[ | |
123 new DeclaringBadTransformer("app|out.txt", | |
124 declareError: false, applyError: true) | |
125 ]]}); | |
126 | |
127 updateSources(["app|foo.txt"]); | |
128 expectNoAsset("app|out.txt"); | |
129 expectAsset("app|foo.txt", "foo"); | |
130 buildShouldFail([isTransformerException(BadTransformer.ERROR)]); | |
131 }); | |
132 | |
133 test("can emit outputs it didn't declare", () { | |
Bob Nystrom
2014/04/08 18:23:44
What about overwriting the primary if it didn't de
nweiz
2014/04/08 23:42:33
See above.
| |
134 initGraph(["app|foo.txt"], {"app": [ | |
135 [new DeclareAssetsTransformer([], ["app|out.txt"])] | |
136 ]}); | |
137 | |
138 updateSources(["app|foo.txt"]); | |
139 // There's probably going to be some time when "out.txt" is unavailable, | |
140 // since it was undeclared. | |
141 schedule(pumpEventQueue); | |
Bob Nystrom
2014/04/08 18:23:44
This is super sketchy.
nweiz
2014/04/08 23:42:33
In what way?
Bob Nystrom
2014/04/09 18:07:08
The comment says "probably" and then just waits an
nweiz
2014/04/09 20:11:52
It's not arbitrary; it waits until there are no ad
| |
142 expectAsset("app|out.txt", "app|out.txt"); | |
143 buildShouldSucceed(); | |
144 }); | |
145 | |
146 test("can declare outputs it doesn't emit", () { | |
Bob Nystrom
2014/04/08 18:23:44
This should at least be a warning.
nweiz
2014/04/08 23:42:33
Done.
| |
147 initGraph(["app|foo.txt"], {"app": [ | |
148 [new DeclareAssetsTransformer(["app|out.txt"], [])] | |
149 ]}); | |
150 | |
151 updateSources(["app|foo.txt"]); | |
152 expectNoAsset("app|out.txt"); | |
153 buildShouldSucceed(); | |
154 }); | |
155 } | |
OLD | NEW |