Crate fn_fixture[−][src]
This crate provides a procedural macro to set up tests based on a directory of inputs to a function.
A more complete explanation is provided in the readme of the repository.
Overview
The annotation has 3 primary requirements:
-
It must be annotating a function with return type implementing
std::fmt::Debug
.Result
is weakly recommended. -
It must use a string literal containing the path (relative to cargo manifest) to a base folder. A base folder must contain test folders or base folders. Test folders must contain exactly one of
input.rs
,input.txt
, orinput.bin
. -
It must have a single parameter of the corresponding to a respective type of the input files as included by their respective macros,
include
,include_str
, andinclude_bytes
.
Example
project_root/src/lib/tests.rs
#[fn_fixture::snapshot("snapshot-tests/examples")] fn parse_unsigned_number(value: &str) -> Result<usize, impl std::fmt::Debug> { value.parse() }
project_root/snapshot-tests/examples/good_number/input.txt
42
Notice that snapshot-tests/examples
does not itself contain an input.txt
Attribute Macros
snapshot | Denotes the entrance point of a function-fixture's snapshots. |