Skip to content

Commit 90ad298

Browse files
authored
Merge pull request #371 from epage/clear
feat(redact): Expose clear_unused
2 parents e60453c + 6a9a6b2 commit 90ad298

File tree

2 files changed

+7
-2
lines changed

2 files changed

+7
-2
lines changed

crates/snapbox/src/filter/pattern.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -585,7 +585,7 @@ fn line_matches(mut actual: &str, expected: &str, redactions: &Redactions) -> bo
585585
return true;
586586
}
587587

588-
let expected = redactions.clear(expected);
588+
let expected = redactions.clear_unused(expected);
589589
let mut sections = expected.split("[..]").peekable();
590590
while let Some(section) = sections.next() {
591591
if let Some(remainder) = actual.strip_prefix(section) {

crates/snapbox/src/filter/redactions.rs

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -133,7 +133,12 @@ impl Redactions {
133133
input
134134
}
135135

136-
pub(crate) fn clear<'v>(&self, pattern: &'v str) -> Cow<'v, str> {
136+
/// Clear unused redactions from expected data
137+
///
138+
/// Some redactions can be conditionally present, like redacting [`std::env::consts::EXE_SUFFIX`].
139+
/// When the redaction is not present, it needs to be removed from the expected data so it can
140+
/// be matched against the actual data.
141+
pub fn clear_unused<'v>(&self, pattern: &'v str) -> Cow<'v, str> {
137142
if !self.unused.as_ref().map(|s| s.is_empty()).unwrap_or(false) && pattern.contains('[') {
138143
let mut pattern = pattern.to_owned();
139144
replace_many(

0 commit comments

Comments
 (0)