Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(178)

Side by Side Diff: pkg/barback/test/package_graph/declaring_transformer_test.dart

Issue 808713003: Remove barback from the repo. (Closed) Base URL: https://dart.googlecode.com/svn/branches/bleeding_edge/dart
Patch Set: Created 6 years ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
OLDNEW
(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", () {
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("blocks on getting a declared asset that wasn't generated last run", () {
78 var transformer = new DeclaringCheckContentAndRenameTransformer(
79 oldExtension: "txt", oldContent: "yes",
80 newExtension: "out", newContent: "done");
81 initGraph({"app|foo.txt": "no"}, {"app": [[transformer]]});
82
83 updateSources(["app|foo.txt"]);
84 expectNoAsset("app|foo.out");
85 buildShouldSucceed();
86
87 // The transform should remember that foo.out was declared, so it should
88 // expect that it might still be generated even though it wasn't last time.
89 transformer.pauseApply();
90 modifyAsset("app|foo.txt", "yes");
91 updateSources(["app|foo.txt"]);
92 expectAssetDoesNotComplete("app|foo.out");
93
94 transformer.resumeApply();
95 expectAsset("app|foo.out", "done");
96 buildShouldSucceed();
97 });
98
99 test("doesn't block on on getting an undeclared asset that wasn't generated "
100 "last run", () {
101 var transformer = new DeclaringCheckContentAndRenameTransformer(
102 oldExtension: "txt", oldContent: "yes",
103 newExtension: "out", newContent: "done");
104 initGraph({"app|foo.txt": "no"}, {"app": [[transformer]]});
105
106 updateSources(["app|foo.txt"]);
107 expectNoAsset("app|foo.out");
108 buildShouldSucceed();
109
110 transformer.pauseApply();
111 modifyAsset("app|foo.txt", "yes");
112 updateSources(["app|foo.txt"]);
113 expectNoAsset("app|undeclared.out");
114
115 transformer.resumeApply();
116 buildShouldSucceed();
117 });
118
119 test("fails to get a consumed asset before apply is finished when a sibling "
120 "has finished applying", () {
121 var transformer = new DeclaringRewriteTransformer("blub", "blab")
122 ..consumePrimary = true;
123 initGraph(["app|foo.blub", "app|foo.txt"], {"app": [[
124 transformer,
125 new RewriteTransformer("txt", "out")
126 ]]});
127
128 transformer.pauseApply();
129 updateSources(["app|foo.blub", "app|foo.txt"]);
130 expectAsset("app|foo.out", "foo.out");
131 expectNoAsset("app|foo.blub");
132
133 transformer.resumeApply();
134 buildShouldSucceed();
135 });
136
137 test("blocks getting a consumed asset before apply is finished when a "
138 "sibling hasn't finished applying", () {
139 var declaring = new DeclaringRewriteTransformer("blub", "blab")
140 ..consumePrimary = true;
141 var eager = new RewriteTransformer("txt", "out");
142 initGraph(["app|foo.blub", "app|foo.txt"], {"app": [[declaring, eager]]});
143
144 declaring.pauseApply();
145 eager.pauseApply();
146 updateSources(["app|foo.blub", "app|foo.txt"]);
147 expectAssetDoesNotComplete("app|foo.blub");
148
149 declaring.resumeApply();
150 eager.resumeApply();
151 expectNoAsset("app|foo.blub");
152 buildShouldSucceed();
153 });
154
155 test("waits until apply is finished to get an overwritten asset", () {
156 var transformer = new DeclaringRewriteTransformer("blub", "blub");
157 initGraph(["app|foo.blub"], {"app": [[transformer]]});
158
159 transformer.pauseApply();
160 updateSources(["app|foo.blub"]);
161 expectAssetDoesNotComplete("app|foo.blub");
162
163 transformer.resumeApply();
164 expectAsset("app|foo.blub", "foo.blub");
165 buildShouldSucceed();
166 });
167
168 test("a declaring transformer following a lazy transformer runs eagerly once "
169 "its input is available", () {
170 var declaring = new DeclaringRewriteTransformer("two", "three");
171 initGraph(["app|foo.in"], {"app": [
172 [new LazyAssetsTransformer(["app|out.one", "app|out.two"])],
173 [declaring]
174 ]});
175
176 updateSources(["app|foo.in"]);
177 // Give the transformers time to declare their assets.
178 schedule(pumpEventQueue);
179
180 expectAsset("app|out.one", "app|out.one");
181 buildShouldSucceed();
182
183 expect(declaring.numRuns, completion(equals(1)));
184 });
185
186 test("a declaring transformer following a lazy transformer doesn't re-run if "
187 "its input becomes available and then unavailable", () {
188 var declaring = new DeclaringRewriteTransformer("two", "three");
189 initGraph(["app|foo.in"], {"app": [
190 [new LazyAssetsTransformer(["app|out.one", "app|out.two"])],
191 [declaring]
192 ]});
193
194 declaring.pauseApply();
195 updateSources(["app|foo.in"]);
196 // Give the transformers time to declare their assets.
197 schedule(pumpEventQueue);
198
199 // Start [declaring] running, because its input became available.
200 expectAsset("app|out.one", "app|out.one");
201
202 // Make sure we're blocking on [declaring.apply].
203 schedule(pumpEventQueue);
204
205 // Now [declaring]'s input is dirty, so it shouldn't re-run without an
206 // explicit request.
207 updateSources(["app|foo.in"]);
208 declaring.resumeApply();
209 buildShouldSucceed();
210
211 // [declaring] should only have run once, despite its input changing. After
212 // the first run, it should be awaiting a force() call.
213 expect(declaring.numRuns, completion(equals(1)));
214
215 // Once we make a request, [declaring] should force the lazy transformer and
216 // then run itself.
217 expectAsset("app|out.three", "app|out.two.three");
218 buildShouldSucceed();
219
220 // Now [declaring] should have run twice. This ensures that it didn't use
221 // its original output for some reason.
222 expect(declaring.numRuns, completion(equals(2)));
223 });
224
225 test("a declaring transformer following a lazy transformer does re-run if "
226 "its input becomes available, it's forced, and then its input becomes "
227 "unavailable", () {
228 var declaring = new DeclaringRewriteTransformer("two", "three");
229 initGraph(["app|foo.in"], {"app": [
230 [new LazyAssetsTransformer(["app|out.one", "app|out.two"])],
231 [declaring]
232 ]});
233
234 declaring.pauseApply();
235 updateSources(["app|foo.in"]);
236
237 // Give the transformers time to declare their assets.
238 schedule(pumpEventQueue);
239
240 // Start [declaring] running, because its input became available.
241 expectAsset("app|out.one", "app|out.one");
242
243 // This shouldn't complete because [declaring.apply] is paused, but it
244 // should force the transformer.
245 expectAssetDoesNotComplete("app|out.three");
246
247 // Make sure we're blocking on [declaring.apply]
248 schedule(pumpEventQueue);
249
250 // Now [declaring]'s input is dirty, so it shouldn't re-run without an
251 // explicit request.
252 updateSources(["app|foo.in"]);
253 declaring.resumeApply();
254 buildShouldSucceed();
255
256 // [declaring] should have run twice, once for its original input and once
257 // after the input changed because it was forced.
258 expect(declaring.numRuns, completion(equals(2)));
259 });
260
261 group("with an error in declareOutputs", () {
262 test("still runs apply", () {
263 initGraph(["app|foo.txt"], {"app": [[
264 new DeclaringBadTransformer("app|out.txt",
265 declareError: true, applyError: false)
266 ]]});
267
268 updateSources(["app|foo.txt"]);
269 expectAsset("app|out.txt", "bad out");
270 expectAsset("app|foo.txt", "foo");
271 buildShouldFail([isTransformerException(BadTransformer.ERROR)]);
272 });
273
274 test("waits for apply to complete before passing through the input even if "
275 "consumePrimary was called", () {
276 var transformer = new DeclaringBadTransformer("app|out.txt",
277 declareError: true, applyError: false)..consumePrimary = true;
278 initGraph(["app|foo.txt"], {"app": [[transformer]]});
279
280 transformer.pauseApply();
281 updateSources(["app|foo.txt"]);
282 expectAssetDoesNotComplete("app|out.txt");
283 expectAssetDoesNotComplete("app|foo.txt");
284
285 transformer.resumeApply();
286 expectAsset("app|out.txt", "bad out");
287 expectNoAsset("app|foo.txt");
288 buildShouldFail([isTransformerException(BadTransformer.ERROR)]);
289 });
290 });
291
292 test("with an error in apply still passes through the input", () {
293 initGraph(["app|foo.txt"], {"app": [[
294 new DeclaringBadTransformer("app|out.txt",
295 declareError: false, applyError: true)
296 ]]});
297
298 updateSources(["app|foo.txt"]);
299 expectNoAsset("app|out.txt");
300 expectAsset("app|foo.txt", "foo");
301 buildShouldFail([isTransformerException(BadTransformer.ERROR)]);
302 });
303
304 test("can emit outputs it didn't declare", () {
305 initGraph(["app|foo.txt"], {"app": [
306 [new DeclareAssetsTransformer([], emitted: ["app|out.txt"])]
307 ]});
308
309 updateSources(["app|foo.txt"]);
310 // There's probably going to be some time when "out.txt" is unavailable,
311 // since it was undeclared.
312 schedule(pumpEventQueue);
313 expectAsset("app|out.txt", "app|out.txt");
314 buildShouldSucceed();
315 });
316
317 test("can overwrite the primary input even if it declared that it wouldn't",
318 () {
319 var transformer = new DeclareAssetsTransformer(
320 [], emitted: ["app|foo.txt"]);
321 initGraph(["app|foo.txt"], {"app": [[transformer]]});
322
323 transformer.pauseApply();
324 updateSources(["app|foo.txt"]);
325 expectAsset("app|foo.txt", "foo");
326
327 transformer.resumeApply();
328 schedule(pumpEventQueue);
329 expectAsset("app|foo.txt", "app|foo.txt");
330 buildShouldSucceed();
331 });
332
333 test("can declare outputs it doesn't emit", () {
334 initGraph(["app|foo.txt"], {"app": [
335 [new DeclareAssetsTransformer(["app|out.txt"], emitted: [])]
336 ]});
337
338 updateSources(["app|foo.txt"]);
339 expectNoAsset("app|out.txt");
340 buildShouldSucceed();
341 });
342 }
OLDNEW
« no previous file with comments | « pkg/barback/test/package_graph/collisions_test.dart ('k') | pkg/barback/test/package_graph/errors_test.dart » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698