6#ifndef MIMICPP_REPORTS_HPP
7#define MIMICPP_REPORTS_HPP
80 template <pr
int_iterator OutIter>
81 OutIter print_times_state(OutIter out,
const std::size_t current,
const std::size_t min,
const std::size_t max)
83 const auto verbalizeValue = [](OutIter o,
const std::size_t value) {
86 case 0:
return format::format_to(std::move(o),
"never");
87 case 1:
return format::format_to(std::move(o),
"once");
88 case 2:
return format::format_to(std::move(o),
"twice");
89 default:
return format::format_to(std::move(o),
"{} times", value);
95 out = format::format_to(
97 "already saturated (matched ");
98 out = verbalizeValue(std::move(out), current);
99 return format::format_to(std::move(out),
")");
104 return format::format_to(
106 "accepts further matches (matched {} out of {} times)",
111 const auto verbalizeInterval = [verbalizeValue](OutIter o,
const std::size_t start,
const std::size_t end) {
114 return format::format_to(
116 "between {} and {} times",
121 o = format::format_to(std::move(o),
"exactly ");
122 return verbalizeValue(std::move(o), end);
125 out = format::format_to(std::move(out),
"matched ");
126 out = verbalizeValue(std::move(out), current);
127 out = format::format_to(std::move(out),
" - ");
128 out = verbalizeInterval(std::move(out), min, max);
129 return format::format_to(std::move(out),
" is expected");
132 struct control_state_printer
134 template <pr
int_iterator OutIter>
137 out = print_times_state(
143 if (
const auto sequenceCount = std::ranges::ssize(state.
sequenceRatings);
146 out = format::format_to(
148 ",\n\tand is the current element of {} sequence(s).",
155 template <pr
int_iterator OutIter>
158 out = print_times_state(
166 return format::format_to(
168 ",\n\tbut is not the current element of {} sequence(s) ({} total).",
173 template <pr
int_iterator OutIter>
176 out = print_times_state(
182 if (
const auto sequenceCount = std::ranges::ssize(state.
sequences);
185 out = format::format_to(
187 ",\n\tand is part of {} sequence(s).",
242 template <
typename Return,
typename... Params>
247 .returnTypeIndex =
typeid(Return),
248 .argDetails = std::apply(
250 return std::vector<CallReport::Arg>{
252 .typeIndex =
typeid(Params),
268 template <pr
int_iterator OutIter>
271 out = format::format_to(
276 out = format::format_to(
289 out = format::format_to(
293 out = format::format_to(
296 "value category: {}\n"
304 out = format::format_to(
307 for (
const std::size_t i : std::views::iota(0u, std::ranges::size(report.
argDetails)))
309 out = format::format_to(
351 class detail::Printer<ExpectationReport>
354 template <pr
int_iterator OutIter>
355 static OutIter
print(OutIter out,
const ExpectationReport& report)
357 out = format::format_to(
359 "Expectation report:\n");
361 if (report.sourceLocation)
363 out = format::format_to(
368 *report.sourceLocation);
369 out = format::format_to(
374 if (report.timesDescription)
376 out = format::format_to(
379 *report.timesDescription);
382 if (std::ranges::any_of(
383 report.expectationDescriptions,
384 [](
const auto& desc) { return desc.has_value(); }))
386 out = format::format_to(
389 for (
const auto& desc : report.expectationDescriptions
390 | std::views::filter([](
const auto& desc) { return desc.has_value(); }))
392 out = format::format_to(
399 if (report.finalizerDescription)
401 out = format::format_to(
404 *report.finalizerDescription);
475 if (!std::holds_alternative<state_applicable>(report.controlReport))
484 class detail::Printer<MatchReport>
487 template <pr
int_iterator OutIter>
488 static OutIter
print(OutIter out,
const MatchReport& report)
490 std::vector<StringT> matchedExpectationDescriptions{};
491 std::vector<StringT> unmatchedExpectationDescriptions{};
493 for (
const auto& [isMatching, description] : report.expectationReports)
499 matchedExpectationDescriptions.emplace_back(*description);
503 unmatchedExpectationDescriptions.emplace_back(*description);
511 out = format::format_to(
513 "Matched expectation: {{\n");
517 out = format::format_to(
519 "Inapplicable, but otherwise matched expectation: {{\n"
522 std::bind_front(control_state_printer{}, std::move(out)),
523 report.controlReport);
524 out = format::format_to(std::move(out),
"\n");
528 out = format::format_to(
530 "Unmatched expectation: {{\n");
539 if (report.sourceLocation)
541 out = format::format_to(
546 *report.sourceLocation);
547 out = format::format_to(
552 if (!std::ranges::empty(unmatchedExpectationDescriptions))
554 out = format::format_to(
557 for (
const auto& desc : unmatchedExpectationDescriptions)
559 out = format::format_to(
566 if (!std::ranges::empty(matchedExpectationDescriptions))
568 out = format::format_to(
571 for (
const auto& desc : matchedExpectationDescriptions)
573 out = format::format_to(
580 return format::format_to(
Definition Reports.hpp:206
std::type_index typeIndex
Definition Reports.hpp:208
friend bool operator==(const Arg &, const Arg &)=default
StringT stateString
Definition Reports.hpp:209
Contains the extracted info from a typed call::Info.
Definition Reports.hpp:203
std::type_index returnTypeIndex
Definition Reports.hpp:215
friend bool operator==(const CallReport &lhs, const CallReport &rhs)
Definition Reports.hpp:223
Constness fromConstness
Definition Reports.hpp:220
ValueCategory fromCategory
Definition Reports.hpp:219
std::vector< Arg > argDetails
Definition Reports.hpp:216
Stacktrace stacktrace
Definition Reports.hpp:218
std::source_location fromLoc
Definition Reports.hpp:217
Contains the extracted info from a typed expectation.
Definition Reports.hpp:331
std::optional< StringT > finalizerDescription
Definition Reports.hpp:334
std::optional< StringT > timesDescription
Definition Reports.hpp:335
std::optional< std::source_location > sourceLocation
Definition Reports.hpp:333
std::vector< std::optional< StringT > > expectationDescriptions
Definition Reports.hpp:336
friend bool operator==(const ExpectationReport &lhs, const ExpectationReport &rhs)
Definition Reports.hpp:339
Information a used expectation policy.
Definition Reports.hpp:436
std::optional< StringT > description
Definition Reports.hpp:439
friend bool operator==(const Expectation &, const Expectation &)=default
bool isMatching
Definition Reports.hpp:438
Information about the used finalizer.
Definition Reports.hpp:423
std::optional< StringT > description
Definition Reports.hpp:425
friend bool operator==(const Finalize &, const Finalize &)=default
Contains the detailed information for match outcomes.
Definition Reports.hpp:417
std::vector< Expectation > expectationReports
Definition Reports.hpp:448
Finalize finalizeReport
Definition Reports.hpp:446
friend bool operator==(const MatchReport &lhs, const MatchReport &rhs)
Definition Reports.hpp:451
control_state_t controlReport
Definition Reports.hpp:447
std::optional< std::source_location > sourceLocation
Definition Reports.hpp:445
A simple type-erase stacktrace abstraction.
Definition Stacktrace.hpp:173
constexpr std::string description(const std::size_t at) const
Queries the underlying stacktrace-backend for the description of the selected stacktrace-entry.
Definition Stacktrace.hpp:254
constexpr bool empty() const
Queries the underlying stacktrace-backend whether its empty.
Definition Stacktrace.hpp:243
constexpr std::size_t source_line(const std::size_t at) const
Queries the underlying stacktrace-backend for the source-line of the selected stacktrace-entry.
Definition Stacktrace.hpp:276
constexpr std::string source_file(const std::size_t at) const
Queries the underlying stacktrace-backend for the source-file of the selected stacktrace-entry.
Definition Stacktrace.hpp:265
ValueCategory fromCategory
Definition Call.hpp:28
Stacktrace stacktrace
Definition Call.hpp:31
std::source_location fromSourceLocation
Definition Call.hpp:30
ArgListT args
Definition Call.hpp:27
Constness fromConstness
Definition Call.hpp:29
The fallback stacktrace-backend.
Definition Stacktrace.hpp:412
MatchResult evaluate_match_report(const MatchReport &report) noexcept
Determines, whether a match report actually denotes a full, inapplicable or no match.
Definition Reports.hpp:468
CallReport make_call_report(call::Info< Return, Params... > callInfo)
Generates the call report for a given call info.
Definition Reports.hpp:244
std::variant< state_inapplicable, state_applicable, state_saturated > control_state_t
Definition Reports.hpp:73
constexpr detail::PrintFn print
Functional object, converting the given object to its textual representation.
Definition Printer.hpp:590
Definition BoostTest.hpp:20
MatchResult
Definition Fwd.hpp:332
@ inapplicable
Definition Fwd.hpp:334
@ none
Definition Fwd.hpp:333
@ full
Definition Fwd.hpp:335
void unreachable()
Invokes undefined behavior.
Definition Utility.hpp:91
constexpr bool is_same_source_location(const std::source_location &lhs, const std::source_location &rhs) noexcept
Definition Utility.hpp:42
ValueCategory
Definition Fwd.hpp:32
Constness
Definition Fwd.hpp:25
std::basic_string< CharT, CharTraitsT > StringT
Definition Fwd.hpp:344
Definition Reports.hpp:52
std::vector< sequence::rating > sequenceRatings
Definition Reports.hpp:56
int count
Definition Reports.hpp:55
int min
Definition Reports.hpp:53
friend bool operator==(const state_applicable &, const state_applicable &)=default
int max
Definition Reports.hpp:54
Definition Reports.hpp:40
std::vector< sequence::rating > sequenceRatings
Definition Reports.hpp:44
int count
Definition Reports.hpp:43
friend bool operator==(const state_inapplicable &, const state_inapplicable &)=default
int min
Definition Reports.hpp:41
int max
Definition Reports.hpp:42
std::vector< sequence::Tag > inapplicableSequences
Definition Reports.hpp:45
Definition Reports.hpp:63
int max
Definition Reports.hpp:65
std::vector< sequence::Tag > sequences
Definition Reports.hpp:67
int count
Definition Reports.hpp:66
friend bool operator==(const state_saturated &, const state_saturated &)=default
int min
Definition Reports.hpp:64