mimic++ v6
Loading...
Searching...
No Matches
Catch2.hpp
Go to the documentation of this file.
1// Copyright Dominic (DNKpp) Koepke 2024 - 2025.
2// Distributed under the Boost Software License, Version 1.0.
3// (See accompanying file LICENSE_1_0.txt or copy at
4// https://www.boost.org/LICENSE_1_0.txt)
5
6#ifndef MIMICPP_ADAPTERS_CATCH2_HPP
7#define MIMICPP_ADAPTERS_CATCH2_HPP
8
9#pragma once
10
11#include "mimic++/Reporter.hpp"
12
13#include <iterator>
14
15#if __has_include(<catch2/catch_test_macros.hpp>)
16 #include <catch2/catch_test_macros.hpp>
17#else
18 #error "Unable to find catch2 includes."
19#endif
20
21namespace mimicpp::detail::catch2
22{
23 [[noreturn]]
24 inline void send_fail(const StringViewT msg)
25 {
26#ifdef CATCH_CONFIG_PREFIX_ALL
27 CATCH_FAIL(msg);
28#else
29 FAIL(msg);
30#endif
31
33 }
34
35 inline void send_success(const StringViewT msg)
36 {
37#ifdef CATCH_CONFIG_PREFIX_ALL
38 CATCH_SUCCEED(msg);
39#else
40 SUCCEED(msg);
41#endif
42 }
43
44 inline void send_warning(const StringViewT msg)
45 {
46#ifdef CATCH_CONFIG_PREFIX_MESSAGES
47 CATCH_WARN(msg);
48#else
49 WARN(msg);
50#endif
51 }
52}
53
54namespace mimicpp
55{
56 // GCOVR_EXCL_START
57
73 &detail::catch2::send_success,
74 &detail::catch2::send_warning,
75 &detail::catch2::send_fail>;
76
77 // GCOVR_EXCL_STOP
78}
79
80namespace mimicpp::detail::catch2
81{
82 [[maybe_unused]]
83 inline const ReporterInstaller<Catch2ReporterT> installer{};
84}
85
86#ifdef MIMICPP_CONFIG_EXPERIMENTAL_CATCH2_MATCHER_INTEGRATION
87
88 #include <catch2/matchers/catch_matchers_templated.hpp>
89
90template <typename Matcher>
91 requires std::derived_from<Matcher, Catch::Matchers::MatcherGenericBase> // new style
92 || std::derived_from<Matcher, Catch::Matchers::MatcherUntypedBase> // old style
94{
95 template <typename T>
96 [[nodiscard]]
97 static constexpr bool matches(const Matcher& matcher, T& value)
98 requires requires { { matcher.match(value) } -> std::convertible_to<bool>; }
99 {
100 return matcher.match(value);
101 }
102};
103
104#endif
105
106#endif
A reporter, which creates text messages and reports them via the provided callbacks.
Definition Reporter.hpp:356
BasicReporter< &detail::catch2::send_success, &detail::catch2::send_warning, &detail::catch2::send_fail > Catch2ReporterT
Reporter for the integration into Catch2.
Definition Catch2.hpp:72
Definition BoostTest.hpp:20
void unreachable()
Invokes undefined behavior.
Definition Utility.hpp:91
std::basic_string_view< CharT, CharTraitsT > StringViewT
Definition Fwd.hpp:345
Definition Common.hpp:21