Skip to main content

The micro-test-plus-inlines.h File Reference

C++ header file with inline implementations for the µTest++ Testing Framework. More...

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

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

constexpr autoexpect (const Expr_T &expr, const reflection::source_location &sl=reflection::source_location::current())

Evaluate a generic condition and report the results. 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

C++ header file with inline implementations for the µTest++ Testing Framework.

This header provides the inline implementations for the principal public API functions and utilities of the µTest++ framework, including test case registration, expectation and assumption evaluation, exception verification, and utility helpers for string processing in tests.

It defines the logic for registering and executing test cases, evaluating logical conditions and custom comparators, and reporting test results with detailed diagnostics. The exception verification functions enable robust testing of error handling and exception safety, while utility functions such as string splitting support flexible validation of string processing logic.

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 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
46
47#ifndef MICRO_TEST_PLUS_INLINES_H_
48#define MICRO_TEST_PLUS_INLINES_H_
49
50// ----------------------------------------------------------------------------
51
52#ifdef __cplusplus
53
54// ----------------------------------------------------------------------------
55
56#if defined(__GNUC__)
57#pragma GCC diagnostic push
58#pragma GCC diagnostic ignored "-Waggregate-return"
59#pragma GCC diagnostic ignored "-Wpadded"
60#if defined(__clang__)
61#pragma clang diagnostic ignored "-Wc++98-compat"
62#pragma clang diagnostic ignored "-Wc++98-c++11-c++14-c++17-compat-pedantic"
63#endif
64#endif
65
67{
68 // --------------------------------------------------------------------------
69
70#if defined(__clang__)
71#pragma clang diagnostic push
72#pragma clang diagnostic ignored "-Wdocumentation"
73#endif
109#if defined(__clang__)
110#pragma clang diagnostic pop
111#endif
112 template <typename Callable_T, typename... Args_T>
113 void
114 test_case (const char* name, Callable_T&& callable, Args_T&&... arguments)
115 {
116#if 0 // defined(MICRO_OS_PLUS_TRACE_MICRO_TEST_PLUS)
117 printf ("%s\n", __PRETTY_FUNCTION__);
118#endif // MICRO_OS_PLUS_TRACE_MICRO_TEST_PLUS
119
120 current_test_suite->begin_test_case (name);
121 std::invoke (std::forward<Callable_T> (callable),
122 std::forward<Args_T> (arguments)...);
123 current_test_suite->end_test_case ();
124 }
125
150
151 template <class Expr_T, type_traits::requires_t<
154 constexpr auto
155 expect (const Expr_T& expr, const reflection::source_location& sl)
156 {
157 return detail::deferred_reporter<Expr_T>{ expr, false, sl };
158 }
159
184 template <class Expr_T, type_traits::requires_t<
187 constexpr auto
188 assume (const Expr_T& expr, const reflection::source_location& sl)
189 {
190 return detail::deferred_reporter<Expr_T>{ expr, true, sl };
191 }
192
193#if defined(__cpp_exceptions)
194
205 template <class Exception_T, class Callable_T>
206 [[nodiscard]] constexpr auto
207 throws (const Callable_T& func)
208 {
210 }
211
222 template <class Callable_T>
223 [[nodiscard]] constexpr auto
224 throws (const Callable_T& func)
225 {
226 return detail::throws_<Callable_T>{ func };
227 }
228
240 template <class Callable_T>
241 [[nodiscard]] constexpr auto
242 nothrow (const Callable_T& func)
243 {
244 return detail::nothrow_<Callable_T>{ func };
245 }
246
247#endif // defined(__cpp_exceptions)
248
249 // --------------------------------------------------------------------------
250 namespace utility
251 {
273 template <class T = std::string_view, class Delim_T>
274 [[nodiscard]] auto
275 split (T input, Delim_T delim) -> std::vector<T>
276 {
277 std::vector<T> output{};
278 std::size_t first{};
279 while (first < std::size (input))
280 {
281 const auto second = input.find_first_of (delim, first);
282 if (first != second)
283 {
284 output.emplace_back (input.substr (first, second - first));
285 }
286 if (second == T::npos)
287 {
288 break;
289 }
290 first = second + 1;
291 }
292 return output;
293 }
294
295 // ------------------------------------------------------------------------
296 } // namespace utility
297
298 // --------------------------------------------------------------------------
299} // namespace micro_os_plus::micro_test_plus
300
301#if defined(__GNUC__)
302#pragma GCC diagnostic pop
303#endif
304
305// ----------------------------------------------------------------------------
306
307#endif // __cplusplus
308
309// ----------------------------------------------------------------------------
310
311#endif // MICRO_TEST_PLUS_INLINES_H_
312
313// ----------------------------------------------------------------------------

Generated via docusaurus-plugin-doxygen by Doxygen 1.14.0.