Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(9)

Side by Side Diff: sdk/lib/_internal/pub/test/transformer/cache_test.dart

Issue 1165473002: Start pulling pub from its own repo. (Closed) Base URL: git@github.com:dart-lang/sdk.git@master
Patch Set: Code review changes Created 5 years, 6 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
(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_stream.dart';
8 import 'package:scheduled_test/scheduled_test.dart';
9
10 import '../descriptor.dart' as d;
11 import '../test_pub.dart';
12 import '../serve/utils.dart';
13
14 const REPLACE_FROM_LIBRARY_TRANSFORMER = """
15 import 'dart:async';
16
17 import 'package:barback/barback.dart';
18 import 'package:bar/bar.dart';
19
20 class ReplaceTransformer extends Transformer {
21 ReplaceTransformer.asPlugin();
22
23 String get allowedExtensions => '.dart';
24
25 Future apply(Transform transform) {
26 return transform.primaryInput.readAsString().then((contents) {
27 transform.addOutput(new Asset.fromString(
28 transform.primaryInput.id,
29 contents.replaceAll("Hello", replacement)));
30 });
31 }
32 }
33 """;
34
35 // TODO(nweiz): Currently scheduled_test.setUp doesn't play well with test_pub,
36 // since it only assigns the sandbox directory once the main test body has
37 // run. Fix this and move this to a real setUp call.
38 void setUp() {
39 servePackages((builder) {
40 builder.serveRepoPackage('barback');
41
42 builder.serve("foo", "1.2.3",
43 deps: {'barback': 'any'},
44 contents: [
45 d.dir("lib", [
46 d.file("transformer.dart", replaceTransformer("Hello", "Goodbye"))
47 ])
48 ]);
49
50 builder.serve("bar", "1.2.3",
51 deps: {'barback': 'any'},
52 contents: [
53 d.dir("lib", [
54 d.file("transformer.dart", replaceTransformer("Goodbye", "See ya"))
55 ])
56 ]);
57
58 builder.serve("baz", "1.2.3");
59 });
60
61 d.dir(appPath, [
62 d.pubspec({
63 "name": "myapp",
64 "dependencies": {
65 "foo": "1.2.3",
66 "bar": "1.2.3"
67 },
68 "transformers": ["foo"]
69 }),
70 d.dir("bin", [
71 d.file("myapp.dart", "main() => print('Hello!');")
72 ])
73 ]).create();
74
75 pubGet();
76 }
77
78 main() {
79 initConfig();
80
81 integration("caches a transformer snapshot", () {
82 setUp();
83
84 var process = pubRun(args: ['myapp']);
85 process.stdout.expect("Goodbye!");
86 process.shouldExit();
87
88 d.dir(appPath, [
89 d.dir(".pub/transformers", [
90 d.file("manifest.txt", "0.1.2+3\nfoo"),
91 d.matcherFile("transformers.snapshot", isNot(isEmpty))
92 ])
93 ]).validate();
94
95 // Run the executable again to make sure loading the transformer from the
96 // cache works.
97 process = pubRun(args: ['myapp']);
98 process.stdout.expect("Goodbye!");
99 process.shouldExit();
100 });
101
102 integration("recaches if the SDK version is out-of-date", () {
103 setUp();
104
105 d.dir(appPath, [
106 d.dir(".pub/transformers", [
107 // The version 0.0.1 is different than the test version 0.1.2+3.
108 d.file("manifest.txt", "0.0.1\nfoo"),
109 d.file("transformers.snapshot", "junk")
110 ])
111 ]).create();
112
113 var process = pubRun(args: ['myapp']);
114 process.stdout.expect("Goodbye!");
115 process.shouldExit();
116
117 d.dir(appPath, [
118 d.dir(".pub/transformers", [
119 d.file("manifest.txt", "0.1.2+3\nfoo"),
120 d.matcherFile("transformers.snapshot", isNot(isEmpty))
121 ])
122 ]).validate();
123 });
124
125 integration("recaches if the transformers change", () {
126 setUp();
127
128 var process = pubRun(args: ['myapp']);
129 process.stdout.expect("Goodbye!");
130 process.shouldExit();
131
132 d.dir(appPath, [
133 d.dir(".pub/transformers", [
134 d.file("manifest.txt", "0.1.2+3\nfoo"),
135 d.matcherFile("transformers.snapshot", isNot(isEmpty))
136 ])
137 ]).validate();
138
139 d.dir(appPath, [
140 d.pubspec({
141 "name": "myapp",
142 "dependencies": {
143 "foo": "1.2.3",
144 "bar": "1.2.3"
145 },
146 "transformers": ["foo", "bar"]
147 }),
148 d.dir("bin", [
149 d.file("myapp.dart", "main() => print('Hello!');")
150 ])
151 ]).create();
152
153 process = pubRun(args: ['myapp']);
154 process.stdout.expect("See ya!");
155 process.shouldExit();
156
157 d.dir(appPath, [
158 d.dir(".pub/transformers", [
159 d.file("manifest.txt", "0.1.2+3\nbar,foo"),
160 d.matcherFile("transformers.snapshot", isNot(isEmpty))
161 ])
162 ]).validate();
163 });
164
165 integration("recaches if the transformer version changes", () {
166 setUp();
167
168 var process = pubRun(args: ['myapp']);
169 process.stdout.expect("Goodbye!");
170 process.shouldExit();
171
172 d.dir(appPath, [
173 d.dir(".pub/transformers", [
174 d.file("manifest.txt", "0.1.2+3\nfoo"),
175 d.matcherFile("transformers.snapshot", isNot(isEmpty))
176 ])
177 ]).validate();
178
179 servePackages((builder) {
180 builder.serve("foo", "2.0.0",
181 deps: {'barback': 'any'},
182 contents: [
183 d.dir("lib", [
184 d.file("transformer.dart", replaceTransformer("Hello", "New"))
185 ])
186 ]);
187 });
188
189 d.dir(appPath, [
190 d.pubspec({
191 "name": "myapp",
192 "dependencies": {"foo": "any"},
193 "transformers": ["foo"]
194 })
195 ]).create();
196
197 pubUpgrade();
198
199 process = pubRun(args: ['myapp']);
200 process.stdout.expect("New!");
201 process.shouldExit();
202
203 d.dir(appPath, [
204 d.dir(".pub/transformers", [
205 d.file("manifest.txt", "0.1.2+3\nfoo"),
206 d.matcherFile("transformers.snapshot", isNot(isEmpty))
207 ])
208 ]).validate();
209 });
210
211 integration("recaches if a transitive dependency version changes", () {
212 servePackages((builder) {
213 builder.serveRepoPackage('barback');
214
215 builder.serve("foo", "1.2.3",
216 deps: {
217 'barback': 'any',
218 'bar': 'any'
219 },
220 contents: [
221 d.dir("lib", [
222 d.file("transformer.dart", REPLACE_FROM_LIBRARY_TRANSFORMER)
223 ])
224 ]);
225
226 builder.serve("bar", "1.2.3", contents: [
227 d.dir("lib", [
228 d.file("bar.dart", "final replacement = 'Goodbye';")
229 ])
230 ]);
231 });
232
233 d.dir(appPath, [
234 d.pubspec({
235 "name": "myapp",
236 "dependencies": {"foo": "1.2.3"},
237 "transformers": ["foo"]
238 }),
239 d.dir("bin", [
240 d.file("myapp.dart", "main() => print('Hello!');")
241 ])
242 ]).create();
243
244 pubGet();
245
246 var process = pubRun(args: ['myapp']);
247 process.stdout.expect("Goodbye!");
248 process.shouldExit();
249
250 servePackages((builder) {
251 builder.serve("bar", "2.0.0", contents: [
252 d.dir("lib", [
253 d.file("bar.dart", "final replacement = 'See ya';")
254 ])
255 ]);
256 });
257
258 d.dir(appPath, [
259 d.pubspec({
260 "name": "myapp",
261 "dependencies": {"foo": "any"},
262 "transformers": ["foo"]
263 })
264 ]).create();
265
266 pubUpgrade();
267
268 process = pubRun(args: ['myapp']);
269 process.stdout.expect("See ya!");
270 process.shouldExit();
271 });
272
273 // Issue 21298.
274 integration("doesn't recache when a transformer is removed", () {
275 setUp();
276
277 d.dir(appPath, [
278 d.pubspec({
279 "name": "myapp",
280 "dependencies": {
281 "foo": "1.2.3",
282 "bar": "1.2.3"
283 },
284 "transformers": ["foo", "bar"]
285 }),
286 d.dir("bin", [
287 d.file("myapp.dart", "main() => print('Hello!');")
288 ])
289 ]).create();
290
291 var process = pubRun(args: ['myapp']);
292 process.stdout.expect("See ya!");
293 process.shouldExit();
294
295 d.dir(appPath, [
296 d.pubspec({
297 "name": "myapp",
298 "dependencies": {
299 "foo": "1.2.3",
300 // Add a new dependency to trigger another "pub get". This works
301 // around issue 20498.
302 "baz": "1.2.3"
303 },
304 "transformers": ["foo"]
305 }),
306 d.dir("bin", [
307 d.file("myapp.dart", "main() => print('Hello!');")
308 ])
309 ]).create();
310
311 process = pubRun(args: ['myapp']);
312 process.stdout.expect(
313 "Your pubspec has changed, so we need to update your lockfile:");
314 process.stdout.expect(consumeThrough("Goodbye!"));
315 process.shouldExit();
316
317 // "bar" should still be in the manifest, since there's no reason to
318 // recompile the cache.
319 d.dir(appPath, [
320 d.dir(".pub/transformers", [
321 d.file("manifest.txt", "0.1.2+3\nbar,foo"),
322 d.matcherFile("transformers.snapshot", isNot(isEmpty))
323 ])
324 ]).validate();
325 });
326 }
327
328 String replaceTransformer(String input, String output) {
329 return """
330 import 'dart:async';
331
332 import 'package:barback/barback.dart';
333
334 class ReplaceTransformer extends Transformer {
335 ReplaceTransformer.asPlugin();
336
337 String get allowedExtensions => '.dart';
338
339 Future apply(Transform transform) {
340 return transform.primaryInput.readAsString().then((contents) {
341 transform.addOutput(new Asset.fromString(
342 transform.primaryInput.id,
343 contents.replaceAll("$input", "$output")));
344 });
345 }
346 }
347 """;
348 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698