tinytest

Crates.iotinytest
lib.rstinytest
version0.1.1
sourcesrc
created_at2021-11-01 23:25:18.894925
updated_at2021-11-01 23:54:15.990986
descriptionWrite more compact unit tests with a small macro.
homepage
repositoryhttps://github.com/Alonely0/tinytest/
max_upload_size
id475484
size5,490
Guillem Jara (Alonely0)

documentation

README

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
            )
        );
    }
}
Commit count: 4

cargo fmt