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

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

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

Powered by Google App Engine
This is Rietveld 408576698