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

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

Issue 149243009: Add support for lazy transformers. (Closed) Base URL: https://dart.googlecode.com/svn/branches/bleeding_edge/dart
Patch Set: name changes Created 6 years, 10 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
(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.lazy_asset_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 test("requesting a lazy asset should cause it to be generated", () {
16 initGraph(["app|foo.blub"], {"app": [
17 [new LazyRewriteTransformer("blub", "blab")]
18 ]});
19 updateSources(["app|foo.blub"]);
20 expectAsset("app|foo.blab", "foo.blab");
21 buildShouldSucceed();
22 });
23
24 test("calling getAllAssets should cause a lazy asset to be generated", () {
25 var transformer = new LazyRewriteTransformer("blub", "blab");
26 initGraph(["app|foo.blub"], {"app": [[transformer]]});
27 updateSources(["app|foo.blub"]);
28 expectAllAssets(["app|foo.blab"]);
29 buildShouldSucceed();
30 expect(transformer.numRuns, completion(equals(1)));
31 });
32
33 test("requesting a lazy asset multiple times should only cause it to be "
34 "generated once", () {
35 var transformer = new LazyRewriteTransformer("blub", "blab");
36 initGraph(["app|foo.blub"], {"app": [[transformer]]});
37 updateSources(["app|foo.blub"]);
38 expectAsset("app|foo.blab", "foo.blab");
39 expectAsset("app|foo.blab", "foo.blab");
40 expectAsset("app|foo.blab", "foo.blab");
41 buildShouldSucceed();
42 expect(transformer.numRuns, completion(equals(1)));
43 });
44
45 test("a lazy asset can be consumed by a non-lazy transformer", () {
46 initGraph(["app|foo.blub"], {"app": [
47 [new LazyRewriteTransformer("blub", "blab")],
48 [new RewriteTransformer("blab", "blib")]
49 ]});
50 updateSources(["app|foo.blub"]);
51 expectAsset("app|foo.blib", "foo.blab.blib");
52 buildShouldSucceed();
53 });
54
55 test("a lazy asset isn't eagerly compiled", () {
56 var transformer = new LazyRewriteTransformer("blub", "blab");
57 initGraph(["app|foo.blub"], {"app": [[transformer]]});
58 updateSources(["app|foo.blub"]);
59 buildShouldSucceed();
60 expect(transformer.numRuns, completion(equals(0)));
61 });
62
63 test("a lazy asset emitted by a group isn't eagerly compiled", () {
64 var transformer = new LazyRewriteTransformer("blub", "blab");
65 initGraph(["app|foo.blub"], {"app": [
66 [new TransformerGroup([[transformer]])]
67 ]});
68 updateSources(["app|foo.blub"]);
69 buildShouldSucceed();
70 expect(transformer.numRuns, completion(equals(0)));
71 });
72
73 test("a lazy asset piped into a non-lazy transformer is eagerly compiled",
74 () {
75 var transformer = new LazyRewriteTransformer("blub", "blab");
76 initGraph(["app|foo.blub"], {"app": [
77 [transformer],
78 [new RewriteTransformer("blab", "blib")]
79 ]});
80 updateSources(["app|foo.blub"]);
81 buildShouldSucceed();
82 expect(transformer.numRuns, completion(equals(1)));
83 });
84
85 // TODO(nweiz): enable these once DeclaringTransformers forward laziness
86 // properly (issue 16442).
87 //
88 // test("a lazy asset piped into a declaring transformer isn't eagerly "
89 // "compiled", () {
90 // var transformer1 = new LazyRewriteTransformer("blub", "blab");
91 // var transformer2 = new DeclaringRewriteTransformer("blab", "blib");
92 // initGraph(["app|foo.blub"], {"app": [
93 // [transformer1], [transformer2]
94 // ]});
95 // updateSources(["app|foo.blub"]);
96 // buildShouldSucceed();
97 // expect(transformer1.numRuns, completion(equals(0)));
98 // expect(transformer2.numRuns, completion(equals(0)));
99 // });
100 //
101 // test("a lazy asset piped into a declaring transformer is compiled on-demand ",
Bob Nystrom 2014/02/07 21:02:28 Long line.
nweiz 2014/02/10 20:14:04 Done.
102 // () {
103 // initGraph(["app|foo.blub"], {"app": [
104 // [new LazyRewriteTransformer("blub", "blab")],
105 // [new DeclaringRewriteTransformer("blab", "blib")]
106 // ]});
107 // updateSources(["app|foo.blub"]);
108 // expectAsset("app|foo.blib", "foo.blab.blib");
109 // buildShouldSucceed();
110 // });
111
112 test("a lazy asset works as a cross-package input", () {
113 initGraph({
114 "pkg1|foo.blub": "foo",
115 "pkg2|a.txt": "pkg1|foo.blab"
116 }, {"pkg1": [
117 [new LazyRewriteTransformer("blub", "blab")],
118 ], "pkg2": [
119 [new ManyToOneTransformer("txt")]
120 ]});
121
122 updateSources(["pkg1|foo.blub", "pkg2|a.txt"]);
123 expectAsset("pkg2|a.out", "foo.blab");
124 buildShouldSucceed();
125 });
126
127 test("a lazy transformer can consume secondary inputs lazily", () {
128 initGraph({
129 "app|a.inc": "a",
130 "app|a.txt": "a.inc"
131 }, {"app": [
132 [new LazyManyToOneTransformer("txt")]
133 ]});
134
135 updateSources(["app|a.inc", "app|a.txt"]);
136 expectAsset("app|a.out", "a");
137 buildShouldSucceed();
138 });
139
140 test("once a lazy transformer is materialized, it runs eagerly afterwards",
141 () {
142 var transformer = new LazyRewriteTransformer("blub", "blab");
143 initGraph(["app|foo.blub"], {"app": [[transformer]]});
144
145 updateSources(["app|foo.blub"]);
146 buildShouldSucceed();
147
148 // Request the asset once to force it to be materialized.
149 expectAsset("app|foo.blab", "foo.blab");
150 buildShouldSucceed();
151
152 updateSources(["app|foo.blub"]);
153 buildShouldSucceed();
154
155 expect(transformer.numRuns, completion(equals(2)));
156 });
157
158 test("an error emitted in a lazy transformer's declareOutputs method is "
159 "caught and reported", () {
160 initGraph(["app|foo.txt"], {"app": [
161 [new LazyBadTransformer("app|foo.out")]
162 ]});
163
164 updateSources(["app|foo.txt"]);
165 buildShouldFail([isTransformerException(equals(LazyBadTransformer.ERROR))]);
166 });
167
168 test("an error emitted in a lazy transformer's declareOuputs method prevents "
169 "it from being materialized", () {
170 var transformer = new LazyBadTransformer("app|foo.out");
171 initGraph(["app|foo.txt"], {"app": [[transformer]]});
172
173 updateSources(["app|foo.txt"]);
174 expectNoAsset("app|foo.out");
175 buildShouldFail([isTransformerException(equals(LazyBadTransformer.ERROR))]);
176 expect(transformer.numRuns, completion(equals(0)));
177 });
178 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698