Allow to customize test function name
For example, I want to test all formats from kaitai-struct gallery. I use following code (folder formats is git checkout of https://github.com/kaitai-io/kaitai_struct_formats repository):
#[cfg(test)]
mod formats {
use std::fs::File;
use test_generator::test_resources;
use super::Ksy;
#[test_resources("formats/**/*.ksy")]
fn parse(resource: &str) {
let file = File::open(resource).expect(&format!("can't read file {}", resource));
let _: Ksy = serde_yaml::from_reader(file).expect(&format!("invalid file {}", resource));
}
}
and get following output:
test parser::formats::parse_formats_archive_cpio_old_le_ksy ... ok
...
Generated function name seems repeat module name. I would be like see something like
test parser::formats::parse_archive_cpio_old_le_ksy ... ok
...
That can be implemented, for example, by introducing capture group in glob pattern, something like #[test_resources("formats/(**/*).ksy")]
Would be a grood improvement, I like this idea :)
+1 to this idea, for an example of a similar crate that allows customization like this you could look at test_case
Their generate tests are actually #[cfg(test)] modules, e.g. this code
#[test_case(1; "my test 1")]
#[test_case(2; "my test 2")]
fn do_test(x: usize) {}
would generate something like
#[cfg(test)]
mod do_test {
fn do_test(x: usize) {}
#[test]
fn my_test_1() {do_test(1);}
#[test]
fn my_test_2() {do_test(2);}
}
Personally I'm a fan of this model as it logically groups related tests into a proper module structure.