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(CallReport callReport, std::vector<MatchReport> noMatchReports)
77 ->report_no_matches(std::move(callReport), std::move(noMatchReports));
86 inline void report_inapplicable_matches(CallReport callReport, std::vector<MatchReport> reports)
89 ->report_inapplicable_matches(std::move(callReport), std::move(reports));
97 inline void report_full_match(CallReport callReport, MatchReport report)
noexcept
100 ->report_full_match(std::move(callReport), std::move(report));
103 inline void report_unfulfilled_expectation(ExpectationReport expectationReport)
106 ->report_unfulfilled_expectation(std::move(expectationReport));
109 inline void report_error(
StringT message)
112 ->report_error(std::move(message));
115 inline void report_unhandled_exception(CallReport callReport, ExpectationReport expectationReport, std::exception_ptr
const& exception)
118 ->report_unhandled_exception(std::move(callReport), std::move(expectationReport), exception);
132 template <std::derived_from<IReporter> T,
typename... Args>
133 requires std::constructible_from<T, Args...>
136 detail::set_reporter(
137 std::make_shared<T>(std::forward<Args>(args)...));
142 template <
typename T>
143 class ReporterInstaller
146 template <
typename... Args>
147 explicit ReporterInstaller(Args&&... args)
150 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:134
Definition BasicReporter.hpp:26
void unreachable()
Invokes undefined behavior.
Definition C++23Backports.hpp:40
std::basic_string< CharT, CharTraitsT > StringT
Definition Fwd.hpp:397