Read-only mirrors. Development, issues and pull requests are on GitHub.

summaryrefslogtreecommitdiffhomepage
path: root/tests/SelfTest/UsageTests
diff options
context:
space:
mode:
authorMartin Hořeňovský2020-04-21 11:00:08 +0200
committerMartin Hořeňovský2020-05-03 07:45:04 +0200
commit53434a2f320aa8c12f8df302d061e222077f52f9 (patch)
tree4c7ca4f7ea7043136e7246bb096892c4767356a8 /tests/SelfTest/UsageTests
parent2a93a65bc24c21102e46c5e102f0905f97a10ee5 (diff)
downloadcatch3-53434a2f320aa8c12f8df302d061e222077f52f9.tar.gz
Support bitand and bitor in REQUIRE/CHECK
This means that bit-flag-like types with conversion to bool can be asserted on, like so `REQUIRE(var & Flags::AddNewline)`.
Diffstat (limited to 'tests/SelfTest/UsageTests')
-rw-r--r--tests/SelfTest/UsageTests/Compilation.tests.cpp28
1 files changed, 28 insertions, 0 deletions
diff --git a/tests/SelfTest/UsageTests/Compilation.tests.cpp b/tests/SelfTest/UsageTests/Compilation.tests.cpp
index 5a0ab65e..4fc63fa0 100644
--- a/tests/SelfTest/UsageTests/Compilation.tests.cpp
+++ b/tests/SelfTest/UsageTests/Compilation.tests.cpp
@@ -237,3 +237,31 @@ namespace { namespace CompilationTests {
}} // namespace CompilationTests
+namespace {
+ struct HasBitOperators {
+ int value;
+
+ 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;
+ }
+
+ friend std::ostream& operator<<(std::ostream& out, HasBitOperators val) {
+ out << "Val: " << val.value;
+ return out;
+ }
+ };
+}
+
+TEST_CASE("Assertion macros support bit operators and bool conversions", "[compilation][bitops]") {
+ HasBitOperators lhs{ 1 }, rhs{ 2 };
+ REQUIRE(lhs | rhs);
+ REQUIRE_FALSE(lhs & rhs);
+ REQUIRE(HasBitOperators{ 1 } & HasBitOperators{ 1 });
+}
+