micro-test-plus 3.2.2
µ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 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
9 * be 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
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;
122 extern test_reporter reporter;
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// ----------------------------------------------------------------------------
Local implementation of source location information for diagnostics.
Definition reflection.h:137
static constexpr auto 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:97
Base class for all test suites.
Definition test-suite.h:98
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_runner runner
Global instance of test_runner.
test_suite_base * current_test_suite
Global pointer references the currently active test suite.
test_reporter reporter
Global instance of test_reporter.
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 inline implementations for the µTest++ 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.