Open jaques-sam opened 4 months ago
No, I should say sadly that there isn't any way to do it today and is not simple to implement it.
rstest
procedural macro cannot know the enum definition because is processed on the early stage immediately after the parsing stage and just the AST of the item that's processed is know (in this case the function): the type resolution is a later stage.
Anyway we can think a sub-optimal convoluted approach like the one used in rstest_reuse
where an enum annotation
generate a macro definition that we can use to generate a #[value]
annotation in the signature: example
#[derive(Debug, PartialEq)]
#[rstest::enumerates]
enum Fruit {
Apple,
Banana,
Orange,
}
#[rstest::enumerates(fruit)]
#[rstest]
fn test_enum_values(fruit: Fruit) {
}
That should expand the rstest
in
#[rstest]
fn test_enum_values(#[values(Fruit::Apple, Fruit::Banana, Fruit::Orange)] fruit: Fruit) {
}
The sad thing here is that (maybe) I cannot move it the argument annotation but I should annotate that rstest
function to be sure to process it before the rstest
one.
Typically you would do something like:
Is there a nice way of simply giving the enum type only so that all variants are tested (or that none of the variants are forgotten)? The logic above won't give an indication about that. Or otherwise, if it's not easily doable, it could be a feature request.