mimic++ v9.2.1
Loading...
Searching...
No Matches
BasicReporter.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_REPORTING_BASIC_REPORTER_HPP
7#define MIMICPP_REPORTING_BASIC_REPORTER_HPP
8
9#pragma once
10
11#include "mimic++/Fwd.hpp"
19
20#ifndef MIMICPP_DETAIL_IS_MODULE
21 #include <concepts>
22 #include <exception>
23 #include <utility>
24#endif
25
27{
34 template <
35 std::invocable<StringT const&> auto successReporter,
36 std::invocable<StringT const&> auto warningReporter,
37 std::invocable<StringT const&> auto failReporter>
39 : public IReporter
40 {
41 public:
42 [[noreturn]]
43 void report_no_matches(CallReport call, std::vector<NoMatchReport> noMatchReports) override
44 {
45 send_fail(stringify_no_matches(std::move(call), noMatchReports));
46 }
47
48 [[noreturn]]
49 void report_inapplicable_matches(CallReport call, std::vector<ExpectationReport> expectationReports) override
50 {
51 send_fail(stringify_inapplicable_matches(std::move(call), expectationReports));
52 }
53
54 void report_full_match(CallReport call, ExpectationReport expectationReport) noexcept override
55 {
56 send_success(stringify_full_match(std::move(call), std::move(expectationReport)));
57 }
58
59 void report_unfulfilled_expectation(const ExpectationReport expectationReport) override
60 {
61 if (0 == std::uncaught_exceptions())
62 {
63 send_fail(stringify_unfulfilled_expectation(expectationReport));
64 }
65 }
66
67 void report_error(StringT const message) override
68 {
69 if (0 == std::uncaught_exceptions())
70 {
71 send_fail(message);
72 }
73 }
74
76 CallReport const call,
77 ExpectationReport const expectationReport,
78 std::exception_ptr const exception) override
79 {
80 send_warning(stringify_unhandled_exception(call, expectationReport, exception));
81 }
82
83 private:
84 void send_success(StringT const& msg)
85 {
86 std::invoke(successReporter, msg);
87 }
88
89 void send_warning(StringT const& msg)
90 {
91 std::invoke(warningReporter, msg);
92 }
93
94 [[noreturn]]
95 void send_fail(StringT const& msg)
96 {
97 // GCOVR_EXCL_START
98 std::invoke(failReporter, msg);
100 // GCOVR_EXCL_STOP
101 }
102 };
103}
104
105#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:40
void report_no_matches(CallReport call, std::vector< NoMatchReport > noMatchReports) override
Expects reports on all non-matching expectations. This is only called when no better options are avai...
Definition BasicReporter.hpp:43
void report_unfulfilled_expectation(const ExpectationReport expectationReport) override
Handles the report of an unfulfilled expectation.
Definition BasicReporter.hpp:59
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:75
void report_error(StringT const message) override
Handles general or unspecified errors.
Definition BasicReporter.hpp:67
void report_full_match(CallReport call, ExpectationReport expectationReport) noexcept override
Handles the report for a fully matching expectation.
Definition BasicReporter.hpp:54
void report_inapplicable_matches(CallReport call, std::vector< ExpectationReport > expectationReports) override
Handles reports for all inapplicable but otherwise matching expectations. This function is called onl...
Definition BasicReporter.hpp:49
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
Definition Call.hpp:24
Definition BasicReporter.hpp:27
StringT stringify_unhandled_exception(CallReport const &call, ExpectationReport const &expectationReport, std::exception_ptr const &exception)
Definition StringifyReports.hpp:466
StringT stringify_unfulfilled_expectation(ExpectationReport const &expectationReport)
Definition StringifyReports.hpp:450
StringT stringify_inapplicable_matches(CallReport const &call, std::span< ExpectationReport > expectations)
Definition StringifyReports.hpp:349
StringT stringify_no_matches(CallReport const &call, std::span< NoMatchReport > noMatchReports)
Definition StringifyReports.hpp:388
StringT stringify_full_match(CallReport const &call, ExpectationReport expectation)
Definition StringifyReports.hpp:315
void unreachable()
Invokes undefined behavior.
Definition C++23Backports.hpp:40
std::basic_string< CharT, CharTraitsT > StringT
Definition Fwd.hpp:391