micro-test-plus 4.1.0
µTest++ Testing Framework
Loading...
Searching...
No Matches
deferred-reporter.cpp
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
36
37// ----------------------------------------------------------------------------
38
39#if defined(MICRO_OS_PLUS_INCLUDE_CONFIG_H)
40#include <micro-os-plus/config.h>
41#endif // MICRO_OS_PLUS_INCLUDE_CONFIG_H
42
43#if defined(MICRO_OS_PLUS_TRACE)
44#include <micro-os-plus/diag/trace.h>
45#endif // MICRO_OS_PLUS_TRACE
46
49
50// ----------------------------------------------------------------------------
51
52#if defined(__GNUC__)
53#pragma GCC diagnostic ignored "-Waggregate-return"
54#if defined(__clang__)
55#pragma clang diagnostic ignored "-Wc++98-compat"
56#pragma clang diagnostic ignored "-Wexit-time-destructors"
57#pragma clang diagnostic ignored "-Wglobal-constructors"
58#endif
59#endif
60
61// ============================================================================
62
64{
65 // --------------------------------------------------------------------------
66 namespace detail
67 {
76 bool value, const reflection::source_location& location,
78 : value_{ value }, location_{ location }, subtest_{ subtest }
79 {
80 // The index starts at 0, must be incremented before the first check is
81 // reported, to ensure that the first check is reported as check #1.
82 subtest_.increment_subtest_index ();
83 }
84
104 {
105#if defined(MICRO_OS_PLUS_TRACE) \
106 && defined(MICRO_OS_PLUS_TRACE_MICRO_TEST_PLUS_CONSTRUCTORS)
107 trace::printf ("%s\n", __PRETTY_FUNCTION__);
108#endif // MICRO_OS_PLUS_TRACE_MICRO_TEST_PLUS_CONSTRUCTORS
109
110 auto& expression_str = subtest_.reporter ().expression ().str ();
111
112 if (value_) [[likely]]
113 {
114 subtest_.reporter ().pass (deferred_output_, expression_str,
115 subtest_);
116 subtest_.totals ().increment_successful_checks ();
117 }
118 else
119 {
120 subtest_.reporter ().fail (abort_, deferred_output_, expression_str,
122 subtest_.totals ().increment_failed_checks ();
123 }
124
125 if (abort_ && !value_) [[unlikely]]
126 {
127 subtest_.reporter ().write_buffer_to_stdout ();
128 subtest_.reporter ().flush ();
129 subtest_.abort (location_);
130 }
131 }
132 } // namespace detail
133
134 // ==========================================================================
135} // namespace micro_os_plus::micro_test_plus
136
137// ----------------------------------------------------------------------------
const reflection::source_location location_
Stores the source location associated with the report.
std::string deferred_output_
String to collect the expectation message passed via operator<<().
~deferred_reporter_base()
Destructor for the deferred reporter base.
bool has_expression_
Indicates whether the reporter has an associated expression.
bool abort_
Indicates whether the reporting should abort further processing.
subtest & subtest_
Reference to the test case invoking this report.
deferred_reporter_base(bool value, const reflection::source_location &location, subtest &subtest)
Constructs a deferred reporter base.
Local implementation of source location information for diagnostics.
Definition reflection.h:138
A named, runnable test case that lives inside a suite.
Definition test.h:542
C++ header file with declarations for the µTest++ deferred reporter.
Internal implementation details for the µTest++ framework.
Primary namespace for the µTest++ testing framework.
C++ header file with declarations for the µTest++ test suite.