Skip to content

Commit c81c32b

Browse files
committed
Auto merge of #14096 - dieterplex:migrate-clean-snapbox, r=weihanglo
test: migrate clean to snapbox Part of #14039, migrating `tests/testsuite/clean.rs` to snapbox.
2 parents c7cb45c + 1794ce4 commit c81c32b

File tree

1 file changed

+117
-93
lines changed

1 file changed

+117
-93
lines changed

tests/testsuite/clean.rs

+117-93
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,9 @@
11
//! Tests for the `cargo clean` command.
22
3-
#![allow(deprecated)]
4-
53
use cargo_test_support::paths::CargoPathExt;
4+
use cargo_test_support::prelude::*;
65
use cargo_test_support::registry::Package;
6+
use cargo_test_support::str;
77
use cargo_test_support::{
88
basic_bin_manifest, basic_manifest, git, main_file, project, project_in, rustc_host,
99
};
@@ -38,7 +38,10 @@ fn different_dir() {
3838

3939
p.cargo("clean")
4040
.cwd("src")
41-
.with_stderr("[REMOVED] [..]")
41+
.with_stderr_data(str![[r#"
42+
[REMOVED] [FILE_NUM] files, [FILE_SIZE]B total
43+
44+
"#]])
4245
.run();
4346
assert!(!p.build_dir().is_dir());
4447
}
@@ -88,7 +91,10 @@ fn clean_multiple_packages() {
8891

8992
p.cargo("clean -p d1 -p d2")
9093
.cwd("src")
91-
.with_stderr("[REMOVED] [..]")
94+
.with_stderr_data(str![[r#"
95+
[REMOVED] [FILE_NUM] files, [FILE_SIZE]B total
96+
97+
"#]])
9298
.run();
9399
assert!(p.bin("foo").is_file());
94100
assert!(!d1_path.is_file());
@@ -235,17 +241,19 @@ fn clean_release() {
235241

236242
p.cargo("clean -p foo").run();
237243
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+
"#]])
239248
.run();
240249

241250
p.cargo("clean -p foo --release").run();
242251
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+
"#]])
249257
.run();
250258

251259
p.cargo("build").run();
@@ -283,7 +291,12 @@ fn clean_doc() {
283291

284292
assert!(doc_path.is_dir());
285293

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();
287300

288301
assert!(!doc_path.is_dir());
289302
assert!(p.build_dir().is_dir());
@@ -326,15 +339,14 @@ fn build_script() {
326339
p.cargo("build").env("FIRST", "1").run();
327340
p.cargo("clean -p foo").run();
328341
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)
332344
[RUNNING] `rustc [..] build.rs [..]`
333-
[RUNNING] `[..]build-script-build`
345+
[RUNNING] `[ROOT]/foo/target/debug/build/foo-[HASH]/build-script-build`
334346
[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+
"#]])
338350
.run();
339351
}
340352

@@ -367,7 +379,12 @@ fn clean_git() {
367379
.build();
368380

369381
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();
371388
p.cargo("build").run();
372389
}
373390

@@ -393,7 +410,12 @@ fn registry() {
393410
Package::new("bar", "0.1.0").publish();
394411

395412
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();
397419
p.cargo("build").run();
398420
}
399421

@@ -420,21 +442,21 @@ fn clean_verbose() {
420442
p.cargo("build").run();
421443
let mut expected = String::from(
422444
"\
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
427449
",
428450
);
429451
if cfg!(target_os = "macos") {
430452
// 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");
433455
}
434456
}
435-
expected.push_str("[REMOVED] [..] files, [..] total\n");
457+
expected.push_str("[REMOVED] [FILE_NUM] files, [FILE_SIZE]B total\n");
436458
p.cargo("clean -p bar --verbose")
437-
.with_stderr_unordered(&expected)
459+
.with_stderr_data(&expected.unordered())
438460
.run();
439461
p.cargo("build").run();
440462
}
@@ -614,21 +636,20 @@ fn clean_spec_version() {
614636
// Check suggestion for bad pkgid.
615637
p.cargo("clean -p baz")
616638
.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
620641
621-
<tab>Did you mean `bar`?
622-
",
623-
)
642+
Did you mean `bar`?
643+
644+
"#]])
624645
.run();
625646

626647
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+
"#]])
632653
.run();
633654
let mut walker = walkdir::WalkDir::new(p.build_dir())
634655
.into_iter()
@@ -670,21 +691,20 @@ fn clean_spec_partial_version() {
670691
// Check suggestion for bad pkgid.
671692
p.cargo("clean -p baz")
672693
.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
676696
677-
<tab>Did you mean `bar`?
678-
",
679-
)
697+
Did you mean `bar`?
698+
699+
"#]])
680700
.run();
681701

682702
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+
"#]])
688708
.run();
689709
let mut walker = walkdir::WalkDir::new(p.build_dir())
690710
.into_iter()
@@ -726,21 +746,20 @@ fn clean_spec_partial_version_ambiguous() {
726746
// Check suggestion for bad pkgid.
727747
p.cargo("clean -p baz")
728748
.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
732751
733-
<tab>Did you mean `bar`?
734-
",
735-
)
752+
Did you mean `bar`?
753+
754+
"#]])
736755
.run();
737756

738757
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+
"#]])
744763
.run();
745764
let mut walker = walkdir::WalkDir::new(p.build_dir())
746765
.into_iter()
@@ -794,19 +813,19 @@ fn clean_spec_reserved() {
794813

795814
// This should not rebuild bar.
796815
p.cargo("build -v --all-targets")
797-
.with_stderr(
798-
"\
816+
.with_stderr_data(str![[r#"
799817
[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+
"#]])
807825
.run();
808826
}
809827

828+
#[allow(deprecated)]
810829
#[cargo_test]
811830
fn clean_dry_run() {
812831
// Basic `clean --dry-run` test.
@@ -829,19 +848,21 @@ fn clean_dry_run() {
829848

830849
// Start with no files.
831850
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+
"#]])
837857
.run();
838858
p.cargo("check").run();
839859
let before = p.build_dir().ls_r();
840860
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+
"#]])
845866
.run();
846867
// Verify it didn't delete anything.
847868
let after = p.build_dir().ls_r();
@@ -851,10 +872,11 @@ fn clean_dry_run() {
851872
// Verify the verbose output.
852873
p.cargo("clean --dry-run -v")
853874
.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+
"#]])
858880
.run();
859881
}
860882

@@ -864,7 +886,10 @@ fn doc_with_package_selection() {
864886
let p = project().file("src/lib.rs", "").build();
865887
p.cargo("clean --doc -p foo")
866888
.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+
"#]])
868893
.run();
869894
}
870895

@@ -879,17 +904,16 @@ fn quiet_does_not_show_summary() {
879904

880905
p.cargo("check").run();
881906
p.cargo("clean --quiet --dry-run")
882-
.with_stdout("")
883-
.with_stderr("")
907+
.with_stdout_data("")
908+
.with_stderr_data("")
884909
.run();
885910
// Verify exact same command without -q would actually display something.
886911
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
891915
[WARNING] no files deleted due to --dry-run
892-
",
893-
)
916+
917+
"#]])
894918
.run();
895919
}

0 commit comments

Comments
 (0)