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

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

Issue 180473003: Barback transforms now pass through the primary input by default. (Closed) Base URL: https://dart.googlecode.com/svn/branches/bleeding_edge/dart
Patch Set: code reivew Created 6 years, 9 months 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
« no previous file with comments | « pkg/barback/lib/src/phase_output.dart ('k') | pkg/barback/test/package_graph/errors_test.dart » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
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.package_graph.transform_test; 5 library barback.test.package_graph.transform_test;
6 6
7 import 'package:barback/src/utils.dart'; 7 import 'package:barback/src/utils.dart';
8 import 'package:scheduled_test/scheduled_test.dart'; 8 import 'package:scheduled_test/scheduled_test.dart';
9 9
10 import '../utils.dart'; 10 import '../utils.dart';
11 11
12 main() { 12 main() {
13 initConfig(); 13 initConfig();
14 test("a new transformer is applied to a matching asset", () { 14 test("a new transformer is applied to a matching asset", () {
15 initGraph(["app|foo.blub"]); 15 initGraph(["app|foo.blub"]);
16 16
17 updateSources(["app|foo.blub"]); 17 updateSources(["app|foo.blub"]);
18 expectAsset("app|foo.blub", "foo"); 18 expectAsset("app|foo.blub", "foo");
19 buildShouldSucceed(); 19 buildShouldSucceed();
20 20
21 updateTransformers("app", [[new RewriteTransformer("blub", "blab")]]); 21 updateTransformers("app", [[new RewriteTransformer("blub", "blab")]]);
22 expectAsset("app|foo.blab", "foo.blab"); 22 expectAsset("app|foo.blab", "foo.blab");
23 expectNoAsset("app|foo.blub");
24 buildShouldSucceed(); 23 buildShouldSucceed();
25 }); 24 });
26 25
27 test("a new transformer is not applied to a non-matching asset", () { 26 test("a new transformer is not applied to a non-matching asset", () {
28 initGraph(["app|foo.blub"]); 27 initGraph(["app|foo.blub"]);
29 28
30 updateSources(["app|foo.blub"]); 29 updateSources(["app|foo.blub"]);
31 expectAsset("app|foo.blub", "foo"); 30 expectAsset("app|foo.blub", "foo");
32 buildShouldSucceed(); 31 buildShouldSucceed();
33 32
34 updateTransformers("app", [[new RewriteTransformer("zip", "zap")]]); 33 updateTransformers("app", [[new RewriteTransformer("zip", "zap")]]);
35 expectAsset("app|foo.blub", "foo"); 34 expectAsset("app|foo.blub", "foo");
36 expectNoAsset("app|foo.zap"); 35 expectNoAsset("app|foo.zap");
37 buildShouldSucceed(); 36 buildShouldSucceed();
38 }); 37 });
39 38
40 test("updateTransformers doesn't re-run an old transformer", () { 39 test("updateTransformers doesn't re-run an old transformer", () {
41 var rewrite = new RewriteTransformer("blub", "blab"); 40 var rewrite = new RewriteTransformer("blub", "blab");
42 initGraph(["app|foo.blub"], {"app": [[rewrite]]}); 41 initGraph(["app|foo.blub"], {"app": [[rewrite]]});
43 42
44 updateSources(["app|foo.blub"]); 43 updateSources(["app|foo.blub"]);
45 expectAsset("app|foo.blab", "foo.blab"); 44 expectAsset("app|foo.blab", "foo.blab");
46 expectNoAsset("app|foo.blub");
47 buildShouldSucceed(); 45 buildShouldSucceed();
48 46
49 updateTransformers("app", [[rewrite]]); 47 updateTransformers("app", [[rewrite]]);
50 expectAsset("app|foo.blab", "foo.blab"); 48 expectAsset("app|foo.blab", "foo.blab");
51 expectNoAsset("app|foo.blub");
52 buildShouldSucceed(); 49 buildShouldSucceed();
53 50
54 expect(rewrite.numRuns, completion(equals(1))); 51 expect(rewrite.numRuns, completion(equals(1)));
55 }); 52 });
56 53
57 test("updateTransformers re-runs old transformers in a new phase", () { 54 test("updateTransformers re-runs old transformers in a new phase", () {
58 var rewrite1 = new RewriteTransformer("txt", "blub"); 55 var rewrite1 = new RewriteTransformer("txt", "blub");
59 var rewrite2 = new RewriteTransformer("blub", "blab"); 56 var rewrite2 = new RewriteTransformer("blub", "blab");
60 initGraph(["app|foo.txt"], {"app": [[rewrite1], [rewrite2]]}); 57 initGraph(["app|foo.txt"], {"app": [[rewrite1], [rewrite2]]});
61 58
62 updateSources(["app|foo.txt"]); 59 updateSources(["app|foo.txt"]);
63 expectAsset("app|foo.blab", "foo.blub.blab"); 60 expectAsset("app|foo.blab", "foo.blub.blab");
64 expectNoAsset("app|foo.blub");
65 buildShouldSucceed(); 61 buildShouldSucceed();
66 62
67 updateTransformers("app", [[rewrite2], [rewrite1]]); 63 updateTransformers("app", [[rewrite2], [rewrite1]]);
68 expectAsset("app|foo.blub", "foo.blub"); 64 expectAsset("app|foo.blub", "foo.blub");
69 expectNoAsset("app|foo.blab"); 65 expectNoAsset("app|foo.blab");
70 buildShouldSucceed(); 66 buildShouldSucceed();
71 }); 67 });
72 68
73 test("updateTransformers re-runs an old transformer when a previous phase " 69 test("updateTransformers re-runs an old transformer when a previous phase "
74 "changes", () { 70 "changes", () {
(...skipping 12 matching lines...) Expand all
87 buildShouldSucceed(); 83 buildShouldSucceed();
88 }); 84 });
89 85
90 test("a removed transformer is no longer applied", () { 86 test("a removed transformer is no longer applied", () {
91 initGraph(["app|foo.blub"], {"app": [ 87 initGraph(["app|foo.blub"], {"app": [
92 [new RewriteTransformer("blub", "blab")] 88 [new RewriteTransformer("blub", "blab")]
93 ]}); 89 ]});
94 90
95 updateSources(["app|foo.blub"]); 91 updateSources(["app|foo.blub"]);
96 expectAsset("app|foo.blab", "foo.blab"); 92 expectAsset("app|foo.blab", "foo.blab");
97 expectNoAsset("app|foo.blub");
98 buildShouldSucceed(); 93 buildShouldSucceed();
99 94
100 updateTransformers("app", []); 95 updateTransformers("app", []);
101 expectAsset("app|foo.blub", "foo"); 96 expectAsset("app|foo.blub", "foo");
102 expectNoAsset("app|foo.blab"); 97 expectNoAsset("app|foo.blab");
103 buildShouldSucceed(); 98 buildShouldSucceed();
104 }); 99 });
105 100
106 test("a new transformer is pipelined", () { 101 test("a new transformer is pipelined", () {
107 var rewrite1 = new RewriteTransformer("source", "phase1"); 102 var rewrite1 = new RewriteTransformer("source", "phase1");
(...skipping 77 matching lines...) Expand 10 before | Expand all | Expand 10 after
185 180
186 updateTransformers("app", [ 181 updateTransformers("app", [
187 [rewrite, new RewriteTransformer("blib", "blob")] 182 [rewrite, new RewriteTransformer("blib", "blob")]
188 ]); 183 ]);
189 rewrite.resumeIsPrimary("app|foo.blub"); 184 rewrite.resumeIsPrimary("app|foo.blub");
190 expectAsset("app|foo.blab", "foo.blab"); 185 expectAsset("app|foo.blab", "foo.blab");
191 expectAsset("app|bar.blob", "bar.blob"); 186 expectAsset("app|bar.blob", "bar.blob");
192 buildShouldSucceed(); 187 buildShouldSucceed();
193 }); 188 });
194 189
195 test("a new transformer can see pass-through assets", () {
196 var rewrite = new RewriteTransformer("zip", "zap");
197 initGraph(["app|foo.blub"], {"app": [[rewrite]]});
198
199 updateSources(["app|foo.blub"]);
200 buildShouldSucceed();
201
202 updateTransformers("app", [
203 [rewrite],
204 [new RewriteTransformer("blub", "blab")]
205 ]);
206 expectAsset("app|foo.blab", "foo.blab");
207 expectNoAsset("app|foo.blub");
208 buildShouldSucceed();
209 });
210
211 test("a cross-package transform sees a new transformer in a new phase", () { 190 test("a cross-package transform sees a new transformer in a new phase", () {
212 var rewrite = new RewriteTransformer("inc", "inc"); 191 var rewrite = new RewriteTransformer("inc", "inc");
213 initGraph({ 192 initGraph({
214 "pkg1|foo.txt": "pkg2|foo.inc", 193 "pkg1|foo.txt": "pkg2|foo.inc",
215 "pkg2|foo.inc": "foo" 194 "pkg2|foo.inc": "foo"
216 }, { 195 }, {
217 "pkg1": [[new ManyToOneTransformer("txt")]], 196 "pkg1": [[new ManyToOneTransformer("txt")]],
218 "pkg2": [[rewrite]] 197 "pkg2": [[rewrite]]
219 }); 198 });
220 199
(...skipping 25 matching lines...) Expand all
246 225
247 updateSources(["pkg1|foo.txt", "pkg2|foo.inc"]); 226 updateSources(["pkg1|foo.txt", "pkg2|foo.inc"]);
248 expectAsset("pkg1|foo.out", "foo.inc.inc"); 227 expectAsset("pkg1|foo.out", "foo.inc.inc");
249 buildShouldSucceed(); 228 buildShouldSucceed();
250 229
251 updateTransformers("pkg2", [[rewrite]]); 230 updateTransformers("pkg2", [[rewrite]]);
252 expectAsset("pkg1|foo.out", "foo.inc"); 231 expectAsset("pkg1|foo.out", "foo.inc");
253 buildShouldSucceed(); 232 buildShouldSucceed();
254 }); 233 });
255 234
235 group("pass-through", () {
236 test("a new transformer can see pass-through assets", () {
237 var rewrite = new RewriteTransformer("zip", "zap");
238 initGraph(["app|foo.blub"], {"app": [[rewrite]]});
239
240 updateSources(["app|foo.blub"]);
241 buildShouldSucceed();
242
243 updateTransformers("app", [
244 [rewrite],
245 [new RewriteTransformer("blub", "blab")]
246 ]);
247 expectAsset("app|foo.blab", "foo.blab");
248 buildShouldSucceed();
249 });
250
251 test("a new transformer can overwrite an old asset", () {
252 var rewrite = new RewriteTransformer("zip", "zap");
253 initGraph(["app|foo.txt"], {"app": [[rewrite]]});
254
255 updateSources(["app|foo.txt"]);
256 expectAsset("app|foo.txt", "foo");
257 buildShouldSucceed();
258
259 // Add a transformer that will overwrite the previously-passed-through
260 // "foo.txt" asset. The transformed asset should be emitted, not the
261 // passed-through asset.
262 updateTransformers("app", [
263 [rewrite, new RewriteTransformer("txt", "txt")]
264 ]);
265 expectAsset("app|foo.txt", "foo.txt");
266 buildShouldSucceed();
267 });
268
269 test("passes an asset through when an overwriting transform is removed",
270 () {
271 initGraph(["app|foo.txt"], {
272 "app": [[new RewriteTransformer("txt", "txt")]]
273 });
274
275 updateSources(["app|foo.txt"]);
276 expectAsset("app|foo.txt", "foo.txt");
277 buildShouldSucceed();
278
279 updateTransformers("app", [[]]);
280 expectAsset("app|foo.txt", "foo");
281 buildShouldSucceed();
282 });
283
284 test("passes an asset through when its overwriting transform is removed "
285 "during apply", () {
286 var rewrite = new RewriteTransformer("txt", "txt");
287 initGraph(["app|foo.txt"], {"app": [[rewrite]]});
288
289 rewrite.pauseApply();
290 updateSources(["app|foo.txt"]);
291 expectAssetDoesNotComplete("app|foo.txt");
292
293 updateTransformers("app", [[]]);
294 rewrite.resumeApply();
295 expectAsset("app|foo.txt", "foo");
296 buildShouldSucceed();
297 });
298
299 test("doesn't pass an asset through when its overwriting transform is "
300 "removed during apply if another transform overwrites it", () {
301 var rewrite1 = new RewriteTransformer("txt", "txt");
302 var rewrite2 = new RewriteTransformer("txt", "txt");
303 initGraph(["app|foo.txt"], {"app": [[rewrite1, rewrite2]]});
304
305 rewrite1.pauseApply();
306 updateSources(["app|foo.txt"]);
307 expectAssetDoesNotComplete("app|foo.txt");
308 // Ensure we're waiting on [rewrite1.apply]
309 schedule(pumpEventQueue);
310
311 updateTransformers("app", [[rewrite2]]);
312 rewrite1.resumeApply();
313 expectAsset("app|foo.txt", "foo.txt");
314 buildShouldSucceed();
315 });
316
317 test("doesn't pass an asset through when one overwriting transform is "
318 "removed if another transform still overwrites it", () {
319 var rewrite = new RewriteTransformer("txt", "txt");
320 initGraph(["app|foo.txt"], {"app": [[
321 rewrite,
322 new RewriteTransformer("txt", "txt")
323 ]]});
324
325 updateSources(["app|foo.txt"]);
326 // This could be either the output of [CheckContentTransformer] or
327 // [RewriteTransformer], depending which completes first.
328 expectAsset("app|foo.txt", anything);
329 buildShouldFail([isAssetCollisionException("app|foo.txt")]);
330
331 updateTransformers("app", [[rewrite]]);
332 expectAsset("app|foo.txt", "foo.txt");
333 buildShouldSucceed();
334 });
335 });
336
256 // Regression test. 337 // Regression test.
257 test("a phase is added, then an input is removed and re-added", () { 338 test("a phase is added, then an input is removed and re-added", () {
258 var rewrite = new RewriteTransformer("txt", "mid"); 339 var rewrite = new RewriteTransformer("txt", "mid");
259 initGraph(["app|foo.txt"], { 340 initGraph(["app|foo.txt"], {
260 "app": [[rewrite]] 341 "app": [[rewrite]]
261 }); 342 });
262 343
263 updateSources(["app|foo.txt"]); 344 updateSources(["app|foo.txt"]);
264 expectAsset("app|foo.mid", "foo.mid"); 345 expectAsset("app|foo.mid", "foo.mid");
265 buildShouldSucceed(); 346 buildShouldSucceed();
266 347
267 updateTransformers("app", [ 348 updateTransformers("app", [
268 [rewrite], 349 [rewrite],
269 [new RewriteTransformer("mid", "out")] 350 [new RewriteTransformer("mid", "out")]
270 ]); 351 ]);
271 expectAsset("app|foo.out", "foo.mid.out"); 352 expectAsset("app|foo.out", "foo.mid.out");
272 buildShouldSucceed(); 353 buildShouldSucceed();
273 354
274 removeSources(["app|foo.txt"]); 355 removeSources(["app|foo.txt"]);
275 expectNoAsset("app|foo.out"); 356 expectNoAsset("app|foo.out");
276 buildShouldSucceed(); 357 buildShouldSucceed();
277 358
278 updateSources(["app|foo.txt"]); 359 updateSources(["app|foo.txt"]);
279 expectAsset("app|foo.out", "foo.mid.out"); 360 expectAsset("app|foo.out", "foo.mid.out");
280 buildShouldSucceed(); 361 buildShouldSucceed();
281 }); 362 });
282 } 363 }
OLDNEW
« no previous file with comments | « pkg/barback/lib/src/phase_output.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