Skip to content

Commit

Permalink
feat(snap): Auto-infer filename for expect_file
Browse files Browse the repository at this point in the history
  • Loading branch information
epage committed Feb 14, 2024
1 parent 4bb90b6 commit 1732694
Showing 1 changed file with 6 additions and 0 deletions.
6 changes: 6 additions & 0 deletions crates/snapbox/src/data.rs
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
/// ```
/// # use snapbox::expect_file;
/// expect_file!["./test_data/bar.html"];
/// expect_file![];
/// ```
#[macro_export]
macro_rules! expect_file {
Expand All @@ -13,6 +14,11 @@ macro_rules! expect_file {
path.push($path);
$crate::Data::read_from(&path, None)
}};
[] => {{
let path = std::path::Path::new(file!()).file_stem().unwrap();
let path = format!("snapshots/{}-{}.txt", path.to_str().unwrap(), line!());
$crate::expect_file![path]
}};
}

/// Test fixture, actual output, or expected result
Expand Down

0 comments on commit 1732694

Please sign in to comment.