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

More macros are now variadic

Also added tests for them
Commit
a9128d0faca8bd0f0d323e5309c5322473fd7c9d
Author
Martin Hořeňovský ·
Parents
c5c3d368a2ef

Files · Download .tar.gz

Changes

 include/internal/catch_capture.hpp                 |  20 ++--
 .../SelfTest/Baselines/console.std.approved.txt    |   4 +-
 .../SelfTest/Baselines/console.sw.approved.txt     |  84 +++++++++++++---
 projects/SelfTest/Baselines/junit.sw.approved.txt  |   4 +-
 projects/SelfTest/Baselines/xml.sw.approved.txt    | 111 +++++++++++++++++++--
 projects/SelfTest/TrickyTests.cpp                  |  27 ++++-
 6 files changed, 211 insertions(+), 39 deletions(-)

diff --git a/include/internal/catch_capture.hpp b/include/internal/catch_capture.hpp
index b0418d46..49673309 100644
--- a/include/internal/catch_capture.hpp
+++ b/include/internal/catch_capture.hpp
@@ -81,21 +81,21 @@
     // The double negation silences MSVC's C4800 warning, the static_cast forces short-circuit evaluation if the type has overloaded &&.
 
 ///////////////////////////////////////////////////////////////////////////////
-#define INTERNAL_CATCH_IF( macroName, resultDisposition, expr ) \
-    INTERNAL_CATCH_TEST( macroName, resultDisposition, expr ); \
+#define INTERNAL_CATCH_IF( macroName, resultDisposition, ... ) \
+    INTERNAL_CATCH_TEST( macroName, resultDisposition, __VA_ARGS__ ); \
     if( Catch::getResultCapture().getLastResult()->succeeded() )
 
 ///////////////////////////////////////////////////////////////////////////////
-#define INTERNAL_CATCH_ELSE( macroName, resultDisposition, expr ) \
-    INTERNAL_CATCH_TEST( macroName, resultDisposition, expr ); \
+#define INTERNAL_CATCH_ELSE( macroName, resultDisposition, ... ) \
+    INTERNAL_CATCH_TEST( macroName, resultDisposition, __VA_ARGS__ ); \
     if( !Catch::getResultCapture().getLastResult()->succeeded() )
 
 ///////////////////////////////////////////////////////////////////////////////
-#define INTERNAL_CATCH_NO_THROW( macroName, resultDisposition, expr ) \
+#define INTERNAL_CATCH_NO_THROW( macroName, resultDisposition, ... ) \
     do { \
-        Catch::ResultBuilder __catchResult( macroName, CATCH_INTERNAL_LINEINFO, #expr, resultDisposition ); \
+        Catch::ResultBuilder __catchResult( macroName, CATCH_INTERNAL_LINEINFO, #__VA_ARGS__, resultDisposition ); \
         try { \
-            static_cast<void>(expr); \
+            static_cast<void>(__VA_ARGS__); \
             __catchResult.captureResult( Catch::ResultWas::Ok ); \
         } \
         catch( ... ) { \
@@ -105,12 +105,12 @@
     } while( Catch::alwaysFalse() )
 
 ///////////////////////////////////////////////////////////////////////////////
-#define INTERNAL_CATCH_THROWS( macroName, resultDisposition, matcher, expr ) \
+#define INTERNAL_CATCH_THROWS( macroName, resultDisposition, matcher, ... ) \
     do { \
-        Catch::ResultBuilder __catchResult( macroName, CATCH_INTERNAL_LINEINFO, #expr, resultDisposition, #matcher ); \
+        Catch::ResultBuilder __catchResult( macroName, CATCH_INTERNAL_LINEINFO, #__VA_ARGS__, resultDisposition, #matcher ); \
         if( __catchResult.allowThrows() ) \
             try { \
-                static_cast<void>(expr); \
+                static_cast<void>(__VA_ARGS__); \
                 __catchResult.captureResult( Catch::ResultWas::DidntThrowException ); \
             } \
             catch( ... ) { \
diff --git a/projects/SelfTest/Baselines/console.std.approved.txt b/projects/SelfTest/Baselines/console.std.approved.txt
index b07d6f3a..c35d3bd1 100644
--- a/projects/SelfTest/Baselines/console.std.approved.txt
+++ b/projects/SelfTest/Baselines/console.std.approved.txt
@@ -940,6 +940,6 @@ with expansion:
   "first" == "second"
 
 ===============================================================================
-test cases: 169 | 121 passed | 44 failed |  4 failed as expected
-assertions: 969 | 861 passed | 87 failed | 21 failed as expected
+test cases: 170 | 122 passed | 44 failed |  4 failed as expected
+assertions: 980 | 872 passed | 87 failed | 21 failed as expected
 
diff --git a/projects/SelfTest/Baselines/console.sw.approved.txt b/projects/SelfTest/Baselines/console.sw.approved.txt
index 9b857c4f..68227089 100644
--- a/projects/SelfTest/Baselines/console.sw.approved.txt
+++ b/projects/SelfTest/Baselines/console.sw.approved.txt
@@ -823,6 +823,74 @@ PASSED:
 with expansion:
   5 == 5
 
+-------------------------------------------------------------------------------
+Commas in various macros are allowed
+-------------------------------------------------------------------------------
+TrickyTests.cpp:<line number>
+...............................................................................
+
+TrickyTests.cpp:<line number>:
+PASSED:
+  REQUIRE_THROWS( std::vector<constructor_throws>{constructor_throws{}, constructor_throws{}} )
+
+TrickyTests.cpp:<line number>:
+PASSED:
+  CHECK_THROWS( std::vector<constructor_throws>{constructor_throws{}, constructor_throws{}} )
+
+TrickyTests.cpp:<line number>:
+PASSED:
+  REQUIRE_NOTHROW( std::vector<int>{1, 2, 3} == std::vector<int>{1, 2, 3} )
+
+TrickyTests.cpp:<line number>:
+PASSED:
+  CHECK_NOTHROW( std::vector<int>{1, 2, 3} == std::vector<int>{1, 2, 3} )
+
+TrickyTests.cpp:<line number>:
+PASSED:
+  REQUIRE( std::vector<int>{1, 2} == std::vector<int>{1, 2} )
+with expansion:
+  { 1, 2 } == { 1, 2 }
+
+TrickyTests.cpp:<line number>:
+PASSED:
+  CHECK( std::vector<int>{1, 2} == std::vector<int>{1, 2} )
+with expansion:
+  { 1, 2 } == { 1, 2 }
+
+TrickyTests.cpp:<line number>:
+PASSED:
+  REQUIRE_FALSE( std::vector<int>{1, 2} == std::vector<int>{1, 2, 3} )
+with expansion:
+  !({ 1, 2 } == { 1, 2, 3 })
+
+TrickyTests.cpp:<line number>:
+PASSED:
+  CHECK_FALSE( std::vector<int>{1, 2} == std::vector<int>{1, 2, 3} )
+with expansion:
+  !({ 1, 2 } == { 1, 2, 3 })
+
+TrickyTests.cpp:<line number>:
+PASSED:
+  CHECK_NOFAIL( std::vector<int>{1, 2} == std::vector<int>{1, 2} )
+with expansion:
+  { 1, 2 } == { 1, 2 }
+
+TrickyTests.cpp:<line number>:
+PASSED:
+  CHECKED_IF( std::vector<int>{1, 2} == std::vector<int>{1, 2} )
+with expansion:
+  { 1, 2 } == { 1, 2 }
+
+TrickyTests.cpp:<line number>:
+PASSED:
+  REQUIRE( true )
+
+TrickyTests.cpp:<line number>:
+PASSED:
+  CHECKED_ELSE( std::vector<int>{1, 2} == std::vector<int>{1, 2} )
+with expansion:
+  { 1, 2 } == { 1, 2 }
+
 -------------------------------------------------------------------------------
 Comparing function pointers
 -------------------------------------------------------------------------------
@@ -8461,18 +8529,6 @@ PASSED:
 with expansion:
   "[\x7F]" == "[\x7F]"
 
--------------------------------------------------------------------------------
-assertions with commas are allowed
--------------------------------------------------------------------------------
-TrickyTests.cpp:<line number>
-...............................................................................
-
-TrickyTests.cpp:<line number>:
-PASSED:
-  REQUIRE( std::vector<int>{1, 2} == std::vector<int>{1, 2} )
-with expansion:
-  { 1, 2 } == { 1, 2 }
-
 -------------------------------------------------------------------------------
 atomic if
 -------------------------------------------------------------------------------
@@ -9492,6 +9548,6 @@ MiscTests.cpp:<line number>:
 PASSED:
 
 ===============================================================================
-test cases: 169 | 120 passed | 45 failed |  4 failed as expected
-assertions: 971 | 861 passed | 89 failed | 21 failed as expected
+test cases: 170 | 121 passed | 45 failed |  4 failed as expected
+assertions: 982 | 872 passed | 89 failed | 21 failed as expected
 
diff --git a/projects/SelfTest/Baselines/junit.sw.approved.txt b/projects/SelfTest/Baselines/junit.sw.approved.txt
index ce6f7d23..5de62625 100644
--- a/projects/SelfTest/Baselines/junit.sw.approved.txt
+++ b/projects/SelfTest/Baselines/junit.sw.approved.txt
@@ -1,6 +1,6 @@
 <?xml version="1.0" encoding="UTF-8"?>
 <testsuitesspanner>
-  <testsuite name="<exe-name>" errors="13" failures="77" tests="972" hostname="tbd" time="{duration}" timestamp="{iso8601-timestamp}">
+  <testsuite name="<exe-name>" errors="13" failures="77" tests="983" hostname="tbd" time="{duration}" timestamp="{iso8601-timestamp}">
     <testcase classname="global" name="# A test name that starts with a #" time="{duration}"/>
     <testcase classname="#748 - captures with unexpected exceptions" name="outside assertions" time="{duration}">
       <error type="TEST_CASE">
@@ -109,6 +109,7 @@ ExceptionTests.cpp:<line number>
     <testcase classname="Character pretty printing" name="Specifically escaped" time="{duration}"/>
     <testcase classname="Character pretty printing" name="General chars" time="{duration}"/>
     <testcase classname="Character pretty printing" name="Low ASCII" time="{duration}"/>
+    <testcase classname="global" name="Commas in various macros are allowed" time="{duration}"/>
     <testcase classname="global" name="Comparing function pointers" time="{duration}"/>
     <testcase classname="global" name="Comparing member function pointers" time="{duration}"/>
     <testcase classname="global" name="Comparisons between ints where one side is computed" time="{duration}"/>
@@ -608,7 +609,6 @@ ExceptionTests.cpp:<line number>
     <testcase classname="XmlEncode" name="string with quotes" time="{duration}"/>
     <testcase classname="XmlEncode" name="string with control char (1)" time="{duration}"/>
     <testcase classname="XmlEncode" name="string with control char (x7F)" time="{duration}"/>
-    <testcase classname="global" name="assertions with commas are allowed" time="{duration}"/>
     <testcase classname="global" name="atomic if" time="{duration}"/>
     <testcase classname="global" name="boolean member" time="{duration}"/>
     <testcase classname="global" name="checkedElse" time="{duration}"/>
diff --git a/projects/SelfTest/Baselines/xml.sw.approved.txt b/projects/SelfTest/Baselines/xml.sw.approved.txt
index 32d233a1..f0bfebd8 100644
--- a/projects/SelfTest/Baselines/xml.sw.approved.txt
+++ b/projects/SelfTest/Baselines/xml.sw.approved.txt
@@ -898,6 +898,105 @@
       </Section>
       <OverallResult success="true"/>
     </TestCase>
+    <TestCase name="Commas in various macros are allowed" filename="projects/<exe-name>/TrickyTests.cpp" >
+      <Expression success="true" type="REQUIRE_THROWS" filename="projects/<exe-name>/TrickyTests.cpp" >
+        <Original>
+          std::vector&lt;constructor_throws>{constructor_throws{}, constructor_throws{}}
+        </Original>
+        <Expanded>
+          std::vector&lt;constructor_throws>{constructor_throws{}, constructor_throws{}}
+        </Expanded>
+      </Expression>
+      <Expression success="true" type="CHECK_THROWS" filename="projects/<exe-name>/TrickyTests.cpp" >
+        <Original>
+          std::vector&lt;constructor_throws>{constructor_throws{}, constructor_throws{}}
+        </Original>
+        <Expanded>
+          std::vector&lt;constructor_throws>{constructor_throws{}, constructor_throws{}}
+        </Expanded>
+      </Expression>
+      <Expression success="true" type="REQUIRE_NOTHROW" filename="projects/<exe-name>/TrickyTests.cpp" >
+        <Original>
+          std::vector&lt;int>{1, 2, 3} == std::vector&lt;int>{1, 2, 3}
+        </Original>
+        <Expanded>
+          std::vector&lt;int>{1, 2, 3} == std::vector&lt;int>{1, 2, 3}
+        </Expanded>
+      </Expression>
+      <Expression success="true" type="CHECK_NOTHROW" filename="projects/<exe-name>/TrickyTests.cpp" >
+        <Original>
+          std::vector&lt;int>{1, 2, 3} == std::vector&lt;int>{1, 2, 3}
+        </Original>
+        <Expanded>
+          std::vector&lt;int>{1, 2, 3} == std::vector&lt;int>{1, 2, 3}
+        </Expanded>
+      </Expression>
+      <Expression success="true" type="REQUIRE" filename="projects/<exe-name>/TrickyTests.cpp" >
+        <Original>
+          std::vector&lt;int>{1, 2} == std::vector&lt;int>{1, 2}
+        </Original>
+        <Expanded>
+          { 1, 2 } == { 1, 2 }
+        </Expanded>
+      </Expression>
+      <Expression success="true" type="CHECK" filename="projects/<exe-name>/TrickyTests.cpp" >
+        <Original>
+          std::vector&lt;int>{1, 2} == std::vector&lt;int>{1, 2}
+        </Original>
+        <Expanded>
+          { 1, 2 } == { 1, 2 }
+        </Expanded>
+      </Expression>
+      <Expression success="true" type="REQUIRE_FALSE" filename="projects/<exe-name>/TrickyTests.cpp" >
+        <Original>
+          !std::vector&lt;int>{1, 2} == std::vector&lt;int>{1, 2, 3}
+        </Original>
+        <Expanded>
+          !({ 1, 2 } == { 1, 2, 3 })
+        </Expanded>
+      </Expression>
+      <Expression success="true" type="CHECK_FALSE" filename="projects/<exe-name>/TrickyTests.cpp" >
+        <Original>
+          !std::vector&lt;int>{1, 2} == std::vector&lt;int>{1, 2, 3}
+        </Original>
+        <Expanded>
+          !({ 1, 2 } == { 1, 2, 3 })
+        </Expanded>
+      </Expression>
+      <Expression success="true" type="CHECK_NOFAIL" filename="projects/<exe-name>/TrickyTests.cpp" >
+        <Original>
+          std::vector&lt;int>{1, 2} == std::vector&lt;int>{1, 2}
+        </Original>
+        <Expanded>
+          { 1, 2 } == { 1, 2 }
+        </Expanded>
+      </Expression>
+      <Expression success="true" type="CHECKED_IF" filename="projects/<exe-name>/TrickyTests.cpp" >
+        <Original>
+          std::vector&lt;int>{1, 2} == std::vector&lt;int>{1, 2}
+        </Original>
+        <Expanded>
+          { 1, 2 } == { 1, 2 }
+        </Expanded>
+      </Expression>
+      <Expression success="true" type="REQUIRE" filename="projects/<exe-name>/TrickyTests.cpp" >
+        <Original>
+          true
+        </Original>
+        <Expanded>
+          true
+        </Expanded>
+      </Expression>
+      <Expression success="true" type="CHECKED_ELSE" filename="projects/<exe-name>/TrickyTests.cpp" >
+        <Original>
+          std::vector&lt;int>{1, 2} == std::vector&lt;int>{1, 2}
+        </Original>
+        <Expanded>
+          { 1, 2 } == { 1, 2 }
+        </Expanded>
+      </Expression>
+      <OverallResult success="true"/>
+    </TestCase>
     <TestCase name="Comparing function pointers" tags="[Tricky][function pointer]" filename="projects/<exe-name>/TrickyTests.cpp" >
       <Expression success="true" type="REQUIRE" filename="projects/<exe-name>/TrickyTests.cpp" >
         <Original>
@@ -9086,14 +9185,6 @@ there"
       <OverallResult success="true"/>
     </TestCase>
     <TestCase name="assertions with commas are allowed" filename="projects/<exe-name>/TrickyTests.cpp" >
-      <Expression success="true" type="REQUIRE" filename="projects/<exe-name>/TrickyTests.cpp" >
-        <Original>
-          std::vector&lt;int>{1, 2} == std::vector&lt;int>{1, 2}
-        </Original>
-        <Expanded>
-          { 1, 2 } == { 1, 2 }
-        </Expanded>
-      </Expression>
       <OverallResult success="true"/>
     </TestCase>
     <TestCase name="atomic if" tags="[0][failing]" filename="projects/<exe-name>/MiscTests.cpp" >
@@ -10139,7 +10230,7 @@ spanner      <OverallResult success="true"/>
       </Section>
       <OverallResult success="true"/>
     </TestCase>
-    <OverallResults successes="861" failures="90" expectedFailures="21"/>
+    <OverallResults successes="872" failures="90" expectedFailures="21"/>
   </Group>
-  <OverallResults successes="861" failures="89" expectedFailures="21"/>
+  <OverallResults successes="872" failures="89" expectedFailures="21"/>
 </Catch>
diff --git a/projects/SelfTest/TrickyTests.cpp b/projects/SelfTest/TrickyTests.cpp
index e5616d0e..4dfdf39e 100644
--- a/projects/SelfTest/TrickyTests.cpp
+++ b/projects/SelfTest/TrickyTests.cpp
@@ -396,6 +396,31 @@ TEST_CASE( "has printf", "" ) {
 }
 
 TEST_CASE( "assertions with commas are allowed" ) {
+}
+
+namespace {
+    struct constructor_throws {
+        constructor_throws() {
+            throw 1;
+        }
+    };
+}
 
-    REQUIRE( std::vector<int>{1, 2} == std::vector<int>{1, 2} );
+TEST_CASE("Commas in various macros are allowed") {
+    REQUIRE_THROWS( std::vector<constructor_throws>{constructor_throws{}, constructor_throws{}} );
+    CHECK_THROWS( std::vector<constructor_throws>{constructor_throws{}, constructor_throws{}} );
+    REQUIRE_NOTHROW( std::vector<int>{1, 2, 3} == std::vector<int>{1, 2, 3} );
+    CHECK_NOTHROW( std::vector<int>{1, 2, 3} == std::vector<int>{1, 2, 3} );
+
+    REQUIRE(std::vector<int>{1, 2} == std::vector<int>{1, 2});
+    CHECK( std::vector<int>{1, 2} == std::vector<int>{1, 2} );
+    REQUIRE_FALSE(std::vector<int>{1, 2} == std::vector<int>{1, 2, 3});
+    CHECK_FALSE( std::vector<int>{1, 2} == std::vector<int>{1, 2, 3} );
+
+    CHECK_NOFAIL( std::vector<int>{1, 2} == std::vector<int>{1, 2} );
+    CHECKED_IF( std::vector<int>{1, 2} == std::vector<int>{1, 2} ) {
+        REQUIRE(true);
+    } CHECKED_ELSE( std::vector<int>{1, 2} == std::vector<int>{1, 2} ) {
+        CHECK(true);
+    }
 }