sleuth/
lib.rs

1//! Extremely opinionated testing framework generating an exact specification and reducing code to its minimal implementation.
2//! ```rust
3//! use ::sleuth::sleuth;
4//!
5//! fn roundtrip<T, U, F, G>(f: F, g: G, x: T) -> bool
6//!   where
7//!   T: PartialEq + Clone,
8//!   F: Fn(U) -> T,
9//!   G: Fn(T) -> U,
10//! {
11//!   x.clone() == f(g(x))
12//! }
13//!
14//! #[sleuth(
15//!     roundtrip(sub_one, 42),
16//!     !roundtrip(add_one, 42),
17//! )]
18//! fn add_one(x: u8) -> u8 {
19//!     x + 1_u8
20//! }
21//!
22//! #[sleuth(
23//!     roundtrip(add_one, 42),
24//!     !roundtrip(sub_one, 42),
25//! )]
26//! fn sub_one(x: u8) -> u8 {
27//!     x - 1_u8
28//! }
29//! ```
30
31// TODO: #![no_std]
32
33#![warn(
34    missing_docs,
35    rustdoc::all,
36    clippy::missing_docs_in_private_items,
37    clippy::all,
38    clippy::restriction,
39    clippy::pedantic,
40    clippy::nursery,
41    clippy::cargo
42)]
43#![allow(
44    clippy::blanket_clippy_restriction_lints,
45    clippy::exhaustive_structs,
46    clippy::implicit_return,
47    clippy::integer_arithmetic,
48    clippy::mod_module_files,
49    clippy::pattern_type_mismatch,
50    clippy::pub_use,
51    clippy::question_mark_used,
52    clippy::separated_literal_suffix,
53    clippy::string_add,
54    clippy::wildcard_enum_match_arm,
55    clippy::wildcard_imports
56)]
57#![deny(warnings)]
58
59pub mod expr;
60
61mod util;
62
63pub use expr::Expr;
64pub use sleuth_mutator as mutator;
65pub use sleuth_mutator::*;
66
67/// Turns the output of a `timid_assert!` into a test.
68/// # Panics
69/// When given an argument that is not `None` (with almost exactly the message given).
70#[inline]
71pub fn testify(check_output: Option<&'static str>) {
72    #![allow(clippy::panic)]
73    use colored::Colorize;
74    let _: Option<()> = check_output.and_then(|e| {
75        panic!(
76            "{}",
77            e.replace(concat!("crate::", env!("CARGO_PKG_NAME"), "::"), "")
78                .as_str()
79                .on_red()
80        )
81    });
82}