FTest - Very simple syntax sugar for test and benchmark

Hey, I built a super simple syntax sugar library for writing tests and benchmarks (using nightly features). The goal is cleaner syntax and less boilerplate (automatic use super::*, no more writing symbol #[test] or #[bench] on every single function). And it supports the unstable nightly benchmark features.

cleaner syntax and less boilerplate

Your README shows:

test!(my_test_module_name, {
    use library_name_if_using_lib;

    const OFFSET: i32 = 10;

    fn helper() -> i32 {
        5
    }

    test_case_one {
        let result = OFFSET + helper();
        assert_eq!(result, 15);
    }

    test_case_two {
        assert!(OFFSET > 0);
    }
});

I've never had an issue with tokens like use super::*; and #[test], to be honest.

They're not that much syntax noise to justify having your code no longer be auto-formattable by rustfmt, and rust-analyzer helps you create them.

if you write tfn (test function) rust-analyzer creates:

#[test]
fn feature() {
    
}

If you write tmd (test module) rust-analyzer creates:

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

    #[test]
    fn test_name() {
        
    }
}

Now, by using a macro like that, you've introduced additional barriers for potential contributors to your project. Tests should be as minimum-effort to write as possible, and by having all of that custom syntax, now you need to learn what all of those macros actually do.

2 Likes