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,25 @@ 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
453
for obj in p. glob ( "target/debug/deps/bar-*.o" ) {
432
- expected. push_str ( & format ! ( "[REMOVING] [..]{}\n " , obj. unwrap( ) . display( ) ) ) ;
454
+ let obj = obj. unwrap ( ) . display ( ) . to_string ( ) ;
455
+ expected. push_str ( & format ! (
456
+ "[REMOVING] {}\n " ,
457
+ obj. replace( p. root( ) . to_str( ) . unwrap( ) , "[ROOT]/foo" )
458
+ ) ) ;
433
459
}
434
460
}
435
- expected. push_str ( "[REMOVED] [.. ] files, [..] total\n " ) ;
461
+ expected. push_str ( "[REMOVED] [FILE_NUM ] files, [FILE_SIZE]B total\n " ) ;
436
462
p. cargo ( "clean -p bar --verbose" )
437
- . with_stderr_unordered ( & expected)
463
+ . with_stderr_data ( & expected. unordered ( ) )
438
464
. run ( ) ;
439
465
p. cargo ( "build" ) . run ( ) ;
440
466
}
@@ -614,21 +640,20 @@ fn clean_spec_version() {
614
640
// Check suggestion for bad pkgid.
615
641
p. cargo ( "clean -p baz" )
616
642
. with_status ( 101 )
617
- . with_stderr (
618
- "\
619
- error: package ID specification `baz` did not match any packages
643
+ . with_stderr_data ( str![ [ r#"
644
+ [ERROR] package ID specification `baz` did not match any packages
620
645
621
- <tab> Did you mean `bar`?
622
- " ,
623
- )
646
+ Did you mean `bar`?
647
+
648
+ "# ] ] )
624
649
. run ( ) ;
625
650
626
651
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
- )
652
+ . with_stderr_data ( str! [ [ r#"
653
+ [WARNING] version qualifier in `-p bar:0.1.0` is ignored, cleaning all versions of `bar` found
654
+ [REMOVED] [FILE_NUM] files, [FILE_SIZE]B total
655
+
656
+ "# ] ] )
632
657
. run ( ) ;
633
658
let mut walker = walkdir:: WalkDir :: new ( p. build_dir ( ) )
634
659
. into_iter ( )
@@ -670,21 +695,20 @@ fn clean_spec_partial_version() {
670
695
// Check suggestion for bad pkgid.
671
696
p. cargo ( "clean -p baz" )
672
697
. with_status ( 101 )
673
- . with_stderr (
674
- "\
675
- error: package ID specification `baz` did not match any packages
698
+ . with_stderr_data ( str![ [ r#"
699
+ [ERROR] package ID specification `baz` did not match any packages
676
700
677
- <tab> Did you mean `bar`?
678
- " ,
679
- )
701
+ Did you mean `bar`?
702
+
703
+ "# ] ] )
680
704
. run ( ) ;
681
705
682
706
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
- )
707
+ . with_stderr_data ( str! [ [ r#"
708
+ [WARNING] version qualifier in `-p bar:0.1` is ignored, cleaning all versions of `bar` found
709
+ [REMOVED] [FILE_NUM] files, [FILE_SIZE]B total
710
+
711
+ "# ] ] )
688
712
. run ( ) ;
689
713
let mut walker = walkdir:: WalkDir :: new ( p. build_dir ( ) )
690
714
. into_iter ( )
@@ -726,21 +750,20 @@ fn clean_spec_partial_version_ambiguous() {
726
750
// Check suggestion for bad pkgid.
727
751
p. cargo ( "clean -p baz" )
728
752
. with_status ( 101 )
729
- . with_stderr (
730
- "\
731
- error: package ID specification `baz` did not match any packages
753
+ . with_stderr_data ( str![ [ r#"
754
+ [ERROR] package ID specification `baz` did not match any packages
732
755
733
- <tab> Did you mean `bar`?
734
- " ,
735
- )
756
+ Did you mean `bar`?
757
+
758
+ "# ] ] )
736
759
. run ( ) ;
737
760
738
761
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
- )
762
+ . with_stderr_data ( str! [ [ r#"
763
+ [WARNING] version qualifier in `-p bar:0` is ignored, cleaning all versions of `bar` found
764
+ [REMOVED] [FILE_NUM] files, [FILE_SIZE]B total
765
+
766
+ "# ] ] )
744
767
. run ( ) ;
745
768
let mut walker = walkdir:: WalkDir :: new ( p. build_dir ( ) )
746
769
. into_iter ( )
@@ -794,16 +817,15 @@ fn clean_spec_reserved() {
794
817
795
818
// This should not rebuild bar.
796
819
p. cargo ( "build -v --all-targets" )
797
- . with_stderr (
798
- "\
820
+ . with_stderr_data ( str![ [ r#"
799
821
[FRESH] bar v1.0.0
800
- [COMPILING] foo v0.1.0 [..]
801
- [RUNNING] `rustc [..]
802
- [RUNNING] `rustc [..]
803
- [RUNNING] `rustc [..]
804
- [FINISHED] [..]
805
- " ,
806
- )
822
+ [COMPILING] foo v0.1.0 ([ROOT]/foo)
823
+ [RUNNING] `rustc [..]`
824
+ [RUNNING] `rustc [..]`
825
+ [RUNNING] `rustc [..]`
826
+ [FINISHED] `dev` profile [unoptimized + debuginfo] target(s) in [ELAPSED]s
827
+
828
+ "# ] ] )
807
829
. run ( ) ;
808
830
}
809
831
@@ -829,32 +851,39 @@ fn clean_dry_run() {
829
851
830
852
// Start with no files.
831
853
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
- )
854
+ . with_stdout_data ( "" )
855
+ . with_stderr_data ( str![ [ r#"
856
+ [SUMMARY] [FILE_NUM] files
857
+ [WARNING] no files deleted due to --dry-run
858
+
859
+ "# ] ] )
837
860
. run ( ) ;
838
861
p. cargo ( "check" ) . run ( ) ;
839
862
let before = p. build_dir ( ) . ls_r ( ) ;
840
863
p. cargo ( "clean --dry-run" )
841
- . with_stderr (
842
- "[SUMMARY] [..] files, [..] total\n \
843
- [WARNING] no files deleted due to --dry-run",
844
- )
864
+ . with_stderr_data ( str![ [ r#"
865
+ [SUMMARY] [FILE_NUM] files, [FILE_SIZE]B total
866
+ [WARNING] no files deleted due to --dry-run
867
+
868
+ "# ] ] )
845
869
. run ( ) ;
846
870
// Verify it didn't delete anything.
847
871
let after = p. build_dir ( ) . ls_r ( ) ;
848
872
assert_eq ! ( before, after) ;
849
- let expected = itertools:: join ( before. iter ( ) . map ( |p| p. to_str ( ) . unwrap ( ) ) , "\n " ) ;
873
+ let path_stringify = |p : & PathBuf | format ! ( "{}\n " , p. to_str( ) . unwrap( ) ) ;
874
+ let files = itertools:: join ( before. iter ( ) . map ( path_stringify) , "" ) ;
875
+ let re = regex:: Regex :: new ( "/(?<head>[a-z0-9\\ -_]+)-([0-9a-f]{16})(?<tail>.*)" ) . unwrap ( ) ;
876
+ let expected = re. replace_all ( & files, "/$head-[HASH]$tail" ) ;
877
+ let expected = expected. replace ( p. build_dir ( ) . to_str ( ) . unwrap ( ) , "[ROOT]/foo/target" ) ;
850
878
eprintln ! ( "{expected}" ) ;
851
879
// Verify the verbose output.
852
880
p. cargo ( "clean --dry-run -v" )
853
- . with_stdout_unordered ( expected)
854
- . with_stderr (
855
- "[SUMMARY] [..] files, [..] total\n \
856
- [WARNING] no files deleted due to --dry-run",
857
- )
881
+ . with_stdout_data ( expected. unordered ( ) )
882
+ . with_stderr_data ( str![ [ r#"
883
+ [SUMMARY] [FILE_NUM] files, [FILE_SIZE]B total
884
+ [WARNING] no files deleted due to --dry-run
885
+
886
+ "# ] ] )
858
887
. run ( ) ;
859
888
}
860
889
@@ -864,7 +893,10 @@ fn doc_with_package_selection() {
864
893
let p = project ( ) . file ( "src/lib.rs" , "" ) . build ( ) ;
865
894
p. cargo ( "clean --doc -p foo" )
866
895
. with_status ( 101 )
867
- . with_stderr ( "error: --doc cannot be used with -p" )
896
+ . with_stderr_data ( str![ [ r#"
897
+ [ERROR] --doc cannot be used with -p
898
+
899
+ "# ] ] )
868
900
. run ( ) ;
869
901
}
870
902
@@ -879,17 +911,16 @@ fn quiet_does_not_show_summary() {
879
911
880
912
p. cargo ( "check" ) . run ( ) ;
881
913
p. cargo ( "clean --quiet --dry-run" )
882
- . with_stdout ( "" )
883
- . with_stderr ( "" )
914
+ . with_stdout_data ( "" )
915
+ . with_stderr_data ( "" )
884
916
. run ( ) ;
885
917
// Verify exact same command without -q would actually display something.
886
918
p. cargo ( "clean --dry-run" )
887
- . with_stdout ( "" )
888
- . with_stderr (
889
- "\
890
- [SUMMARY] [..] files, [..] total
919
+ . with_stdout_data ( "" )
920
+ . with_stderr_data ( str![ [ r#"
921
+ [SUMMARY] [FILE_NUM] files, [FILE_SIZE]B total
891
922
[WARNING] no files deleted due to --dry-run
892
- " ,
893
- )
923
+
924
+ "# ] ] )
894
925
. run ( ) ;
895
926
}
0 commit comments