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

Fix compilation for types where relops don't return bool

Closes #1147
Commit
de36b2ada6e4593a9a32c4c86cd47d4bc002b148
Author
Martin Hořeňovský ·
Parents
9700ee4fc0f9

Files · Download .tar.gz

Changes

 include/internal/catch_decomposer.h                | 12 ++---
 .../SelfTest/Baselines/compact.sw.approved.txt     |  6 +++
 .../SelfTest/Baselines/console.std.approved.txt    |  4 +-
 .../SelfTest/Baselines/console.sw.approved.txt     | 46 +++++++++++++++++-
 .../SelfTest/Baselines/console.swa4.approved.txt   | 46 +++++++++++++++++-
 projects/SelfTest/Baselines/junit.sw.approved.txt  |  3 +-
 projects/SelfTest/Baselines/xml.sw.approved.txt    | 55 +++++++++++++++++++++-
 projects/SelfTest/UsageTests/Compilation.tests.cpp | 25 ++++++++++
 8 files changed, 182 insertions(+), 15 deletions(-)

diff --git a/include/internal/catch_decomposer.h b/include/internal/catch_decomposer.h
index d663114b..4fe15c4a 100644
--- a/include/internal/catch_decomposer.h
+++ b/include/internal/catch_decomposer.h
@@ -82,7 +82,7 @@ namespace Catch {
 
     // Specialised comparison functions to handle equality comparisons between ints and pointers (NULL deduces as an int)
     template<typename LhsT, typename RhsT>
-    auto compareEqual( LhsT const& lhs, RhsT const& rhs ) -> bool { return lhs == rhs; };
+    auto compareEqual( LhsT const& lhs, RhsT const& rhs ) -> bool { return static_cast<bool>(lhs == rhs); };
     template<typename T>
     auto compareEqual( T* const& lhs, int rhs ) -> bool { return lhs == reinterpret_cast<void const*>( rhs ); }
     template<typename T>
@@ -93,7 +93,7 @@ namespace Catch {
     auto compareEqual( long lhs, T* const& rhs ) -> bool { return reinterpret_cast<void const*>( lhs ) == rhs; }
 
     template<typename LhsT, typename RhsT>
-    auto compareNotEqual( LhsT const& lhs, RhsT&& rhs ) -> bool { return lhs != rhs; };
+    auto compareNotEqual( LhsT const& lhs, RhsT&& rhs ) -> bool { return static_cast<bool>(lhs != rhs); };
     template<typename T>
     auto compareNotEqual( T* const& lhs, int rhs ) -> bool { return lhs != reinterpret_cast<void const*>( rhs ); }
     template<typename T>
@@ -128,19 +128,19 @@ namespace Catch {
 
         template<typename RhsT>
         auto operator > ( RhsT const& rhs ) -> BinaryExpr<LhsT, RhsT const&> const {
-            return { m_lhs > rhs, m_lhs, ">", rhs };
+            return { static_cast<bool>(m_lhs > rhs), m_lhs, ">", rhs };
         }
         template<typename RhsT>
         auto operator < ( RhsT const& rhs ) -> BinaryExpr<LhsT, RhsT const&> const {
-            return { m_lhs < rhs, m_lhs, "<", rhs };
+            return { static_cast<bool>(m_lhs < rhs), m_lhs, "<", rhs };
         }
         template<typename RhsT>
         auto operator >= ( RhsT const& rhs ) -> BinaryExpr<LhsT, RhsT const&> const {
-            return { m_lhs >= rhs, m_lhs, ">=", rhs };
+            return { static_cast<bool>(m_lhs >= rhs), m_lhs, ">=", rhs };
         }
         template<typename RhsT>
         auto operator <= ( RhsT const& rhs ) -> BinaryExpr<LhsT, RhsT const&> const {
-            return { m_lhs <= rhs, m_lhs, "<=", rhs };
+            return { static_cast<bool>(m_lhs <= rhs), m_lhs, "<=", rhs };
         }
 
         auto makeUnaryExpr() const -> UnaryExpr<LhsT> {
diff --git a/projects/SelfTest/Baselines/compact.sw.approved.txt b/projects/SelfTest/Baselines/compact.sw.approved.txt
index e7dafe5a..f8c2ba21 100644
--- a/projects/SelfTest/Baselines/compact.sw.approved.txt
+++ b/projects/SelfTest/Baselines/compact.sw.approved.txt
@@ -3,6 +3,12 @@ Decomposition.tests.cpp:<line number>: passed: fptr == 0 for: 0 == 0
 Decomposition.tests.cpp:<line number>: passed: fptr == 0l for: 0 == 0
 Compilation.tests.cpp:<line number>: passed: y.v == 0 for: 0 == 0
 Compilation.tests.cpp:<line number>: passed: 0 == y.v for: 0 == 0
+Compilation.tests.cpp:<line number>: passed: t1 == t2 for: {?} == {?}
+Compilation.tests.cpp:<line number>: passed: t1 != t2 for: {?} != {?}
+Compilation.tests.cpp:<line number>: passed: t1 < t2 for: {?} < {?}
+Compilation.tests.cpp:<line number>: passed: t1 > t2 for: {?} > {?}
+Compilation.tests.cpp:<line number>: passed: t1 <= t2 for: {?} <= {?}
+Compilation.tests.cpp:<line number>: passed: t1 >= t2 for: {?} >= {?}
 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 375fb71a..79387418 100644
--- a/projects/SelfTest/Baselines/console.std.approved.txt
+++ b/projects/SelfTest/Baselines/console.std.approved.txt
@@ -1064,6 +1064,6 @@ with expansion:
   "first" == "second"
 
 ===============================================================================
-test cases: 195 | 144 passed |  47 failed |  4 failed as expected
-assertions: 983 | 857 passed | 105 failed | 21 failed as expected
+test cases: 196 | 145 passed |  47 failed |  4 failed as expected
+assertions: 989 | 863 passed | 105 failed | 21 failed as expected
 
diff --git a/projects/SelfTest/Baselines/console.sw.approved.txt b/projects/SelfTest/Baselines/console.sw.approved.txt
index 57c3ca79..29be3496 100644
--- a/projects/SelfTest/Baselines/console.sw.approved.txt
+++ b/projects/SelfTest/Baselines/console.sw.approved.txt
@@ -51,6 +51,48 @@ PASSED:
 with expansion:
   0 == 0
 
+-------------------------------------------------------------------------------
+#1147
+-------------------------------------------------------------------------------
+Compilation.tests.cpp:<line number>
+...............................................................................
+
+Compilation.tests.cpp:<line number>:
+PASSED:
+  REQUIRE( t1 == t2 )
+with expansion:
+  {?} == {?}
+
+Compilation.tests.cpp:<line number>:
+PASSED:
+  REQUIRE( t1 != t2 )
+with expansion:
+  {?} != {?}
+
+Compilation.tests.cpp:<line number>:
+PASSED:
+  REQUIRE( t1 < t2 )
+with expansion:
+  {?} < {?}
+
+Compilation.tests.cpp:<line number>:
+PASSED:
+  REQUIRE( t1 > t2 )
+with expansion:
+  {?} > {?}
+
+Compilation.tests.cpp:<line number>:
+PASSED:
+  REQUIRE( t1 <= t2 )
+with expansion:
+  {?} <= {?}
+
+Compilation.tests.cpp:<line number>:
+PASSED:
+  REQUIRE( t1 >= t2 )
+with expansion:
+  {?} >= {?}
+
 -------------------------------------------------------------------------------
 #748 - captures with unexpected exceptions
   outside assertions
@@ -8246,6 +8288,6 @@ Misc.tests.cpp:<line number>:
 PASSED:
 
 ===============================================================================
-test cases: 195 | 142 passed |  49 failed |  4 failed as expected
-assertions: 982 | 853 passed | 108 failed | 21 failed as expected
+test cases: 196 | 143 passed |  49 failed |  4 failed as expected
+assertions: 988 | 859 passed | 108 failed | 21 failed as expected
 
diff --git a/projects/SelfTest/Baselines/console.swa4.approved.txt b/projects/SelfTest/Baselines/console.swa4.approved.txt
index 19c6e5c1..6232f8d9 100644
--- a/projects/SelfTest/Baselines/console.swa4.approved.txt
+++ b/projects/SelfTest/Baselines/console.swa4.approved.txt
@@ -51,6 +51,48 @@ PASSED:
 with expansion:
   0 == 0
 
+-------------------------------------------------------------------------------
+#1147
+-------------------------------------------------------------------------------
+Compilation.tests.cpp:<line number>
+...............................................................................
+
+Compilation.tests.cpp:<line number>:
+PASSED:
+  REQUIRE( t1 == t2 )
+with expansion:
+  {?} == {?}
+
+Compilation.tests.cpp:<line number>:
+PASSED:
+  REQUIRE( t1 != t2 )
+with expansion:
+  {?} != {?}
+
+Compilation.tests.cpp:<line number>:
+PASSED:
+  REQUIRE( t1 < t2 )
+with expansion:
+  {?} < {?}
+
+Compilation.tests.cpp:<line number>:
+PASSED:
+  REQUIRE( t1 > t2 )
+with expansion:
+  {?} > {?}
+
+Compilation.tests.cpp:<line number>:
+PASSED:
+  REQUIRE( t1 <= t2 )
+with expansion:
+  {?} <= {?}
+
+Compilation.tests.cpp:<line number>:
+PASSED:
+  REQUIRE( t1 >= t2 )
+with expansion:
+  {?} >= {?}
+
 -------------------------------------------------------------------------------
 #748 - captures with unexpected exceptions
   outside assertions
@@ -257,6 +299,6 @@ with expansion:
   !true
 
 ===============================================================================
-test cases: 10 |  7 passed | 1 failed | 2 failed as expected
-assertions: 28 | 21 passed | 4 failed | 3 failed as expected
+test cases: 11 |  8 passed | 1 failed | 2 failed as expected
+assertions: 34 | 27 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 c7d422a8..136f8d38 100644
--- a/projects/SelfTest/Baselines/junit.sw.approved.txt
+++ b/projects/SelfTest/Baselines/junit.sw.approved.txt
@@ -1,10 +1,11 @@
 <?xml version="1.0" encoding="UTF-8"?>
 <testsuitesloose text artifact
 >
-  <testsuite name="<exe-name>" errors="15" failures="94" tests="983" hostname="tbd" time="{duration}" timestamp="{iso8601-timestamp}">
+  <testsuite name="<exe-name>" errors="15" failures="94" tests="989" 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}"/>
+    <testcase classname="<exe-name>.global" name="#1147" 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 18823424..e5759ee8 100644
--- a/projects/SelfTest/Baselines/xml.sw.approved.txt
+++ b/projects/SelfTest/Baselines/xml.sw.approved.txt
@@ -42,6 +42,57 @@
       </Expression>
       <OverallResult success="true"/>
     </TestCase>
+    <TestCase name="#1147" filename="projects/<exe-name>/UsageTests/Compilation.tests.cpp" >
+      <Expression success="true" type="REQUIRE" filename="projects/<exe-name>/UsageTests/Compilation.tests.cpp" >
+        <Original>
+          t1 == t2
+        </Original>
+        <Expanded>
+          {?} == {?}
+        </Expanded>
+      </Expression>
+      <Expression success="true" type="REQUIRE" filename="projects/<exe-name>/UsageTests/Compilation.tests.cpp" >
+        <Original>
+          t1 != t2
+        </Original>
+        <Expanded>
+          {?} != {?}
+        </Expanded>
+      </Expression>
+      <Expression success="true" type="REQUIRE" filename="projects/<exe-name>/UsageTests/Compilation.tests.cpp" >
+        <Original>
+          t1 &lt; t2
+        </Original>
+        <Expanded>
+          {?} &lt; {?}
+        </Expanded>
+      </Expression>
+      <Expression success="true" type="REQUIRE" filename="projects/<exe-name>/UsageTests/Compilation.tests.cpp" >
+        <Original>
+          t1 > t2
+        </Original>
+        <Expanded>
+          {?} > {?}
+        </Expanded>
+      </Expression>
+      <Expression success="true" type="REQUIRE" filename="projects/<exe-name>/UsageTests/Compilation.tests.cpp" >
+        <Original>
+          t1 &lt;= t2
+        </Original>
+        <Expanded>
+          {?} &lt;= {?}
+        </Expanded>
+      </Expression>
+      <Expression success="true" type="REQUIRE" filename="projects/<exe-name>/UsageTests/Compilation.tests.cpp" >
+        <Original>
+          t1 >= t2
+        </Original>
+        <Expanded>
+          {?} >= {?}
+        </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>
@@ -9168,7 +9219,7 @@ loose text artifact
       </Section>
       <OverallResult success="true"/>
     </TestCase>
-    <OverallResults successes="853" failures="109" expectedFailures="21"/>
+    <OverallResults successes="859" failures="109" expectedFailures="21"/>
   </Group>
-  <OverallResults successes="853" failures="108" expectedFailures="21"/>
+  <OverallResults successes="859" failures="108" expectedFailures="21"/>
 </Catch>
diff --git a/projects/SelfTest/UsageTests/Compilation.tests.cpp b/projects/SelfTest/UsageTests/Compilation.tests.cpp
index f140e3e8..9075743a 100644
--- a/projects/SelfTest/UsageTests/Compilation.tests.cpp
+++ b/projects/SelfTest/UsageTests/Compilation.tests.cpp
@@ -12,6 +12,19 @@ namespace { namespace CompilationTests {
 #ifndef COMPILATION_TEST_HELPERS_INCLUDED // Don't compile this more than once per TU
 #define COMPILATION_TEST_HELPERS_INCLUDED
 
+    // Comparison operators can return non-booleans.
+    // This is unusual, but should be supported.
+    struct logic_t {
+        logic_t operator< (logic_t) const { return {}; }
+        logic_t operator<=(logic_t) const { return {}; }
+        logic_t operator> (logic_t) const { return {}; }
+        logic_t operator>=(logic_t) const { return {}; }
+        logic_t operator==(logic_t) const { return {}; }
+        logic_t operator!=(logic_t) const { return {}; }
+        explicit operator bool() const { return true; }
+    };
+
+
 // This is a minimal example for an issue we have found in 1.7.0
     struct foo {
         int i;
@@ -109,4 +122,16 @@ namespace { namespace CompilationTests {
         REQUIRE(0 == y.v);
     }
 
+    // Comparison operators can return non-booleans.
+    // This is unusual, but should be supported.
+    TEST_CASE("#1147") {
+        logic_t t1, t2;
+        REQUIRE(t1 == t2);
+        REQUIRE(t1 != t2);
+        REQUIRE(t1 <  t2);
+        REQUIRE(t1 >  t2);
+        REQUIRE(t1 <= t2);
+        REQUIRE(t1 >= t2);
+    }
+
 }} // namespace CompilationTests