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

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

Issue 22371005: Consistently schedule operations in the barback tests. (Closed) Base URL: https://dart.googlecode.com/svn/branches/bleeding_edge/dart
Patch Set: Created 7 years, 4 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
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 'dart:async'; 7 import 'dart:async';
8 8
9 import 'package:barback/barback.dart'; 9 import 'package:barback/barback.dart';
10 import 'package:barback/src/utils.dart'; 10 import 'package:barback/src/utils.dart';
(...skipping 77 matching lines...) Expand 10 before | Expand all | Expand 10 after
88 }); 88 });
89 89
90 test("only runs a transform once for all of its outputs", () { 90 test("only runs a transform once for all of its outputs", () {
91 var transformer = new RewriteTransformer("blub", "a b c"); 91 var transformer = new RewriteTransformer("blub", "a b c");
92 initGraph(["app|foo.blub"], {"app": [[transformer]]}); 92 initGraph(["app|foo.blub"], {"app": [[transformer]]});
93 updateSources(["app|foo.blub"]); 93 updateSources(["app|foo.blub"]);
94 expectAsset("app|foo.a", "foo.a"); 94 expectAsset("app|foo.a", "foo.a");
95 expectAsset("app|foo.b", "foo.b"); 95 expectAsset("app|foo.b", "foo.b");
96 expectAsset("app|foo.c", "foo.c"); 96 expectAsset("app|foo.c", "foo.c");
97 buildShouldSucceed(); 97 buildShouldSucceed();
98 schedule(() { 98 expect(transformer.numRuns, completion(equals(1)));
99 expect(transformer.numRuns, equals(1));
100 });
101 }); 99 });
102 100
103 test("runs transforms in the same phase in parallel", () { 101 test("runs transforms in the same phase in parallel", () {
104 var transformerA = new RewriteTransformer("txt", "a"); 102 var transformerA = new RewriteTransformer("txt", "a");
105 var transformerB = new RewriteTransformer("txt", "b"); 103 var transformerB = new RewriteTransformer("txt", "b");
106 initGraph(["app|foo.txt"], {"app": [[transformerA, transformerB]]}); 104 initGraph(["app|foo.txt"], {"app": [[transformerA, transformerB]]});
107 105
108 transformerA.pauseApply(); 106 transformerA.pauseApply();
109 transformerB.pauseApply(); 107 transformerB.pauseApply();
110 108
111 schedule(() { 109 updateSources(["app|foo.txt"]);
112 updateSources(["app|foo.txt"]);
113 110
114 // Wait for them both to start. 111 // Wait for them both to start.
115 return Future.wait([transformerA.started, transformerB.started]); 112 transformerA.waitUntilStarted();
116 }); 113 transformerB.waitUntilStarted();
117 114
118 schedule(() { 115 // They should both still be running.
119 // They should both still be running. 116 expect(transformerA.isRunning, completion(isTrue));
120 expect(transformerA.isRunning, isTrue); 117 expect(transformerB.isRunning, completion(isTrue));
121 expect(transformerB.isRunning, isTrue);
122 118
123 transformerA.resumeApply(); 119 transformerA.resumeApply();
124 transformerB.resumeApply(); 120 transformerB.resumeApply();
125 });
126 121
127 expectAsset("app|foo.a", "foo.a"); 122 expectAsset("app|foo.a", "foo.a");
128 expectAsset("app|foo.b", "foo.b"); 123 expectAsset("app|foo.b", "foo.b");
129 buildShouldSucceed(); 124 buildShouldSucceed();
130 }); 125 });
131 126
132 test("outputs are inaccessible once used", () { 127 test("outputs are inaccessible once used", () {
133 initGraph(["app|foo.a"], {"app": [ 128 initGraph(["app|foo.a"], {"app": [
134 [new RewriteTransformer("a", "b")], 129 [new RewriteTransformer("a", "b")],
135 [new RewriteTransformer("a", "c")] 130 [new RewriteTransformer("a", "c")]
136 ]}); 131 ]});
137 updateSources(["app|foo.a"]); 132 updateSources(["app|foo.a"]);
138 expectAsset("app|foo.b", "foo.b"); 133 expectAsset("app|foo.b", "foo.b");
139 expectNoAsset("app|foo.a"); 134 expectNoAsset("app|foo.a");
140 expectNoAsset("app|foo.c"); 135 expectNoAsset("app|foo.c");
141 buildShouldSucceed(); 136 buildShouldSucceed();
142 }); 137 });
143 138
144 test("does not reapply transform when inputs are not modified", () { 139 test("does not reapply transform when inputs are not modified", () {
145 var transformer = new RewriteTransformer("blub", "blab"); 140 var transformer = new RewriteTransformer("blub", "blab");
146 initGraph(["app|foo.blub"], {"app": [[transformer]]}); 141 initGraph(["app|foo.blub"], {"app": [[transformer]]});
147 updateSources(["app|foo.blub"]); 142 updateSources(["app|foo.blub"]);
148 expectAsset("app|foo.blab", "foo.blab"); 143 expectAsset("app|foo.blab", "foo.blab");
149 expectAsset("app|foo.blab", "foo.blab"); 144 expectAsset("app|foo.blab", "foo.blab");
150 expectAsset("app|foo.blab", "foo.blab"); 145 expectAsset("app|foo.blab", "foo.blab");
151 buildShouldSucceed(); 146 buildShouldSucceed();
152 147
153 schedule(() { 148 expect(transformer.numRuns, completion(equals(1)));
154 expect(transformer.numRuns, equals(1));
155 });
156 }); 149 });
157 150
158 test("reapplies a transform when its input is modified", () { 151 test("reapplies a transform when its input is modified", () {
159 var transformer = new RewriteTransformer("blub", "blab"); 152 var transformer = new RewriteTransformer("blub", "blab");
160 initGraph(["app|foo.blub"], {"app": [[transformer]]}); 153 initGraph(["app|foo.blub"], {"app": [[transformer]]});
161 154
162 schedule(() { 155 updateSources(["app|foo.blub"]);
163 updateSources(["app|foo.blub"]);
164 });
165
166 expectAsset("app|foo.blab", "foo.blab"); 156 expectAsset("app|foo.blab", "foo.blab");
167 buildShouldSucceed(); 157 buildShouldSucceed();
168 158
169 schedule(() { 159 updateSources(["app|foo.blub"]);
170 updateSources(["app|foo.blub"]);
171 });
172
173 expectAsset("app|foo.blab", "foo.blab"); 160 expectAsset("app|foo.blab", "foo.blab");
174 buildShouldSucceed(); 161 buildShouldSucceed();
175 162
176 schedule(() { 163 updateSources(["app|foo.blub"]);
177 updateSources(["app|foo.blub"]);
178 });
179
180 expectAsset("app|foo.blab", "foo.blab"); 164 expectAsset("app|foo.blab", "foo.blab");
181 buildShouldSucceed(); 165 buildShouldSucceed();
182 166
183 schedule(() { 167 expect(transformer.numRuns, completion(equals(3)));
184 expect(transformer.numRuns, equals(3));
185 });
186 }); 168 });
187 169
188 test("does not reapply transform when a removed input is modified", () { 170 test("does not reapply transform when a removed input is modified", () {
189 var transformer = new ManyToOneTransformer("txt"); 171 var transformer = new ManyToOneTransformer("txt");
190 initGraph({ 172 initGraph({
191 "app|a.txt": "a.inc,b.inc", 173 "app|a.txt": "a.inc,b.inc",
192 "app|a.inc": "a", 174 "app|a.inc": "a",
193 "app|b.inc": "b" 175 "app|b.inc": "b"
194 }, {"app": [[transformer]]}); 176 }, {"app": [[transformer]]});
195 177
196 updateSources(["app|a.txt", "app|a.inc", "app|b.inc"]); 178 updateSources(["app|a.txt", "app|a.inc", "app|b.inc"]);
197 179
198 expectAsset("app|a.out", "ab"); 180 expectAsset("app|a.out", "ab");
199 buildShouldSucceed(); 181 buildShouldSucceed();
200 182
201 // Remove the dependency on the non-primary input. 183 // Remove the dependency on the non-primary input.
202 modifyAsset("app|a.txt", "a.inc"); 184 modifyAsset("app|a.txt", "a.inc");
203 schedule(() => updateSources(["app|a.txt"])); 185 updateSources(["app|a.txt"]);
204 186
205 // Process it again. 187 // Process it again.
206 expectAsset("app|a.out", "a"); 188 expectAsset("app|a.out", "a");
207 buildShouldSucceed(); 189 buildShouldSucceed();
208 190
209 // Now touch the removed input. It should not trigger another build. 191 // Now touch the removed input. It should not trigger another build.
210 schedule(() { 192 updateSources(["app|b.inc"]);
211 updateSources(["app|b.inc"]);
212 });
213
214 expectAsset("app|a.out", "a"); 193 expectAsset("app|a.out", "a");
215 buildShouldSucceed(); 194 buildShouldSucceed();
216 195
217 schedule(() { 196 expect(transformer.numRuns, completion(equals(2)));
218 expect(transformer.numRuns, equals(2));
219 });
220 }); 197 });
221 198
222 test("allows a transform to generate multiple outputs", () { 199 test("allows a transform to generate multiple outputs", () {
223 initGraph({"app|foo.txt": "a.out,b.out"}, {"app": [ 200 initGraph({"app|foo.txt": "a.out,b.out"}, {"app": [
224 [new OneToManyTransformer("txt")] 201 [new OneToManyTransformer("txt")]
225 ]}); 202 ]});
226 203
227 updateSources(["app|foo.txt"]); 204 updateSources(["app|foo.txt"]);
228 205
229 expectAsset("app|a.out", "spread txt"); 206 expectAsset("app|a.out", "spread txt");
(...skipping 11 matching lines...) Expand all
241 [aa, bb], 218 [aa, bb],
242 ]}); 219 ]});
243 220
244 updateSources(["app|foo.a"]); 221 updateSources(["app|foo.a"]);
245 updateSources(["app|foo.b"]); 222 updateSources(["app|foo.b"]);
246 223
247 expectAsset("app|foo.aaa", "foo.aa.aaa"); 224 expectAsset("app|foo.aaa", "foo.aa.aaa");
248 expectAsset("app|foo.bbb", "foo.bb.bbb"); 225 expectAsset("app|foo.bbb", "foo.bb.bbb");
249 buildShouldSucceed(); 226 buildShouldSucceed();
250 227
251 schedule(() { 228 updateSources(["app|foo.a"]);
252 updateSources(["app|foo.a"]);
253 });
254
255 expectAsset("app|foo.aaa", "foo.aa.aaa"); 229 expectAsset("app|foo.aaa", "foo.aa.aaa");
256 expectAsset("app|foo.bbb", "foo.bb.bbb"); 230 expectAsset("app|foo.bbb", "foo.bb.bbb");
257 buildShouldSucceed(); 231 buildShouldSucceed();
258 232
259 schedule(() { 233 expect(aa.numRuns, completion(equals(2)));
260 expect(aa.numRuns, equals(2)); 234 expect(bb.numRuns, completion(equals(1)));
261 expect(bb.numRuns, equals(1));
262 });
263 }); 235 });
264 236
265 test("doesn't get an output from a transform whose primary input is removed", 237 test("doesn't get an output from a transform whose primary input is removed",
266 () { 238 () {
267 initGraph(["app|foo.txt"], {"app": [ 239 initGraph(["app|foo.txt"], {"app": [
268 [new RewriteTransformer("txt", "out")] 240 [new RewriteTransformer("txt", "out")]
269 ]}); 241 ]});
270 242
271 updateSources(["app|foo.txt"]); 243 updateSources(["app|foo.txt"]);
272 expectAsset("app|foo.out", "foo.out"); 244 expectAsset("app|foo.out", "foo.out");
273 buildShouldSucceed(); 245 buildShouldSucceed();
274 246
275 schedule(() { 247 removeSources(["app|foo.txt"]);
276 removeSources(["app|foo.txt"]);
277 });
278
279 expectNoAsset("app|foo.out"); 248 expectNoAsset("app|foo.out");
280 buildShouldSucceed(); 249 buildShouldSucceed();
281 }); 250 });
282 251
283 test("discards outputs from a transform whose primary input is removed " 252 test("discards outputs from a transform whose primary input is removed "
284 "during processing", () { 253 "during processing", () {
285 var rewrite = new RewriteTransformer("txt", "out"); 254 var rewrite = new RewriteTransformer("txt", "out");
286 initGraph(["app|foo.txt"], {"app": [[rewrite]]}); 255 initGraph(["app|foo.txt"], {"app": [[rewrite]]});
287 256
288 rewrite.pauseApply(); 257 rewrite.pauseApply();
289 updateSources(["app|foo.txt"]); 258 updateSources(["app|foo.txt"]);
290 schedule(() => rewrite.started); 259 rewrite.waitUntilStarted();
291 schedule(() {
292 removeSources(["app|foo.txt"]);
293 rewrite.resumeApply();
294 });
295 260
261 removeSources(["app|foo.txt"]);
262 rewrite.resumeApply();
296 expectNoAsset("app|foo.out"); 263 expectNoAsset("app|foo.out");
297 buildShouldSucceed(); 264 buildShouldSucceed();
298 }); 265 });
299 266
300 test("reapplies a transform when a non-primary input changes", () { 267 test("reapplies a transform when a non-primary input changes", () {
301 initGraph({ 268 initGraph({
302 "app|a.txt": "a.inc", 269 "app|a.txt": "a.inc",
303 "app|a.inc": "a" 270 "app|a.inc": "a"
304 }, {"app": [[new ManyToOneTransformer("txt")]]}); 271 }, {"app": [[new ManyToOneTransformer("txt")]]});
305 272
306 updateSources(["app|a.txt", "app|a.inc"]); 273 updateSources(["app|a.txt", "app|a.inc"]);
307 expectAsset("app|a.out", "a"); 274 expectAsset("app|a.out", "a");
308 buildShouldSucceed(); 275 buildShouldSucceed();
309 276
310 modifyAsset("app|a.inc", "after"); 277 modifyAsset("app|a.inc", "after");
311 schedule(() => updateSources(["app|a.inc"])); 278 updateSources(["app|a.inc"]);
312 279
313 expectAsset("app|a.out", "after"); 280 expectAsset("app|a.out", "after");
314 buildShouldSucceed(); 281 buildShouldSucceed();
315 }); 282 });
316 283
317 test("applies a transform when it becomes newly primary", () { 284 test("applies a transform when it becomes newly primary", () {
318 initGraph({ 285 initGraph({
319 "app|foo.txt": "this", 286 "app|foo.txt": "this",
320 }, {"app": [[new CheckContentTransformer("that", " and the other")]]}); 287 }, {"app": [[new CheckContentTransformer("that", " and the other")]]});
321 288
322 updateSources(["app|foo.txt"]); 289 updateSources(["app|foo.txt"]);
323 expectAsset("app|foo.txt", "this"); 290 expectAsset("app|foo.txt", "this");
324 buildShouldSucceed(); 291 buildShouldSucceed();
325 292
326 modifyAsset("app|foo.txt", "that"); 293 modifyAsset("app|foo.txt", "that");
327 schedule(() => updateSources(["app|foo.txt"])); 294 updateSources(["app|foo.txt"]);
328 295
329 expectAsset("app|foo.txt", "that and the other"); 296 expectAsset("app|foo.txt", "that and the other");
330 buildShouldSucceed(); 297 buildShouldSucceed();
331 }); 298 });
332 299
333 test("applies the correct transform if an asset is modified during isPrimary", 300 test("applies the correct transform if an asset is modified during isPrimary",
334 () { 301 () {
335 var check1 = new CheckContentTransformer("first", "#1"); 302 var check1 = new CheckContentTransformer("first", "#1");
336 var check2 = new CheckContentTransformer("second", "#2"); 303 var check2 = new CheckContentTransformer("second", "#2");
337 initGraph({ 304 initGraph({
338 "app|foo.txt": "first", 305 "app|foo.txt": "first",
339 }, {"app": [[check1, check2]]}); 306 }, {"app": [[check1, check2]]});
340 307
341 check1.pauseIsPrimary("app|foo.txt"); 308 check1.pauseIsPrimary("app|foo.txt");
342 updateSources(["app|foo.txt"]); 309 updateSources(["app|foo.txt"]);
343 // Ensure that we're waiting on check1's isPrimary. 310 // Ensure that we're waiting on check1's isPrimary.
344 schedule(pumpEventQueue); 311 schedule(pumpEventQueue);
345 312
346 modifyAsset("app|foo.txt", "second"); 313 modifyAsset("app|foo.txt", "second");
347 schedule(() { 314 updateSources(["app|foo.txt"]);
348 updateSources(["app|foo.txt"]); 315 check1.resumeIsPrimary("app|foo.txt");
349 check1.resumeIsPrimary("app|foo.txt");
350 });
351 316
352 expectAsset("app|foo.txt", "second#2"); 317 expectAsset("app|foo.txt", "second#2");
353 buildShouldSucceed(); 318 buildShouldSucceed();
354 }); 319 });
355 320
356 test("applies the correct transform if an asset is removed and added during " 321 test("applies the correct transform if an asset is removed and added during "
357 "isPrimary", () { 322 "isPrimary", () {
358 var check1 = new CheckContentTransformer("first", "#1"); 323 var check1 = new CheckContentTransformer("first", "#1");
359 var check2 = new CheckContentTransformer("second", "#2"); 324 var check2 = new CheckContentTransformer("second", "#2");
360 initGraph({ 325 initGraph({
361 "app|foo.txt": "first", 326 "app|foo.txt": "first",
362 }, {"app": [[check1, check2]]}); 327 }, {"app": [[check1, check2]]});
363 328
364 check1.pauseIsPrimary("app|foo.txt"); 329 check1.pauseIsPrimary("app|foo.txt");
365 updateSources(["app|foo.txt"]); 330 updateSources(["app|foo.txt"]);
366 // Ensure that we're waiting on check1's isPrimary. 331 // Ensure that we're waiting on check1's isPrimary.
367 schedule(pumpEventQueue); 332 schedule(pumpEventQueue);
368 333
369 schedule(() => removeSources(["app|foo.txt"])); 334 removeSources(["app|foo.txt"]);
370 modifyAsset("app|foo.txt", "second"); 335 modifyAsset("app|foo.txt", "second");
371 schedule(() { 336 updateSources(["app|foo.txt"]);
372 updateSources(["app|foo.txt"]); 337 check1.resumeIsPrimary("app|foo.txt");
373 check1.resumeIsPrimary("app|foo.txt");
374 });
375 338
376 expectAsset("app|foo.txt", "second#2"); 339 expectAsset("app|foo.txt", "second#2");
377 buildShouldSucceed(); 340 buildShouldSucceed();
378 }); 341 });
379 342
380 test("restarts processing if a change occurs during processing", () { 343 test("restarts processing if a change occurs during processing", () {
381 var transformer = new RewriteTransformer("txt", "out"); 344 var transformer = new RewriteTransformer("txt", "out");
382 initGraph(["app|foo.txt"], {"app": [[transformer]]}); 345 initGraph(["app|foo.txt"], {"app": [[transformer]]});
383 346
384 transformer.pauseApply(); 347 transformer.pauseApply();
385 348
386 schedule(() { 349 updateSources(["app|foo.txt"]);
387 updateSources(["app|foo.txt"]); 350 // Wait for the transform to start.
Bob Nystrom 2013/08/08 21:35:35 This comment is unneeded now. Here and below.
nweiz 2013/08/09 19:41:51 Done.
351 transformer.waitUntilStarted();
388 352
389 // Wait for the transform to start. 353 // Now update the graph during it.
390 return transformer.started; 354 updateSources(["app|foo.txt"]);
391 }); 355 transformer.resumeApply();
392
393 schedule(() {
394 // Now update the graph during it.
395 updateSources(["app|foo.txt"]);
396 transformer.resumeApply();
397 });
398 356
399 expectAsset("app|foo.out", "foo.out"); 357 expectAsset("app|foo.out", "foo.out");
400 buildShouldSucceed(); 358 buildShouldSucceed();
401 359
402 schedule(() { 360 expect(transformer.numRuns, completion(equals(2)));
403 expect(transformer.numRuns, equals(2));
404 });
405 }); 361 });
406 362
407 test("aborts processing if the primary input is removed during processing", 363 test("aborts processing if the primary input is removed during processing",
408 () { 364 () {
409 var transformer = new RewriteTransformer("txt", "out"); 365 var transformer = new RewriteTransformer("txt", "out");
410 initGraph(["app|foo.txt"], {"app": [[transformer]]}); 366 initGraph(["app|foo.txt"], {"app": [[transformer]]});
411 367
412 transformer.pauseApply(); 368 transformer.pauseApply();
413 369
414 schedule(() { 370 updateSources(["app|foo.txt"]);
415 updateSources(["app|foo.txt"]); 371 // Wait for the transform to start.
372 transformer.waitUntilStarted();
416 373
417 // Wait for the transform to start. 374 // Now remove its primary input while it's running.
418 return transformer.started; 375 removeSources(["app|foo.txt"]);
419 }); 376 transformer.resumeApply();
420
421 schedule(() {
422 // Now remove its primary input while it's running.
423 removeSources(["app|foo.txt"]);
424 transformer.resumeApply();
425 });
426 377
427 expectNoAsset("app|foo.out"); 378 expectNoAsset("app|foo.out");
428 buildShouldSucceed(); 379 buildShouldSucceed();
429 380
430 schedule(() { 381 expect(transformer.numRuns, completion(equals(1)));
431 expect(transformer.numRuns, equals(1));
432 });
433 }); 382 });
434 383
435 test("restarts processing if a change to a new secondary input occurs during " 384 test("restarts processing if a change to a new secondary input occurs during "
436 "processing", () { 385 "processing", () {
437 var transformer = new ManyToOneTransformer("txt"); 386 var transformer = new ManyToOneTransformer("txt");
438 initGraph({ 387 initGraph({
439 "app|foo.txt": "bar.inc", 388 "app|foo.txt": "bar.inc",
440 "app|bar.inc": "bar" 389 "app|bar.inc": "bar"
441 }, {"app": [[transformer]]}); 390 }, {"app": [[transformer]]});
442 391
443 transformer.pauseApply(); 392 transformer.pauseApply();
444 393
445 updateSources(["app|foo.txt", "app|bar.inc"]); 394 updateSources(["app|foo.txt", "app|bar.inc"]);
446 // Wait for the transform to start. 395 // Wait for the transform to start.
447 schedule(() => transformer.started); 396 transformer.waitUntilStarted();
448 397
449 // Give the transform time to load bar.inc the first time. 398 // Give the transform time to load bar.inc the first time.
450 schedule(pumpEventQueue); 399 schedule(pumpEventQueue);
451 400
452 // Now update the secondary input before the transform finishes. 401 // Now update the secondary input before the transform finishes.
453 modifyAsset("app|bar.inc", "baz"); 402 modifyAsset("app|bar.inc", "baz");
454 schedule(() => updateSources(["app|bar.inc"])); 403 updateSources(["app|bar.inc"]);
455 // Give bar.inc enough time to be loaded and marked available before the 404 // Give bar.inc enough time to be loaded and marked available before the
456 // transformer completes. 405 // transformer completes.
457 schedule(pumpEventQueue); 406 schedule(pumpEventQueue);
458 407
459 schedule(transformer.resumeApply); 408 transformer.resumeApply();
460 409
461 expectAsset("app|foo.out", "baz"); 410 expectAsset("app|foo.out", "baz");
462 buildShouldSucceed(); 411 buildShouldSucceed();
463 412
464 schedule(() { 413 expect(transformer.numRuns, completion(equals(2)));
465 expect(transformer.numRuns, equals(2));
466 });
467 }); 414 });
468 415
469 test("doesn't restart processing if a change to an old secondary input " 416 test("doesn't restart processing if a change to an old secondary input "
470 "occurs during processing", () { 417 "occurs during processing", () {
471 var transformer = new ManyToOneTransformer("txt"); 418 var transformer = new ManyToOneTransformer("txt");
472 initGraph({ 419 initGraph({
473 "app|foo.txt": "bar.inc", 420 "app|foo.txt": "bar.inc",
474 "app|bar.inc": "bar", 421 "app|bar.inc": "bar",
475 "app|baz.inc": "baz" 422 "app|baz.inc": "baz"
476 }, {"app": [[transformer]]}); 423 }, {"app": [[transformer]]});
477 424
478 updateSources(["app|foo.txt", "app|bar.inc", "app|baz.inc"]); 425 updateSources(["app|foo.txt", "app|bar.inc", "app|baz.inc"]);
479 expectAsset("app|foo.out", "bar"); 426 expectAsset("app|foo.out", "bar");
480 buildShouldSucceed(); 427 buildShouldSucceed();
481 428
482 schedule(transformer.pauseApply); 429 transformer.pauseApply();
483 modifyAsset("app|foo.txt", "baz.inc"); 430 modifyAsset("app|foo.txt", "baz.inc");
484 schedule(() { 431 updateSources(["app|foo.txt"]);
485 updateSources(["app|foo.txt"]); 432 // Wait for the transform to start.
486 // Wait for the transform to start. 433 transformer.waitUntilStarted();
487 return transformer.started;
488 });
489 434
490 // Now update the old secondary input before the transform finishes. 435 // Now update the old secondary input before the transform finishes.
491 modifyAsset("app|bar.inc", "new bar"); 436 modifyAsset("app|bar.inc", "new bar");
492 schedule(() => updateSources(["app|bar.inc"])); 437 updateSources(["app|bar.inc"]);
493 // Give bar.inc enough time to be loaded and marked available before the 438 // Give bar.inc enough time to be loaded and marked available before the
494 // transformer completes. 439 // transformer completes.
495 schedule(pumpEventQueue); 440 schedule(pumpEventQueue);
496 441
497 schedule(transformer.resumeApply); 442 transformer.resumeApply();
498
499 expectAsset("app|foo.out", "baz"); 443 expectAsset("app|foo.out", "baz");
500 buildShouldSucceed(); 444 buildShouldSucceed();
501 445
502 schedule(() { 446 // Should have run once the first time, then again when switching to
503 // Should have run once the first time, then again when switching to 447 // baz.inc. Should not run a third time because of bar.inc being modified.
504 // baz.inc. Should not run a third time because of bar.inc being modified. 448 expect(transformer.numRuns, completion(equals(2)));
505 expect(transformer.numRuns, equals(2));
506 });
507 }); 449 });
508 450
509 test("handles an output moving from one transformer to another", () { 451 test("handles an output moving from one transformer to another", () {
510 // In the first run, "shared.out" is created by the "a.a" transformer. 452 // In the first run, "shared.out" is created by the "a.a" transformer.
511 initGraph({ 453 initGraph({
512 "app|a.a": "a.out,shared.out", 454 "app|a.a": "a.out,shared.out",
513 "app|b.b": "b.out" 455 "app|b.b": "b.out"
514 }, {"app": [ 456 }, {"app": [
515 [new OneToManyTransformer("a"), new OneToManyTransformer("b")] 457 [new OneToManyTransformer("a"), new OneToManyTransformer("b")]
516 ]}); 458 ]});
517 459
518 updateSources(["app|a.a", "app|b.b"]); 460 updateSources(["app|a.a", "app|b.b"]);
519 461
520 expectAsset("app|a.out", "spread a"); 462 expectAsset("app|a.out", "spread a");
521 expectAsset("app|b.out", "spread b"); 463 expectAsset("app|b.out", "spread b");
522 expectAsset("app|shared.out", "spread a"); 464 expectAsset("app|shared.out", "spread a");
523 buildShouldSucceed(); 465 buildShouldSucceed();
524 466
525 // Now switch their contents so that "shared.out" will be output by "b.b"'s 467 // Now switch their contents so that "shared.out" will be output by "b.b"'s
526 // transformer. 468 // transformer.
527 modifyAsset("app|a.a", "a.out"); 469 modifyAsset("app|a.a", "a.out");
528 modifyAsset("app|b.b", "b.out,shared.out"); 470 modifyAsset("app|b.b", "b.out,shared.out");
529 schedule(() => updateSources(["app|a.a", "app|b.b"])); 471 updateSources(["app|a.a", "app|b.b"]);
530 472
531 expectAsset("app|a.out", "spread a"); 473 expectAsset("app|a.out", "spread a");
532 expectAsset("app|b.out", "spread b"); 474 expectAsset("app|b.out", "spread b");
533 expectAsset("app|shared.out", "spread b"); 475 expectAsset("app|shared.out", "spread b");
534 buildShouldSucceed(); 476 buildShouldSucceed();
535 }); 477 });
536 478
537 test("restarts before finishing later phases when a change occurs", () { 479 test("restarts before finishing later phases when a change occurs", () {
538 var txtToInt = new RewriteTransformer("txt", "int"); 480 var txtToInt = new RewriteTransformer("txt", "int");
539 var intToOut = new RewriteTransformer("int", "out"); 481 var intToOut = new RewriteTransformer("int", "out");
540 initGraph(["app|foo.txt", "app|bar.txt"], 482 initGraph(["app|foo.txt", "app|bar.txt"],
541 {"app": [[txtToInt], [intToOut]]}); 483 {"app": [[txtToInt], [intToOut]]});
542 484
543 txtToInt.pauseApply(); 485 txtToInt.pauseApply();
544 486
545 schedule(() { 487 updateSources(["app|foo.txt"]);
546 updateSources(["app|foo.txt"]); 488 // Wait for the first transform to start.
489 txtToInt.waitUntilStarted();
547 490
548 // Wait for the first transform to start. 491 // Now update the graph during it.
549 return txtToInt.started; 492 updateSources(["app|bar.txt"]);
550 }); 493 txtToInt.resumeApply();
551
552 schedule(() {
553 // Now update the graph during it.
554 updateSources(["app|bar.txt"]);
555 });
556
557 schedule(() {
558 txtToInt.resumeApply();
559 });
560 494
561 expectAsset("app|foo.out", "foo.int.out"); 495 expectAsset("app|foo.out", "foo.int.out");
562 expectAsset("app|bar.out", "bar.int.out"); 496 expectAsset("app|bar.out", "bar.int.out");
563 buildShouldSucceed(); 497 buildShouldSucceed();
564 498
565 schedule(() { 499 // Should only have run each transform once for each primary.
566 // Should only have run each transform once for each primary. 500 expect(txtToInt.numRuns, completion(equals(2)));
567 expect(txtToInt.numRuns, equals(2)); 501 expect(intToOut.numRuns, completion(equals(2)));
568 expect(intToOut.numRuns, equals(2));
569 });
570 }); 502 });
571 503
572 test("applies transforms to the correct packages", () { 504 test("applies transforms to the correct packages", () {
573 var rewrite1 = new RewriteTransformer("txt", "out1"); 505 var rewrite1 = new RewriteTransformer("txt", "out1");
574 var rewrite2 = new RewriteTransformer("txt", "out2"); 506 var rewrite2 = new RewriteTransformer("txt", "out2");
575 initGraph([ 507 initGraph([
576 "pkg1|foo.txt", 508 "pkg1|foo.txt",
577 "pkg2|foo.txt" 509 "pkg2|foo.txt"
578 ], {"pkg1": [[rewrite1]], "pkg2": [[rewrite2]]}); 510 ], {"pkg1": [[rewrite1]], "pkg2": [[rewrite2]]});
579 511
(...skipping 19 matching lines...) Expand all
599 [new RewriteTransformer("in", "mid")], 531 [new RewriteTransformer("in", "mid")],
600 [new RewriteTransformer("mid", "out")] 532 [new RewriteTransformer("mid", "out")]
601 ]}); 533 ]});
602 534
603 updateSources(["app|foo.in"]); 535 updateSources(["app|foo.in"]);
604 expectAsset("app|foo.out", "foo.mid.out"); 536 expectAsset("app|foo.out", "foo.mid.out");
605 buildShouldSucceed(); 537 buildShouldSucceed();
606 538
607 pauseProvider(); 539 pauseProvider();
608 modifyAsset("app|foo.in", "new"); 540 modifyAsset("app|foo.in", "new");
609 schedule(() => updateSources(["app|foo.in"])); 541 updateSources(["app|foo.in"]);
610 expectAssetDoesNotComplete("app|foo.out"); 542 expectAssetDoesNotComplete("app|foo.out");
611 buildShouldNotBeDone(); 543 buildShouldNotBeDone();
612 544
613 resumeProvider(); 545 resumeProvider();
614 expectAsset("app|foo.out", "new.mid.out"); 546 expectAsset("app|foo.out", "new.mid.out");
615 buildShouldSucceed(); 547 buildShouldSucceed();
616 }); 548 });
617 549
618 test("doesn't return an asset until its in-place transform is done", () { 550 test("doesn't return an asset until its in-place transform is done", () {
619 var rewrite = new RewriteTransformer("txt", "txt"); 551 var rewrite = new RewriteTransformer("txt", "txt");
620 initGraph(["app|foo.txt"], {"app": [[rewrite]]}); 552 initGraph(["app|foo.txt"], {"app": [[rewrite]]});
621 553
622 rewrite.pauseApply(); 554 rewrite.pauseApply();
623 updateSources(["app|foo.txt"]); 555 updateSources(["app|foo.txt"]);
624 expectAssetDoesNotComplete("app|foo.txt"); 556 expectAssetDoesNotComplete("app|foo.txt");
625 557
626 schedule(rewrite.resumeApply); 558 rewrite.resumeApply();
627 expectAsset("app|foo.txt", "foo.txt"); 559 expectAsset("app|foo.txt", "foo.txt");
628 buildShouldSucceed(); 560 buildShouldSucceed();
629 }); 561 });
630 562
631 test("doesn't return an asset until we know it won't be transformed", 563 test("doesn't return an asset until we know it won't be transformed",
632 () { 564 () {
633 var rewrite = new RewriteTransformer("txt", "txt"); 565 var rewrite = new RewriteTransformer("txt", "txt");
634 initGraph(["app|foo.a"], {"app": [[rewrite]]}); 566 initGraph(["app|foo.a"], {"app": [[rewrite]]});
635 567
636 rewrite.pauseIsPrimary("app|foo.a"); 568 rewrite.pauseIsPrimary("app|foo.a");
637 updateSources(["app|foo.a"]); 569 updateSources(["app|foo.a"]);
638 expectAssetDoesNotComplete("app|foo.a"); 570 expectAssetDoesNotComplete("app|foo.a");
639 571
640 schedule(() => rewrite.resumeIsPrimary("app|foo.a")); 572 rewrite.resumeIsPrimary("app|foo.a");
641 expectAsset("app|foo.a", "foo"); 573 expectAsset("app|foo.a", "foo");
642 buildShouldSucceed(); 574 buildShouldSucceed();
643 }); 575 });
644 576
645 test("doesn't return a modified asset until we know it will still be " 577 test("doesn't return a modified asset until we know it will still be "
646 "transformed", () { 578 "transformed", () {
647 var rewrite = new RewriteTransformer("txt", "txt"); 579 var rewrite = new RewriteTransformer("txt", "txt");
648 initGraph(["app|foo.txt"], {"app": [[rewrite]]}); 580 initGraph(["app|foo.txt"], {"app": [[rewrite]]});
649 581
650 updateSources(["app|foo.txt"]); 582 updateSources(["app|foo.txt"]);
651 expectAsset("app|foo.txt", "foo.txt"); 583 expectAsset("app|foo.txt", "foo.txt");
652 buildShouldSucceed(); 584 buildShouldSucceed();
653 585
654 schedule(() => rewrite.pauseIsPrimary("app|foo.txt")); 586 rewrite.pauseIsPrimary("app|foo.txt");
655 schedule(() => updateSources(["app|foo.txt"])); 587 updateSources(["app|foo.txt"]);
656 expectAssetDoesNotComplete("app|foo.txt"); 588 expectAssetDoesNotComplete("app|foo.txt");
657 589
658 schedule(() => rewrite.resumeIsPrimary("app|foo.txt")); 590 rewrite.resumeIsPrimary("app|foo.txt");
659 expectAsset("app|foo.txt", "foo.txt"); 591 expectAsset("app|foo.txt", "foo.txt");
660 buildShouldSucceed(); 592 buildShouldSucceed();
661 }); 593 });
662 594
663 test("doesn't return an asset that's removed during isPrimary", () { 595 test("doesn't return an asset that's removed during isPrimary", () {
664 var rewrite = new RewriteTransformer("txt", "txt"); 596 var rewrite = new RewriteTransformer("txt", "txt");
665 initGraph(["app|foo.txt"], {"app": [[rewrite]]}); 597 initGraph(["app|foo.txt"], {"app": [[rewrite]]});
666 598
667 rewrite.pauseIsPrimary("app|foo.txt"); 599 rewrite.pauseIsPrimary("app|foo.txt");
668 updateSources(["app|foo.txt"]); 600 updateSources(["app|foo.txt"]);
669 // Make sure we're waiting on isPrimary. 601 // Make sure we're waiting on isPrimary.
670 schedule(pumpEventQueue); 602 schedule(pumpEventQueue);
671 603
672 schedule(() { 604 removeSources(["app|foo.txt"]);
673 removeSources(["app|foo.txt"]); 605 rewrite.resumeIsPrimary("app|foo.txt");
674 rewrite.resumeIsPrimary("app|foo.txt");
675 });
676 expectNoAsset("app|foo.txt"); 606 expectNoAsset("app|foo.txt");
677 buildShouldSucceed(); 607 buildShouldSucceed();
678 }); 608 });
679 609
680 test("doesn't transform an asset that goes from primary to non-primary " 610 test("doesn't transform an asset that goes from primary to non-primary "
681 "during isPrimary", () { 611 "during isPrimary", () {
682 var check = new CheckContentTransformer("do", "ne"); 612 var check = new CheckContentTransformer("do", "ne");
683 initGraph({ 613 initGraph({
684 "app|foo.txt": "do" 614 "app|foo.txt": "do"
685 }, {"app": [[check]]}); 615 }, {"app": [[check]]});
686 616
687 check.pauseIsPrimary("app|foo.txt"); 617 check.pauseIsPrimary("app|foo.txt");
688 updateSources(["app|foo.txt"]); 618 updateSources(["app|foo.txt"]);
689 // Make sure we're waiting on isPrimary. 619 // Make sure we're waiting on isPrimary.
690 schedule(pumpEventQueue); 620 schedule(pumpEventQueue);
691 621
692 modifyAsset("app|foo.txt", "don't"); 622 modifyAsset("app|foo.txt", "don't");
693 schedule(() { 623 updateSources(["app|foo.txt"]);
694 updateSources(["app|foo.txt"]); 624 check.resumeIsPrimary("app|foo.txt");
695 check.resumeIsPrimary("app|foo.txt");
696 });
697 625
698 expectAsset("app|foo.txt", "don't"); 626 expectAsset("app|foo.txt", "don't");
699 buildShouldSucceed(); 627 buildShouldSucceed();
700 }); 628 });
701 629
702 test("transforms an asset that goes from non-primary to primary " 630 test("transforms an asset that goes from non-primary to primary "
703 "during isPrimary", () { 631 "during isPrimary", () {
704 var check = new CheckContentTransformer("do", "ne"); 632 var check = new CheckContentTransformer("do", "ne");
705 initGraph({ 633 initGraph({
706 "app|foo.txt": "don't" 634 "app|foo.txt": "don't"
707 }, {"app": [[check]]}); 635 }, {"app": [[check]]});
708 636
709 check.pauseIsPrimary("app|foo.txt"); 637 check.pauseIsPrimary("app|foo.txt");
710 updateSources(["app|foo.txt"]); 638 updateSources(["app|foo.txt"]);
711 // Make sure we're waiting on isPrimary. 639 // Make sure we're waiting on isPrimary.
712 schedule(pumpEventQueue); 640 schedule(pumpEventQueue);
713 641
714 modifyAsset("app|foo.txt", "do"); 642 modifyAsset("app|foo.txt", "do");
715 schedule(() { 643 updateSources(["app|foo.txt"]);
716 updateSources(["app|foo.txt"]); 644 check.resumeIsPrimary("app|foo.txt");
717 check.resumeIsPrimary("app|foo.txt");
718 });
719 645
720 expectAsset("app|foo.txt", "done"); 646 expectAsset("app|foo.txt", "done");
721 buildShouldSucceed(); 647 buildShouldSucceed();
722 }); 648 });
723 649
724 test("doesn't return an asset that's removed during another transformer's " 650 test("doesn't return an asset that's removed during another transformer's "
725 "isPrimary", () { 651 "isPrimary", () {
726 var rewrite1 = new RewriteTransformer("txt", "txt"); 652 var rewrite1 = new RewriteTransformer("txt", "txt");
727 var rewrite2 = new RewriteTransformer("md", "md"); 653 var rewrite2 = new RewriteTransformer("md", "md");
728 initGraph(["app|foo.txt", "app|foo.md"], {"app": [[rewrite1, rewrite2]]}); 654 initGraph(["app|foo.txt", "app|foo.md"], {"app": [[rewrite1, rewrite2]]});
729 655
730 rewrite2.pauseIsPrimary("app|foo.md"); 656 rewrite2.pauseIsPrimary("app|foo.md");
731 updateSources(["app|foo.txt", "app|foo.md"]); 657 updateSources(["app|foo.txt", "app|foo.md"]);
732 // Make sure we're waiting on the correct isPrimary. 658 // Make sure we're waiting on the correct isPrimary.
733 schedule(pumpEventQueue); 659 schedule(pumpEventQueue);
734 660
735 schedule(() { 661 removeSources(["app|foo.txt"]);
736 removeSources(["app|foo.txt"]); 662 rewrite2.resumeIsPrimary("app|foo.md");
737 rewrite2.resumeIsPrimary("app|foo.md");
738 });
739 expectNoAsset("app|foo.txt"); 663 expectNoAsset("app|foo.txt");
740 expectAsset("app|foo.md", "foo.md"); 664 expectAsset("app|foo.md", "foo.md");
741 buildShouldSucceed(); 665 buildShouldSucceed();
742 }); 666 });
743 667
744 test("doesn't transform an asset that goes from primary to non-primary " 668 test("doesn't transform an asset that goes from primary to non-primary "
745 "during another transformer's isPrimary", () { 669 "during another transformer's isPrimary", () {
746 var rewrite = new RewriteTransformer("md", "md"); 670 var rewrite = new RewriteTransformer("md", "md");
747 var check = new CheckContentTransformer("do", "ne"); 671 var check = new CheckContentTransformer("do", "ne");
748 initGraph({ 672 initGraph({
749 "app|foo.txt": "do", 673 "app|foo.txt": "do",
750 "app|foo.md": "foo" 674 "app|foo.md": "foo"
751 }, {"app": [[rewrite, check]]}); 675 }, {"app": [[rewrite, check]]});
752 676
753 rewrite.pauseIsPrimary("app|foo.md"); 677 rewrite.pauseIsPrimary("app|foo.md");
754 updateSources(["app|foo.txt", "app|foo.md"]); 678 updateSources(["app|foo.txt", "app|foo.md"]);
755 // Make sure we're waiting on the correct isPrimary. 679 // Make sure we're waiting on the correct isPrimary.
756 schedule(pumpEventQueue); 680 schedule(pumpEventQueue);
757 681
758 modifyAsset("app|foo.txt", "don't"); 682 modifyAsset("app|foo.txt", "don't");
759 schedule(() { 683 updateSources(["app|foo.txt"]);
760 updateSources(["app|foo.txt"]); 684 rewrite.resumeIsPrimary("app|foo.md");
761 rewrite.resumeIsPrimary("app|foo.md");
762 });
763 685
764 expectAsset("app|foo.txt", "don't"); 686 expectAsset("app|foo.txt", "don't");
765 expectAsset("app|foo.md", "foo.md"); 687 expectAsset("app|foo.md", "foo.md");
766 buildShouldSucceed(); 688 buildShouldSucceed();
767 }); 689 });
768 690
769 test("transforms an asset that goes from non-primary to primary " 691 test("transforms an asset that goes from non-primary to primary "
770 "during another transformer's isPrimary", () { 692 "during another transformer's isPrimary", () {
771 var rewrite = new RewriteTransformer("md", "md"); 693 var rewrite = new RewriteTransformer("md", "md");
772 var check = new CheckContentTransformer("do", "ne"); 694 var check = new CheckContentTransformer("do", "ne");
773 initGraph({ 695 initGraph({
774 "app|foo.txt": "don't", 696 "app|foo.txt": "don't",
775 "app|foo.md": "foo" 697 "app|foo.md": "foo"
776 }, {"app": [[rewrite, check]]}); 698 }, {"app": [[rewrite, check]]});
777 699
778 rewrite.pauseIsPrimary("app|foo.md"); 700 rewrite.pauseIsPrimary("app|foo.md");
779 updateSources(["app|foo.txt", "app|foo.md"]); 701 updateSources(["app|foo.txt", "app|foo.md"]);
780 // Make sure we're waiting on the correct isPrimary. 702 // Make sure we're waiting on the correct isPrimary.
781 schedule(pumpEventQueue); 703 schedule(pumpEventQueue);
782 704
783 modifyAsset("app|foo.txt", "do"); 705 modifyAsset("app|foo.txt", "do");
784 schedule(() { 706 updateSources(["app|foo.txt"]);
785 updateSources(["app|foo.txt"]); 707 rewrite.resumeIsPrimary("app|foo.md");
786 rewrite.resumeIsPrimary("app|foo.md");
787 });
788 708
789 expectAsset("app|foo.txt", "done"); 709 expectAsset("app|foo.txt", "done");
790 expectAsset("app|foo.md", "foo.md"); 710 expectAsset("app|foo.md", "foo.md");
791 buildShouldSucceed(); 711 buildShouldSucceed();
792 }); 712 });
793 713
794 test("removes pipelined transforms when the root primary input is removed", 714 test("removes pipelined transforms when the root primary input is removed",
795 () { 715 () {
796 initGraph(["app|foo.txt"], {"app": [ 716 initGraph(["app|foo.txt"], {"app": [
797 [new RewriteTransformer("txt", "mid")], 717 [new RewriteTransformer("txt", "mid")],
798 [new RewriteTransformer("mid", "out")] 718 [new RewriteTransformer("mid", "out")]
799 ]}); 719 ]});
800 720
801 updateSources(["app|foo.txt"]); 721 updateSources(["app|foo.txt"]);
802 expectAsset("app|foo.out", "foo.mid.out"); 722 expectAsset("app|foo.out", "foo.mid.out");
803 buildShouldSucceed(); 723 buildShouldSucceed();
804 724
805 schedule(() => removeSources(["app|foo.txt"])); 725 removeSources(["app|foo.txt"]);
806 expectNoAsset("app|foo.out"); 726 expectNoAsset("app|foo.out");
807 buildShouldSucceed(); 727 buildShouldSucceed();
808 }); 728 });
809 729
810 test("removes pipelined transforms when the parent ceases to generate the " 730 test("removes pipelined transforms when the parent ceases to generate the "
811 "primary input", () { 731 "primary input", () {
812 initGraph({"app|foo.txt": "foo.mid"}, {'app': [ 732 initGraph({"app|foo.txt": "foo.mid"}, {'app': [
813 [new OneToManyTransformer('txt')], 733 [new OneToManyTransformer('txt')],
814 [new RewriteTransformer('mid', 'out')] 734 [new RewriteTransformer('mid', 'out')]
815 ]}); 735 ]});
816 736
817 updateSources(['app|foo.txt']); 737 updateSources(['app|foo.txt']);
818 expectAsset('app|foo.out', 'spread txt.out'); 738 expectAsset('app|foo.out', 'spread txt.out');
819 buildShouldSucceed(); 739 buildShouldSucceed();
820 740
821 modifyAsset("app|foo.txt", "bar.mid"); 741 modifyAsset("app|foo.txt", "bar.mid");
822 schedule(() => updateSources(["app|foo.txt"])); 742 updateSources(["app|foo.txt"]);
823 expectNoAsset('app|foo.out'); 743 expectNoAsset('app|foo.out');
824 expectAsset('app|bar.out', 'spread txt.out'); 744 expectAsset('app|bar.out', 'spread txt.out');
825 buildShouldSucceed(); 745 buildShouldSucceed();
826 }); 746 });
827 747
828 test("returns an asset even if an unrelated build is running", () { 748 test("returns an asset even if an unrelated build is running", () {
829 initGraph([ 749 initGraph([
830 "app|foo.in", 750 "app|foo.in",
831 "app|bar.in", 751 "app|bar.in",
832 ], {"app": [[new RewriteTransformer("in", "out")]]}); 752 ], {"app": [[new RewriteTransformer("in", "out")]]});
833 753
834 updateSources(["app|foo.in", "app|bar.in"]); 754 updateSources(["app|foo.in", "app|bar.in"]);
835 expectAsset("app|foo.out", "foo.out"); 755 expectAsset("app|foo.out", "foo.out");
836 expectAsset("app|bar.out", "bar.out"); 756 expectAsset("app|bar.out", "bar.out");
837 buildShouldSucceed(); 757 buildShouldSucceed();
838 758
839 pauseProvider(); 759 pauseProvider();
840 modifyAsset("app|foo.in", "new"); 760 modifyAsset("app|foo.in", "new");
841 schedule(() => updateSources(["app|foo.in"])); 761 updateSources(["app|foo.in"]);
842 expectAssetDoesNotComplete("app|foo.out"); 762 expectAssetDoesNotComplete("app|foo.out");
843 expectAsset("app|bar.out", "bar.out"); 763 expectAsset("app|bar.out", "bar.out");
844 buildShouldNotBeDone(); 764 buildShouldNotBeDone();
845 765
846 resumeProvider(); 766 resumeProvider();
847 expectAsset("app|foo.out", "new.out"); 767 expectAsset("app|foo.out", "new.out");
848 buildShouldSucceed(); 768 buildShouldSucceed();
849 }); 769 });
850 770
851 test("doesn't report AssetNotFound until all builds are finished", () { 771 test("doesn't report AssetNotFound until all builds are finished", () {
852 initGraph([ 772 initGraph([
853 "app|foo.in", 773 "app|foo.in",
854 ], {"app": [[new RewriteTransformer("in", "out")]]}); 774 ], {"app": [[new RewriteTransformer("in", "out")]]});
855 775
856 updateSources(["app|foo.in"]); 776 updateSources(["app|foo.in"]);
857 expectAsset("app|foo.out", "foo.out"); 777 expectAsset("app|foo.out", "foo.out");
858 buildShouldSucceed(); 778 buildShouldSucceed();
859 779
860 pauseProvider(); 780 pauseProvider();
861 schedule(() => updateSources(["app|foo.in"])); 781 updateSources(["app|foo.in"]);
862 expectAssetDoesNotComplete("app|foo.out"); 782 expectAssetDoesNotComplete("app|foo.out");
863 expectAssetDoesNotComplete("app|non-existent.out"); 783 expectAssetDoesNotComplete("app|non-existent.out");
864 buildShouldNotBeDone(); 784 buildShouldNotBeDone();
865 785
866 resumeProvider(); 786 resumeProvider();
867 expectAsset("app|foo.out", "foo.out"); 787 expectAsset("app|foo.out", "foo.out");
868 expectNoAsset("app|non-existent.out"); 788 expectNoAsset("app|non-existent.out");
869 buildShouldSucceed(); 789 buildShouldSucceed();
870 }); 790 });
871 791
872 test("doesn't emit a result until all builds are finished", () { 792 test("doesn't emit a result until all builds are finished", () {
873 var rewrite = new RewriteTransformer("txt", "out"); 793 var rewrite = new RewriteTransformer("txt", "out");
874 initGraph([ 794 initGraph([
875 "pkg1|foo.txt", 795 "pkg1|foo.txt",
876 "pkg2|foo.txt" 796 "pkg2|foo.txt"
877 ], {"pkg1": [[rewrite]], "pkg2": [[rewrite]]}); 797 ], {"pkg1": [[rewrite]], "pkg2": [[rewrite]]});
878 798
879 // First, run both packages' transformers so both packages are successful. 799 // First, run both packages' transformers so both packages are successful.
880 updateSources(["pkg1|foo.txt", "pkg2|foo.txt"]); 800 updateSources(["pkg1|foo.txt", "pkg2|foo.txt"]);
881 expectAsset("pkg1|foo.out", "foo.out"); 801 expectAsset("pkg1|foo.out", "foo.out");
882 expectAsset("pkg2|foo.out", "foo.out"); 802 expectAsset("pkg2|foo.out", "foo.out");
883 buildShouldSucceed(); 803 buildShouldSucceed();
884 804
885 // pkg1 is still successful, but pkg2 is waiting on the provider, so the 805 // pkg1 is still successful, but pkg2 is waiting on the provider, so the
886 // overall build shouldn't finish. 806 // overall build shouldn't finish.
887 pauseProvider(); 807 pauseProvider();
888 schedule(() => updateSources(["pkg2|foo.txt"])); 808 updateSources(["pkg2|foo.txt"]);
889 expectAsset("pkg1|foo.out", "foo.out"); 809 expectAsset("pkg1|foo.out", "foo.out");
890 buildShouldNotBeDone(); 810 buildShouldNotBeDone();
891 811
892 // Now that the provider is unpaused, pkg2's transforms finish and the 812 // Now that the provider is unpaused, pkg2's transforms finish and the
893 // overall build succeeds. 813 // overall build succeeds.
894 resumeProvider(); 814 resumeProvider();
895 buildShouldSucceed(); 815 buildShouldSucceed();
896 }); 816 });
897 817
898 group('cross-package transforms', () { 818 group('cross-package transforms', () {
(...skipping 28 matching lines...) Expand all
927 "pkg2|a.inc": "a" 847 "pkg2|a.inc": "a"
928 }, { 848 }, {
929 "pkg1": [[new ManyToOneTransformer("txt")]] 849 "pkg1": [[new ManyToOneTransformer("txt")]]
930 }); 850 });
931 851
932 updateSources(["pkg1|a.txt", "pkg2|a.inc"]); 852 updateSources(["pkg1|a.txt", "pkg2|a.inc"]);
933 expectAsset("pkg1|a.out", "a"); 853 expectAsset("pkg1|a.out", "a");
934 buildShouldSucceed(); 854 buildShouldSucceed();
935 855
936 modifyAsset("pkg2|a.inc", "new a"); 856 modifyAsset("pkg2|a.inc", "new a");
937 schedule(() => updateSources(["pkg2|a.inc"])); 857 updateSources(["pkg2|a.inc"]);
938 expectAsset("pkg1|a.out", "new a"); 858 expectAsset("pkg1|a.out", "new a");
939 buildShouldSucceed(); 859 buildShouldSucceed();
940 }); 860 });
941 861
942 test("re-runs a transform when a transformed input from another package " 862 test("re-runs a transform when a transformed input from another package "
943 "changes", () { 863 "changes", () {
944 initGraph({ 864 initGraph({
945 "pkg1|a.txt": "pkg2|a.inc", 865 "pkg1|a.txt": "pkg2|a.inc",
946 "pkg2|a.txt": "a" 866 "pkg2|a.txt": "a"
947 }, { 867 }, {
948 "pkg1": [[new ManyToOneTransformer("txt")]], 868 "pkg1": [[new ManyToOneTransformer("txt")]],
949 "pkg2": [[new RewriteTransformer("txt", "inc")]] 869 "pkg2": [[new RewriteTransformer("txt", "inc")]]
950 }); 870 });
951 871
952 updateSources(["pkg1|a.txt", "pkg2|a.txt"]); 872 updateSources(["pkg1|a.txt", "pkg2|a.txt"]);
953 expectAsset("pkg1|a.out", "a.inc"); 873 expectAsset("pkg1|a.out", "a.inc");
954 buildShouldSucceed(); 874 buildShouldSucceed();
955 875
956 modifyAsset("pkg2|a.txt", "new a"); 876 modifyAsset("pkg2|a.txt", "new a");
957 schedule(() => updateSources(["pkg2|a.txt"])); 877 updateSources(["pkg2|a.txt"]);
958 expectAsset("pkg1|a.out", "new a.inc"); 878 expectAsset("pkg1|a.out", "new a.inc");
959 buildShouldSucceed(); 879 buildShouldSucceed();
960 }); 880 });
961 881
962 test("runs a transform that's added because of a change in another package", 882 test("runs a transform that's added because of a change in another package",
963 () { 883 () {
964 initGraph({ 884 initGraph({
965 "pkg1|a.txt": "pkg2|a.inc", 885 "pkg1|a.txt": "pkg2|a.inc",
966 "pkg2|a.inc": "b" 886 "pkg2|a.inc": "b"
967 }, { 887 }, {
968 "pkg1": [ 888 "pkg1": [
969 [new ManyToOneTransformer("txt")], 889 [new ManyToOneTransformer("txt")],
970 [new OneToManyTransformer("out")], 890 [new OneToManyTransformer("out")],
971 [new RewriteTransformer("md", "done")] 891 [new RewriteTransformer("md", "done")]
972 ], 892 ],
973 }); 893 });
974 894
975 // pkg1|a.txt generates outputs based on the contents of pkg2|a.inc. At 895 // pkg1|a.txt generates outputs based on the contents of pkg2|a.inc. At
976 // first pkg2|a.inc only includes "b", which is not transformed. Then 896 // first pkg2|a.inc only includes "b", which is not transformed. Then
977 // pkg2|a.inc is updated to include "b,c.md". pkg1|c.md triggers the 897 // pkg2|a.inc is updated to include "b,c.md". pkg1|c.md triggers the
978 // md->done rewrite transformer, producing pkg1|c.done. 898 // md->done rewrite transformer, producing pkg1|c.done.
979 899
980 updateSources(["pkg1|a.txt", "pkg2|a.inc"]); 900 updateSources(["pkg1|a.txt", "pkg2|a.inc"]);
981 expectAsset("pkg1|b", "spread out"); 901 expectAsset("pkg1|b", "spread out");
982 buildShouldSucceed(); 902 buildShouldSucceed();
983 903
984 modifyAsset("pkg2|a.inc", "b,c.md"); 904 modifyAsset("pkg2|a.inc", "b,c.md");
985 schedule(() => updateSources(["pkg2|a.inc"])); 905 updateSources(["pkg2|a.inc"]);
986 expectAsset("pkg1|b", "spread out"); 906 expectAsset("pkg1|b", "spread out");
987 expectAsset("pkg1|c.done", "spread out.done"); 907 expectAsset("pkg1|c.done", "spread out.done");
988 buildShouldSucceed(); 908 buildShouldSucceed();
989 }); 909 });
990 910
991 test("doesn't run a transform that's removed because of a change in " 911 test("doesn't run a transform that's removed because of a change in "
992 "another package", () { 912 "another package", () {
993 initGraph({ 913 initGraph({
994 "pkg1|a.txt": "pkg2|a.inc", 914 "pkg1|a.txt": "pkg2|a.inc",
995 "pkg2|a.inc": "b,c.md" 915 "pkg2|a.inc": "b,c.md"
996 }, { 916 }, {
997 "pkg1": [ 917 "pkg1": [
998 [new ManyToOneTransformer("txt")], 918 [new ManyToOneTransformer("txt")],
999 [new OneToManyTransformer("out")], 919 [new OneToManyTransformer("out")],
1000 [new RewriteTransformer("md", "done")] 920 [new RewriteTransformer("md", "done")]
1001 ], 921 ],
1002 }); 922 });
1003 923
1004 updateSources(["pkg1|a.txt", "pkg2|a.inc"]); 924 updateSources(["pkg1|a.txt", "pkg2|a.inc"]);
1005 expectAsset("pkg1|b", "spread out"); 925 expectAsset("pkg1|b", "spread out");
1006 expectAsset("pkg1|c.done", "spread out.done"); 926 expectAsset("pkg1|c.done", "spread out.done");
1007 buildShouldSucceed(); 927 buildShouldSucceed();
1008 928
1009 modifyAsset("pkg2|a.inc", "b"); 929 modifyAsset("pkg2|a.inc", "b");
1010 schedule(() => updateSources(["pkg2|a.inc"])); 930 updateSources(["pkg2|a.inc"]);
1011 expectAsset("pkg1|b", "spread out"); 931 expectAsset("pkg1|b", "spread out");
1012 expectNoAsset("pkg1|c.done"); 932 expectNoAsset("pkg1|c.done");
1013 buildShouldSucceed(); 933 buildShouldSucceed();
1014 }); 934 });
1015 }); 935 });
1016 } 936 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698