5
5
import 'package:path/path.dart' as p;
6
6
import 'package:test/test.dart' ;
7
7
8
+ import 'package:pub/src/io.dart' ;
9
+
8
10
import '../descriptor.dart' as d;
9
11
import '../serve/utils.dart' ;
10
12
import '../test_pub.dart' ;
@@ -115,7 +117,7 @@ main() {
115
117
await pubGet (output: contains ("Precompiled foo." ));
116
118
117
119
await d.dir (appPath, [
118
- d.dir (".pub/deps/debug/foo/lib" ,
120
+ d.dir (".dart_tool/ pub/deps/debug/foo/lib" ,
119
121
[d.file ("foo.dart" , "final message = 'Goodbye!';" )])
120
122
]).validate ();
121
123
});
@@ -146,7 +148,7 @@ main() {
146
148
await pubGet (output: contains ("Precompiled foo." ));
147
149
148
150
await d.dir (appPath, [
149
- d.dir (".pub/deps/debug/foo/lib" ,
151
+ d.dir (".dart_tool/ pub/deps/debug/foo/lib" ,
150
152
[d.file ("foo.dart" , "final message = 'Goodbye!';" )])
151
153
]).validate ();
152
154
});
@@ -164,7 +166,7 @@ main() {
164
166
165
167
await pubGet (output: isNot (contains ("Precompiled foo." )));
166
168
167
- await d.dir (appPath, [d.nothing (".pub/deps" )]).validate ();
169
+ await d.dir (appPath, [d.nothing (".dart_tool/ pub/deps" )]).validate ();
168
170
});
169
171
170
172
test ("recaches when the dependency is updated" , () async {
@@ -199,7 +201,7 @@ main() {
199
201
await pubGet (output: contains ("Precompiled foo." ));
200
202
201
203
await d.dir (appPath, [
202
- d.dir (".pub/deps/debug/foo/lib" ,
204
+ d.dir (".dart_tool/ pub/deps/debug/foo/lib" ,
203
205
[d.file ("foo.dart" , "final message = 'Goodbye!';" )])
204
206
]).validate ();
205
207
@@ -209,7 +211,7 @@ main() {
209
211
await pubGet (output: contains ("Precompiled foo." ));
210
212
211
213
await d.dir (appPath, [
212
- d.dir (".pub/deps/debug/foo/lib" ,
214
+ d.dir (".dart_tool/ pub/deps/debug/foo/lib" ,
213
215
[d.file ("foo.dart" , "final message = 'See ya!';" )])
214
216
]).validate ();
215
217
});
@@ -286,7 +288,7 @@ main() {
286
288
await pubGet (output: contains ("Precompiled foo." ));
287
289
288
290
await d.dir (appPath, [
289
- d.dir (".pub/deps/debug/foo/lib" ,
291
+ d.dir (".dart_tool/ pub/deps/debug/foo/lib" ,
290
292
[d.file ("foo.dart" , "final mode = 'debug';" )])
291
293
]).validate ();
292
294
});
@@ -320,7 +322,7 @@ main() {
320
322
await pubGet (output: contains ("Precompiled foo." ));
321
323
322
324
await d.dir (appPath, [
323
- d.dir (".pub/deps/debug/foo/lib" ,
325
+ d.dir (".dart_tool/ pub/deps/debug/foo/lib" ,
324
326
[d.file ("foo.dart" , "final message = 'Modified!';" )])
325
327
]).create ();
326
328
@@ -357,6 +359,51 @@ main() {
357
359
358
360
await pubGet (output: contains ("Precompiled foo." ));
359
361
362
+ // Manually reset the cache to its original state to prove that the
363
+ // transformer won't be run again on it.
364
+ await d.dir (appPath, [
365
+ d.dir (".dart_tool/pub/deps/debug/foo/lib" ,
366
+ [d.file ("foo.dart" , "final message = 'Hello!';" )])
367
+ ]).create ();
368
+
369
+ var pub = await pubRun (args: ["bin/script" ]);
370
+ expect (pub.stdout, emits ("Hello!" ));
371
+ await pub.shouldExit ();
372
+ });
373
+
374
+ test ("reads cached packages from the old-style cache" , () async {
375
+ await servePackages ((builder) {
376
+ builder.serveRealPackage ('barback' );
377
+
378
+ builder.serve ("foo" , "1.2.3" , deps: {
379
+ 'barback' : 'any'
380
+ }, pubspec: {
381
+ 'transformers' : ['foo' ]
382
+ }, contents: [
383
+ d.dir ("lib" , [
384
+ d.file ("transformer.dart" , replaceTransformer ("Hello" , "Goodbye" )),
385
+ d.file ("foo.dart" , "final message = 'Hello!';" )
386
+ ])
387
+ ]);
388
+ });
389
+
390
+ await d.dir (appPath, [
391
+ d.appPubspec ({"foo" : "1.2.3" }),
392
+ d.dir ('bin' , [
393
+ d.file ('script.dart' , """
394
+ import 'package:foo/foo.dart';
395
+
396
+ void main() => print(message);""" )
397
+ ])
398
+ ]).create ();
399
+
400
+ await pubGet (output: contains ("Precompiled foo." ));
401
+
402
+ // Move the directory to the old location to simulate it being created by an
403
+ // older version of pub.
404
+ renameDir (p.join (d.sandbox, appPath, '.dart_tool' , 'pub' ),
405
+ p.join (d.sandbox, appPath, '.pub' ));
406
+
360
407
// Manually reset the cache to its original state to prove that the
361
408
// transformer won't be run again on it.
362
409
await d.dir (appPath, [
@@ -369,6 +416,42 @@ main() {
369
416
await pub.shouldExit ();
370
417
});
371
418
419
+ test ("migrates the old-style cache" , () async {
420
+ await servePackages ((builder) {
421
+ builder.serveRealPackage ('barback' );
422
+
423
+ builder.serve ("foo" , "1.2.3" , deps: {
424
+ 'barback' : 'any'
425
+ }, pubspec: {
426
+ 'transformers' : ['foo' ]
427
+ }, contents: [
428
+ d.dir ("lib" , [
429
+ d.file ("transformer.dart" , replaceTransformer ("Hello" , "Goodbye" )),
430
+ d.file ("foo.dart" , "final message = 'Hello!';" )
431
+ ])
432
+ ]);
433
+ });
434
+
435
+ await d.dir (appPath, [
436
+ d.appPubspec ({"foo" : "1.2.3" }),
437
+
438
+ // Simulate an old-style cache directory.
439
+ d.dir (".pub" , [d.file ("junk" , "junk" )])
440
+ ]).create ();
441
+
442
+ await pubGet (output: contains ("Precompiled foo." ));
443
+
444
+ await d.dir (appPath, [d.nothing (".pub" )]).validate ();
445
+
446
+ await d.dir (appPath, [
447
+ d.dir (".dart_tool/pub" , [
448
+ d.file ("junk" , "junk" ),
449
+ d.dir ("deps/debug/foo/lib" ,
450
+ [d.file ("foo.dart" , "final message = 'Goodbye!';" )])
451
+ ])
452
+ ]).validate ();
453
+ });
454
+
372
455
// Regression test for issue 21087.
373
456
test ("hasInput works for static packages" , () async {
374
457
await servePackages ((builder) {
@@ -436,7 +519,7 @@ main() {
436
519
await pubGet (output: contains ("Precompiled foo." ));
437
520
438
521
await d.dir (appPath, [
439
- d.dir (".pub/deps/debug/foo/lib" ,
522
+ d.dir (".dart_tool/ pub/deps/debug/foo/lib" ,
440
523
[d.file ("foo.dart" , "final message = 'Goodbye!';" )])
441
524
]).validate ();
442
525
@@ -445,7 +528,8 @@ main() {
445
528
446
529
await pubGet (output: isNot (contains ("Precompiled foo." )));
447
530
448
- await d.dir (appPath, [d.nothing (".pub/deps/debug/foo" )]).validate ();
531
+ await d
532
+ .dir (appPath, [d.nothing (".dart_tool/pub/deps/debug/foo" )]).validate ();
449
533
});
450
534
451
535
// Regression test for https://github.com/dart-lang/pub/issues/1586.
@@ -472,7 +556,8 @@ main() {
472
556
await pubGet (output: contains ("Precompiled foo" ));
473
557
474
558
await d.dir (appPath, [
475
- d.file (".pub/deps/debug/foo/lib/inputs.txt" , contains ('hello.dart.copy' ))
559
+ d.file (".dart_tool/pub/deps/debug/foo/lib/inputs.txt" ,
560
+ contains ('hello.dart.copy' ))
476
561
]).validate ();
477
562
478
563
await pubServe ();
@@ -508,7 +593,7 @@ foo|lib/list_transformer.dart.copy""");
508
593
await pubGet (
509
594
args: ["--no-precompile" ], output: isNot (contains ("Precompiled" )));
510
595
511
- await d.nothing (p.join (appPath, ".pub" )).validate ();
596
+ await d.nothing (p.join (appPath, ".dart_tool/ pub" )).validate ();
512
597
});
513
598
514
599
test ("deletes the cache when the dependency is updated" , () async {
@@ -543,7 +628,7 @@ foo|lib/list_transformer.dart.copy""");
543
628
await pubGet (output: contains ("Precompiled foo." ));
544
629
545
630
await d.dir (appPath, [
546
- d.dir (".pub/deps/debug/foo/lib" ,
631
+ d.dir (".dart_tool/ pub/deps/debug/foo/lib" ,
547
632
[d.file ("foo.dart" , "final message = 'Goodbye!';" )])
548
633
]).validate ();
549
634
@@ -553,7 +638,9 @@ foo|lib/list_transformer.dart.copy""");
553
638
await pubGet (
554
639
args: ["--no-precompile" ], output: isNot (contains ("Precompiled" )));
555
640
556
- await d.nothing (p.join (appPath, ".pub/deps/debug/foo" )).validate ();
641
+ await d
642
+ .nothing (p.join (appPath, ".dart_tool/pub/deps/debug/foo" ))
643
+ .validate ();
557
644
});
558
645
559
646
test (
@@ -580,7 +667,7 @@ foo|lib/list_transformer.dart.copy""");
580
667
await pubGet (output: contains ("Precompiled foo." ));
581
668
582
669
await d.dir (appPath, [
583
- d.dir (".pub/deps/debug/foo/lib" ,
670
+ d.dir (".dart_tool/ pub/deps/debug/foo/lib" ,
584
671
[d.file ("foo.dart" , "final message = 'Goodbye!';" )])
585
672
]).validate ();
586
673
@@ -589,7 +676,7 @@ foo|lib/list_transformer.dart.copy""");
589
676
args: ["--no-precompile" ], output: isNot (contains ("Precompiled" )));
590
677
591
678
await d.dir (appPath, [
592
- d.dir (".pub/deps/debug/foo/lib" ,
679
+ d.dir (".dart_tool/ pub/deps/debug/foo/lib" ,
593
680
[d.file ("foo.dart" , "final message = 'Goodbye!';" )])
594
681
]).validate ();
595
682
});
0 commit comments