6#ifndef MIMICPP_REPORTING_GLOBAL_REPORTER_HPP
7#define MIMICPP_REPORTING_GLOBAL_REPORTER_HPP
19#ifndef MIMICPP_DETAIL_IS_MODULE
27namespace mimicpp::reporting::detail
29#ifdef __cpp_lib_atomic_shared_ptr
32 inline std::atomic<std::shared_ptr<IReporter>>& reporter() noexcept
34 static std::atomic<std::shared_ptr<IReporter>> reporter{
35 std::make_shared<DefaultReporter>(std::cerr)};
39 inline void set_reporter(std::shared_ptr<IReporter> newReporter)
noexcept
41 reporter().store(std::move(newReporter));
45 inline std::shared_ptr<IReporter> get_reporter() noexcept
47 return reporter().load();
53 inline std::shared_ptr<IReporter>* reporter() noexcept
55 static std::shared_ptr<IReporter> reporter{
56 std::make_shared<DefaultReporter>(std::cerr)};
57 return std::addressof(reporter);
60 inline void set_reporter(std::shared_ptr<IReporter> newReporter)
62 std::atomic_store(reporter(), std::move(newReporter));
66 inline std::shared_ptr<IReporter> get_reporter() noexcept
68 return std::atomic_load(reporter());
74 inline void report_no_matches(
75 CallReport callReport,
76 std::vector<NoMatchReport> noMatchReports)
82 std::move(callReport),
83 std::move(noMatchReports));
92 inline void report_inapplicable_matches(
93 CallReport callReport,
94 std::vector<ExpectationReport> expectationReports)
98 ->report_inapplicable_matches(
100 std::move(callReport),
101 std::move(expectationReports));
109 inline void report_full_match(
110 CallReport callReport,
111 ExpectationReport expectationReport)
noexcept
115 std::move(callReport),
116 std::move(expectationReport));
119 inline void report_unfulfilled_expectation(
120 ExpectationReport expectationReport)
123 ->report_unfulfilled_expectation(std::move(expectationReport));
126 inline void report_error(
StringT message)
129 ->report_error(std::move(message));
132 inline void report_unhandled_exception(
133 CallReport callReport,
134 ExpectationReport expectationReport,
135 std::exception_ptr
const& exception)
138 ->report_unhandled_exception(
139 std::move(callReport),
140 std::move(expectationReport),
155 template <std::derived_from<IReporter> T,
typename... Args>
156 requires std::constructible_from<T, Args...>
159 detail::set_reporter(
160 std::make_shared<T>(std::forward<Args>(args)...));
165 template <
typename T>
166 class ReporterInstaller
169 template <
typename... Args>
170 explicit ReporterInstaller(Args&&... args)
173 std::forward<Args>(args)...);
#define MIMICPP_DETAIL_MODULE_EXPORT
Definition Config.hpp:19
void install_reporter(Args &&... args)
Replaces the previous reporter with a newly constructed one.
Definition GlobalReporter.hpp:157
Definition BasicReporter.hpp:27
void unreachable()
Invokes undefined behavior.
Definition C++23Backports.hpp:40
std::basic_string< CharT, CharTraitsT > StringT
Definition Fwd.hpp:391