2021-11-15 20:05:12 +01:00
|
|
|
|
|
|
|
|
// Copyright Catch2 Authors
|
|
|
|
|
// Distributed under the Boost Software License, Version 1.0.
|
2022-10-28 11:22:53 +02:00
|
|
|
// (See accompanying file LICENSE.txt or copy at
|
2021-11-15 20:05:12 +01:00
|
|
|
// https://www.boost.org/LICENSE_1_0.txt)
|
|
|
|
|
|
|
|
|
|
// SPDX-License-Identifier: BSL-1.0
|
|
|
|
|
|
|
|
|
|
/**\file
|
|
|
|
|
* Checks that when `STATIC_CHECK` is deferred to runtime and fails, it
|
|
|
|
|
* does not abort the test case.
|
|
|
|
|
*/
|
|
|
|
|
|
|
|
|
|
#include <catch2/catch_test_macros.hpp>
|
2026-05-10 23:05:46 +02:00
|
|
|
#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
|
2021-11-15 20:05:12 +01:00
|
|
|
|
|
|
|
|
TEST_CASE("Deferred static checks") {
|
|
|
|
|
STATIC_CHECK(1 == 2);
|
|
|
|
|
STATIC_CHECK_FALSE(1 != 2);
|
2026-05-10 23:05:46 +02:00
|
|
|
#if defined(CATCH_INTERNAL_CONSTEXPR_MATCHERS_ENABLED)
|
|
|
|
|
STATIC_CHECK_THAT(1, MatchNone());
|
|
|
|
|
#endif
|
2021-11-15 20:05:12 +01:00
|
|
|
// This last assertion must be executed too
|
|
|
|
|
CHECK(1 == 2);
|
|
|
|
|
}
|