Skip to content

Commit d6c0efe

Browse files
committed
Improve naming for TEMPLATE_LIST_TEST_CASE_METHOD
It's not often very useful to name tests simply by incrementing numbers. This change adds a mechanism by which a name can be generated using both the index of the type in the type list, and also some from the type itself somehow.
1 parent d4c2b39 commit d6c0efe

19 files changed

+227
-20
lines changed

src/catch2/internal/catch_template_test_registry.hpp

Lines changed: 12 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -185,9 +185,10 @@
185185
template<typename... Types> \
186186
struct TestName { \
187187
void reg_tests() { \
188+
using Catch::IndexedTestTypeName; \
188189
size_t index = 0; \
189190
using expander = size_t[]; \
190-
(void)expander{(Catch::AutoReg( Catch::makeTestInvoker( &TestFunc<Types> ), CATCH_INTERNAL_LINEINFO, Catch::StringRef(), Catch::NameAndTags{ Name INTERNAL_CATCH_CONFIG_NAME_SEPARATOR INTERNAL_CATCH_STRINGIZE(TmplList) INTERNAL_CATCH_CONFIG_NAME_SEPARATOR + std::to_string(index), Tags } ), index++)... };/* NOLINT */\
191+
(void)expander{(Catch::AutoReg( Catch::makeTestInvoker( &TestFunc<Types> ), CATCH_INTERNAL_LINEINFO, Catch::StringRef(), Catch::NameAndTags{ Name INTERNAL_CATCH_CONFIG_NAME_SEPARATOR INTERNAL_CATCH_STRINGIZE(TmplList) INTERNAL_CATCH_CONFIG_NAME_SEPARATOR + IndexedTestTypeName<Types>{}(index), Tags } ), index++)... };/* NOLINT */\
191192
} \
192193
};\
193194
static int INTERNAL_CATCH_UNIQUE_NAME( globalRegistrar ) = [](){ \
@@ -320,9 +321,10 @@
320321
template<typename...Types>\
321322
struct TestNameClass{\
322323
void reg_tests(){\
324+
using Catch::IndexedTestTypeName;\
323325
size_t index = 0;\
324326
using expander = size_t[];\
325-
(void)expander{(Catch::AutoReg( Catch::makeTestInvoker( &TestName<Types>::test ), CATCH_INTERNAL_LINEINFO, #ClassName##_catch_sr, Catch::NameAndTags{ Name INTERNAL_CATCH_CONFIG_NAME_SEPARATOR INTERNAL_CATCH_STRINGIZE(TmplList) INTERNAL_CATCH_CONFIG_NAME_SEPARATOR + std::to_string(index), Tags } ), index++)... };/* NOLINT */ \
327+
(void)expander{(Catch::AutoReg( Catch::makeTestInvoker( &TestName<Types>::test ), CATCH_INTERNAL_LINEINFO, #ClassName##_catch_sr, Catch::NameAndTags{ Name INTERNAL_CATCH_CONFIG_NAME_SEPARATOR INTERNAL_CATCH_STRINGIZE(TmplList) INTERNAL_CATCH_CONFIG_NAME_SEPARATOR + IndexedTestTypeName<Types>{}(index), Tags } ), index++)... };/* NOLINT */ \
326328
}\
327329
};\
328330
static int INTERNAL_CATCH_UNIQUE_NAME( globalRegistrar ) = [](){\
@@ -339,5 +341,13 @@
339341
#define INTERNAL_CATCH_TEMPLATE_LIST_TEST_CASE_METHOD(ClassName, Name, Tags, TmplList) \
340342
INTERNAL_CATCH_TEMPLATE_LIST_TEST_CASE_METHOD_2( INTERNAL_CATCH_UNIQUE_NAME( CATCH2_INTERNAL_TEMPLATE_TEST_ ), INTERNAL_CATCH_UNIQUE_NAME( CATCH2_INTERNAL_TEMPLATE_TEST_ ), ClassName, Name, Tags, TmplList )
341343

344+
namespace Catch {
345+
template <typename T>
346+
struct IndexedTestTypeName {
347+
std::string operator()(size_t index) const {
348+
return std::to_string(index);
349+
}
350+
};
351+
}
342352

343353
#endif // CATCH_TEMPLATE_TEST_REGISTRY_HPP_INCLUDED

tests/SelfTest/Baselines/automake.sw.approved.txt

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -258,6 +258,9 @@ Message from section two
258258
:test-result: FAIL Tabs and newlines show in output
259259
:test-result: PASS Tag alias can be registered against tag patterns
260260
:test-result: PASS Tags with spaces and non-alphanumerical characters are accepted
261+
:test-result: PASS Template list test case with specialized IndexedTestTypeName--NamedTypes--A
262+
:test-result: PASS Template list test case with specialized IndexedTestTypeName--NamedTypes--B
263+
:test-result: PASS Template list test case with specialized IndexedTestTypeName--NamedTypes--C
261264
:test-result: PASS Template test case method with test types specified inside std::tuple - MyTypes - 0
262265
:test-result: PASS Template test case method with test types specified inside std::tuple - MyTypes - 1
263266
:test-result: PASS Template test case method with test types specified inside std::tuple - MyTypes - 2

tests/SelfTest/Baselines/automake.sw.multi.approved.txt

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -251,6 +251,9 @@
251251
:test-result: FAIL Tabs and newlines show in output
252252
:test-result: PASS Tag alias can be registered against tag patterns
253253
:test-result: PASS Tags with spaces and non-alphanumerical characters are accepted
254+
:test-result: PASS Template list test case with specialized IndexedTestTypeName--NamedTypes--A
255+
:test-result: PASS Template list test case with specialized IndexedTestTypeName--NamedTypes--B
256+
:test-result: PASS Template list test case with specialized IndexedTestTypeName--NamedTypes--C
254257
:test-result: PASS Template test case method with test types specified inside std::tuple - MyTypes - 0
255258
:test-result: PASS Template test case method with test types specified inside std::tuple - MyTypes - 1
256259
:test-result: PASS Template test case method with test types specified inside std::tuple - MyTypes - 2

tests/SelfTest/Baselines/compact.sw.approved.txt

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1744,6 +1744,9 @@ Tag.tests.cpp:<line number>: passed: registry.add( "@no square bracket at start]
17441744
Tag.tests.cpp:<line number>: passed: registry.add( "[@no square bracket at end", "", Catch::SourceLineInfo( "file", 3 ) )
17451745
Tag.tests.cpp:<line number>: passed: testCase.tags.size() == 2 for: 2 == 2
17461746
Tag.tests.cpp:<line number>: passed: testCase.tags, VectorContains( Tag( "tag with spaces" ) ) && VectorContains( Tag( "I said \"good day\" sir!"_catch_sr ) ) for: { {?}, {?} } ( Contains: {?} and Contains: {?} )
1747+
CustomNaming.tests.cpp:<line number>: passed: Template_Foo<TestType>{}.size() == 0 for: 0 == 0
1748+
CustomNaming.tests.cpp:<line number>: passed: Template_Foo<TestType>{}.size() == 0 for: 0 == 0
1749+
CustomNaming.tests.cpp:<line number>: passed: Template_Foo<TestType>{}.size() == 0 for: 0 == 0
17471750
Class.tests.cpp:<line number>: passed: Template_Fixture<TestType>::m_a == 1 for: 1 == 1
17481751
Class.tests.cpp:<line number>: passed: Template_Fixture<TestType>::m_a == 1 for: 1 == 1
17491752
Class.tests.cpp:<line number>: passed: Template_Fixture<TestType>::m_a == 1 for: 1.0 == 1
@@ -2700,7 +2703,7 @@ InternalBenchmark.tests.cpp:<line number>: passed: med == 18. for: 18.0 == 18.0
27002703
InternalBenchmark.tests.cpp:<line number>: passed: q3 == 23. for: 23.0 == 23.0
27012704
Misc.tests.cpp:<line number>: passed:
27022705
Misc.tests.cpp:<line number>: passed:
2703-
test cases: 432 | 327 passed | 85 failed | 6 skipped | 14 failed as expected
2704-
assertions: 2271 | 2090 passed | 146 failed | 35 failed as expected
2706+
test cases: 435 | 330 passed | 85 failed | 6 skipped | 14 failed as expected
2707+
assertions: 2274 | 2093 passed | 146 failed | 35 failed as expected
27052708

27062709

tests/SelfTest/Baselines/compact.sw.multi.approved.txt

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1737,6 +1737,9 @@ Tag.tests.cpp:<line number>: passed: registry.add( "@no square bracket at start]
17371737
Tag.tests.cpp:<line number>: passed: registry.add( "[@no square bracket at end", "", Catch::SourceLineInfo( "file", 3 ) )
17381738
Tag.tests.cpp:<line number>: passed: testCase.tags.size() == 2 for: 2 == 2
17391739
Tag.tests.cpp:<line number>: passed: testCase.tags, VectorContains( Tag( "tag with spaces" ) ) && VectorContains( Tag( "I said \"good day\" sir!"_catch_sr ) ) for: { {?}, {?} } ( Contains: {?} and Contains: {?} )
1740+
CustomNaming.tests.cpp:<line number>: passed: Template_Foo<TestType>{}.size() == 0 for: 0 == 0
1741+
CustomNaming.tests.cpp:<line number>: passed: Template_Foo<TestType>{}.size() == 0 for: 0 == 0
1742+
CustomNaming.tests.cpp:<line number>: passed: Template_Foo<TestType>{}.size() == 0 for: 0 == 0
17401743
Class.tests.cpp:<line number>: passed: Template_Fixture<TestType>::m_a == 1 for: 1 == 1
17411744
Class.tests.cpp:<line number>: passed: Template_Fixture<TestType>::m_a == 1 for: 1 == 1
17421745
Class.tests.cpp:<line number>: passed: Template_Fixture<TestType>::m_a == 1 for: 1.0 == 1
@@ -2689,7 +2692,7 @@ InternalBenchmark.tests.cpp:<line number>: passed: med == 18. for: 18.0 == 18.0
26892692
InternalBenchmark.tests.cpp:<line number>: passed: q3 == 23. for: 23.0 == 23.0
26902693
Misc.tests.cpp:<line number>: passed:
26912694
Misc.tests.cpp:<line number>: passed:
2692-
test cases: 432 | 327 passed | 85 failed | 6 skipped | 14 failed as expected
2693-
assertions: 2271 | 2090 passed | 146 failed | 35 failed as expected
2695+
test cases: 435 | 330 passed | 85 failed | 6 skipped | 14 failed as expected
2696+
assertions: 2274 | 2093 passed | 146 failed | 35 failed as expected
26942697

26952698

tests/SelfTest/Baselines/console.std.approved.txt

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1588,6 +1588,6 @@ due to unexpected exception with message:
15881588
Why would you throw a std::string?
15891589

15901590
===============================================================================
1591-
test cases: 432 | 341 passed | 70 failed | 7 skipped | 14 failed as expected
1592-
assertions: 2254 | 2090 passed | 129 failed | 35 failed as expected
1591+
test cases: 435 | 344 passed | 70 failed | 7 skipped | 14 failed as expected
1592+
assertions: 2257 | 2093 passed | 129 failed | 35 failed as expected
15931593

tests/SelfTest/Baselines/console.sw.approved.txt

Lines changed: 35 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -11749,6 +11749,39 @@ Tag.tests.cpp:<line number>: PASSED:
1174911749
with expansion:
1175011750
{ {?}, {?} } ( Contains: {?} and Contains: {?} )
1175111751

11752+
-------------------------------------------------------------------------------
11753+
Template list test case with specialized IndexedTestTypeName--NamedTypes--A
11754+
-------------------------------------------------------------------------------
11755+
CustomNaming.tests.cpp:<line number>
11756+
...............................................................................
11757+
11758+
CustomNaming.tests.cpp:<line number>: PASSED:
11759+
REQUIRE( Template_Foo<TestType>{}.size() == 0 )
11760+
with expansion:
11761+
0 == 0
11762+
11763+
-------------------------------------------------------------------------------
11764+
Template list test case with specialized IndexedTestTypeName--NamedTypes--B
11765+
-------------------------------------------------------------------------------
11766+
CustomNaming.tests.cpp:<line number>
11767+
...............................................................................
11768+
11769+
CustomNaming.tests.cpp:<line number>: PASSED:
11770+
REQUIRE( Template_Foo<TestType>{}.size() == 0 )
11771+
with expansion:
11772+
0 == 0
11773+
11774+
-------------------------------------------------------------------------------
11775+
Template list test case with specialized IndexedTestTypeName--NamedTypes--C
11776+
-------------------------------------------------------------------------------
11777+
CustomNaming.tests.cpp:<line number>
11778+
...............................................................................
11779+
11780+
CustomNaming.tests.cpp:<line number>: PASSED:
11781+
REQUIRE( Template_Foo<TestType>{}.size() == 0 )
11782+
with expansion:
11783+
0 == 0
11784+
1175211785
-------------------------------------------------------------------------------
1175311786
Template test case method with test types specified inside std::tuple - MyTypes
1175411787
- 0
@@ -18889,6 +18922,6 @@ Misc.tests.cpp:<line number>
1888918922
Misc.tests.cpp:<line number>: PASSED:
1889018923

1889118924
===============================================================================
18892-
test cases: 432 | 327 passed | 85 failed | 6 skipped | 14 failed as expected
18893-
assertions: 2271 | 2090 passed | 146 failed | 35 failed as expected
18925+
test cases: 435 | 330 passed | 85 failed | 6 skipped | 14 failed as expected
18926+
assertions: 2274 | 2093 passed | 146 failed | 35 failed as expected
1889418927

tests/SelfTest/Baselines/console.sw.multi.approved.txt

Lines changed: 35 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -11742,6 +11742,39 @@ Tag.tests.cpp:<line number>: PASSED:
1174211742
with expansion:
1174311743
{ {?}, {?} } ( Contains: {?} and Contains: {?} )
1174411744

11745+
-------------------------------------------------------------------------------
11746+
Template list test case with specialized IndexedTestTypeName--NamedTypes--A
11747+
-------------------------------------------------------------------------------
11748+
CustomNaming.tests.cpp:<line number>
11749+
...............................................................................
11750+
11751+
CustomNaming.tests.cpp:<line number>: PASSED:
11752+
REQUIRE( Template_Foo<TestType>{}.size() == 0 )
11753+
with expansion:
11754+
0 == 0
11755+
11756+
-------------------------------------------------------------------------------
11757+
Template list test case with specialized IndexedTestTypeName--NamedTypes--B
11758+
-------------------------------------------------------------------------------
11759+
CustomNaming.tests.cpp:<line number>
11760+
...............................................................................
11761+
11762+
CustomNaming.tests.cpp:<line number>: PASSED:
11763+
REQUIRE( Template_Foo<TestType>{}.size() == 0 )
11764+
with expansion:
11765+
0 == 0
11766+
11767+
-------------------------------------------------------------------------------
11768+
Template list test case with specialized IndexedTestTypeName--NamedTypes--C
11769+
-------------------------------------------------------------------------------
11770+
CustomNaming.tests.cpp:<line number>
11771+
...............................................................................
11772+
11773+
CustomNaming.tests.cpp:<line number>: PASSED:
11774+
REQUIRE( Template_Foo<TestType>{}.size() == 0 )
11775+
with expansion:
11776+
0 == 0
11777+
1174511778
-------------------------------------------------------------------------------
1174611779
Template test case method with test types specified inside std::tuple - MyTypes
1174711780
- 0
@@ -18878,6 +18911,6 @@ Misc.tests.cpp:<line number>
1887818911
Misc.tests.cpp:<line number>: PASSED:
1887918912

1888018913
===============================================================================
18881-
test cases: 432 | 327 passed | 85 failed | 6 skipped | 14 failed as expected
18882-
assertions: 2271 | 2090 passed | 146 failed | 35 failed as expected
18914+
test cases: 435 | 330 passed | 85 failed | 6 skipped | 14 failed as expected
18915+
assertions: 2274 | 2093 passed | 146 failed | 35 failed as expected
1888318916

tests/SelfTest/Baselines/junit.sw.approved.txt

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
<?xml version="1.0" encoding="UTF-8"?>
22
<testsuitesloose text artifact
33
>
4-
<testsuite name="<exe-name>" errors="17" failures="129" skipped="12" tests="2283" hostname="tbd" time="{duration}" timestamp="{iso8601-timestamp}">
4+
<testsuite name="<exe-name>" errors="17" failures="129" skipped="12" tests="2286" hostname="tbd" time="{duration}" timestamp="{iso8601-timestamp}">
55
<properties>
66
<property name="random-seed" value="1"/>
77
<property name="filters" value="&quot;*&quot; ~[!nonportable] ~[!benchmark] ~[approvals]"/>
@@ -1336,6 +1336,9 @@ at Misc.tests.cpp:<line number>
13361336
<testcase classname="<exe-name>.global" name="Tag alias can be registered against tag patterns/The same tag alias can only be registered once" time="{duration}" status="run"/>
13371337
<testcase classname="<exe-name>.global" name="Tag alias can be registered against tag patterns/Tag aliases must be of the form [@name]" time="{duration}" status="run"/>
13381338
<testcase classname="<exe-name>.global" name="Tags with spaces and non-alphanumerical characters are accepted" time="{duration}" status="run"/>
1339+
<testcase classname="<exe-name>.Template_Foo" name="Template list test case with specialized IndexedTestTypeName--NamedTypes--A" time="{duration}" status="run"/>
1340+
<testcase classname="<exe-name>.Template_Foo" name="Template list test case with specialized IndexedTestTypeName--NamedTypes--B" time="{duration}" status="run"/>
1341+
<testcase classname="<exe-name>.Template_Foo" name="Template list test case with specialized IndexedTestTypeName--NamedTypes--C" time="{duration}" status="run"/>
13391342
<testcase classname="<exe-name>.Template_Fixture" name="Template test case method with test types specified inside std::tuple - MyTypes - 0" time="{duration}" status="run"/>
13401343
<testcase classname="<exe-name>.Template_Fixture" name="Template test case method with test types specified inside std::tuple - MyTypes - 1" time="{duration}" status="run"/>
13411344
<testcase classname="<exe-name>.Template_Fixture" name="Template test case method with test types specified inside std::tuple - MyTypes - 2" time="{duration}" status="run"/>

tests/SelfTest/Baselines/junit.sw.multi.approved.txt

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
<?xml version="1.0" encoding="UTF-8"?>
22
<testsuites>
3-
<testsuite name="<exe-name>" errors="17" failures="129" skipped="12" tests="2283" hostname="tbd" time="{duration}" timestamp="{iso8601-timestamp}">
3+
<testsuite name="<exe-name>" errors="17" failures="129" skipped="12" tests="2286" hostname="tbd" time="{duration}" timestamp="{iso8601-timestamp}">
44
<properties>
55
<property name="random-seed" value="1"/>
66
<property name="filters" value="&quot;*&quot; ~[!nonportable] ~[!benchmark] ~[approvals]"/>
@@ -1335,6 +1335,9 @@ at Misc.tests.cpp:<line number>
13351335
<testcase classname="<exe-name>.global" name="Tag alias can be registered against tag patterns/The same tag alias can only be registered once" time="{duration}" status="run"/>
13361336
<testcase classname="<exe-name>.global" name="Tag alias can be registered against tag patterns/Tag aliases must be of the form [@name]" time="{duration}" status="run"/>
13371337
<testcase classname="<exe-name>.global" name="Tags with spaces and non-alphanumerical characters are accepted" time="{duration}" status="run"/>
1338+
<testcase classname="<exe-name>.Template_Foo" name="Template list test case with specialized IndexedTestTypeName--NamedTypes--A" time="{duration}" status="run"/>
1339+
<testcase classname="<exe-name>.Template_Foo" name="Template list test case with specialized IndexedTestTypeName--NamedTypes--B" time="{duration}" status="run"/>
1340+
<testcase classname="<exe-name>.Template_Foo" name="Template list test case with specialized IndexedTestTypeName--NamedTypes--C" time="{duration}" status="run"/>
13381341
<testcase classname="<exe-name>.Template_Fixture" name="Template test case method with test types specified inside std::tuple - MyTypes - 0" time="{duration}" status="run"/>
13391342
<testcase classname="<exe-name>.Template_Fixture" name="Template test case method with test types specified inside std::tuple - MyTypes - 1" time="{duration}" status="run"/>
13401343
<testcase classname="<exe-name>.Template_Fixture" name="Template test case method with test types specified inside std::tuple - MyTypes - 2" time="{duration}" status="run"/>

tests/SelfTest/Baselines/sonarqube.sw.approved.txt

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -904,6 +904,9 @@ at Condition.tests.cpp:<line number>
904904
<testCase name="A TEMPLATE_TEST_CASE_METHOD_SIG based test with a custom separator--1" duration="{duration}"/>
905905
<testCase name="A TEMPLATE_TEST_CASE_METHOD_SIG based test with a custom separator--3" duration="{duration}"/>
906906
<testCase name="A TEMPLATE_TEST_CASE_METHOD_SIG based test with a custom separator--6" duration="{duration}"/>
907+
<testCase name="Template list test case with specialized IndexedTestTypeName--NamedTypes--A" duration="{duration}"/>
908+
<testCase name="Template list test case with specialized IndexedTestTypeName--NamedTypes--B" duration="{duration}"/>
909+
<testCase name="Template list test case with specialized IndexedTestTypeName--NamedTypes--C" duration="{duration}"/>
907910
<testCase name="Template test case method with test types specified inside std::tuple with a custom separator--MyTypes--0" duration="{duration}"/>
908911
<testCase name="Template test case method with test types specified inside std::tuple with a custom separator--MyTypes--1" duration="{duration}"/>
909912
<testCase name="Template test case method with test types specified inside std::tuple with a custom separator--MyTypes--2" duration="{duration}"/>

tests/SelfTest/Baselines/sonarqube.sw.multi.approved.txt

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -903,6 +903,9 @@ at Condition.tests.cpp:<line number>
903903
<testCase name="A TEMPLATE_TEST_CASE_METHOD_SIG based test with a custom separator--1" duration="{duration}"/>
904904
<testCase name="A TEMPLATE_TEST_CASE_METHOD_SIG based test with a custom separator--3" duration="{duration}"/>
905905
<testCase name="A TEMPLATE_TEST_CASE_METHOD_SIG based test with a custom separator--6" duration="{duration}"/>
906+
<testCase name="Template list test case with specialized IndexedTestTypeName--NamedTypes--A" duration="{duration}"/>
907+
<testCase name="Template list test case with specialized IndexedTestTypeName--NamedTypes--B" duration="{duration}"/>
908+
<testCase name="Template list test case with specialized IndexedTestTypeName--NamedTypes--C" duration="{duration}"/>
906909
<testCase name="Template test case method with test types specified inside std::tuple with a custom separator--MyTypes--0" duration="{duration}"/>
907910
<testCase name="Template test case method with test types specified inside std::tuple with a custom separator--MyTypes--1" duration="{duration}"/>
908911
<testCase name="Template test case method with test types specified inside std::tuple with a custom separator--MyTypes--2" duration="{duration}"/>

0 commit comments

Comments
 (0)