Available on crate feature
harness
only.Expand description
Harness
for discovering test inputs and asserting against snapshot files
§Examples
snapbox::harness::Harness::new(
"tests/fixtures/invalid",
setup,
test,
)
.select(["tests/cases/*.in"])
.action_env("SNAPSHOTS")
.test();
fn setup(input_path: std::path::PathBuf) -> snapbox::harness::Case {
let name = input_path.file_name().unwrap().to_str().unwrap().to_owned();
let expected = input_path.with_extension("out");
snapbox::harness::Case {
name,
fixture: input_path,
expected,
}
}
fn test(input_path: &std::path::Path) -> Result<usize, Box<dyn std::error::Error>> {
let raw = std::fs::read_to_string(input_path)?;
let num = raw.parse::<usize>()?;
let actual = num + 10;
Ok(actual)
}