Progmasoft Git

catch3

Progmasoft Catch3: an independently maintained C++17 test framework with a parallel runner, property checks, snapshots and structured results.

Clonegit clone https://git.progmasoft.com/catch3

Namespace our type traits in catch_meta

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

Fixes #1548
Commit
29b3b7ae6b28501165d2b3d992bfc259e532d585
Author
Martin Hořeňovský ·
Parents
ef5fd8d42f1f

Files · Download .tar.gz

Changes

 include/internal/catch_meta.hpp                    | 64 ++++++++++------------
 include/internal/catch_preprocessor.hpp            |  2 +-
 include/internal/catch_test_registry.h             |  4 +-
 .../SelfTest/Baselines/compact.sw.approved.txt     |  1 +
 .../SelfTest/Baselines/console.std.approved.txt    |  4 +-
 .../SelfTest/Baselines/console.sw.approved.txt     | 15 ++++-
 .../SelfTest/Baselines/console.swa4.approved.txt   | 15 ++++-
 projects/SelfTest/Baselines/junit.sw.approved.txt  |  3 +-
 projects/SelfTest/Baselines/xml.sw.approved.txt    | 15 ++++-
 projects/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 <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
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<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))
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<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;\
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:<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'
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:<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
 
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:<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
 
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 @@
     <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
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 @@
       </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>
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 <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