Skip to content

Commit

Permalink
feat(snap)!: Allow Harness users to specify DataFormat
Browse files Browse the repository at this point in the history
BREAKING CHANGE: `Case` requires a `format: Option<DataFormat>` field

Fixes assert-rs#263
  • Loading branch information
epage committed Apr 19, 2024
1 parent c1c0b01 commit 30a9b78
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 1 deletion.
8 changes: 7 additions & 1 deletion crates/snapbox/src/harness.rs
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@
//! name,
//! fixture: input_path,
//! expected,
//! format: None,
//! }
//! }
//!
Expand Down Expand Up @@ -125,7 +126,10 @@ where
Trial::test(case.name.clone(), move || {
let actual = (test)(&case.fixture)?;
let actual = actual.to_string();
let actual = crate::Data::text(actual).normalize(NormalizeNewlines);
let mut actual = crate::Data::text(actual).normalize(NormalizeNewlines);
if let Some(format) = case.format {
actual = actual.coerce_to(format);
}
#[allow(deprecated)]
let verify = Verifier::new()
.palette(crate::report::Palette::auto())
Expand Down Expand Up @@ -229,4 +233,6 @@ pub struct Case {
pub fixture: std::path::PathBuf,
/// What the actual output should be compared against or updated
pub expected: std::path::PathBuf,
/// Explicitly specify what format `expected` is stored in
pub format: Option<DataFormat>,
}
1 change: 1 addition & 0 deletions crates/snapbox/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -76,6 +76,7 @@
//! name,
//! fixture: input_path,
//! expected,
//! format: None,
//! }
//! }
//!
Expand Down

0 comments on commit 30a9b78

Please sign in to comment.