#unit-testing #unit #testing #unit-tests #no-std

no-std tinytest

Write more compact unit tests with a small macro

2 releases

0.1.1 Nov 1, 2021
0.1.0 Nov 1, 2021

#2465 in Rust patterns


Used in voila

MIT license

5KB

Usage

use tinytest::unit_test;

unit_test!(test1, || some_function_in_scope("test").unwrap(), "expected output")

automatically gets translated in compile time to a standard test:

#[cfg(test)]
mod test1 {
    use super::*;

    #[test]
    fn tiny_test() {
        assert_eq!(some_function_in_scope("test").unwrap(), "expected output");
    }
}

the same applies to this larger closure:

use tinytest::unit_test;

unit_test!(test2, || {
    let mut c = some_function_in_scope("test").unwrap().chars()
    c.next();
    c.next_back();
    (
        c.collect::<String>(),
        some_other_function_in_scope(73)
    )
}, (
    "expected output".to_string(),
    21
    )
)

that translates to:

#[cfg(test)]
mod test2 {
    use super::*;

    #[test]
    fn tiny_test() {
        assert_eq!(
            {
                let mut c = some_function_in_scope("test").unwrap().chars()
                c.next();
                c.next_back();
                (
                    c.collect::<String>(),
                    some_other_function_in_scope(73)
                )
            }, (
                "expected output".to_string(),
                21
            )
        );
    }
}

No runtime deps