Announcing conformance::tests: a conformance testing proc-macro attribute

Read the blog post!

conformance::tests allows you to write simply something like

#[conformance::tests(exact,
    ser = serde_yaml::to_string,
    de = serde_yaml::from_str,
    file = "tests/example.test")]
fn lex_tokens(s: &str) -> Vec<Token> {
    lib::tokenize(s).collect()
}

and generate standard test-runner tests for every test in tests/example.test very easily.

Individual tests are formatted as a name, ===, the input string, ---, the serialized output, and ... as a terminator. Any number of tests can be in one file, and any number of conformance::tests attributes can apply to one function. If you deserialize the input first, you can test any API, not just those that take string input.

This is most useful when writing a parser, but can be applied to any API where you want a large test suite with the input/output pairs visible in data next to each other, as opposed to the separate files typical to snapshot testing.

Did I mention that this generates a unique Rust test-runner test per test in your dataset? This means you always run all the tests, and the standard test runner (cargo test) can display pass/failure statistics, and any tooling that integrates with cargo test just works as well.

Add it as a dependency today!

Was that the right amount of commercial?

3 Likes