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

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

Issue 896623005: Use native async/await support in pub. (Closed) Base URL: https://dart.googlecode.com/svn/branches/bleeding_edge/dart
Patch Set: Code review changes Created 5 years, 10 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 | Annotate | Revision Log
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", deps: {
43 'barback': 'any'
44 },
45 contents: [
46 d.dir(
47 "lib",
48 [d.file("transformer.dart", replaceTransformer("Hello", "Goodbye "))])]);
49
50 builder.serve("bar", "1.2.3", deps: {
51 'barback': 'any'
52 },
53 contents: [
54 d.dir(
55 "lib",
56 [d.file("transformer.dart", replaceTransformer("Goodbye", "See y a"))])]);
57
58 builder.serve("baz", "1.2.3");
59 });
60
61 d.dir(appPath, [d.pubspec({
62 "name": "myapp",
63 "dependencies": {
64 "foo": "1.2.3",
65 "bar": "1.2.3"
66 },
67 "transformers": ["foo"]
68 }),
69 d.dir("bin", [d.file("myapp.dart", "main() => print('Hello!');")])]).cre ate();
70
71 pubGet();
72 }
73
74 main() {
75 initConfig();
76
77 integration("caches a transformer snapshot", () {
78 setUp();
79
80 var process = pubRun(args: ['myapp']);
81 process.stdout.expect("Goodbye!");
82 process.shouldExit();
83
84 d.dir(
85 appPath,
86 [
87 d.dir(
88 ".pub/transformers",
89 [
90 d.file("manifest.txt", "0.1.2+3\nfoo"),
91 d.matcherFile("transformers.snapshot", isNot(isEmpty))])]).v alidate();
92
93 // Run the executable again to make sure loading the transformer from the
94 // cache works.
95 process = pubRun(args: ['myapp']);
96 process.stdout.expect("Goodbye!");
97 process.shouldExit();
98 });
99
100 integration("recaches if the SDK version is out-of-date", () {
101 setUp();
102
103 d.dir(
104 appPath,
105 [
106 d.dir(
107 ".pub/transformers",
108 [// The version 0.0.1 is different than the test version 0.1.2+3 .
109 d.file("manifest.txt", "0.0.1\nfoo"),
110 d.file("transformers.snapshot", "junk")])]).create();
111
112 var process = pubRun(args: ['myapp']);
113 process.stdout.expect("Goodbye!");
114 process.shouldExit();
115
116 d.dir(
117 appPath,
118 [
119 d.dir(
120 ".pub/transformers",
121 [
122 d.file("manifest.txt", "0.1.2+3\nfoo"),
123 d.matcherFile("transformers.snapshot", isNot(isEmpty))])]).v alidate();
124 });
125
126 integration("recaches if the transformers change", () {
127 setUp();
128
129 var process = pubRun(args: ['myapp']);
130 process.stdout.expect("Goodbye!");
131 process.shouldExit();
132
133 d.dir(
134 appPath,
135 [
136 d.dir(
137 ".pub/transformers",
138 [
139 d.file("manifest.txt", "0.1.2+3\nfoo"),
140 d.matcherFile("transformers.snapshot", isNot(isEmpty))])]).v alidate();
141
142 d.dir(appPath, [d.pubspec({
143 "name": "myapp",
144 "dependencies": {
145 "foo": "1.2.3",
146 "bar": "1.2.3"
147 },
148 "transformers": ["foo", "bar"]
149 }),
150 d.dir("bin", [d.file("myapp.dart", "main() => print('Hello!');")])]).c reate();
151
152 process = pubRun(args: ['myapp']);
153 process.stdout.expect("See ya!");
154 process.shouldExit();
155
156 d.dir(
157 appPath,
158 [
159 d.dir(
160 ".pub/transformers",
161 [
162 d.file("manifest.txt", "0.1.2+3\nbar,foo"),
163 d.matcherFile("transformers.snapshot", isNot(isEmpty))])]).v alidate();
164 });
165
166 integration("recaches if the transformer version changes", () {
167 setUp();
168
169 var process = pubRun(args: ['myapp']);
170 process.stdout.expect("Goodbye!");
171 process.shouldExit();
172
173 d.dir(
174 appPath,
175 [
176 d.dir(
177 ".pub/transformers",
178 [
179 d.file("manifest.txt", "0.1.2+3\nfoo"),
180 d.matcherFile("transformers.snapshot", isNot(isEmpty))])]).v alidate();
181
182 servePackages((builder) {
183 builder.serve("foo", "2.0.0", deps: {
184 'barback': 'any'
185 },
186 contents: [
187 d.dir(
188 "lib",
189 [d.file("transformer.dart", replaceTransformer("Hello", "New") )])]);
190 });
191
192 d.dir(appPath, [d.pubspec({
193 "name": "myapp",
194 "dependencies": {
195 "foo": "any"
196 },
197 "transformers": ["foo"]
198 })]).create();
199
200 pubUpgrade();
201
202 process = pubRun(args: ['myapp']);
203 process.stdout.expect("New!");
204 process.shouldExit();
205
206 d.dir(
207 appPath,
208 [
209 d.dir(
210 ".pub/transformers",
211 [
212 d.file("manifest.txt", "0.1.2+3\nfoo"),
213 d.matcherFile("transformers.snapshot", isNot(isEmpty))])]).v alidate();
214 });
215
216 integration("recaches if a transitive dependency version changes", () {
217 servePackages((builder) {
218 builder.serveRepoPackage('barback');
219
220 builder.serve("foo", "1.2.3", deps: {
221 'barback': 'any',
222 'bar': 'any'
223 },
224 contents: [
225 d.dir("lib", [d.file("transformer.dart", REPLACE_FROM_LIBRARY_TRAN SFORMER)])]);
226
227 builder.serve(
228 "bar",
229 "1.2.3",
230 contents: [
231 d.dir("lib", [d.file("bar.dart", "final replacement = 'Goodbye';") ])]);
232 });
233
234 d.dir(appPath, [d.pubspec({
235 "name": "myapp",
236 "dependencies": {
237 "foo": "1.2.3"
238 },
239 "transformers": ["foo"]
240 }),
241 d.dir("bin", [d.file("myapp.dart", "main() => print('Hello!');")])]).c reate();
242
243 pubGet();
244
245 var process = pubRun(args: ['myapp']);
246 process.stdout.expect("Goodbye!");
247 process.shouldExit();
248
249 servePackages((builder) {
250 builder.serve(
251 "bar",
252 "2.0.0",
253 contents: [
254 d.dir("lib", [d.file("bar.dart", "final replacement = 'See ya';")] )]);
255 });
256
257 d.dir(appPath, [d.pubspec({
258 "name": "myapp",
259 "dependencies": {
260 "foo": "any"
261 },
262 "transformers": ["foo"]
263 })]).create();
264
265 pubUpgrade();
266
267 process = pubRun(args: ['myapp']);
268 process.stdout.expect("See ya!");
269 process.shouldExit();
270 });
271
272 // Issue 21298.
273 integration("doesn't recache when a transformer is removed", () {
274 setUp();
275
276 d.dir(appPath, [d.pubspec({
277 "name": "myapp",
278 "dependencies": {
279 "foo": "1.2.3",
280 "bar": "1.2.3"
281 },
282 "transformers": ["foo", "bar"]
283 }),
284 d.dir("bin", [d.file("myapp.dart", "main() => print('Hello!');")])]).c reate();
285
286 var process = pubRun(args: ['myapp']);
287 process.stdout.expect("See ya!");
288 process.shouldExit();
289
290 d.dir(appPath, [d.pubspec({
291 "name": "myapp",
292 "dependencies": {
293 "foo": "1.2.3",
294 // Add a new dependency to trigger another "pub get". This works
295 // around issue 20498.
296 "baz": "1.2.3"
297 },
298 "transformers": ["foo"]
299 }),
300 d.dir("bin", [d.file("myapp.dart", "main() => print('Hello!');")])]).c reate();
301
302 process = pubRun(args: ['myapp']);
303 process.stdout.expect(
304 "Your pubspec has changed, so we need to update your lockfile:");
305 process.stdout.expect(consumeThrough("Goodbye!"));
306 process.shouldExit();
307
308 // "bar" should still be in the manifest, since there's no reason to
309 // recompile the cache.
310 d.dir(
311 appPath,
312 [
313 d.dir(
314 ".pub/transformers",
315 [
316 d.file("manifest.txt", "0.1.2+3\nbar,foo"),
317 d.matcherFile("transformers.snapshot", isNot(isEmpty))])]).v alidate();
318 });
319 }
320
321 String replaceTransformer(String input, String output) {
322 return """
323 import 'dart:async';
324
325 import 'package:barback/barback.dart';
326
327 class ReplaceTransformer extends Transformer {
328 ReplaceTransformer.asPlugin();
329
330 String get allowedExtensions => '.dart';
331
332 Future apply(Transform transform) {
333 return transform.primaryInput.readAsString().then((contents) {
334 transform.addOutput(new Asset.fromString(
335 transform.primaryInput.id,
336 contents.replaceAll("$input", "$output")));
337 });
338 }
339 }
340 """;
341 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698