sample_test/
lib.rs

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