Skip to main content

runner.h File

C++ header file with declarations for the µTest++ test runner. More...

Included Headers

#include "timings.h" #include "test.h" #include "reflection.h" #include <functional> #include <memory> #include <string> #include "inlines/runner-inlines.h"

Namespaces Index

namespacemicro_os_plus

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

namespacemicro_test_plus

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

Classes Index

classrunner

The test runner for the µTest++ framework. More...

classstatic_runner

A runner variant that also manages statically-registered test suites. More...

Description

C++ header file with declarations for the µTest++ test runner.

This header provides the declarations for the test runner facilities used within the µTest++ framework. It defines the interface for managing the registration and execution of test suites, supporting automated discovery and orchestration of tests across a project.

The test runner is responsible for initialising the test environment, registering test suites, managing command-line arguments, and determining the overall test result via an exit code. It also provides mechanisms for aborting test execution and retrieving the default suite name.

All definitions reside within the micro_os_plus::micro_test_plus namespace, ensuring clear separation from user code and minimising the risk of naming conflicts.

The header files are organised within the include/micro-os-plus/micro-test-plus folder to maintain a structured and modular codebase.

This file is intended solely for internal use within the framework and should not be included directly by user code.

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 * 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 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_TEST_RUNNER_H_
46#define MICRO_OS_PLUS_MICRO_TEST_PLUS_TEST_RUNNER_H_
47
48// ----------------------------------------------------------------------------
49
50#if defined(__cplusplus)
51
52// ----------------------------------------------------------------------------
53
54#if __has_include("micro-os-plus/project-config.h")
55#include "micro-os-plus/project-config.h"
56#endif // __has_include("micro-os-plus/project-config.h")
57
58#if __has_include("micro-os-plus/micro-test-plus-defines.h")
59#include "micro-os-plus/micro-test-plus-defines.h"
60#endif // __has_include("micro-os-plus/micro-test-plus-defines.h")
61
62#include "timings.h"
63#include "test.h"
64#include "reflection.h"
65
66#include <functional>
67#include <memory>
68#include <string>
69
70// ----------------------------------------------------------------------------
71
72#if defined(__GNUC__)
73#pragma GCC diagnostic push
74
75#pragma GCC diagnostic ignored "-Wpadded"
76#if defined(__clang__)
77#pragma clang diagnostic ignored "-Wc++98-compat"
78#else // GCC only
79#pragma GCC diagnostic ignored "-Wsuggest-final-types"
80#pragma GCC diagnostic ignored "-Wsuggest-final-methods"
81#pragma GCC diagnostic ignored "-Wredundant-tags"
82#endif // defined(__clang__)
83#endif // defined(__GNUC__)
84
85// ============================================================================
86
112{
113 // --------------------------------------------------------------------------
114
115 class suite;
116 class top_suite;
117 class reporter;
118
119 // ==========================================================================
120
144 {
145 public:
152 runner (void);
153
162 runner (const char* top_suite_name);
163
167 runner (const runner&) = delete;
168
172 runner (runner&&) = delete;
173
177 runner&
179 = delete;
180
184 runner&
186 = delete;
187
191 virtual ~runner () override;
192
202 class suite&
203 initialise (int argc, char* argv[], const char* top_suite_name = "");
204
212 int
213 exit_code (void);
214
229 template <typename Callable_T, typename... Args_T>
230 void
231 suite (const char* name, Callable_T&& callable, Args_T&&... arguments);
232
233 // ------------------------------------------------------------------------
234
242 [[noreturn]] void
245
246 // ------------------------------------------------------------------------
247 // Getters.
248
256 [[nodiscard]] virtual size_t
257 total_suites_count (void) const noexcept;
258
266 [[nodiscard]] class reporter&
267 reporter (void) const noexcept;
268
276 [[nodiscard]] detail::timestamps&
277 timings () noexcept;
278
286 [[nodiscard]] const detail::timestamps&
287 timings () const noexcept;
288
296 [[nodiscard]] size_t
297 suites_count (void) const noexcept;
298
299 protected:
306 virtual void
307 run_suites_ (void);
308
316 void
317 register_suite_ (std::unique_ptr<class suite> suite);
318
319 // ------------------------------------------------------------------------
320 protected:
325
334 std::vector<std::unique_ptr<class suite>> children_suites_;
335
339 std::unique_ptr<class reporter> reporter_;
340
344 detail::timestamps timings_;
345
349 std::string top_suite_name_;
350 };
351
352 // ==========================================================================
353
377 class static_runner final : public runner
378 {
379 public:
386 static_runner (void);
387
396 static_runner (const char* top_suite_name);
397
401 static_runner (const static_runner&) = delete;
402
407
413 = delete;
414
420 = delete;
421
425 virtual ~static_runner () override;
426
427 // ------------------------------------------------------------------------
428
435 static void
437
445 [[nodiscard]] size_t
446 static_suites_count (void) const noexcept;
447
456 [[nodiscard]] virtual size_t
457 total_suites_count (void) const noexcept final override;
458
459 protected:
466 void
467 run_suites_ (void) override;
468
469 protected:
483 std::vector<static_suite*>* static_children_suites_;
484 };
485
486} // namespace micro_os_plus::micro_test_plus
487
488#if defined(__GNUC__)
489#pragma GCC diagnostic pop
490#endif // defined(__GNUC__)
491
492// ----------------------------------------------------------------------------
493
494#endif // defined(__cplusplus)
495
496// ============================================================================
497// Templates, inlines & constexpr implementations.
498
500
501// ----------------------------------------------------------------------------
502
503#endif // MICRO_OS_PLUS_MICRO_TEST_PLUS_TEST_RUNNER_H_
504
505// ----------------------------------------------------------------------------

Generated via doxygen2docusaurus 2.2.2 by Doxygen 1.17.0.