From 29b3b7ae6b28501165d2b3d992bfc259e532d585 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Martin=20Ho=C5=99e=C5=88ovsk=C3=BD?= Date: Sat, 23 Feb 2019 21:06:16 +0100 Subject: [PATCH] Namespace our type traits in catch_meta Previously they could conflict with user-defined type traits that were in the global namespace. Fixes #1548 --- include/internal/catch_meta.hpp | 64 +++++++++---------- include/internal/catch_preprocessor.hpp | 2 +- include/internal/catch_test_registry.h | 4 +- .../Baselines/compact.sw.approved.txt | 1 + .../Baselines/console.std.approved.txt | 4 +- .../Baselines/console.sw.approved.txt | 15 ++++- .../Baselines/console.swa4.approved.txt | 15 ++++- .../SelfTest/Baselines/junit.sw.approved.txt | 3 +- .../SelfTest/Baselines/xml.sw.approved.txt | 15 ++++- .../SelfTest/UsageTests/Compilation.tests.cpp | 10 +++ 10 files changed, 87 insertions(+), 46 deletions(-) diff --git a/include/internal/catch_meta.hpp b/include/internal/catch_meta.hpp index e69c4955..3508a46f 100644 --- a/include/internal/catch_meta.hpp +++ b/include/internal/catch_meta.hpp @@ -11,65 +11,59 @@ #include +namespace Catch { template< typename... > -struct TypeList{}; +struct TypeList {}; template< typename... > struct append; template< template class L1 - , typename...E1 - , template class L2 - , typename...E2 - > -struct append< L1, L2 > -{ - using type = L1; + , typename...E1 + , template class L2 + , typename...E2 +> +struct append< L1, L2 > { + using type = L1; }; template< template class L1 - , typename...E1 - , template class L2 - , typename...E2 - , typename...Rest - > -struct append< L1, L2, Rest...> -{ - using type = typename append< L1, Rest... >::type; + , typename...E1 + , template class L2 + , typename...E2 + , typename...Rest +> +struct append< L1, L2, Rest...> { + using type = typename append< L1, Rest... >::type; }; template< template class - , typename... - > + , typename... +> struct rewrap; template< template class Container - , template class List - , typename...elems - > -struct rewrap> -{ + , template class List + , typename...elems +> +struct rewrap> { using type = TypeList< Container< elems... > >; }; template< template class Container - , template class List - , class...Elems - , typename...Elements> -struct rewrap, Elements...> -{ + , template class List + , class...Elems + , typename...Elements> + struct rewrap, Elements...> { using type = typename append>, typename rewrap::type>::type; }; template< template class...Containers > -struct combine -{ +struct combine { template< typename...Types > - struct with_types - { + struct with_types { template< template class Final > - struct into - { + struct into { using type = typename append, typename rewrap::type...>::type; }; }; @@ -78,4 +72,6 @@ struct combine template struct always_false : std::false_type {}; +} // namespace Catch + #endif // TWOBLUECUBES_CATCH_META_HPP_INCLUDED diff --git a/include/internal/catch_preprocessor.hpp b/include/internal/catch_preprocessor.hpp index 545e9705..faf41e6b 100644 --- a/include/internal/catch_preprocessor.hpp +++ b/include/internal/catch_preprocessor.hpp @@ -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 +#define INTERNAL_CATCH_MAKE_TYPE_LIST(types) Catch::TypeList #define INTERNAL_CATCH_MAKE_TYPE_LISTS_FROM_TYPES(types)\ CATCH_REC_LIST(INTERNAL_CATCH_MAKE_TYPE_LIST,INTERNAL_CATCH_REMOVE_PARENS(types)) diff --git a/include/internal/catch_test_registry.h b/include/internal/catch_test_registry.h index 4d247f36..0e7b53de 100644 --- a/include/internal/catch_test_registry.h +++ b/include/internal/catch_test_registry.h @@ -168,7 +168,7 @@ struct AutoReg : NonCopyable { } \ }; \ static int INTERNAL_CATCH_UNIQUE_NAME( globalRegistrar ) = [](){ \ - using TestInit = combine \ + using TestInit = Catch::combine \ ::with_types::into::type; \ TestInit(); \ return 0; \ @@ -236,7 +236,7 @@ struct AutoReg : NonCopyable { }\ };\ static int INTERNAL_CATCH_UNIQUE_NAME( globalRegistrar ) = [](){\ - using TestInit = combine\ + using TestInit = Catch::combine\ ::with_types::into::type;\ TestInit();\ return 0;\ diff --git a/projects/SelfTest/Baselines/compact.sw.approved.txt b/projects/SelfTest/Baselines/compact.sw.approved.txt index 824c4a6b..31c7ee0d 100644 --- a/projects/SelfTest/Baselines/compact.sw.approved.txt +++ b/projects/SelfTest/Baselines/compact.sw.approved.txt @@ -14,6 +14,7 @@ Compilation.tests.cpp:: passed: std::memcmp(uarr, "123", sizeof(uar Compilation.tests.cpp:: passed: std::memcmp(sarr, "456", sizeof(sarr)) == 0 for: 0 == 0 with 2 messages: 'uarr := "123"' and 'sarr := "456"' Compilation.tests.cpp:: passed: Compilation.tests.cpp:: passed: h1 == h2 for: [1403 helper] == [1403 helper] +Compilation.tests.cpp:: passed: std::is_same, TypeList>::value for: true Exception.tests.cpp:: failed: unexpected exception with message: 'answer := 42' with 1 message: 'expected exception' Exception.tests.cpp:: failed: unexpected exception with message: 'answer := 42'; expression was: thisThrows() with 1 message: 'expected exception' Exception.tests.cpp:: passed: thisThrows() with 1 message: 'answer := 42' diff --git a/projects/SelfTest/Baselines/console.std.approved.txt b/projects/SelfTest/Baselines/console.std.approved.txt index d936ba03..9be03dcd 100644 --- a/projects/SelfTest/Baselines/console.std.approved.txt +++ b/projects/SelfTest/Baselines/console.std.approved.txt @@ -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 diff --git a/projects/SelfTest/Baselines/console.sw.approved.txt b/projects/SelfTest/Baselines/console.sw.approved.txt index 6205211a..23f91912 100644 --- a/projects/SelfTest/Baselines/console.sw.approved.txt +++ b/projects/SelfTest/Baselines/console.sw.approved.txt @@ -133,6 +133,17 @@ Compilation.tests.cpp:: PASSED: with expansion: [1403 helper] == [1403 helper] +------------------------------------------------------------------------------- +#1548 +------------------------------------------------------------------------------- +Compilation.tests.cpp: +............................................................................... + +Compilation.tests.cpp:: PASSED: + REQUIRE( std::is_same, TypeList>::value ) +with expansion: + true + ------------------------------------------------------------------------------- #748 - captures with unexpected exceptions outside assertions @@ -10698,6 +10709,6 @@ Misc.tests.cpp: Misc.tests.cpp:: 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 diff --git a/projects/SelfTest/Baselines/console.swa4.approved.txt b/projects/SelfTest/Baselines/console.swa4.approved.txt index 36ca1bde..63d7e28f 100644 --- a/projects/SelfTest/Baselines/console.swa4.approved.txt +++ b/projects/SelfTest/Baselines/console.swa4.approved.txt @@ -133,6 +133,17 @@ Compilation.tests.cpp:: PASSED: with expansion: [1403 helper] == [1403 helper] +------------------------------------------------------------------------------- +#1548 +------------------------------------------------------------------------------- +Compilation.tests.cpp: +............................................................................... + +Compilation.tests.cpp:: PASSED: + REQUIRE( std::is_same, TypeList>::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 diff --git a/projects/SelfTest/Baselines/junit.sw.approved.txt b/projects/SelfTest/Baselines/junit.sw.approved.txt index e477c29c..2c8a6495 100644 --- a/projects/SelfTest/Baselines/junit.sw.approved.txt +++ b/projects/SelfTest/Baselines/junit.sw.approved.txt @@ -4,7 +4,7 @@ loose text artifact - + @@ -13,6 +13,7 @@ loose text artifact + expected exception diff --git a/projects/SelfTest/Baselines/xml.sw.approved.txt b/projects/SelfTest/Baselines/xml.sw.approved.txt index 31ba5800..60257c25 100644 --- a/projects/SelfTest/Baselines/xml.sw.approved.txt +++ b/projects/SelfTest/Baselines/xml.sw.approved.txt @@ -142,6 +142,17 @@ + + + + std::is_same<TypeList<int>, TypeList<int>>::value + + + true + + + +
@@ -12948,7 +12959,7 @@ loose text artifact
- + - + diff --git a/projects/SelfTest/UsageTests/Compilation.tests.cpp b/projects/SelfTest/UsageTests/Compilation.tests.cpp index 325a8142..7f2ad8bc 100644 --- a/projects/SelfTest/UsageTests/Compilation.tests.cpp +++ b/projects/SelfTest/UsageTests/Compilation.tests.cpp @@ -17,6 +17,11 @@ namespace foo { }; } +namespace bar { + template + struct TypeList {}; +} + #ifdef __GNUC__ #pragma GCC diagnostic ignored "-Wmissing-declarations" #endif @@ -184,6 +189,11 @@ namespace { namespace CompilationTests { STATIC_REQUIRE_FALSE( std::is_void::value ); } + TEST_CASE("#1548", "[compilation]") { + using namespace bar; + REQUIRE(std::is_same, TypeList>::value); + } + }} // namespace CompilationTests