mimic++ v10.0.1
Loading...
Searching...
No Matches
BasicReporter.hpp
Go to the documentation of this file.
1// Copyright Dominic (DNKpp) Koepke 2024 - 2026.
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_REPORTING_BASIC_REPORTER_HPP
7#define MIMICPP_REPORTING_BASIC_REPORTER_HPP
8
9#pragma once
10
11#include "mimic++/Fwd.hpp"
18
19#ifndef MIMICPP_DETAIL_IS_MODULE
20 #include <concepts>
21 #include <exception>
22 #include <utility>
23#endif
24
26{
33 template <
34 std::invocable<StringT const&> auto successReporter,
35 std::invocable<StringT const&> auto warningReporter,
36 std::invocable<StringT const&> auto failReporter>
38 : public IReporter
39 {
40 public:
41 [[noreturn]]
42 void report_no_matches(CallReport call, std::vector<MatchReport> noMatchReports) override
43 {
44 send_fail(stringify_no_matches(std::move(call), noMatchReports));
45 }
46
47 [[noreturn]]
48 void report_inapplicable_matches(CallReport call, std::vector<MatchReport> reports) override
49 {
50 send_fail(stringify_inapplicable_matches(std::move(call), reports));
51 }
52
53 void report_full_match(CallReport call, MatchReport report) noexcept override
54 {
55 send_success(stringify_full_match(std::move(call), std::move(report)));
56 }
57
58 void report_unfulfilled_expectation(ExpectationReport const expectationReport) override
59 {
60 if (0 == std::uncaught_exceptions())
61 {
62 send_fail(stringify_unfulfilled_expectation(expectationReport));
63 }
64 }
65
66 void report_error(StringT const message) override
67 {
68 if (0 == std::uncaught_exceptions())
69 {
70 send_fail(message);
71 }
72 }
73
75 CallReport const call,
76 ExpectationReport const expectationReport,
77 std::exception_ptr const exception) override
78 {
79 send_warning(stringify_unhandled_exception(call, expectationReport, exception));
80 }
81
82 private:
83 void send_success(StringT const& msg)
84 {
85 std::invoke(successReporter, msg);
86 }
87
88 void send_warning(StringT const& msg)
89 {
90 std::invoke(warningReporter, msg);
91 }
92
93 [[noreturn]]
94 void send_fail(StringT const& msg)
95 {
96 // GCOVR_EXCL_START
97 std::invoke(failReporter, msg);
99 // GCOVR_EXCL_STOP
100 }
101 };
102}
103
104#endif
#define MIMICPP_DETAIL_MODULE_EXPORT
Definition Config.hpp:19
A reporter, which creates text messages and reports them via the provided callbacks.
Definition BasicReporter.hpp:39
void report_unhandled_exception(CallReport const call, ExpectationReport const expectationReport, std::exception_ptr const exception) override
Handles reports about unhandled exceptions during handle_call.
Definition BasicReporter.hpp:74
void report_unfulfilled_expectation(ExpectationReport const expectationReport) override
Handles the report of an unfulfilled expectation.
Definition BasicReporter.hpp:58
void report_error(StringT const message) override
Handles general or unspecified errors.
Definition BasicReporter.hpp:66
void report_inapplicable_matches(CallReport call, std::vector< MatchReport > reports) override
Handles reports for all inapplicable but otherwise matching expectations. This function is called onl...
Definition BasicReporter.hpp:48
void report_full_match(CallReport call, MatchReport report) noexcept override
Handles the report for a fully matching expectation.
Definition BasicReporter.hpp:53
void report_no_matches(CallReport call, std::vector< MatchReport > noMatchReports) override
Expects reports on all non-matching expectations. This is only called when no better options are avai...
Definition BasicReporter.hpp:42
Contains the extracted info from a typed call::Info.
Definition CallReport.hpp:43
Contains the extracted info from a typed expectation.
Definition ExpectationReport.hpp:85
Contains the expectation-report and the match-results to a specific call.
Definition MatchReport.hpp:22
Definition Call.hpp:24
Definition BasicReporter.hpp:26
StringT stringify_full_match(CallReport const &call, MatchReport match)
Definition StringifyReports.hpp:317
StringT stringify_unhandled_exception(CallReport const &call, ExpectationReport const &expectationReport, std::exception_ptr const &exception)
Definition StringifyReports.hpp:471
StringT stringify_unfulfilled_expectation(ExpectationReport const &expectationReport)
Definition StringifyReports.hpp:455
StringT stringify_inapplicable_matches(CallReport const &call, std::span< MatchReport > reports)
Definition StringifyReports.hpp:354
StringT stringify_no_matches(CallReport const &call, std::span< MatchReport > noMatchReports)
Definition StringifyReports.hpp:394
void unreachable()
Invokes undefined behavior.
Definition C++23Backports.hpp:40
std::basic_string< CharT, CharTraitsT > StringT
Definition Fwd.hpp:397