1
1
//! Tests for the `cargo clean` command.
2
2
3
- #![ allow( deprecated) ]
4
-
5
3
use cargo_test_support:: paths:: CargoPathExt ;
4
+ use cargo_test_support:: prelude:: * ;
6
5
use cargo_test_support:: registry:: Package ;
6
+ use cargo_test_support:: str;
7
7
use cargo_test_support:: {
8
8
basic_bin_manifest, basic_manifest, git, main_file, project, project_in, rustc_host,
9
9
} ;
@@ -38,7 +38,10 @@ fn different_dir() {
38
38
39
39
p. cargo ( "clean" )
40
40
. cwd ( "src" )
41
- . with_stderr ( "[REMOVED] [..]" )
41
+ . with_stderr_data ( str![ [ r#"
42
+ [REMOVED] [FILE_NUM] files, [FILE_SIZE]B total
43
+
44
+ "# ] ] )
42
45
. run ( ) ;
43
46
assert ! ( !p. build_dir( ) . is_dir( ) ) ;
44
47
}
@@ -88,7 +91,10 @@ fn clean_multiple_packages() {
88
91
89
92
p. cargo ( "clean -p d1 -p d2" )
90
93
. cwd ( "src" )
91
- . with_stderr ( "[REMOVED] [..]" )
94
+ . with_stderr_data ( str![ [ r#"
95
+ [REMOVED] [FILE_NUM] files, [FILE_SIZE]B total
96
+
97
+ "# ] ] )
92
98
. run ( ) ;
93
99
assert ! ( p. bin( "foo" ) . is_file( ) ) ;
94
100
assert ! ( !d1_path. is_file( ) ) ;
@@ -235,17 +241,19 @@ fn clean_release() {
235
241
236
242
p. cargo ( "clean -p foo" ) . run ( ) ;
237
243
p. cargo ( "build --release" )
238
- . with_stderr ( "[FINISHED] [..]" )
244
+ . with_stderr_data ( str![ [ r#"
245
+ [FINISHED] `release` profile [optimized] target(s) in [ELAPSED]s
246
+
247
+ "# ] ] )
239
248
. run ( ) ;
240
249
241
250
p. cargo ( "clean -p foo --release" ) . run ( ) ;
242
251
p. cargo ( "build --release" )
243
- . with_stderr (
244
- "\
245
- [COMPILING] foo v0.0.1 ([..])
246
- [FINISHED] `release` profile [optimized] target(s) in [..]
247
- " ,
248
- )
252
+ . with_stderr_data ( str![ [ r#"
253
+ [COMPILING] foo v0.0.1 ([ROOT]/foo)
254
+ [FINISHED] `release` profile [optimized] target(s) in [ELAPSED]s
255
+
256
+ "# ] ] )
249
257
. run ( ) ;
250
258
251
259
p. cargo ( "build" ) . run ( ) ;
@@ -283,7 +291,12 @@ fn clean_doc() {
283
291
284
292
assert ! ( doc_path. is_dir( ) ) ;
285
293
286
- p. cargo ( "clean --doc" ) . with_stderr ( "[REMOVED] [..]" ) . run ( ) ;
294
+ p. cargo ( "clean --doc" )
295
+ . with_stderr_data ( str![ [ r#"
296
+ [REMOVED] [FILE_NUM] files, [FILE_SIZE]B total
297
+
298
+ "# ] ] )
299
+ . run ( ) ;
287
300
288
301
assert ! ( !doc_path. is_dir( ) ) ;
289
302
assert ! ( p. build_dir( ) . is_dir( ) ) ;
@@ -326,15 +339,14 @@ fn build_script() {
326
339
p. cargo ( "build" ) . env ( "FIRST" , "1" ) . run ( ) ;
327
340
p. cargo ( "clean -p foo" ) . run ( ) ;
328
341
p. cargo ( "build -v" )
329
- . with_stderr (
330
- "\
331
- [COMPILING] foo v0.0.1 ([..])
342
+ . with_stderr_data ( str![ [ r#"
343
+ [COMPILING] foo v0.0.1 ([ROOT]/foo)
332
344
[RUNNING] `rustc [..] build.rs [..]`
333
- [RUNNING] `[..] build-script-build`
345
+ [RUNNING] `[ROOT]/foo/target/debug/build/foo-[HASH]/ build-script-build`
334
346
[RUNNING] `rustc [..] src/main.rs [..]`
335
- [FINISHED] `dev` profile [unoptimized + debuginfo] target(s) in [..]
336
- " ,
337
- )
347
+ [FINISHED] `dev` profile [unoptimized + debuginfo] target(s) in [ELAPSED]s
348
+
349
+ "# ] ] )
338
350
. run ( ) ;
339
351
}
340
352
@@ -367,7 +379,12 @@ fn clean_git() {
367
379
. build ( ) ;
368
380
369
381
p. cargo ( "build" ) . run ( ) ;
370
- p. cargo ( "clean -p dep" ) . with_stderr ( "[REMOVED] [..]" ) . run ( ) ;
382
+ p. cargo ( "clean -p dep" )
383
+ . with_stderr_data ( str![ [ r#"
384
+ [REMOVED] [FILE_NUM] files, [FILE_SIZE]B total
385
+
386
+ "# ] ] )
387
+ . run ( ) ;
371
388
p. cargo ( "build" ) . run ( ) ;
372
389
}
373
390
@@ -393,7 +410,12 @@ fn registry() {
393
410
Package :: new ( "bar" , "0.1.0" ) . publish ( ) ;
394
411
395
412
p. cargo ( "build" ) . run ( ) ;
396
- p. cargo ( "clean -p bar" ) . with_stderr ( "[REMOVED] [..]" ) . run ( ) ;
413
+ p. cargo ( "clean -p bar" )
414
+ . with_stderr_data ( str![ [ r#"
415
+ [REMOVED] [FILE_NUM] files, [FILE_SIZE]B total
416
+
417
+ "# ] ] )
418
+ . run ( ) ;
397
419
p. cargo ( "build" ) . run ( ) ;
398
420
}
399
421
@@ -420,21 +442,21 @@ fn clean_verbose() {
420
442
p. cargo ( "build" ) . run ( ) ;
421
443
let mut expected = String :: from (
422
444
"\
423
- [REMOVING] [..] target/debug/.fingerprint/bar[.. ]
424
- [REMOVING] [..] target/debug/deps/libbar[.. ].rlib
425
- [REMOVING] [..] target/debug/deps/bar-[.. ].d
426
- [REMOVING] [..] target/debug/deps/libbar[.. ].rmeta
445
+ [REMOVING] [ROOT]/foo/ target/debug/.fingerprint/bar-[HASH ]
446
+ [REMOVING] [ROOT]/foo/ target/debug/deps/libbar-[HASH ].rlib
447
+ [REMOVING] [ROOT]/foo/ target/debug/deps/bar-[HASH ].d
448
+ [REMOVING] [ROOT]/foo/ target/debug/deps/libbar-[HASH ].rmeta
427
449
" ,
428
450
) ;
429
451
if cfg ! ( target_os = "macos" ) {
430
452
// Rust 1.69 has changed so that split-debuginfo=unpacked includes unpacked for rlibs.
431
- for obj in p. glob ( "target/debug/deps/bar-*.o" ) {
432
- expected. push_str ( & format ! ( "[REMOVING] [..]{} \n " , obj . unwrap ( ) . display ( ) ) ) ;
453
+ for _ in p. glob ( "target/debug/deps/bar-*.o" ) {
454
+ expected. push_str ( "[REMOVING] [ROOT]/foo/target/debug/deps/bar-[HASH][ ..].o \n " ) ;
433
455
}
434
456
}
435
- expected. push_str ( "[REMOVED] [.. ] files, [..] total\n " ) ;
457
+ expected. push_str ( "[REMOVED] [FILE_NUM ] files, [FILE_SIZE]B total\n " ) ;
436
458
p. cargo ( "clean -p bar --verbose" )
437
- . with_stderr_unordered ( & expected)
459
+ . with_stderr_data ( & expected. unordered ( ) )
438
460
. run ( ) ;
439
461
p. cargo ( "build" ) . run ( ) ;
440
462
}
@@ -614,21 +636,20 @@ fn clean_spec_version() {
614
636
// Check suggestion for bad pkgid.
615
637
p. cargo ( "clean -p baz" )
616
638
. with_status ( 101 )
617
- . with_stderr (
618
- "\
619
- error: package ID specification `baz` did not match any packages
639
+ . with_stderr_data ( str![ [ r#"
640
+ [ERROR] package ID specification `baz` did not match any packages
620
641
621
- <tab> Did you mean `bar`?
622
- " ,
623
- )
642
+ Did you mean `bar`?
643
+
644
+ "# ] ] )
624
645
. run ( ) ;
625
646
626
647
p. cargo ( "clean -p bar:0.1.0" )
627
- . with_stderr (
628
- "warning: version qualifier in `-p bar:0.1.0` is ignored, \
629
- cleaning all versions of `bar` found \n \
630
- [REMOVED] [..] files, [..] total" ,
631
- )
648
+ . with_stderr_data ( str! [ [ r#"
649
+ [WARNING] version qualifier in `-p bar:0.1.0` is ignored, cleaning all versions of `bar` found
650
+ [REMOVED] [FILE_NUM] files, [FILE_SIZE]B total
651
+
652
+ "# ] ] )
632
653
. run ( ) ;
633
654
let mut walker = walkdir:: WalkDir :: new ( p. build_dir ( ) )
634
655
. into_iter ( )
@@ -670,21 +691,20 @@ fn clean_spec_partial_version() {
670
691
// Check suggestion for bad pkgid.
671
692
p. cargo ( "clean -p baz" )
672
693
. with_status ( 101 )
673
- . with_stderr (
674
- "\
675
- error: package ID specification `baz` did not match any packages
694
+ . with_stderr_data ( str![ [ r#"
695
+ [ERROR] package ID specification `baz` did not match any packages
676
696
677
- <tab> Did you mean `bar`?
678
- " ,
679
- )
697
+ Did you mean `bar`?
698
+
699
+ "# ] ] )
680
700
. run ( ) ;
681
701
682
702
p. cargo ( "clean -p bar:0.1" )
683
- . with_stderr (
684
- "warning: version qualifier in `-p bar:0.1` is ignored, \
685
- cleaning all versions of `bar` found \n \
686
- [REMOVED] [..] files, [..] total" ,
687
- )
703
+ . with_stderr_data ( str! [ [ r#"
704
+ [WARNING] version qualifier in `-p bar:0.1` is ignored, cleaning all versions of `bar` found
705
+ [REMOVED] [FILE_NUM] files, [FILE_SIZE]B total
706
+
707
+ "# ] ] )
688
708
. run ( ) ;
689
709
let mut walker = walkdir:: WalkDir :: new ( p. build_dir ( ) )
690
710
. into_iter ( )
@@ -726,21 +746,20 @@ fn clean_spec_partial_version_ambiguous() {
726
746
// Check suggestion for bad pkgid.
727
747
p. cargo ( "clean -p baz" )
728
748
. with_status ( 101 )
729
- . with_stderr (
730
- "\
731
- error: package ID specification `baz` did not match any packages
749
+ . with_stderr_data ( str![ [ r#"
750
+ [ERROR] package ID specification `baz` did not match any packages
732
751
733
- <tab> Did you mean `bar`?
734
- " ,
735
- )
752
+ Did you mean `bar`?
753
+
754
+ "# ] ] )
736
755
. run ( ) ;
737
756
738
757
p. cargo ( "clean -p bar:0" )
739
- . with_stderr (
740
- "warning: version qualifier in `-p bar:0` is ignored, \
741
- cleaning all versions of `bar` found \n \
742
- [REMOVED] [..] files, [..] total" ,
743
- )
758
+ . with_stderr_data ( str! [ [ r#"
759
+ [WARNING] version qualifier in `-p bar:0` is ignored, cleaning all versions of `bar` found
760
+ [REMOVED] [FILE_NUM] files, [FILE_SIZE]B total
761
+
762
+ "# ] ] )
744
763
. run ( ) ;
745
764
let mut walker = walkdir:: WalkDir :: new ( p. build_dir ( ) )
746
765
. into_iter ( )
@@ -794,19 +813,19 @@ fn clean_spec_reserved() {
794
813
795
814
// This should not rebuild bar.
796
815
p. cargo ( "build -v --all-targets" )
797
- . with_stderr (
798
- "\
816
+ . with_stderr_data ( str![ [ r#"
799
817
[FRESH] bar v1.0.0
800
- [COMPILING] foo v0.1.0 [..]
801
- [RUNNING] `rustc [..]
802
- [RUNNING] `rustc [..]
803
- [RUNNING] `rustc [..]
804
- [FINISHED] [..]
805
- " ,
806
- )
818
+ [COMPILING] foo v0.1.0 ([ROOT]/foo)
819
+ [RUNNING] `rustc [..]`
820
+ [RUNNING] `rustc [..]`
821
+ [RUNNING] `rustc [..]`
822
+ [FINISHED] `dev` profile [unoptimized + debuginfo] target(s) in [ELAPSED]s
823
+
824
+ "# ] ] )
807
825
. run ( ) ;
808
826
}
809
827
828
+ #[ allow( deprecated) ]
810
829
#[ cargo_test]
811
830
fn clean_dry_run ( ) {
812
831
// Basic `clean --dry-run` test.
@@ -829,19 +848,21 @@ fn clean_dry_run() {
829
848
830
849
// Start with no files.
831
850
p. cargo ( "clean --dry-run" )
832
- . with_stdout ( "" )
833
- . with_stderr (
834
- "[SUMMARY] 0 files\n \
835
- [WARNING] no files deleted due to --dry-run",
836
- )
851
+ . with_stdout_data ( "" )
852
+ . with_stderr_data ( str![ [ r#"
853
+ [SUMMARY] [FILE_NUM] files
854
+ [WARNING] no files deleted due to --dry-run
855
+
856
+ "# ] ] )
837
857
. run ( ) ;
838
858
p. cargo ( "check" ) . run ( ) ;
839
859
let before = p. build_dir ( ) . ls_r ( ) ;
840
860
p. cargo ( "clean --dry-run" )
841
- . with_stderr (
842
- "[SUMMARY] [..] files, [..] total\n \
843
- [WARNING] no files deleted due to --dry-run",
844
- )
861
+ . with_stderr_data ( str![ [ r#"
862
+ [SUMMARY] [FILE_NUM] files, [FILE_SIZE]B total
863
+ [WARNING] no files deleted due to --dry-run
864
+
865
+ "# ] ] )
845
866
. run ( ) ;
846
867
// Verify it didn't delete anything.
847
868
let after = p. build_dir ( ) . ls_r ( ) ;
@@ -851,10 +872,11 @@ fn clean_dry_run() {
851
872
// Verify the verbose output.
852
873
p. cargo ( "clean --dry-run -v" )
853
874
. with_stdout_unordered ( expected)
854
- . with_stderr (
855
- "[SUMMARY] [..] files, [..] total\n \
856
- [WARNING] no files deleted due to --dry-run",
857
- )
875
+ . with_stderr_data ( str![ [ r#"
876
+ [SUMMARY] [FILE_NUM] files, [FILE_SIZE]B total
877
+ [WARNING] no files deleted due to --dry-run
878
+
879
+ "# ] ] )
858
880
. run ( ) ;
859
881
}
860
882
@@ -864,7 +886,10 @@ fn doc_with_package_selection() {
864
886
let p = project ( ) . file ( "src/lib.rs" , "" ) . build ( ) ;
865
887
p. cargo ( "clean --doc -p foo" )
866
888
. with_status ( 101 )
867
- . with_stderr ( "error: --doc cannot be used with -p" )
889
+ . with_stderr_data ( str![ [ r#"
890
+ [ERROR] --doc cannot be used with -p
891
+
892
+ "# ] ] )
868
893
. run ( ) ;
869
894
}
870
895
@@ -879,17 +904,16 @@ fn quiet_does_not_show_summary() {
879
904
880
905
p. cargo ( "check" ) . run ( ) ;
881
906
p. cargo ( "clean --quiet --dry-run" )
882
- . with_stdout ( "" )
883
- . with_stderr ( "" )
907
+ . with_stdout_data ( "" )
908
+ . with_stderr_data ( "" )
884
909
. run ( ) ;
885
910
// Verify exact same command without -q would actually display something.
886
911
p. cargo ( "clean --dry-run" )
887
- . with_stdout ( "" )
888
- . with_stderr (
889
- "\
890
- [SUMMARY] [..] files, [..] total
912
+ . with_stdout_data ( "" )
913
+ . with_stderr_data ( str![ [ r#"
914
+ [SUMMARY] [FILE_NUM] files, [FILE_SIZE]B total
891
915
[WARNING] no files deleted due to --dry-run
892
- " ,
893
- )
916
+
917
+ "# ] ] )
894
918
. run ( ) ;
895
919
}
0 commit comments