Parametrized tests tools for Rust
This rustc
plugin adds a macro to help you make parametrized tests:
```rust // Basic usage plague! { for [ (1, 1), (2, 2), ] test fn eq(a: i32, b: i32) { assert_eq!(a, b); } }
// You can also specify the expected value, Plague will assert_eq!
the result for you
plague! {
for [1 -> 2, 2 -> 4]
test fn double(a: i32) -> i32 {
2*a
}
}
// And you can call functions defined somewhere else plague! { for [ ("",) -> 0, ("foo",) -> 3, ("foo\u{0}bar",) -> 7, ] test str::len } ```
The plugin will generate one test function for each parameter set, this way,
running cargo test
will show each failed value, instead of just one:
```
running 8 tests
test pos0 ... ok
test pos2 ... FAILED
test pos3 ... FAILED
test pos1 ... FAILED
test pos4 ... ok
test pos5 ... ok
test pos6 ... ok
test withoutplague ... FAILED
failures:
---- pos2 stdout ----
thread 'pos2' panicked at 'assertion failed: (left == right)
(left: Some(0)
, right: None
)', examples/cmp.rs:15
---- pos3 stdout ----
thread 'pos3' panicked at 'assertion failed: (left == right)
(left: Some(0)
, right: Some(2)
)', examples/cmp.rs:15
---- pos1 stdout ----
thread 'pos1' panicked at 'assertion failed: (left == right)
(left: Some(0)
, right: None
)', examples/cmp.rs:15
---- withoutplague stdout ----
thread 'withoutplague' panicked at 'assertion failed: (left == right)
(left: None
, right: Some(0)
)', examples/cmp.rs:41
failures: pos1 pos2 pos3 withoutplague
test result: FAILED. 4 passed; 4 failed; 0 ignored; 0 measured ```