Fix non-default-constructible type lists used in TEMPLATE_LIST_TEST_CASE (#1697)

* Fix non-default-constructible type lists used in TEMPLATE_LIST_TEST_CASE

std::tuple is not default constructible when the first type is not
default-constuctible. Therefore it can not be instantiated.
to circumvent this, we have to use std::declval in the unevaluate decltype
context.
This commit is contained in:
Benjamin Worpitz 2019-07-22 12:56:33 +02:00 committed by Martin Hořeňovský
parent a22b7df46c
commit e7c26f09d1
7 changed files with 94 additions and 9 deletions

View File

@ -247,7 +247,7 @@ struct AutoReg : NonCopyable {
} \ } \
};\ };\
static int INTERNAL_CATCH_UNIQUE_NAME( globalRegistrar ) = [](){ \ static int INTERNAL_CATCH_UNIQUE_NAME( globalRegistrar ) = [](){ \
using TestInit = decltype(convert<TestName>(TmplList {})); \ using TestInit = decltype(convert<TestName>(std::declval<TmplList>())); \
TestInit t; \ TestInit t; \
t.reg_tests(); \ t.reg_tests(); \
return 0; \ return 0; \
@ -374,7 +374,7 @@ struct AutoReg : NonCopyable {
}\ }\
};\ };\
static int INTERNAL_CATCH_UNIQUE_NAME( globalRegistrar ) = [](){\ static int INTERNAL_CATCH_UNIQUE_NAME( globalRegistrar ) = [](){\
using TestInit = decltype(convert<TestNameClass>(TmplList {}));\ using TestInit = decltype(convert<TestNameClass>(std::declval<TmplList>()));\
TestInit t;\ TestInit t;\
t.reg_tests();\ t.reg_tests();\
return 0;\ return 0;\

View File

@ -1084,6 +1084,9 @@ Tag.tests.cpp:<line number>: passed: registry.add( "[@no square bracket at end",
Class.tests.cpp:<line number>: passed: Template_Fixture<TestType>::m_a == 1 for: 1 == 1 Class.tests.cpp:<line number>: passed: Template_Fixture<TestType>::m_a == 1 for: 1 == 1
Class.tests.cpp:<line number>: passed: Template_Fixture<TestType>::m_a == 1 for: 1 == 1 Class.tests.cpp:<line number>: passed: Template_Fixture<TestType>::m_a == 1 for: 1 == 1
Class.tests.cpp:<line number>: passed: Template_Fixture<TestType>::m_a == 1 for: 1.0 == 1 Class.tests.cpp:<line number>: passed: Template_Fixture<TestType>::m_a == 1 for: 1.0 == 1
Misc.tests.cpp:<line number>: passed: sizeof(TestType) > 0 for: 1 > 0
Misc.tests.cpp:<line number>: passed: sizeof(TestType) > 0 for: 1 > 0
Misc.tests.cpp:<line number>: passed: sizeof(TestType) > 0 for: 4 > 0
Misc.tests.cpp:<line number>: passed: sizeof(TestType) > 0 for: 4 > 0 Misc.tests.cpp:<line number>: passed: sizeof(TestType) > 0 for: 4 > 0
Misc.tests.cpp:<line number>: passed: sizeof(TestType) > 0 for: 1 > 0 Misc.tests.cpp:<line number>: passed: sizeof(TestType) > 0 for: 1 > 0
Misc.tests.cpp:<line number>: passed: sizeof(TestType) > 0 for: 4 > 0 Misc.tests.cpp:<line number>: passed: sizeof(TestType) > 0 for: 4 > 0

View File

@ -1380,6 +1380,6 @@ due to unexpected exception with message:
Why would you throw a std::string? Why would you throw a std::string?
=============================================================================== ===============================================================================
test cases: 295 | 221 passed | 70 failed | 4 failed as expected test cases: 298 | 224 passed | 70 failed | 4 failed as expected
assertions: 1550 | 1398 passed | 131 failed | 21 failed as expected assertions: 1553 | 1401 passed | 131 failed | 21 failed as expected

View File

@ -8022,6 +8022,42 @@ Class.tests.cpp:<line number>: PASSED:
with expansion: with expansion:
1.0 == 1 1.0 == 1
-------------------------------------------------------------------------------
Template test case with test types specified inside non-default-constructible
std::tuple - MyNonDefaultConstructibleTypes - 0
-------------------------------------------------------------------------------
Misc.tests.cpp:<line number>
...............................................................................
Misc.tests.cpp:<line number>: PASSED:
REQUIRE( sizeof(TestType) > 0 )
with expansion:
1 > 0
-------------------------------------------------------------------------------
Template test case with test types specified inside non-default-constructible
std::tuple - MyNonDefaultConstructibleTypes - 1
-------------------------------------------------------------------------------
Misc.tests.cpp:<line number>
...............................................................................
Misc.tests.cpp:<line number>: PASSED:
REQUIRE( sizeof(TestType) > 0 )
with expansion:
1 > 0
-------------------------------------------------------------------------------
Template test case with test types specified inside non-default-constructible
std::tuple - MyNonDefaultConstructibleTypes - 2
-------------------------------------------------------------------------------
Misc.tests.cpp:<line number>
...............................................................................
Misc.tests.cpp:<line number>: PASSED:
REQUIRE( sizeof(TestType) > 0 )
with expansion:
4 > 0
------------------------------------------------------------------------------- -------------------------------------------------------------------------------
Template test case with test types specified inside std::tuple - MyTypes - 0 Template test case with test types specified inside std::tuple - MyTypes - 0
------------------------------------------------------------------------------- -------------------------------------------------------------------------------
@ -12373,6 +12409,6 @@ Misc.tests.cpp:<line number>
Misc.tests.cpp:<line number>: PASSED: Misc.tests.cpp:<line number>: PASSED:
=============================================================================== ===============================================================================
test cases: 295 | 205 passed | 86 failed | 4 failed as expected test cases: 298 | 208 passed | 86 failed | 4 failed as expected
assertions: 1567 | 1398 passed | 148 failed | 21 failed as expected assertions: 1570 | 1401 passed | 148 failed | 21 failed as expected

View File

@ -1,7 +1,7 @@
<?xml version="1.0" encoding="UTF-8"?> <?xml version="1.0" encoding="UTF-8"?>
<testsuitesloose text artifact <testsuitesloose text artifact
> >
<testsuite name="<exe-name>" errors="17" failures="132" tests="1568" hostname="tbd" time="{duration}" timestamp="{iso8601-timestamp}"> <testsuite name="<exe-name>" errors="17" failures="132" tests="1571" hostname="tbd" time="{duration}" timestamp="{iso8601-timestamp}">
<properties> <properties>
<property name="filters" value="~[!nonportable]~[!benchmark]~[approvals]"/> <property name="filters" value="~[!nonportable]~[!benchmark]~[approvals]"/>
<property name="random-seed" value="1"/> <property name="random-seed" value="1"/>
@ -750,6 +750,9 @@ Misc.tests.cpp:<line number>
<testcase classname="<exe-name>.Template_Fixture" name="Template test case method with test types specified inside std::tuple - MyTypes - 0" time="{duration}"/> <testcase classname="<exe-name>.Template_Fixture" name="Template test case method with test types specified inside std::tuple - MyTypes - 0" time="{duration}"/>
<testcase classname="<exe-name>.Template_Fixture" name="Template test case method with test types specified inside std::tuple - MyTypes - 1" time="{duration}"/> <testcase classname="<exe-name>.Template_Fixture" name="Template test case method with test types specified inside std::tuple - MyTypes - 1" time="{duration}"/>
<testcase classname="<exe-name>.Template_Fixture" name="Template test case method with test types specified inside std::tuple - MyTypes - 2" time="{duration}"/> <testcase classname="<exe-name>.Template_Fixture" name="Template test case method with test types specified inside std::tuple - MyTypes - 2" time="{duration}"/>
<testcase classname="<exe-name>.global" name="Template test case with test types specified inside non-default-constructible std::tuple - MyNonDefaultConstructibleTypes - 0" time="{duration}"/>
<testcase classname="<exe-name>.global" name="Template test case with test types specified inside non-default-constructible std::tuple - MyNonDefaultConstructibleTypes - 1" time="{duration}"/>
<testcase classname="<exe-name>.global" name="Template test case with test types specified inside non-default-constructible std::tuple - MyNonDefaultConstructibleTypes - 2" time="{duration}"/>
<testcase classname="<exe-name>.global" name="Template test case with test types specified inside std::tuple - MyTypes - 0" time="{duration}"/> <testcase classname="<exe-name>.global" name="Template test case with test types specified inside std::tuple - MyTypes - 0" time="{duration}"/>
<testcase classname="<exe-name>.global" name="Template test case with test types specified inside std::tuple - MyTypes - 1" time="{duration}"/> <testcase classname="<exe-name>.global" name="Template test case with test types specified inside std::tuple - MyTypes - 1" time="{duration}"/>
<testcase classname="<exe-name>.global" name="Template test case with test types specified inside std::tuple - MyTypes - 2" time="{duration}"/> <testcase classname="<exe-name>.global" name="Template test case with test types specified inside std::tuple - MyTypes - 2" time="{duration}"/>

View File

@ -9895,6 +9895,39 @@ Message from section two
</Expression> </Expression>
<OverallResult success="true"/> <OverallResult success="true"/>
</TestCase> </TestCase>
<TestCase name="Template test case with test types specified inside non-default-constructible std::tuple - MyNonDefaultConstructibleTypes - 0" tags="[list][template]" filename="projects/<exe-name>/UsageTests/Misc.tests.cpp" >
<Expression success="true" type="REQUIRE" filename="projects/<exe-name>/UsageTests/Misc.tests.cpp" >
<Original>
sizeof(TestType) > 0
</Original>
<Expanded>
1 > 0
</Expanded>
</Expression>
<OverallResult success="true"/>
</TestCase>
<TestCase name="Template test case with test types specified inside non-default-constructible std::tuple - MyNonDefaultConstructibleTypes - 1" tags="[list][template]" filename="projects/<exe-name>/UsageTests/Misc.tests.cpp" >
<Expression success="true" type="REQUIRE" filename="projects/<exe-name>/UsageTests/Misc.tests.cpp" >
<Original>
sizeof(TestType) > 0
</Original>
<Expanded>
1 > 0
</Expanded>
</Expression>
<OverallResult success="true"/>
</TestCase>
<TestCase name="Template test case with test types specified inside non-default-constructible std::tuple - MyNonDefaultConstructibleTypes - 2" tags="[list][template]" filename="projects/<exe-name>/UsageTests/Misc.tests.cpp" >
<Expression success="true" type="REQUIRE" filename="projects/<exe-name>/UsageTests/Misc.tests.cpp" >
<Original>
sizeof(TestType) > 0
</Original>
<Expanded>
4 > 0
</Expanded>
</Expression>
<OverallResult success="true"/>
</TestCase>
<TestCase name="Template test case with test types specified inside std::tuple - MyTypes - 0" tags="[list][template]" filename="projects/<exe-name>/UsageTests/Misc.tests.cpp" > <TestCase name="Template test case with test types specified inside std::tuple - MyTypes - 0" tags="[list][template]" filename="projects/<exe-name>/UsageTests/Misc.tests.cpp" >
<Expression success="true" type="REQUIRE" filename="projects/<exe-name>/UsageTests/Misc.tests.cpp" > <Expression success="true" type="REQUIRE" filename="projects/<exe-name>/UsageTests/Misc.tests.cpp" >
<Original> <Original>
@ -14734,7 +14767,7 @@ loose text artifact
</Section> </Section>
<OverallResult success="true"/> <OverallResult success="true"/>
</TestCase> </TestCase>
<OverallResults successes="1398" failures="149" expectedFailures="21"/> <OverallResults successes="1401" failures="149" expectedFailures="21"/>
</Group> </Group>
<OverallResults successes="1398" failures="148" expectedFailures="21"/> <OverallResults successes="1401" failures="148" expectedFailures="21"/>
</Catch> </Catch>

View File

@ -371,6 +371,16 @@ TEMPLATE_LIST_TEST_CASE("Template test case with test types specified inside std
REQUIRE(sizeof(TestType) > 0); REQUIRE(sizeof(TestType) > 0);
} }
struct NonDefaultConstructibleType {
NonDefaultConstructibleType() = delete;
};
using MyNonDefaultConstructibleTypes = std::tuple<NonDefaultConstructibleType, char, float>;
TEMPLATE_LIST_TEST_CASE("Template test case with test types specified inside non-default-constructible std::tuple", "[template][list]", MyNonDefaultConstructibleTypes)
{
REQUIRE(sizeof(TestType) > 0);
}
// https://github.com/philsquared/Catch/issues/166 // https://github.com/philsquared/Catch/issues/166
TEST_CASE("A couple of nested sections followed by a failure", "[failing][.]") { TEST_CASE("A couple of nested sections followed by a failure", "[failing][.]") {
SECTION("Outer") SECTION("Outer")