micro-test-plus
5.0.1
µ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_OS_PLUS_MICRO_TEST_PLUS_INLINES_DEFERRED_REPORTER_INLINES_H_
46
#define MICRO_OS_PLUS_MICRO_TEST_PLUS_INLINES_DEFERRED_REPORTER_INLINES_H_
47
48
// ----------------------------------------------------------------------------
49
50
#if defined(__cplusplus)
51
52
// ----------------------------------------------------------------------------
53
54
#if __has_include("micro-os-plus/diag/trace.h")
55
#include "micro-os-plus/diag/trace.h"
56
#endif
// __has_include("micro-os-plus/diag/trace.h")
57
58
#include <charconv>
59
#include <cstdio>
60
61
// ----------------------------------------------------------------------------
62
63
#if defined(__GNUC__)
64
#pragma GCC diagnostic push
65
66
#pragma GCC diagnostic ignored "-Waggregate-return"
67
#if defined(__clang__)
68
#pragma clang diagnostic ignored "-Wc++98-compat"
69
#pragma clang diagnostic ignored "-Wc++98-compat-pedantic"
70
#endif
// defined(__clang__)
71
#endif
// defined(__GNUC__)
72
73
// ============================================================================
74
75
namespace
micro_os_plus::micro_test_plus
76
{
77
// --------------------------------------------------------------------------
78
79
namespace
detail
80
{
81
// ========================================================================
82
87
inline
bool
88
deferred_reporter_base::value
()
const
89
{
90
return
value_
;
91
}
92
93
// ------------------------------------------------------------------------
94
106
template
<
class
T>
107
requires
type_traits::printable<T>
108
auto
&
109
deferred_reporter_base::operator<<
(
const
T& msg)
110
{
111
if
constexpr
(std::is_same_v<T, char>)
112
{
113
deferred_output_
.push_back (msg);
114
}
115
else
if
constexpr
(std::is_arithmetic_v<T>)
116
{
117
// Optimise to avoid dynamic memory allocation in std::to_string by
118
// using a fixed-size buffer and std::to_chars.
119
#if defined(__GNUC__)
120
#pragma GCC diagnostic push
121
122
#if defined(__clang__)
123
#pragma clang diagnostic ignored "-Wunsafe-buffer-usage"
124
#endif
// defined(__clang__)
125
#endif
// defined(__GNUC__)
126
127
char
buf[64];
128
// 64 bytes is sufficient for the longest decimal representation
129
// of any standard arithmetic type (long double ~45 chars).
130
static_assert
(
sizeof
(buf) >= 50,
131
"buf must be large enough for any arithmetic type"
);
132
auto
[ptr, ec] = std::to_chars (buf, buf +
sizeof
(buf), msg);
133
if
(ec == std::errc{})
134
deferred_output_
.append (buf, ptr);
135
136
#if defined(__GNUC__)
137
#pragma GCC diagnostic pop
138
#endif
// defined(__GNUC__)
139
}
140
else
141
{
142
deferred_output_
.append (msg);
143
}
144
return
*
this
;
145
}
146
147
// ------------------------------------------------------------------------
148
160
template
<
class
Expr_T>
161
deferred_reporter::deferred_reporter
(
162
const
Expr_T& expr,
bool
abort,
163
const
reflection::source_location
& location,
subtest
&
subtest
,
164
expression_formatter
& expression)
165
:
deferred_reporter_base
{ static_cast<bool> (expr), location,
subtest
}
166
167
{
168
#if defined(MICRO_OS_PLUS_MICRO_TEST_PLUS_TRACE_CONSTRUCTORS_ENABLED)
169
trace::printf (
"%s\n"
, __PRETTY_FUNCTION__);
170
#endif
// MICRO_OS_PLUS_MICRO_TEST_PLUS_TRACE_CONSTRUCTORS_ENABLED
171
abort_
= abort;
172
has_expression_
=
type_traits::is_op<Expr_T>
;
173
174
expression.
clear
();
175
176
expression << expr;
177
}
178
179
// ------------------------------------------------------------------------
180
}
// namespace detail
181
182
// --------------------------------------------------------------------------
183
}
// namespace micro_os_plus::micro_test_plus
184
185
#if defined(__GNUC__)
186
#pragma GCC diagnostic pop
187
#endif
// defined(__GNUC__)
188
189
// ----------------------------------------------------------------------------
190
191
#endif
// defined(__cplusplus)
192
193
// ----------------------------------------------------------------------------
194
195
#endif
// MICRO_OS_PLUS_MICRO_TEST_PLUS_INLINES_DEFERRED_REPORTER_INLINES_H_
196
197
// ----------------------------------------------------------------------------
micro_os_plus::micro_test_plus::detail::deferred_reporter_base::value
bool value() const
Retrieves the result value.
Definition
deferred-reporter-inlines.h:88
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:202
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:109
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:191
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:186
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:180
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:161
micro_os_plus::micro_test_plus::detail::expression_formatter
Formats values and expressions into an owned string buffer.
Definition
expression-formatter.h:160
micro_os_plus::micro_test_plus::detail::expression_formatter::clear
void clear() noexcept
Clears the internal buffer.
Definition
expression-formatter-inlines.h:128
micro_os_plus::micro_test_plus::reflection::source_location
Local implementation of source location information for diagnostics.
Definition
reflection.h:150
micro_os_plus::micro_test_plus::subtest
A named, runnable test case that lives inside a suite.
Definition
test.h:551
micro_os_plus::micro_test_plus::type_traits::is_op
C++20 concept satisfied when a type derives from op.
Definition
type-traits.h:446
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:495
micro_os_plus::micro_test_plus::detail
Internal implementation details for the µTest++ framework.
Definition
deferred-reporter.h:88
micro_os_plus::micro_test_plus
Primary namespace for the µTest++ testing framework.
Definition
deferred-reporter.h:82
include
micro-os-plus
micro-test-plus
inlines
deferred-reporter-inlines.h
Generated by
1.17.0