Skip to main content

The micro-test-plus.h File Reference

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_os_plus::micro_test_plus

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

namespacemicro_os_plus::micro_test_plus::utility

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_reporterreporter

Global instance of 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 306 of file micro-test-plus.cpp.

reporter

test_reporter micro_os_plus::micro_test_plus::reporter

Global instance of test_reporter.

This global instance of 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.

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

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.

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 Liviu Ionescu. All rights reserved.
4 *
5 * Permission to use, copy, modify, and/or distribute this software
6 * for any 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
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&#95;1&#95;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
79
80// ----------------------------------------------------------------------------
81
82#if defined(__GNUC__)
83#pragma GCC diagnostic push
84#pragma GCC diagnostic ignored "-Wpadded"
85#pragma GCC diagnostic ignored "-Waggregate-return"
86#if defined(__clang__)
87#pragma clang diagnostic ignored "-Wc++98-compat"
88#pragma clang diagnostic ignored "-Wc++98-compat-pedantic"
89#pragma clang diagnostic ignored "-Wctad-maybe-unsupported"
90#endif
91#endif
92
118{
119 // --------------------------------------------------------------------------
120
121 extern test_runner runner;
124
125 // --------------------------------------------------------------------------
126 // Public API.
127
139 void
140 initialize (int argc, char* argv[], const char* name = "Main");
141
150 [[nodiscard]] int
151 exit_code (void);
152
168 template <typename Callable_T, typename... Args_T>
169 void
170 test_case (const char* name, Callable_T&& callable, Args_T&&... arguments);
171
183 template <class Expr_T, type_traits::requires_t<
186 = 0>
187 constexpr auto
188 expect (const Expr_T& expr, const reflection::source_location& sl
190
202 template <class Expr_T, type_traits::requires_t<
205 = 0>
206 constexpr auto
207 assume (const Expr_T& expr, const reflection::source_location& sl
209
210 // --------------------------------------------------------------------------
211
212#if defined(__cpp_exceptions)
213
224 template <class Exception_T, class Callable_T>
225 [[nodiscard]] constexpr auto
226 throws (const Callable_T& func);
227
237 template <class Callable_T>
238 [[nodiscard]] constexpr auto
239 throws (const Callable_T& func);
240
249 template <class Callable_T>
250 [[nodiscard]] constexpr auto
251 nothrow (const Callable_T& func);
252
253#endif
254
255 // --------------------------------------------------------------------------
256
275 namespace utility
276 {
286 [[nodiscard]] bool
287 is_match (std::string_view input, std::string_view pattern);
288
300 template <class T, class Delim_T>
301 [[nodiscard]] auto
302 split (T input, Delim_T delim) -> std::vector<T>;
303
304 // ------------------------------------------------------------------------
305 } // namespace utility
306
307 // --------------------------------------------------------------------------
308} // namespace micro_os_plus::micro_test_plus
309
310#if defined(__GNUC__)
311#pragma GCC diagnostic pop
312#endif
313
314// ----------------------------------------------------------------------------
315
316#endif // __cplusplus
317
318// ===== Inlines & templates implementations
319// ====================================
320
321// All inlines are included **after** all declarations.
325
328
331
333
334// ----------------------------------------------------------------------------
335
336#endif // MICRO_TEST_PLUS_MICRO_TEST_PLUS_H_
337
338// ----------------------------------------------------------------------------

Generated via docusaurus-plugin-doxygen by Doxygen 1.14.0.