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 - auto compareEqual( LhsT const& lhs, RhsT const& rhs ) -> bool { return lhs == rhs; }; + auto compareEqual( LhsT const& lhs, RhsT const& rhs ) -> bool { return static_cast(lhs == rhs); }; template auto compareEqual( T* const& lhs, int rhs ) -> bool { return lhs == reinterpret_cast( rhs ); } template @@ -93,7 +93,7 @@ namespace Catch { auto compareEqual( long lhs, T* const& rhs ) -> bool { return reinterpret_cast( lhs ) == rhs; } template - auto compareNotEqual( LhsT const& lhs, RhsT&& rhs ) -> bool { return lhs != rhs; }; + auto compareNotEqual( LhsT const& lhs, RhsT&& rhs ) -> bool { return static_cast(lhs != rhs); }; template auto compareNotEqual( T* const& lhs, int rhs ) -> bool { return lhs != reinterpret_cast( rhs ); } template @@ -128,19 +128,19 @@ namespace Catch { template auto operator > ( RhsT const& rhs ) -> BinaryExpr const { - return { m_lhs > rhs, m_lhs, ">", rhs }; + return { static_cast(m_lhs > rhs), m_lhs, ">", rhs }; } template auto operator < ( RhsT const& rhs ) -> BinaryExpr const { - return { m_lhs < rhs, m_lhs, "<", rhs }; + return { static_cast(m_lhs < rhs), m_lhs, "<", rhs }; } template auto operator >= ( RhsT const& rhs ) -> BinaryExpr const { - return { m_lhs >= rhs, m_lhs, ">=", rhs }; + return { static_cast(m_lhs >= rhs), m_lhs, ">=", rhs }; } template auto operator <= ( RhsT const& rhs ) -> BinaryExpr const { - return { m_lhs <= rhs, m_lhs, "<=", rhs }; + return { static_cast(m_lhs <= rhs), m_lhs, "<=", rhs }; } auto makeUnaryExpr() const -> UnaryExpr { 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:: passed: fptr == 0 for: 0 == 0 Decomposition.tests.cpp:: passed: fptr == 0l for: 0 == 0 Compilation.tests.cpp:: passed: y.v == 0 for: 0 == 0 Compilation.tests.cpp:: passed: 0 == y.v for: 0 == 0 +Compilation.tests.cpp:: passed: t1 == t2 for: {?} == {?} +Compilation.tests.cpp:: passed: t1 != t2 for: {?} != {?} +Compilation.tests.cpp:: passed: t1 < t2 for: {?} < {?} +Compilation.tests.cpp:: passed: t1 > t2 for: {?} > {?} +Compilation.tests.cpp:: passed: t1 <= t2 for: {?} <= {?} +Compilation.tests.cpp:: passed: t1 >= t2 for: {?} >= {?} 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 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: +............................................................................... + +Compilation.tests.cpp:: +PASSED: + REQUIRE( t1 == t2 ) +with expansion: + {?} == {?} + +Compilation.tests.cpp:: +PASSED: + REQUIRE( t1 != t2 ) +with expansion: + {?} != {?} + +Compilation.tests.cpp:: +PASSED: + REQUIRE( t1 < t2 ) +with expansion: + {?} < {?} + +Compilation.tests.cpp:: +PASSED: + REQUIRE( t1 > t2 ) +with expansion: + {?} > {?} + +Compilation.tests.cpp:: +PASSED: + REQUIRE( t1 <= t2 ) +with expansion: + {?} <= {?} + +Compilation.tests.cpp:: +PASSED: + REQUIRE( t1 >= t2 ) +with expansion: + {?} >= {?} + ------------------------------------------------------------------------------- #748 - captures with unexpected exceptions outside assertions @@ -8246,6 +8288,6 @@ Misc.tests.cpp:: 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: +............................................................................... + +Compilation.tests.cpp:: +PASSED: + REQUIRE( t1 == t2 ) +with expansion: + {?} == {?} + +Compilation.tests.cpp:: +PASSED: + REQUIRE( t1 != t2 ) +with expansion: + {?} != {?} + +Compilation.tests.cpp:: +PASSED: + REQUIRE( t1 < t2 ) +with expansion: + {?} < {?} + +Compilation.tests.cpp:: +PASSED: + REQUIRE( t1 > t2 ) +with expansion: + {?} > {?} + +Compilation.tests.cpp:: +PASSED: + REQUIRE( t1 <= t2 ) +with expansion: + {?} <= {?} + +Compilation.tests.cpp:: +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 @@ - + + 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 @@ + + + + t1 == t2 + + + {?} == {?} + + + + + t1 != t2 + + + {?} != {?} + + + + + t1 < t2 + + + {?} < {?} + + + + + t1 > t2 + + + {?} > {?} + + + + + t1 <= t2 + + + {?} <= {?} + + + + + t1 >= t2 + + + {?} >= {?} + + + +
@@ -9168,7 +9219,7 @@ loose text artifact
- + - + 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