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...

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...

Functions Index

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...

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...

constexpr autonothrow (const Callable_T &func)

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

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

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

voidtest_case (const char *name, Callable_T &&callable, Args_T &&... arguments)

Define and execute a test case. More...

constexpr autothrows (const Callable_T &func)

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

constexpr autothrows (const Callable_T &func)

Check if a callable throws an exception (any exception). 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
71
72#ifndef MICRO_TEST_PLUS_MICRO_TEST_PLUS_H_
73#define MICRO_TEST_PLUS_MICRO_TEST_PLUS_H_
74
75// ----------------------------------------------------------------------------
76
77#ifdef __cplusplus
78
79// ----------------------------------------------------------------------------
80
81#if defined(MICRO_OS_PLUS_INCLUDE_CONFIG_H)
82#include <micro-os-plus/config.h>
83#endif // MICRO_OS_PLUS_INCLUDE_CONFIG_H
84
87
89
94
98
99// ----------------------------------------------------------------------------
100
101#if defined(__GNUC__)
102#pragma GCC diagnostic push
103#pragma GCC diagnostic ignored "-Wpadded"
104#pragma GCC diagnostic ignored "-Waggregate-return"
105#if defined(__clang__)
106#pragma clang diagnostic ignored "-Wc++98-compat"
107#pragma clang diagnostic ignored "-Wc++98-compat-pedantic"
108#pragma clang diagnostic ignored "-Wctad-maybe-unsupported"
109#endif
110#endif
111
137{
138 // --------------------------------------------------------------------------
139
140 extern test_runner runner;
143
144 // --------------------------------------------------------------------------
145 // Public API.
146
158 void
159 initialize (int argc, char* argv[], const char* name = "Main");
160
169 [[nodiscard]] int
170 exit_code (void);
171
187 template <typename Callable_T, typename... Args_T>
188 void
189 test_case (const char* name, Callable_T&& callable, Args_T&&... arguments);
190
202 template <class Expr_T, type_traits::requires_t<
205 = 0>
206 constexpr auto
207 expect (const Expr_T& expr, const reflection::source_location& sl
209
221 template <class Expr_T, type_traits::requires_t<
224 = 0>
225 constexpr auto
226 assume (const Expr_T& expr, const reflection::source_location& sl
228
229 // --------------------------------------------------------------------------
230
231#if defined(__cpp_exceptions)
232
243 template <class Exception_T, class Callable_T>
244 [[nodiscard]] constexpr auto
245 throws (const Callable_T& func);
246
256 template <class Callable_T>
257 [[nodiscard]] constexpr auto
258 throws (const Callable_T& func);
259
268 template <class Callable_T>
269 [[nodiscard]] constexpr auto
270 nothrow (const Callable_T& func);
271
272#endif
273
274 // --------------------------------------------------------------------------
275
294 namespace utility
295 {
305 [[nodiscard]] bool
306 is_match (std::string_view input, std::string_view pattern);
307
319 template <class T, class Delim_T>
320 [[nodiscard]] auto
321 split (T input, Delim_T delim) -> std::vector<T>;
322
323 // ------------------------------------------------------------------------
324 } // namespace utility
325
326 // --------------------------------------------------------------------------
327} // namespace micro_os_plus::micro_test_plus
328
329#if defined(__GNUC__)
330#pragma GCC diagnostic pop
331#endif
332
333// ----------------------------------------------------------------------------
334
335#endif // __cplusplus
336
337// ===== Inlines & templates implementations
338// ====================================
339
340// All inlines are included **after** all declarations.
344
347
350
352
353// ----------------------------------------------------------------------------
354
355#endif // MICRO_TEST_PLUS_MICRO_TEST_PLUS_H_
356
357// ----------------------------------------------------------------------------

Generated via docusaurus-plugin-doxygen by Doxygen 1.14.0.