OLD | NEW |
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.source_test; | 5 library barback.test.package_graph.source_test; |
6 | 6 |
7 import 'package:barback/src/utils.dart'; | |
8 import 'package:scheduled_test/scheduled_test.dart'; | 7 import 'package:scheduled_test/scheduled_test.dart'; |
9 | 8 |
10 import '../utils.dart'; | 9 import '../utils.dart'; |
11 | 10 |
12 main() { | 11 main() { |
13 initConfig(); | 12 initConfig(); |
14 | 13 |
15 test("does not report asset not found errors in results", () { | 14 test("does not report asset not found errors in results", () { |
16 initGraph(["app|bar.txt"]); | 15 initGraph(["app|bar.txt"]); |
17 | 16 |
18 // Trigger a build. | 17 // Trigger a build. |
19 updateSources(["app|bar.txt"]); | 18 updateSources(["app|bar.txt"]); |
20 | 19 |
21 expectNoAsset("app|foo.txt"); | 20 expectNoAsset("app|foo.txt"); |
22 buildShouldSucceed(); | 21 buildShouldSucceed(); |
23 }); | 22 }); |
24 | 23 |
25 test("reports an error for an unprovided package", () { | 24 test("reports an error for an unprovided package", () { |
26 initGraph(); | 25 initGraph(); |
27 expect(() => updateSourcesSync(["unknown|foo.txt"]), throwsArgumentError); | 26 expect(() => updateSourcesSync(["unknown|foo.txt"]), throwsArgumentError); |
28 }); | 27 }); |
29 | 28 |
30 test("reports an error for an unprovided source", () { | 29 test("reports an error for an unprovided source", () { |
31 initGraph(["app|known.txt"], {"app": [ | 30 initGraph([ |
32 // Have a dummy transformer so that barback at least tries to load the | 31 "app|known.txt" |
33 // asset. | 32 ], { |
34 [new RewriteTransformer("a", "b")] | 33 "app": [ |
35 ]}); | 34 // Have a dummy transformer so that barback at least tries to load the |
| 35 // asset. |
| 36 [new RewriteTransformer("a", "b")] |
| 37 ] |
| 38 }); |
36 | 39 |
37 updateSources(["app|unknown.txt"]); | 40 updateSources(["app|unknown.txt"]); |
38 | 41 |
39 buildShouldFail([ | 42 buildShouldFail([ |
40 isAssetLoadException("app|unknown.txt", | 43 isAssetLoadException( |
41 isAssetNotFoundException("app|unknown.txt")) | 44 "app|unknown.txt", isAssetNotFoundException("app|unknown.txt")) |
42 ]); | 45 ]); |
43 }); | 46 }); |
44 | 47 |
45 test("reports missing input errors in results", () { | 48 test("reports missing input errors in results", () { |
46 initGraph({"app|a.txt": "a.inc"}, {"app": [ | 49 initGraph({ |
47 [new ManyToOneTransformer("txt")] | 50 "app|a.txt": "a.inc" |
48 ]}); | 51 }, { |
| 52 "app": [ |
| 53 [new ManyToOneTransformer("txt")] |
| 54 ] |
| 55 }); |
49 | 56 |
50 updateSources(["app|a.txt"]); | 57 updateSources(["app|a.txt"]); |
51 expectNoAsset("app|a.out"); | 58 expectNoAsset("app|a.out"); |
52 buildShouldFail([isMissingInputException("app|a.inc")]); | 59 buildShouldFail([isMissingInputException("app|a.inc")]); |
53 }); | 60 }); |
54 | 61 |
55 test("reports an error if a transformer emits an asset for another package", | 62 test("reports an error if a transformer emits an asset for another package", |
56 () { | 63 () { |
57 initGraph(["app|foo.txt"], { | 64 initGraph([ |
58 "app": [[new CreateAssetTransformer("wrong|foo.txt")]] | 65 "app|foo.txt" |
| 66 ], { |
| 67 "app": [ |
| 68 [new CreateAssetTransformer("wrong|foo.txt")] |
| 69 ] |
59 }); | 70 }); |
60 | 71 |
61 updateSources(["app|foo.txt"]); | 72 updateSources(["app|foo.txt"]); |
62 buildShouldFail([isInvalidOutputException("wrong|foo.txt")]); | 73 buildShouldFail([isInvalidOutputException("wrong|foo.txt")]); |
63 }); | 74 }); |
64 | 75 |
65 test("fails if a non-primary input is removed", () { | 76 test("fails if a non-primary input is removed", () { |
66 initGraph({ | 77 initGraph({ |
67 "app|a.txt": "a.inc,b.inc,c.inc", | 78 "app|a.txt": "a.inc,b.inc,c.inc", |
68 "app|a.inc": "a", | 79 "app|a.inc": "a", |
69 "app|b.inc": "b", | 80 "app|b.inc": "b", |
70 "app|c.inc": "c" | 81 "app|c.inc": "c" |
71 }, {"app": [ | 82 }, { |
72 [new ManyToOneTransformer("txt")] | 83 "app": [ |
73 ]}); | 84 [new ManyToOneTransformer("txt")] |
| 85 ] |
| 86 }); |
74 | 87 |
75 updateSources(["app|a.txt", "app|a.inc", "app|b.inc", "app|c.inc"]); | 88 updateSources(["app|a.txt", "app|a.inc", "app|b.inc", "app|c.inc"]); |
76 expectAsset("app|a.out", "abc"); | 89 expectAsset("app|a.out", "abc"); |
77 buildShouldSucceed(); | 90 buildShouldSucceed(); |
78 | 91 |
79 removeSources(["app|b.inc"]); | 92 removeSources(["app|b.inc"]); |
80 buildShouldFail([isMissingInputException("app|b.inc")]); | 93 buildShouldFail([isMissingInputException("app|b.inc")]); |
81 expectNoAsset("app|a.out"); | 94 expectNoAsset("app|a.out"); |
82 }); | 95 }); |
83 | 96 |
84 test("catches transformer exceptions and reports them", () { | 97 test("catches transformer exceptions and reports them", () { |
85 initGraph(["app|foo.txt"], {"app": [ | 98 initGraph([ |
86 [new BadTransformer(["app|foo.out"])] | 99 "app|foo.txt" |
87 ]}); | 100 ], { |
| 101 "app": [ |
| 102 [ |
| 103 new BadTransformer(["app|foo.out"]) |
| 104 ] |
| 105 ] |
| 106 }); |
88 | 107 |
89 updateSources(["app|foo.txt"]); | 108 updateSources(["app|foo.txt"]); |
90 expectNoAsset("app|foo.out"); | 109 expectNoAsset("app|foo.out"); |
91 buildShouldFail([isTransformerException(equals(BadTransformer.ERROR))]); | 110 buildShouldFail([isTransformerException(equals(BadTransformer.ERROR))]); |
92 }); | 111 }); |
93 | 112 |
94 test("catches errors even if nothing is waiting for process results", () { | 113 test("catches errors even if nothing is waiting for process results", () { |
95 initGraph(["app|foo.txt"], {"app": [[new BadTransformer([])]]}); | 114 initGraph([ |
| 115 "app|foo.txt" |
| 116 ], { |
| 117 "app": [ |
| 118 [new BadTransformer([])] |
| 119 ] |
| 120 }); |
96 | 121 |
97 updateSources(["app|foo.txt"]); | 122 updateSources(["app|foo.txt"]); |
98 // Note: No asset requests here. | 123 // Note: No asset requests here. |
99 buildShouldFail([isTransformerException(equals(BadTransformer.ERROR))]); | 124 buildShouldFail([isTransformerException(equals(BadTransformer.ERROR))]); |
100 }); | 125 }); |
101 | 126 |
102 test("discards outputs from failed transforms", () { | 127 test("discards outputs from failed transforms", () { |
103 initGraph(["app|foo.txt"], {"app": [ | 128 initGraph([ |
104 [new BadTransformer(["a.out", "b.out"])] | 129 "app|foo.txt" |
105 ]}); | 130 ], { |
| 131 "app": [ |
| 132 [ |
| 133 new BadTransformer(["a.out", "b.out"]) |
| 134 ] |
| 135 ] |
| 136 }); |
106 | 137 |
107 updateSources(["app|foo.txt"]); | 138 updateSources(["app|foo.txt"]); |
108 expectNoAsset("app|a.out"); | 139 expectNoAsset("app|a.out"); |
109 }); | 140 }); |
110 | 141 |
111 test("fails if only one package fails", () { | 142 test("fails if only one package fails", () { |
112 initGraph(["pkg1|foo.txt", "pkg2|foo.txt"], | 143 initGraph([ |
113 {"pkg1": [[new BadTransformer([])]]}); | 144 "pkg1|foo.txt", |
| 145 "pkg2|foo.txt" |
| 146 ], { |
| 147 "pkg1": [ |
| 148 [new BadTransformer([])] |
| 149 ] |
| 150 }); |
114 | 151 |
115 updateSources(["pkg1|foo.txt", "pkg2|foo.txt"]); | 152 updateSources(["pkg1|foo.txt", "pkg2|foo.txt"]); |
116 expectAsset("pkg2|foo.txt", "foo"); | 153 expectAsset("pkg2|foo.txt", "foo"); |
117 buildShouldFail([isTransformerException(equals(BadTransformer.ERROR))]); | 154 buildShouldFail([isTransformerException(equals(BadTransformer.ERROR))]); |
118 }); | 155 }); |
119 | 156 |
120 test("emits multiple failures if multiple packages fail", () { | 157 test("emits multiple failures if multiple packages fail", () { |
121 initGraph(["pkg1|foo.txt", "pkg2|foo.txt"], { | 158 initGraph([ |
122 "pkg1": [[new BadTransformer([])]], | 159 "pkg1|foo.txt", |
123 "pkg2": [[new BadTransformer([])]] | 160 "pkg2|foo.txt" |
| 161 ], { |
| 162 "pkg1": [ |
| 163 [new BadTransformer([])] |
| 164 ], |
| 165 "pkg2": [ |
| 166 [new BadTransformer([])] |
| 167 ] |
124 }); | 168 }); |
125 | 169 |
126 updateSources(["pkg1|foo.txt", "pkg2|foo.txt"]); | 170 updateSources(["pkg1|foo.txt", "pkg2|foo.txt"]); |
127 buildShouldFail([ | 171 buildShouldFail([ |
128 isTransformerException(equals(BadTransformer.ERROR)), | 172 isTransformerException(equals(BadTransformer.ERROR)), |
129 isTransformerException(equals(BadTransformer.ERROR)) | 173 isTransformerException(equals(BadTransformer.ERROR)) |
130 ]); | 174 ]); |
131 }); | 175 }); |
132 | 176 |
133 test("an error loading an asset removes the asset from the graph", () { | 177 test("an error loading an asset removes the asset from the graph", () { |
134 initGraph(["app|foo.txt"], {"app": [ | 178 initGraph([ |
135 // Have a dummy transformer so that barback at least tries to load the | 179 "app|foo.txt" |
136 // asset. | 180 ], { |
137 [new RewriteTransformer("a", "b")] | 181 "app": [ |
138 ]}); | 182 // Have a dummy transformer so that barback at least tries to load the |
| 183 // asset. |
| 184 [new RewriteTransformer("a", "b")] |
| 185 ] |
| 186 }); |
139 | 187 |
140 setAssetError("app|foo.txt"); | 188 setAssetError("app|foo.txt"); |
141 updateSources(["app|foo.txt"]); | 189 updateSources(["app|foo.txt"]); |
142 expectNoAsset("app|foo.txt"); | 190 expectNoAsset("app|foo.txt"); |
143 buildShouldFail([ | 191 buildShouldFail([ |
144 isAssetLoadException("app|foo.txt", isMockLoadException("app|foo.txt")) | 192 isAssetLoadException("app|foo.txt", isMockLoadException("app|foo.txt")) |
145 ]); | 193 ]); |
146 }); | 194 }); |
147 | 195 |
148 test("a synchronous error loading an asset removes the asset from the graph", | 196 test("a synchronous error loading an asset removes the asset from the graph", |
149 () { | 197 () { |
150 initGraph(["app|foo.txt"], {"app": [ | 198 initGraph([ |
151 // Have a dummy transformer so that barback at least tries to load the | 199 "app|foo.txt" |
152 // asset. | 200 ], { |
153 [new RewriteTransformer("a", "b")] | 201 "app": [ |
154 ]}); | 202 // Have a dummy transformer so that barback at least tries to load the |
| 203 // asset. |
| 204 [new RewriteTransformer("a", "b")] |
| 205 ] |
| 206 }); |
155 | 207 |
156 setAssetError("app|foo.txt", async: false); | 208 setAssetError("app|foo.txt", async: false); |
157 updateSources(["app|foo.txt"]); | 209 updateSources(["app|foo.txt"]); |
158 expectNoAsset("app|foo.txt"); | 210 expectNoAsset("app|foo.txt"); |
159 buildShouldFail([ | 211 buildShouldFail([ |
160 isAssetLoadException("app|foo.txt", isMockLoadException("app|foo.txt")) | 212 isAssetLoadException("app|foo.txt", isMockLoadException("app|foo.txt")) |
161 ]); | 213 ]); |
162 }); | 214 }); |
163 | 215 |
164 test("an asset isn't passed through a transformer with an error", () { | 216 test("an asset isn't passed through a transformer with an error", () { |
165 initGraph(["app|foo.txt"], {"app": [[new BadTransformer([])]]}); | 217 initGraph([ |
| 218 "app|foo.txt" |
| 219 ], { |
| 220 "app": [ |
| 221 [new BadTransformer([])] |
| 222 ] |
| 223 }); |
166 | 224 |
167 updateSources(["app|foo.txt"]); | 225 updateSources(["app|foo.txt"]); |
168 expectNoAsset("app|foo.txt"); | 226 expectNoAsset("app|foo.txt"); |
169 buildShouldFail([isTransformerException(equals(BadTransformer.ERROR))]); | 227 buildShouldFail([isTransformerException(equals(BadTransformer.ERROR))]); |
170 }); | 228 }); |
171 | 229 |
172 test("a transformer that logs errors shouldn't produce output", () { | 230 test("a transformer that logs errors shouldn't produce output", () { |
173 initGraph(["app|foo.txt"], {"app": [ | 231 initGraph([ |
174 [new BadLogTransformer(["app|out.txt"])] | 232 "app|foo.txt" |
175 ]}); | 233 ], { |
| 234 "app": [ |
| 235 [ |
| 236 new BadLogTransformer(["app|out.txt"]) |
| 237 ] |
| 238 ] |
| 239 }); |
176 | 240 |
177 updateSources(["app|foo.txt"]); | 241 updateSources(["app|foo.txt"]); |
178 expectNoAsset("app|foo.txt"); | 242 expectNoAsset("app|foo.txt"); |
179 expectNoAsset("app|out.txt"); | 243 expectNoAsset("app|out.txt"); |
180 buildShouldFail([ | 244 buildShouldFail([ |
181 isTransformerException(equals("first error")), | 245 isTransformerException(equals("first error")), |
182 isTransformerException(equals("second error")) | 246 isTransformerException(equals("second error")) |
183 ]); | 247 ]); |
184 }); | 248 }); |
185 | 249 |
186 test("a transformer can catch an error loading a secondary input", () { | 250 test("a transformer can catch an error loading a secondary input", () { |
187 initGraph(["app|foo.txt"], {"app": [ | 251 initGraph([ |
188 [new CatchAssetNotFoundTransformer(".txt", "app|nothing")] | 252 "app|foo.txt" |
189 ]}); | 253 ], { |
| 254 "app": [ |
| 255 [new CatchAssetNotFoundTransformer(".txt", "app|nothing")] |
| 256 ] |
| 257 }); |
190 | 258 |
191 updateSources(["app|foo.txt"]); | 259 updateSources(["app|foo.txt"]); |
192 expectAsset("app|foo.txt", "failed to load app|nothing"); | 260 expectAsset("app|foo.txt", "failed to load app|nothing"); |
193 buildShouldSucceed(); | 261 buildShouldSucceed(); |
194 }); | 262 }); |
195 | 263 |
196 test("a transformer that fails due to a missing secondary input is re-run " | 264 test( |
| 265 "a transformer that fails due to a missing secondary input is re-run " |
197 "when that input appears", () { | 266 "when that input appears", () { |
198 initGraph({ | 267 initGraph({ |
199 "app|foo.txt": "bar.inc", | 268 "app|foo.txt": "bar.inc", |
200 "app|bar.inc": "bar" | 269 "app|bar.inc": "bar" |
201 }, {"app": [ | 270 }, { |
202 [new ManyToOneTransformer("txt")] | 271 "app": [ |
203 ]}); | 272 [new ManyToOneTransformer("txt")] |
| 273 ] |
| 274 }); |
204 | 275 |
205 updateSources(["app|foo.txt"]); | 276 updateSources(["app|foo.txt"]); |
206 expectNoAsset("app|foo.out"); | 277 expectNoAsset("app|foo.out"); |
207 buildShouldFail([isMissingInputException("app|bar.inc")]); | 278 buildShouldFail([isMissingInputException("app|bar.inc")]); |
208 | 279 |
209 updateSources(["app|bar.inc"]); | 280 updateSources(["app|bar.inc"]); |
210 expectAsset("app|foo.out", "bar"); | 281 expectAsset("app|foo.out", "bar"); |
211 buildShouldSucceed(); | 282 buildShouldSucceed(); |
212 }); | 283 }); |
213 } | 284 } |
OLD | NEW |