Support for more generic Cartesian product of type lists in type-parameterized tests
- Dominant language
- C++
- Stars
- 21.5k
- Forks
- 3.5k
- Avg merge
- 3d 16h
- Merged PRs (30d)
- 2
Description
**Description**
Today, the `TEMPLATE_PRODUCT_TEST_CASE` allows you to specify a list of template-template types and a list of types to plugin as the template arguments for the template-template types. E.g., from the docs
```
template< typename T>
struct Foo {
size_t size() {
return 0;
}
};
TEMPLATE_PRODUCT_TEST_CASE("A Template product test case", "[template][product]", (std::vector, Foo), (int, float)) {
TestType x;
REQUIRE(x.size() == 0);
}
```
This will instantiate tests where `TestType` is `std::vector, std::vector, Foo, Foo`.
I would like something more general where the first list of types need not be a list of template-template types. This makes more sense in the context of `TEMPLATE_TEST_CASE_SIG`. For example, what I would like is something like this:
```
template
struct Foo{};
TEMPLATE_CROSS_PRODUCT_TEST_CASE_SIG("Example", "", ((typename T, int S), T, S), (int, float), (1, 42) {
Foo f;
}
```
This would instantiate tests for all of `Foo, Foo, Foo, Foo`.
Today I'm required to manually unfold the cross-product like this:
```
TEMPLATE_TEST_CASE_SIG("Workaround", "]", ((typename T, int S), T, S), (int,1), (int,42), (float, 1), (float,42) ){
Foo f;
}
```
**Additional Context**
This may not actually require an additional `TEMPLATE_TEST_CASE` macro and could instead simply be a utility that given lists of types it constructs a new type list that manifests that cross-product of the input type lists.
I already have some machinery that allows to me do this cross-product of type lists that I use for Google Tests today. There's nothing strictly unique about it for Google Test, so it could be used in Catch2 as well.
See: https://github.com/rapidsai/cudf/blob/8192833a7f820abcfa31a00186a8e325abc56b0b/cpp/tests/utilities/type_list_utilities.hpp#L267-L283
Contributor guide
Assessment
This issue has not been assessed yet.