#generic #proc-macro #test #debugging #parameterize

macro generic_parameterize

A test parameterization macro that works on generic arguments

4 releases

new 0.2.2 May 6, 2024
0.2.1 Jun 14, 2023
0.2.0 Jun 14, 2023
0.1.0 Aug 15, 2022

#703 in Testing

Download history 6/week @ 2024-02-17 27/week @ 2024-02-24 4/week @ 2024-03-02 6/week @ 2024-03-09 1/week @ 2024-03-16 43/week @ 2024-03-30 13/week @ 2024-04-06 144/week @ 2024-05-04

144 downloads per month
Used in vector-victor

MPL-2.0 license

22KB
387 lines

Generic Parameterize

This crate provides the parameterize macro, which allow parameterizing generic functions for applications like unit testing.

for example,

use generic_parameterize::parameterize;
use std::fmt::Debug;

#[parameterize(T = (i32, f32), N = [4, 5, 6])]
#[test]
fn test_array<T: Default, const N: usize>() where [T; N]: Default + Debug {
    let foo: [T; N] = Default::default();
    println!("{:?}", foo)
}

generates a module called test_array containing functions called test_array_i32_4, test_array_i32_5 etc. The #[test] attribute gets copied to the child functions, which in turn call a copy of test_array. The result looks like:

mod test_array {
    use std::println;
    fn test_array<T: Default, const N : usize>() where [T;N]: Default + std::fmt::Debug{
         let foo: [T;N] = Default::default();
         println!("{:?}", foo)
    }

    #[test]
    fn test_array_i32_4() {test_array::<i32,4>();}
    #[test]
    fn test_array_f32_4() {test_array::<f32,4>();}
    #[test]
    fn test_array_i32_5() {test_array::<i32,5>();}
    // etc...
 }

Dependencies

~0.7–1.2MB
~26K SLoC