Macro proptest
macro_rules! proptest {
(#![proptest_config($config:expr)]
$(
$(#[$meta:meta])*
fn $test_name:ident($($parm:pat in $strategy:expr),+ $(,)?) $body:block
)*) => { ... };
(#![proptest_config($config:expr)]
$(
$(#[$meta:meta])*
fn $test_name:ident($($arg:tt)+) $body:block
)*) => { ... };
($(
$(#[$meta:meta])*
fn $test_name:ident($($parm:pat in $strategy:expr),+ $(,)?) $body:block
)*) => { ... };
($(
$(#[$meta:meta])*
fn $test_name:ident($($arg:tt)+) $body:block
)*) => { ... };
(|($($parm:pat in $strategy:expr),+ $(,)?)| $body:expr) => { ... };
(move |($($parm:pat in $strategy:expr),+ $(,)?)| $body:expr) => { ... };
(|($($arg:tt)+)| $body:expr) => { ... };
(move |($($arg:tt)+)| $body:expr) => { ... };
($config:expr, |($($parm:pat in $strategy:expr),+ $(,)?)| $body:expr) => { ... };
($config:expr, move |($($parm:pat in $strategy:expr),+ $(,)?)| $body:expr) => { ... };
($config:expr, |($($arg:tt)+)| $body:expr) => { ... };
($config:expr, move |($($arg:tt)+)| $body:expr) => { ... };
}
Easily define proptest tests.
Within proptest!, define one or more functions without return type
normally, except instead of putting : type after each parameter, write
in strategy, where strategy is an expression evaluating to some
Strategy.
Each function will be wrapped in a function which sets up a TestRunner,
and then invokes the function body with inputs generated according to the
strategies.
Example
use *;
proptest!
#
#
You can also use the normal argument syntax pattern: type as in:
use *;
proptest!
#
#
As you can see, you can mix pattern: type and pattern in expr.
Due to limitations in macro_rules!, pattern: type does not work in
all circumstances. In such a case, use (pattern): type instead.
To override the default configuration, you can start the proptest! block
with #![proptest_config(expr)], where expr is an expression that
evaluates to a proptest::test_runner::Config (or a reference to one).
use *;
proptest!
#
#
Closure-Style Invocation
As of proptest 0.8.1, an alternative, "closure-style" invocation is
supported. In this form, proptest! is a function-like macro taking a
closure-esque argument. This makes it possible to run multiple tests that
require some expensive setup process. Note that the "fork" and "timeout"
features are not supported in closure style.
To use a custom configuration, pass the Config object as a first
argument.
Example
use *;
# /*
#[test]
# */
#
#