Skip to main content

micro-test-plus.h File

Main C++ header with the declarations for the µTest++ Testing Framework. 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...

namespaceutility

Utility functions for the µTest++ testing framework. More...

Functions Index

template < ... >
constexpr autoassume (const Expr_T &expr, const reflection::source_location &sl=reflection::source_location::current())

Check a condition and, if false, abort test execution. More...

intexit_code (void)

Complete the test run and return the exit code. More...

template < ... >
constexpr autoexpect (const Expr_T &expr, const reflection::source_location &sl=reflection::source_location::current())

Evaluate a generic condition and report the results. More...

voidinitialize (int argc, char *argv[], const char *name="Main")

Initialise the µTest++ framework. More...

boolis_match (std::string_view input, std::string_view pattern)

Check if a string matches a pattern. More...

template <class Callable_T>
constexpr autonothrow (const Callable_T &func)

Check if a callable does not throw an exception. More...

template <class T, class Delim_T>
auto split (T input, Delim_T delim) -> std::vector< T >

Split a string into a vector of sub-strings. More...

template <typename Callable_T, typename... Args_T>
voidtest_case (const char *name, Callable_T &&callable, Args_T &&... arguments)

Define and execute a test case. More...

template <class Exception_T, class Callable_T>
constexpr autothrows (const Callable_T &func)

Check if a callable throws a specific exception. More...

template <class Callable_T>
constexpr autothrows (const Callable_T &func)

Check if a callable throws an exception (any exception). More...

Variables Index

test_suite_base *current_test_suite

Global pointer references the currently active test suite. More...

test_reporter *reporter = nullptr

Global pointer to test_reporter. More...

test_runnerrunner

Global instance of test_runner. More...

Description

Main C++ header with the declarations for the µTest++ Testing Framework.

This header serves as the principal entry point for the µTest++ testing framework, purpose-built for both embedded and general C++ projects.

It provides all essential declarations required to write and manage tests, including test runner and reporter objects, test suite and test case management, expectations, assumptions, comparators, logical operators, exception verification, and utility functions.

The header also incorporates all necessary dependencies and internal headers to ensure the framework operates correctly and efficiently.

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

This file is located in the top-level include/micro-os-plus directory; all other header files are organised within the include/micro-os-plus/micro-test-plus directory to maintain a structured and modular codebase.

To access the complete functionality of the µTest++ framework, users should include this header in their test projects.

The implementation is significantly inspired by Boost UT, with adaptations and extensions to address the requirements of embedded development and the µTest++ framework.

Variables

current_test_suite

test_suite_base * micro_os_plus::micro_test_plus::current_test_suite

Global pointer references the currently active test suite.

This global pointer references the currently active test suite within the µTest++ framework. It is used to track and update the state of the test suite during test execution, including recording test results and statistics. By maintaining a pointer to the current test suite, the framework ensures accurate association of test outcomes with their respective suites, supporting clear and organised reporting across all test cases and folders.

Definition at line 307 of file micro-test-plus.cpp.

Referenced by micro_os_plus::micro_test_plus::detail::deferred_reporter_base::deferred_reporter_base, micro_os_plus::micro_test_plus::test_reporter_basic::end_test_case, micro_os_plus::micro_test_plus::test_reporter_tap::end_test_case, micro_os_plus::micro_test_plus::test_runner::exit_code, micro_os_plus::micro_test_plus::test_reporter::fail, micro_os_plus::micro_test_plus::test_runner::initialize, micro_os_plus::micro_test_plus::test_reporter_tap::output_fail_prefix_, micro_os_plus::micro_test_plus::test_reporter_tap::output_pass_prefix_, micro_os_plus::micro_test_plus::test_reporter::pass and micro_os_plus::micro_test_plus::test_case.

reporter

test_reporter * micro_os_plus::micro_test_plus::reporter = nullptr

Global pointer to test_reporter.

This global pointer to test_reporter is responsible for collecting, formatting, and outputting the results of test execution within the µTest++ framework. It manages the reporting of test outcomes, including successes and failures, and ensures that all relevant information is presented clearly to the user. By maintaining a single shared reporter, the framework provides consistent and centralised reporting across all test cases and folders. The reporter is initialized in test_runner::initialize().

Definition at line 293 of file micro-test-plus.cpp.

Referenced by micro_os_plus::micro_test_plus::detail::deferred_reporter< Expr_T >::~deferred_reporter, micro_os_plus::micro_test_plus::detail::deferred_reporter_base::~deferred_reporter_base, micro_os_plus::micro_test_plus::test_suite_base::begin_test_case, micro_os_plus::micro_test_plus::test_suite_base::begin_test_suite, micro_os_plus::micro_test_plus::test_suite_base::end_test_case, micro_os_plus::micro_test_plus::test_suite_base::end_test_suite, micro_os_plus::micro_test_plus::endl, micro_os_plus::micro_test_plus::test_runner::exit_code and micro_os_plus::micro_test_plus::test_runner::initialize.

runner

test_runner micro_os_plus::micro_test_plus::runner

Global instance of test_runner.

This global instance of test_runner manages the lifecycle of test suites and test cases within the µTest++ framework. It is responsible for initialising the test environment, registering test suites, executing tests, and collecting results. By maintaining a single shared runner, the framework ensures consistent test execution and reporting across all test cases and folders.

Declaration at line 278 of file micro-test-plus.cpp, definition at line 74 of file test-suite-inlines.h.

Referenced by micro_os_plus::micro_test_plus::test_suite::test_suite, micro_os_plus::micro_test_plus::test_reporter_basic::~test_reporter_basic, micro_os_plus::micro_test_plus::test_reporter_tap::~test_reporter_tap, micro_os_plus::micro_test_plus::test_suite_base::begin_test_case, micro_os_plus::micro_test_plus::test_reporter::end_test, micro_os_plus::micro_test_plus::test_reporter_basic::end_test, micro_os_plus::micro_test_plus::test_reporter_tap::end_test, micro_os_plus::micro_test_plus::test_suite_base::end_test_suite, micro_os_plus::micro_test_plus::exit_code and micro_os_plus::micro_test_plus::initialize.

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
52
53#ifndef MICRO_TEST_PLUS_MICRO_TEST_PLUS_H_
54#define MICRO_TEST_PLUS_MICRO_TEST_PLUS_H_
55
56// ----------------------------------------------------------------------------
57
58#ifdef __cplusplus
59
60// ----------------------------------------------------------------------------
61
62#if defined(MICRO_OS_PLUS_INCLUDE_CONFIG_H)
63#include <micro-os-plus/config.h>
64#endif // MICRO_OS_PLUS_INCLUDE_CONFIG_H
65
68
70
75
81
82// ----------------------------------------------------------------------------
83
84#if defined(__GNUC__)
85#pragma GCC diagnostic push
86#pragma GCC diagnostic ignored "-Wpadded"
87#pragma GCC diagnostic ignored "-Waggregate-return"
88#if defined(__clang__)
89#pragma clang diagnostic ignored "-Wc++98-compat"
90#pragma clang diagnostic ignored "-Wc++98-compat-pedantic"
91#pragma clang diagnostic ignored "-Wctad-maybe-unsupported"
92#endif
93#endif
94
120{
121 // --------------------------------------------------------------------------
122
123 extern test_runner runner;
124 extern test_reporter* reporter;
126
127 // --------------------------------------------------------------------------
128 // Public API.
129
141 void
142 initialize (int argc, char* argv[], const char* name = "Main");
143
152 [[nodiscard]] int
153 exit_code (void);
154
170 template <typename Callable_T, typename... Args_T>
171 void
172 test_case (const char* name, Callable_T&& callable, Args_T&&... arguments);
173
189 template <class Expr_T, type_traits::requires_t<
192 = 0>
193 constexpr auto
194 expect (const Expr_T& expr, const reflection::source_location& sl
196
211 template <class Expr_T, type_traits::requires_t<
214 = 0>
215 constexpr auto
216 assume (const Expr_T& expr, const reflection::source_location& sl
218
219 // --------------------------------------------------------------------------
220
221#if defined(__cpp_exceptions)
222
233 template <class Exception_T, class Callable_T>
234 [[nodiscard]] constexpr auto
235 throws (const Callable_T& func);
236
246 template <class Callable_T>
247 [[nodiscard]] constexpr auto
248 throws (const Callable_T& func);
249
258 template <class Callable_T>
259 [[nodiscard]] constexpr auto
260 nothrow (const Callable_T& func);
261
262#endif
263
264 // --------------------------------------------------------------------------
265
284 namespace utility
285 {
295 [[nodiscard]] bool
296 is_match (std::string_view input, std::string_view pattern);
297
309 template <class T, class Delim_T>
310 [[nodiscard]] auto
311 split (T input, Delim_T delim) -> std::vector<T>;
312
313 // ------------------------------------------------------------------------
314 } // namespace utility
315
316 // --------------------------------------------------------------------------
317} // namespace micro_os_plus::micro_test_plus
318
319#if defined(__GNUC__)
320#pragma GCC diagnostic pop
321#endif
322
323// ----------------------------------------------------------------------------
324
325#endif // __cplusplus
326
327// ===== Inlines & templates implementations
328// ====================================
329
330// All inlines are included **after** all declarations.
334
337
340
342
343// ----------------------------------------------------------------------------
344
345#endif // MICRO_TEST_PLUS_MICRO_TEST_PLUS_H_
346
347// ----------------------------------------------------------------------------

Generated via doxygen2docusaurus 2.0.0 by Doxygen 1.14.0.