1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84
//! Testing utilities for use with samplers defined via [`sample_std`].
//!
//! The easiest way to use these facilities is with the exported [`sample_test`]
//! macro:
//!
//! ```
//! use sample_test::{sample_test, Sample};
//!
//! #[sample_test]
//! fn test_order(#[sample(0..10)] a: usize, #[sample(20..30)] b: usize) -> bool {
//! a < b
//! }
//! ```
//!
//! You may also use [`tester::SampleTest`] or [`tester::sample_test`] directly:
//!
//! ```
//! use sample_test::{Random, tester::sample_test};
//! fn test(a: usize, b: usize) -> bool {
//! let sum = a + b;
//! sum >= a && sum >= b
//! }
//!
//! let mut r = Random::new();
//! let mut s = (0..10, 0..10);
//!
//! sample_test(s, test as fn(usize, usize) -> bool);
//! ```
pub use sample_test_macros::sample_test;
pub use quickcheck::{Arbitrary, Gen};
pub use sample_std::{Random, Sample};
pub mod tester;
pub use tester::{SampleTest, TestResult, Testable};
#[cfg(feature = "use_logging")]
pub fn env_logger_init() -> Result<(), log::SetLoggerError> {
env_logger::try_init()
}
#[cfg(feature = "use_logging")]
macro_rules! error {
($($tt:tt)*) => {
log::error!($($tt)*)
};
}
#[cfg(feature = "use_logging")]
macro_rules! info {
($($tt:tt)*) => {
log::info!($($tt)*)
};
}
#[cfg(feature = "use_logging")]
macro_rules! trace {
($($tt:tt)*) => {
log::trace!($($tt)*)
};
}
#[cfg(not(feature = "use_logging"))]
pub fn env_logger_init() {}
#[cfg(not(feature = "use_logging"))]
macro_rules! error {
($($_ignore:tt)*) => {
()
};
}
#[cfg(not(feature = "use_logging"))]
macro_rules! info {
($($_ignore:tt)*) => {
()
};
}
#[cfg(not(feature = "use_logging"))]
macro_rules! trace {
($($_ignore:tt)*) => {
()
};
}
pub(crate) use error;
pub(crate) use info;
pub(crate) use trace;