diff --git a/crates/snapbox/src/filter/pattern.rs b/crates/snapbox/src/filter/pattern.rs index fc4de65b..a6200914 100644 --- a/crates/snapbox/src/filter/pattern.rs +++ b/crates/snapbox/src/filter/pattern.rs @@ -585,7 +585,7 @@ fn line_matches(mut actual: &str, expected: &str, redactions: &Redactions) -> bo return true; } - let expected = redactions.clear(expected); + let expected = redactions.clear_unused(expected); let mut sections = expected.split("[..]").peekable(); while let Some(section) = sections.next() { if let Some(remainder) = actual.strip_prefix(section) { diff --git a/crates/snapbox/src/filter/redactions.rs b/crates/snapbox/src/filter/redactions.rs index 6585c4db..6eed6d1b 100644 --- a/crates/snapbox/src/filter/redactions.rs +++ b/crates/snapbox/src/filter/redactions.rs @@ -133,7 +133,12 @@ impl Redactions { input } - pub(crate) fn clear<'v>(&self, pattern: &'v str) -> Cow<'v, str> { + /// Clear unused redactions from expected data + /// + /// Some redactions can be conditionally present, like redacting [`std::env::consts::EXE_SUFFIX`]. + /// When the redaction is not present, it needs to be removed from the expected data so it can + /// be matched against the actual data. + pub fn clear_unused<'v>(&self, pattern: &'v str) -> Cow<'v, str> { if !self.unused.as_ref().map(|s| s.is_empty()).unwrap_or(false) && pattern.contains('[') { let mut pattern = pattern.to_owned(); replace_many(