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

summaryrefslogtreecommitdiffhomepage
path: root/tests/ExtraTests
diff options
context:
space:
mode:
authorMartin Hořeňovský2026-05-10 23:05:46 +0200
committerMartin Hořeňovský2026-05-12 11:05:02 +0200
commit651247c7f40eda6846fec736d2f9edac8949dacb (patch)
tree76b4ef9f6d100c787f6b8af93779c43ea9524f67 /tests/ExtraTests
parent15b9393f0f32327e28833c5032b2c4e02c31d82c (diff)
downloadcatch3-651247c7f40eda6846fec736d2f9edac8949dacb.tar.gz
Support for constexpr matchers in C++20 (P0784)
To make this all work, I had to remove the stringification cache from matchers. In theory, this can cause performance penalty in cases where single matcher instance is stringified multiple times, but in practice this does not happen much, and the difference is surprisingly small anyway, because the performance of stringification is already horrible and full of allocating strings just to throw them away. The matcher combinators need P2738 from C++26 to be `constexpr`. Closes #3091
Diffstat (limited to 'tests/ExtraTests')
-rw-r--r--tests/ExtraTests/CMakeLists.txt2
-rw-r--r--tests/ExtraTests/X02-DisabledMacros.cpp2
-rw-r--r--tests/ExtraTests/X05-DeferredStaticChecks.cpp26
3 files changed, 29 insertions, 1 deletions
diff --git a/tests/ExtraTests/CMakeLists.txt b/tests/ExtraTests/CMakeLists.txt
index 886c059e..731bcf1c 100644
--- a/tests/ExtraTests/CMakeLists.txt
+++ b/tests/ExtraTests/CMakeLists.txt
@@ -174,7 +174,7 @@ target_compile_definitions(DeferredStaticChecks PRIVATE "CATCH_CONFIG_RUNTIME_ST
add_test(NAME DeferredStaticChecks COMMAND DeferredStaticChecks -r compact)
set_tests_properties(DeferredStaticChecks
PROPERTIES
- PASS_REGULAR_EXPRESSION "test cases: 1 \\| 1 failed\nassertions: 3 \\| 3 failed"
+ PASS_REGULAR_EXPRESSION "test cases: 1 \\| 1 failed\nassertions: 3 \\| 3 failed;test cases: 1 \\| 1 failed\nassertions: 4 \\| 4 failed"
)
add_executable(MixingClearedAndUnclearedMessages ${TESTS_DIR}/X06-MixingClearedAndUnclearedMessages.cpp)
diff --git a/tests/ExtraTests/X02-DisabledMacros.cpp b/tests/ExtraTests/X02-DisabledMacros.cpp
index 0c051acc..3449ab73 100644
--- a/tests/ExtraTests/X02-DisabledMacros.cpp
+++ b/tests/ExtraTests/X02-DisabledMacros.cpp
@@ -53,6 +53,8 @@ TEST_CASE( "Disabled Macros" ) {
REQUIRE_THAT( 1,
Catch::Matchers::Predicate( []( int ) { return false; } ) );
BENCHMARK( "Disabled benchmark" ) { REQUIRE( 1 == 2 ); };
+
+ STATIC_REQUIRE_THAT( 1, Catch::Matchers::Predicate( []( int ) { return false; } ) );
}
struct DisabledFixture {};
diff --git a/tests/ExtraTests/X05-DeferredStaticChecks.cpp b/tests/ExtraTests/X05-DeferredStaticChecks.cpp
index 8005dbcf..79ff35cc 100644
--- a/tests/ExtraTests/X05-DeferredStaticChecks.cpp
+++ b/tests/ExtraTests/X05-DeferredStaticChecks.cpp
@@ -12,10 +12,36 @@
*/
#include <catch2/catch_test_macros.hpp>
+#include <catch2/matchers/catch_matchers_templated.hpp>
+
+#if defined( CATCH_INTERNAL_CONSTEXPR_MATCHERS_ENABLED )
+
+namespace {
+ struct MatchNoneMatcher final : public Catch::Matchers::MatcherGenericBase {
+ public:
+ template <typename Any>
+ constexpr bool match( Any&& ) const {
+ return false;
+ }
+
+ std::string describe() const override {
+ using namespace std::string_literals;
+ return "Matches anything"s;
+ }
+ };
+
+ constexpr MatchNoneMatcher MatchNone() { return MatchNoneMatcher(); }
+
+} // namespace
+
+#endif
TEST_CASE("Deferred static checks") {
STATIC_CHECK(1 == 2);
STATIC_CHECK_FALSE(1 != 2);
+#if defined(CATCH_INTERNAL_CONSTEXPR_MATCHERS_ENABLED)
+ STATIC_CHECK_THAT(1, MatchNone());
+#endif
// This last assertion must be executed too
CHECK(1 == 2);
}