diff --git a/Cargo.lock b/Cargo.lock index f82241f1c..b6cf090f6 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -761,6 +761,7 @@ dependencies = [ "proptest", "rand", "rayon", + "regex", "same-file", "snap", "tar", @@ -793,7 +794,7 @@ dependencies = [ "proc-macro2", "quote", "regex", - "regex-syntax 0.7.4", + "regex-syntax 0.7.5", "structmeta", "syn", ] @@ -974,25 +975,25 @@ dependencies = [ [[package]] name = "regex" -version = "1.9.3" +version = "1.9.5" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "81bc1d4caf89fac26a70747fe603c130093b53c773888797a6329091246d651a" +checksum = "697061221ea1b4a94a624f67d0ae2bfe4e22b8a17b6a192afb11046542cc8c47" dependencies = [ "aho-corasick", "memchr", "regex-automata", - "regex-syntax 0.7.4", + "regex-syntax 0.7.5", ] [[package]] name = "regex-automata" -version = "0.3.6" +version = "0.3.8" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "fed1ceff11a1dddaee50c9dc8e4938bd106e9d89ae372f192311e7da498e3b69" +checksum = "c2f401f4955220693b56f8ec66ee9c78abffd8d1c4f23dc41a23839eb88f0795" dependencies = [ "aho-corasick", "memchr", - "regex-syntax 0.7.4", + "regex-syntax 0.7.5", ] [[package]] @@ -1003,9 +1004,9 @@ checksum = "f162c6dd7b008981e4d40210aca20b4bd0f9b60ca9271061b07f78537722f2e1" [[package]] name = "regex-syntax" -version = "0.7.4" +version = "0.7.5" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "e5ea92a5b6195c6ef2a0295ea818b312502c6fc94dde986c5553242e18fd4ce2" +checksum = "dbb5fb1acd8a1a18b3dd5be62d25485eb770e05afb408a9627d14d451bae12da" [[package]] name = "roff" diff --git a/Cargo.toml b/Cargo.toml index 3dca850b3..c824ede71 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -49,6 +49,7 @@ insta = "1.31.0" parse-display = "0.8.2" proptest = "1.2.0" rand = { version = "0.8.5", default-features = false, features = ["small_rng", "std"] } +regex = { version = "1.9.5", default-features = false, features = ["unicode-perl"] } test-strategy = "0.3.1" [features] diff --git a/tests/ui.rs b/tests/ui.rs index 68c642e98..7f2135e63 100644 --- a/tests/ui.rs +++ b/tests/ui.rs @@ -9,6 +9,7 @@ mod utils; use std::{io, path::Path, process::Output}; use insta::assert_display_snapshot as ui; +use regex::Regex; use crate::utils::run_in; @@ -37,9 +38,16 @@ fn run_ouch(argv: &str, dir: &Path) -> String { // remove random tempdir paths from snapshots to make them deterministic fn redact_paths(text: &str, path: &Path) -> String { - let path = format!("{}/", path.display()); - - text.replace(&path, "/") + let path = path.display(); + let redacted = ""; + + if cfg!(target_os = "macos") { + let pattern = &format!(r"(/private[\w\S]+?/)?{path}"); + let pattern = Regex::new(pattern).unwrap(); + pattern.replace_all(text, redacted).to_string() + } else { + text.replace(&path.to_string(), redacted) + } } fn output_to_string(output: Output) -> String {