Skip to content

Commit f7f7abc

Browse files
committed
test(gc): Update remaining unordered tests to snapbox
1 parent 91809c4 commit f7f7abc

File tree

1 file changed

+59
-52
lines changed

1 file changed

+59
-52
lines changed

tests/testsuite/global_cache_tracker.rs

Lines changed: 59 additions & 52 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@ use cargo::core::global_cache_tracker::{self, DeferredGlobalLastUse, GlobalCache
1818
use cargo::util::cache_lock::CacheLockMode;
1919
use cargo::util::interning::InternedString;
2020
use cargo::GlobalContext;
21+
use cargo_test_support::compare::assert_e2e;
2122
use cargo_test_support::paths;
2223
use cargo_test_support::prelude::*;
2324
use cargo_test_support::registry::{Package, RegistryBuilder};
@@ -749,7 +750,6 @@ fn both_git_and_http_index_cleans() {
749750
drop(lock);
750751
}
751752

752-
#[expect(deprecated)]
753753
#[cargo_test]
754754
fn clean_gc_dry_run() {
755755
// Basic `clean --gc --dry-run` test.
@@ -772,16 +772,19 @@ fn clean_gc_dry_run() {
772772
let index = glob_registry("index").ls_r();
773773
let src = glob_registry("src").ls_r();
774774
let cache = glob_registry("cache").ls_r();
775-
let expected_files = index
775+
let mut expected_files = index
776776
.iter()
777777
.chain(src.iter())
778778
.chain(cache.iter())
779779
.map(|p| p.to_str().unwrap())
780780
.join("\n");
781+
expected_files.push_str("\n");
782+
let expected_files = snapbox::filter::normalize_paths(&expected_files);
783+
let expected_files = assert_e2e().redactions().redact(&expected_files);
781784

782785
p.cargo("clean gc --dry-run -v -Zgc")
783786
.masquerade_as_nightly_cargo(&["gc"])
784-
.with_stdout_unordered(&expected_files)
787+
.with_stdout_data(expected_files.as_str().unordered())
785788
.with_stderr_data(str![[r#"
786789
[SUMMARY] [FILE_NUM] files, [FILE_SIZE]B total
787790
[WARNING] no files deleted due to --dry-run
@@ -792,7 +795,7 @@ fn clean_gc_dry_run() {
792795
// Again, make sure the information is still tracked.
793796
p.cargo("clean gc --dry-run -v -Zgc")
794797
.masquerade_as_nightly_cargo(&["gc"])
795-
.with_stdout_unordered(&expected_files)
798+
.with_stdout_data(expected_files.as_str().unordered())
796799
.with_stderr_data(str![[r#"
797800
[SUMMARY] [FILE_NUM] files, [FILE_SIZE]B total
798801
[WARNING] no files deleted due to --dry-run
@@ -895,7 +898,6 @@ fn tracks_sizes() {
895898
assert!(db_sizes[1] > 26000);
896899
}
897900

898-
#[expect(deprecated)]
899901
#[cargo_test]
900902
fn max_size() {
901903
// Checks --max-crate-size and --max-src-size with various cleaning thresholds.
@@ -924,20 +926,20 @@ fn max_size() {
924926
.collect();
925927

926928
// This exercises the different boundary conditions.
927-
for (clean_size, files, bytes) in [
928-
(22, 0, 0),
929-
(21, 1, 6),
930-
(16, 1, 6),
931-
(15, 2, 8),
932-
(14, 2, 8),
933-
(13, 3, 9),
934-
(12, 4, 12),
935-
(10, 4, 12),
936-
(9, 5, 16),
937-
(6, 5, 16),
938-
(5, 6, 21),
939-
(1, 6, 21),
940-
(0, 7, 22),
929+
for (clean_size, files) in [
930+
(22, 0),
931+
(21, 1),
932+
(16, 1),
933+
(15, 2),
934+
(14, 2),
935+
(13, 3),
936+
(12, 4),
937+
(10, 4),
938+
(9, 5),
939+
(6, 5),
940+
(5, 6),
941+
(1, 6),
942+
(0, 7),
941943
] {
942944
let (removed, kept) = names_by_timestamp.split_at(files);
943945
// --max-crate-size
@@ -947,19 +949,21 @@ fn max_size() {
947949
writeln!(stderr, "[REMOVING] [..]{name}.crate").unwrap();
948950
}
949951
let total_display = if removed.is_empty() {
950-
String::new()
952+
""
951953
} else {
952-
format!(", {bytes}B total")
954+
", [FILE_SIZE]B total"
953955
};
954-
let files_display = if files == 1 {
955-
format!("1 file")
956+
let files_display = if files == 0 {
957+
"0 files"
958+
} else if files == 1 {
959+
"1 file"
956960
} else {
957-
format!("{files} files")
961+
"[FILE_NUM] files"
958962
};
959-
write!(stderr, "[REMOVED] {files_display}{total_display}").unwrap();
963+
writeln!(stderr, "[REMOVED] {files_display}{total_display}").unwrap();
960964
cargo_process(&format!("clean gc -Zgc -v --max-crate-size={clean_size}"))
961965
.masquerade_as_nightly_cargo(&["gc"])
962-
.with_stderr_unordered(&stderr)
966+
.with_stderr_data(stderr.unordered())
963967
.run();
964968
for name in kept {
965969
assert!(cache_dir.join(format!("{name}.crate")).exists());
@@ -974,15 +978,15 @@ fn max_size() {
974978
for name in removed {
975979
writeln!(stderr, "[REMOVING] [..]{name}").unwrap();
976980
}
977-
let total_display = if files == 0 {
978-
String::new()
981+
let total_display = if removed.is_empty() {
982+
""
979983
} else {
980-
format!(", {bytes}B total")
984+
", [FILE_SIZE]B total"
981985
};
982-
write!(stderr, "[REMOVED] {files_display}{total_display}").unwrap();
986+
writeln!(stderr, "[REMOVED] {files_display}{total_display}").unwrap();
983987
cargo_process(&format!("clean gc -Zgc -v --max-src-size={clean_size}"))
984988
.masquerade_as_nightly_cargo(&["gc"])
985-
.with_stderr_unordered(&stderr)
989+
.with_stderr_data(stderr.unordered())
986990
.run();
987991
for name in kept {
988992
assert!(src_dir.join(name).exists());
@@ -1122,7 +1126,6 @@ fn max_size_untracked_src_from_clean() {
11221126
max_size_untracked_verify(&gctx);
11231127
}
11241128

1125-
#[expect(deprecated)]
11261129
#[cargo_test]
11271130
fn max_download_size() {
11281131
// --max-download-size
@@ -1140,13 +1143,13 @@ fn max_download_size() {
11401143
("b-1.0.0", 1, 1, 7),
11411144
];
11421145

1143-
for (max_size, num_deleted, files_deleted, bytes) in [
1144-
(30, 0, 0, 0),
1145-
(29, 1, 1, 5),
1146-
(24, 2, 2, 9),
1147-
(20, 3, 3, 12),
1148-
(1, 7, 7, 29),
1149-
(0, 8, 8, 30),
1146+
for (max_size, num_deleted, files_deleted) in [
1147+
(30, 0, 0),
1148+
(29, 1, 1),
1149+
(24, 2, 2),
1150+
(20, 3, 3),
1151+
(1, 7, 7),
1152+
(0, 8, 8),
11501153
] {
11511154
populate_cache(&gctx, &test_crates);
11521155
// Determine the order things will be deleted.
@@ -1159,20 +1162,22 @@ fn max_download_size() {
11591162
for name in removed {
11601163
writeln!(stderr, "[REMOVING] [..]{name}").unwrap();
11611164
}
1162-
let files_display = if files_deleted == 1 {
1163-
format!("1 file")
1165+
let files_display = if files_deleted == 0 {
1166+
"0 files"
1167+
} else if files_deleted == 1 {
1168+
"1 file"
11641169
} else {
1165-
format!("{files_deleted} files")
1170+
"[FILE_NUM] files"
11661171
};
11671172
let total_display = if removed.is_empty() {
1168-
String::new()
1173+
""
11691174
} else {
1170-
format!(", {bytes}B total")
1175+
", [FILE_SIZE]B total"
11711176
};
1172-
write!(stderr, "[REMOVED] {files_display}{total_display}",).unwrap();
1177+
writeln!(stderr, "[REMOVED] {files_display}{total_display}",).unwrap();
11731178
cargo_process(&format!("clean gc -Zgc -v --max-download-size={max_size}"))
11741179
.masquerade_as_nightly_cargo(&["gc"])
1175-
.with_stderr_unordered(&stderr)
1180+
.with_stderr_data(stderr.unordered())
11761181
.run();
11771182
}
11781183
}
@@ -1683,7 +1688,6 @@ fn clean_max_src_crate_age() {
16831688
.run();
16841689
}
16851690

1686-
#[expect(deprecated)]
16871691
#[cargo_test]
16881692
fn clean_max_git_size() {
16891693
// clean --max-git-size
@@ -1767,13 +1771,16 @@ fn clean_max_git_size() {
17671771
// And then try cleaning everything.
17681772
p.cargo("clean gc --max-git-size=0 -Zgc -v")
17691773
.masquerade_as_nightly_cargo(&["gc"])
1770-
.with_stderr_unordered(&format!(
1771-
"\
1772-
[REMOVING] [ROOT]/home/.cargo/git/checkouts/{db_name}/{second_co_name}
1773-
[REMOVING] [ROOT]/home/.cargo/git/db/{db_name}
1774+
.with_stderr_data(
1775+
format!(
1776+
"\
1777+
[REMOVING] [ROOT]/home/.cargo/git/checkouts/bar-[HASH]/{second_co_name}
1778+
[REMOVING] [ROOT]/home/.cargo/git/db/bar-[HASH]
17741779
[REMOVED] [..]
17751780
"
1776-
))
1781+
)
1782+
.unordered(),
1783+
)
17771784
.run();
17781785
}
17791786

0 commit comments

Comments
 (0)