micro-test-plus 3.2.2
The µTest++ Testing Framework
Loading...
Searching...
No Matches
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#ifndef MICRO_TEST_PLUS_INLINES_H_
17#define MICRO_TEST_PLUS_INLINES_H_
18
19// ----------------------------------------------------------------------------
20
21#ifdef __cplusplus
22
23// ----------------------------------------------------------------------------
24
25#if defined(__GNUC__)
26#pragma GCC diagnostic push
27#pragma GCC diagnostic ignored "-Waggregate-return"
28#pragma GCC diagnostic ignored "-Wpadded"
29#if defined(__clang__)
30#pragma clang diagnostic ignored "-Wc++98-compat"
31#pragma clang diagnostic ignored "-Wc++98-c++11-c++14-c++17-compat-pedantic"
32#endif
33#endif
34
36{
37 // --------------------------------------------------------------------------
38
39 template <typename Callable_T, typename... Args_T>
40 test_suite::test_suite (const char* name, Callable_T&& callable,
41 Args_T&&... arguments)
43 callable_{ std::bind (callable, arguments...) }
44 {
45#if defined(MICRO_OS_PLUS_TRACE_MICRO_TEST_PLUS)
46 printf ("%s\n", __PRETTY_FUNCTION__);
47#endif // MICRO_OS_PLUS_TRACE_MICRO_TEST_PLUS
48
49 runner.register_test_suite (this);
50 }
51
52 // --------------------------------------------------------------------------
53
54#if defined(__clang__)
55#pragma clang diagnostic push
56#pragma clang diagnostic ignored "-Wdocumentation"
57#endif
87#if defined(__clang__)
88#pragma clang diagnostic pop
89#endif
90 template <typename Callable_T, typename... Args_T>
91 void
92 test_case (const char* name, Callable_T&& callable, Args_T&&... arguments)
93 {
94#if 0 // defined(MICRO_OS_PLUS_TRACE_MICRO_TEST_PLUS)
95 printf ("%s\n", __PRETTY_FUNCTION__);
96#endif // MICRO_OS_PLUS_TRACE_MICRO_TEST_PLUS
97
98 current_test_suite->begin_test_case (name);
99 std::invoke (std::forward<Callable_T> (callable),
100 std::forward<Args_T> (arguments)...);
101 current_test_suite->end_test_case ();
102 }
103
104 // --------------------------------------------------------------------------
105 namespace detail
106 {
107 // ------------------------------------------------------------------------
108
109 template <class T>
110 auto&
112 {
113 if constexpr (std::is_arithmetic_v<T>)
114 {
115 message_.append (std::to_string (msg));
116 }
117 else
118 {
119 message_.append (msg);
120 }
121 return *this;
122 }
123
124 // ------------------------------------------------------------------------
125
126 template <class Expr_T>
128 const Expr_T& expr, bool abort,
129 const reflection::source_location& location)
130 : deferred_reporter_base{ static_cast<bool> (expr), location },
131 expr_{ expr }
132 {
133#if 0 // defined(MICRO_OS_PLUS_TRACE_MICRO_TEST_PLUS)
134 printf ("%s\n", __PRETTY_FUNCTION__);
135#endif // MICRO_OS_PLUS_TRACE_MICRO_TEST_PLUS
136 abort_ = abort;
137 }
138
139 template <class Expr_T>
141 {
142 if (value_)
143 {
144 reporter.pass (expr_, message_);
145 }
146 else
147 {
149 }
150 }
151
152 // ------------------------------------------------------------------------
153 } // namespace detail
154
155 // --------------------------------------------------------------------------
156 namespace utility
157 {
172 template <class T = std::string_view, class Delim_T>
173 [[nodiscard]] auto
174 split (T input, Delim_T delim) -> std::vector<T>
175 {
176 std::vector<T> output{};
177 std::size_t first{};
178 while (first < std::size (input))
179 {
180 const auto second = input.find_first_of (delim, first);
181 if (first != second)
182 {
183 output.emplace_back (input.substr (first, second - first));
184 }
185 if (second == T::npos)
186 {
187 break;
188 }
189 first = second + 1;
190 }
191 return output;
192 }
193 } // namespace utility
194
195} // namespace micro_os_plus::micro_test_plus
196
197#if defined(__GNUC__)
198#pragma GCC diagnostic pop
199#endif
200
201// ----------------------------------------------------------------------------
202
203#endif // __cplusplus
204
205// ----------------------------------------------------------------------------
206
207#endif // MICRO_TEST_PLUS_INLINES_H_
208
209// ----------------------------------------------------------------------------
std::string message_
String to collect the expectation message passed via operator<<().
Definition detail.h:725
deferred_reporter_base(bool value, const reflection::source_location location)
constexpr deferred_reporter(const Expr_T &expr, bool abort, const reflection::source_location &location)
Definition inlines.h:127
Local implementation of the std::source_location.
Definition reflection.h:57
test_suite_base(const char *name)
Construct a test suite.
constexpr const char * name()
Get the suite name.
Definition test-suite.h:106
std::function< void(void)> callable_
Definition test-suite.h:288
test_suite(const char *name, Callable_T &&callable, Args_T &&... arguments)
Construct a test suite.
Definition inlines.h:40
void test_case(const char *name, Callable_T &&callable, Args_T &&... arguments)
Define and execute a test case.
Definition inlines.h:92
auto split(T input, Delim_T delim) -> std::vector< T >
Split a string into a vector of sub-strings.
Definition inlines.h:174