micro-test-plus 6.0.1
µTest++ Testing Framework
Loading...
Searching...
No Matches
runner-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
12// ----------------------------------------------------------------------------
13
35
36#ifndef MICRO_OS_PLUS_MICRO_TEST_PLUS_INLINES_RUNNER_INLINES_H_
37#define MICRO_OS_PLUS_MICRO_TEST_PLUS_INLINES_RUNNER_INLINES_H_
38
39// ----------------------------------------------------------------------------
40
41#if defined(__cplusplus)
42
43// ----------------------------------------------------------------------------
44
45#if __has_include("micro-os-plus/diag/trace.h")
46#include "micro-os-plus/diag/trace.h"
47#endif // __has_include("micro-os-plus/diag/trace.h")
48
49// ----------------------------------------------------------------------------
50
51#if defined(__GNUC__)
52#pragma GCC diagnostic push
53
54#pragma GCC diagnostic ignored "-Waggregate-return"
55#if defined(__clang__)
56#pragma clang diagnostic ignored "-Wunknown-warning-option"
57#pragma clang diagnostic ignored "-Wc++98-compat"
58#pragma clang diagnostic ignored "-Wc++98-compat-pedantic"
59#pragma clang diagnostic ignored "-Wunsafe-buffer-usage-in-libc-call"
60#else // GCC only
61#pragma GCC diagnostic ignored "-Wredundant-tags"
62#endif // defined(__clang__)
63#endif // defined(__GNUC__)
64
65// ============================================================================
66
68{
69 // ==========================================================================
70
76 inline auto
78 {
79 return options_.verbosity_level;
80 }
81
86 inline bool
87 runner::is_listing (void) const noexcept
88 {
89 return options_.list_tests;
90 }
91
99 inline bool
100 runner::has_option_errors (void) const noexcept
101 {
102 return options_.has_errors ()
103 || (reporter_ != nullptr && reporter_->has_output_file_error ());
104 }
105
106#if defined(MICRO_OS_PLUS_MICRO_TEST_PLUS_DEPRECATED_ENABLED)
111 // Deprecated since 6.0.0; use verbosity_level().
112 inline auto
114 {
115 return verbosity_level ();
116 }
117#endif // defined(MICRO_OS_PLUS_MICRO_TEST_PLUS_DEPRECATED_ENABLED)
118
123 inline const counters&
124 runner::totals (void) const noexcept
125 {
126 return totals_;
127 }
128
134 inline std::span<const std::string>
135 runner::application_arguments (void) const noexcept
136 {
137 return options_.application_arguments ();
138 }
139
140#if defined(MICRO_OS_PLUS_MICRO_TEST_PLUS_DEPRECATED_ENABLED)
145 // Deprecated since 6.0.0; the timings are internal.
146 inline const detail::stopwatch&
147 runner::timings (void) const noexcept
148 {
149 return stopwatch_;
150 }
151
156 // Deprecated since 6.0.0; the timings are internal.
157 inline detail::stopwatch&
158 runner::timings (void) noexcept
159 {
160 return stopwatch_;
161 }
162
168 // Deprecated since 6.0.0; use verbosity_level().
169 inline detail::reporter&
170 runner::reporter (void) const noexcept
171 {
172 return *reporter_;
173 }
174#endif // defined(MICRO_OS_PLUS_MICRO_TEST_PLUS_DEPRECATED_ENABLED)
175
176 // --------------------------------------------------------------------------
177
188 template <typename Callable_T, typename... Args_T>
189 requires detail::suite_body<Callable_T, Args_T...>
190 void
191 runner::add_suite (located_name name, Callable_T&& callable,
192 Args_T&&... arguments)
193 {
194#if defined(MICRO_OS_PLUS_MICRO_TEST_PLUS_TRACE_ENABLED)
195 trace::printf ("%s '%s'\n", __PRETTY_FUNCTION__, name.name ());
196#endif // MICRO_OS_PLUS_MICRO_TEST_PLUS_TRACE_ENABLED
197
198 // Not std::make_unique(), which cannot access the private constructor.
199 std::unique_ptr<class suite> child_suite{ new class suite (
200 std::move (name), *this, std::forward<Callable_T> (callable),
201 std::forward<Args_T> (arguments)...) };
202
203 register_suite (std::move (child_suite));
204 }
205
206#if !defined(__DOXYGEN__)
212 template <typename Callable_T, typename... Args_T>
213 requires (!detail::suite_body<Callable_T, Args_T...>)
214 void
215 runner::add_suite ([[maybe_unused]] located_name name,
216 [[maybe_unused]] Callable_T&& callable,
217 [[maybe_unused]] Args_T&&... arguments)
218 {
219 detail::reject_suite_body<Callable_T, Args_T...> ();
220 }
221#endif // !defined(__DOXYGEN__)
222
223#if defined(MICRO_OS_PLUS_MICRO_TEST_PLUS_DEPRECATED_ENABLED)
228 // Deprecated since 6.0.0; use add_suite().
229 template <typename Callable_T, typename... Args_T>
230 void
231 runner::suite (std::string_view name, Callable_T&& callable,
232 Args_T&&... arguments)
233 {
234 add_suite (located_name{ name }, std::forward<Callable_T> (callable),
235 std::forward<Args_T> (arguments)...);
236 }
237#endif // defined(MICRO_OS_PLUS_MICRO_TEST_PLUS_DEPRECATED_ENABLED)
238
239 // --------------------------------------------------------------------------
240} // namespace micro_os_plus::micro_test_plus
241
242#if defined(__GNUC__)
243#pragma GCC diagnostic pop
244#endif // defined(__GNUC__)
245
246// ----------------------------------------------------------------------------
247
248#endif // defined(__cplusplus)
249
250// ----------------------------------------------------------------------------
251
252#endif // MICRO_OS_PLUS_MICRO_TEST_PLUS_INLINES_RUNNER_INLINES_H_
253
254// ----------------------------------------------------------------------------
Aggregated check and test case counters for a node in the test tree.
Definition counters.h:123
Abstract base class for the reporters that display test results, including operand values for failure...
Definition reporter.h:276
Measures the elapsed time of an operation.
Definition stopwatch.h:138
A name of a suite or of a test case, with the location where it was given.
Definition test.h:177
const char * name(void) const noexcept
Returns the name.
counters totals_
Totals of the test session.
Definition runner.h:1294
bool has_option_errors(void) const noexcept
Checks whether an option error was found by initialise().
detail::stopwatch stopwatch_
Stopwatch of this runner.
Definition runner.h:1285
void register_suite(std::unique_ptr< class suite > suite)
Registers a test suite with the runner.
Definition runner.cpp:599
auto verbosity_level(void) const noexcept -> micro_test_plus::verbosity
Returns the verbosity level of the console output.
void suite(std::string_view name, Callable_T &&callable, Args_T &&... arguments)
Deprecated name of add_suite().
const counters & totals(void) const noexcept
Returns the totals of the test session.
const char * name(void) const noexcept
Deprecated name of the runner.
Definition runner.cpp:1086
detail::reporter & reporter(void) const noexcept
Deprecated access to the reporter of the test session.
std::unique_ptr< detail::reporter > reporter_
Owning pointer to the test reporter used for outputting test results.
Definition runner.h:1275
std::span< const std::string > application_arguments(void) const noexcept
Returns the command-line arguments left to the application.
auto verbosity(void) const noexcept -> micro_test_plus::verbosity
Deprecated name of verbosity_level().
void add_suite(located_name name, Callable_T &&callable, Args_T &&... arguments)
Adds a test suite to the runner, to be run by run_suites().
runner_options options_
The options of the test session.
Definition runner.h:1306
bool is_listing(void) const noexcept
Checks whether the test cases are listed instead of run.
const detail::stopwatch & timings(void) const noexcept
Deprecated access to the timings of the test session.
Concept satisfied by a callable object that can be the body of a suite.
Definition test.h:1217
verbosity
The verbosity levels for test reporting.
constexpr void reject_suite_body(void) noexcept
Stops the compilation with a message that tells what the body of a suite takes.
Primary namespace for the µTest++ testing framework.