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 '../descriptor.dart' as d; | |
8 import '../test_pub.dart'; | |
9 import 'utils.dart'; | |
10 | |
11 void main() { | |
12 initConfig(); | |
13 | |
14 integration("allows a package dependency cycle that's unrelated to " | |
15 "transformers", () { | |
16 d.dir(appPath, [ | |
17 d.pubspec({ | |
18 "name": "myapp", | |
19 "dependencies": {"foo": {"path": "../foo"}}, | |
20 "transformers": ["myapp/first", "myapp/second"] | |
21 }), | |
22 d.dir('lib', [ | |
23 d.file("first.dart", transformer()), | |
24 d.file("second.dart", transformer()) | |
25 ]) | |
26 ]).create(); | |
27 | |
28 d.dir("foo", [ | |
29 d.libPubspec("foo", "1.0.0", deps: {"bar": {"path": "../bar"}}) | |
30 ]).create(); | |
31 | |
32 d.dir("bar", [ | |
33 d.libPubspec("bar", "1.0.0", deps: {"baz": {"path": "../baz"}}) | |
34 ]).create(); | |
35 | |
36 d.dir("baz", [ | |
37 d.libPubspec("baz", "1.0.0", deps: {"foo": {"path": "../foo"}}) | |
38 ]).create(); | |
39 | |
40 expectDependencies({'myapp/first': [], 'myapp/second': ['myapp/first']}); | |
41 }); | |
42 | |
43 integration("disallows a package dependency cycle that may be related to " | |
44 "transformers", () { | |
45 // Two layers of myapp transformers are necessary here because otherwise pub | |
46 // will figure out that the transformer doesn't import "foo" and thus | |
47 // doesn't transitively import itself. Import loops are tested below. | |
48 d.dir(appPath, [ | |
49 d.pubspec({ | |
50 "name": "myapp", | |
51 "dependencies": {"foo": {"path": "../foo"}}, | |
52 "transformers": ["myapp/first", "myapp/second"] | |
53 }), | |
54 d.dir('lib', [ | |
55 d.file("first.dart", transformer()), | |
56 d.file("second.dart", transformer()) | |
57 ]) | |
58 ]).create(); | |
59 | |
60 d.dir("foo", [ | |
61 d.libPubspec("foo", "1.0.0", deps: {"bar": {"path": "../bar"}}) | |
62 ]).create(); | |
63 | |
64 d.dir("bar", [ | |
65 d.libPubspec("bar", "1.0.0", deps: {"myapp": {"path": "../myapp"}}) | |
66 ]).create(); | |
67 | |
68 expectCycleException([ | |
69 "myapp is transformed by myapp/second", | |
70 "myapp depends on foo", | |
71 "foo depends on bar", | |
72 "bar depends on myapp", | |
73 "myapp is transformed by myapp/first" | |
74 ]); | |
75 }); | |
76 | |
77 integration("disallows a transformation dependency cycle", () { | |
78 d.dir(appPath, [ | |
79 d.pubspec({ | |
80 "name": "myapp", | |
81 "dependencies": {"foo": {"path": "../foo"}}, | |
82 "transformers": ["foo"] | |
83 }), | |
84 d.dir('lib', [d.file("myapp.dart", transformer())]) | |
85 ]).create(); | |
86 | |
87 d.dir("foo", [ | |
88 d.pubspec({ | |
89 "name": "foo", | |
90 "dependencies": {"bar": {"path": "../bar"}}, | |
91 "transformers": ["bar"] | |
92 }), | |
93 d.dir('lib', [d.file("foo.dart", transformer())]) | |
94 ]).create(); | |
95 | |
96 d.dir("bar", [ | |
97 d.pubspec({ | |
98 "name": "bar", | |
99 "dependencies": {"myapp": {"path": "../myapp"}}, | |
100 "transformers": ["myapp"] | |
101 }), | |
102 d.dir('lib', [d.file("bar.dart", transformer())]) | |
103 ]).create(); | |
104 | |
105 expectCycleException([ | |
106 "bar is transformed by myapp", | |
107 "myapp is transformed by foo", | |
108 "foo is transformed by bar" | |
109 ]); | |
110 }); | |
111 | |
112 integration("allows a cross-package import cycle that's unrelated to " | |
113 "transformers", () { | |
114 d.dir(appPath, [ | |
115 d.pubspec({ | |
116 "name": "myapp", | |
117 "dependencies": {"foo": {"path": "../foo"}}, | |
118 "transformers": ["myapp"] | |
119 }), | |
120 d.dir('lib', [ | |
121 d.file("myapp.dart", transformer(['package:foo/foo.dart'])) | |
122 ]) | |
123 ]).create(); | |
124 | |
125 d.dir("foo", [ | |
126 d.libPubspec("foo", "1.0.0", deps: {"bar": {"path": "../bar"}}), | |
127 d.dir('lib', [d.file("foo.dart", "import 'package:bar/bar.dart';")]) | |
128 ]).create(); | |
129 | |
130 d.dir("bar", [ | |
131 d.libPubspec("bar", "1.0.0", deps: {"baz": {"path": "../baz"}}), | |
132 d.dir('lib', [d.file("bar.dart", "import 'package:baz/baz.dart';")]) | |
133 ]).create(); | |
134 | |
135 d.dir("baz", [ | |
136 d.libPubspec("baz", "1.0.0", deps: {"foo": {"path": "../foo"}}), | |
137 d.dir('lib', [d.file("baz.dart", "import 'package:foo/foo.dart';")]) | |
138 ]).create(); | |
139 | |
140 expectDependencies({'myapp': []}); | |
141 }); | |
142 | |
143 integration("disallows a cross-package import cycle that's related to " | |
144 "transformers", () { | |
145 d.dir(appPath, [ | |
146 d.pubspec({ | |
147 "name": "myapp", | |
148 "dependencies": {"foo": {"path": "../foo"}}, | |
149 "transformers": ["myapp"] | |
150 }), | |
151 d.dir('lib', [ | |
152 d.file("myapp.dart", transformer(['package:foo/foo.dart'])) | |
153 ]) | |
154 ]).create(); | |
155 | |
156 d.dir("foo", [ | |
157 d.libPubspec("foo", "1.0.0", deps: {"bar": {"path": "../bar"}}), | |
158 d.dir('lib', [d.file("foo.dart", "import 'package:bar/bar.dart';")]) | |
159 ]).create(); | |
160 | |
161 d.dir("bar", [ | |
162 d.libPubspec("bar", "1.0.0", deps: {"myapp": {"path": "../myapp"}}), | |
163 d.dir('lib', [d.file("bar.dart", "import 'package:myapp/myapp.dart';")]) | |
164 ]).create(); | |
165 | |
166 expectCycleException([ | |
167 "myapp is transformed by myapp", | |
168 "myapp depends on foo", | |
169 "foo depends on bar", | |
170 "bar depends on myapp" | |
171 ]); | |
172 }); | |
173 | |
174 integration("allows a single-package import cycle that's unrelated to " | |
175 "transformers", () { | |
176 d.dir(appPath, [ | |
177 d.pubspec({ | |
178 "name": "myapp", | |
179 "dependencies": {"foo": {"path": "../foo"}}, | |
180 "transformers": ["myapp"] | |
181 }), | |
182 d.dir('lib', [ | |
183 d.file("myapp.dart", transformer(['foo.dart'])), | |
184 d.file("foo.dart", "import 'bar.dart';"), | |
185 d.file("bar.dart", "import 'baz.dart';"), | |
186 d.file("baz.dart", "import 'foo.dart';") | |
187 ]) | |
188 ]).create(); | |
189 | |
190 expectDependencies({'myapp': []}); | |
191 }); | |
192 | |
193 integration("allows a single-package import cycle that's related to " | |
194 "transformers", () { | |
195 d.dir(appPath, [ | |
196 d.pubspec({ | |
197 "name": "myapp", | |
198 "dependencies": {"foo": {"path": "../foo"}}, | |
199 "transformers": ["myapp"] | |
200 }), | |
201 d.dir('lib', [ | |
202 d.file("myapp.dart", transformer(['foo.dart'])), | |
203 d.file("foo.dart", "import 'bar.dart';"), | |
204 d.file("bar.dart", "import 'myapp.dart';"), | |
205 ]) | |
206 ]).create(); | |
207 | |
208 expectDependencies({'myapp': []}); | |
209 }); | |
210 } | |
OLD | NEW |