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,7 @@ fn different_dir() {
38
38
39
39
p. cargo ( "clean" )
40
40
. cwd ( "src" )
41
- . with_stderr ( "[REMOVED] [..] " )
41
+ . with_stderr_data ( "[REMOVED] 11 files, [FILE_SIZE]B total \n " )
42
42
. run ( ) ;
43
43
assert ! ( !p. build_dir( ) . is_dir( ) ) ;
44
44
}
@@ -88,7 +88,7 @@ fn clean_multiple_packages() {
88
88
89
89
p. cargo ( "clean -p d1 -p d2" )
90
90
. cwd ( "src" )
91
- . with_stderr ( "[REMOVED] [..] " )
91
+ . with_stderr_data ( "[REMOVED] 16 files, [FILE_SIZE]B total \n " )
92
92
. run ( ) ;
93
93
assert ! ( p. bin( "foo" ) . is_file( ) ) ;
94
94
assert ! ( !d1_path. is_file( ) ) ;
@@ -235,17 +235,16 @@ fn clean_release() {
235
235
236
236
p. cargo ( "clean -p foo" ) . run ( ) ;
237
237
p. cargo ( "build --release" )
238
- . with_stderr ( "[FINISHED] [..] " )
238
+ . with_stderr_data ( "[FINISHED] `release` profile [optimized] target(s) in [ELAPSED]s \n " )
239
239
. run ( ) ;
240
240
241
241
p. cargo ( "clean -p foo --release" ) . run ( ) ;
242
242
p. cargo ( "build --release" )
243
- . with_stderr (
244
- "\
245
- [COMPILING] foo v0.0.1 ([..])
246
- [FINISHED] `release` profile [optimized] target(s) in [..]
247
- " ,
248
- )
243
+ . with_stderr_data ( str![ [ r#"
244
+ [COMPILING] foo v0.0.1 ([ROOT]/foo)
245
+ [FINISHED] `release` profile [optimized] target(s) in [ELAPSED]s
246
+
247
+ "# ] ] )
249
248
. run ( ) ;
250
249
251
250
p. cargo ( "build" ) . run ( ) ;
@@ -283,7 +282,9 @@ fn clean_doc() {
283
282
284
283
assert ! ( doc_path. is_dir( ) ) ;
285
284
286
- p. cargo ( "clean --doc" ) . with_stderr ( "[REMOVED] [..]" ) . run ( ) ;
285
+ p. cargo ( "clean --doc" )
286
+ . with_stderr_data ( "[REMOVED] 47 files, [FILE_SIZE]B total\n " )
287
+ . run ( ) ;
287
288
288
289
assert ! ( !doc_path. is_dir( ) ) ;
289
290
assert ! ( p. build_dir( ) . is_dir( ) ) ;
@@ -326,15 +327,14 @@ fn build_script() {
326
327
p. cargo ( "build" ) . env ( "FIRST" , "1" ) . run ( ) ;
327
328
p. cargo ( "clean -p foo" ) . run ( ) ;
328
329
p. cargo ( "build -v" )
329
- . with_stderr (
330
- "\
331
- [COMPILING] foo v0.0.1 ([..])
330
+ . with_stderr_data ( str![ [ r#"
331
+ [COMPILING] foo v0.0.1 ([ROOT]/foo)
332
332
[RUNNING] `rustc [..] build.rs [..]`
333
- [RUNNING] `[..] build-script-build`
333
+ [RUNNING] `[ROOT]/foo/target/debug/build/foo-[HASH]/ build-script-build`
334
334
[RUNNING] `rustc [..] src/main.rs [..]`
335
- [FINISHED] `dev` profile [unoptimized + debuginfo] target(s) in [..]
336
- " ,
337
- )
335
+ [FINISHED] `dev` profile [unoptimized + debuginfo] target(s) in [ELAPSED]s
336
+
337
+ "# ] ] )
338
338
. run ( ) ;
339
339
}
340
340
@@ -367,7 +367,9 @@ fn clean_git() {
367
367
. build ( ) ;
368
368
369
369
p. cargo ( "build" ) . run ( ) ;
370
- p. cargo ( "clean -p dep" ) . with_stderr ( "[REMOVED] [..]" ) . run ( ) ;
370
+ p. cargo ( "clean -p dep" )
371
+ . with_stderr_data ( "[REMOVED] 7 files, [FILE_SIZE]B total\n " )
372
+ . run ( ) ;
371
373
p. cargo ( "build" ) . run ( ) ;
372
374
}
373
375
@@ -393,7 +395,9 @@ fn registry() {
393
395
Package :: new ( "bar" , "0.1.0" ) . publish ( ) ;
394
396
395
397
p. cargo ( "build" ) . run ( ) ;
396
- p. cargo ( "clean -p bar" ) . with_stderr ( "[REMOVED] [..]" ) . run ( ) ;
398
+ p. cargo ( "clean -p bar" )
399
+ . with_stderr_data ( "[REMOVED] 7 files, [FILE_SIZE]B total\n " )
400
+ . run ( ) ;
397
401
p. cargo ( "build" ) . run ( ) ;
398
402
}
399
403
@@ -420,21 +424,24 @@ fn clean_verbose() {
420
424
p. cargo ( "build" ) . run ( ) ;
421
425
let mut expected = String :: from (
422
426
"\
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
427
+ [REMOVING] [ROOT]/foo/ target/debug/.fingerprint/bar-[HASH ]
428
+ [REMOVING] [ROOT]/foo/ target/debug/deps/libbar-[HASH ].rlib
429
+ [REMOVING] [ROOT]/foo/ target/debug/deps/bar-[HASH ].d
430
+ [REMOVING] [ROOT]/foo/ target/debug/deps/libbar-[HASH ].rmeta
427
431
" ,
428
432
) ;
429
433
if cfg ! ( target_os = "macos" ) {
430
434
// Rust 1.69 has changed so that split-debuginfo=unpacked includes unpacked for rlibs.
431
435
for obj in p. glob ( "target/debug/deps/bar-*.o" ) {
432
- expected. push_str ( & format ! ( "[REMOVING] [..]{}\n " , obj. unwrap( ) . display( ) ) ) ;
436
+ expected. push_str ( & format ! (
437
+ "[REMOVING] [ROOT]/foo/{}\n " ,
438
+ obj. unwrap( ) . display( )
439
+ ) ) ;
433
440
}
434
441
}
435
- expected. push_str ( "[REMOVED] [..] files, [..] total\n " ) ;
442
+ expected. push_str ( "[REMOVED] 7 files, [FILE_SIZE]B total\n " ) ;
436
443
p. cargo ( "clean -p bar --verbose" )
437
- . with_stderr_unordered ( & expected)
444
+ . with_stderr_data ( & expected. unordered ( ) )
438
445
. run ( ) ;
439
446
p. cargo ( "build" ) . run ( ) ;
440
447
}
@@ -614,21 +621,20 @@ fn clean_spec_version() {
614
621
// Check suggestion for bad pkgid.
615
622
p. cargo ( "clean -p baz" )
616
623
. with_status ( 101 )
617
- . with_stderr (
618
- "\
619
- error: package ID specification `baz` did not match any packages
624
+ . with_stderr_data ( str![ [ r#"
625
+ [ERROR] package ID specification `baz` did not match any packages
620
626
621
- <tab> Did you mean `bar`?
622
- " ,
623
- )
627
+ Did you mean `bar`?
628
+
629
+ "# ] ] )
624
630
. run ( ) ;
625
631
626
632
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
- )
633
+ . with_stderr_data ( str! [ [ r#"
634
+ [WARNING] version qualifier in `-p bar:0.1.0` is ignored, cleaning all versions of `bar` found
635
+ [REMOVED] 14 files, [FILE_SIZE]B total
636
+
637
+ "# ] ] )
632
638
. run ( ) ;
633
639
let mut walker = walkdir:: WalkDir :: new ( p. build_dir ( ) )
634
640
. into_iter ( )
@@ -670,21 +676,20 @@ fn clean_spec_partial_version() {
670
676
// Check suggestion for bad pkgid.
671
677
p. cargo ( "clean -p baz" )
672
678
. with_status ( 101 )
673
- . with_stderr (
674
- "\
675
- error: package ID specification `baz` did not match any packages
679
+ . with_stderr_data ( str![ [ r#"
680
+ [ERROR] package ID specification `baz` did not match any packages
676
681
677
- <tab> Did you mean `bar`?
678
- " ,
679
- )
682
+ Did you mean `bar`?
683
+
684
+ "# ] ] )
680
685
. run ( ) ;
681
686
682
687
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
- )
688
+ . with_stderr_data ( str! [ [ r#"
689
+ [WARNING] version qualifier in `-p bar:0.1` is ignored, cleaning all versions of `bar` found
690
+ [REMOVED] 14 files, [FILE_SIZE]B total
691
+
692
+ "# ] ] )
688
693
. run ( ) ;
689
694
let mut walker = walkdir:: WalkDir :: new ( p. build_dir ( ) )
690
695
. into_iter ( )
@@ -726,21 +731,20 @@ fn clean_spec_partial_version_ambiguous() {
726
731
// Check suggestion for bad pkgid.
727
732
p. cargo ( "clean -p baz" )
728
733
. with_status ( 101 )
729
- . with_stderr (
730
- "\
731
- error: package ID specification `baz` did not match any packages
734
+ . with_stderr_data ( str![ [ r#"
735
+ [ERROR] package ID specification `baz` did not match any packages
732
736
733
- <tab> Did you mean `bar`?
734
- " ,
735
- )
737
+ Did you mean `bar`?
738
+
739
+ "# ] ] )
736
740
. run ( ) ;
737
741
738
742
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
- )
743
+ . with_stderr_data ( str! [ [ r#"
744
+ [WARNING] version qualifier in `-p bar:0` is ignored, cleaning all versions of `bar` found
745
+ [REMOVED] 14 files, [FILE_SIZE]B total
746
+
747
+ "# ] ] )
744
748
. run ( ) ;
745
749
let mut walker = walkdir:: WalkDir :: new ( p. build_dir ( ) )
746
750
. into_iter ( )
@@ -794,16 +798,15 @@ fn clean_spec_reserved() {
794
798
795
799
// This should not rebuild bar.
796
800
p. cargo ( "build -v --all-targets" )
797
- . with_stderr (
798
- "\
801
+ . with_stderr_data ( str![ [ r#"
799
802
[FRESH] bar v1.0.0
800
- [COMPILING] foo v0.1.0 [..]
801
- [RUNNING] `rustc [..]
802
- [RUNNING] `rustc [..]
803
- [RUNNING] `rustc [..]
804
- [FINISHED] [..]
805
- " ,
806
- )
803
+ [COMPILING] foo v0.1.0 ([ROOT]/foo)
804
+ [RUNNING] `rustc [..]`
805
+ [RUNNING] `rustc [..]`
806
+ [RUNNING] `rustc [..]`
807
+ [FINISHED] `dev` profile [unoptimized + debuginfo] target(s) in [ELAPSED]s
808
+
809
+ "# ] ] )
807
810
. run ( ) ;
808
811
}
809
812
@@ -829,32 +832,39 @@ fn clean_dry_run() {
829
832
830
833
// Start with no files.
831
834
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
- )
835
+ . with_stdout_data ( "" )
836
+ . with_stderr_data ( str![ [ r#"
837
+ [SUMMARY] 0 files
838
+ [WARNING] no files deleted due to --dry-run
839
+
840
+ "# ] ] )
837
841
. run ( ) ;
838
842
p. cargo ( "check" ) . run ( ) ;
839
843
let before = p. build_dir ( ) . ls_r ( ) ;
840
844
p. cargo ( "clean --dry-run" )
841
- . with_stderr (
842
- "[SUMMARY] [..] files, [..] total\n \
843
- [WARNING] no files deleted due to --dry-run",
844
- )
845
+ . with_stderr_data ( str![ [ r#"
846
+ [SUMMARY] 15 files, [FILE_SIZE]B total
847
+ [WARNING] no files deleted due to --dry-run
848
+
849
+ "# ] ] )
845
850
. run ( ) ;
846
851
// Verify it didn't delete anything.
847
852
let after = p. build_dir ( ) . ls_r ( ) ;
848
853
assert_eq ! ( before, after) ;
849
- let expected = itertools:: join ( before. iter ( ) . map ( |p| p. to_str ( ) . unwrap ( ) ) , "\n " ) ;
854
+ let path_stringify = |p : & PathBuf | format ! ( "{}\n " , p. to_str( ) . unwrap( ) ) ;
855
+ let files = itertools:: join ( before. iter ( ) . map ( path_stringify) , "" ) ;
856
+ let re = regex:: Regex :: new ( "/(?<head>[a-z0-9\\ -_]+)-([0-9a-f]{16})(?<tail>.*)" ) . unwrap ( ) ;
857
+ let expected = re. replace_all ( & files, "/$head-[HASH]$tail" ) ;
858
+ let expected = expected. replace ( p. build_dir ( ) . to_str ( ) . unwrap ( ) , "[ROOT]/foo/target" ) ;
850
859
eprintln ! ( "{expected}" ) ;
851
860
// Verify the verbose output.
852
861
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
- )
862
+ . with_stdout_data ( expected. unordered ( ) )
863
+ . with_stderr_data ( str![ [ r#"
864
+ [SUMMARY] 15 files, [FILE_SIZE]B total
865
+ [WARNING] no files deleted due to --dry-run
866
+
867
+ "# ] ] )
858
868
. run ( ) ;
859
869
}
860
870
@@ -864,7 +874,7 @@ fn doc_with_package_selection() {
864
874
let p = project ( ) . file ( "src/lib.rs" , "" ) . build ( ) ;
865
875
p. cargo ( "clean --doc -p foo" )
866
876
. with_status ( 101 )
867
- . with_stderr ( "error: --doc cannot be used with -p")
877
+ . with_stderr_data ( "[ERROR] --doc cannot be used with -p\n ")
868
878
. run ( ) ;
869
879
}
870
880
@@ -879,17 +889,16 @@ fn quiet_does_not_show_summary() {
879
889
880
890
p. cargo ( "check" ) . run ( ) ;
881
891
p. cargo ( "clean --quiet --dry-run" )
882
- . with_stdout ( "" )
883
- . with_stderr ( "" )
892
+ . with_stdout_data ( "" )
893
+ . with_stderr_data ( "" )
884
894
. run ( ) ;
885
895
// Verify exact same command without -q would actually display something.
886
896
p. cargo ( "clean --dry-run" )
887
- . with_stdout ( "" )
888
- . with_stderr (
889
- "\
890
- [SUMMARY] [..] files, [..] total
897
+ . with_stdout_data ( "" )
898
+ . with_stderr_data ( str![ [ r#"
899
+ [SUMMARY] 9 files, [FILE_SIZE]B total
891
900
[WARNING] no files deleted due to --dry-run
892
- " ,
893
- )
901
+
902
+ "# ] ] )
894
903
. run ( ) ;
895
904
}
0 commit comments