Skip to content

Commit df90ea3

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 c18b88f commit df90ea3

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
@@ -259,6 +259,9 @@ Message from section two
259259
:test-result: FAIL Tabs and newlines show in output
260260
:test-result: PASS Tag alias can be registered against tag patterns
261261
:test-result: PASS Tags with spaces and non-alphanumerical characters are accepted
262+
:test-result: PASS Template list test case with specialized IndexedTestTypeName--NamedTypes--A
263+
:test-result: PASS Template list test case with specialized IndexedTestTypeName--NamedTypes--B
264+
:test-result: PASS Template list test case with specialized IndexedTestTypeName--NamedTypes--C
262265
:test-result: PASS Template test case method with test types specified inside std::tuple - MyTypes - 0
263266
:test-result: PASS Template test case method with test types specified inside std::tuple - MyTypes - 1
264267
: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
@@ -252,6 +252,9 @@
252252
:test-result: FAIL Tabs and newlines show in output
253253
:test-result: PASS Tag alias can be registered against tag patterns
254254
:test-result: PASS Tags with spaces and non-alphanumerical characters are accepted
255+
:test-result: PASS Template list test case with specialized IndexedTestTypeName--NamedTypes--A
256+
:test-result: PASS Template list test case with specialized IndexedTestTypeName--NamedTypes--B
257+
:test-result: PASS Template list test case with specialized IndexedTestTypeName--NamedTypes--C
255258
:test-result: PASS Template test case method with test types specified inside std::tuple - MyTypes - 0
256259
:test-result: PASS Template test case method with test types specified inside std::tuple - MyTypes - 1
257260
: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
@@ -1748,6 +1748,9 @@ Tag.tests.cpp:<line number>: passed: registry.add( "@no square bracket at start]
17481748
Tag.tests.cpp:<line number>: passed: registry.add( "[@no square bracket at end", "", Catch::SourceLineInfo( "file", 3 ) )
17491749
Tag.tests.cpp:<line number>: passed: testCase.tags.size() == 2 for: 2 == 2
17501750
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: {?} )
1751+
CustomNaming.tests.cpp:<line number>: passed: Template_Foo<TestType>{}.size() == 0 for: 0 == 0
1752+
CustomNaming.tests.cpp:<line number>: passed: Template_Foo<TestType>{}.size() == 0 for: 0 == 0
1753+
CustomNaming.tests.cpp:<line number>: passed: Template_Foo<TestType>{}.size() == 0 for: 0 == 0
17511754
Class.tests.cpp:<line number>: passed: Template_Fixture<TestType>::m_a == 1 for: 1 == 1
17521755
Class.tests.cpp:<line number>: passed: Template_Fixture<TestType>::m_a == 1 for: 1 == 1
17531756
Class.tests.cpp:<line number>: passed: Template_Fixture<TestType>::m_a == 1 for: 1.0 == 1
@@ -2706,7 +2709,7 @@ InternalBenchmark.tests.cpp:<line number>: passed: med == 18. for: 18.0 == 18.0
27062709
InternalBenchmark.tests.cpp:<line number>: passed: q3 == 23. for: 23.0 == 23.0
27072710
Misc.tests.cpp:<line number>: passed:
27082711
Misc.tests.cpp:<line number>: passed:
2709-
test cases: 434 | 329 passed | 85 failed | 6 skipped | 14 failed as expected
2710-
assertions: 2277 | 2096 passed | 146 failed | 35 failed as expected
2712+
test cases: 437 | 332 passed | 85 failed | 6 skipped | 14 failed as expected
2713+
assertions: 2280 | 2099 passed | 146 failed | 35 failed as expected
27112714

27122715

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

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1741,6 +1741,9 @@ Tag.tests.cpp:<line number>: passed: registry.add( "@no square bracket at start]
17411741
Tag.tests.cpp:<line number>: passed: registry.add( "[@no square bracket at end", "", Catch::SourceLineInfo( "file", 3 ) )
17421742
Tag.tests.cpp:<line number>: passed: testCase.tags.size() == 2 for: 2 == 2
17431743
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: {?} )
1744+
CustomNaming.tests.cpp:<line number>: passed: Template_Foo<TestType>{}.size() == 0 for: 0 == 0
1745+
CustomNaming.tests.cpp:<line number>: passed: Template_Foo<TestType>{}.size() == 0 for: 0 == 0
1746+
CustomNaming.tests.cpp:<line number>: passed: Template_Foo<TestType>{}.size() == 0 for: 0 == 0
17441747
Class.tests.cpp:<line number>: passed: Template_Fixture<TestType>::m_a == 1 for: 1 == 1
17451748
Class.tests.cpp:<line number>: passed: Template_Fixture<TestType>::m_a == 1 for: 1 == 1
17461749
Class.tests.cpp:<line number>: passed: Template_Fixture<TestType>::m_a == 1 for: 1.0 == 1
@@ -2695,7 +2698,7 @@ InternalBenchmark.tests.cpp:<line number>: passed: med == 18. for: 18.0 == 18.0
26952698
InternalBenchmark.tests.cpp:<line number>: passed: q3 == 23. for: 23.0 == 23.0
26962699
Misc.tests.cpp:<line number>: passed:
26972700
Misc.tests.cpp:<line number>: passed:
2698-
test cases: 434 | 329 passed | 85 failed | 6 skipped | 14 failed as expected
2699-
assertions: 2277 | 2096 passed | 146 failed | 35 failed as expected
2701+
test cases: 437 | 332 passed | 85 failed | 6 skipped | 14 failed as expected
2702+
assertions: 2280 | 2099 passed | 146 failed | 35 failed as expected
27002703

27012704

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: 434 | 343 passed | 70 failed | 7 skipped | 14 failed as expected
1592-
assertions: 2260 | 2096 passed | 129 failed | 35 failed as expected
1591+
test cases: 437 | 346 passed | 70 failed | 7 skipped | 14 failed as expected
1592+
assertions: 2263 | 2099 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
@@ -11793,6 +11793,39 @@ Tag.tests.cpp:<line number>: PASSED:
1179311793
with expansion:
1179411794
{ {?}, {?} } ( Contains: {?} and Contains: {?} )
1179511795

11796+
-------------------------------------------------------------------------------
11797+
Template list test case with specialized IndexedTestTypeName--NamedTypes--A
11798+
-------------------------------------------------------------------------------
11799+
CustomNaming.tests.cpp:<line number>
11800+
...............................................................................
11801+
11802+
CustomNaming.tests.cpp:<line number>: PASSED:
11803+
REQUIRE( Template_Foo<TestType>{}.size() == 0 )
11804+
with expansion:
11805+
0 == 0
11806+
11807+
-------------------------------------------------------------------------------
11808+
Template list test case with specialized IndexedTestTypeName--NamedTypes--B
11809+
-------------------------------------------------------------------------------
11810+
CustomNaming.tests.cpp:<line number>
11811+
...............................................................................
11812+
11813+
CustomNaming.tests.cpp:<line number>: PASSED:
11814+
REQUIRE( Template_Foo<TestType>{}.size() == 0 )
11815+
with expansion:
11816+
0 == 0
11817+
11818+
-------------------------------------------------------------------------------
11819+
Template list test case with specialized IndexedTestTypeName--NamedTypes--C
11820+
-------------------------------------------------------------------------------
11821+
CustomNaming.tests.cpp:<line number>
11822+
...............................................................................
11823+
11824+
CustomNaming.tests.cpp:<line number>: PASSED:
11825+
REQUIRE( Template_Foo<TestType>{}.size() == 0 )
11826+
with expansion:
11827+
0 == 0
11828+
1179611829
-------------------------------------------------------------------------------
1179711830
Template test case method with test types specified inside std::tuple - MyTypes
1179811831
- 0
@@ -18949,6 +18982,6 @@ Misc.tests.cpp:<line number>
1894918982
Misc.tests.cpp:<line number>: PASSED:
1895018983

1895118984
===============================================================================
18952-
test cases: 434 | 329 passed | 85 failed | 6 skipped | 14 failed as expected
18953-
assertions: 2277 | 2096 passed | 146 failed | 35 failed as expected
18985+
test cases: 437 | 332 passed | 85 failed | 6 skipped | 14 failed as expected
18986+
assertions: 2280 | 2099 passed | 146 failed | 35 failed as expected
1895418987

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

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

11789+
-------------------------------------------------------------------------------
11790+
Template list test case with specialized IndexedTestTypeName--NamedTypes--A
11791+
-------------------------------------------------------------------------------
11792+
CustomNaming.tests.cpp:<line number>
11793+
...............................................................................
11794+
11795+
CustomNaming.tests.cpp:<line number>: PASSED:
11796+
REQUIRE( Template_Foo<TestType>{}.size() == 0 )
11797+
with expansion:
11798+
0 == 0
11799+
11800+
-------------------------------------------------------------------------------
11801+
Template list test case with specialized IndexedTestTypeName--NamedTypes--B
11802+
-------------------------------------------------------------------------------
11803+
CustomNaming.tests.cpp:<line number>
11804+
...............................................................................
11805+
11806+
CustomNaming.tests.cpp:<line number>: PASSED:
11807+
REQUIRE( Template_Foo<TestType>{}.size() == 0 )
11808+
with expansion:
11809+
0 == 0
11810+
11811+
-------------------------------------------------------------------------------
11812+
Template list test case with specialized IndexedTestTypeName--NamedTypes--C
11813+
-------------------------------------------------------------------------------
11814+
CustomNaming.tests.cpp:<line number>
11815+
...............................................................................
11816+
11817+
CustomNaming.tests.cpp:<line number>: PASSED:
11818+
REQUIRE( Template_Foo<TestType>{}.size() == 0 )
11819+
with expansion:
11820+
0 == 0
11821+
1178911822
-------------------------------------------------------------------------------
1179011823
Template test case method with test types specified inside std::tuple - MyTypes
1179111824
- 0
@@ -18938,6 +18971,6 @@ Misc.tests.cpp:<line number>
1893818971
Misc.tests.cpp:<line number>: PASSED:
1893918972

1894018973
===============================================================================
18941-
test cases: 434 | 329 passed | 85 failed | 6 skipped | 14 failed as expected
18942-
assertions: 2277 | 2096 passed | 146 failed | 35 failed as expected
18974+
test cases: 437 | 332 passed | 85 failed | 6 skipped | 14 failed as expected
18975+
assertions: 2280 | 2099 passed | 146 failed | 35 failed as expected
1894318976

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="2289" hostname="tbd" time="{duration}" timestamp="{iso8601-timestamp}">
4+
<testsuite name="<exe-name>" errors="17" failures="129" skipped="12" tests="2292" 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]"/>
@@ -1337,6 +1337,9 @@ at Misc.tests.cpp:<line number>
13371337
<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"/>
13381338
<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"/>
13391339
<testcase classname="<exe-name>.global" name="Tags with spaces and non-alphanumerical characters are accepted" time="{duration}" status="run"/>
1340+
<testcase classname="<exe-name>.Template_Foo" name="Template list test case with specialized IndexedTestTypeName--NamedTypes--A" time="{duration}" status="run"/>
1341+
<testcase classname="<exe-name>.Template_Foo" name="Template list test case with specialized IndexedTestTypeName--NamedTypes--B" time="{duration}" status="run"/>
1342+
<testcase classname="<exe-name>.Template_Foo" name="Template list test case with specialized IndexedTestTypeName--NamedTypes--C" time="{duration}" status="run"/>
13401343
<testcase classname="<exe-name>.Template_Fixture" name="Template test case method with test types specified inside std::tuple - MyTypes - 0" time="{duration}" status="run"/>
13411344
<testcase classname="<exe-name>.Template_Fixture" name="Template test case method with test types specified inside std::tuple - MyTypes - 1" time="{duration}" status="run"/>
13421345
<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="2289" hostname="tbd" time="{duration}" timestamp="{iso8601-timestamp}">
3+
<testsuite name="<exe-name>" errors="17" failures="129" skipped="12" tests="2292" 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]"/>
@@ -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/sonarqube.sw.approved.txt

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

0 commit comments

Comments
 (0)