mimic++
v10.0.1
Toggle main menu visibility
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
#if __has_include("mimic++/Reporting.hpp")
12
#include "
mimic++/Reporting.hpp
"
13
#include "
mimic++/utilities/C++23Backports.hpp
"
14
#elif not defined(MIMICPP_VERSION)
15
#error "It appears that the test-adapter is not included in the mimic++ project or package." \
16
"If you plan to use it alongside the mimic++-amalgamated header, please ensure to include the adapter-header afterwards."
17
#endif
18
19
#if __has_include(<catch2/catch_test_macros.hpp>)
20
#include <catch2/catch_test_macros.hpp>
21
#else
22
#error "Unable to find catch2 includes."
23
#endif
24
25
namespace
mimicpp::reporting::detail::catch2
26
{
27
inline
void
send_success(
StringViewT
const
msg)
28
{
29
#ifdef CATCH_CONFIG_PREFIX_ALL
30
CATCH_SUCCEED(msg);
31
#else
32
SUCCEED(msg);
33
#endif
34
}
35
36
inline
void
send_warning(
StringViewT
const
msg)
37
{
38
#ifdef CATCH_CONFIG_PREFIX_MESSAGES
39
CATCH_WARN(msg);
40
#else
41
WARN(msg);
42
#endif
43
}
44
45
[[noreturn]]
46
inline
void
send_fail(
StringViewT
const
msg)
47
{
48
/* This is a workaround because when there is a `noexcept` function somewhere in the current call-stack,
49
* the error message will not be flushed to the actual output before the process termination.
50
* So, we catch it here, write another message which seems to flush the current content,
51
* so *mimic++* users can see the actual error-description.
52
*/
53
CATCH_TRY
54
{
55
#ifdef CATCH_CONFIG_PREFIX_ALL
56
CATCH_FAIL(msg);
57
#else
58
FAIL(msg);
59
#endif
60
}
61
CATCH_CATCH_ANON(Catch::TestFailureException
const
&)
62
{
63
send_warning(
"Fatal failure!"
);
64
throw
;
65
}
66
}
67
}
68
69
namespace
mimicpp::reporting
70
{
71
// GCOVR_EXCL_START
72
87
using
Catch2ReporterT
=
BasicReporter
<
88
&detail::catch2::send_success,
89
&detail::catch2::send_warning,
90
&detail::catch2::send_fail>;
91
92
// GCOVR_EXCL_STOP
93
}
94
95
namespace
mimicpp::reporting::detail::catch2
96
{
97
[[maybe_unused]]
98
inline
const
ReporterInstaller<Catch2ReporterT> installer{};
99
}
100
101
#ifdef MIMICPP_CONFIG_EXPERIMENTAL_CATCH2_MATCHER_INTEGRATION
102
103
#include <catch2/matchers/catch_matchers_templated.hpp>
104
105
template
<
typename
Matcher>
106
requires
std::derived_from<Matcher, Catch::Matchers::MatcherGenericBase>
// new style
107
|| std::derived_from<Matcher, Catch::Matchers::MatcherUntypedBase>
// old style
108
struct
mimicpp::custom::matcher_traits
<Matcher>
109
{
110
template
<
typename
T>
111
[[nodiscard]]
112
static
constexpr
bool
matches(
const
Matcher& matcher, T& value)
113
requires
requires
{ { matcher.match(value) } -> std::convertible_to<bool>; }
114
{
115
return
matcher.match(value);
116
}
117
};
118
119
#endif
120
121
#endif
Reporting.hpp
mimicpp::reporting::BasicReporter
A reporter, which creates text messages and reports them via the provided callbacks.
Definition
BasicReporter.hpp:39
mimicpp::reporting::Catch2ReporterT
BasicReporter< &detail::catch2::send_success, &detail::catch2::send_warning, &detail::catch2::send_fail > Catch2ReporterT
Reporter for the integration into Catch2.
Definition
Catch2.hpp:87
mimicpp::reporting
Definition
BasicReporter.hpp:26
mimicpp::StringViewT
std::basic_string_view< CharT, CharTraitsT > StringViewT
Definition
Fwd.hpp:398
mimicpp::custom::matcher_traits
Definition
Common.hpp:27
C++23Backports.hpp
mimic++_ext
adapters
Catch2.hpp
Generated on
for mimic++ by
1.18.0