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 pub_tests; | |
6 | |
7 import 'package:scheduled_test/scheduled_test.dart'; | |
8 | |
9 import '../descriptor.dart' as d; | |
10 import '../test_pub.dart'; | |
11 import 'utils.dart'; | |
12 | |
13 void main() { | |
14 initConfig(); | |
15 | |
16 integration("reports previous transformers as dependencies if the " | |
17 "transformer is transformed", () { | |
18 // The root app just exists so that something is transformed by pkg and qux. | |
19 d.dir(appPath, [ | |
20 d.pubspec({ | |
21 "name": "myapp", | |
22 "version": "1.0.0", | |
23 "dependencies": { | |
24 "pkg": {"path": "../pkg"}, | |
25 "qux": {"path": "../qux"} | |
26 }, | |
27 "transformers": ["pkg", "qux"] | |
28 }) | |
29 ]).create(); | |
30 | |
31 d.dir("pkg", [ | |
32 d.pubspec({ | |
33 "name": "pkg", | |
34 "version": "1.0.0", | |
35 "dependencies": { | |
36 "foo": {"path": "../foo"}, | |
37 "bar": {"path": "../bar"}, | |
38 "baz": {"path": "../baz"}, | |
39 }, | |
40 "transformers": [ | |
41 {"foo": {"\$include": "lib/pkg.dart"}}, | |
42 {"bar": {"\$exclude": "lib/transformer.dart"}}, | |
43 "baz" | |
44 ] | |
45 }), | |
46 d.dir("lib", [ | |
47 d.file("pkg.dart", ""), | |
48 d.file("transformer.dart", transformer()) | |
49 ]) | |
50 ]).create(); | |
51 | |
52 // Even though foo and bar don't modify pkg/lib/transformer.dart themselves, | |
53 // it may be modified to import a library that they modify or generate, so | |
54 // pkg will depend on them. | |
55 d.dir("foo", [ | |
56 d.libPubspec("foo", "1.0.0"), | |
57 d.dir("lib", [d.file("foo.dart", transformer())]) | |
58 ]).create(); | |
59 | |
60 d.dir("bar", [ | |
61 d.libPubspec("bar", "1.0.0"), | |
62 d.dir("lib", [d.file("bar.dart", transformer())]) | |
63 ]).create(); | |
64 | |
65 // baz transforms pkg/lib/transformer.dart, so pkg will obviously | |
66 // depend on it. | |
67 d.dir("baz", [ | |
68 d.libPubspec("baz", "1.0.0"), | |
69 d.dir("lib", [d.file("baz.dart", transformer())]) | |
70 ]).create(); | |
71 | |
72 // qux doesn't transform anything in pkg, so pkg won't depend on it. | |
73 d.dir("qux", [ | |
74 d.libPubspec("qux", "1.0.0"), | |
75 d.dir("lib", [d.file("qux.dart", transformer())]) | |
76 ]).create(); | |
77 | |
78 expectDependencies({ | |
79 'pkg': ['foo', 'bar', 'baz'], 'foo': [], 'bar': [], 'baz': [], 'qux': [] | |
80 }); | |
81 }); | |
82 | |
83 integration("reports all transitive package dependencies' transformers as " | |
84 "dependencies if the transformer is transformed", () { | |
85 // The root app just exists so that something is transformed by pkg and qux. | |
86 d.dir(appPath, [ | |
87 d.pubspec({ | |
88 "name": "myapp", | |
89 "dependencies": { | |
90 "pkg": {"path": "../pkg"}, | |
91 "qux": {"path": "../qux"} | |
92 }, | |
93 "transformers": ["pkg"] | |
94 }) | |
95 ]).create(); | |
96 | |
97 d.dir("pkg", [ | |
98 d.pubspec({ | |
99 "name": "pkg", | |
100 "version": "1.0.0", | |
101 "dependencies": { | |
102 "foo": {"path": "../foo"}, | |
103 "baz": {"path": "../baz"} | |
104 }, | |
105 "transformers": ["baz"] | |
106 }), | |
107 d.dir("lib", [d.file("pkg.dart", transformer())]) | |
108 ]).create(); | |
109 | |
110 // pkg depends on foo. Even though it's not transformed by foo, its | |
111 // transformed transformer could import foo, so it has to depend on foo. | |
112 d.dir("foo", [ | |
113 d.pubspec({ | |
114 "name": "foo", | |
115 "version": "1.0.0", | |
116 "dependencies": {"bar": {"path": "../bar"}}, | |
117 "transformers": ["foo"] | |
118 }), | |
119 d.dir("lib", [d.file("foo.dart", transformer())]) | |
120 ]).create(); | |
121 | |
122 // foo depends on bar, and like pkg's dependency on foo, the transformed | |
123 // version of foo's transformer could import bar, so foo has to depend on | |
124 // bar. | |
125 d.dir("bar", [ | |
126 d.pubspec({ | |
127 "name": "bar", | |
128 "version": "1.0.0", | |
129 "transformers": ["bar"] | |
130 }), | |
131 d.dir("lib", [d.file("bar.dart", transformer())]) | |
132 ]).create(); | |
133 | |
134 /// foo is transformed by baz. | |
135 d.dir("baz", [ | |
136 d.libPubspec("baz", "1.0.0"), | |
137 d.dir("lib", [d.file("baz.dart", transformer())]) | |
138 ]).create(); | |
139 | |
140 /// qux is not part of pkg's transitive dependency tree, so pkg shouldn't | |
141 /// depend on it. | |
142 d.dir("qux", [ | |
143 d.pubspec({ | |
144 "name": "qux", | |
145 "version": "1.0.0", | |
146 "transformers": ["qux"] | |
147 }), | |
148 d.dir("lib", [d.file("qux.dart", transformer())]) | |
149 ]).create(); | |
150 | |
151 expectDependencies({ | |
152 'pkg': ['foo', 'bar', 'baz'], 'foo': [], 'bar': [], 'baz': [], 'qux': [] | |
153 }); | |
154 }); | |
155 | |
156 integration("reports previous transformers as dependencies if a " | |
157 "nonexistent local file is imported", () { | |
158 // The root app just exists so that something is transformed by pkg and bar. | |
159 d.dir(appPath, [ | |
160 d.pubspec({ | |
161 "name": "myapp", | |
162 "dependencies": { | |
163 "pkg": {"path": "../pkg"}, | |
164 "bar": {"path": "../bar"} | |
165 }, | |
166 "transformers": ["pkg", "bar"] | |
167 }) | |
168 ]).create(); | |
169 | |
170 d.dir("pkg", [ | |
171 d.pubspec({ | |
172 "name": "pkg", | |
173 "version": "1.0.0", | |
174 "dependencies": { | |
175 "foo": {"path": "../foo"}, | |
176 "bar": {"path": "../bar"} | |
177 }, | |
178 "transformers": [{"foo": {"\$include": "lib/pkg.dart"}}] | |
179 }), | |
180 d.dir("lib", [ | |
181 d.file("pkg.dart", ""), | |
182 d.file("transformer.dart", transformer(["nonexistent.dart"])) | |
183 ]) | |
184 ]).create(); | |
185 | |
186 // Since pkg's transformer imports a nonexistent file, we assume that file | |
187 // was generated by foo's transformer. Thus pkg's transformer depends on | |
188 // foo's even though the latter doesn't transform the former. | |
189 d.dir("foo", [ | |
190 d.libPubspec("foo", "1.0.0"), | |
191 d.dir("lib", [d.file("foo.dart", transformer())]) | |
192 ]).create(); | |
193 | |
194 /// qux is not part of pkg's transitive dependency tree, so pkg shouldn't | |
195 /// depend on it. | |
196 d.dir("bar", [ | |
197 d.libPubspec("bar", "1.0.0"), | |
198 d.dir("lib", [d.file("bar.dart", transformer())]) | |
199 ]).create(); | |
200 | |
201 expectDependencies({'pkg': ['foo'], 'foo': [], 'bar': []}); | |
202 }); | |
203 | |
204 integration("reports all that package's dependencies' transformers as " | |
205 "dependencies if a non-existent file is imported from another package", | |
206 () { | |
207 d.dir(appPath, [ | |
208 d.pubspec({ | |
209 "name": "myapp", | |
210 "dependencies": { | |
211 "foo": {"path": "../foo"}, | |
212 "qux": {"path": "../qux"} | |
213 }, | |
214 "transformers": ["myapp"] | |
215 }), | |
216 d.dir("lib", [ | |
217 d.file("myapp.dart", transformer(["package:foo/nonexistent.dart"])) | |
218 ]) | |
219 ]).create(); | |
220 | |
221 // myapp imported a nonexistent file from foo so myapp will depend on every | |
222 // transformer transitively reachable from foo, since the nonexistent file | |
223 // could be generated to import anything. | |
224 d.dir("foo", [ | |
225 d.pubspec({ | |
226 "name": "foo", | |
227 "version": "1.0.0", | |
228 "dependencies": { | |
229 "bar": {"path": "../bar"}, | |
230 "baz": {"path": "../baz"} | |
231 }, | |
232 "transformers": ["foo"] | |
233 }), | |
234 d.dir("lib", [d.file("foo.dart", transformer())]) | |
235 ]).create(); | |
236 | |
237 // bar is a dependency of foo so myapp will depend on it. | |
238 d.dir("bar", [ | |
239 d.pubspec({ | |
240 "name": "bar", | |
241 "version": "1.0.0", | |
242 "transformers": ["bar"] | |
243 }), | |
244 d.dir("lib", [d.file("bar.dart", transformer())]) | |
245 ]).create(); | |
246 | |
247 // baz is a dependency of foo so myapp will depend on it. | |
248 d.dir("baz", [ | |
249 d.pubspec({ | |
250 "name": "baz", | |
251 "version": "1.0.0", | |
252 "transformers": ["baz"] | |
253 }), | |
254 d.dir("lib", [d.file("baz.dart", transformer())]) | |
255 ]).create(); | |
256 | |
257 // qux is not transitively reachable from foo so myapp won't depend on it. | |
258 d.dir("qux", [ | |
259 d.pubspec({ | |
260 "name": "qux", | |
261 "version": "1.0.0", | |
262 "transformers": ["qux"] | |
263 }), | |
264 d.dir("lib", [d.file("qux.dart", transformer())]) | |
265 ]).create(); | |
266 | |
267 expectDependencies({ | |
268 'myapp': ['foo', 'bar', 'baz'], 'foo': [], 'bar': [], 'baz': [], 'qux': [] | |
269 }); | |
270 }); | |
271 | |
272 integration("reports all that package's dependencies' transformers as " | |
273 "dependencies if a non-existent transformer is used from another package", | |
274 () { | |
275 d.dir(appPath, [ | |
276 d.pubspec({ | |
277 "name": "myapp", | |
278 "dependencies": { | |
279 "foo": {"path": "../foo"}, | |
280 "qux": {"path": "../qux"} | |
281 }, | |
282 "transformers": ["myapp"] | |
283 }), | |
284 d.dir("lib", [ | |
285 d.file("myapp.dart", transformer(["package:foo/nonexistent.dart"])) | |
286 ]) | |
287 ]).create(); | |
288 | |
289 // myapp imported a nonexistent file from foo so myapp will depend on every | |
290 // transformer transitively reachable from foo, since the nonexistent file | |
291 // could be generated to import anything. | |
292 d.dir("foo", [ | |
293 d.pubspec({ | |
294 "name": "foo", | |
295 "version": "1.0.0", | |
296 "dependencies": { | |
297 "bar": {"path": "../bar"}, | |
298 "baz": {"path": "../baz"} | |
299 }, | |
300 "transformers": ["bar"] | |
301 }) | |
302 ]).create(); | |
303 | |
304 // bar is a dependency of foo so myapp will depend on it. | |
305 d.dir("bar", [ | |
306 d.libPubspec("bar", "1.0.0"), | |
307 d.dir("lib", [d.file("bar.dart", transformer())]) | |
308 ]).create(); | |
309 | |
310 // baz is a dependency of foo so myapp will depend on it. | |
311 d.dir("baz", [ | |
312 d.pubspec({ | |
313 "name": "baz", | |
314 "version": "1.0.0", | |
315 "transformers": ["baz"] | |
316 }), | |
317 d.dir("lib", [d.file("baz.dart", transformer())]) | |
318 ]).create(); | |
319 | |
320 // qux is not transitively reachable from foo so myapp won't depend on it. | |
321 d.dir("qux", [ | |
322 d.pubspec({ | |
323 "name": "qux", | |
324 "version": "1.0.0", | |
325 "transformers": ["qux"] | |
326 }), | |
327 d.dir("lib", [d.file("qux.dart", transformer())]) | |
328 ]).create(); | |
329 | |
330 expectDependencies({ | |
331 'myapp': ['bar', 'baz'], 'bar': [], 'baz': [], 'qux': [] | |
332 }); | |
333 }); | |
334 | |
335 test("reports dependencies on transformers in past phases", () { | |
336 d.dir(appPath, [ | |
337 d.pubspec({ | |
338 "name": "myapp", | |
339 "transformers": [ | |
340 "myapp/first", | |
341 "myapp/second", | |
342 "myapp/third" | |
343 ] | |
344 }), | |
345 d.dir("lib", [ | |
346 d.file("first.dart", transformer()), | |
347 d.file("second.dart", transformer()), | |
348 d.file("third.dart", transformer()) | |
349 ]) | |
350 ]).create(); | |
351 | |
352 expectDependencies({ | |
353 'myapp/first': [], | |
354 'myapp/second': ['myapp/first'], | |
355 'myapp/third': ['myapp/second', 'myapp/first'] | |
356 }); | |
357 }); | |
358 | |
359 integration("considers the entrypoint package's dev and override " | |
360 "dependencies", () { | |
361 d.dir(appPath, [ | |
362 d.pubspec({ | |
363 "name": "myapp", | |
364 "dependencies": {"foo": {"path": "../foo"}}, | |
365 "dev_dependencies": {"bar": {"path": "../bar"}}, | |
366 "dependency_overrides": {"baz": {"path": "../baz"}}, | |
367 "transformers": ["foo", "myapp"] | |
368 }), | |
369 d.dir("lib", [d.file("myapp.dart", transformer())]) | |
370 ]).create(); | |
371 | |
372 // foo transforms myapp's transformer so it could import from bar or baz. | |
373 d.dir("foo", [ | |
374 d.pubspec({ | |
375 "name": "foo", | |
376 "version": "1.0.0", | |
377 "transformers": ["foo"] | |
378 }), | |
379 d.dir("lib", [d.file("foo.dart", transformer())]) | |
380 ]).create(); | |
381 | |
382 // bar is a dev dependency that myapp could import from, so myapp should | |
383 // depend on it. | |
384 d.dir("bar", [ | |
385 d.pubspec({ | |
386 "name": "bar", | |
387 "version": "1.0.0", | |
388 "transformers": ["bar"] | |
389 }), | |
390 d.dir("lib", [d.file("bar.dart", transformer())]) | |
391 ]).create(); | |
392 | |
393 // baz is an override dependency that myapp could import from, so myapp | |
394 // should depend on it. | |
395 d.dir("baz", [ | |
396 d.pubspec({ | |
397 "name": "baz", | |
398 "version": "1.0.0", | |
399 "transformers": ["baz"] | |
400 }), | |
401 d.dir("lib", [d.file("baz.dart", transformer())]) | |
402 ]).create(); | |
403 | |
404 expectDependencies({ | |
405 'myapp': ['foo', 'bar', 'baz'], 'foo': [], 'bar': [], 'baz': [] | |
406 }); | |
407 }); | |
408 | |
409 integration("doesn't consider a non-entrypoint package's dev and override " | |
410 "dependencies", () { | |
411 // myapp just exists so that pkg isn't the entrypoint. | |
412 d.dir(appPath, [ | |
413 d.pubspec({ | |
414 "name": "myapp", | |
415 "dependencies": {"pkg": {"path": "../pkg"}} | |
416 }) | |
417 ]).create(); | |
418 | |
419 d.dir("pkg", [ | |
420 d.pubspec({ | |
421 "name": "pkg", | |
422 "dependencies": {"foo": {"path": "../foo"}}, | |
423 "dev_dependencies": {"bar": {"path": "../bar"}}, | |
424 "dependency_overrides": {"baz": {"path": "../baz"}}, | |
425 "transformers": ["foo", "pkg"] | |
426 }), | |
427 d.dir("lib", [d.file("pkg.dart", transformer())]) | |
428 ]).create(); | |
429 | |
430 // foo transforms pkg's transformer so it could theoretcially import from | |
431 // bar or baz. However, since pkg isn't the entrypoint, it doesn't have | |
432 // access to them. | |
433 d.dir("foo", [ | |
434 d.pubspec({ | |
435 "name": "foo", | |
436 "version": "1.0.0", | |
437 "transformers": ["foo"] | |
438 }), | |
439 d.dir("lib", [d.file("foo.dart", transformer())]) | |
440 ]).create(); | |
441 | |
442 // bar is a dev dependency that myapp can't import from, so myapp shouldn't | |
443 // depend on it. | |
444 d.dir("bar", [ | |
445 d.pubspec({ | |
446 "name": "bar", | |
447 "version": "1.0.0", | |
448 "transformers": ["bar"] | |
449 }), | |
450 d.dir("lib", [d.file("bar.dart", transformer())]) | |
451 ]).create(); | |
452 | |
453 // baz is a dev dependency that myapp can't import from, so myapp shouldn't | |
454 // depend on it. | |
455 d.dir("baz", [ | |
456 d.pubspec({ | |
457 "name": "baz", | |
458 "version": "1.0.0", | |
459 "transformers": ["baz"] | |
460 }), | |
461 d.dir("lib", [d.file("baz.dart", transformer())]) | |
462 ]).create(); | |
463 | |
464 expectDependencies({'pkg': ['foo'], 'foo': [], 'bar': [], 'baz': []}); | |
465 }); | |
466 } | |
OLD | NEW |