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

summaryrefslogtreecommitdiffhomepage
path: root/projects/SelfTest/UsageTests/Compilation.tests.cpp
diff options
context:
space:
mode:
authorMartin Hořeňovský2020-04-21 11:00:08 +0200
committerMartin Hořeňovský2020-04-21 11:00:08 +0200
commit4e4171420d8c3ada47d8782f419908e47e2564ad (patch)
treea54f7e8b40a03c92943c254f4990d834910871cc /projects/SelfTest/UsageTests/Compilation.tests.cpp
parent37cbf4a4fe7a2963f8ae6d6fe998f8ac9360cbc0 (diff)
downloadcatch3-4e4171420d8c3ada47d8782f419908e47e2564ad.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 'projects/SelfTest/UsageTests/Compilation.tests.cpp')
-rw-r--r--projects/SelfTest/UsageTests/Compilation.tests.cpp28
1 files changed, 28 insertions, 0 deletions
diff --git a/projects/SelfTest/UsageTests/Compilation.tests.cpp b/projects/SelfTest/UsageTests/Compilation.tests.cpp
index 0baf2842..7ec17448 100644
--- a/projects/SelfTest/UsageTests/Compilation.tests.cpp
+++ b/projects/SelfTest/UsageTests/Compilation.tests.cpp
@@ -234,3 +234,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 });
+}
+