diff --git a/crates/snapbox/src/assert.rs b/crates/snapbox/src/assert.rs index 5d57088c..cfb83a23 100644 --- a/crates/snapbox/src/assert.rs +++ b/crates/snapbox/src/assert.rs @@ -25,7 +25,7 @@ pub struct Assert { pub(crate) action: Action, action_var: Option, normalize_paths: bool, - substitutions: crate::Substitutions, + substitutions: crate::Redactions, pub(crate) palette: crate::report::Palette, } @@ -432,8 +432,8 @@ impl Assert { self } - /// Override the default [`Substitutions`][crate::Substitutions] - pub fn substitutions(mut self, substitutions: crate::Substitutions) -> Self { + /// Override the default [`Redactions`][crate::Redactions] + pub fn substitutions(mut self, substitutions: crate::Redactions) -> Self { self.substitutions = substitutions; self } @@ -456,6 +456,6 @@ impl Default for Assert { substitutions: Default::default(), palette: crate::report::Palette::color(), } - .substitutions(crate::Substitutions::with_exe()) + .substitutions(crate::Redactions::with_exe()) } } diff --git a/crates/snapbox/src/data/normalize.rs b/crates/snapbox/src/data/normalize.rs index aa66972b..04db1b12 100644 --- a/crates/snapbox/src/data/normalize.rs +++ b/crates/snapbox/src/data/normalize.rs @@ -12,24 +12,24 @@ impl Normalize for NormalizeNewlines { DataInner::Error(err) => err.into(), DataInner::Binary(bin) => Data::binary(bin), DataInner::Text(text) => { - let lines = crate::normalization::normalize_lines(&text); + let lines = crate::filters::normalize_lines(&text); Data::text(lines) } #[cfg(feature = "json")] DataInner::Json(value) => { let mut value = value; - normalize_value(&mut value, crate::normalization::normalize_lines); + normalize_value(&mut value, crate::filters::normalize_lines); Data::json(value) } #[cfg(feature = "json")] DataInner::JsonLines(value) => { let mut value = value; - normalize_value(&mut value, crate::normalization::normalize_lines); + normalize_value(&mut value, crate::filters::normalize_lines); DataInner::JsonLines(value).into() } #[cfg(feature = "term-svg")] DataInner::TermSvg(text) => { - let lines = crate::normalization::normalize_lines(&text); + let lines = crate::filters::normalize_lines(&text); DataInner::TermSvg(lines).into() } }; @@ -45,24 +45,24 @@ impl Normalize for NormalizePaths { DataInner::Error(err) => err.into(), DataInner::Binary(bin) => Data::binary(bin), DataInner::Text(text) => { - let lines = crate::normalization::normalize_paths(&text); + let lines = crate::filters::normalize_paths(&text); Data::text(lines) } #[cfg(feature = "json")] DataInner::Json(value) => { let mut value = value; - normalize_value(&mut value, crate::normalization::normalize_paths); + normalize_value(&mut value, crate::filters::normalize_paths); Data::json(value) } #[cfg(feature = "json")] DataInner::JsonLines(value) => { let mut value = value; - normalize_value(&mut value, crate::normalization::normalize_paths); + normalize_value(&mut value, crate::filters::normalize_paths); DataInner::JsonLines(value).into() } #[cfg(feature = "term-svg")] DataInner::TermSvg(text) => { - let lines = crate::normalization::normalize_paths(&text); + let lines = crate::filters::normalize_paths(&text); DataInner::TermSvg(lines).into() } }; @@ -72,12 +72,12 @@ impl Normalize for NormalizePaths { } pub struct NormalizeMatches<'a> { - substitutions: &'a crate::Substitutions, + substitutions: &'a crate::Redactions, pattern: &'a Data, } impl<'a> NormalizeMatches<'a> { - pub fn new(substitutions: &'a crate::Substitutions, pattern: &'a Data) -> Self { + pub fn new(substitutions: &'a crate::Redactions, pattern: &'a Data) -> Self { NormalizeMatches { substitutions, pattern, @@ -153,7 +153,7 @@ fn normalize_value(value: &mut serde_json::Value, op: fn(&str) -> String) { fn normalize_value_matches( actual: &mut serde_json::Value, expected: &serde_json::Value, - substitutions: &crate::Substitutions, + substitutions: &crate::Redactions, ) { use serde_json::Value::*; diff --git a/crates/snapbox/src/normalization/mod.rs b/crates/snapbox/src/filters/mod.rs similarity index 60% rename from crates/snapbox/src/normalization/mod.rs rename to crates/snapbox/src/filters/mod.rs index 6f090fd8..b0020a4f 100644 --- a/crates/snapbox/src/normalization/mod.rs +++ b/crates/snapbox/src/filters/mod.rs @@ -1,9 +1,15 @@ -mod substitutions; +//! Normalize `actual` or `expected` data +//! +//! This can be done for +//! - Making snapshots consistent across platforms or conditional compilation +//! - Focusing snapshots on the characteristics of the data being tested +mod redactions; + +pub use redactions::RedactedValue; +pub use redactions::Redactions; #[cfg(feature = "regex")] pub use regex::Regex; -pub use substitutions::SubstitutedValue; -pub use substitutions::Substitutions; /// Normalize line endings pub fn normalize_lines(data: &str) -> String { @@ -15,6 +21,11 @@ fn normalize_lines_chars(data: impl Iterator) -> impl Iterator String { normalize_paths_chars(data.chars()).collect() } diff --git a/crates/snapbox/src/normalization/substitutions.rs b/crates/snapbox/src/filters/redactions.rs similarity index 73% rename from crates/snapbox/src/normalization/substitutions.rs rename to crates/snapbox/src/filters/redactions.rs index 2917d8c5..927c6c23 100644 --- a/crates/snapbox/src/normalization/substitutions.rs +++ b/crates/snapbox/src/filters/redactions.rs @@ -1,80 +1,79 @@ use std::borrow::Cow; -/// Match pattern expressions, see [`Assert`][crate::Assert] +/// Replace data with placeholders /// -/// Built-in expressions: +/// Built-in placeholders: /// - `...` on a line of its own: match multiple complete lines /// - `[..]`: match multiple characters within a line #[derive(Default, Clone, Debug)] -pub struct Substitutions { - vars: - std::collections::BTreeMap<&'static str, std::collections::BTreeSet>, - unused: std::collections::BTreeSet, +pub struct Redactions { + vars: std::collections::BTreeMap<&'static str, std::collections::BTreeSet>, + unused: std::collections::BTreeSet, } -impl Substitutions { +impl Redactions { pub fn new() -> Self { Default::default() } pub(crate) fn with_exe() -> Self { - let mut substitutions = Self::new(); - substitutions + let mut redactions = Self::new(); + redactions .insert("[EXE]", std::env::consts::EXE_SUFFIX) .unwrap(); - substitutions + redactions } /// Insert an additional match pattern /// - /// `key` must be enclosed in `[` and `]`. + /// `placeholder` must be enclosed in `[` and `]`. /// /// ```rust - /// let mut subst = snapbox::Substitutions::new(); + /// let mut subst = snapbox::Redactions::new(); /// subst.insert("[EXE]", std::env::consts::EXE_SUFFIX); /// ``` /// /// With the `regex` feature, you can define patterns using regexes. /// You can choose to replace a subset of the regex by giving it the named capture group - /// `replace`. + /// `redacted`. /// /// ```rust /// # #[cfg(feature = "regex")] { - /// let mut subst = snapbox::Substitutions::new(); - /// subst.insert("[OBJECT]", regex::Regex::new("(?(world|moon))").unwrap()); + /// let mut subst = snapbox::Redactions::new(); + /// subst.insert("[OBJECT]", regex::Regex::new("(?(world|moon))").unwrap()); /// # } /// ``` pub fn insert( &mut self, - key: &'static str, - value: impl Into, + placeholder: &'static str, + value: impl Into, ) -> Result<(), crate::Error> { - let key = validate_key(key)?; + let placeholder = validate_placeholder(placeholder)?; let value = value.into(); if let Some(inner) = value.inner { - self.vars.entry(key).or_default().insert(inner); + self.vars.entry(placeholder).or_default().insert(inner); } else { - self.unused.insert(SubstitutedValueInner::Str(key)); + self.unused.insert(RedactedValueInner::Str(placeholder)); } Ok(()) } /// Insert additional match patterns /// - /// keys must be enclosed in `[` and `]`. + /// Placeholders must be enclosed in `[` and `]`. pub fn extend( &mut self, - vars: impl IntoIterator)>, + vars: impl IntoIterator)>, ) -> Result<(), crate::Error> { - for (key, value) in vars { - self.insert(key, value)?; + for (placeholder, value) in vars { + self.insert(placeholder, value)?; } Ok(()) } - pub fn remove(&mut self, key: &'static str) -> Result<(), crate::Error> { - let key = validate_key(key)?; - self.vars.remove(key); + pub fn remove(&mut self, placeholder: &'static str) -> Result<(), crate::Error> { + let placeholder = validate_placeholder(placeholder)?; + self.vars.remove(placeholder); Ok(()) } @@ -85,7 +84,7 @@ impl Substitutions { /// Otherwise, `input`, with as many patterns replaced as possible, will be returned. /// /// ```rust - /// let subst = snapbox::Substitutions::new(); + /// let subst = snapbox::Redactions::new(); /// let output = subst.normalize("Hello World!", "Hello [..]!"); /// assert_eq!(output, "Hello [..]!"); /// ``` @@ -116,19 +115,19 @@ impl Substitutions { } #[derive(Clone)] -pub struct SubstitutedValue { - inner: Option, +pub struct RedactedValue { + inner: Option, } #[derive(Clone, Debug)] -enum SubstitutedValueInner { +enum RedactedValueInner { Str(&'static str), String(String), #[cfg(feature = "regex")] Regex(regex::Regex), } -impl SubstitutedValueInner { +impl RedactedValueInner { fn find_in(&self, buffer: &str) -> Option> { match self { Self::Str(s) => buffer.find(s).map(|offset| offset..(offset + s.len())), @@ -136,7 +135,7 @@ impl SubstitutedValueInner { #[cfg(feature = "regex")] Self::Regex(r) => { let captures = r.captures(buffer)?; - let m = captures.name("replace").or_else(|| captures.get(0))?; + let m = captures.name("redacted").or_else(|| captures.get(0))?; Some(m.range()) } } @@ -152,41 +151,41 @@ impl SubstitutedValueInner { } } -impl From<&'static str> for SubstitutedValue { +impl From<&'static str> for RedactedValue { fn from(inner: &'static str) -> Self { if inner.is_empty() { Self { inner: None } } else { Self { - inner: Some(SubstitutedValueInner::String( - crate::normalization::normalize_text(inner), - )), + inner: Some(RedactedValueInner::String(crate::filters::normalize_text( + inner, + ))), } } } } -impl From for SubstitutedValue { +impl From for RedactedValue { fn from(inner: String) -> Self { if inner.is_empty() { Self { inner: None } } else { Self { - inner: Some(SubstitutedValueInner::String( - crate::normalization::normalize_text(&inner), - )), + inner: Some(RedactedValueInner::String(crate::filters::normalize_text( + &inner, + ))), } } } } -impl From<&'_ String> for SubstitutedValue { +impl From<&'_ String> for RedactedValue { fn from(inner: &'_ String) -> Self { inner.clone().into() } } -impl From> for SubstitutedValue { +impl From> for RedactedValue { fn from(inner: Cow<'static, str>) -> Self { match inner { Cow::Borrowed(s) => s.into(), @@ -196,45 +195,45 @@ impl From> for SubstitutedValue { } #[cfg(feature = "regex")] -impl From for SubstitutedValue { +impl From for RedactedValue { fn from(inner: regex::Regex) -> Self { Self { - inner: Some(SubstitutedValueInner::Regex(inner)), + inner: Some(RedactedValueInner::Regex(inner)), } } } #[cfg(feature = "regex")] -impl From<&'_ regex::Regex> for SubstitutedValue { +impl From<&'_ regex::Regex> for RedactedValue { fn from(inner: &'_ regex::Regex) -> Self { inner.clone().into() } } -impl PartialOrd for SubstitutedValueInner { +impl PartialOrd for RedactedValueInner { fn partial_cmp(&self, other: &Self) -> Option { self.as_cmp().partial_cmp(other.as_cmp()) } } -impl Ord for SubstitutedValueInner { +impl Ord for RedactedValueInner { fn cmp(&self, other: &Self) -> std::cmp::Ordering { self.as_cmp().cmp(other.as_cmp()) } } -impl PartialEq for SubstitutedValueInner { +impl PartialEq for RedactedValueInner { fn eq(&self, other: &Self) -> bool { self.as_cmp().eq(other.as_cmp()) } } -impl Eq for SubstitutedValueInner {} +impl Eq for RedactedValueInner {} /// Replacements is `(from, to)` fn replace_many<'a>( buffer: &mut String, - replacements: impl IntoIterator, + replacements: impl IntoIterator, ) { for (var, replace) in replacements { let mut index = 0; @@ -246,27 +245,27 @@ fn replace_many<'a>( } } -fn validate_key(key: &'static str) -> Result<&'static str, crate::Error> { - if !key.starts_with('[') || !key.ends_with(']') { - return Err(format!("Key `{}` is not enclosed in []", key).into()); +fn validate_placeholder(placeholder: &'static str) -> Result<&'static str, crate::Error> { + if !placeholder.starts_with('[') || !placeholder.ends_with(']') { + return Err(format!("Key `{}` is not enclosed in []", placeholder).into()); } - if key[1..(key.len() - 1)] + if placeholder[1..(placeholder.len() - 1)] .find(|c: char| !c.is_ascii_uppercase()) .is_some() { - return Err(format!("Key `{}` can only be A-Z but ", key).into()); + return Err(format!("Key `{}` can only be A-Z but ", placeholder).into()); } - Ok(key) + Ok(placeholder) } -fn normalize(input: &str, pattern: &str, substitutions: &Substitutions) -> String { +fn normalize(input: &str, pattern: &str, redactions: &Redactions) -> String { if input == pattern { return input.to_owned(); } - let input = substitutions.substitute(input); + let input = redactions.substitute(input); let mut normalized: Vec<&str> = Vec::new(); let mut input_index = 0; @@ -278,7 +277,7 @@ fn normalize(input: &str, pattern: &str, substitutions: &Substitutions) -> Strin for (index_offset, next_input_line) in input_lines[input_index..].iter().copied().enumerate() { - if line_matches(next_input_line, next_pattern_line, substitutions) { + if line_matches(next_input_line, next_pattern_line, redactions) { normalized.push(pattern_line); input_index += index_offset; continue 'outer; @@ -299,7 +298,7 @@ fn normalize(input: &str, pattern: &str, substitutions: &Substitutions) -> Strin break; }; - if line_matches(input_line, pattern_line, substitutions) { + if line_matches(input_line, pattern_line, redactions) { input_index += 1; normalized.push(pattern_line); } else { @@ -317,12 +316,12 @@ fn is_line_elide(line: &str) -> bool { line == "...\n" || line == "..." } -fn line_matches(mut input: &str, pattern: &str, substitutions: &Substitutions) -> bool { +fn line_matches(mut input: &str, pattern: &str, redactions: &Redactions) -> bool { if input == pattern { return true; } - let pattern = substitutions.clear(pattern); + let pattern = redactions.clear(pattern); let mut sections = pattern.split("[..]").peekable(); while let Some(section) = sections.next() { if let Some(remainder) = input.strip_prefix(section) { @@ -352,7 +351,7 @@ mod test { let input = ""; let pattern = ""; let expected = ""; - let actual = normalize(input, pattern, &Substitutions::new()); + let actual = normalize(input, pattern, &Redactions::new()); assert_eq!(expected, actual); } @@ -361,7 +360,7 @@ mod test { let input = "Hello\nWorld"; let pattern = "Hello\nWorld"; let expected = "Hello\nWorld"; - let actual = normalize(input, pattern, &Substitutions::new()); + let actual = normalize(input, pattern, &Redactions::new()); assert_eq!(expected, actual); } @@ -370,7 +369,7 @@ mod test { let input = "Hello\nWorld"; let pattern = "Hello\n"; let expected = "Hello\nWorld"; - let actual = normalize(input, pattern, &Substitutions::new()); + let actual = normalize(input, pattern, &Redactions::new()); assert_eq!(expected, actual); } @@ -379,7 +378,7 @@ mod test { let input = "Hello\n"; let pattern = "Hello\nWorld"; let expected = "Hello\n"; - let actual = normalize(input, pattern, &Substitutions::new()); + let actual = normalize(input, pattern, &Redactions::new()); assert_eq!(expected, actual); } @@ -388,7 +387,7 @@ mod test { let input = "Hello\nWorld"; let pattern = "Goodbye\nMoon"; let expected = "Hello\nWorld"; - let actual = normalize(input, pattern, &Substitutions::new()); + let actual = normalize(input, pattern, &Redactions::new()); assert_eq!(expected, actual); } @@ -397,7 +396,7 @@ mod test { let input = "Hello\nWorld\nGoodbye"; let pattern = "Hello\nMoon\nGoodbye"; let expected = "Hello\nWorld\nGoodbye"; - let actual = normalize(input, pattern, &Substitutions::new()); + let actual = normalize(input, pattern, &Redactions::new()); assert_eq!(expected, actual); } @@ -406,7 +405,7 @@ mod test { let input = "Hello World\nHow are you?\nGoodbye World"; let pattern = "Hello [..]\n...\nGoodbye [..]"; let expected = "Hello [..]\n...\nGoodbye [..]"; - let actual = normalize(input, pattern, &Substitutions::new()); + let actual = normalize(input, pattern, &Redactions::new()); assert_eq!(expected, actual); } @@ -415,7 +414,7 @@ mod test { let input = "Hello\nWorld\nGoodbye"; let pattern = "...\nGoodbye"; let expected = "...\nGoodbye"; - let actual = normalize(input, pattern, &Substitutions::new()); + let actual = normalize(input, pattern, &Redactions::new()); assert_eq!(expected, actual); } @@ -424,7 +423,7 @@ mod test { let input = "Hello\nWorld\nGoodbye"; let pattern = "Hello\n..."; let expected = "Hello\n..."; - let actual = normalize(input, pattern, &Substitutions::new()); + let actual = normalize(input, pattern, &Redactions::new()); assert_eq!(expected, actual); } @@ -433,7 +432,7 @@ mod test { let input = "Hello\nWorld\nGoodbye"; let pattern = "Hello\n...\nGoodbye"; let expected = "Hello\n...\nGoodbye"; - let actual = normalize(input, pattern, &Substitutions::new()); + let actual = normalize(input, pattern, &Redactions::new()); assert_eq!(expected, actual); } @@ -442,7 +441,7 @@ mod test { let input = "Hello\nSun\nAnd\nWorld"; let pattern = "Hello\n...\nMoon"; let expected = "Hello\nSun\nAnd\nWorld"; - let actual = normalize(input, pattern, &Substitutions::new()); + let actual = normalize(input, pattern, &Redactions::new()); assert_eq!(expected, actual); } @@ -451,7 +450,7 @@ mod test { let input = "Hello\nWorld\nGoodbye\nSir"; let pattern = "Hello\nMoon\nGoodbye\n..."; let expected = "Hello\nWorld\nGoodbye\nSir"; - let actual = normalize(input, pattern, &Substitutions::new()); + let actual = normalize(input, pattern, &Redactions::new()); assert_eq!(expected, actual); } @@ -460,7 +459,7 @@ mod test { let input = "Hello\nWorld\nGoodbye\nSir"; let pattern = "Hello\nW[..]d\nGoodbye\nSir"; let expected = "Hello\nW[..]d\nGoodbye\nSir"; - let actual = normalize(input, pattern, &Substitutions::new()); + let actual = normalize(input, pattern, &Redactions::new()); assert_eq!(expected, actual); } @@ -504,13 +503,13 @@ mod test { ("hello world, goodbye moon", "hello [..], [..] world", false), ]; for (line, pattern, expected) in cases { - let actual = line_matches(line, pattern, &Substitutions::new()); + let actual = line_matches(line, pattern, &Redactions::new()); assert_eq!(expected, actual, "line={:?} pattern={:?}", line, pattern); } } #[test] - fn test_validate_key() { + fn test_validate_placeholder() { let cases = [ ("[HELLO", false), ("HELLO]", false), @@ -518,9 +517,9 @@ mod test { ("[hello]", false), ("[HE O]", false), ]; - for (key, expected) in cases { - let actual = validate_key(key).is_ok(); - assert_eq!(expected, actual, "key={:?}", key); + for (placeholder, expected) in cases { + let actual = validate_placeholder(placeholder).is_ok(); + assert_eq!(expected, actual, "placeholder={:?}", placeholder); } } @@ -528,7 +527,7 @@ mod test { fn substitute_literal() { let input = "Hello world!"; let pattern = "Hello [OBJECT]!"; - let mut sub = Substitutions::new(); + let mut sub = Redactions::new(); sub.insert("[OBJECT]", "world").unwrap(); let actual = normalize(input, pattern, &sub); assert_eq!(actual, pattern); @@ -538,7 +537,7 @@ mod test { fn substitute_disabled() { let input = "cargo"; let pattern = "cargo[EXE]"; - let mut sub = Substitutions::new(); + let mut sub = Redactions::new(); sub.insert("[EXE]", "").unwrap(); let actual = normalize(input, pattern, &sub); assert_eq!(actual, pattern); @@ -549,7 +548,7 @@ mod test { fn substitute_regex_unnamed() { let input = "Hello world!"; let pattern = "Hello [OBJECT]!"; - let mut sub = Substitutions::new(); + let mut sub = Redactions::new(); sub.insert("[OBJECT]", regex::Regex::new("world").unwrap()) .unwrap(); let actual = normalize(input, pattern, &sub); @@ -561,9 +560,12 @@ mod test { fn substitute_regex_named() { let input = "Hello world!"; let pattern = "Hello [OBJECT]!"; - let mut sub = Substitutions::new(); - sub.insert("[OBJECT]", regex::Regex::new("(?world)!").unwrap()) - .unwrap(); + let mut sub = Redactions::new(); + sub.insert( + "[OBJECT]", + regex::Regex::new("(?world)!").unwrap(), + ) + .unwrap(); let actual = normalize(input, pattern, &sub); assert_eq!(actual, pattern); } diff --git a/crates/snapbox/src/lib.rs b/crates/snapbox/src/lib.rs index 1a16c0de..cea2b307 100644 --- a/crates/snapbox/src/lib.rs +++ b/crates/snapbox/src/lib.rs @@ -100,7 +100,7 @@ mod macros; pub mod cmd; pub mod data; -pub mod normalization; +pub mod filters; pub mod path; pub mod report; pub mod utils; @@ -114,7 +114,7 @@ pub use assert::Assert; pub use data::Data; pub use data::ToDebug; pub use error::Error; -pub use normalization::Substitutions; +pub use filters::Redactions; pub use snapbox_macros::debug; pub type Result = std::result::Result; diff --git a/crates/snapbox/src/path.rs b/crates/snapbox/src/path.rs index 8d5d0919..d046c749 100644 --- a/crates/snapbox/src/path.rs +++ b/crates/snapbox/src/path.rs @@ -218,7 +218,7 @@ impl PathDiff { pub fn subset_matches_iter( pattern_root: impl Into, actual_root: impl Into, - substitutions: &crate::Substitutions, + substitutions: &crate::Redactions, ) -> impl Iterator> + '_ { let pattern_root = pattern_root.into(); let actual_root = actual_root.into(); @@ -229,7 +229,7 @@ impl PathDiff { pub(crate) fn subset_matches_iter_inner( expected_root: std::path::PathBuf, actual_root: std::path::PathBuf, - substitutions: &crate::Substitutions, + substitutions: &crate::Redactions, normalize_paths: bool, ) -> impl Iterator> + '_ { let walker = Walk::new(&expected_root); diff --git a/src/cases.rs b/src/cases.rs index 22518340..a3c60c5b 100644 --- a/src/cases.rs +++ b/src/cases.rs @@ -5,7 +5,7 @@ use std::borrow::Cow; pub struct TestCases { runner: std::cell::RefCell, bins: std::cell::RefCell, - substitutions: std::cell::RefCell, + substitutions: std::cell::RefCell, has_run: std::cell::Cell, } diff --git a/src/runner.rs b/src/runner.rs index d175cca4..9494e613 100644 --- a/src/runner.rs +++ b/src/runner.rs @@ -35,7 +35,7 @@ impl Runner { &self, mode: &Mode, bins: &crate::BinRegistry, - substitutions: &snapbox::Substitutions, + substitutions: &snapbox::Redactions, ) { let palette = snapbox::report::Palette::color(); @@ -139,7 +139,7 @@ impl Case { &self, mode: &Mode, bins: &crate::BinRegistry, - substitutions: &snapbox::Substitutions, + substitutions: &snapbox::Redactions, ) -> Vec> { if self.expected == Some(crate::schema::CommandStatus::Skipped) { let output = Output::sequence(self.path.clone()); @@ -308,7 +308,7 @@ impl Case { step: &mut crate::schema::Step, cwd: Option<&std::path::Path>, bins: &crate::BinRegistry, - substitutions: &snapbox::Substitutions, + substitutions: &snapbox::Redactions, ) -> Result { let output = if let Some(id) = step.id.clone() { Output::step(self.path.clone(), id) @@ -406,7 +406,7 @@ impl Case { &self, mut output: Output, step: &crate::schema::Step, - substitutions: &snapbox::Substitutions, + substitutions: &snapbox::Redactions, ) -> Output { output.stdout = self.validate_stream( output.stdout, @@ -429,7 +429,7 @@ impl Case { stream: Option, expected_content: Option<&crate::Data>, binary: bool, - substitutions: &snapbox::Substitutions, + substitutions: &snapbox::Redactions, ) -> Option { let mut stream = stream?; @@ -500,7 +500,7 @@ impl Case { actual_root: &std::path::Path, mut fs: Filesystem, mode: &Mode, - substitutions: &snapbox::Substitutions, + substitutions: &snapbox::Redactions, ) -> Result { let mut ok = true; diff --git a/src/schema.rs b/src/schema.rs index 26211df5..0790f7e2 100644 --- a/src/schema.rs +++ b/src/schema.rs @@ -68,7 +68,7 @@ impl TryCmd { } else if ext == std::ffi::OsStr::new("trycmd") || ext == std::ffi::OsStr::new("md") { let raw = std::fs::read_to_string(path) .map_err(|e| format!("Failed to read {}: {}", path.display(), e))?; - let normalized = snapbox::normalization::normalize_lines(&raw); + let normalized = snapbox::filters::normalize_lines(&raw); Self::parse_trycmd(&normalized)? } else { return Err(format!("Unsupported extension: {}", ext.to_string_lossy()).into()); @@ -159,7 +159,7 @@ impl TryCmd { let raw = std::fs::read_to_string(path) .map_err(|e| format!("Failed to read {}: {}", path.display(), e))?; - let mut normalized = snapbox::normalization::normalize_lines(&raw); + let mut normalized = snapbox::filters::normalize_lines(&raw); overwrite_trycmd_status(exit, step, &mut line_nums, &mut normalized)?;