#parametrized #test

nightly plague

Parametrized tests tools

9 unstable releases

Uses old Rust 2015

0.6.3 Oct 24, 2016
0.6.0 Jul 8, 2016
0.5.3 Feb 25, 2016
0.5.1 Jan 11, 2016
0.2.0 Jan 10, 2016

#372 in Testing

Download history 19/week @ 2023-10-29 2/week @ 2023-11-05 3/week @ 2023-11-12 12/week @ 2023-11-19 30/week @ 2023-11-26 19/week @ 2023-12-03 9/week @ 2023-12-10 1/week @ 2023-12-17 19/week @ 2023-12-24 10/week @ 2023-12-31 1/week @ 2024-01-07 1/week @ 2024-01-14 20/week @ 2024-01-21 19/week @ 2024-01-28 1/week @ 2024-02-04 31/week @ 2024-02-11

71 downloads per month

MIT license

10KB
207 lines

Plague Build Status Crates.io License

Parametrized tests tools for Rust

What

This rustc plugin adds a macro to help you make parametrized tests:

// 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 or give meaningful names to test cases
plague! {
    for [
        'empty ("",) -> 0,
        ("foo",) -> 3,
        'c_str ("foo\u{0}bar",) -> 7,
    ]
    test str::len
}

Why

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 pos#4 ... ok
test pos#2 ... FAILED
test pos#3 ... FAILED
test pos#5 ... ok
test pos'empty ... ok
test pos'not_found ... ok
test pos'unary ... FAILED
test without_plague ... FAILED

failures:

---- pos#2 stdout ----
	thread 'pos#2' panicked at 'test failed: got `None`, expected `Some(0)`', examples/cmp.rs:15

---- pos#3 stdout ----
	thread 'pos#3' panicked at 'test failed: got `Some(2)`, expected `Some(0)`', examples/cmp.rs:15

---- pos'unary stdout ----
	thread 'pos'unary' panicked at 'test failed: got `None`, expected `Some(0)`', examples/cmp.rs:15

---- without_plague stdout ----
	thread 'without_plague' panicked at 'assertion failed: `(left == right)` (left: `None`, right: `Some(0)`)', examples/cmp.rs:41


failures:
    pos#2
    pos#3
    pos'unary
    without_plague

test result: FAILED. 4 passed; 4 failed; 0 ignored; 0 measured

No runtime deps