micro-test-plus
4.1.0
µTest++ Testing Framework
Toggle main menu visibility
Loading...
Searching...
No Matches
deferred-reporter-inlines.h
Go to the documentation of this file.
1
/*
2
* This file is part of the µOS++ project (https://micro-os-plus.github.io/).
3
* Copyright (c) 2021-2026 Liviu Ionescu. All rights reserved.
4
*
5
* Permission to use, copy, modify, and/or distribute this software for any
6
* purpose is hereby granted, under the terms of the MIT license.
7
*
8
* If a copy of the license was not distributed with this file, it can be
9
* obtained from https://opensource.org/licenses/mit.
10
*
11
* Major parts of the code are inspired from v1.1.8 of the Boost UT project,
12
* released under the terms of the Boost Version 1.0 Software License,
13
* which can be obtained from https://www.boost.org/LICENSE_1_0.txt.
14
*/
15
16
// ----------------------------------------------------------------------------
17
44
45
#ifndef MICRO_TEST_PLUS_DEFERRED_REPORTER_INLINES_H_
46
#define MICRO_TEST_PLUS_DEFERRED_REPORTER_INLINES_H_
47
48
// ----------------------------------------------------------------------------
49
50
#ifdef __cplusplus
51
52
// ----------------------------------------------------------------------------
53
54
#include <charconv>
55
#include <cstdio>
56
57
#if defined(MICRO_OS_PLUS_TRACE)
58
#include <micro-os-plus/diag/trace.h>
59
#endif
// MICRO_OS_PLUS_TRACE
60
61
// ----------------------------------------------------------------------------
62
63
#if defined(__GNUC__)
64
#pragma GCC diagnostic push
65
#pragma GCC diagnostic ignored "-Waggregate-return"
66
#if defined(__clang__)
67
#pragma clang diagnostic ignored "-Wc++98-compat"
68
#pragma clang diagnostic ignored "-Wc++98-compat-pedantic"
69
#endif
70
#endif
71
72
// ============================================================================
73
74
namespace
micro_os_plus::micro_test_plus
75
{
76
// --------------------------------------------------------------------------
77
78
namespace
detail
79
{
80
// ========================================================================
81
86
inline
bool
87
deferred_reporter_base::value
()
const
88
{
89
return
value_
;
90
}
91
92
// ------------------------------------------------------------------------
93
105
template
<
class
T>
106
requires
type_traits::printable<T>
107
auto
&
108
deferred_reporter_base::operator<<
(
const
T& msg)
109
{
110
if
constexpr
(std::is_same_v<T, char>)
111
{
112
deferred_output_
.push_back (msg);
113
}
114
else
if
constexpr
(std::is_arithmetic_v<T>)
115
{
116
// Optimise to avoid dynamic memory allocation in std::to_string by
117
// using a fixed-size buffer and std::to_chars.
118
#if defined(__GNUC__)
119
#pragma GCC diagnostic push
120
#if defined(__clang__)
121
#pragma clang diagnostic ignored "-Wunsafe-buffer-usage"
122
#endif
123
#endif
124
char
buf[64];
125
// 64 bytes is sufficient for the longest decimal representation
126
// of any standard arithmetic type (long double ~45 chars).
127
static_assert
(
sizeof
(buf) >= 50,
128
"buf must be large enough for any arithmetic type"
);
129
auto
[ptr, ec] = std::to_chars (buf, buf +
sizeof
(buf), msg);
130
if
(ec == std::errc{})
131
deferred_output_
.append (buf, ptr);
132
#if defined(__GNUC__)
133
#pragma GCC diagnostic pop
134
#endif
135
}
136
else
137
{
138
deferred_output_
.append (msg);
139
}
140
return
*
this
;
141
}
142
143
// ------------------------------------------------------------------------
144
156
template
<
class
Expr_T>
157
deferred_reporter::deferred_reporter
(
158
const
Expr_T& expr,
bool
abort,
159
const
reflection::source_location
& location,
subtest
&
subtest
,
160
expression_formatter
& expression)
161
:
deferred_reporter_base
{ static_cast<bool> (expr), location,
subtest
}
162
163
{
164
#if defined(MICRO_OS_PLUS_TRACE) \
165
&& defined(MICRO_OS_PLUS_TRACE_MICRO_TEST_PLUS_CONSTRUCTORS)
166
trace::printf (
"%s\n"
, __PRETTY_FUNCTION__);
167
#endif
// MICRO_OS_PLUS_TRACE_MICRO_TEST_PLUS_CONSTRUCTORS
168
abort_
= abort;
169
has_expression_
=
type_traits::is_op<Expr_T>
;
170
171
expression.
clear
();
172
173
expression << expr;
174
}
175
176
// ------------------------------------------------------------------------
177
}
// namespace detail
178
179
// --------------------------------------------------------------------------
180
}
// namespace micro_os_plus::micro_test_plus
181
182
#if defined(__GNUC__)
183
#pragma GCC diagnostic pop
184
#endif
185
186
// ----------------------------------------------------------------------------
187
188
#endif
// __cplusplus
189
190
// ----------------------------------------------------------------------------
191
192
#endif
// MICRO_TEST_PLUS_DEFERRED_REPORTER_INLINES_H_
193
194
// ----------------------------------------------------------------------------
micro_os_plus::micro_test_plus::detail::deferred_reporter_base::value
bool value() const
Retrieves the result value.
Definition
deferred-reporter-inlines.h:87
micro_os_plus::micro_test_plus::detail::deferred_reporter_base::deferred_output_
std::string deferred_output_
String to collect the expectation message passed via operator<<().
Definition
deferred-reporter.h:193
micro_os_plus::micro_test_plus::detail::deferred_reporter_base::operator<<
auto & operator<<(const T &msg)
Appends a message to the reporter.
Definition
deferred-reporter-inlines.h:108
micro_os_plus::micro_test_plus::detail::deferred_reporter_base::has_expression_
bool has_expression_
Indicates whether the reporter has an associated expression.
Definition
deferred-reporter.h:182
micro_os_plus::micro_test_plus::detail::deferred_reporter_base::abort_
bool abort_
Indicates whether the reporting should abort further processing.
Definition
deferred-reporter.h:177
micro_os_plus::micro_test_plus::detail::deferred_reporter_base::deferred_reporter_base
deferred_reporter_base(bool value, const reflection::source_location &location, subtest &subtest)
Constructs a deferred reporter base.
Definition
deferred-reporter.cpp:75
micro_os_plus::micro_test_plus::detail::deferred_reporter_base::value_
bool value_
Stores the result value of the report.
Definition
deferred-reporter.h:171
micro_os_plus::micro_test_plus::detail::deferred_reporter::deferred_reporter
deferred_reporter(const Expr_T &expr, bool abort, const reflection::source_location &location, subtest &subtest, expression_formatter &expression)
Constructs a deferred reporter for a specific expression.
Definition
deferred-reporter-inlines.h:157
micro_os_plus::micro_test_plus::detail::expression_formatter
Formats values and expressions into an owned string buffer.
Definition
expression-formatter.h:151
micro_os_plus::micro_test_plus::detail::expression_formatter::clear
void clear() noexcept
Clears the internal buffer.
Definition
expression-formatter-inlines.h:126
micro_os_plus::micro_test_plus::reflection::source_location
Local implementation of source location information for diagnostics.
Definition
reflection.h:138
micro_os_plus::micro_test_plus::subtest
A named, runnable test case that lives inside a suite.
Definition
test.h:542
micro_os_plus::micro_test_plus::type_traits::is_op
C++20 concept satisfied when a type derives from op.
Definition
type-traits.h:437
micro_os_plus::micro_test_plus::type_traits::printable
C++20 concept satisfied when a type can be appended to the deferred reporter's output via operator<<.
Definition
type-traits.h:486
micro_os_plus::micro_test_plus::detail
Internal implementation details for the µTest++ framework.
Definition
deferred-reporter.h:79
micro_os_plus::micro_test_plus
Primary namespace for the µTest++ testing framework.
include
micro-os-plus
micro-test-plus
inlines
deferred-reporter-inlines.h
Generated by
1.17.0