quickcheck/
lib.rs

1//! This crate is a port of
2//! [Haskell's QuickCheck](http://hackage.haskell.org/package/QuickCheck).
3//!
4//! For detailed examples, please see the
5//! [README](https://github.com/BurntSushi/quickcheck).
6
7#![allow(deprecated)] // for connect -> join in 1.3
8
9extern crate env_logger;
10#[macro_use] extern crate log;
11extern crate rand;
12
13pub use arbitrary::{
14    Arbitrary, Gen, StdGen,
15    empty_shrinker, single_shrinker,
16};
17pub use rand::Rng;
18pub use tester::{QuickCheck, Testable, TestResult, quickcheck};
19
20/// A macro for writing quickcheck tests.
21///
22/// This macro takes as input one or more property functions to test, and
23/// produces a proper `#[test]` function for each property. If the property
24/// fails, the behavior is as if `quickcheck` were called on the property
25/// (i.e., it panics and fails the test).
26///
27/// Note that this macro doesn't support `mut` or patterns in parameters.
28///
29/// # Example
30///
31/// ```rust
32/// # #[macro_use] extern crate quickcheck; fn main() {
33/// quickcheck! {
34///     fn prop_reverse_reverse(xs: Vec<usize>) -> bool {
35///         let rev: Vec<_> = xs.clone().into_iter().rev().collect();
36///         let revrev: Vec<_> = rev.into_iter().rev().collect();
37///         xs == revrev
38///     }
39/// };
40/// # }
41/// ```
42#[macro_export]
43macro_rules! quickcheck {
44    (@as_items $($i:item)*) => ($($i)*);
45    {
46        $(
47            fn $fn_name:ident($($arg_name:ident : $arg_ty:ty),*) -> $ret:ty {
48                $($code:tt)*
49            }
50        )*
51    } => (
52        quickcheck! {
53            @as_items
54            $(
55                #[test]
56                fn $fn_name() {
57                    fn prop($($arg_name: $arg_ty),*) -> $ret {
58                        $($code)*
59                    }
60                    $crate::quickcheck(prop as fn($($arg_ty),*) -> $ret);
61                }
62            )*
63        }
64    )
65}
66
67mod arbitrary;
68mod tester;
69
70#[cfg(test)]
71mod tests;