qcheck/lib.rs
1pub use crate::arbitrary::{empty_shrinker, single_shrinker, Arbitrary, Gen};
2pub use crate::tester::{quickcheck, QuickCheck, TestResult, Testable};
3
4/// A macro for writing quickcheck tests.
5///
6/// This macro takes as input one or more property functions to test, and
7/// produces a proper `#[test]` function for each property. If the property
8/// fails, the behavior is as if `quickcheck` were called on the property
9/// (i.e., it panics and fails the test).
10///
11/// Note that this macro doesn't support `mut` or patterns in parameters.
12///
13/// # Example
14///
15/// ```rust
16/// # #[macro_use] extern crate qcheck; fn main() {
17/// quickcheck! {
18/// fn prop_reverse_reverse(xs: Vec<usize>) -> bool {
19/// let rev: Vec<_> = xs.clone().into_iter().rev().collect();
20/// let revrev: Vec<_> = rev.into_iter().rev().collect();
21/// xs == revrev
22/// }
23/// };
24/// # }
25/// ```
26#[macro_export]
27macro_rules! quickcheck {
28 (@as_items $($i:item)*) => ($($i)*);
29 {
30 $(
31 $(#[$m:meta])*
32 fn $fn_name:ident($($arg_name:ident : $arg_ty:ty),*) -> $ret:ty {
33 $($code:tt)*
34 }
35 )*
36 } => (
37 $crate::quickcheck! {
38 @as_items
39 $(
40 #[test]
41 $(#[$m])*
42 fn $fn_name() {
43 fn prop($($arg_name: $arg_ty),*) -> $ret {
44 $($code)*
45 }
46 $crate::quickcheck(prop as fn($($arg_ty),*) -> $ret);
47 }
48 )*
49 }
50 )
51}
52
53mod arbitrary;
54mod tester;
55
56#[cfg(test)]
57mod tests;