Skip to content

Commit

Permalink
test: Migrate global_cache_tracker::clean_gc_dry_run to snapbox
Browse files Browse the repository at this point in the history
  • Loading branch information
dieterplex committed Jul 16, 2024
1 parent 1afdad1 commit 5faffc3
Showing 1 changed file with 17 additions and 3 deletions.
20 changes: 17 additions & 3 deletions tests/testsuite/global_cache_tracker.rs
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@ use cargo_test_support::{
thread_wait_timeout, Execs, Project,
};
use itertools::Itertools;
use regex::Regex;

use super::config::GlobalContextBuilder;

Expand Down Expand Up @@ -749,7 +750,6 @@ fn both_git_and_http_index_cleans() {
drop(lock);
}

#[allow(deprecated)]
#[cargo_test]
fn clean_gc_dry_run() {
// Basic `clean --gc --dry-run` test.
Expand Down Expand Up @@ -778,10 +778,24 @@ fn clean_gc_dry_run() {
.chain(cache.iter())
.map(|p| p.to_str().unwrap())
.join("\n");
let expected = {
let root = paths::root().display().to_string();
let re_crate = Regex::new(r"-[a-z0-9]{16}\b").unwrap();
let re_pack = Regex::new(r"pack-[a-z0-9]{40}").unwrap();
let p = if cfg!(windows) {
expected_files.replace("\\", "/")
} else {
expected_files
};
let p = p.replace(&root, "[ROOT]");
let p = re_crate.replace_all(&p, "-[HASH]");
let p = re_pack.replace_all(&p, "pack-[HASH]");
format!("{p}\n")
};

p.cargo("clean gc --dry-run -v -Zgc")
.masquerade_as_nightly_cargo(&["gc"])
.with_stdout_unordered(&expected_files)
.with_stdout_data(expected.clone().unordered())
.with_stderr_data(str![[r#"
[SUMMARY] [FILE_NUM] files, [FILE_SIZE]B total
[WARNING] no files deleted due to --dry-run
Expand All @@ -792,7 +806,7 @@ fn clean_gc_dry_run() {
// Again, make sure the information is still tracked.
p.cargo("clean gc --dry-run -v -Zgc")
.masquerade_as_nightly_cargo(&["gc"])
.with_stdout_unordered(&expected_files)
.with_stdout_data(expected.unordered())
.with_stderr_data(str![[r#"
[SUMMARY] [FILE_NUM] files, [FILE_SIZE]B total
[WARNING] no files deleted due to --dry-run
Expand Down

0 comments on commit 5faffc3

Please sign in to comment.