https://github.com/drewcassidy/generic-parameterize
A Rust attribute for parameterizing generic functions
https://github.com/drewcassidy/generic-parameterize
parameterization parameterized-tests proc-macro-attributes rust testing
Last synced: 2 months ago
JSON representation
A Rust attribute for parameterizing generic functions
- Host: GitHub
- URL: https://github.com/drewcassidy/generic-parameterize
- Owner: drewcassidy
- License: mpl-2.0
- Created: 2022-08-11T02:53:10.000Z (almost 3 years ago)
- Default Branch: main
- Last Pushed: 2024-06-16T19:51:47.000Z (12 months ago)
- Last Synced: 2025-04-02T05:18:05.054Z (2 months ago)
- Topics: parameterization, parameterized-tests, proc-macro-attributes, rust, testing
- Language: Rust
- Homepage:
- Size: 76.2 KB
- Stars: 0
- Watchers: 1
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- Changelog: CHANGELOG.md
- License: LICENSE.md
Awesome Lists containing this project
README
Generic Parameterize
====================This crate provides the `parameterize` macro, which allow parameterizing generic functions for applications like unit
testing.for example,
```rust
use generic_parameterize::parameterize;
use std::fmt::Debug;#[parameterize(T = (i32, f32), N = [4, 5, 6])]
#[test]
fn test_array() 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:```rust
mod test_array {
use std::println;
fn test_array() where [T;N]: Default + std::fmt::Debug{
let foo: [T;N] = Default::default();
println!("{:?}", foo)
}#[test]
fn test_array_i32_4() {test_array::();}
#[test]
fn test_array_f32_4() {test_array::();}
#[test]
fn test_array_i32_5() {test_array::();}
// etc...
}