Skip to main content

check-result.cpp File

C++ source file with implementations for the µTest++ check result member functions. More...

Included Headers​

Namespaces Index​

namespacemicro_os_plus

The primary namespace for the µOS++ framework. More...

namespacemicro_test_plus

Primary namespace for the µTest++ testing framework. More...

namespacedetail

Internal implementation details for the µTest++ framework. More...

Description​

C++ source file with implementations for the µTest++ check result member functions.

This source file contains the non-template members of the detail::check_result class, which reports the result of one check when destroyed. The private start() function, called by init(), captures the result value, the kind of the check, the source location, and the test case reference; the destructor updates the test case counters and, after a failed require(), stops the test case.

All definitions reside within the micro_os_plus::micro_test_plus::detail namespace.

This file must be included when building the µTest++ library.

File Listing​

The file content with the documentation metadata removed is:

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
12// ----------------------------------------------------------------------------
13
32
33// ----------------------------------------------------------------------------
34
37
38#if __has_include("micro-os-plus/diag/trace.h")
39#include "micro-os-plus/diag/trace.h"
40#endif // __has_include("micro-os-plus/diag/trace.h")
41
42#include <exception>
43
44// ----------------------------------------------------------------------------
45
46#if defined(__GNUC__)
47#pragma GCC diagnostic ignored "-Waggregate-return"
48#if defined(__clang__)
49#pragma clang diagnostic ignored "-Wc++98-compat"
50#pragma clang diagnostic ignored "-Wexit-time-destructors"
51#pragma clang diagnostic ignored "-Wglobal-constructors"
52#endif // defined(__clang__)
53#endif // defined(__GNUC__)
54
55// ============================================================================
56
57#if defined(MICRO_OS_PLUS_MICRO_TEST_PLUS_ENABLED)
58
59// ----------------------------------------------------------------------------
60
62{
63 // --------------------------------------------------------------------------
64 namespace detail
65 {
71 check_result::check_result (void) = default;
72
88 void
89 check_result::start (bool value, check_kind kind, bool has_expression,
90 const reflection::source_location& location,
91 test_case& test_case, bool writes_passed)
92 {
94 is_written_ = !value || writes_passed;
95 info_ = failure_info{ kind, {}, has_expression, location };
97#if defined(__cpp_exceptions)
98 uncaught_exceptions_ = std::uncaught_exceptions ();
99#endif // defined(__cpp_exceptions)
100 }
101
139 check_result::~check_result () noexcept (false)
140 {
141#if defined(MICRO_OS_PLUS_MICRO_TEST_PLUS_TRACE_CONSTRUCTORS_ENABLED)
142 trace::printf ("%s\n", __PRETTY_FUNCTION__);
143#endif // MICRO_OS_PLUS_MICRO_TEST_PLUS_TRACE_CONSTRUCTORS_ENABLED
144
145 // A result that was not initialised, such as a default argument
146 // whose function did not run, reports nothing.
147 if (test_case_ == nullptr) [[unlikely]]
148 {
149 return;
150 }
151
152 // The index starts at 0; it must be incremented before the check is
153 // reported, so that the first check is reported as check #1.
155
156 // The text formatted by this check, even if the formatter was used by
157 // other checks in the meantime (when this result was kept).
158 auto& expression = test_case_->test_reporter ().expression_;
159 const std::string& expression_str = expression.check_text (this);
160
161 if (value_) [[likely]]
162 {
163 if (is_written_)
164 {
165 test_case_->test_reporter ().pass (info_.message, expression_str,
166 *test_case_);
167 }
168 else
169 {
171 }
173 }
174 else
175 {
176 test_case_->test_reporter ().fail (info_, expression_str,
177 *test_case_);
179 }
180
181 expression.end_check (this);
182
183 if (info_.kind == check_kind::requirement && !value_) [[unlikely]]
184 {
185#if defined(__cpp_exceptions)
186 if (std::uncaught_exceptions () <= uncaught_exceptions_)
187 {
188 throw failed_requirement{};
189 }
190#else
192#endif // defined(__cpp_exceptions)
193 }
194 }
195 } // namespace detail
196
197 // --------------------------------------------------------------------------
198} // namespace micro_os_plus::micro_test_plus
199
200// ----------------------------------------------------------------------------
201
202#endif // defined(MICRO_OS_PLUS_MICRO_TEST_PLUS_ENABLED)
203
204// ----------------------------------------------------------------------------

Generated via doxygen2docusaurus 2.2.8 by Doxygen 1.18.0.