Namespace our type traits in catch_meta

Previously they could conflict with user-defined type traits that
were in the global namespace.

Fixes #1548
This commit is contained in:
Martin Hořeňovský 2019-02-23 21:06:16 +01:00
parent ef5fd8d42f
commit 29b3b7ae6b
No known key found for this signature in database
GPG Key ID: DE48307B8B0D381A
10 changed files with 87 additions and 46 deletions

View File

@ -11,65 +11,59 @@
#include <type_traits>
namespace Catch {
template< typename... >
struct TypeList{};
struct TypeList {};
template< typename... >
struct append;
template< template<typename...> class L1
, typename...E1
, template<typename...> class L2
, typename...E2
>
struct append< L1<E1...>, L2<E2...> >
{
using type = L1<E1..., E2...>;
, typename...E1
, template<typename...> class L2
, typename...E2
>
struct append< L1<E1...>, L2<E2...> > {
using type = L1<E1..., E2...>;
};
template< template<typename...> class L1
, typename...E1
, template<typename...> class L2
, typename...E2
, typename...Rest
>
struct append< L1<E1...>, L2<E2...>, Rest...>
{
using type = typename append< L1<E1..., E2...>, Rest... >::type;
, typename...E1
, template<typename...> class L2
, typename...E2
, typename...Rest
>
struct append< L1<E1...>, L2<E2...>, Rest...> {
using type = typename append< L1<E1..., E2...>, Rest... >::type;
};
template< template<typename...> class
, typename...
>
, typename...
>
struct rewrap;
template< template<typename...> class Container
, template<typename...> class List
, typename...elems
>
struct rewrap<Container, List<elems...>>
{
, template<typename...> class List
, typename...elems
>
struct rewrap<Container, List<elems...>> {
using type = TypeList< Container< elems... > >;
};
template< template<typename...> class Container
, template<typename...> class List
, class...Elems
, typename...Elements>
struct rewrap<Container, List<Elems...>, Elements...>
{
, template<typename...> class List
, class...Elems
, typename...Elements>
struct rewrap<Container, List<Elems...>, Elements...> {
using type = typename append<TypeList<Container<Elems...>>, typename rewrap<Container, Elements...>::type>::type;
};
template< template<typename...> class...Containers >
struct combine
{
struct combine {
template< typename...Types >
struct with_types
{
struct with_types {
template< template <typename...> class Final >
struct into
{
struct into {
using type = typename append<Final<>, typename rewrap<Containers, Types...>::type...>::type;
};
};
@ -78,4 +72,6 @@ struct combine
template<typename T>
struct always_false : std::false_type {};
} // namespace Catch
#endif // TWOBLUECUBES_CATCH_META_HPP_INCLUDED

View File

@ -81,7 +81,7 @@
#define INTERNAL_CATCH_TEMPLATE_UNIQUE_NAME(Name, ...) INTERNAL_CATCH_TEMPLATE_UNIQUE_NAME1(Name, INTERNAL_CATCH_EXPAND_VARGS(INTERNAL_CATCH_REMOVE_PARENS(__VA_ARGS__)))
#endif
#define INTERNAL_CATCH_MAKE_TYPE_LIST(types) TypeList<INTERNAL_CATCH_REMOVE_PARENS(types)>
#define INTERNAL_CATCH_MAKE_TYPE_LIST(types) Catch::TypeList<INTERNAL_CATCH_REMOVE_PARENS(types)>
#define INTERNAL_CATCH_MAKE_TYPE_LISTS_FROM_TYPES(types)\
CATCH_REC_LIST(INTERNAL_CATCH_MAKE_TYPE_LIST,INTERNAL_CATCH_REMOVE_PARENS(types))

View File

@ -168,7 +168,7 @@ struct AutoReg : NonCopyable {
} \
}; \
static int INTERNAL_CATCH_UNIQUE_NAME( globalRegistrar ) = [](){ \
using TestInit = combine<INTERNAL_CATCH_REMOVE_PARENS(TmplTypes)> \
using TestInit = Catch::combine<INTERNAL_CATCH_REMOVE_PARENS(TmplTypes)> \
::with_types<INTERNAL_CATCH_MAKE_TYPE_LISTS_FROM_TYPES(TypesList)>::into<TestName>::type; \
TestInit(); \
return 0; \
@ -236,7 +236,7 @@ struct AutoReg : NonCopyable {
}\
};\
static int INTERNAL_CATCH_UNIQUE_NAME( globalRegistrar ) = [](){\
using TestInit = combine<INTERNAL_CATCH_REMOVE_PARENS(TmplTypes)>\
using TestInit = Catch::combine<INTERNAL_CATCH_REMOVE_PARENS(TmplTypes)>\
::with_types<INTERNAL_CATCH_MAKE_TYPE_LISTS_FROM_TYPES(TypesList)>::into<TestNameClass>::type;\
TestInit();\
return 0;\

View File

@ -14,6 +14,7 @@ Compilation.tests.cpp:<line number>: passed: std::memcmp(uarr, "123", sizeof(uar
Compilation.tests.cpp:<line number>: passed: std::memcmp(sarr, "456", sizeof(sarr)) == 0 for: 0 == 0 with 2 messages: 'uarr := "123"' and 'sarr := "456"'
Compilation.tests.cpp:<line number>: passed:
Compilation.tests.cpp:<line number>: passed: h1 == h2 for: [1403 helper] == [1403 helper]
Compilation.tests.cpp:<line number>: passed: std::is_same<TypeList<int>, TypeList<int>>::value for: true
Exception.tests.cpp:<line number>: failed: unexpected exception with message: 'answer := 42' with 1 message: 'expected exception'
Exception.tests.cpp:<line number>: failed: unexpected exception with message: 'answer := 42'; expression was: thisThrows() with 1 message: 'expected exception'
Exception.tests.cpp:<line number>: passed: thisThrows() with 1 message: 'answer := 42'

View File

@ -1174,6 +1174,6 @@ due to unexpected exception with message:
Why would you throw a std::string?
===============================================================================
test cases: 245 | 185 passed | 56 failed | 4 failed as expected
assertions: 1379 | 1243 passed | 115 failed | 21 failed as expected
test cases: 246 | 186 passed | 56 failed | 4 failed as expected
assertions: 1380 | 1244 passed | 115 failed | 21 failed as expected

View File

@ -133,6 +133,17 @@ Compilation.tests.cpp:<line number>: PASSED:
with expansion:
[1403 helper] == [1403 helper]
-------------------------------------------------------------------------------
#1548
-------------------------------------------------------------------------------
Compilation.tests.cpp:<line number>
...............................................................................
Compilation.tests.cpp:<line number>: PASSED:
REQUIRE( std::is_same<TypeList<int>, TypeList<int>>::value )
with expansion:
true
-------------------------------------------------------------------------------
#748 - captures with unexpected exceptions
outside assertions
@ -10698,6 +10709,6 @@ Misc.tests.cpp:<line number>
Misc.tests.cpp:<line number>: PASSED:
===============================================================================
test cases: 245 | 172 passed | 69 failed | 4 failed as expected
assertions: 1393 | 1243 passed | 129 failed | 21 failed as expected
test cases: 246 | 173 passed | 69 failed | 4 failed as expected
assertions: 1394 | 1244 passed | 129 failed | 21 failed as expected

View File

@ -133,6 +133,17 @@ Compilation.tests.cpp:<line number>: PASSED:
with expansion:
[1403 helper] == [1403 helper]
-------------------------------------------------------------------------------
#1548
-------------------------------------------------------------------------------
Compilation.tests.cpp:<line number>
...............................................................................
Compilation.tests.cpp:<line number>: PASSED:
REQUIRE( std::is_same<TypeList<int>, TypeList<int>>::value )
with expansion:
true
-------------------------------------------------------------------------------
#748 - captures with unexpected exceptions
outside assertions
@ -323,6 +334,6 @@ with expansion:
!true
===============================================================================
test cases: 15 | 12 passed | 1 failed | 2 failed as expected
assertions: 39 | 32 passed | 4 failed | 3 failed as expected
test cases: 16 | 13 passed | 1 failed | 2 failed as expected
assertions: 40 | 33 passed | 4 failed | 3 failed as expected

View File

@ -4,7 +4,7 @@
<property name="random-seed" value="1"/>
</properties>
loose text artifact
<testsuite name="<exe-name>" errors="17" failures="113" tests="1394" hostname="tbd" time="{duration}" timestamp="{iso8601-timestamp}">
<testsuite name="<exe-name>" errors="17" failures="113" tests="1395" hostname="tbd" time="{duration}" timestamp="{iso8601-timestamp}">
<testcase classname="<exe-name>.global" name="# A test name that starts with a #" time="{duration}"/>
<testcase classname="<exe-name>.global" name="#1005: Comparing pointer to int and long (NULL can be either on various systems)" time="{duration}"/>
<testcase classname="<exe-name>.global" name="#1027" time="{duration}"/>
@ -13,6 +13,7 @@ loose text artifact
<testcase classname="<exe-name>.global" name="#1238" time="{duration}"/>
<testcase classname="<exe-name>.(Fixture_1245&lt;int, int>)" name="#1245" time="{duration}"/>
<testcase classname="<exe-name>.global" name="#1403" time="{duration}"/>
<testcase classname="<exe-name>.global" name="#1548" time="{duration}"/>
<testcase classname="<exe-name>.global" name="#748 - captures with unexpected exceptions/outside assertions" time="{duration}">
<error type="TEST_CASE">
expected exception

View File

@ -142,6 +142,17 @@
</Expression>
<OverallResult success="true"/>
</TestCase>
<TestCase name="#1548" tags="[compilation]" filename="projects/<exe-name>/UsageTests/Compilation.tests.cpp" >
<Expression success="true" type="REQUIRE" filename="projects/<exe-name>/UsageTests/Compilation.tests.cpp" >
<Original>
std::is_same&lt;TypeList&lt;int>, TypeList&lt;int>>::value
</Original>
<Expanded>
true
</Expanded>
</Expression>
<OverallResult success="true"/>
</TestCase>
<TestCase name="#748 - captures with unexpected exceptions" tags="[!shouldfail][!throws][.][failing]" filename="projects/<exe-name>/UsageTests/Exception.tests.cpp" >
<Section name="outside assertions" filename="projects/<exe-name>/UsageTests/Exception.tests.cpp" >
<Info>
@ -12948,7 +12959,7 @@ loose text artifact
</Section>
<OverallResult success="true"/>
</TestCase>
<OverallResults successes="1243" failures="130" expectedFailures="21"/>
<OverallResults successes="1244" failures="130" expectedFailures="21"/>
</Group>
<OverallResults successes="1243" failures="129" expectedFailures="21"/>
<OverallResults successes="1244" failures="129" expectedFailures="21"/>
</Catch>

View File

@ -17,6 +17,11 @@ namespace foo {
};
}
namespace bar {
template <typename... Ts>
struct TypeList {};
}
#ifdef __GNUC__
#pragma GCC diagnostic ignored "-Wmissing-declarations"
#endif
@ -184,6 +189,11 @@ namespace { namespace CompilationTests {
STATIC_REQUIRE_FALSE( std::is_void<int>::value );
}
TEST_CASE("#1548", "[compilation]") {
using namespace bar;
REQUIRE(std::is_same<TypeList<int>, TypeList<int>>::value);
}
}} // namespace CompilationTests