-
-
Notifications
You must be signed in to change notification settings - Fork 3.1k
Open
Description
I would like to be able to control the generated part of the test case name when using TEMPLATE_LIST_TEST_CASE. At present it uses the name of the type list and the index into the list. For example:
using arithmetic_type_list = type_list<int, long, float, double>;
TEMPLATE_LIST_TEST_CASE("test-case", "[tag]", arithmetic_type_list) {}
With this code we end up with test cases with names like:
test-case - arithmetic_type_list - 0
test-case - arithmetic_type_list - 1
test-case - arithmetic_type_list - 2
test-case - arithmetic_type_list - 3
I would like to be able to have:
test-case - int
test-case - long
test-case - float
test-case - double
As far as I can tell the relevant code is:
#define INTERNAL_CATCH_TEMPLATE_LIST_TEST_CASE_2(TestName, TestFunc, Name, Tags, TmplList)\
CATCH_INTERNAL_START_WARNINGS_SUPPRESSION \
CATCH_INTERNAL_SUPPRESS_GLOBALS_WARNINGS \
CATCH_INTERNAL_SUPPRESS_UNUSED_TEMPLATE_WARNINGS \
CATCH_INTERNAL_SUPPRESS_UNUSED_VARIABLE_WARNINGS \
template<typename TestType> static void TestFunc(); \
namespace {\
namespace INTERNAL_CATCH_MAKE_NAMESPACE(TestName){\
INTERNAL_CATCH_TYPE_GEN\
template<typename... Types> \
struct TestName { \
void reg_tests() { \
size_t index = 0; \
using expander = size_t[]; \
(void)expander{(Catch::AutoReg( Catch::makeTestInvoker( &TestFunc<Types> ), CATCH_INTERNAL_LINEINFO, Catch::StringRef(), Catch::NameAndTags{ Name " - " + std::string(INTERNAL_CATCH_STRINGIZE(TmplList)) + " - " + std::to_string(index), Tags } ), index++)... };/* NOLINT */\
} \
};\
static int INTERNAL_CATCH_UNIQUE_NAME( globalRegistrar ) = [](){ \
using TestInit = typename convert<TestName, TmplList>::type; \
TestInit t; \
t.reg_tests(); \
return 0; \
}(); \
}}\
CATCH_INTERNAL_STOP_WARNINGS_SUPPRESSION \
template<typename TestType> \
static void TestFunc()
Specifically:
Catch::NameAndTags{ Name " - " + std::string(INTERNAL_CATCH_STRINGIZE(TmplList)) + " - " + std::to_string(index), Tags }
To get the behaviour I would like would require something like:
Catch::NameAndTags{ Name " - " + std::string(typeid(Types).name()), Tags }
Would you be happy with a macro such as:
#ifndef CATCH_TEMPLATE_LIST_TEST_CASE_SUFFIX
#define CATCH_TEMPLATE_LIST_TEST_CASE_SUFFIX(TmplList) std::string(INTERNAL_CATCH_STRINGIZE(TmplList)) + " - " + std::to_string(index)
#endif
So that the relevant code becomes:
Catch::NameAndTags{ Name " - " + CATCH_TEMPLATE_LIST_TEST_CASE_SUFFIX(TmplList), Tags }
Then I could put in my code something like:
#define CATCH_TEMPLATE_LIST_TEST_CASE_SUFFIX(TL) \
std::string(typeid(Types).name())
Thoughts? Problems with the macro definition/usage?
If you are happy with this approach, let me know and I should be able to prepare a pull request based on the above.
Metadata
Metadata
Assignees
Labels
No labels