From 5b8cccaf6a9f16267ac61449a65b2df77d82d886 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Martin=20Ho=C5=99e=C5=88ovsk=C3=BD?= Date: Tue, 21 Apr 2020 19:27:12 +0200 Subject: [PATCH] Add support for bitwise xor to the decomposer --- src/catch2/internal/catch_decomposer.hpp | 4 ++++ .../Baselines/compact.sw.approved.txt | 2 ++ .../Baselines/console.std.approved.txt | 2 +- .../Baselines/console.sw.approved.txt | 12 ++++++++++- .../SelfTest/Baselines/junit.sw.approved.txt | 2 +- tests/SelfTest/Baselines/tap.sw.approved.txt | 6 +++++- tests/SelfTest/Baselines/xml.sw.approved.txt | 20 +++++++++++++++++-- .../SelfTest/UsageTests/Compilation.tests.cpp | 5 +++++ 8 files changed, 47 insertions(+), 6 deletions(-) diff --git a/src/catch2/internal/catch_decomposer.hpp b/src/catch2/internal/catch_decomposer.hpp index 814824c6..260a3f78 100644 --- a/src/catch2/internal/catch_decomposer.hpp +++ b/src/catch2/internal/catch_decomposer.hpp @@ -216,6 +216,10 @@ namespace Catch { auto operator & (RhsT const& rhs) -> BinaryExpr const { return { static_cast(m_lhs & rhs), m_lhs, "&", rhs }; } + template + auto operator ^ (RhsT const& rhs) -> BinaryExpr const { + return { static_cast(m_lhs ^ rhs), m_lhs, "^", rhs }; + } template auto operator && ( RhsT const& ) -> BinaryExpr const { diff --git a/tests/SelfTest/Baselines/compact.sw.approved.txt b/tests/SelfTest/Baselines/compact.sw.approved.txt index c965699f..d505f9b6 100644 --- a/tests/SelfTest/Baselines/compact.sw.approved.txt +++ b/tests/SelfTest/Baselines/compact.sw.approved.txt @@ -248,6 +248,8 @@ Matchers.tests.cpp:: passed: "This wouldn't pass", !Predicate: passed: lhs | rhs for: Val: 1 | Val: 2 Compilation.tests.cpp:: passed: !(lhs & rhs) for: !(Val: 1 & Val: 2) Compilation.tests.cpp:: passed: HasBitOperators{ 1 } & HasBitOperators{ 1 } for: Val: 1 & Val: 1 +Compilation.tests.cpp:: passed: lhs ^ rhs for: Val: 1 ^ Val: 2 +Compilation.tests.cpp:: passed: !(lhs ^ lhs) for: !(Val: 1 ^ Val: 1) Tricky.tests.cpp:: passed: true Tricky.tests.cpp:: passed: true Tricky.tests.cpp:: passed: true diff --git a/tests/SelfTest/Baselines/console.std.approved.txt b/tests/SelfTest/Baselines/console.std.approved.txt index 9c523a54..0fb3f0b2 100644 --- a/tests/SelfTest/Baselines/console.std.approved.txt +++ b/tests/SelfTest/Baselines/console.std.approved.txt @@ -1381,5 +1381,5 @@ due to unexpected exception with message: =============================================================================== test cases: 335 | 261 passed | 70 failed | 4 failed as expected -assertions: 1895 | 1743 passed | 131 failed | 21 failed as expected +assertions: 1897 | 1745 passed | 131 failed | 21 failed as expected diff --git a/tests/SelfTest/Baselines/console.sw.approved.txt b/tests/SelfTest/Baselines/console.sw.approved.txt index 1feae362..6818786f 100644 --- a/tests/SelfTest/Baselines/console.sw.approved.txt +++ b/tests/SelfTest/Baselines/console.sw.approved.txt @@ -1964,6 +1964,16 @@ Compilation.tests.cpp:: PASSED: with expansion: Val: 1 & Val: 1 +Compilation.tests.cpp:: PASSED: + REQUIRE( lhs ^ rhs ) +with expansion: + Val: 1 ^ Val: 2 + +Compilation.tests.cpp:: PASSED: + REQUIRE_FALSE( lhs ^ lhs ) +with expansion: + !(Val: 1 ^ Val: 1) + ------------------------------------------------------------------------------- Assertions then sections ------------------------------------------------------------------------------- @@ -14795,5 +14805,5 @@ Misc.tests.cpp:: PASSED: =============================================================================== test cases: 335 | 245 passed | 86 failed | 4 failed as expected -assertions: 1912 | 1743 passed | 148 failed | 21 failed as expected +assertions: 1914 | 1745 passed | 148 failed | 21 failed as expected diff --git a/tests/SelfTest/Baselines/junit.sw.approved.txt b/tests/SelfTest/Baselines/junit.sw.approved.txt index b2d601e9..26044c54 100644 --- a/tests/SelfTest/Baselines/junit.sw.approved.txt +++ b/tests/SelfTest/Baselines/junit.sw.approved.txt @@ -1,7 +1,7 @@ - + diff --git a/tests/SelfTest/Baselines/tap.sw.approved.txt b/tests/SelfTest/Baselines/tap.sw.approved.txt index 9d6eedb3..f7a5aeb7 100644 --- a/tests/SelfTest/Baselines/tap.sw.approved.txt +++ b/tests/SelfTest/Baselines/tap.sw.approved.txt @@ -494,6 +494,10 @@ ok {test-number} - lhs | rhs for: Val: 1 | Val: 2 ok {test-number} - !(lhs & rhs) for: !(Val: 1 & Val: 2) # Assertion macros support bit operators and bool conversions ok {test-number} - HasBitOperators{ 1 } & HasBitOperators{ 1 } for: Val: 1 & Val: 1 +# Assertion macros support bit operators and bool conversions +ok {test-number} - lhs ^ rhs for: Val: 1 ^ Val: 2 +# Assertion macros support bit operators and bool conversions +ok {test-number} - !(lhs ^ lhs) for: !(Val: 1 ^ Val: 1) # Assertions then sections ok {test-number} - true # Assertions then sections @@ -3816,5 +3820,5 @@ ok {test-number} - q3 == 23. for: 23.0 == 23.0 ok {test-number} - # xmlentitycheck ok {test-number} - -1..1904 +1..1906 diff --git a/tests/SelfTest/Baselines/xml.sw.approved.txt b/tests/SelfTest/Baselines/xml.sw.approved.txt index eb2b2593..70de0b73 100644 --- a/tests/SelfTest/Baselines/xml.sw.approved.txt +++ b/tests/SelfTest/Baselines/xml.sw.approved.txt @@ -2208,6 +2208,22 @@ Nor would this Val: 1 & Val: 1 + + + lhs ^ rhs + + + Val: 1 ^ Val: 2 + + + + + !(lhs ^ lhs) + + + !(Val: 1 ^ Val: 1) + + @@ -17759,7 +17775,7 @@ loose text artifact - + - + diff --git a/tests/SelfTest/UsageTests/Compilation.tests.cpp b/tests/SelfTest/UsageTests/Compilation.tests.cpp index 4fc63fa0..9e4211ff 100644 --- a/tests/SelfTest/UsageTests/Compilation.tests.cpp +++ b/tests/SelfTest/UsageTests/Compilation.tests.cpp @@ -247,6 +247,9 @@ namespace { friend HasBitOperators operator& (HasBitOperators lhs, HasBitOperators rhs) { return { lhs.value & rhs.value }; } + friend HasBitOperators operator^ (HasBitOperators lhs, HasBitOperators rhs) { + return { lhs.value ^ rhs.value }; + } explicit operator bool() const { return !!value; } @@ -263,5 +266,7 @@ TEST_CASE("Assertion macros support bit operators and bool conversions", "[compi REQUIRE(lhs | rhs); REQUIRE_FALSE(lhs & rhs); REQUIRE(HasBitOperators{ 1 } & HasBitOperators{ 1 }); + REQUIRE(lhs ^ rhs); + REQUIRE_FALSE(lhs ^ lhs); }