Crates.io | typed_test_gen |
lib.rs | typed_test_gen |
version | 0.1.2 |
source | src |
created_at | 2023-09-01 13:01:25.836395 |
updated_at | 2024-10-01 14:01:54.323239 |
description | Macros to help generate tests from functions with a generic type parameter. |
homepage | |
repository | https://github.com/twiby/test_gen/ |
max_upload_size | |
id | 960885 |
size | 44,841 |
Rust crate for defining a macro that automatically specializes generic tests on provided types. This is useful
when we want to write identical tests with different underlying types. This crate provide the syntax #[test_with(Type1, Type2)]
which will instantiate 2 tests: one on Type1
, the other on Type2
. Those types could be any path to any generic type like
module::something::Type<Gen>
.
An example is better than words:
#[test_with(u32, u64, char)]
fn test_vec<T>() {
let vec = Vec::<T>::with_capacity(10);
assert_eq!(vec.len(), 0);
assert!(vec.capacity() >= 10);
}
This code will generate 3 tests function: _specialized__test_vec__u32_
, _specialized__test_vec__u64_
, and _specialized__test_vec__char_
.
This support adding the attribute #[should_panic]
to the definition.
#[test_with(u32, u64, char)]
#[should_panic]
fn test_vec_fail<T>() {
let vec = Vec::<T>::with_capacity(10);
assert_eq!(vec.len(), 0);
assert!(vec.capacity() < 10);
}