micro-test-plus 3.3.1
µTest++ Testing Framework
Loading...
Searching...
No Matches
micro-test-plus.h
Go to the documentation of this file.
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.0 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// ----------------------------------------------------------------------------
Local implementation of source location information for diagnostics.
Definition reflection.h:137
static constexpr source_location current(const char *file="unknown", unsigned int line={}) noexcept
Obtain the current source location.
Reporter to display test results, including operand values and types for failures.
The test runner for the µTest++ framework.
Definition test-runner.h:99
Base class for all test suites.
Definition test-suite.h:100
C++ header file with declarations for the µTest++ internals.
C++ header file with inline implementations for the µTest++ internals.
C++ header file with inline implementations for the µTest++ function comparators.
C++ header file with declarations for the µTest++ function comparators.
constexpr auto assume(const Expr_T &expr, const reflection::source_location &sl=reflection::source_location::current())
Check a condition and, if false, abort test execution.
constexpr auto nothrow(const Callable_T &func)
Check if a callable does not throw an exception.
constexpr auto expect(const Expr_T &expr, const reflection::source_location &sl=reflection::source_location::current())
Evaluate a generic condition and report the results.
int exit_code(void)
Complete the test run and return the exit code.
void initialize(int argc, char *argv[], const char *name="Main")
Initialise the µTest++ framework.
void test_case(const char *name, Callable_T &&callable, Args_T &&... arguments)
Define and execute a test case.
auto split(T input, Delim_T delim) -> std::vector< T >
Split a string into a vector of sub-strings.
bool is_match(std::string_view input, std::string_view pattern)
Check if a string matches a pattern.
C++ header file with inline implementations for the µTest++ literals and type wrappers.
C++ header file with declarations for the µTest++ user-defined literals and type wrappers.
C++ header file with inline implementations for the µTest++ mathematical utilities.
C++ header file with declarations for the µTest++ mathematical utilities.
C++ header file with inline implementations for the µTest++ Testing Framework.
typename requires_< Cond >::type requires_t
Alias template for extracting the type member from requires_.
constexpr auto is_convertible_v
Variable template to determine if one type is convertible to another.
constexpr auto is_op_v
Variable template to determine if a type derives from op.
Utility functions for the µTest++ testing framework.
Primary namespace for the µTest++ testing framework.
test_reporter * reporter
Global pointer to test_reporter.
test_runner runner
Global instance of test_runner.
test_suite_base * current_test_suite
Global pointer references the currently active test suite.
C++ header file with declarations for the µTest++ operators.
C++ header file with inline implementations for the µTest++ reflection utilities.
C++ header file with declarations for the µTest++ reflection utilities.
C++ header file with declarations for the µTest++ basic test reporter.
C++ header file with inline implementations for the µTest++ test reporter.
C++ header file with declarations for the µTest++ TAP test reporter.
C++ header file with declarations for the µTest++ test reporter.
C++ header file with declarations for the µTest++ test runner.
C++ header file with inline implementations for the µTest++ test suite.
C++ header file with declarations for the µTest++ test suite.
C++ header file with declarations for the µTest++ type trait utilities and metaprogramming support.