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

Fix & extend tests for comparing const instances of zero lit types

Commit
05fb437cbbf60de794a7101c5e6ef8f650755ce4
Author
Martin Hořeňovský ·
Parents
71b11c4e3328

Files · Download .tar.gz

Changes

 tests/SelfTest/UsageTests/Compilation.tests.cpp    | 28 +++++++++++++++-------
 .../helpers/type_with_lit_0_comparisons.hpp        | 22 ++++++++++-------
 2 files changed, 34 insertions(+), 16 deletions(-)

diff --git a/tests/SelfTest/UsageTests/Compilation.tests.cpp b/tests/SelfTest/UsageTests/Compilation.tests.cpp
index ebb2add6..a7fbf08f 100644
--- a/tests/SelfTest/UsageTests/Compilation.tests.cpp
+++ b/tests/SelfTest/UsageTests/Compilation.tests.cpp
@@ -405,14 +405,26 @@ TEST_CASE( "#2555 - types that can only be compared with 0 literal implemented a
 // have the ambiguity issue) for `==` and `!=`.
 TEST_CASE( "Comparing const instances of type registered with capture_by_value",
            "[regression][approvals][compilation]" ) {
-    auto const const_Lit0Type_1 = TypeWithLit0Comparisons{};
-    auto const const_Lit0Type_2 = TypeWithLit0Comparisons{};
-    REQUIRE( const_Lit0Type_1 == const_Lit0Type_2 );
-    REQUIRE( const_Lit0Type_1 <= const_Lit0Type_2 );
-    REQUIRE( const_Lit0Type_1 < const_Lit0Type_2 );
-    REQUIRE( const_Lit0Type_1 >= const_Lit0Type_2 );
-    REQUIRE( const_Lit0Type_1 > const_Lit0Type_2 );
-    REQUIRE_FALSE( const_Lit0Type_1 != const_Lit0Type_2 );
+    SECTION("Type with consteval-int constructor") {
+        auto const const_Lit0Type_1 = TypeWithConstevalLit0Comparison{};
+        auto const const_Lit0Type_2 = TypeWithConstevalLit0Comparison{};
+        REQUIRE( const_Lit0Type_1 == const_Lit0Type_2 );
+        REQUIRE( const_Lit0Type_1 <= const_Lit0Type_2 );
+        REQUIRE( const_Lit0Type_1 < const_Lit0Type_2 );
+        REQUIRE( const_Lit0Type_1 >= const_Lit0Type_2 );
+        REQUIRE( const_Lit0Type_1 > const_Lit0Type_2 );
+        REQUIRE( const_Lit0Type_1 != const_Lit0Type_2 );
+    }
+    SECTION("Type with constexpr-int constructor") {
+        auto const const_Lit0Type_1 = TypeWithLit0Comparisons{};
+        auto const const_Lit0Type_2 = TypeWithLit0Comparisons{};
+        REQUIRE( const_Lit0Type_1 == const_Lit0Type_2 );
+        REQUIRE( const_Lit0Type_1 <= const_Lit0Type_2 );
+        REQUIRE( const_Lit0Type_1 < const_Lit0Type_2 );
+        REQUIRE( const_Lit0Type_1 >= const_Lit0Type_2 );
+        REQUIRE( const_Lit0Type_1 > const_Lit0Type_2 );
+        REQUIRE( const_Lit0Type_1 != const_Lit0Type_2 );
+    }
 }
 
 #endif // C++20 consteval
diff --git a/tests/SelfTest/helpers/type_with_lit_0_comparisons.hpp b/tests/SelfTest/helpers/type_with_lit_0_comparisons.hpp
index 88d2f2a7..a8e517c0 100644
--- a/tests/SelfTest/helpers/type_with_lit_0_comparisons.hpp
+++ b/tests/SelfTest/helpers/type_with_lit_0_comparisons.hpp
@@ -26,14 +26,20 @@ struct ZeroLiteralAsPointer {
 
 
 struct TypeWithLit0Comparisons {
-#define DEFINE_COMP_OP( op )                                       \
-    constexpr friend bool operator op( TypeWithLit0Comparisons,    \
-                                       ZeroLiteralAsPointer ) {    \
-        return true;                                               \
-    }                                                              \
-    constexpr friend bool operator op( ZeroLiteralAsPointer,       \
-                                       TypeWithLit0Comparisons ) { \
-        return false;                                              \
+#define DEFINE_COMP_OP( op )                                          \
+    constexpr friend bool operator op( TypeWithLit0Comparisons,       \
+                                       ZeroLiteralAsPointer ) {       \
+        return true;                                                  \
+    }                                                                 \
+    constexpr friend bool operator op( ZeroLiteralAsPointer,          \
+                                       TypeWithLit0Comparisons ) {    \
+        return false;                                                 \
+    }                                                                 \
+    /* std::orderings only have these for ==, but we add them for all \
+       operators so we can test all overloads for decomposer */       \
+    constexpr friend bool operator op( TypeWithLit0Comparisons,       \
+                                       TypeWithLit0Comparisons ) {    \
+        return true;                                                  \
     }
 
     DEFINE_COMP_OP( < )