I have a function that I want to test for each possible input with Catch2. This function has multiple compile-time constants as its parameter. For simplicity, let's say I have two enums
enum class A { a, b};
enum class B { a, b};
and the function
template<A a, B b> void foo() { /* do something */ }
that I want to test with each possible combination of the values of A
and B
.
How can I achieve this in Catch2? I would expect this to be possible without having to list all possible permutations.
What I've tried so far
A a = GENERATE(A::a, A::b);
B b = GENERATE(B::a, B::b);
does not do the trick because I want them to be compile-time constants, i.e., I would need constexpr A a = GENERATE(...)
which does not work.
Using TEMPLATE_TEST_CASE_SIG
would work:
TEMPLATE_TEST_CASE_SIG("foo works", "[foo]",
((A T, B V), T, V), (A::a,B::a), (A::b, B::a), (A::a,B::b),(A::b,B::b)) {
foo<T, V>();
}
But this would require me to list each possible permutation of A and B, which is not maintainable for any example that is larger than 2*2 values.