6#ifndef MIMICPP_REPORTER_HPP
7#define MIMICPP_REPORTER_HPP
76 std::vector<MatchReport> matchReports
93 std::vector<MatchReport> matchReports
146 std::exception_ptr exception
159 template <
typename Data = std::
nullptr_t>
161 :
public std::runtime_error
166 const std::string& what,
167 Data&&
data = Data{},
168 const std::source_location& loc = std::source_location::current()
170 : std::runtime_error{what},
171 m_Data{std::move(
data)},
177 const Data&
data() const noexcept
183 const std::source_location&
where() const noexcept
190 std::source_location m_Loc;
200 std::invocable<const StringT&>
auto successReporter,
201 std::invocable<const StringT&>
auto warningReporter,
202 std::invocable<const StringT&>
auto failReporter
212 ss <<
"No match for ";
214 std::ostreambuf_iterator{ss},
218 if (std::ranges::empty(matchReports))
220 ss <<
"No expectations available.\n";
225 std::ostreambuf_iterator{ss},
226 "{} available expectation(s):\n",
227 std::ranges::size(matchReports));
229 for (
const auto& report : matchReports)
232 std::ostreambuf_iterator{ss},
238 send_fail(std::move(ss).str());
245 ss <<
"No applicable match for ";
247 std::ostreambuf_iterator{ss},
251 ss <<
"Tested expectations:\n";
252 for (
const auto& report : matchReports)
255 std::ostreambuf_iterator{ss},
260 send_fail(std::move(ss).str());
266 ss <<
"Found match for ";
268 std::ostreambuf_iterator{ss},
273 std::ostreambuf_iterator{ss},
277 send_success(std::move(ss).str());
282 if (0 == std::uncaught_exceptions())
285 ss <<
"Unfulfilled expectation:\n";
287 std::ostreambuf_iterator{ss},
291 send_fail(std::move(ss).str());
297 if (0 == std::uncaught_exceptions())
306 const std::exception_ptr exception
310 ss <<
"Unhandled exception: ";
314 std::rethrow_exception(exception);
316 catch (
const std::exception& e)
324 ss <<
"Unknown exception type.\n";
327 ss <<
"while checking expectation:\n";
329 std::ostreambuf_iterator{ss},
335 std::ostreambuf_iterator{ss},
339 send_warning(std::move(ss).str());
343 void send_success(
const StringT& msg)
345 std::invoke(successReporter, msg);
348 void send_warning(
const StringT& msg)
350 std::invoke(warningReporter, msg);
354 void send_fail(
const StringT& msg)
357 std::invoke(failReporter, msg);
376 std::vector<MatchReport> matchReports
385 const std::source_location loc{call.
fromLoc};
388 {std::move(call), std::move(matchReports)},
396 std::vector<MatchReport> matchReports
405 const std::source_location loc{call.
fromLoc};
407 "No applicable match found.",
408 {std::move(call), std::move(matchReports)},
425 if (0 == std::uncaught_exceptions())
428 "Expectation is unfulfilled.",
429 std::move(expectationReport)
436 if (0 == std::uncaught_exceptions())
438 throw Error{message};
445 [[maybe_unused]] std::exception_ptr exception
456namespace mimicpp::detail
459 inline std::unique_ptr<IReporter>& get_reporter() noexcept
461 static std::unique_ptr<IReporter> reporter{
462 std::make_unique<DefaultReporter>()
468 inline void report_no_matches(
469 CallReport callReport,
470 std::vector<MatchReport> matchReports
477 std::move(callReport),
478 std::move(matchReports));
487 inline void report_inapplicable_matches(
488 CallReport callReport,
489 std::vector<MatchReport> matchReports
494 ->report_inapplicable_matches(
496 std::move(callReport),
497 std::move(matchReports));
505 inline void report_full_match(
506 CallReport callReport,
507 MatchReport matchReport
512 std::move(callReport),
513 std::move(matchReport));
516 inline void report_unfulfilled_expectation(
517 ExpectationReport expectationReport
521 ->report_unfulfilled_expectation(std::move(expectationReport));
524 inline void report_error(
StringT message)
527 ->report_error(std::move(message));
530 inline void report_unhandled_exception(
531 CallReport callReport,
532 ExpectationReport expectationReport,
533 const std::exception_ptr& exception
537 ->report_unhandled_exception(
538 std::move(callReport),
539 std::move(expectationReport),
554 template <std::derived_from<IReporter> T,
typename... Args>
555 requires std::constructible_from<T, Args...>
558 detail::get_reporter() = std::make_unique<T>(
559 std::forward<Args>(args)...);
564 template <
typename T>
565 class ReporterInstaller
568 template <
typename... Args>
569 explicit ReporterInstaller(Args&&... args)
572 std::forward<Args>(args)...);
A reporter, which creates text messages and reports them via the provided callbacks.
Definition Reporter.hpp:206
void report_error(const StringT message) override
Expects rather unspecific errors.
Definition Reporter.hpp:295
void report_full_match(const CallReport call, const MatchReport matchReport) noexcept override
Expects the report about a full matching expectation.
Definition Reporter.hpp:263
void report_unhandled_exception(const CallReport call, const ExpectationReport expectationReport, const std::exception_ptr exception) override
Expects reports about unhandled exceptions, during handle_call.
Definition Reporter.hpp:303
void report_unfulfilled_expectation(const ExpectationReport expectationReport) override
Expects the report of an unfulfilled expectation.
Definition Reporter.hpp:280
void report_no_matches(const CallReport call, const std::vector< MatchReport > matchReports) override
Expects reports about all none matching expectations. This is only called, if there are no better opt...
Definition Reporter.hpp:209
void report_inapplicable_matches(const CallReport call, const std::vector< MatchReport > matchReports) override
Expects reports about all inapplicable matching expectations. This is only called,...
Definition Reporter.hpp:242
Contains the extracted info from a typed call::Info.
Definition Reports.hpp:205
std::source_location fromLoc
Definition Reports.hpp:219
The default reporter.
Definition Reporter.hpp:371
void report_unhandled_exception(CallReport call, ExpectationReport expectationReport, std::exception_ptr exception) override
Expects reports about unhandled exceptions, during handle_call.
Definition Reporter.hpp:442
void report_no_matches(CallReport call, std::vector< MatchReport > matchReports) override
Expects reports about all none matching expectations. This is only called, if there are no better opt...
Definition Reporter.hpp:374
void report_error(StringT message) override
Expects rather unspecific errors.
Definition Reporter.hpp:434
void report_unfulfilled_expectation(ExpectationReport expectationReport) override
Expects the report of an unfulfilled expectation.
Definition Reporter.hpp:421
void report_full_match(CallReport call, MatchReport matchReport) noexcept override
Expects the report about a full matching expectation.
Definition Reporter.hpp:413
void report_inapplicable_matches(CallReport call, std::vector< MatchReport > matchReports) override
Expects reports about all inapplicable matching expectations. This is only called,...
Definition Reporter.hpp:394
Definition Reporter.hpp:162
Error(const std::string &what, Data &&data=Data{}, const std::source_location &loc=std::source_location::current())
Definition Reporter.hpp:165
const Data & data() const noexcept
Definition Reporter.hpp:177
const std::source_location & where() const noexcept
Definition Reporter.hpp:183
Contains the extracted info from a typed expectation.
Definition Reports.hpp:320
The reporter interface.
Definition Reporter.hpp:55
IReporter(const IReporter &)=default
virtual void report_unhandled_exception(CallReport call, ExpectationReport expectationReport, std::exception_ptr exception)=0
Expects reports about unhandled exceptions, during handle_call.
virtual void report_error(StringT message)=0
Expects rather unspecific errors.
virtual void report_no_matches(CallReport call, std::vector< MatchReport > matchReports)=0
Expects reports about all none matching expectations. This is only called, if there are no better opt...
virtual void report_full_match(CallReport call, MatchReport matchReport) noexcept=0
Expects the report about a full matching expectation.
virtual ~IReporter()=default
Defaulted virtual destructor.
IReporter(IReporter &&)=default
IReporter & operator=(const IReporter &)=default
virtual void report_unfulfilled_expectation(ExpectationReport expectationReport)=0
Expects the report of an unfulfilled expectation.
virtual void report_inapplicable_matches(CallReport call, std::vector< MatchReport > matchReports)=0
Expects reports about all inapplicable matching expectations. This is only called,...
Contains the detailed information for match outcomes.
Definition Reports.hpp:407
MatchResult evaluate_match_report(const MatchReport &report) noexcept
Determines, whether a match report actually denotes a full, inapplicable or no match.
Definition Reports.hpp:458
void install_reporter(Args &&... args)
Replaces the previous reporter with a newly constructed one.
Definition Reporter.hpp:556
constexpr detail::PrintFn print
Functional object, converting the given object to its textual representation.
Definition Printer.hpp:537
Definition BoostTest.hpp:20
void unreachable()
Invokes undefined behavior.
Definition Utility.hpp:93
std::basic_ostringstream< CharT, CharTraitsT > StringStreamT
Definition Printer.hpp:41
std::basic_string< CharT, CharTraitsT > StringT
Definition Fwd.hpp:112