1 /*!
2 This crate is a port of
3 [Haskell's QuickCheck](https://hackage.haskell.org/package/QuickCheck).
4 
5 For detailed examples, please see the
6 [README](https://github.com/BurntSushi/quickcheck).
7 
8 # Compatibility
9 
10 In general, this crate considers the `Arbitrary` implementations provided as
11 implementation details. Strategies may or may not change over time, which may
12 cause new test failures, presumably due to the discovery of new bugs due to a
13 new kind of witness being generated. These sorts of changes may happen in
14 semver compatible releases.
15 */
16 
17 pub use crate::arbitrary::{empty_shrinker, single_shrinker, Arbitrary, Gen};
18 pub use crate::tester::{quickcheck, QuickCheck, TestResult, Testable};
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]
43 macro_rules! quickcheck {
44     (@as_items $($i:item)*) => ($($i)*);
45     {
46         $(
47             $(#[$m:meta])*
48             fn $fn_name:ident($($arg_name:ident : $arg_ty:ty),*) -> $ret:ty {
49                 $($code:tt)*
50             }
51         )*
52     } => (
53         $crate::quickcheck! {
54             @as_items
55             $(
56                 #[test]
57                 $(#[$m])*
58                 fn $fn_name() {
59                     fn prop($($arg_name: $arg_ty),*) -> $ret {
60                         $($code)*
61                     }
62                     $crate::quickcheck(prop as fn($($arg_ty),*) -> $ret);
63                 }
64             )*
65         }
66     )
67 }
68 
69 #[cfg(feature = "use_logging")]
env_logger_init() -> Result<(), log::SetLoggerError>70 fn env_logger_init() -> Result<(), log::SetLoggerError> {
71     env_logger::try_init()
72 }
73 #[cfg(feature = "use_logging")]
74 macro_rules! info {
75     ($($tt:tt)*) => {
76         log::info!($($tt)*)
77     };
78 }
79 
80 #[cfg(not(feature = "use_logging"))]
env_logger_init()81 fn env_logger_init() {}
82 #[cfg(not(feature = "use_logging"))]
83 macro_rules! info {
84     ($($_ignore:tt)*) => {
85         ()
86     };
87 }
88 
89 mod arbitrary;
90 mod tester;
91 
92 #[cfg(test)]
93 mod tests;
94