macro_rules! collect_fails {
($input:ty, $expected:ty, $result:ty, $cases:expr, $test:expr, $assert:expr) => { ... };
($input:ty, $result:ty, $cases:expr, $test:expr) => { ... };
}
Expand description
Executes a series of test-cases, collecting error information.
§Usage
- An iterator of input and expected output data is required.
- By default compares the result and expected result for equality, a custom assertion function may be provided as sixth parameter.
- While debugging, panics on assertion failure, otherwise collects all failed data in a
Vec
§Examples
Basic usage:
#[test]
fn test_parse_fragment_any() {
report_fails(collect_fails!(
// input type
&str,
// output type
IResult<&str, Fragment, ()>,
// test cases in format (input, expected)
vec![
("/", Ok(("", Fragment::Separator))),
("///", Ok(("", Fragment::Separator))),
("path/to/file", Ok(("/to/file", Fragment::Plain("path"))))
].into_iter(),
// test function
parse_fragment
));
}
Custom assertion:
fn test_in_range() {
report_fails(collect_fails!(
usize,
std::ops::Range<usize>,
usize,
vec![(2, 1..4), (3, 4..6), (0, 1..3)].into_iter(),
|input| input + 2,
|output: &usize, expected: &Range<usize>| expected.contains(output)
));
}