I'm looking for a good way to use Catch to test a templated class. I have something that almost works:
#define RUN_ALL(fn, params) \
fn<uint8_t, bool>(params); \
fn<uint8_t, char>(params); \
fn<uint16_t, bool>(params); \
fn<uint16_t, char>(params); \
fn<uint32_t, bool>(params); \
fn<uint32_t, char>(params); \
fn<uint64_t, bool>(params); \
fn<uint64_t, char>(params);
template<typename A, typename B>
void test_number_one() {
REQUIRE(...)
}
TEST_CASE("Foo::Foo() works nicely", "[SmallGraph]") {
RUN_ALL(test_number_one)
}
This setup will run only until the first failure, which is fine because it is highly likely that all 8 cases will fail the same way. However, it would be nice to know which set of template arguments are in use when a failure occurs. My idea is to do this:
#define RUN_ALL_P(fn, params) \
INFO("Testing <uint8_t, bool>"); \
fn<uint8_t, bool>(params); \
INFO("Testing <uint8_t, char>"); \
fn<uint8_t, char>(params); \
INFO("Testing <uint16_t, bool>"); \
fn<uint16_t, bool>(params); \
...
However, I can't use more than one INFO in RUN_ALL because doing so generates code with a duplicate identifier.
FOO.cpp:270:3: error: redefinition of 'scopedMessage270'
RUN_ALL(test_number_one);
(RUN_ALL(test_number_one)
appears on line 270.)
Any ideas for a workaround that doesn't require all test functions to the same signature?
(I would also welcome pointers to articles about testing template code using CATCH, as well as suggestions on how to search for such articles without getting a bunch of results about general exception handling -- i.e., try/catch.)