Module snapbox::harness

source ·
Available on crate feature harness only.
Expand description

Harness for discovering test inputs and asserting against snapshot files

This is a custom test harness and should be put in its own test binary with test.harness = false.

§Examples

snapbox::harness::Harness::new(
    "tests/fixtures/invalid",
    setup,
    test,
)
.select(["tests/cases/*.in"])
.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)
}

Structs§

  • A test case enumerated by the Harness with data from the setup function
  • HarnessDeprecated
    [Fallback dependenciesforfallback-dependenciess [Build script directivesck-build-script-directivess [When to use packages or workspaces?ck-when-to-use-packages-or-workspacess [Cargo and rustupes?cargo-and-rustups