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.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 DryRunTransformers forward laziness | |
86 // properly. | |
Bob Nystrom
2014/01/30 19:33:44
File a bug for this.
nweiz
2014/01/31 03:43:27
Done.
| |
87 // | |
88 // test("a lazy asset piped into a dry-run transformer isn't eagerly " | |
89 // "compiled", () { | |
90 // var transformer1 = new LazyRewriteTransformer("blub", "blab"); | |
91 // var transformer2 = new DryRunRewriteTransformer("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 dry-run transformer is compiled on-demand", | |
102 // () { | |
103 // initGraph(["app|foo.blub"], {"app": [ | |
104 // [new LazyRewriteTransformer("blub", "blab")], | |
105 // [new DryRunRewriteTransformer("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", | |
Bob Nystrom
2014/01/30 19:33:44
I know this is what we discussed, but I wonder if
nweiz
2014/01/31 03:43:27
I think this is correct. I think when the user is
Bob Nystrom
2014/01/31 18:28:53
SGTM!
| |
141 () { | |
142 var transformer = new LazyRewriteTransformer("blub", "blab"); | |
143 initGraph(["app|foo.blub"], {"app": [[transformer]]}); | |
144 | |
145 updateSources(["app|foo.blub"]); | |
146 buildShouldSucceed(); | |
147 | |
Bob Nystrom
2014/01/30 19:33:44
Comment: // Request the asset once to force it to
nweiz
2014/01/31 03:43:27
Done.
| |
148 expectAsset("app|foo.blab", "foo.blab"); | |
149 buildShouldSucceed(); | |
150 | |
151 updateSources(["app|foo.blub"]); | |
152 buildShouldSucceed(); | |
153 | |
154 expect(transformer.numRuns, completion(equals(2))); | |
155 }); | |
156 | |
157 test("an error emitted in a lazy transformer's dryRun method is caught and " | |
158 "reported", () { | |
159 initGraph(["app|foo.txt"], {"app": [ | |
160 [new LazyBadTransformer("app|foo.out")] | |
161 ]}); | |
162 | |
163 updateSources(["app|foo.txt"]); | |
164 buildShouldFail([isTransformerException(equals(LazyBadTransformer.ERROR))]); | |
165 }); | |
166 | |
167 test("an error emitted in a lazy transformer's dryRun method prevents it " | |
168 "from being materialized", () { | |
169 var transformer = new LazyBadTransformer("app|foo.out"); | |
170 initGraph(["app|foo.txt"], {"app": [[transformer]]}); | |
171 | |
172 updateSources(["app|foo.txt"]); | |
173 expectNoAsset("app|foo.out"); | |
174 buildShouldFail([isTransformerException(equals(LazyBadTransformer.ERROR))]); | |
175 expect(transformer.numRuns, completion(equals(0))); | |
176 }); | |
177 } | |
OLD | NEW |