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

Changed rhs expression capture from universal ref to const ref.

- addresses #1027
Commit
c2b7bd15c092e2528f52bf26046e3c55ca629392
Author
Phil Nash ·
Parents
ba6845a865c6

Files · Download .tar.gz

Changes

 include/internal/catch_decomposer.h                | 26 +++++++++++-----------
 .../SelfTest/Baselines/console.std.approved.txt    |  4 ++--
 .../SelfTest/Baselines/console.sw.approved.txt     | 22 ++++++++++++++++--
 projects/SelfTest/Baselines/junit.sw.approved.txt  |  3 ++-
 projects/SelfTest/Baselines/xml.sw.approved.txt    | 23 +++++++++++++++++--
 projects/SelfTest/TrickyTests.cpp                  | 11 ++++++++-
 6 files changed, 68 insertions(+), 21 deletions(-)

diff --git a/include/internal/catch_decomposer.h b/include/internal/catch_decomposer.h
index 786a052e..fee24e72 100644
--- a/include/internal/catch_decomposer.h
+++ b/include/internal/catch_decomposer.h
@@ -77,7 +77,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&& rhs ) -> bool { return lhs == rhs; };
+    auto compareEqual( LhsT const& lhs, RhsT const& rhs ) -> bool { return lhs == rhs; };
     template<typename T>
     auto compareEqual( T* const& lhs, int rhs ) -> bool { return lhs == reinterpret_cast<void const*>( rhs ); }
     template<typename T>
@@ -106,36 +106,36 @@ namespace Catch {
         ExprLhs( LhsT lhs ) : m_lhs( lhs ) {}
 
         template<typename RhsT>
-        auto operator == ( RhsT&& rhs ) -> BinaryExpr<LhsT, RhsT&> const {
-            return BinaryExpr<LhsT, RhsT&>( compareEqual( m_lhs, rhs ), m_lhs, "==", rhs );
+        auto operator == ( RhsT const& rhs ) -> BinaryExpr<LhsT, RhsT const&> const {
+            return BinaryExpr<LhsT, RhsT const&>( compareEqual( m_lhs, rhs ), m_lhs, "==", rhs );
         }
         auto operator == ( bool rhs ) -> BinaryExpr<LhsT, bool> const {
             return BinaryExpr<LhsT, bool>( m_lhs == rhs, m_lhs, "==", rhs );
         }
 
         template<typename RhsT>
-        auto operator != ( RhsT&& rhs ) -> BinaryExpr<LhsT, RhsT&> const {
-            return BinaryExpr<LhsT, RhsT&>( compareNotEqual( m_lhs, rhs ), m_lhs, "!=", rhs );
+        auto operator != ( RhsT const& rhs ) -> BinaryExpr<LhsT, RhsT const&> const {
+            return BinaryExpr<LhsT, RhsT const&>( compareNotEqual( m_lhs, rhs ), m_lhs, "!=", rhs );
         }
         auto operator != ( bool rhs ) -> BinaryExpr<LhsT, bool> const {
             return BinaryExpr<LhsT, bool>( m_lhs != rhs, m_lhs, "!=", rhs );
         }
 
         template<typename RhsT>
-        auto operator > ( RhsT&& rhs ) -> BinaryExpr<LhsT, RhsT&> const {
-            return BinaryExpr<LhsT, RhsT&>( m_lhs > rhs, m_lhs, ">", rhs );
+        auto operator > ( RhsT const& rhs ) -> BinaryExpr<LhsT, RhsT const&> const {
+            return BinaryExpr<LhsT, RhsT const&>( m_lhs > rhs, m_lhs, ">", rhs );
         }
         template<typename RhsT>
-        auto operator < ( RhsT&& rhs ) -> BinaryExpr<LhsT, RhsT&> const {
-            return BinaryExpr<LhsT, RhsT&>( m_lhs < rhs, m_lhs, "<", rhs );
+        auto operator < ( RhsT const& rhs ) -> BinaryExpr<LhsT, RhsT const&> const {
+            return BinaryExpr<LhsT, RhsT const&>( m_lhs < rhs, m_lhs, "<", rhs );
         }
         template<typename RhsT>
-        auto operator >= ( RhsT&& rhs ) -> BinaryExpr<LhsT, RhsT&> const {
-            return BinaryExpr<LhsT, RhsT&>( m_lhs >= rhs, m_lhs, ">=", rhs );
+        auto operator >= ( RhsT const& rhs ) -> BinaryExpr<LhsT, RhsT const&> const {
+            return BinaryExpr<LhsT, RhsT const&>( m_lhs >= rhs, m_lhs, ">=", rhs );
         }
         template<typename RhsT>
-        auto operator <= ( RhsT&& rhs ) -> BinaryExpr<LhsT, RhsT&> const {
-            return BinaryExpr<LhsT, RhsT&>( m_lhs <= rhs, m_lhs, "<=", rhs );
+        auto operator <= ( RhsT const& rhs ) -> BinaryExpr<LhsT, RhsT const&> const {
+            return BinaryExpr<LhsT, RhsT const&>( m_lhs <= rhs, m_lhs, "<=", rhs );
         }
 
         auto makeUnaryExpr() const -> UnaryExpr<LhsT> {
diff --git a/projects/SelfTest/Baselines/console.std.approved.txt b/projects/SelfTest/Baselines/console.std.approved.txt
index 6aaa7ed1..939d0d89 100644
--- a/projects/SelfTest/Baselines/console.std.approved.txt
+++ b/projects/SelfTest/Baselines/console.std.approved.txt
@@ -1003,6 +1003,6 @@ with expansion:
   "{?}" == "1"
 
 ===============================================================================
-test cases: 179 | 128 passed | 47 failed |  4 failed as expected
-assertions: 884 | 767 passed | 96 failed | 21 failed as expected
+test cases: 180 | 129 passed | 47 failed |  4 failed as expected
+assertions: 886 | 769 passed | 96 failed | 21 failed as expected
 
diff --git a/projects/SelfTest/Baselines/console.sw.approved.txt b/projects/SelfTest/Baselines/console.sw.approved.txt
index 10b6fc35..1d64df20 100644
--- a/projects/SelfTest/Baselines/console.sw.approved.txt
+++ b/projects/SelfTest/Baselines/console.sw.approved.txt
@@ -738,6 +738,24 @@ PASSED:
 with expansion:
   true
 
+-------------------------------------------------------------------------------
+Bitfields can be captured (#1027)
+-------------------------------------------------------------------------------
+TrickyTests.cpp:<line number>
+...............................................................................
+
+TrickyTests.cpp:<line number>:
+PASSED:
+  REQUIRE( y.v == 0 )
+with expansion:
+  0 == 0
+
+TrickyTests.cpp:<line number>:
+PASSED:
+  REQUIRE( 0 == y.v )
+with expansion:
+  0 == 0
+
 -------------------------------------------------------------------------------
 Capture and info messages
   Capture should stringify like assertions
@@ -7490,6 +7508,6 @@ MiscTests.cpp:<line number>:
 PASSED:
 
 ===============================================================================
-test cases: 179 | 126 passed | 49 failed |  4 failed as expected
-assertions: 883 | 763 passed | 99 failed | 21 failed as expected
+test cases: 180 | 127 passed | 49 failed |  4 failed as expected
+assertions: 885 | 765 passed | 99 failed | 21 failed as expected
 
diff --git a/projects/SelfTest/Baselines/junit.sw.approved.txt b/projects/SelfTest/Baselines/junit.sw.approved.txt
index b306b393..508b9206 100644
--- a/projects/SelfTest/Baselines/junit.sw.approved.txt
+++ b/projects/SelfTest/Baselines/junit.sw.approved.txt
@@ -1,7 +1,7 @@
 <?xml version="1.0" encoding="UTF-8"?>
 <testsuitesloose text artifact
 >
-  <testsuite name="<exe-name>" errors="15" failures="85" tests="884" hostname="tbd" time="{duration}" timestamp="{iso8601-timestamp}">
+  <testsuite name="<exe-name>" errors="15" failures="85" tests="886" 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="#748 - captures with unexpected exceptions/outside assertions" time="{duration}">
@@ -109,6 +109,7 @@ ExceptionTests.cpp:<line number>
     <testcase classname="<exe-name>.global" name="Assertions then sections/A section" time="{duration}"/>
     <testcase classname="<exe-name>.global" name="Assertions then sections/A section/Another section" time="{duration}"/>
     <testcase classname="<exe-name>.global" name="Assertions then sections/A section/Another other section" time="{duration}"/>
+    <testcase classname="<exe-name>.global" name="Bitfields can be captured (#1027)" time="{duration}"/>
     <testcase classname="<exe-name>.global" name="Capture and info messages/Capture should stringify like assertions" time="{duration}"/>
     <testcase classname="<exe-name>.global" name="Capture and info messages/Info should NOT stringify the way assertions do" time="{duration}"/>
     <testcase classname="<exe-name>.global" name="Character pretty printing/Specifically escaped" time="{duration}"/>
diff --git a/projects/SelfTest/Baselines/xml.sw.approved.txt b/projects/SelfTest/Baselines/xml.sw.approved.txt
index da12285d..72b7c1b6 100644
--- a/projects/SelfTest/Baselines/xml.sw.approved.txt
+++ b/projects/SelfTest/Baselines/xml.sw.approved.txt
@@ -750,6 +750,25 @@
       </Section>
       <OverallResult success="true"/>
     </TestCase>
+    <TestCase name="Bitfields can be captured (#1027)" filename="projects/<exe-name>/TrickyTests.cpp" >
+      <Expression success="true" type="REQUIRE" filename="projects/<exe-name>/TrickyTests.cpp" >
+        <Original>
+          y.v == 0
+        </Original>
+        <Expanded>
+          0 == 0
+        </Expanded>
+      </Expression>
+      <Expression success="true" type="REQUIRE" filename="projects/<exe-name>/TrickyTests.cpp" >
+        <Original>
+          0 == y.v
+        </Original>
+        <Expanded>
+          0 == 0
+        </Expanded>
+      </Expression>
+      <OverallResult success="true"/>
+    </TestCase>
     <TestCase name="Capture and info messages" filename="projects/<exe-name>/ToStringGeneralTests.cpp" >
       <Section name="Capture should stringify like assertions" filename="projects/<exe-name>/ToStringGeneralTests.cpp" >
         <Info>
@@ -8268,7 +8287,7 @@ loose text artifact
       </Section>
       <OverallResult success="true"/>
     </TestCase>
-    <OverallResults successes="763" failures="100" expectedFailures="21"/>
+    <OverallResults successes="765" failures="100" expectedFailures="21"/>
   </Group>
-  <OverallResults successes="763" failures="99" expectedFailures="21"/>
+  <OverallResults successes="765" failures="99" expectedFailures="21"/>
 </Catch>
diff --git a/projects/SelfTest/TrickyTests.cpp b/projects/SelfTest/TrickyTests.cpp
index 78f7052f..820d2fbd 100644
--- a/projects/SelfTest/TrickyTests.cpp
+++ b/projects/SelfTest/TrickyTests.cpp
@@ -168,7 +168,7 @@ namespace ObjectWithConversions
 {
     struct Object
     {
-        operator unsigned int() {return 0xc0000000;}
+        operator unsigned int() const {return 0xc0000000;}
     };
 
     ///////////////////////////////////////////////////////////////////////////////
@@ -436,3 +436,12 @@ TEST_CASE("#925: comparing function pointer to function address failed to compil
     TestClass test;
     REQUIRE(utility::synchronizing_callback != test.testMethod_uponComplete_arg);
 }
+
+TEST_CASE( "Bitfields can be captured (#1027)" ) {
+    struct Y {
+        uint32_t v : 1;
+    };
+    Y y{ 0 };
+    REQUIRE( y.v == 0 );
+    REQUIRE( 0 == y.v );
+}