OLD | NEW |
---|---|
(Empty) | |
1 // Copyright (c) 2014, the Dart project authors. Please see the AUTHORS d.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 '../serve/utils.dart'; | |
12 | |
13 // TODO(nweiz): Currently scheduled_test.setUp doesn't play well with test_pub, | |
14 // since it only assigns the sandbox directory once the main test body has | |
15 // run. Fix this and move this to a real setUp call. | |
16 void setUp() { | |
17 servePackages((builder) { | |
18 builder.serveRepoPackage('barback'); | |
19 | |
20 builder.serve("foo", "1.2.3", | |
21 deps: {'barback': 'any'}, | |
22 contents: [ | |
23 d.dir("lib", [ | |
24 d.file("transformer.dart", replaceTransformer("Hello", "Goodbye")) | |
25 ]) | |
26 ]); | |
27 | |
28 builder.serve("bar", "1.2.3", | |
29 deps: {'barback': 'any'}, | |
30 contents: [ | |
31 d.dir("lib", [ | |
32 d.file("transformer.dart", replaceTransformer("Goodbye", "See ya")) | |
33 ]) | |
34 ]); | |
35 }); | |
36 | |
37 d.dir(appPath, [ | |
38 d.pubspec({ | |
39 "name": "myapp", | |
40 "dependencies": { | |
41 "foo": "1.2.3", | |
42 "bar": "1.2.3" | |
43 }, | |
44 "transformers": ["foo"] | |
45 }), | |
46 d.dir("bin", [ | |
47 d.file("myapp.dart", "main() => print('Hello!');") | |
48 ]) | |
49 ]).create(); | |
50 | |
51 pubGet(); | |
52 } | |
53 | |
54 main() { | |
55 initConfig(); | |
56 | |
57 integration("caches a transformer snapshot", () { | |
58 setUp(); | |
59 | |
60 var process = pubRun(args: ['myapp']); | |
61 process.stdout.expect("Goodbye!"); | |
62 process.shouldExit(); | |
63 | |
64 d.dir(appPath, [ | |
65 d.dir(".pub/transformers", [ | |
66 d.file("manifest.txt", "0.1.2+3\nfoo"), | |
67 d.matcherFile("transformers.snapshot", isNot(isEmpty)) | |
68 ]) | |
69 ]).validate(); | |
70 | |
71 // Run the executable again to make sure loading the transformer from the | |
72 // cache works. | |
73 process = pubRun(args: ['myapp']); | |
74 process.stdout.expect("Goodbye!"); | |
75 process.shouldExit(); | |
76 }); | |
77 | |
78 integration("recaches if the SDK version is out-of-date", () { | |
79 setUp(); | |
80 | |
81 d.dir(appPath, [ | |
82 d.dir(".pub/transformers", [ | |
83 // The version 0.0.1 is different than the test version 0.1.2+3. | |
84 d.file("manifest.txt", "0.0.1\nfoo"), | |
85 d.file("transformers.snapshot", "junk") | |
86 ]) | |
87 ]).create(); | |
88 | |
89 var process = pubRun(args: ['myapp']); | |
90 process.stdout.expect("Goodbye!"); | |
91 process.shouldExit(); | |
92 | |
93 d.dir(appPath, [ | |
94 d.dir(".pub/transformers", [ | |
95 d.file("manifest.txt", "0.1.2+3\nfoo"), | |
96 d.matcherFile("transformers.snapshot", isNot(isEmpty)) | |
97 ]) | |
98 ]).validate(); | |
99 }); | |
100 | |
101 integration("recaches if the transformers change", () { | |
102 setUp(); | |
103 | |
104 var process = pubRun(args: ['myapp']); | |
105 process.stdout.expect("Goodbye!"); | |
106 process.shouldExit(); | |
107 | |
108 d.dir(appPath, [ | |
109 d.dir(".pub/transformers", [ | |
110 d.file("manifest.txt", "0.1.2+3\nfoo"), | |
111 d.matcherFile("transformers.snapshot", isNot(isEmpty)) | |
112 ]) | |
113 ]).validate(); | |
114 | |
115 d.dir(appPath, [ | |
116 d.pubspec({ | |
117 "name": "myapp", | |
118 "dependencies": { | |
119 "foo": "1.2.3", | |
120 "bar": "1.2.3" | |
121 }, | |
122 "transformers": ["foo", "bar"] | |
123 }), | |
124 d.dir("bin", [ | |
125 d.file("myapp.dart", "main() => print('Hello!');") | |
126 ]) | |
127 ]).create(); | |
128 | |
129 process = pubRun(args: ['myapp']); | |
130 process.stdout.expect("See ya!"); | |
131 process.shouldExit(); | |
132 | |
133 d.dir(appPath, [ | |
134 d.dir(".pub/transformers", [ | |
135 d.file("manifest.txt", "0.1.2+3\nbar,foo"), | |
136 d.matcherFile("transformers.snapshot", isNot(isEmpty)) | |
137 ]) | |
138 ]).validate(); | |
139 }); | |
140 | |
141 integration("recaches if the transformer version changes", () { | |
142 setUp(); | |
143 | |
144 var process = pubRun(args: ['myapp']); | |
145 process.stdout.expect("Goodbye!"); | |
146 process.shouldExit(); | |
147 | |
148 d.dir(appPath, [ | |
149 d.dir(".pub/transformers", [ | |
150 d.file("manifest.txt", "0.1.2+3\nfoo"), | |
151 d.matcherFile("transformers.snapshot", isNot(isEmpty)) | |
152 ]) | |
153 ]).validate(); | |
154 | |
155 servePackages((builder) { | |
156 builder.serve("foo", "2.0.0", | |
157 deps: {'barback': 'any'}, | |
158 contents: [ | |
159 d.dir("lib", [ | |
160 d.file("transformer.dart", replaceTransformer("Hello", "New")) | |
161 ]) | |
162 ]); | |
163 }); | |
164 | |
165 d.dir(appPath, [ | |
166 d.pubspec({ | |
167 "name": "myapp", | |
168 "dependencies": {"foo": "any"}, | |
169 "transformers": ["foo"] | |
170 }) | |
171 ]).create(); | |
172 | |
173 pubUpgrade(); | |
174 | |
175 process = pubRun(args: ['myapp']); | |
176 process.stdout.expect("New!"); | |
177 process.shouldExit(); | |
178 | |
179 d.dir(appPath, [ | |
180 d.dir(".pub/transformers", [ | |
181 d.file("manifest.txt", "0.1.2+3\nfoo"), | |
182 d.matcherFile("transformers.snapshot", isNot(isEmpty)) | |
183 ]) | |
184 ]).validate(); | |
185 }); | |
186 | |
187 | |
188 integration("recaches if a transitive dependency version changes", () { | |
189 servePackages((builder) { | |
190 builder.serveRepoPackage('barback'); | |
191 | |
192 builder.serve("foo", "1.2.3", | |
193 deps: { | |
194 'barback': 'any', | |
195 'bar': 'any' | |
196 }, | |
197 contents: [ | |
198 d.dir("lib", [ | |
199 d.file("transformer.dart", """ | |
200 import 'dart:async'; | |
Bob Nystrom
2014/09/16 19:54:26
Do you mind pulling this string out to a separate
| |
201 | |
202 import 'package:barback/barback.dart'; | |
203 import 'package:bar/bar.dart'; | |
204 | |
205 class ReplaceTransformer extends Transformer { | |
206 ReplaceTransformer.asPlugin(); | |
207 | |
208 String get allowedExtensions => '.dart'; | |
209 | |
210 Future apply(Transform transform) { | |
211 return transform.primaryInput.readAsString().then((contents) { | |
212 transform.addOutput(new Asset.fromString( | |
213 transform.primaryInput.id, | |
214 contents.replaceAll("Hello", replacement))); | |
215 }); | |
216 } | |
217 } | |
218 """) | |
219 ]) | |
220 ]); | |
221 | |
222 builder.serve("bar", "1.2.3", contents: [ | |
223 d.dir("lib", [ | |
224 d.file("bar.dart", "final replacement = 'Goodbye';") | |
225 ]) | |
226 ]); | |
227 }); | |
228 | |
229 d.dir(appPath, [ | |
230 d.pubspec({ | |
231 "name": "myapp", | |
232 "dependencies": {"foo": "1.2.3"}, | |
233 "transformers": ["foo"] | |
234 }), | |
235 d.dir("bin", [ | |
236 d.file("myapp.dart", "main() => print('Hello!');") | |
237 ]) | |
238 ]).create(); | |
239 | |
240 pubGet(); | |
241 | |
242 var process = pubRun(args: ['myapp']); | |
243 process.stdout.expect("Goodbye!"); | |
244 process.shouldExit(); | |
245 | |
246 servePackages((builder) { | |
247 builder.serve("bar", "2.0.0", contents: [ | |
248 d.dir("lib", [ | |
249 d.file("bar.dart", "final replacement = 'See ya';") | |
250 ]) | |
251 ]); | |
252 }); | |
253 | |
254 d.dir(appPath, [ | |
255 d.pubspec({ | |
256 "name": "myapp", | |
257 "dependencies": {"foo": "any"}, | |
258 "transformers": ["foo"] | |
259 }) | |
260 ]).create(); | |
261 | |
262 pubUpgrade(); | |
263 | |
264 process = pubRun(args: ['myapp']); | |
265 process.stdout.expect("See ya!"); | |
266 process.shouldExit(); | |
267 }); | |
268 } | |
269 | |
270 String replaceTransformer(String input, String output) { | |
271 return """ | |
272 import 'dart:async'; | |
273 | |
274 import 'package:barback/barback.dart'; | |
275 | |
276 class ReplaceTransformer extends Transformer { | |
277 ReplaceTransformer.asPlugin(); | |
278 | |
279 String get allowedExtensions => '.dart'; | |
280 | |
281 Future apply(Transform transform) { | |
282 return transform.primaryInput.readAsString().then((contents) { | |
283 transform.addOutput(new Asset.fromString( | |
284 transform.primaryInput.id, | |
285 contents.replaceAll("$input", "$output"))); | |
286 }); | |
287 } | |
288 } | |
289 """; | |
290 } | |
OLD | NEW |