Crate tryfn

Source
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

fn some_func(num: usize) -> usize {
    // ...
}

tryfn::Harness::new(
    "tests/fixtures/invalid",
    setup,
    test,
)
.select(["tests/cases/*.in"])
.test();

fn setup(input_path: std::path::PathBuf) -> tryfn::Case {
    let name = input_path.file_name().unwrap().to_str().unwrap().to_owned();
    let expected = tryfn::Data::read_from(&input_path.with_extension("out"), None);
    tryfn::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 = some_func(num);

    Ok(actual)
}

Structs§

Case
A test case enumerated by the Harness with data from the Setup function
Data
Test fixture, actual output, or expected result
Harness
Harness for discovering test inputs and asserting against snapshot files

Enums§

DataFormat
Describes the structure of Data

Traits§

Setup
Function signature for generating a test Case from a path fixture
Test
Function signature for running a test Case