unit_testing/
lib.rs

1#![allow(clippy::multiple_crate_versions)]
2pub mod assertions;
3pub mod objects;
4pub mod output;
5pub mod suite;
6pub mod unit;
7
8///
9/// # Failures are prohibited
10///
11/// - `title` The title
12/// - `description` A detailed description
13/// - `time` The asserting sleep time
14/// - `callbacks` The callbacks to execute
15///
16#[macro_export]
17macro_rules! assert_that {
18    ($title:expr,$description:expr,$time:expr,$callbacks:expr) => {
19        Assert::it($title, $description, $time, $callbacks);
20    };
21}
22
23///
24/// # Failures are not prohibited
25///
26/// - `title` A title
27/// - `description` A detailed description
28/// - `time` The asserting sleep time
29/// - `callbacks` The callbacks to execute
30///
31#[macro_export]
32macro_rules! check_that {
33    ($title:expr,$description:expr,$time:expr,$callbacks:expr) => {
34        Unit::it($title, $description, $time, $callbacks);
35    };
36}
37///
38/// # Always panic but disable output message
39///
40/// - `c` callback
41///
42#[macro_export]
43macro_rules! always_panic {
44    () => {
45        std::panic::set_hook(Box::new(|_| {}));
46        panic!("");
47    };
48}
49///
50///
51/// # Run test suite
52///
53/// - `t` The test result (bool)
54/// - `s` The test success message
55/// - `e` The error message
56/// - `before` The before each callback
57/// - `after` The after each callback
58///
59#[macro_export]
60macro_rules! run {
61    ($t:expr,$s:expr,$e:expr,$before:ident,$after:ident) => {
62        $before();
63        std::panic::set_hook(Box::new(|_| {
64            println!(
65                "{}\n",
66                format_args!("\t\t{} {}", "*".red().bold(), $e.red().blink().bold())
67            );
68        }));
69        if $t.eq(&false) {
70            panic!("");
71        }
72        println!(
73            "{}\n",
74            format_args!(
75                "\t\t{} {}",
76                "".true_color(55, 190, 176).bold(),
77                $s.true_color(55, 190, 176).bold()
78            )
79        );
80        $after();
81        std::thread::sleep(std::time::Duration::from_millis(50));
82    };
83}
84
85///
86///
87/// # Run test suite
88///
89/// - `title` The test title
90/// - `description` The test description message
91/// - `before_all` The before all callback
92/// - `before` The before each callback
93/// - `after_all` The after all callback
94/// - `after` The after each callback
95/// - `main` The main callback
96///
97#[macro_export]
98macro_rules! it {
99    ($title:expr,$description:expr,$before_all:ident,$before:ident,$after_all:ident,$after:ident,$main:ident) => {
100        assert!($crate::suite::describe(
101            $title,
102            $description,
103            $after_all,
104            $after,
105            $before_all,
106            $before,
107            $main,
108        )
109        .end()
110        .is_ok());
111    };
112}