micro-test-plus 3.2.2
µTest++ Testing Framework
Loading...
Searching...
No Matches
micro-test-plus-inlines.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
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// ----------------------------------------------------------------------------
Deferred reporter class template for a specific expression.
Definition detail.h:1837
Local implementation of source location information for diagnostics.
Definition reflection.h:137
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.
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.
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.
Primary namespace for the µTest++ testing framework.
test_suite_base * current_test_suite
Global pointer references the currently active test suite.
Operator struct template to check if an expression does not throw any exception.
Definition detail.h:1673
Operator struct template to check if an expression throws a specific exception.
Definition detail.h:1512