test_gen
A comprehensive declarative macro, for concisely defining parameterized tests.
This crate provides the declarative macro of its namesake, test_gen,
which enables the concise definition of batches of named tests,
implementing a parameterized argument format to minimise the boilerplate
otherwise required for specifying batches of similar tests.
Documentation can be found at Docs.rs.
Usage
Minimum Supported Rust Version: 1.61.0
test_gen can be included, by adding this to your Cargo.toml:
[dev-dependancies]
test_gen = "0.1.0"
Examples
Fruits:
use test_gen::*;
enum Fruit<T> {
Apple,
Pear,
Other(T),
}
enum BrambleFruit {
BlackBerry,
}
trait NameOf {
fn name_of(&self) -> &str;
}
impl<T: NameOf> NameOf for Fruit<T> {
fn name_of(&self) -> &str {
use Fruit::*;
match self {
Apple => "apple",
Pear => "pear",
Other(fruit) => fruit.name_of(),
}
}
}
impl NameOf for BrambleFruit {
fn name_of(&self) -> &str {
use BrambleFruit::*;
match self {
BlackBerry => "blackberry",
}
}
}
fn assert_fruit<T: NameOf>(fruit: Fruit<T>, name: &str) {
assert_eq!(fruit.name_of(), name);
}
test_gen! {
assert_fruit::<BrambleFruit> => {
apple: { (Fruit::Apple, "apple") },
pear: { [ignore], (Fruit::Pear, "pear") },
isnt_pear: { [should_panic], (Fruit::Pear, "apple") },
blackberry: { (Fruit::Other(BrambleFruit::BlackBerry), "blackberry") }
}
}
License
test_gen is licensed under the BSD 3-Clause license.
See LICENSE for details.