enum_name
Loading...
Searching...
No Matches
doctest_fwd.h
1//
2// doctest.h - the lightest feature-rich C++ single-header testing framework for unit tests and TDD
3//
4// Copyright (c) 2016-2023 Viktor Kirilov
5//
6// Distributed under the MIT Software License
7// See accompanying file LICENSE.txt or copy at
8// https://opensource.org/licenses/MIT
9//
10// The documentation can be found at the library's page:
11// https://github.com/doctest/doctest/blob/master/doc/markdown/readme.md
12//
13// =================================================================================================
14// =================================================================================================
15// =================================================================================================
16//
17// The library is heavily influenced by Catch - https://github.com/catchorg/Catch2
18// which uses the Boost Software License - Version 1.0
19// see here - https://github.com/catchorg/Catch2/blob/master/LICENSE.txt
20//
21// The concept of subcases (sections in Catch) and expression decomposition are from there.
22// Some parts of the code are taken directly:
23// - stringification - the detection of "ostream& operator<<(ostream&, const T&)" and StringMaker<>
24// - the Approx() helper class for floating point comparison
25// - colors in the console
26// - breaking into a debugger
27// - signal / SEH handling
28// - timer
29// - XmlWriter class - thanks to Phil Nash for allowing the direct reuse (AKA copy/paste)
30//
31// The expression decomposing templates are taken from lest - https://github.com/martinmoene/lest
32// which uses the Boost Software License - Version 1.0
33// see here - https://github.com/martinmoene/lest/blob/master/LICENSE.txt
34//
35// =================================================================================================
36// =================================================================================================
37// =================================================================================================
38
39#ifndef DOCTEST_LIBRARY_INCLUDED
40#define DOCTEST_LIBRARY_INCLUDED
41
42// =================================================================================================
43// == VERSION ======================================================================================
44// =================================================================================================
45
46#define DOCTEST_VERSION_MAJOR 2
47#define DOCTEST_VERSION_MINOR 4
48#define DOCTEST_VERSION_PATCH 11
49
50// util we need here
51#define DOCTEST_TOSTR_IMPL(x) #x
52#define DOCTEST_TOSTR(x) DOCTEST_TOSTR_IMPL(x)
53
54#define DOCTEST_VERSION_STR \
55 DOCTEST_TOSTR(DOCTEST_VERSION_MAJOR) "." \
56 DOCTEST_TOSTR(DOCTEST_VERSION_MINOR) "." \
57 DOCTEST_TOSTR(DOCTEST_VERSION_PATCH)
58
59#define DOCTEST_VERSION \
60 (DOCTEST_VERSION_MAJOR * 10000 + DOCTEST_VERSION_MINOR * 100 + DOCTEST_VERSION_PATCH)
61
62// =================================================================================================
63// == COMPILER VERSION =============================================================================
64// =================================================================================================
65
66// ideas for the version stuff are taken from here: https://github.com/cxxstuff/cxx_detect
67
68#ifdef _MSC_VER
69#define DOCTEST_CPLUSPLUS _MSVC_LANG
70#else
71#define DOCTEST_CPLUSPLUS __cplusplus
72#endif
73
74#define DOCTEST_COMPILER(MAJOR, MINOR, PATCH) ((MAJOR)*10000000 + (MINOR)*100000 + (PATCH))
75
76// GCC/Clang and GCC/MSVC are mutually exclusive, but Clang/MSVC are not because of clang-cl...
77#if defined(_MSC_VER) && defined(_MSC_FULL_VER)
78#if _MSC_VER == _MSC_FULL_VER / 10000
79#define DOCTEST_MSVC DOCTEST_COMPILER(_MSC_VER / 100, _MSC_VER % 100, _MSC_FULL_VER % 10000)
80#else // MSVC
81#define DOCTEST_MSVC \
82 DOCTEST_COMPILER(_MSC_VER / 100, (_MSC_FULL_VER / 100000) % 100, _MSC_FULL_VER % 100000)
83#endif // MSVC
84#endif // MSVC
85#if defined(__clang__) && defined(__clang_minor__) && defined(__clang_patchlevel__)
86#define DOCTEST_CLANG DOCTEST_COMPILER(__clang_major__, __clang_minor__, __clang_patchlevel__)
87#elif defined(__GNUC__) && defined(__GNUC_MINOR__) && defined(__GNUC_PATCHLEVEL__) && \
88 !defined(__INTEL_COMPILER)
89#define DOCTEST_GCC DOCTEST_COMPILER(__GNUC__, __GNUC_MINOR__, __GNUC_PATCHLEVEL__)
90#endif // GCC
91#if defined(__INTEL_COMPILER)
92#define DOCTEST_ICC DOCTEST_COMPILER(__INTEL_COMPILER / 100, __INTEL_COMPILER % 100, 0)
93#endif // ICC
94
95#ifndef DOCTEST_MSVC
96#define DOCTEST_MSVC 0
97#endif // DOCTEST_MSVC
98#ifndef DOCTEST_CLANG
99#define DOCTEST_CLANG 0
100#endif // DOCTEST_CLANG
101#ifndef DOCTEST_GCC
102#define DOCTEST_GCC 0
103#endif // DOCTEST_GCC
104#ifndef DOCTEST_ICC
105#define DOCTEST_ICC 0
106#endif // DOCTEST_ICC
107
108// =================================================================================================
109// == COMPILER WARNINGS HELPERS ====================================================================
110// =================================================================================================
111
112#if DOCTEST_CLANG && !DOCTEST_ICC
113#define DOCTEST_PRAGMA_TO_STR(x) _Pragma(#x)
114#define DOCTEST_CLANG_SUPPRESS_WARNING_PUSH _Pragma("clang diagnostic push")
115#define DOCTEST_CLANG_SUPPRESS_WARNING(w) DOCTEST_PRAGMA_TO_STR(clang diagnostic ignored w)
116#define DOCTEST_CLANG_SUPPRESS_WARNING_POP _Pragma("clang diagnostic pop")
117#define DOCTEST_CLANG_SUPPRESS_WARNING_WITH_PUSH(w) \
118 DOCTEST_CLANG_SUPPRESS_WARNING_PUSH DOCTEST_CLANG_SUPPRESS_WARNING(w)
119#else // DOCTEST_CLANG
120#define DOCTEST_CLANG_SUPPRESS_WARNING_PUSH
121#define DOCTEST_CLANG_SUPPRESS_WARNING(w)
122#define DOCTEST_CLANG_SUPPRESS_WARNING_POP
123#define DOCTEST_CLANG_SUPPRESS_WARNING_WITH_PUSH(w)
124#endif // DOCTEST_CLANG
125
126#if DOCTEST_GCC
127#define DOCTEST_PRAGMA_TO_STR(x) _Pragma(#x)
128#define DOCTEST_GCC_SUPPRESS_WARNING_PUSH _Pragma("GCC diagnostic push")
129#define DOCTEST_GCC_SUPPRESS_WARNING(w) DOCTEST_PRAGMA_TO_STR(GCC diagnostic ignored w)
130#define DOCTEST_GCC_SUPPRESS_WARNING_POP _Pragma("GCC diagnostic pop")
131#define DOCTEST_GCC_SUPPRESS_WARNING_WITH_PUSH(w) \
132 DOCTEST_GCC_SUPPRESS_WARNING_PUSH DOCTEST_GCC_SUPPRESS_WARNING(w)
133#else // DOCTEST_GCC
134#define DOCTEST_GCC_SUPPRESS_WARNING_PUSH
135#define DOCTEST_GCC_SUPPRESS_WARNING(w)
136#define DOCTEST_GCC_SUPPRESS_WARNING_POP
137#define DOCTEST_GCC_SUPPRESS_WARNING_WITH_PUSH(w)
138#endif // DOCTEST_GCC
139
140#if DOCTEST_MSVC
141#define DOCTEST_MSVC_SUPPRESS_WARNING_PUSH __pragma(warning(push))
142#define DOCTEST_MSVC_SUPPRESS_WARNING(w) __pragma(warning(disable : w))
143#define DOCTEST_MSVC_SUPPRESS_WARNING_POP __pragma(warning(pop))
144#define DOCTEST_MSVC_SUPPRESS_WARNING_WITH_PUSH(w) \
145 DOCTEST_MSVC_SUPPRESS_WARNING_PUSH DOCTEST_MSVC_SUPPRESS_WARNING(w)
146#else // DOCTEST_MSVC
147#define DOCTEST_MSVC_SUPPRESS_WARNING_PUSH
148#define DOCTEST_MSVC_SUPPRESS_WARNING(w)
149#define DOCTEST_MSVC_SUPPRESS_WARNING_POP
150#define DOCTEST_MSVC_SUPPRESS_WARNING_WITH_PUSH(w)
151#endif // DOCTEST_MSVC
152
153// =================================================================================================
154// == COMPILER WARNINGS ============================================================================
155// =================================================================================================
156
157// both the header and the implementation suppress all of these,
158// so it only makes sense to aggregate them like so
159#define DOCTEST_SUPPRESS_COMMON_WARNINGS_PUSH \
160 DOCTEST_CLANG_SUPPRESS_WARNING_PUSH \
161 DOCTEST_CLANG_SUPPRESS_WARNING("-Wunknown-pragmas") \
162 DOCTEST_CLANG_SUPPRESS_WARNING("-Wweak-vtables") \
163 DOCTEST_CLANG_SUPPRESS_WARNING("-Wpadded") \
164 DOCTEST_CLANG_SUPPRESS_WARNING("-Wmissing-prototypes") \
165 DOCTEST_CLANG_SUPPRESS_WARNING("-Wc++98-compat") \
166 DOCTEST_CLANG_SUPPRESS_WARNING("-Wc++98-compat-pedantic") \
167 \
168 DOCTEST_GCC_SUPPRESS_WARNING_PUSH \
169 DOCTEST_GCC_SUPPRESS_WARNING("-Wunknown-pragmas") \
170 DOCTEST_GCC_SUPPRESS_WARNING("-Wpragmas") \
171 DOCTEST_GCC_SUPPRESS_WARNING("-Weffc++") \
172 DOCTEST_GCC_SUPPRESS_WARNING("-Wstrict-overflow") \
173 DOCTEST_GCC_SUPPRESS_WARNING("-Wstrict-aliasing") \
174 DOCTEST_GCC_SUPPRESS_WARNING("-Wmissing-declarations") \
175 DOCTEST_GCC_SUPPRESS_WARNING("-Wuseless-cast") \
176 DOCTEST_GCC_SUPPRESS_WARNING("-Wnoexcept") \
177 \
178 DOCTEST_MSVC_SUPPRESS_WARNING_PUSH \
179 /* these 4 also disabled globally via cmake: */ \
180 DOCTEST_MSVC_SUPPRESS_WARNING(4514) /* unreferenced inline function has been removed */ \
181 DOCTEST_MSVC_SUPPRESS_WARNING(4571) /* SEH related */ \
182 DOCTEST_MSVC_SUPPRESS_WARNING(4710) /* function not inlined */ \
183 DOCTEST_MSVC_SUPPRESS_WARNING(4711) /* function selected for inline expansion*/ \
184 /* common ones */ \
185 DOCTEST_MSVC_SUPPRESS_WARNING(4616) /* invalid compiler warning */ \
186 DOCTEST_MSVC_SUPPRESS_WARNING(4619) /* invalid compiler warning */ \
187 DOCTEST_MSVC_SUPPRESS_WARNING(4996) /* The compiler encountered a deprecated declaration */ \
188 DOCTEST_MSVC_SUPPRESS_WARNING(4706) /* assignment within conditional expression */ \
189 DOCTEST_MSVC_SUPPRESS_WARNING(4512) /* 'class' : assignment operator could not be generated */ \
190 DOCTEST_MSVC_SUPPRESS_WARNING(4127) /* conditional expression is constant */ \
191 DOCTEST_MSVC_SUPPRESS_WARNING(4820) /* padding */ \
192 DOCTEST_MSVC_SUPPRESS_WARNING(4625) /* copy constructor was implicitly deleted */ \
193 DOCTEST_MSVC_SUPPRESS_WARNING(4626) /* assignment operator was implicitly deleted */ \
194 DOCTEST_MSVC_SUPPRESS_WARNING(5027) /* move assignment operator implicitly deleted */ \
195 DOCTEST_MSVC_SUPPRESS_WARNING(5026) /* move constructor was implicitly deleted */ \
196 DOCTEST_MSVC_SUPPRESS_WARNING(4640) /* construction of local static object not thread-safe */ \
197 DOCTEST_MSVC_SUPPRESS_WARNING(5045) /* Spectre mitigation for memory load */ \
198 DOCTEST_MSVC_SUPPRESS_WARNING(5264) /* 'variable-name': 'const' variable is not used */ \
199 /* static analysis */ \
200 DOCTEST_MSVC_SUPPRESS_WARNING(26439) /* Function may not throw. Declare it 'noexcept' */ \
201 DOCTEST_MSVC_SUPPRESS_WARNING(26495) /* Always initialize a member variable */ \
202 DOCTEST_MSVC_SUPPRESS_WARNING(26451) /* Arithmetic overflow ... */ \
203 DOCTEST_MSVC_SUPPRESS_WARNING(26444) /* Avoid unnamed objects with custom ctor and dtor... */ \
204 DOCTEST_MSVC_SUPPRESS_WARNING(26812) /* Prefer 'enum class' over 'enum' */
205
206#define DOCTEST_SUPPRESS_COMMON_WARNINGS_POP \
207 DOCTEST_CLANG_SUPPRESS_WARNING_POP \
208 DOCTEST_GCC_SUPPRESS_WARNING_POP \
209 DOCTEST_MSVC_SUPPRESS_WARNING_POP
210
211DOCTEST_SUPPRESS_COMMON_WARNINGS_PUSH
212
213DOCTEST_CLANG_SUPPRESS_WARNING_PUSH
214DOCTEST_CLANG_SUPPRESS_WARNING("-Wnon-virtual-dtor")
215DOCTEST_CLANG_SUPPRESS_WARNING("-Wdeprecated")
216
217DOCTEST_GCC_SUPPRESS_WARNING_PUSH
218DOCTEST_GCC_SUPPRESS_WARNING("-Wctor-dtor-privacy")
219DOCTEST_GCC_SUPPRESS_WARNING("-Wnon-virtual-dtor")
220DOCTEST_GCC_SUPPRESS_WARNING("-Wsign-promo")
221
222DOCTEST_MSVC_SUPPRESS_WARNING_PUSH
223DOCTEST_MSVC_SUPPRESS_WARNING(4623) // default constructor was implicitly defined as deleted
224
225#define DOCTEST_MAKE_STD_HEADERS_CLEAN_FROM_WARNINGS_ON_WALL_BEGIN \
226 DOCTEST_MSVC_SUPPRESS_WARNING_PUSH \
227 DOCTEST_MSVC_SUPPRESS_WARNING(4548) /* before comma no effect; expected side - effect */ \
228 DOCTEST_MSVC_SUPPRESS_WARNING(4265) /* virtual functions, but destructor is not virtual */ \
229 DOCTEST_MSVC_SUPPRESS_WARNING(4986) /* exception specification does not match previous */ \
230 DOCTEST_MSVC_SUPPRESS_WARNING(4350) /* 'member1' called instead of 'member2' */ \
231 DOCTEST_MSVC_SUPPRESS_WARNING(4668) /* not defined as a preprocessor macro */ \
232 DOCTEST_MSVC_SUPPRESS_WARNING(4365) /* signed/unsigned mismatch */ \
233 DOCTEST_MSVC_SUPPRESS_WARNING(4774) /* format string not a string literal */ \
234 DOCTEST_MSVC_SUPPRESS_WARNING(4820) /* padding */ \
235 DOCTEST_MSVC_SUPPRESS_WARNING(4625) /* copy constructor was implicitly deleted */ \
236 DOCTEST_MSVC_SUPPRESS_WARNING(4626) /* assignment operator was implicitly deleted */ \
237 DOCTEST_MSVC_SUPPRESS_WARNING(5027) /* move assignment operator implicitly deleted */ \
238 DOCTEST_MSVC_SUPPRESS_WARNING(5026) /* move constructor was implicitly deleted */ \
239 DOCTEST_MSVC_SUPPRESS_WARNING(4623) /* default constructor was implicitly deleted */ \
240 DOCTEST_MSVC_SUPPRESS_WARNING(5039) /* pointer to pot. throwing function passed to extern C */ \
241 DOCTEST_MSVC_SUPPRESS_WARNING(5045) /* Spectre mitigation for memory load */ \
242 DOCTEST_MSVC_SUPPRESS_WARNING(5105) /* macro producing 'defined' has undefined behavior */ \
243 DOCTEST_MSVC_SUPPRESS_WARNING(4738) /* storing float result in memory, loss of performance */ \
244 DOCTEST_MSVC_SUPPRESS_WARNING(5262) /* implicit fall-through */
245
246#define DOCTEST_MAKE_STD_HEADERS_CLEAN_FROM_WARNINGS_ON_WALL_END DOCTEST_MSVC_SUPPRESS_WARNING_POP
247
248// =================================================================================================
249// == FEATURE DETECTION ============================================================================
250// =================================================================================================
251
252// general compiler feature support table: https://en.cppreference.com/w/cpp/compiler_support
253// MSVC C++11 feature support table: https://msdn.microsoft.com/en-us/library/hh567368.aspx
254// GCC C++11 feature support table: https://gcc.gnu.org/projects/cxx-status.html
255// MSVC version table:
256// https://en.wikipedia.org/wiki/Microsoft_Visual_C%2B%2B#Internal_version_numbering
257// MSVC++ 14.3 (17) _MSC_VER == 1930 (Visual Studio 2022)
258// MSVC++ 14.2 (16) _MSC_VER == 1920 (Visual Studio 2019)
259// MSVC++ 14.1 (15) _MSC_VER == 1910 (Visual Studio 2017)
260// MSVC++ 14.0 _MSC_VER == 1900 (Visual Studio 2015)
261// MSVC++ 12.0 _MSC_VER == 1800 (Visual Studio 2013)
262// MSVC++ 11.0 _MSC_VER == 1700 (Visual Studio 2012)
263// MSVC++ 10.0 _MSC_VER == 1600 (Visual Studio 2010)
264// MSVC++ 9.0 _MSC_VER == 1500 (Visual Studio 2008)
265// MSVC++ 8.0 _MSC_VER == 1400 (Visual Studio 2005)
266
267// Universal Windows Platform support
268#if defined(WINAPI_FAMILY) && (WINAPI_FAMILY == WINAPI_FAMILY_APP)
269#define DOCTEST_CONFIG_NO_WINDOWS_SEH
270#endif // WINAPI_FAMILY
271#if DOCTEST_MSVC && !defined(DOCTEST_CONFIG_WINDOWS_SEH)
272#define DOCTEST_CONFIG_WINDOWS_SEH
273#endif // MSVC
274#if defined(DOCTEST_CONFIG_NO_WINDOWS_SEH) && defined(DOCTEST_CONFIG_WINDOWS_SEH)
275#undef DOCTEST_CONFIG_WINDOWS_SEH
276#endif // DOCTEST_CONFIG_NO_WINDOWS_SEH
277
278#if !defined(_WIN32) && !defined(__QNX__) && !defined(DOCTEST_CONFIG_POSIX_SIGNALS) && \
279 !defined(__EMSCRIPTEN__) && !defined(__wasi__)
280#define DOCTEST_CONFIG_POSIX_SIGNALS
281#endif // _WIN32
282#if defined(DOCTEST_CONFIG_NO_POSIX_SIGNALS) && defined(DOCTEST_CONFIG_POSIX_SIGNALS)
283#undef DOCTEST_CONFIG_POSIX_SIGNALS
284#endif // DOCTEST_CONFIG_NO_POSIX_SIGNALS
285
286#ifndef DOCTEST_CONFIG_NO_EXCEPTIONS
287#if !defined(__cpp_exceptions) && !defined(__EXCEPTIONS) && !defined(_CPPUNWIND) \
288 || defined(__wasi__)
289#define DOCTEST_CONFIG_NO_EXCEPTIONS
290#endif // no exceptions
291#endif // DOCTEST_CONFIG_NO_EXCEPTIONS
292
293#ifdef DOCTEST_CONFIG_NO_EXCEPTIONS_BUT_WITH_ALL_ASSERTS
294#ifndef DOCTEST_CONFIG_NO_EXCEPTIONS
295#define DOCTEST_CONFIG_NO_EXCEPTIONS
296#endif // DOCTEST_CONFIG_NO_EXCEPTIONS
297#endif // DOCTEST_CONFIG_NO_EXCEPTIONS_BUT_WITH_ALL_ASSERTS
298
299#if defined(DOCTEST_CONFIG_NO_EXCEPTIONS) && !defined(DOCTEST_CONFIG_NO_TRY_CATCH_IN_ASSERTS)
300#define DOCTEST_CONFIG_NO_TRY_CATCH_IN_ASSERTS
301#endif // DOCTEST_CONFIG_NO_EXCEPTIONS && !DOCTEST_CONFIG_NO_TRY_CATCH_IN_ASSERTS
302
303#ifdef __wasi__
304#define DOCTEST_CONFIG_NO_MULTITHREADING
305#endif
306
307#if defined(DOCTEST_CONFIG_IMPLEMENT_WITH_MAIN) && !defined(DOCTEST_CONFIG_IMPLEMENT)
308#define DOCTEST_CONFIG_IMPLEMENT
309#endif // DOCTEST_CONFIG_IMPLEMENT_WITH_MAIN
310
311#if defined(_WIN32) || defined(__CYGWIN__)
312#if DOCTEST_MSVC
313#define DOCTEST_SYMBOL_EXPORT __declspec(dllexport)
314#define DOCTEST_SYMBOL_IMPORT __declspec(dllimport)
315#else // MSVC
316#define DOCTEST_SYMBOL_EXPORT __attribute__((dllexport))
317#define DOCTEST_SYMBOL_IMPORT __attribute__((dllimport))
318#endif // MSVC
319#else // _WIN32
320#define DOCTEST_SYMBOL_EXPORT __attribute__((visibility("default")))
321#define DOCTEST_SYMBOL_IMPORT
322#endif // _WIN32
323
324#ifdef DOCTEST_CONFIG_IMPLEMENTATION_IN_DLL
325#ifdef DOCTEST_CONFIG_IMPLEMENT
326#define DOCTEST_INTERFACE DOCTEST_SYMBOL_EXPORT
327#else // DOCTEST_CONFIG_IMPLEMENT
328#define DOCTEST_INTERFACE DOCTEST_SYMBOL_IMPORT
329#endif // DOCTEST_CONFIG_IMPLEMENT
330#else // DOCTEST_CONFIG_IMPLEMENTATION_IN_DLL
331#define DOCTEST_INTERFACE
332#endif // DOCTEST_CONFIG_IMPLEMENTATION_IN_DLL
333
334// needed for extern template instantiations
335// see https://github.com/fmtlib/fmt/issues/2228
336#if DOCTEST_MSVC
337#define DOCTEST_INTERFACE_DECL
338#define DOCTEST_INTERFACE_DEF DOCTEST_INTERFACE
339#else // DOCTEST_MSVC
340#define DOCTEST_INTERFACE_DECL DOCTEST_INTERFACE
341#define DOCTEST_INTERFACE_DEF
342#endif // DOCTEST_MSVC
343
344#define DOCTEST_EMPTY
345
346#if DOCTEST_MSVC
347#define DOCTEST_NOINLINE __declspec(noinline)
348#define DOCTEST_UNUSED
349#define DOCTEST_ALIGNMENT(x)
350#elif DOCTEST_CLANG && DOCTEST_CLANG < DOCTEST_COMPILER(3, 5, 0)
351#define DOCTEST_NOINLINE
352#define DOCTEST_UNUSED
353#define DOCTEST_ALIGNMENT(x)
354#else
355#define DOCTEST_NOINLINE __attribute__((noinline))
356#define DOCTEST_UNUSED __attribute__((unused))
357#define DOCTEST_ALIGNMENT(x) __attribute__((aligned(x)))
358#endif
359
360#ifdef DOCTEST_CONFIG_NO_CONTRADICTING_INLINE
361#define DOCTEST_INLINE_NOINLINE inline
362#else
363#define DOCTEST_INLINE_NOINLINE inline DOCTEST_NOINLINE
364#endif
365
366#ifndef DOCTEST_NORETURN
367#if DOCTEST_MSVC && (DOCTEST_MSVC < DOCTEST_COMPILER(19, 0, 0))
368#define DOCTEST_NORETURN
369#else // DOCTEST_MSVC
370#define DOCTEST_NORETURN [[noreturn]]
371#endif // DOCTEST_MSVC
372#endif // DOCTEST_NORETURN
373
374#ifndef DOCTEST_NOEXCEPT
375#if DOCTEST_MSVC && (DOCTEST_MSVC < DOCTEST_COMPILER(19, 0, 0))
376#define DOCTEST_NOEXCEPT
377#else // DOCTEST_MSVC
378#define DOCTEST_NOEXCEPT noexcept
379#endif // DOCTEST_MSVC
380#endif // DOCTEST_NOEXCEPT
381
382#ifndef DOCTEST_CONSTEXPR
383#if DOCTEST_MSVC && (DOCTEST_MSVC < DOCTEST_COMPILER(19, 0, 0))
384#define DOCTEST_CONSTEXPR const
385#define DOCTEST_CONSTEXPR_FUNC inline
386#else // DOCTEST_MSVC
387#define DOCTEST_CONSTEXPR constexpr
388#define DOCTEST_CONSTEXPR_FUNC constexpr
389#endif // DOCTEST_MSVC
390#endif // DOCTEST_CONSTEXPR
391
392#ifndef DOCTEST_NO_SANITIZE_INTEGER
393#if DOCTEST_CLANG >= DOCTEST_COMPILER(3, 7, 0)
394#define DOCTEST_NO_SANITIZE_INTEGER __attribute__((no_sanitize("integer")))
395#else
396#define DOCTEST_NO_SANITIZE_INTEGER
397#endif
398#endif // DOCTEST_NO_SANITIZE_INTEGER
399
400// =================================================================================================
401// == FEATURE DETECTION END ========================================================================
402// =================================================================================================
403
404#define DOCTEST_DECLARE_INTERFACE(name) \
405 virtual ~name(); \
406 name() = default; \
407 name(const name&) = delete; \
408 name(name&&) = delete; \
409 name& operator=(const name&) = delete; \
410 name& operator=(name&&) = delete;
411
412#define DOCTEST_DEFINE_INTERFACE(name) \
413 name::~name() = default;
414
415// internal macros for string concatenation and anonymous variable name generation
416#define DOCTEST_CAT_IMPL(s1, s2) s1##s2
417#define DOCTEST_CAT(s1, s2) DOCTEST_CAT_IMPL(s1, s2)
418#ifdef __COUNTER__ // not standard and may be missing for some compilers
419#define DOCTEST_ANONYMOUS(x) DOCTEST_CAT(x, __COUNTER__)
420#else // __COUNTER__
421#define DOCTEST_ANONYMOUS(x) DOCTEST_CAT(x, __LINE__)
422#endif // __COUNTER__
423
424#ifndef DOCTEST_CONFIG_ASSERTION_PARAMETERS_BY_VALUE
425#define DOCTEST_REF_WRAP(x) x&
426#else // DOCTEST_CONFIG_ASSERTION_PARAMETERS_BY_VALUE
427#define DOCTEST_REF_WRAP(x) x
428#endif // DOCTEST_CONFIG_ASSERTION_PARAMETERS_BY_VALUE
429
430// not using __APPLE__ because... this is how Catch does it
431#ifdef __MAC_OS_X_VERSION_MIN_REQUIRED
432#define DOCTEST_PLATFORM_MAC
433#elif defined(__IPHONE_OS_VERSION_MIN_REQUIRED)
434#define DOCTEST_PLATFORM_IPHONE
435#elif defined(_WIN32)
436#define DOCTEST_PLATFORM_WINDOWS
437#elif defined(__wasi__)
438#define DOCTEST_PLATFORM_WASI
439#else // DOCTEST_PLATFORM
440#define DOCTEST_PLATFORM_LINUX
441#endif // DOCTEST_PLATFORM
442
443namespace doctest { namespace detail {
444 static DOCTEST_CONSTEXPR int consume(const int*, int) noexcept { return 0; }
445}}
446
447#define DOCTEST_GLOBAL_NO_WARNINGS(var, ...) \
448 DOCTEST_CLANG_SUPPRESS_WARNING_WITH_PUSH("-Wglobal-constructors") \
449 static const int var = doctest::detail::consume(&var, __VA_ARGS__); \
450 DOCTEST_CLANG_SUPPRESS_WARNING_POP
451
452#ifndef DOCTEST_BREAK_INTO_DEBUGGER
453// should probably take a look at https://github.com/scottt/debugbreak
454#ifdef DOCTEST_PLATFORM_LINUX
455#if defined(__GNUC__) && (defined(__i386) || defined(__x86_64))
456// Break at the location of the failing check if possible
457#define DOCTEST_BREAK_INTO_DEBUGGER() __asm__("int $3\n" : :) // NOLINT(hicpp-no-assembler)
458#else
459#include <signal.h>
460#define DOCTEST_BREAK_INTO_DEBUGGER() raise(SIGTRAP)
461#endif
462#elif defined(DOCTEST_PLATFORM_MAC)
463#if defined(__x86_64) || defined(__x86_64__) || defined(__amd64__) || defined(__i386)
464#define DOCTEST_BREAK_INTO_DEBUGGER() __asm__("int $3\n" : :) // NOLINT(hicpp-no-assembler)
465#elif defined(__ppc__) || defined(__ppc64__)
466// https://www.cocoawithlove.com/2008/03/break-into-debugger.html
467#define DOCTEST_BREAK_INTO_DEBUGGER() __asm__("li r0, 20\nsc\nnop\nli r0, 37\nli r4, 2\nsc\nnop\n": : : "memory","r0","r3","r4") // NOLINT(hicpp-no-assembler)
468#else
469#define DOCTEST_BREAK_INTO_DEBUGGER() __asm__("brk #0"); // NOLINT(hicpp-no-assembler)
470#endif
471#elif DOCTEST_MSVC
472#define DOCTEST_BREAK_INTO_DEBUGGER() __debugbreak()
473#elif defined(__MINGW32__)
474DOCTEST_GCC_SUPPRESS_WARNING_WITH_PUSH("-Wredundant-decls")
475extern "C" __declspec(dllimport) void __stdcall DebugBreak();
476DOCTEST_GCC_SUPPRESS_WARNING_POP
477#define DOCTEST_BREAK_INTO_DEBUGGER() ::DebugBreak()
478#else // linux
479#define DOCTEST_BREAK_INTO_DEBUGGER() (static_cast<void>(0))
480#endif // linux
481#endif // DOCTEST_BREAK_INTO_DEBUGGER
482
483// this is kept here for backwards compatibility since the config option was changed
484#ifdef DOCTEST_CONFIG_USE_IOSFWD
485#ifndef DOCTEST_CONFIG_USE_STD_HEADERS
486#define DOCTEST_CONFIG_USE_STD_HEADERS
487#endif
488#endif // DOCTEST_CONFIG_USE_IOSFWD
489
490// for clang - always include ciso646 (which drags some std stuff) because
491// we want to check if we are using libc++ with the _LIBCPP_VERSION macro in
492// which case we don't want to forward declare stuff from std - for reference:
493// https://github.com/doctest/doctest/issues/126
494// https://github.com/doctest/doctest/issues/356
495#if DOCTEST_CLANG
496#include <ciso646>
497#endif // clang
498
499#ifdef _LIBCPP_VERSION
500#ifndef DOCTEST_CONFIG_USE_STD_HEADERS
501#define DOCTEST_CONFIG_USE_STD_HEADERS
502#endif
503#endif // _LIBCPP_VERSION
504
505#ifdef DOCTEST_CONFIG_USE_STD_HEADERS
506#ifndef DOCTEST_CONFIG_INCLUDE_TYPE_TRAITS
507#define DOCTEST_CONFIG_INCLUDE_TYPE_TRAITS
508#endif // DOCTEST_CONFIG_INCLUDE_TYPE_TRAITS
509DOCTEST_MAKE_STD_HEADERS_CLEAN_FROM_WARNINGS_ON_WALL_BEGIN
510#include <cstddef>
511#include <ostream>
512#include <istream>
513DOCTEST_MAKE_STD_HEADERS_CLEAN_FROM_WARNINGS_ON_WALL_END
514#else // DOCTEST_CONFIG_USE_STD_HEADERS
515
516// Forward declaring 'X' in namespace std is not permitted by the C++ Standard.
517DOCTEST_MSVC_SUPPRESS_WARNING_WITH_PUSH(4643)
518
519namespace std { // NOLINT(cert-dcl58-cpp)
520typedef decltype(nullptr) nullptr_t; // NOLINT(modernize-use-using)
521typedef decltype(sizeof(void*)) size_t; // NOLINT(modernize-use-using)
522template <class charT>
523struct char_traits;
524template <>
525struct char_traits<char>;
526template <class charT, class traits>
527class basic_ostream; // NOLINT(fuchsia-virtual-inheritance)
528typedef basic_ostream<char, char_traits<char>> ostream; // NOLINT(modernize-use-using)
529template<class traits>
530// NOLINTNEXTLINE
531basic_ostream<char, traits>& operator<<(basic_ostream<char, traits>&, const char*);
532template <class charT, class traits>
533class basic_istream;
534typedef basic_istream<char, char_traits<char>> istream; // NOLINT(modernize-use-using)
535template <class... Types>
536class tuple;
537#if DOCTEST_MSVC >= DOCTEST_COMPILER(19, 20, 0)
538// see this issue on why this is needed: https://github.com/doctest/doctest/issues/183
539template <class Ty>
540class allocator;
541template <class Elem, class Traits, class Alloc>
542class basic_string;
543using string = basic_string<char, char_traits<char>, allocator<char>>;
544#endif // VS 2019
545} // namespace std
546
547DOCTEST_MSVC_SUPPRESS_WARNING_POP
548
549#endif // DOCTEST_CONFIG_USE_STD_HEADERS
550
551#ifdef DOCTEST_CONFIG_INCLUDE_TYPE_TRAITS
552#include <type_traits>
553#endif // DOCTEST_CONFIG_INCLUDE_TYPE_TRAITS
554
555namespace doctest {
556
557using std::size_t;
558
559DOCTEST_INTERFACE extern bool is_running_in_test;
560
561#ifndef DOCTEST_CONFIG_STRING_SIZE_TYPE
562#define DOCTEST_CONFIG_STRING_SIZE_TYPE unsigned
563#endif
564
565// A 24 byte string class (can be as small as 17 for x64 and 13 for x86) that can hold strings with length
566// of up to 23 chars on the stack before going on the heap - the last byte of the buffer is used for:
567// - "is small" bit - the highest bit - if "0" then it is small - otherwise its "1" (128)
568// - if small - capacity left before going on the heap - using the lowest 5 bits
569// - if small - 2 bits are left unused - the second and third highest ones
570// - if small - acts as a null terminator if strlen() is 23 (24 including the null terminator)
571// and the "is small" bit remains "0" ("as well as the capacity left") so its OK
572// Idea taken from this lecture about the string implementation of facebook/folly - fbstring
573// https://www.youtube.com/watch?v=kPR8h4-qZdk
574// TODO:
575// - optimizations - like not deleting memory unnecessarily in operator= and etc.
576// - resize/reserve/clear
577// - replace
578// - back/front
579// - iterator stuff
580// - find & friends
581// - push_back/pop_back
582// - assign/insert/erase
583// - relational operators as free functions - taking const char* as one of the params
584class DOCTEST_INTERFACE String
585{
586public:
587 using size_type = DOCTEST_CONFIG_STRING_SIZE_TYPE;
588
589private:
590 static DOCTEST_CONSTEXPR size_type len = 24;
591 static DOCTEST_CONSTEXPR size_type last = len - 1;
592
593 struct view // len should be more than sizeof(view) - because of the final byte for flags
594 {
595 char* ptr;
596 size_type size;
597 size_type capacity;
598 };
599
600 union
601 {
602 char buf[len]; // NOLINT(*-avoid-c-arrays)
603 view data;
604 };
605
606 char* allocate(size_type sz);
607
608 bool isOnStack() const noexcept { return (buf[last] & 128) == 0; }
609 void setOnHeap() noexcept;
610 void setLast(size_type in = last) noexcept;
611 void setSize(size_type sz) noexcept;
612
613 void copy(const String& other);
614
615public:
616 static DOCTEST_CONSTEXPR size_type npos = static_cast<size_type>(-1);
617
618 String() noexcept;
619 ~String();
620
621 // cppcheck-suppress noExplicitConstructor
622 String(const char* in);
623 String(const char* in, size_type in_size);
624
625 String(std::istream& in, size_type in_size);
626
627 String(const String& other);
628 String& operator=(const String& other);
629
630 String& operator+=(const String& other);
631
632 String(String&& other) noexcept;
633 String& operator=(String&& other) noexcept;
634
635 char operator[](size_type i) const;
636 char& operator[](size_type i);
637
638 // the only functions I'm willing to leave in the interface - available for inlining
639 const char* c_str() const { return const_cast<String*>(this)->c_str(); } // NOLINT
640 char* c_str() {
641 if (isOnStack()) {
642 return reinterpret_cast<char*>(buf);
643 }
644 return data.ptr;
645 }
646
647 size_type size() const;
648 size_type capacity() const;
649
650 String substr(size_type pos, size_type cnt = npos) &&;
651 String substr(size_type pos, size_type cnt = npos) const &;
652
653 size_type find(char ch, size_type pos = 0) const;
654 size_type rfind(char ch, size_type pos = npos) const;
655
656 int compare(const char* other, bool no_case = false) const;
657 int compare(const String& other, bool no_case = false) const;
658
659friend DOCTEST_INTERFACE std::ostream& operator<<(std::ostream& s, const String& in);
660};
661
662DOCTEST_INTERFACE String operator+(const String& lhs, const String& rhs);
663
664DOCTEST_INTERFACE bool operator==(const String& lhs, const String& rhs);
665DOCTEST_INTERFACE bool operator!=(const String& lhs, const String& rhs);
666DOCTEST_INTERFACE bool operator<(const String& lhs, const String& rhs);
667DOCTEST_INTERFACE bool operator>(const String& lhs, const String& rhs);
668DOCTEST_INTERFACE bool operator<=(const String& lhs, const String& rhs);
669DOCTEST_INTERFACE bool operator>=(const String& lhs, const String& rhs);
670
671class DOCTEST_INTERFACE Contains {
672public:
673 explicit Contains(const String& string);
674
675 bool checkWith(const String& other) const;
676
677 String string;
678};
679
680DOCTEST_INTERFACE String toString(const Contains& in);
681
682DOCTEST_INTERFACE bool operator==(const String& lhs, const Contains& rhs);
683DOCTEST_INTERFACE bool operator==(const Contains& lhs, const String& rhs);
684DOCTEST_INTERFACE bool operator!=(const String& lhs, const Contains& rhs);
685DOCTEST_INTERFACE bool operator!=(const Contains& lhs, const String& rhs);
686
687namespace Color {
688 enum Enum
689 {
690 None = 0,
691 White,
692 Red,
693 Green,
694 Blue,
695 Cyan,
696 Yellow,
697 Grey,
698
699 Bright = 0x10,
700
701 BrightRed = Bright | Red,
702 BrightGreen = Bright | Green,
703 LightGrey = Bright | Grey,
704 BrightWhite = Bright | White
705 };
706
707 DOCTEST_INTERFACE std::ostream& operator<<(std::ostream& s, Color::Enum code);
708} // namespace Color
709
710namespace assertType {
711 enum Enum
712 {
713 // macro traits
714
715 is_warn = 1,
716 is_check = 2 * is_warn,
717 is_require = 2 * is_check,
718
719 is_normal = 2 * is_require,
720 is_throws = 2 * is_normal,
721 is_throws_as = 2 * is_throws,
722 is_throws_with = 2 * is_throws_as,
723 is_nothrow = 2 * is_throws_with,
724
725 is_false = 2 * is_nothrow,
726 is_unary = 2 * is_false, // not checked anywhere - used just to distinguish the types
727
728 is_eq = 2 * is_unary,
729 is_ne = 2 * is_eq,
730
731 is_lt = 2 * is_ne,
732 is_gt = 2 * is_lt,
733
734 is_ge = 2 * is_gt,
735 is_le = 2 * is_ge,
736
737 // macro types
738
739 DT_WARN = is_normal | is_warn,
740 DT_CHECK = is_normal | is_check,
741 DT_REQUIRE = is_normal | is_require,
742
743 DT_WARN_FALSE = is_normal | is_false | is_warn,
744 DT_CHECK_FALSE = is_normal | is_false | is_check,
745 DT_REQUIRE_FALSE = is_normal | is_false | is_require,
746
747 DT_WARN_THROWS = is_throws | is_warn,
748 DT_CHECK_THROWS = is_throws | is_check,
749 DT_REQUIRE_THROWS = is_throws | is_require,
750
751 DT_WARN_THROWS_AS = is_throws_as | is_warn,
752 DT_CHECK_THROWS_AS = is_throws_as | is_check,
753 DT_REQUIRE_THROWS_AS = is_throws_as | is_require,
754
755 DT_WARN_THROWS_WITH = is_throws_with | is_warn,
756 DT_CHECK_THROWS_WITH = is_throws_with | is_check,
757 DT_REQUIRE_THROWS_WITH = is_throws_with | is_require,
758
759 DT_WARN_THROWS_WITH_AS = is_throws_with | is_throws_as | is_warn,
760 DT_CHECK_THROWS_WITH_AS = is_throws_with | is_throws_as | is_check,
761 DT_REQUIRE_THROWS_WITH_AS = is_throws_with | is_throws_as | is_require,
762
763 DT_WARN_NOTHROW = is_nothrow | is_warn,
764 DT_CHECK_NOTHROW = is_nothrow | is_check,
765 DT_REQUIRE_NOTHROW = is_nothrow | is_require,
766
767 DT_WARN_EQ = is_normal | is_eq | is_warn,
768 DT_CHECK_EQ = is_normal | is_eq | is_check,
769 DT_REQUIRE_EQ = is_normal | is_eq | is_require,
770
771 DT_WARN_NE = is_normal | is_ne | is_warn,
772 DT_CHECK_NE = is_normal | is_ne | is_check,
773 DT_REQUIRE_NE = is_normal | is_ne | is_require,
774
775 DT_WARN_GT = is_normal | is_gt | is_warn,
776 DT_CHECK_GT = is_normal | is_gt | is_check,
777 DT_REQUIRE_GT = is_normal | is_gt | is_require,
778
779 DT_WARN_LT = is_normal | is_lt | is_warn,
780 DT_CHECK_LT = is_normal | is_lt | is_check,
781 DT_REQUIRE_LT = is_normal | is_lt | is_require,
782
783 DT_WARN_GE = is_normal | is_ge | is_warn,
784 DT_CHECK_GE = is_normal | is_ge | is_check,
785 DT_REQUIRE_GE = is_normal | is_ge | is_require,
786
787 DT_WARN_LE = is_normal | is_le | is_warn,
788 DT_CHECK_LE = is_normal | is_le | is_check,
789 DT_REQUIRE_LE = is_normal | is_le | is_require,
790
791 DT_WARN_UNARY = is_normal | is_unary | is_warn,
792 DT_CHECK_UNARY = is_normal | is_unary | is_check,
793 DT_REQUIRE_UNARY = is_normal | is_unary | is_require,
794
795 DT_WARN_UNARY_FALSE = is_normal | is_false | is_unary | is_warn,
796 DT_CHECK_UNARY_FALSE = is_normal | is_false | is_unary | is_check,
797 DT_REQUIRE_UNARY_FALSE = is_normal | is_false | is_unary | is_require,
798 };
799} // namespace assertType
800
801DOCTEST_INTERFACE const char* assertString(assertType::Enum at);
802DOCTEST_INTERFACE const char* failureString(assertType::Enum at);
803DOCTEST_INTERFACE const char* skipPathFromFilename(const char* file);
804
805struct DOCTEST_INTERFACE TestCaseData
806{
807 String m_file; // the file in which the test was registered (using String - see #350)
808 unsigned m_line; // the line where the test was registered
809 const char* m_name; // name of the test case
810 const char* m_test_suite; // the test suite in which the test was added
811 const char* m_description;
812 bool m_skip;
813 bool m_no_breaks;
814 bool m_no_output;
815 bool m_may_fail;
816 bool m_should_fail;
817 int m_expected_failures;
818 double m_timeout;
819};
820
821struct DOCTEST_INTERFACE AssertData
822{
823 // common - for all asserts
824 const TestCaseData* m_test_case;
825 assertType::Enum m_at;
826 const char* m_file;
827 int m_line;
828 const char* m_expr;
829 bool m_failed;
830
831 // exception-related - for all asserts
832 bool m_threw;
833 String m_exception;
834
835 // for normal asserts
836 String m_decomp;
837
838 // for specific exception-related asserts
839 bool m_threw_as;
840 const char* m_exception_type;
841
842 class DOCTEST_INTERFACE StringContains {
843 private:
844 Contains content;
845 bool isContains;
846
847 public:
848 StringContains(const String& str) : content(str), isContains(false) { }
849 StringContains(Contains cntn) : content(static_cast<Contains&&>(cntn)), isContains(true) { }
850
851 bool check(const String& str) { return isContains ? (content == str) : (content.string == str); }
852
853 operator const String&() const { return content.string; }
854
855 const char* c_str() const { return content.string.c_str(); }
856 } m_exception_string;
857
858 AssertData(assertType::Enum at, const char* file, int line, const char* expr,
859 const char* exception_type, const StringContains& exception_string);
860};
861
862struct DOCTEST_INTERFACE MessageData
863{
864 String m_string;
865 const char* m_file;
866 int m_line;
867 assertType::Enum m_severity;
868};
869
870struct DOCTEST_INTERFACE SubcaseSignature
871{
872 String m_name;
873 const char* m_file;
874 int m_line;
875
876 bool operator==(const SubcaseSignature& other) const;
877 bool operator<(const SubcaseSignature& other) const;
878};
879
880struct DOCTEST_INTERFACE IContextScope
881{
882 DOCTEST_DECLARE_INTERFACE(IContextScope)
883 virtual void stringify(std::ostream*) const = 0;
884};
885
886namespace detail {
887 struct DOCTEST_INTERFACE TestCase;
888} // namespace detail
889
890struct ContextOptions
891{
892 std::ostream* cout = nullptr; // stdout stream
893 String binary_name; // the test binary name
894
895 const detail::TestCase* currentTest = nullptr;
896
897 // == parameters from the command line
898 String out; // output filename
899 String order_by; // how tests should be ordered
900 unsigned rand_seed; // the seed for rand ordering
901
902 unsigned first; // the first (matching) test to be executed
903 unsigned last; // the last (matching) test to be executed
904
905 int abort_after; // stop tests after this many failed assertions
906 int subcase_filter_levels; // apply the subcase filters for the first N levels
907
908 bool success; // include successful assertions in output
909 bool case_sensitive; // if filtering should be case sensitive
910 bool exit; // if the program should be exited after the tests are ran/whatever
911 bool duration; // print the time duration of each test case
912 bool minimal; // minimal console output (only test failures)
913 bool quiet; // no console output
914 bool no_throw; // to skip exceptions-related assertion macros
915 bool no_exitcode; // if the framework should return 0 as the exitcode
916 bool no_run; // to not run the tests at all (can be done with an "*" exclude)
917 bool no_intro; // to not print the intro of the framework
918 bool no_version; // to not print the version of the framework
919 bool no_colors; // if output to the console should be colorized
920 bool force_colors; // forces the use of colors even when a tty cannot be detected
921 bool no_breaks; // to not break into the debugger
922 bool no_skip; // don't skip test cases which are marked to be skipped
923 bool gnu_file_line; // if line numbers should be surrounded with :x: and not (x):
924 bool no_path_in_filenames; // if the path to files should be removed from the output
925 bool no_line_numbers; // if source code line numbers should be omitted from the output
926 bool no_debug_output; // no output in the debug console when a debugger is attached
927 bool no_skipped_summary; // don't print "skipped" in the summary !!! UNDOCUMENTED !!!
928 bool no_time_in_output; // omit any time/timestamps from output !!! UNDOCUMENTED !!!
929
930 bool help; // to print the help
931 bool version; // to print the version
932 bool count; // if only the count of matching tests is to be retrieved
933 bool list_test_cases; // to list all tests matching the filters
934 bool list_test_suites; // to list all suites matching the filters
935 bool list_reporters; // lists all registered reporters
936};
937
938namespace detail {
939 namespace types {
940#ifdef DOCTEST_CONFIG_INCLUDE_TYPE_TRAITS
941 using namespace std;
942#else
943 template <bool COND, typename T = void>
944 struct enable_if { };
945
946 template <typename T>
947 struct enable_if<true, T> { using type = T; };
948
949 struct true_type { static DOCTEST_CONSTEXPR bool value = true; };
950 struct false_type { static DOCTEST_CONSTEXPR bool value = false; };
951
952 template <typename T> struct remove_reference { using type = T; };
953 template <typename T> struct remove_reference<T&> { using type = T; };
954 template <typename T> struct remove_reference<T&&> { using type = T; };
955
956 template <typename T> struct is_rvalue_reference : false_type { };
957 template <typename T> struct is_rvalue_reference<T&&> : true_type { };
958
959 template<typename T> struct remove_const { using type = T; };
960 template <typename T> struct remove_const<const T> { using type = T; };
961
962 // Compiler intrinsics
963 template <typename T> struct is_enum { static DOCTEST_CONSTEXPR bool value = __is_enum(T); };
964 template <typename T> struct underlying_type { using type = __underlying_type(T); };
965
966 template <typename T> struct is_pointer : false_type { };
967 template <typename T> struct is_pointer<T*> : true_type { };
968
969 template <typename T> struct is_array : false_type { };
970 // NOLINTNEXTLINE(*-avoid-c-arrays)
971 template <typename T, size_t SIZE> struct is_array<T[SIZE]> : true_type { };
972#endif
973 }
974
975 // <utility>
976 template <typename T>
977 T&& declval();
978
979 template <class T>
980 DOCTEST_CONSTEXPR_FUNC T&& forward(typename types::remove_reference<T>::type& t) DOCTEST_NOEXCEPT {
981 return static_cast<T&&>(t);
982 }
983
984 template <class T>
985 DOCTEST_CONSTEXPR_FUNC T&& forward(typename types::remove_reference<T>::type&& t) DOCTEST_NOEXCEPT {
986 return static_cast<T&&>(t);
987 }
988
989 template <typename T>
990 struct deferred_false : types::false_type { };
991
992// MSVS 2015 :(
993#if !DOCTEST_CLANG && defined(_MSC_VER) && _MSC_VER <= 1900
994 template <typename T, typename = void>
995 struct has_global_insertion_operator : types::false_type { };
996
997 template <typename T>
998 struct has_global_insertion_operator<T, decltype(::operator<<(declval<std::ostream&>(), declval<const T&>()), void())> : types::true_type { };
999
1000 template <typename T, typename = void>
1001 struct has_insertion_operator { static DOCTEST_CONSTEXPR bool value = has_global_insertion_operator<T>::value; };
1002
1003 template <typename T, bool global>
1004 struct insert_hack;
1005
1006 template <typename T>
1007 struct insert_hack<T, true> {
1008 static void insert(std::ostream& os, const T& t) { ::operator<<(os, t); }
1009 };
1010
1011 template <typename T>
1012 struct insert_hack<T, false> {
1013 static void insert(std::ostream& os, const T& t) { operator<<(os, t); }
1014 };
1015
1016 template <typename T>
1017 using insert_hack_t = insert_hack<T, has_global_insertion_operator<T>::value>;
1018#else
1019 template <typename T, typename = void>
1020 struct has_insertion_operator : types::false_type { };
1021#endif
1022
1023 template <typename T>
1024 struct has_insertion_operator<T, decltype(operator<<(declval<std::ostream&>(), declval<const T&>()), void())> : types::true_type { };
1025
1026 template <typename T>
1027 struct should_stringify_as_underlying_type {
1028 static DOCTEST_CONSTEXPR bool value = detail::types::is_enum<T>::value && !doctest::detail::has_insertion_operator<T>::value;
1029 };
1030
1031 DOCTEST_INTERFACE std::ostream* tlssPush();
1032 DOCTEST_INTERFACE String tlssPop();
1033
1034 template <bool C>
1035 struct StringMakerBase {
1036 template <typename T>
1037 static String convert(const DOCTEST_REF_WRAP(T)) {
1038#ifdef DOCTEST_CONFIG_REQUIRE_STRINGIFICATION_FOR_ALL_USED_TYPES
1039 static_assert(deferred_false<T>::value, "No stringification detected for type T. See string conversion manual");
1040#endif
1041 return "{?}";
1042 }
1043 };
1044
1045 template <typename T>
1046 struct filldata;
1047
1048 template <typename T>
1049 void filloss(std::ostream* stream, const T& in) {
1050 filldata<T>::fill(stream, in);
1051 }
1052
1053 template <typename T, size_t N>
1054 void filloss(std::ostream* stream, const T (&in)[N]) { // NOLINT(*-avoid-c-arrays)
1055 // T[N], T(&)[N], T(&&)[N] have same behaviour.
1056 // Hence remove reference.
1057 filloss<typename types::remove_reference<decltype(in)>::type>(stream, in);
1058 }
1059
1060 template <typename T>
1061 String toStream(const T& in) {
1062 std::ostream* stream = tlssPush();
1063 filloss(stream, in);
1064 return tlssPop();
1065 }
1066
1067 template <>
1068 struct StringMakerBase<true> {
1069 template <typename T>
1070 static String convert(const DOCTEST_REF_WRAP(T) in) {
1071 return toStream(in);
1072 }
1073 };
1074} // namespace detail
1075
1076template <typename T>
1077struct StringMaker : public detail::StringMakerBase<
1078 detail::has_insertion_operator<T>::value || detail::types::is_pointer<T>::value || detail::types::is_array<T>::value>
1079{};
1080
1081#ifndef DOCTEST_STRINGIFY
1082#ifdef DOCTEST_CONFIG_DOUBLE_STRINGIFY
1083#define DOCTEST_STRINGIFY(...) toString(toString(__VA_ARGS__))
1084#else
1085#define DOCTEST_STRINGIFY(...) toString(__VA_ARGS__)
1086#endif
1087#endif
1088
1089template <typename T>
1090String toString() {
1091#if DOCTEST_CLANG == 0 && DOCTEST_GCC == 0 && DOCTEST_ICC == 0
1092 String ret = __FUNCSIG__; // class doctest::String __cdecl doctest::toString<TYPE>(void)
1093 String::size_type beginPos = ret.find('<');
1094 return ret.substr(beginPos + 1, ret.size() - beginPos - static_cast<String::size_type>(sizeof(">(void)")));
1095#else
1096 String ret = __PRETTY_FUNCTION__; // doctest::String toString() [with T = TYPE]
1097 String::size_type begin = ret.find('=') + 2;
1098 return ret.substr(begin, ret.size() - begin - 1);
1099#endif
1100}
1101
1102template <typename T, typename detail::types::enable_if<!detail::should_stringify_as_underlying_type<T>::value, bool>::type = true>
1103String toString(const DOCTEST_REF_WRAP(T) value) {
1104 return StringMaker<T>::convert(value);
1105}
1106
1107#ifdef DOCTEST_CONFIG_TREAT_CHAR_STAR_AS_STRING
1108DOCTEST_INTERFACE String toString(const char* in);
1109#endif // DOCTEST_CONFIG_TREAT_CHAR_STAR_AS_STRING
1110
1111#if DOCTEST_MSVC >= DOCTEST_COMPILER(19, 20, 0)
1112// see this issue on why this is needed: https://github.com/doctest/doctest/issues/183
1113DOCTEST_INTERFACE String toString(const std::string& in);
1114#endif // VS 2019
1115
1116DOCTEST_INTERFACE String toString(String in);
1117
1118DOCTEST_INTERFACE String toString(std::nullptr_t);
1119
1120DOCTEST_INTERFACE String toString(bool in);
1121
1122DOCTEST_INTERFACE String toString(float in);
1123DOCTEST_INTERFACE String toString(double in);
1124DOCTEST_INTERFACE String toString(double long in);
1125
1126DOCTEST_INTERFACE String toString(char in);
1127DOCTEST_INTERFACE String toString(char signed in);
1128DOCTEST_INTERFACE String toString(char unsigned in);
1129DOCTEST_INTERFACE String toString(short in);
1130DOCTEST_INTERFACE String toString(short unsigned in);
1131DOCTEST_INTERFACE String toString(signed in);
1132DOCTEST_INTERFACE String toString(unsigned in);
1133DOCTEST_INTERFACE String toString(long in);
1134DOCTEST_INTERFACE String toString(long unsigned in);
1135DOCTEST_INTERFACE String toString(long long in);
1136DOCTEST_INTERFACE String toString(long long unsigned in);
1137
1138template <typename T, typename detail::types::enable_if<detail::should_stringify_as_underlying_type<T>::value, bool>::type = true>
1139String toString(const DOCTEST_REF_WRAP(T) value) {
1140 using UT = typename detail::types::underlying_type<T>::type;
1141 return (DOCTEST_STRINGIFY(static_cast<UT>(value)));
1142}
1143
1144namespace detail {
1145 template <typename T>
1147 {
1148 static void fill(std::ostream* stream, const T& in) {
1149#if defined(_MSC_VER) && _MSC_VER <= 1900
1150 insert_hack_t<T>::insert(*stream, in);
1151#else
1152 operator<<(*stream, in);
1153#endif
1154 }
1155 };
1156
1157DOCTEST_MSVC_SUPPRESS_WARNING_WITH_PUSH(4866)
1158// NOLINTBEGIN(*-avoid-c-arrays)
1159 template <typename T, size_t N>
1160 struct filldata<T[N]> {
1161 static void fill(std::ostream* stream, const T(&in)[N]) {
1162 *stream << "[";
1163 for (size_t i = 0; i < N; i++) {
1164 if (i != 0) { *stream << ", "; }
1165 *stream << (DOCTEST_STRINGIFY(in[i]));
1166 }
1167 *stream << "]";
1168 }
1169 };
1170// NOLINTEND(*-avoid-c-arrays)
1171DOCTEST_MSVC_SUPPRESS_WARNING_POP
1172
1173 // Specialized since we don't want the terminating null byte!
1174// NOLINTBEGIN(*-avoid-c-arrays)
1175 template <size_t N>
1176 struct filldata<const char[N]> {
1177 static void fill(std::ostream* stream, const char (&in)[N]) {
1178 *stream << String(in, in[N - 1] ? N : N - 1);
1179 } // NOLINT(clang-analyzer-cplusplus.NewDeleteLeaks)
1180 };
1181// NOLINTEND(*-avoid-c-arrays)
1182
1183 template <>
1184 struct filldata<const void*> {
1185 static void fill(std::ostream* stream, const void* in);
1186 };
1187
1188 template <typename T>
1189 struct filldata<T*> {
1190DOCTEST_MSVC_SUPPRESS_WARNING_WITH_PUSH(4180)
1191 static void fill(std::ostream* stream, const T* in) {
1192DOCTEST_MSVC_SUPPRESS_WARNING_POP
1193DOCTEST_CLANG_SUPPRESS_WARNING_WITH_PUSH("-Wmicrosoft-cast")
1194 filldata<const void*>::fill(stream,
1195#if DOCTEST_GCC == 0 || DOCTEST_GCC >= DOCTEST_COMPILER(4, 9, 0)
1196 reinterpret_cast<const void*>(in)
1197#else
1198 *reinterpret_cast<const void* const*>(&in)
1199#endif
1200 );
1201DOCTEST_CLANG_SUPPRESS_WARNING_POP
1202 }
1203 };
1204}
1205
1206struct DOCTEST_INTERFACE Approx
1207{
1208 Approx(double value);
1209
1210 Approx operator()(double value) const;
1211
1212#ifdef DOCTEST_CONFIG_INCLUDE_TYPE_TRAITS
1213 template <typename T>
1214 explicit Approx(const T& value,
1215 typename detail::types::enable_if<std::is_constructible<double, T>::value>::type* =
1216 static_cast<T*>(nullptr)) {
1217 *this = static_cast<double>(value);
1218 }
1219#endif // DOCTEST_CONFIG_INCLUDE_TYPE_TRAITS
1220
1221 Approx& epsilon(double newEpsilon);
1222
1223#ifdef DOCTEST_CONFIG_INCLUDE_TYPE_TRAITS
1224 template <typename T>
1225 typename std::enable_if<std::is_constructible<double, T>::value, Approx&>::type epsilon(
1226 const T& newEpsilon) {
1227 m_epsilon = static_cast<double>(newEpsilon);
1228 return *this;
1229 }
1230#endif // DOCTEST_CONFIG_INCLUDE_TYPE_TRAITS
1231
1232 Approx& scale(double newScale);
1233
1234#ifdef DOCTEST_CONFIG_INCLUDE_TYPE_TRAITS
1235 template <typename T>
1236 typename std::enable_if<std::is_constructible<double, T>::value, Approx&>::type scale(
1237 const T& newScale) {
1238 m_scale = static_cast<double>(newScale);
1239 return *this;
1240 }
1241#endif // DOCTEST_CONFIG_INCLUDE_TYPE_TRAITS
1242
1243 // clang-format off
1244 DOCTEST_INTERFACE friend bool operator==(double lhs, const Approx & rhs);
1245 DOCTEST_INTERFACE friend bool operator==(const Approx & lhs, double rhs);
1246 DOCTEST_INTERFACE friend bool operator!=(double lhs, const Approx & rhs);
1247 DOCTEST_INTERFACE friend bool operator!=(const Approx & lhs, double rhs);
1248 DOCTEST_INTERFACE friend bool operator<=(double lhs, const Approx & rhs);
1249 DOCTEST_INTERFACE friend bool operator<=(const Approx & lhs, double rhs);
1250 DOCTEST_INTERFACE friend bool operator>=(double lhs, const Approx & rhs);
1251 DOCTEST_INTERFACE friend bool operator>=(const Approx & lhs, double rhs);
1252 DOCTEST_INTERFACE friend bool operator< (double lhs, const Approx & rhs);
1253 DOCTEST_INTERFACE friend bool operator< (const Approx & lhs, double rhs);
1254 DOCTEST_INTERFACE friend bool operator> (double lhs, const Approx & rhs);
1255 DOCTEST_INTERFACE friend bool operator> (const Approx & lhs, double rhs);
1256
1257#ifdef DOCTEST_CONFIG_INCLUDE_TYPE_TRAITS
1258#define DOCTEST_APPROX_PREFIX \
1259 template <typename T> friend typename std::enable_if<std::is_constructible<double, T>::value, bool>::type
1260
1261 DOCTEST_APPROX_PREFIX operator==(const T& lhs, const Approx& rhs) { return operator==(static_cast<double>(lhs), rhs); }
1262 DOCTEST_APPROX_PREFIX operator==(const Approx& lhs, const T& rhs) { return operator==(rhs, lhs); }
1263 DOCTEST_APPROX_PREFIX operator!=(const T& lhs, const Approx& rhs) { return !operator==(lhs, rhs); }
1264 DOCTEST_APPROX_PREFIX operator!=(const Approx& lhs, const T& rhs) { return !operator==(rhs, lhs); }
1265 DOCTEST_APPROX_PREFIX operator<=(const T& lhs, const Approx& rhs) { return static_cast<double>(lhs) < rhs.m_value || lhs == rhs; }
1266 DOCTEST_APPROX_PREFIX operator<=(const Approx& lhs, const T& rhs) { return lhs.m_value < static_cast<double>(rhs) || lhs == rhs; }
1267 DOCTEST_APPROX_PREFIX operator>=(const T& lhs, const Approx& rhs) { return static_cast<double>(lhs) > rhs.m_value || lhs == rhs; }
1268 DOCTEST_APPROX_PREFIX operator>=(const Approx& lhs, const T& rhs) { return lhs.m_value > static_cast<double>(rhs) || lhs == rhs; }
1269 DOCTEST_APPROX_PREFIX operator< (const T& lhs, const Approx& rhs) { return static_cast<double>(lhs) < rhs.m_value && lhs != rhs; }
1270 DOCTEST_APPROX_PREFIX operator< (const Approx& lhs, const T& rhs) { return lhs.m_value < static_cast<double>(rhs) && lhs != rhs; }
1271 DOCTEST_APPROX_PREFIX operator> (const T& lhs, const Approx& rhs) { return static_cast<double>(lhs) > rhs.m_value && lhs != rhs; }
1272 DOCTEST_APPROX_PREFIX operator> (const Approx& lhs, const T& rhs) { return lhs.m_value > static_cast<double>(rhs) && lhs != rhs; }
1273#undef DOCTEST_APPROX_PREFIX
1274#endif // DOCTEST_CONFIG_INCLUDE_TYPE_TRAITS
1275
1276 // clang-format on
1277
1278 double m_epsilon;
1279 double m_scale;
1280 double m_value;
1281};
1282
1283DOCTEST_INTERFACE String toString(const Approx& in);
1284
1285DOCTEST_INTERFACE const ContextOptions* getContextOptions();
1286
1287template <typename F>
1288struct DOCTEST_INTERFACE_DECL IsNaN
1289{
1290 F value; bool flipped;
1291 IsNaN(F f, bool flip = false) : value(f), flipped(flip) { }
1292 IsNaN<F> operator!() const { return { value, !flipped }; }
1293 operator bool() const;
1294};
1295#ifndef __MINGW32__
1296extern template struct DOCTEST_INTERFACE_DECL IsNaN<float>;
1297extern template struct DOCTEST_INTERFACE_DECL IsNaN<double>;
1298extern template struct DOCTEST_INTERFACE_DECL IsNaN<long double>;
1299#endif
1300DOCTEST_INTERFACE String toString(IsNaN<float> in);
1301DOCTEST_INTERFACE String toString(IsNaN<double> in);
1302DOCTEST_INTERFACE String toString(IsNaN<double long> in);
1303
1304#ifndef DOCTEST_CONFIG_DISABLE
1305
1306namespace detail {
1307 // clang-format off
1308#ifdef DOCTEST_CONFIG_TREAT_CHAR_STAR_AS_STRING
1309 template<class T> struct decay_array { using type = T; };
1310 template<class T, unsigned N> struct decay_array<T[N]> { using type = T*; };
1311 template<class T> struct decay_array<T[]> { using type = T*; };
1312
1313 template<class T> struct not_char_pointer { static DOCTEST_CONSTEXPR int value = 1; };
1314 template<> struct not_char_pointer<char*> { static DOCTEST_CONSTEXPR int value = 0; };
1315 template<> struct not_char_pointer<const char*> { static DOCTEST_CONSTEXPR int value = 0; };
1316
1317 template<class T> struct can_use_op : public not_char_pointer<typename decay_array<T>::type> {};
1318#endif // DOCTEST_CONFIG_TREAT_CHAR_STAR_AS_STRING
1319 // clang-format on
1320
1321 struct DOCTEST_INTERFACE TestFailureException
1322 {
1323 };
1324
1325 DOCTEST_INTERFACE bool checkIfShouldThrow(assertType::Enum at);
1326
1327#ifndef DOCTEST_CONFIG_NO_EXCEPTIONS
1328 DOCTEST_NORETURN
1329#endif // DOCTEST_CONFIG_NO_EXCEPTIONS
1330 DOCTEST_INTERFACE void throwException();
1331
1332 struct DOCTEST_INTERFACE Subcase
1333 {
1334 SubcaseSignature m_signature;
1335 bool m_entered = false;
1336
1337 Subcase(const String& name, const char* file, int line);
1338 Subcase(const Subcase&) = delete;
1339 Subcase(Subcase&&) = delete;
1340 Subcase& operator=(const Subcase&) = delete;
1341 Subcase& operator=(Subcase&&) = delete;
1342 ~Subcase();
1343
1344 operator bool() const;
1345
1346 private:
1347 bool checkFilters();
1348 };
1349
1350 template <typename L, typename R>
1351 String stringifyBinaryExpr(const DOCTEST_REF_WRAP(L) lhs, const char* op,
1352 const DOCTEST_REF_WRAP(R) rhs) {
1353 return (DOCTEST_STRINGIFY(lhs)) + op + (DOCTEST_STRINGIFY(rhs));
1354 }
1355
1356#if DOCTEST_CLANG && DOCTEST_CLANG < DOCTEST_COMPILER(3, 6, 0)
1357DOCTEST_CLANG_SUPPRESS_WARNING_WITH_PUSH("-Wunused-comparison")
1358#endif
1359
1360// This will check if there is any way it could find a operator like member or friend and uses it.
1361// If not it doesn't find the operator or if the operator at global scope is defined after
1362// this template, the template won't be instantiated due to SFINAE. Once the template is not
1363// instantiated it can look for global operator using normal conversions.
1364#ifdef __NVCC__
1365#define SFINAE_OP(ret,op) ret
1366#else
1367#define SFINAE_OP(ret,op) decltype((void)(doctest::detail::declval<L>() op doctest::detail::declval<R>()),ret{})
1368#endif
1369
1370#define DOCTEST_DO_BINARY_EXPRESSION_COMPARISON(op, op_str, op_macro) \
1371 template <typename R> \
1372 DOCTEST_NOINLINE SFINAE_OP(Result,op) operator op(R&& rhs) { \
1373 bool res = op_macro(doctest::detail::forward<const L>(lhs), doctest::detail::forward<R>(rhs)); \
1374 if(m_at & assertType::is_false) \
1375 res = !res; \
1376 if(!res || doctest::getContextOptions()->success) \
1377 return Result(res, stringifyBinaryExpr(lhs, op_str, rhs)); \
1378 return Result(res); \
1379 }
1380
1381 // more checks could be added - like in Catch:
1382 // https://github.com/catchorg/Catch2/pull/1480/files
1383 // https://github.com/catchorg/Catch2/pull/1481/files
1384#define DOCTEST_FORBIT_EXPRESSION(rt, op) \
1385 template <typename R> \
1386 rt& operator op(const R&) { \
1387 static_assert(deferred_false<R>::value, \
1388 "Expression Too Complex Please Rewrite As Binary Comparison!"); \
1389 return *this; \
1390 }
1391
1392 struct DOCTEST_INTERFACE Result // NOLINT(*-member-init)
1393 {
1394 bool m_passed;
1395 String m_decomp;
1396
1397 Result() = default; // TODO: Why do we need this? (To remove NOLINT)
1398 Result(bool passed, const String& decomposition = String());
1399
1400 // forbidding some expressions based on this table: https://en.cppreference.com/w/cpp/language/operator_precedence
1401 DOCTEST_FORBIT_EXPRESSION(Result, &)
1402 DOCTEST_FORBIT_EXPRESSION(Result, ^)
1403 DOCTEST_FORBIT_EXPRESSION(Result, |)
1404 DOCTEST_FORBIT_EXPRESSION(Result, &&)
1405 DOCTEST_FORBIT_EXPRESSION(Result, ||)
1406 DOCTEST_FORBIT_EXPRESSION(Result, ==)
1407 DOCTEST_FORBIT_EXPRESSION(Result, !=)
1408 DOCTEST_FORBIT_EXPRESSION(Result, <)
1409 DOCTEST_FORBIT_EXPRESSION(Result, >)
1410 DOCTEST_FORBIT_EXPRESSION(Result, <=)
1411 DOCTEST_FORBIT_EXPRESSION(Result, >=)
1412 DOCTEST_FORBIT_EXPRESSION(Result, =)
1413 DOCTEST_FORBIT_EXPRESSION(Result, +=)
1414 DOCTEST_FORBIT_EXPRESSION(Result, -=)
1415 DOCTEST_FORBIT_EXPRESSION(Result, *=)
1416 DOCTEST_FORBIT_EXPRESSION(Result, /=)
1417 DOCTEST_FORBIT_EXPRESSION(Result, %=)
1418 DOCTEST_FORBIT_EXPRESSION(Result, <<=)
1419 DOCTEST_FORBIT_EXPRESSION(Result, >>=)
1420 DOCTEST_FORBIT_EXPRESSION(Result, &=)
1421 DOCTEST_FORBIT_EXPRESSION(Result, ^=)
1422 DOCTEST_FORBIT_EXPRESSION(Result, |=)
1423 };
1424
1425#ifndef DOCTEST_CONFIG_NO_COMPARISON_WARNING_SUPPRESSION
1426
1427 DOCTEST_CLANG_SUPPRESS_WARNING_PUSH
1428 DOCTEST_CLANG_SUPPRESS_WARNING("-Wsign-conversion")
1429 DOCTEST_CLANG_SUPPRESS_WARNING("-Wsign-compare")
1430 //DOCTEST_CLANG_SUPPRESS_WARNING("-Wdouble-promotion")
1431 //DOCTEST_CLANG_SUPPRESS_WARNING("-Wconversion")
1432 //DOCTEST_CLANG_SUPPRESS_WARNING("-Wfloat-equal")
1433
1434 DOCTEST_GCC_SUPPRESS_WARNING_PUSH
1435 DOCTEST_GCC_SUPPRESS_WARNING("-Wsign-conversion")
1436 DOCTEST_GCC_SUPPRESS_WARNING("-Wsign-compare")
1437 //DOCTEST_GCC_SUPPRESS_WARNING("-Wdouble-promotion")
1438 //DOCTEST_GCC_SUPPRESS_WARNING("-Wconversion")
1439 //DOCTEST_GCC_SUPPRESS_WARNING("-Wfloat-equal")
1440
1441 DOCTEST_MSVC_SUPPRESS_WARNING_PUSH
1442 // https://stackoverflow.com/questions/39479163 what's the difference between 4018 and 4389
1443 DOCTEST_MSVC_SUPPRESS_WARNING(4388) // signed/unsigned mismatch
1444 DOCTEST_MSVC_SUPPRESS_WARNING(4389) // 'operator' : signed/unsigned mismatch
1445 DOCTEST_MSVC_SUPPRESS_WARNING(4018) // 'expression' : signed/unsigned mismatch
1446 //DOCTEST_MSVC_SUPPRESS_WARNING(4805) // 'operation' : unsafe mix of type 'type' and type 'type' in operation
1447
1448#endif // DOCTEST_CONFIG_NO_COMPARISON_WARNING_SUPPRESSION
1449
1450 // clang-format off
1451#ifndef DOCTEST_CONFIG_TREAT_CHAR_STAR_AS_STRING
1452#define DOCTEST_COMPARISON_RETURN_TYPE bool
1453#else // DOCTEST_CONFIG_TREAT_CHAR_STAR_AS_STRING
1454#define DOCTEST_COMPARISON_RETURN_TYPE typename types::enable_if<can_use_op<L>::value || can_use_op<R>::value, bool>::type
1455 inline bool eq(const char* lhs, const char* rhs) { return String(lhs) == String(rhs); }
1456 inline bool ne(const char* lhs, const char* rhs) { return String(lhs) != String(rhs); }
1457 inline bool lt(const char* lhs, const char* rhs) { return String(lhs) < String(rhs); }
1458 inline bool gt(const char* lhs, const char* rhs) { return String(lhs) > String(rhs); }
1459 inline bool le(const char* lhs, const char* rhs) { return String(lhs) <= String(rhs); }
1460 inline bool ge(const char* lhs, const char* rhs) { return String(lhs) >= String(rhs); }
1461#endif // DOCTEST_CONFIG_TREAT_CHAR_STAR_AS_STRING
1462 // clang-format on
1463
1464#define DOCTEST_RELATIONAL_OP(name, op) \
1465 template <typename L, typename R> \
1466 DOCTEST_COMPARISON_RETURN_TYPE name(const DOCTEST_REF_WRAP(L) lhs, \
1467 const DOCTEST_REF_WRAP(R) rhs) { \
1468 return lhs op rhs; \
1469 }
1470
1471 DOCTEST_RELATIONAL_OP(eq, ==)
1472 DOCTEST_RELATIONAL_OP(ne, !=)
1473 DOCTEST_RELATIONAL_OP(lt, <)
1474 DOCTEST_RELATIONAL_OP(gt, >)
1475 DOCTEST_RELATIONAL_OP(le, <=)
1476 DOCTEST_RELATIONAL_OP(ge, >=)
1477
1478#ifndef DOCTEST_CONFIG_TREAT_CHAR_STAR_AS_STRING
1479#define DOCTEST_CMP_EQ(l, r) l == r
1480#define DOCTEST_CMP_NE(l, r) l != r
1481#define DOCTEST_CMP_GT(l, r) l > r
1482#define DOCTEST_CMP_LT(l, r) l < r
1483#define DOCTEST_CMP_GE(l, r) l >= r
1484#define DOCTEST_CMP_LE(l, r) l <= r
1485#else // DOCTEST_CONFIG_TREAT_CHAR_STAR_AS_STRING
1486#define DOCTEST_CMP_EQ(l, r) eq(l, r)
1487#define DOCTEST_CMP_NE(l, r) ne(l, r)
1488#define DOCTEST_CMP_GT(l, r) gt(l, r)
1489#define DOCTEST_CMP_LT(l, r) lt(l, r)
1490#define DOCTEST_CMP_GE(l, r) ge(l, r)
1491#define DOCTEST_CMP_LE(l, r) le(l, r)
1492#endif // DOCTEST_CONFIG_TREAT_CHAR_STAR_AS_STRING
1493
1494 template <typename L>
1495 // cppcheck-suppress copyCtorAndEqOperator
1496 struct Expression_lhs
1497 {
1498 L lhs;
1499 assertType::Enum m_at;
1500
1501 explicit Expression_lhs(L&& in, assertType::Enum at)
1502 : lhs(static_cast<L&&>(in))
1503 , m_at(at) {}
1504
1505 DOCTEST_NOINLINE operator Result() {
1506// this is needed only for MSVC 2015
1507DOCTEST_MSVC_SUPPRESS_WARNING_WITH_PUSH(4800) // 'int': forcing value to bool
1508 bool res = static_cast<bool>(lhs);
1509DOCTEST_MSVC_SUPPRESS_WARNING_POP
1510 if(m_at & assertType::is_false) {
1511 res = !res;
1512 }
1513
1514 if(!res || getContextOptions()->success) {
1515 return { res, (DOCTEST_STRINGIFY(lhs)) };
1516 }
1517 return { res };
1518 }
1519
1520 /* This is required for user-defined conversions from Expression_lhs to L */
1521 operator L() const { return lhs; }
1522
1523 // clang-format off
1524 DOCTEST_DO_BINARY_EXPRESSION_COMPARISON(==, " == ", DOCTEST_CMP_EQ)
1525 DOCTEST_DO_BINARY_EXPRESSION_COMPARISON(!=, " != ", DOCTEST_CMP_NE)
1526 DOCTEST_DO_BINARY_EXPRESSION_COMPARISON(>, " > ", DOCTEST_CMP_GT)
1527 DOCTEST_DO_BINARY_EXPRESSION_COMPARISON(<, " < ", DOCTEST_CMP_LT)
1528 DOCTEST_DO_BINARY_EXPRESSION_COMPARISON(>=, " >= ", DOCTEST_CMP_GE)
1529 DOCTEST_DO_BINARY_EXPRESSION_COMPARISON(<=, " <= ", DOCTEST_CMP_LE)
1530 // clang-format on
1531
1532 // forbidding some expressions based on this table: https://en.cppreference.com/w/cpp/language/operator_precedence
1533 DOCTEST_FORBIT_EXPRESSION(Expression_lhs, &)
1534 DOCTEST_FORBIT_EXPRESSION(Expression_lhs, ^)
1535 DOCTEST_FORBIT_EXPRESSION(Expression_lhs, |)
1536 DOCTEST_FORBIT_EXPRESSION(Expression_lhs, &&)
1537 DOCTEST_FORBIT_EXPRESSION(Expression_lhs, ||)
1538 DOCTEST_FORBIT_EXPRESSION(Expression_lhs, =)
1539 DOCTEST_FORBIT_EXPRESSION(Expression_lhs, +=)
1540 DOCTEST_FORBIT_EXPRESSION(Expression_lhs, -=)
1541 DOCTEST_FORBIT_EXPRESSION(Expression_lhs, *=)
1542 DOCTEST_FORBIT_EXPRESSION(Expression_lhs, /=)
1543 DOCTEST_FORBIT_EXPRESSION(Expression_lhs, %=)
1544 DOCTEST_FORBIT_EXPRESSION(Expression_lhs, <<=)
1545 DOCTEST_FORBIT_EXPRESSION(Expression_lhs, >>=)
1546 DOCTEST_FORBIT_EXPRESSION(Expression_lhs, &=)
1547 DOCTEST_FORBIT_EXPRESSION(Expression_lhs, ^=)
1548 DOCTEST_FORBIT_EXPRESSION(Expression_lhs, |=)
1549 // these 2 are unfortunate because they should be allowed - they have higher precedence over the comparisons, but the
1550 // ExpressionDecomposer class uses the left shift operator to capture the left operand of the binary expression...
1551 DOCTEST_FORBIT_EXPRESSION(Expression_lhs, <<)
1552 DOCTEST_FORBIT_EXPRESSION(Expression_lhs, >>)
1553 };
1554
1555#ifndef DOCTEST_CONFIG_NO_COMPARISON_WARNING_SUPPRESSION
1556
1557 DOCTEST_CLANG_SUPPRESS_WARNING_POP
1558 DOCTEST_MSVC_SUPPRESS_WARNING_POP
1559 DOCTEST_GCC_SUPPRESS_WARNING_POP
1560
1561#endif // DOCTEST_CONFIG_NO_COMPARISON_WARNING_SUPPRESSION
1562
1563#if DOCTEST_CLANG && DOCTEST_CLANG < DOCTEST_COMPILER(3, 6, 0)
1564DOCTEST_CLANG_SUPPRESS_WARNING_POP
1565#endif
1566
1567 struct DOCTEST_INTERFACE ExpressionDecomposer
1568 {
1569 assertType::Enum m_at;
1570
1571 ExpressionDecomposer(assertType::Enum at);
1572
1573 // The right operator for capturing expressions is "<=" instead of "<<" (based on the operator precedence table)
1574 // but then there will be warnings from GCC about "-Wparentheses" and since "_Pragma()" is problematic this will stay for now...
1575 // https://github.com/catchorg/Catch2/issues/870
1576 // https://github.com/catchorg/Catch2/issues/565
1577 template <typename L>
1578 Expression_lhs<L> operator<<(L&& operand) {
1579 return Expression_lhs<L>(static_cast<L&&>(operand), m_at);
1580 }
1581
1582 template <typename L,typename types::enable_if<!doctest::detail::types::is_rvalue_reference<L>::value,void >::type* = nullptr>
1583 Expression_lhs<const L&> operator<<(const L &operand) {
1584 return Expression_lhs<const L&>(operand, m_at);
1585 }
1586 };
1587
1588 struct DOCTEST_INTERFACE TestSuite
1589 {
1590 const char* m_test_suite = nullptr;
1591 const char* m_description = nullptr;
1592 bool m_skip = false;
1593 bool m_no_breaks = false;
1594 bool m_no_output = false;
1595 bool m_may_fail = false;
1596 bool m_should_fail = false;
1597 int m_expected_failures = 0;
1598 double m_timeout = 0;
1599
1600 TestSuite& operator*(const char* in);
1601
1602 template <typename T>
1603 TestSuite& operator*(const T& in) {
1604 in.fill(*this);
1605 return *this;
1606 }
1607 };
1608
1609 using funcType = void (*)();
1610
1611 struct DOCTEST_INTERFACE TestCase : public TestCaseData
1612 {
1613 funcType m_test; // a function pointer to the test case
1614
1615 String m_type; // for templated test cases - gets appended to the real name
1616 int m_template_id; // an ID used to distinguish between the different versions of a templated test case
1617 String m_full_name; // contains the name (only for templated test cases!) + the template type
1618
1619 TestCase(funcType test, const char* file, unsigned line, const TestSuite& test_suite,
1620 const String& type = String(), int template_id = -1);
1621
1622 TestCase(const TestCase& other);
1623 TestCase(TestCase&&) = delete;
1624
1625 DOCTEST_MSVC_SUPPRESS_WARNING_WITH_PUSH(26434) // hides a non-virtual function
1626 TestCase& operator=(const TestCase& other);
1627 DOCTEST_MSVC_SUPPRESS_WARNING_POP
1628
1629 TestCase& operator=(TestCase&&) = delete;
1630
1631 TestCase& operator*(const char* in);
1632
1633 template <typename T>
1634 TestCase& operator*(const T& in) {
1635 in.fill(*this);
1636 return *this;
1637 }
1638
1639 bool operator<(const TestCase& other) const;
1640
1641 ~TestCase() = default;
1642 };
1643
1644 // forward declarations of functions used by the macros
1645 DOCTEST_INTERFACE int regTest(const TestCase& tc);
1646 DOCTEST_INTERFACE int setTestSuite(const TestSuite& ts);
1647 DOCTEST_INTERFACE bool isDebuggerActive();
1648
1649 template<typename T>
1650 int instantiationHelper(const T&) { return 0; }
1651
1652 namespace binaryAssertComparison {
1653 enum Enum
1654 {
1655 eq = 0,
1656 ne,
1657 gt,
1658 lt,
1659 ge,
1660 le
1661 };
1662 } // namespace binaryAssertComparison
1663
1664 // clang-format off
1665 template <int, class L, class R> struct RelationalComparator { bool operator()(const DOCTEST_REF_WRAP(L), const DOCTEST_REF_WRAP(R) ) const { return false; } };
1666
1667#define DOCTEST_BINARY_RELATIONAL_OP(n, op) \
1668 template <class L, class R> struct RelationalComparator<n, L, R> { bool operator()(const DOCTEST_REF_WRAP(L) lhs, const DOCTEST_REF_WRAP(R) rhs) const { return op(lhs, rhs); } };
1669 // clang-format on
1670
1671 DOCTEST_BINARY_RELATIONAL_OP(0, doctest::detail::eq)
1672 DOCTEST_BINARY_RELATIONAL_OP(1, doctest::detail::ne)
1673 DOCTEST_BINARY_RELATIONAL_OP(2, doctest::detail::gt)
1674 DOCTEST_BINARY_RELATIONAL_OP(3, doctest::detail::lt)
1675 DOCTEST_BINARY_RELATIONAL_OP(4, doctest::detail::ge)
1676 DOCTEST_BINARY_RELATIONAL_OP(5, doctest::detail::le)
1677
1678 struct DOCTEST_INTERFACE ResultBuilder : public AssertData
1679 {
1680 ResultBuilder(assertType::Enum at, const char* file, int line, const char* expr,
1681 const char* exception_type = "", const String& exception_string = "");
1682
1683 ResultBuilder(assertType::Enum at, const char* file, int line, const char* expr,
1684 const char* exception_type, const Contains& exception_string);
1685
1686 void setResult(const Result& res);
1687
1688 template <int comparison, typename L, typename R>
1689 DOCTEST_NOINLINE bool binary_assert(const DOCTEST_REF_WRAP(L) lhs,
1690 const DOCTEST_REF_WRAP(R) rhs) {
1691 m_failed = !RelationalComparator<comparison, L, R>()(lhs, rhs);
1692 if (m_failed || getContextOptions()->success) {
1693 m_decomp = stringifyBinaryExpr(lhs, ", ", rhs);
1694 }
1695 return !m_failed;
1696 }
1697
1698 template <typename L>
1699 DOCTEST_NOINLINE bool unary_assert(const DOCTEST_REF_WRAP(L) val) {
1700 m_failed = !val;
1701
1702 if (m_at & assertType::is_false) {
1703 m_failed = !m_failed;
1704 }
1705
1706 if (m_failed || getContextOptions()->success) {
1707 m_decomp = (DOCTEST_STRINGIFY(val));
1708 }
1709
1710 return !m_failed;
1711 }
1712
1713 void translateException();
1714
1715 bool log();
1716 void react() const;
1717 };
1718
1719 namespace assertAction {
1720 enum Enum
1721 {
1722 nothing = 0,
1723 dbgbreak = 1,
1724 shouldthrow = 2
1725 };
1726 } // namespace assertAction
1727
1728 DOCTEST_INTERFACE void failed_out_of_a_testing_context(const AssertData& ad);
1729
1730 DOCTEST_INTERFACE bool decomp_assert(assertType::Enum at, const char* file, int line,
1731 const char* expr, const Result& result);
1732
1733#define DOCTEST_ASSERT_OUT_OF_TESTS(decomp) \
1734 do { \
1735 if(!is_running_in_test) { \
1736 if(failed) { \
1737 ResultBuilder rb(at, file, line, expr); \
1738 rb.m_failed = failed; \
1739 rb.m_decomp = decomp; \
1740 failed_out_of_a_testing_context(rb); \
1741 if(isDebuggerActive() && !getContextOptions()->no_breaks) \
1742 DOCTEST_BREAK_INTO_DEBUGGER(); \
1743 if(checkIfShouldThrow(at)) \
1744 throwException(); \
1745 } \
1746 return !failed; \
1747 } \
1748 } while(false)
1749
1750#define DOCTEST_ASSERT_IN_TESTS(decomp) \
1751 ResultBuilder rb(at, file, line, expr); \
1752 rb.m_failed = failed; \
1753 if(rb.m_failed || getContextOptions()->success) \
1754 rb.m_decomp = decomp; \
1755 if(rb.log()) \
1756 DOCTEST_BREAK_INTO_DEBUGGER(); \
1757 if(rb.m_failed && checkIfShouldThrow(at)) \
1758 throwException()
1759
1760 template <int comparison, typename L, typename R>
1761 DOCTEST_NOINLINE bool binary_assert(assertType::Enum at, const char* file, int line,
1762 const char* expr, const DOCTEST_REF_WRAP(L) lhs,
1763 const DOCTEST_REF_WRAP(R) rhs) {
1764 bool failed = !RelationalComparator<comparison, L, R>()(lhs, rhs);
1765
1766 // ###################################################################################
1767 // IF THE DEBUGGER BREAKS HERE - GO 1 LEVEL UP IN THE CALLSTACK FOR THE FAILING ASSERT
1768 // THIS IS THE EFFECT OF HAVING 'DOCTEST_CONFIG_SUPER_FAST_ASSERTS' DEFINED
1769 // ###################################################################################
1770 DOCTEST_ASSERT_OUT_OF_TESTS(stringifyBinaryExpr(lhs, ", ", rhs));
1771 DOCTEST_ASSERT_IN_TESTS(stringifyBinaryExpr(lhs, ", ", rhs));
1772 return !failed;
1773 }
1774
1775 template <typename L>
1776 DOCTEST_NOINLINE bool unary_assert(assertType::Enum at, const char* file, int line,
1777 const char* expr, const DOCTEST_REF_WRAP(L) val) {
1778 bool failed = !val;
1779
1780 if(at & assertType::is_false)
1781 failed = !failed;
1782
1783 // ###################################################################################
1784 // IF THE DEBUGGER BREAKS HERE - GO 1 LEVEL UP IN THE CALLSTACK FOR THE FAILING ASSERT
1785 // THIS IS THE EFFECT OF HAVING 'DOCTEST_CONFIG_SUPER_FAST_ASSERTS' DEFINED
1786 // ###################################################################################
1787 DOCTEST_ASSERT_OUT_OF_TESTS((DOCTEST_STRINGIFY(val)));
1788 DOCTEST_ASSERT_IN_TESTS((DOCTEST_STRINGIFY(val)));
1789 return !failed;
1790 }
1791
1792 struct DOCTEST_INTERFACE IExceptionTranslator
1793 {
1794 DOCTEST_DECLARE_INTERFACE(IExceptionTranslator)
1795 virtual bool translate(String&) const = 0;
1796 };
1797
1798 template <typename T>
1799 class ExceptionTranslator : public IExceptionTranslator
1800 {
1801 public:
1802 explicit ExceptionTranslator(String (*translateFunction)(T))
1803 : m_translateFunction(translateFunction) {}
1804
1805 bool translate(String& res) const override {
1806#ifndef DOCTEST_CONFIG_NO_EXCEPTIONS
1807 try {
1808 throw; // lgtm [cpp/rethrow-no-exception]
1809 // cppcheck-suppress catchExceptionByValue
1810 } catch(const T& ex) {
1811 res = m_translateFunction(ex);
1812 return true;
1813 } catch(...) {}
1814#endif // DOCTEST_CONFIG_NO_EXCEPTIONS
1815 static_cast<void>(res); // to silence -Wunused-parameter
1816 return false;
1817 }
1818
1819 private:
1820 String (*m_translateFunction)(T);
1821 };
1822
1823 DOCTEST_INTERFACE void registerExceptionTranslatorImpl(const IExceptionTranslator* et);
1824
1825 // ContextScope base class used to allow implementing methods of ContextScope
1826 // that don't depend on the template parameter in doctest.cpp.
1827 struct DOCTEST_INTERFACE ContextScopeBase : public IContextScope {
1828 ContextScopeBase(const ContextScopeBase&) = delete;
1829
1830 ContextScopeBase& operator=(const ContextScopeBase&) = delete;
1831 ContextScopeBase& operator=(ContextScopeBase&&) = delete;
1832
1833 ~ContextScopeBase() override = default;
1834
1835 protected:
1836 ContextScopeBase();
1837 ContextScopeBase(ContextScopeBase&& other) noexcept;
1838
1839 void destroy();
1840 bool need_to_destroy{true};
1841 };
1842
1843 template <typename L> class ContextScope : public ContextScopeBase
1844 {
1845 L lambda_;
1846
1847 public:
1848 explicit ContextScope(const L &lambda) : lambda_(lambda) {}
1849 explicit ContextScope(L&& lambda) : lambda_(static_cast<L&&>(lambda)) { }
1850
1851 ContextScope(const ContextScope&) = delete;
1852 ContextScope(ContextScope&&) noexcept = default;
1853
1854 ContextScope& operator=(const ContextScope&) = delete;
1855 ContextScope& operator=(ContextScope&&) = delete;
1856
1857 void stringify(std::ostream* s) const override { lambda_(s); }
1858
1859 ~ContextScope() override {
1860 if (need_to_destroy) {
1861 destroy();
1862 }
1863 }
1864 };
1865
1866 struct DOCTEST_INTERFACE MessageBuilder : public MessageData
1867 {
1868 std::ostream* m_stream;
1869 bool logged = false;
1870
1871 MessageBuilder(const char* file, int line, assertType::Enum severity);
1872
1873 MessageBuilder(const MessageBuilder&) = delete;
1874 MessageBuilder(MessageBuilder&&) = delete;
1875
1876 MessageBuilder& operator=(const MessageBuilder&) = delete;
1877 MessageBuilder& operator=(MessageBuilder&&) = delete;
1878
1879 ~MessageBuilder();
1880
1881 // the preferred way of chaining parameters for stringification
1882DOCTEST_MSVC_SUPPRESS_WARNING_WITH_PUSH(4866)
1883 template <typename T>
1884 MessageBuilder& operator,(const T& in) {
1885 *m_stream << (DOCTEST_STRINGIFY(in));
1886 return *this;
1887 }
1888DOCTEST_MSVC_SUPPRESS_WARNING_POP
1889
1890 // kept here just for backwards-compatibility - the comma operator should be preferred now
1891 template <typename T>
1892 MessageBuilder& operator<<(const T& in) { return this->operator,(in); }
1893
1894 // the `,` operator has the lowest operator precedence - if `<<` is used by the user then
1895 // the `,` operator will be called last which is not what we want and thus the `*` operator
1896 // is used first (has higher operator precedence compared to `<<`) so that we guarantee that
1897 // an operator of the MessageBuilder class is called first before the rest of the parameters
1898 template <typename T>
1899 MessageBuilder& operator*(const T& in) { return this->operator,(in); }
1900
1901 bool log();
1902 void react();
1903 };
1904
1905 template <typename L>
1906 ContextScope<L> MakeContextScope(const L &lambda) {
1907 return ContextScope<L>(lambda);
1908 }
1909} // namespace detail
1910
1911#define DOCTEST_DEFINE_DECORATOR(name, type, def) \
1912 struct name \
1913 { \
1914 type data; \
1915 name(type in = def) \
1916 : data(in) {} \
1917 void fill(detail::TestCase& state) const { state.DOCTEST_CAT(m_, name) = data; } \
1918 void fill(detail::TestSuite& state) const { state.DOCTEST_CAT(m_, name) = data; } \
1919 }
1920
1921DOCTEST_DEFINE_DECORATOR(test_suite, const char*, "");
1922DOCTEST_DEFINE_DECORATOR(description, const char*, "");
1923DOCTEST_DEFINE_DECORATOR(skip, bool, true);
1924DOCTEST_DEFINE_DECORATOR(no_breaks, bool, true);
1925DOCTEST_DEFINE_DECORATOR(no_output, bool, true);
1926DOCTEST_DEFINE_DECORATOR(timeout, double, 0);
1927DOCTEST_DEFINE_DECORATOR(may_fail, bool, true);
1928DOCTEST_DEFINE_DECORATOR(should_fail, bool, true);
1929DOCTEST_DEFINE_DECORATOR(expected_failures, int, 0);
1930
1931template <typename T>
1932int registerExceptionTranslator(String (*translateFunction)(T)) {
1933 DOCTEST_CLANG_SUPPRESS_WARNING_WITH_PUSH("-Wexit-time-destructors")
1934 static detail::ExceptionTranslator<T> exceptionTranslator(translateFunction);
1935 DOCTEST_CLANG_SUPPRESS_WARNING_POP
1936 detail::registerExceptionTranslatorImpl(&exceptionTranslator);
1937 return 0;
1938}
1939
1940} // namespace doctest
1941
1942// in a separate namespace outside of doctest because the DOCTEST_TEST_SUITE macro
1943// introduces an anonymous namespace in which getCurrentTestSuite gets overridden
1944namespace doctest_detail_test_suite_ns {
1945DOCTEST_INTERFACE doctest::detail::TestSuite& getCurrentTestSuite();
1946} // namespace doctest_detail_test_suite_ns
1947
1948namespace doctest {
1949#else // DOCTEST_CONFIG_DISABLE
1950template <typename T>
1951int registerExceptionTranslator(String (*)(T)) {
1952 return 0;
1953}
1954#endif // DOCTEST_CONFIG_DISABLE
1955
1956namespace detail {
1957 using assert_handler = void (*)(const AssertData&);
1958 struct ContextState;
1959} // namespace detail
1960
1961class DOCTEST_INTERFACE Context
1962{
1963 detail::ContextState* p;
1964
1965 void parseArgs(int argc, const char* const* argv, bool withDefaults = false);
1966
1967public:
1968 explicit Context(int argc = 0, const char* const* argv = nullptr);
1969
1970 Context(const Context&) = delete;
1971 Context(Context&&) = delete;
1972
1973 Context& operator=(const Context&) = delete;
1974 Context& operator=(Context&&) = delete;
1975
1976 ~Context(); // NOLINT(performance-trivially-destructible)
1977
1978 void applyCommandLine(int argc, const char* const* argv);
1979
1980 void addFilter(const char* filter, const char* value);
1981 void clearFilters();
1982 void setOption(const char* option, bool value);
1983 void setOption(const char* option, int value);
1984 void setOption(const char* option, const char* value);
1985
1986 bool shouldExit();
1987
1988 void setAsDefaultForAssertsOutOfTestCases();
1989
1990 void setAssertHandler(detail::assert_handler ah);
1991
1992 void setCout(std::ostream* out);
1993
1994 int run();
1995};
1996
1997namespace TestCaseFailureReason {
1998 enum Enum
1999 {
2000 None = 0,
2001 AssertFailure = 1, // an assertion has failed in the test case
2002 Exception = 2, // test case threw an exception
2003 Crash = 4, // a crash...
2004 TooManyFailedAsserts = 8, // the abort-after option
2005 Timeout = 16, // see the timeout decorator
2006 ShouldHaveFailedButDidnt = 32, // see the should_fail decorator
2007 ShouldHaveFailedAndDid = 64, // see the should_fail decorator
2008 DidntFailExactlyNumTimes = 128, // see the expected_failures decorator
2009 FailedExactlyNumTimes = 256, // see the expected_failures decorator
2010 CouldHaveFailedAndDid = 512 // see the may_fail decorator
2011 };
2012} // namespace TestCaseFailureReason
2013
2014struct DOCTEST_INTERFACE CurrentTestCaseStats
2015{
2016 int numAssertsCurrentTest;
2017 int numAssertsFailedCurrentTest;
2018 double seconds;
2019 int failure_flags; // use TestCaseFailureReason::Enum
2020 bool testCaseSuccess;
2021};
2022
2023struct DOCTEST_INTERFACE TestCaseException
2024{
2025 String error_string;
2026 bool is_crash;
2027};
2028
2029struct DOCTEST_INTERFACE TestRunStats
2030{
2031 unsigned numTestCases;
2032 unsigned numTestCasesPassingFilters;
2033 unsigned numTestSuitesPassingFilters;
2034 unsigned numTestCasesFailed;
2035 int numAsserts;
2036 int numAssertsFailed;
2037};
2038
2039struct QueryData
2040{
2041 const TestRunStats* run_stats = nullptr;
2042 const TestCaseData** data = nullptr;
2043 unsigned num_data = 0;
2044};
2045
2046struct DOCTEST_INTERFACE IReporter
2047{
2048 // The constructor has to accept "const ContextOptions&" as a single argument
2049 // which has most of the options for the run + a pointer to the stdout stream
2050 // Reporter(const ContextOptions& in)
2051
2052 // called when a query should be reported (listing test cases, printing the version, etc.)
2053 virtual void report_query(const QueryData&) = 0;
2054
2055 // called when the whole test run starts
2056 virtual void test_run_start() = 0;
2057 // called when the whole test run ends (caching a pointer to the input doesn't make sense here)
2058 virtual void test_run_end(const TestRunStats&) = 0;
2059
2060 // called when a test case is started (safe to cache a pointer to the input)
2061 virtual void test_case_start(const TestCaseData&) = 0;
2062 // called when a test case is reentered because of unfinished subcases (safe to cache a pointer to the input)
2063 virtual void test_case_reenter(const TestCaseData&) = 0;
2064 // called when a test case has ended
2065 virtual void test_case_end(const CurrentTestCaseStats&) = 0;
2066
2067 // called when an exception is thrown from the test case (or it crashes)
2068 virtual void test_case_exception(const TestCaseException&) = 0;
2069
2070 // called whenever a subcase is entered (don't cache pointers to the input)
2071 virtual void subcase_start(const SubcaseSignature&) = 0;
2072 // called whenever a subcase is exited (don't cache pointers to the input)
2073 virtual void subcase_end() = 0;
2074
2075 // called for each assert (don't cache pointers to the input)
2076 virtual void log_assert(const AssertData&) = 0;
2077 // called for each message (don't cache pointers to the input)
2078 virtual void log_message(const MessageData&) = 0;
2079
2080 // called when a test case is skipped either because it doesn't pass the filters, has a skip decorator
2081 // or isn't in the execution range (between first and last) (safe to cache a pointer to the input)
2082 virtual void test_case_skipped(const TestCaseData&) = 0;
2083
2084 DOCTEST_DECLARE_INTERFACE(IReporter)
2085
2086 // can obtain all currently active contexts and stringify them if one wishes to do so
2087 static int get_num_active_contexts();
2088 static const IContextScope* const* get_active_contexts();
2089
2090 // can iterate through contexts which have been stringified automatically in their destructors when an exception has been thrown
2091 static int get_num_stringified_contexts();
2092 static const String* get_stringified_contexts();
2093};
2094
2095namespace detail {
2096 using reporterCreatorFunc = IReporter* (*)(const ContextOptions&);
2097
2098 DOCTEST_INTERFACE void registerReporterImpl(const char* name, int prio, reporterCreatorFunc c, bool isReporter);
2099
2100 template <typename Reporter>
2101 IReporter* reporterCreator(const ContextOptions& o) {
2102 return new Reporter(o);
2103 }
2104} // namespace detail
2105
2106template <typename Reporter>
2107int registerReporter(const char* name, int priority, bool isReporter) {
2108 detail::registerReporterImpl(name, priority, detail::reporterCreator<Reporter>, isReporter);
2109 return 0;
2110}
2111} // namespace doctest
2112
2113#ifdef DOCTEST_CONFIG_ASSERTS_RETURN_VALUES
2114#define DOCTEST_FUNC_EMPTY [] { return false; }()
2115#else
2116#define DOCTEST_FUNC_EMPTY (void)0
2117#endif
2118
2119// if registering is not disabled
2120#ifndef DOCTEST_CONFIG_DISABLE
2121
2122#ifdef DOCTEST_CONFIG_ASSERTS_RETURN_VALUES
2123#define DOCTEST_FUNC_SCOPE_BEGIN [&]
2124#define DOCTEST_FUNC_SCOPE_END ()
2125#define DOCTEST_FUNC_SCOPE_RET(v) return v
2126#else
2127#define DOCTEST_FUNC_SCOPE_BEGIN do
2128#define DOCTEST_FUNC_SCOPE_END while(false)
2129#define DOCTEST_FUNC_SCOPE_RET(v) (void)0
2130#endif
2131
2132// common code in asserts - for convenience
2133#define DOCTEST_ASSERT_LOG_REACT_RETURN(b) \
2134 if(b.log()) DOCTEST_BREAK_INTO_DEBUGGER(); \
2135 b.react(); \
2136 DOCTEST_FUNC_SCOPE_RET(!b.m_failed)
2137
2138#ifdef DOCTEST_CONFIG_NO_TRY_CATCH_IN_ASSERTS
2139#define DOCTEST_WRAP_IN_TRY(x) x;
2140#else // DOCTEST_CONFIG_NO_TRY_CATCH_IN_ASSERTS
2141#define DOCTEST_WRAP_IN_TRY(x) \
2142 try { \
2143 x; \
2144 } catch(...) { DOCTEST_RB.translateException(); }
2145#endif // DOCTEST_CONFIG_NO_TRY_CATCH_IN_ASSERTS
2146
2147#ifdef DOCTEST_CONFIG_VOID_CAST_EXPRESSIONS
2148#define DOCTEST_CAST_TO_VOID(...) \
2149 DOCTEST_GCC_SUPPRESS_WARNING_WITH_PUSH("-Wuseless-cast") \
2150 static_cast<void>(__VA_ARGS__); \
2151 DOCTEST_GCC_SUPPRESS_WARNING_POP
2152#else // DOCTEST_CONFIG_VOID_CAST_EXPRESSIONS
2153#define DOCTEST_CAST_TO_VOID(...) __VA_ARGS__;
2154#endif // DOCTEST_CONFIG_VOID_CAST_EXPRESSIONS
2155
2156// registers the test by initializing a dummy var with a function
2157#define DOCTEST_REGISTER_FUNCTION(global_prefix, f, decorators) \
2158 global_prefix DOCTEST_GLOBAL_NO_WARNINGS(DOCTEST_ANONYMOUS(DOCTEST_ANON_VAR_), /* NOLINT */ \
2159 doctest::detail::regTest( \
2160 doctest::detail::TestCase( \
2161 f, __FILE__, __LINE__, \
2162 doctest_detail_test_suite_ns::getCurrentTestSuite()) * \
2163 decorators))
2164
2165#define DOCTEST_IMPLEMENT_FIXTURE(der, base, func, decorators) \
2166 namespace { /* NOLINT */ \
2167 struct der : public base \
2168 { \
2169 void f(); \
2170 }; \
2171 static DOCTEST_INLINE_NOINLINE void func() { \
2172 der v; \
2173 v.f(); \
2174 } \
2175 DOCTEST_REGISTER_FUNCTION(DOCTEST_EMPTY, func, decorators) \
2176 } \
2177 DOCTEST_INLINE_NOINLINE void der::f() // NOLINT(misc-definitions-in-headers)
2178
2179#define DOCTEST_CREATE_AND_REGISTER_FUNCTION(f, decorators) \
2180 static void f(); \
2181 DOCTEST_REGISTER_FUNCTION(DOCTEST_EMPTY, f, decorators) \
2182 static void f()
2183
2184#define DOCTEST_CREATE_AND_REGISTER_FUNCTION_IN_CLASS(f, proxy, decorators) \
2185 static doctest::detail::funcType proxy() { return f; } \
2186 DOCTEST_REGISTER_FUNCTION(inline, proxy(), decorators) \
2187 static void f()
2188
2189// for registering tests
2190#define DOCTEST_TEST_CASE(decorators) \
2191 DOCTEST_CREATE_AND_REGISTER_FUNCTION(DOCTEST_ANONYMOUS(DOCTEST_ANON_FUNC_), decorators)
2192
2193// for registering tests in classes - requires C++17 for inline variables!
2194#if DOCTEST_CPLUSPLUS >= 201703L
2195#define DOCTEST_TEST_CASE_CLASS(decorators) \
2196 DOCTEST_CREATE_AND_REGISTER_FUNCTION_IN_CLASS(DOCTEST_ANONYMOUS(DOCTEST_ANON_FUNC_), \
2197 DOCTEST_ANONYMOUS(DOCTEST_ANON_PROXY_), \
2198 decorators)
2199#else // DOCTEST_TEST_CASE_CLASS
2200#define DOCTEST_TEST_CASE_CLASS(...) \
2201 TEST_CASES_CAN_BE_REGISTERED_IN_CLASSES_ONLY_IN_CPP17_MODE_OR_WITH_VS_2017_OR_NEWER
2202#endif // DOCTEST_TEST_CASE_CLASS
2203
2204// for registering tests with a fixture
2205#define DOCTEST_TEST_CASE_FIXTURE(c, decorators) \
2206 DOCTEST_IMPLEMENT_FIXTURE(DOCTEST_ANONYMOUS(DOCTEST_ANON_CLASS_), c, \
2207 DOCTEST_ANONYMOUS(DOCTEST_ANON_FUNC_), decorators)
2208
2209// for converting types to strings without the <typeinfo> header and demangling
2210#define DOCTEST_TYPE_TO_STRING_AS(str, ...) \
2211 namespace doctest { \
2212 template <> \
2213 inline String toString<__VA_ARGS__>() { \
2214 return str; \
2215 } \
2216 } \
2217 static_assert(true, "")
2218
2219#define DOCTEST_TYPE_TO_STRING(...) DOCTEST_TYPE_TO_STRING_AS(#__VA_ARGS__, __VA_ARGS__)
2220
2221#define DOCTEST_TEST_CASE_TEMPLATE_DEFINE_IMPL(dec, T, iter, func) \
2222 template <typename T> \
2223 static void func(); \
2224 namespace { /* NOLINT */ \
2225 template <typename Tuple> \
2226 struct iter; \
2227 template <typename Type, typename... Rest> \
2228 struct iter<std::tuple<Type, Rest...>> \
2229 { \
2230 iter(const char* file, unsigned line, int index) { \
2231 doctest::detail::regTest(doctest::detail::TestCase(func<Type>, file, line, \
2232 doctest_detail_test_suite_ns::getCurrentTestSuite(), \
2233 doctest::toString<Type>(), \
2234 int(line) * 1000 + index) \
2235 * dec); \
2236 iter<std::tuple<Rest...>>(file, line, index + 1); \
2237 } \
2238 }; \
2239 template <> \
2240 struct iter<std::tuple<>> \
2241 { \
2242 iter(const char*, unsigned, int) {} \
2243 }; \
2244 } \
2245 template <typename T> \
2246 static void func()
2247
2248#define DOCTEST_TEST_CASE_TEMPLATE_DEFINE(dec, T, id) \
2249 DOCTEST_TEST_CASE_TEMPLATE_DEFINE_IMPL(dec, T, DOCTEST_CAT(id, ITERATOR), \
2250 DOCTEST_ANONYMOUS(DOCTEST_ANON_TMP_))
2251
2252#define DOCTEST_TEST_CASE_TEMPLATE_INSTANTIATE_IMPL(id, anon, ...) \
2253 DOCTEST_GLOBAL_NO_WARNINGS(DOCTEST_CAT(anon, DUMMY), /* NOLINT(cert-err58-cpp, fuchsia-statically-constructed-objects) */ \
2254 doctest::detail::instantiationHelper( \
2255 DOCTEST_CAT(id, ITERATOR)<__VA_ARGS__>(__FILE__, __LINE__, 0)))
2256
2257#define DOCTEST_TEST_CASE_TEMPLATE_INVOKE(id, ...) \
2258 DOCTEST_TEST_CASE_TEMPLATE_INSTANTIATE_IMPL(id, DOCTEST_ANONYMOUS(DOCTEST_ANON_TMP_), std::tuple<__VA_ARGS__>) \
2259 static_assert(true, "")
2260
2261#define DOCTEST_TEST_CASE_TEMPLATE_APPLY(id, ...) \
2262 DOCTEST_TEST_CASE_TEMPLATE_INSTANTIATE_IMPL(id, DOCTEST_ANONYMOUS(DOCTEST_ANON_TMP_), __VA_ARGS__) \
2263 static_assert(true, "")
2264
2265#define DOCTEST_TEST_CASE_TEMPLATE_IMPL(dec, T, anon, ...) \
2266 DOCTEST_TEST_CASE_TEMPLATE_DEFINE_IMPL(dec, T, DOCTEST_CAT(anon, ITERATOR), anon); \
2267 DOCTEST_TEST_CASE_TEMPLATE_INSTANTIATE_IMPL(anon, anon, std::tuple<__VA_ARGS__>) \
2268 template <typename T> \
2269 static void anon()
2270
2271#define DOCTEST_TEST_CASE_TEMPLATE(dec, T, ...) \
2272 DOCTEST_TEST_CASE_TEMPLATE_IMPL(dec, T, DOCTEST_ANONYMOUS(DOCTEST_ANON_TMP_), __VA_ARGS__)
2273
2274// for subcases
2275#define DOCTEST_SUBCASE(name) \
2276 if(const doctest::detail::Subcase & DOCTEST_ANONYMOUS(DOCTEST_ANON_SUBCASE_) DOCTEST_UNUSED = \
2277 doctest::detail::Subcase(name, __FILE__, __LINE__))
2278
2279// for grouping tests in test suites by using code blocks
2280#define DOCTEST_TEST_SUITE_IMPL(decorators, ns_name) \
2281 namespace ns_name { namespace doctest_detail_test_suite_ns { \
2282 static DOCTEST_NOINLINE doctest::detail::TestSuite& getCurrentTestSuite() noexcept { \
2283 DOCTEST_MSVC_SUPPRESS_WARNING_WITH_PUSH(4640) \
2284 DOCTEST_CLANG_SUPPRESS_WARNING_WITH_PUSH("-Wexit-time-destructors") \
2285 DOCTEST_GCC_SUPPRESS_WARNING_WITH_PUSH("-Wmissing-field-initializers") \
2286 static doctest::detail::TestSuite data{}; \
2287 static bool inited = false; \
2288 DOCTEST_MSVC_SUPPRESS_WARNING_POP \
2289 DOCTEST_CLANG_SUPPRESS_WARNING_POP \
2290 DOCTEST_GCC_SUPPRESS_WARNING_POP \
2291 if(!inited) { \
2292 data* decorators; \
2293 inited = true; \
2294 } \
2295 return data; \
2296 } \
2297 } \
2298 } \
2299 namespace ns_name
2300
2301#define DOCTEST_TEST_SUITE(decorators) \
2302 DOCTEST_TEST_SUITE_IMPL(decorators, DOCTEST_ANONYMOUS(DOCTEST_ANON_SUITE_))
2303
2304// for starting a testsuite block
2305#define DOCTEST_TEST_SUITE_BEGIN(decorators) \
2306 DOCTEST_GLOBAL_NO_WARNINGS(DOCTEST_ANONYMOUS(DOCTEST_ANON_VAR_), /* NOLINT(cert-err58-cpp) */ \
2307 doctest::detail::setTestSuite(doctest::detail::TestSuite() * decorators)) \
2308 static_assert(true, "")
2309
2310// for ending a testsuite block
2311#define DOCTEST_TEST_SUITE_END \
2312 DOCTEST_GLOBAL_NO_WARNINGS(DOCTEST_ANONYMOUS(DOCTEST_ANON_VAR_), /* NOLINT(cert-err58-cpp) */ \
2313 doctest::detail::setTestSuite(doctest::detail::TestSuite() * "")) \
2314 using DOCTEST_ANONYMOUS(DOCTEST_ANON_FOR_SEMICOLON_) = int
2315
2316// for registering exception translators
2317#define DOCTEST_REGISTER_EXCEPTION_TRANSLATOR_IMPL(translatorName, signature) \
2318 inline doctest::String translatorName(signature); \
2319 DOCTEST_GLOBAL_NO_WARNINGS(DOCTEST_ANONYMOUS(DOCTEST_ANON_TRANSLATOR_), /* NOLINT(cert-err58-cpp) */ \
2320 doctest::registerExceptionTranslator(translatorName)) \
2321 doctest::String translatorName(signature)
2322
2323#define DOCTEST_REGISTER_EXCEPTION_TRANSLATOR(signature) \
2324 DOCTEST_REGISTER_EXCEPTION_TRANSLATOR_IMPL(DOCTEST_ANONYMOUS(DOCTEST_ANON_TRANSLATOR_), \
2325 signature)
2326
2327// for registering reporters
2328#define DOCTEST_REGISTER_REPORTER(name, priority, reporter) \
2329 DOCTEST_GLOBAL_NO_WARNINGS(DOCTEST_ANONYMOUS(DOCTEST_ANON_REPORTER_), /* NOLINT(cert-err58-cpp) */ \
2330 doctest::registerReporter<reporter>(name, priority, true)) \
2331 static_assert(true, "")
2332
2333// for registering listeners
2334#define DOCTEST_REGISTER_LISTENER(name, priority, reporter) \
2335 DOCTEST_GLOBAL_NO_WARNINGS(DOCTEST_ANONYMOUS(DOCTEST_ANON_REPORTER_), /* NOLINT(cert-err58-cpp) */ \
2336 doctest::registerReporter<reporter>(name, priority, false)) \
2337 static_assert(true, "")
2338
2339// clang-format off
2340// for logging - disabling formatting because it's important to have these on 2 separate lines - see PR #557
2341#define DOCTEST_INFO(...) \
2342 DOCTEST_INFO_IMPL(DOCTEST_ANONYMOUS(DOCTEST_CAPTURE_), \
2343 DOCTEST_ANONYMOUS(DOCTEST_CAPTURE_OTHER_), \
2344 __VA_ARGS__)
2345// clang-format on
2346
2347#define DOCTEST_INFO_IMPL(mb_name, s_name, ...) \
2348 auto DOCTEST_ANONYMOUS(DOCTEST_CAPTURE_) = doctest::detail::MakeContextScope( \
2349 [&](std::ostream* s_name) { \
2350 doctest::detail::MessageBuilder mb_name(__FILE__, __LINE__, doctest::assertType::is_warn); \
2351 mb_name.m_stream = s_name; \
2352 mb_name * __VA_ARGS__; \
2353 })
2354
2355#define DOCTEST_CAPTURE(x) DOCTEST_INFO(#x " := ", x)
2356
2357#define DOCTEST_ADD_AT_IMPL(type, file, line, mb, ...) \
2358 DOCTEST_FUNC_SCOPE_BEGIN { \
2359 doctest::detail::MessageBuilder mb(file, line, doctest::assertType::type); \
2360 mb * __VA_ARGS__; \
2361 if(mb.log()) \
2362 DOCTEST_BREAK_INTO_DEBUGGER(); \
2363 mb.react(); \
2364 } DOCTEST_FUNC_SCOPE_END
2365
2366// clang-format off
2367#define DOCTEST_ADD_MESSAGE_AT(file, line, ...) DOCTEST_ADD_AT_IMPL(is_warn, file, line, DOCTEST_ANONYMOUS(DOCTEST_MESSAGE_), __VA_ARGS__)
2368#define DOCTEST_ADD_FAIL_CHECK_AT(file, line, ...) DOCTEST_ADD_AT_IMPL(is_check, file, line, DOCTEST_ANONYMOUS(DOCTEST_MESSAGE_), __VA_ARGS__)
2369#define DOCTEST_ADD_FAIL_AT(file, line, ...) DOCTEST_ADD_AT_IMPL(is_require, file, line, DOCTEST_ANONYMOUS(DOCTEST_MESSAGE_), __VA_ARGS__)
2370// clang-format on
2371
2372#define DOCTEST_MESSAGE(...) DOCTEST_ADD_MESSAGE_AT(__FILE__, __LINE__, __VA_ARGS__)
2373#define DOCTEST_FAIL_CHECK(...) DOCTEST_ADD_FAIL_CHECK_AT(__FILE__, __LINE__, __VA_ARGS__)
2374#define DOCTEST_FAIL(...) DOCTEST_ADD_FAIL_AT(__FILE__, __LINE__, __VA_ARGS__)
2375
2376#define DOCTEST_TO_LVALUE(...) __VA_ARGS__ // Not removed to keep backwards compatibility.
2377
2378#ifndef DOCTEST_CONFIG_SUPER_FAST_ASSERTS
2379
2380#define DOCTEST_ASSERT_IMPLEMENT_2(assert_type, ...) \
2381 DOCTEST_CLANG_SUPPRESS_WARNING_WITH_PUSH("-Woverloaded-shift-op-parentheses") \
2382 /* NOLINTNEXTLINE(clang-analyzer-cplusplus.NewDeleteLeaks) */ \
2383 doctest::detail::ResultBuilder DOCTEST_RB(doctest::assertType::assert_type, __FILE__, \
2384 __LINE__, #__VA_ARGS__); \
2385 DOCTEST_WRAP_IN_TRY(DOCTEST_RB.setResult( \
2386 doctest::detail::ExpressionDecomposer(doctest::assertType::assert_type) \
2387 << __VA_ARGS__)) /* NOLINTNEXTLINE(clang-analyzer-cplusplus.NewDeleteLeaks) */ \
2388 DOCTEST_ASSERT_LOG_REACT_RETURN(DOCTEST_RB) \
2389 DOCTEST_CLANG_SUPPRESS_WARNING_POP
2390
2391#define DOCTEST_ASSERT_IMPLEMENT_1(assert_type, ...) \
2392 DOCTEST_FUNC_SCOPE_BEGIN { \
2393 DOCTEST_ASSERT_IMPLEMENT_2(assert_type, __VA_ARGS__); \
2394 } DOCTEST_FUNC_SCOPE_END // NOLINT(clang-analyzer-cplusplus.NewDeleteLeaks)
2395
2396#define DOCTEST_BINARY_ASSERT(assert_type, comp, ...) \
2397 DOCTEST_FUNC_SCOPE_BEGIN { \
2398 doctest::detail::ResultBuilder DOCTEST_RB(doctest::assertType::assert_type, __FILE__, \
2399 __LINE__, #__VA_ARGS__); \
2400 DOCTEST_WRAP_IN_TRY( \
2401 DOCTEST_RB.binary_assert<doctest::detail::binaryAssertComparison::comp>( \
2402 __VA_ARGS__)) \
2403 DOCTEST_ASSERT_LOG_REACT_RETURN(DOCTEST_RB); \
2404 } DOCTEST_FUNC_SCOPE_END
2405
2406#define DOCTEST_UNARY_ASSERT(assert_type, ...) \
2407 DOCTEST_FUNC_SCOPE_BEGIN { \
2408 doctest::detail::ResultBuilder DOCTEST_RB(doctest::assertType::assert_type, __FILE__, \
2409 __LINE__, #__VA_ARGS__); \
2410 DOCTEST_WRAP_IN_TRY(DOCTEST_RB.unary_assert(__VA_ARGS__)) \
2411 DOCTEST_ASSERT_LOG_REACT_RETURN(DOCTEST_RB); \
2412 } DOCTEST_FUNC_SCOPE_END
2413
2414#else // DOCTEST_CONFIG_SUPER_FAST_ASSERTS
2415
2416// necessary for <ASSERT>_MESSAGE
2417#define DOCTEST_ASSERT_IMPLEMENT_2 DOCTEST_ASSERT_IMPLEMENT_1
2418
2419#define DOCTEST_ASSERT_IMPLEMENT_1(assert_type, ...) \
2420 DOCTEST_CLANG_SUPPRESS_WARNING_WITH_PUSH("-Woverloaded-shift-op-parentheses") \
2421 doctest::detail::decomp_assert( \
2422 doctest::assertType::assert_type, __FILE__, __LINE__, #__VA_ARGS__, \
2423 doctest::detail::ExpressionDecomposer(doctest::assertType::assert_type) \
2424 << __VA_ARGS__) DOCTEST_CLANG_SUPPRESS_WARNING_POP
2425
2426#define DOCTEST_BINARY_ASSERT(assert_type, comparison, ...) \
2427 doctest::detail::binary_assert<doctest::detail::binaryAssertComparison::comparison>( \
2428 doctest::assertType::assert_type, __FILE__, __LINE__, #__VA_ARGS__, __VA_ARGS__)
2429
2430#define DOCTEST_UNARY_ASSERT(assert_type, ...) \
2431 doctest::detail::unary_assert(doctest::assertType::assert_type, __FILE__, __LINE__, \
2432 #__VA_ARGS__, __VA_ARGS__)
2433
2434#endif // DOCTEST_CONFIG_SUPER_FAST_ASSERTS
2435
2436#define DOCTEST_WARN(...) DOCTEST_ASSERT_IMPLEMENT_1(DT_WARN, __VA_ARGS__)
2437#define DOCTEST_CHECK(...) DOCTEST_ASSERT_IMPLEMENT_1(DT_CHECK, __VA_ARGS__)
2438#define DOCTEST_REQUIRE(...) DOCTEST_ASSERT_IMPLEMENT_1(DT_REQUIRE, __VA_ARGS__)
2439#define DOCTEST_WARN_FALSE(...) DOCTEST_ASSERT_IMPLEMENT_1(DT_WARN_FALSE, __VA_ARGS__)
2440#define DOCTEST_CHECK_FALSE(...) DOCTEST_ASSERT_IMPLEMENT_1(DT_CHECK_FALSE, __VA_ARGS__)
2441#define DOCTEST_REQUIRE_FALSE(...) DOCTEST_ASSERT_IMPLEMENT_1(DT_REQUIRE_FALSE, __VA_ARGS__)
2442
2443// clang-format off
2444#define DOCTEST_WARN_MESSAGE(cond, ...) DOCTEST_FUNC_SCOPE_BEGIN { DOCTEST_INFO(__VA_ARGS__); DOCTEST_ASSERT_IMPLEMENT_2(DT_WARN, cond); } DOCTEST_FUNC_SCOPE_END
2445#define DOCTEST_CHECK_MESSAGE(cond, ...) DOCTEST_FUNC_SCOPE_BEGIN { DOCTEST_INFO(__VA_ARGS__); DOCTEST_ASSERT_IMPLEMENT_2(DT_CHECK, cond); } DOCTEST_FUNC_SCOPE_END
2446#define DOCTEST_REQUIRE_MESSAGE(cond, ...) DOCTEST_FUNC_SCOPE_BEGIN { DOCTEST_INFO(__VA_ARGS__); DOCTEST_ASSERT_IMPLEMENT_2(DT_REQUIRE, cond); } DOCTEST_FUNC_SCOPE_END
2447#define DOCTEST_WARN_FALSE_MESSAGE(cond, ...) DOCTEST_FUNC_SCOPE_BEGIN { DOCTEST_INFO(__VA_ARGS__); DOCTEST_ASSERT_IMPLEMENT_2(DT_WARN_FALSE, cond); } DOCTEST_FUNC_SCOPE_END
2448#define DOCTEST_CHECK_FALSE_MESSAGE(cond, ...) DOCTEST_FUNC_SCOPE_BEGIN { DOCTEST_INFO(__VA_ARGS__); DOCTEST_ASSERT_IMPLEMENT_2(DT_CHECK_FALSE, cond); } DOCTEST_FUNC_SCOPE_END
2449#define DOCTEST_REQUIRE_FALSE_MESSAGE(cond, ...) DOCTEST_FUNC_SCOPE_BEGIN { DOCTEST_INFO(__VA_ARGS__); DOCTEST_ASSERT_IMPLEMENT_2(DT_REQUIRE_FALSE, cond); } DOCTEST_FUNC_SCOPE_END
2450// clang-format on
2451
2452#define DOCTEST_WARN_EQ(...) DOCTEST_BINARY_ASSERT(DT_WARN_EQ, eq, __VA_ARGS__)
2453#define DOCTEST_CHECK_EQ(...) DOCTEST_BINARY_ASSERT(DT_CHECK_EQ, eq, __VA_ARGS__)
2454#define DOCTEST_REQUIRE_EQ(...) DOCTEST_BINARY_ASSERT(DT_REQUIRE_EQ, eq, __VA_ARGS__)
2455#define DOCTEST_WARN_NE(...) DOCTEST_BINARY_ASSERT(DT_WARN_NE, ne, __VA_ARGS__)
2456#define DOCTEST_CHECK_NE(...) DOCTEST_BINARY_ASSERT(DT_CHECK_NE, ne, __VA_ARGS__)
2457#define DOCTEST_REQUIRE_NE(...) DOCTEST_BINARY_ASSERT(DT_REQUIRE_NE, ne, __VA_ARGS__)
2458#define DOCTEST_WARN_GT(...) DOCTEST_BINARY_ASSERT(DT_WARN_GT, gt, __VA_ARGS__)
2459#define DOCTEST_CHECK_GT(...) DOCTEST_BINARY_ASSERT(DT_CHECK_GT, gt, __VA_ARGS__)
2460#define DOCTEST_REQUIRE_GT(...) DOCTEST_BINARY_ASSERT(DT_REQUIRE_GT, gt, __VA_ARGS__)
2461#define DOCTEST_WARN_LT(...) DOCTEST_BINARY_ASSERT(DT_WARN_LT, lt, __VA_ARGS__)
2462#define DOCTEST_CHECK_LT(...) DOCTEST_BINARY_ASSERT(DT_CHECK_LT, lt, __VA_ARGS__)
2463#define DOCTEST_REQUIRE_LT(...) DOCTEST_BINARY_ASSERT(DT_REQUIRE_LT, lt, __VA_ARGS__)
2464#define DOCTEST_WARN_GE(...) DOCTEST_BINARY_ASSERT(DT_WARN_GE, ge, __VA_ARGS__)
2465#define DOCTEST_CHECK_GE(...) DOCTEST_BINARY_ASSERT(DT_CHECK_GE, ge, __VA_ARGS__)
2466#define DOCTEST_REQUIRE_GE(...) DOCTEST_BINARY_ASSERT(DT_REQUIRE_GE, ge, __VA_ARGS__)
2467#define DOCTEST_WARN_LE(...) DOCTEST_BINARY_ASSERT(DT_WARN_LE, le, __VA_ARGS__)
2468#define DOCTEST_CHECK_LE(...) DOCTEST_BINARY_ASSERT(DT_CHECK_LE, le, __VA_ARGS__)
2469#define DOCTEST_REQUIRE_LE(...) DOCTEST_BINARY_ASSERT(DT_REQUIRE_LE, le, __VA_ARGS__)
2470
2471#define DOCTEST_WARN_UNARY(...) DOCTEST_UNARY_ASSERT(DT_WARN_UNARY, __VA_ARGS__)
2472#define DOCTEST_CHECK_UNARY(...) DOCTEST_UNARY_ASSERT(DT_CHECK_UNARY, __VA_ARGS__)
2473#define DOCTEST_REQUIRE_UNARY(...) DOCTEST_UNARY_ASSERT(DT_REQUIRE_UNARY, __VA_ARGS__)
2474#define DOCTEST_WARN_UNARY_FALSE(...) DOCTEST_UNARY_ASSERT(DT_WARN_UNARY_FALSE, __VA_ARGS__)
2475#define DOCTEST_CHECK_UNARY_FALSE(...) DOCTEST_UNARY_ASSERT(DT_CHECK_UNARY_FALSE, __VA_ARGS__)
2476#define DOCTEST_REQUIRE_UNARY_FALSE(...) DOCTEST_UNARY_ASSERT(DT_REQUIRE_UNARY_FALSE, __VA_ARGS__)
2477
2478#ifndef DOCTEST_CONFIG_NO_EXCEPTIONS
2479
2480#define DOCTEST_ASSERT_THROWS_AS(expr, assert_type, message, ...) \
2481 DOCTEST_FUNC_SCOPE_BEGIN { \
2482 if(!doctest::getContextOptions()->no_throw) { \
2483 doctest::detail::ResultBuilder DOCTEST_RB(doctest::assertType::assert_type, __FILE__, \
2484 __LINE__, #expr, #__VA_ARGS__, message); \
2485 try { \
2486 DOCTEST_CAST_TO_VOID(expr) \
2487 } catch(const typename doctest::detail::types::remove_const< \
2488 typename doctest::detail::types::remove_reference<__VA_ARGS__>::type>::type&) {\
2489 DOCTEST_RB.translateException(); \
2490 DOCTEST_RB.m_threw_as = true; \
2491 } catch(...) { DOCTEST_RB.translateException(); } \
2492 DOCTEST_ASSERT_LOG_REACT_RETURN(DOCTEST_RB); \
2493 } else { /* NOLINT(*-else-after-return) */ \
2494 DOCTEST_FUNC_SCOPE_RET(false); \
2495 } \
2496 } DOCTEST_FUNC_SCOPE_END
2497
2498#define DOCTEST_ASSERT_THROWS_WITH(expr, expr_str, assert_type, ...) \
2499 DOCTEST_FUNC_SCOPE_BEGIN { \
2500 if(!doctest::getContextOptions()->no_throw) { \
2501 doctest::detail::ResultBuilder DOCTEST_RB(doctest::assertType::assert_type, __FILE__, \
2502 __LINE__, expr_str, "", __VA_ARGS__); \
2503 try { \
2504 DOCTEST_CAST_TO_VOID(expr) \
2505 } catch(...) { DOCTEST_RB.translateException(); } \
2506 DOCTEST_ASSERT_LOG_REACT_RETURN(DOCTEST_RB); \
2507 } else { /* NOLINT(*-else-after-return) */ \
2508 DOCTEST_FUNC_SCOPE_RET(false); \
2509 } \
2510 } DOCTEST_FUNC_SCOPE_END
2511
2512#define DOCTEST_ASSERT_NOTHROW(assert_type, ...) \
2513 DOCTEST_FUNC_SCOPE_BEGIN { \
2514 doctest::detail::ResultBuilder DOCTEST_RB(doctest::assertType::assert_type, __FILE__, \
2515 __LINE__, #__VA_ARGS__); \
2516 try { \
2517 DOCTEST_CAST_TO_VOID(__VA_ARGS__) \
2518 } catch(...) { DOCTEST_RB.translateException(); } \
2519 DOCTEST_ASSERT_LOG_REACT_RETURN(DOCTEST_RB); \
2520 } DOCTEST_FUNC_SCOPE_END
2521
2522// clang-format off
2523#define DOCTEST_WARN_THROWS(...) DOCTEST_ASSERT_THROWS_WITH((__VA_ARGS__), #__VA_ARGS__, DT_WARN_THROWS, "")
2524#define DOCTEST_CHECK_THROWS(...) DOCTEST_ASSERT_THROWS_WITH((__VA_ARGS__), #__VA_ARGS__, DT_CHECK_THROWS, "")
2525#define DOCTEST_REQUIRE_THROWS(...) DOCTEST_ASSERT_THROWS_WITH((__VA_ARGS__), #__VA_ARGS__, DT_REQUIRE_THROWS, "")
2526
2527#define DOCTEST_WARN_THROWS_AS(expr, ...) DOCTEST_ASSERT_THROWS_AS(expr, DT_WARN_THROWS_AS, "", __VA_ARGS__)
2528#define DOCTEST_CHECK_THROWS_AS(expr, ...) DOCTEST_ASSERT_THROWS_AS(expr, DT_CHECK_THROWS_AS, "", __VA_ARGS__)
2529#define DOCTEST_REQUIRE_THROWS_AS(expr, ...) DOCTEST_ASSERT_THROWS_AS(expr, DT_REQUIRE_THROWS_AS, "", __VA_ARGS__)
2530
2531#define DOCTEST_WARN_THROWS_WITH(expr, ...) DOCTEST_ASSERT_THROWS_WITH(expr, #expr, DT_WARN_THROWS_WITH, __VA_ARGS__)
2532#define DOCTEST_CHECK_THROWS_WITH(expr, ...) DOCTEST_ASSERT_THROWS_WITH(expr, #expr, DT_CHECK_THROWS_WITH, __VA_ARGS__)
2533#define DOCTEST_REQUIRE_THROWS_WITH(expr, ...) DOCTEST_ASSERT_THROWS_WITH(expr, #expr, DT_REQUIRE_THROWS_WITH, __VA_ARGS__)
2534
2535#define DOCTEST_WARN_THROWS_WITH_AS(expr, message, ...) DOCTEST_ASSERT_THROWS_AS(expr, DT_WARN_THROWS_WITH_AS, message, __VA_ARGS__)
2536#define DOCTEST_CHECK_THROWS_WITH_AS(expr, message, ...) DOCTEST_ASSERT_THROWS_AS(expr, DT_CHECK_THROWS_WITH_AS, message, __VA_ARGS__)
2537#define DOCTEST_REQUIRE_THROWS_WITH_AS(expr, message, ...) DOCTEST_ASSERT_THROWS_AS(expr, DT_REQUIRE_THROWS_WITH_AS, message, __VA_ARGS__)
2538
2539#define DOCTEST_WARN_NOTHROW(...) DOCTEST_ASSERT_NOTHROW(DT_WARN_NOTHROW, __VA_ARGS__)
2540#define DOCTEST_CHECK_NOTHROW(...) DOCTEST_ASSERT_NOTHROW(DT_CHECK_NOTHROW, __VA_ARGS__)
2541#define DOCTEST_REQUIRE_NOTHROW(...) DOCTEST_ASSERT_NOTHROW(DT_REQUIRE_NOTHROW, __VA_ARGS__)
2542
2543#define DOCTEST_WARN_THROWS_MESSAGE(expr, ...) DOCTEST_FUNC_SCOPE_BEGIN { DOCTEST_INFO(__VA_ARGS__); DOCTEST_WARN_THROWS(expr); } DOCTEST_FUNC_SCOPE_END
2544#define DOCTEST_CHECK_THROWS_MESSAGE(expr, ...) DOCTEST_FUNC_SCOPE_BEGIN { DOCTEST_INFO(__VA_ARGS__); DOCTEST_CHECK_THROWS(expr); } DOCTEST_FUNC_SCOPE_END
2545#define DOCTEST_REQUIRE_THROWS_MESSAGE(expr, ...) DOCTEST_FUNC_SCOPE_BEGIN { DOCTEST_INFO(__VA_ARGS__); DOCTEST_REQUIRE_THROWS(expr); } DOCTEST_FUNC_SCOPE_END
2546#define DOCTEST_WARN_THROWS_AS_MESSAGE(expr, ex, ...) DOCTEST_FUNC_SCOPE_BEGIN { DOCTEST_INFO(__VA_ARGS__); DOCTEST_WARN_THROWS_AS(expr, ex); } DOCTEST_FUNC_SCOPE_END
2547#define DOCTEST_CHECK_THROWS_AS_MESSAGE(expr, ex, ...) DOCTEST_FUNC_SCOPE_BEGIN { DOCTEST_INFO(__VA_ARGS__); DOCTEST_CHECK_THROWS_AS(expr, ex); } DOCTEST_FUNC_SCOPE_END
2548#define DOCTEST_REQUIRE_THROWS_AS_MESSAGE(expr, ex, ...) DOCTEST_FUNC_SCOPE_BEGIN { DOCTEST_INFO(__VA_ARGS__); DOCTEST_REQUIRE_THROWS_AS(expr, ex); } DOCTEST_FUNC_SCOPE_END
2549#define DOCTEST_WARN_THROWS_WITH_MESSAGE(expr, with, ...) DOCTEST_FUNC_SCOPE_BEGIN { DOCTEST_INFO(__VA_ARGS__); DOCTEST_WARN_THROWS_WITH(expr, with); } DOCTEST_FUNC_SCOPE_END
2550#define DOCTEST_CHECK_THROWS_WITH_MESSAGE(expr, with, ...) DOCTEST_FUNC_SCOPE_BEGIN { DOCTEST_INFO(__VA_ARGS__); DOCTEST_CHECK_THROWS_WITH(expr, with); } DOCTEST_FUNC_SCOPE_END
2551#define DOCTEST_REQUIRE_THROWS_WITH_MESSAGE(expr, with, ...) DOCTEST_FUNC_SCOPE_BEGIN { DOCTEST_INFO(__VA_ARGS__); DOCTEST_REQUIRE_THROWS_WITH(expr, with); } DOCTEST_FUNC_SCOPE_END
2552#define DOCTEST_WARN_THROWS_WITH_AS_MESSAGE(expr, with, ex, ...) DOCTEST_FUNC_SCOPE_BEGIN { DOCTEST_INFO(__VA_ARGS__); DOCTEST_WARN_THROWS_WITH_AS(expr, with, ex); } DOCTEST_FUNC_SCOPE_END
2553#define DOCTEST_CHECK_THROWS_WITH_AS_MESSAGE(expr, with, ex, ...) DOCTEST_FUNC_SCOPE_BEGIN { DOCTEST_INFO(__VA_ARGS__); DOCTEST_CHECK_THROWS_WITH_AS(expr, with, ex); } DOCTEST_FUNC_SCOPE_END
2554#define DOCTEST_REQUIRE_THROWS_WITH_AS_MESSAGE(expr, with, ex, ...) DOCTEST_FUNC_SCOPE_BEGIN { DOCTEST_INFO(__VA_ARGS__); DOCTEST_REQUIRE_THROWS_WITH_AS(expr, with, ex); } DOCTEST_FUNC_SCOPE_END
2555#define DOCTEST_WARN_NOTHROW_MESSAGE(expr, ...) DOCTEST_FUNC_SCOPE_BEGIN { DOCTEST_INFO(__VA_ARGS__); DOCTEST_WARN_NOTHROW(expr); } DOCTEST_FUNC_SCOPE_END
2556#define DOCTEST_CHECK_NOTHROW_MESSAGE(expr, ...) DOCTEST_FUNC_SCOPE_BEGIN { DOCTEST_INFO(__VA_ARGS__); DOCTEST_CHECK_NOTHROW(expr); } DOCTEST_FUNC_SCOPE_END
2557#define DOCTEST_REQUIRE_NOTHROW_MESSAGE(expr, ...) DOCTEST_FUNC_SCOPE_BEGIN { DOCTEST_INFO(__VA_ARGS__); DOCTEST_REQUIRE_NOTHROW(expr); } DOCTEST_FUNC_SCOPE_END
2558// clang-format on
2559
2560#endif // DOCTEST_CONFIG_NO_EXCEPTIONS
2561
2562// =================================================================================================
2563// == WHAT FOLLOWS IS VERSIONS OF THE MACROS THAT DO NOT DO ANY REGISTERING! ==
2564// == THIS CAN BE ENABLED BY DEFINING DOCTEST_CONFIG_DISABLE GLOBALLY! ==
2565// =================================================================================================
2566#else // DOCTEST_CONFIG_DISABLE
2567
2568#define DOCTEST_IMPLEMENT_FIXTURE(der, base, func, name) \
2569 namespace /* NOLINT */ { \
2570 template <typename DOCTEST_UNUSED_TEMPLATE_TYPE> \
2571 struct der : public base \
2572 { void f(); }; \
2573 } \
2574 template <typename DOCTEST_UNUSED_TEMPLATE_TYPE> \
2575 inline void der<DOCTEST_UNUSED_TEMPLATE_TYPE>::f()
2576
2577#define DOCTEST_CREATE_AND_REGISTER_FUNCTION(f, name) \
2578 template <typename DOCTEST_UNUSED_TEMPLATE_TYPE> \
2579 static inline void f()
2580
2581// for registering tests
2582#define DOCTEST_TEST_CASE(name) \
2583 DOCTEST_CREATE_AND_REGISTER_FUNCTION(DOCTEST_ANONYMOUS(DOCTEST_ANON_FUNC_), name)
2584
2585// for registering tests in classes
2586#define DOCTEST_TEST_CASE_CLASS(name) \
2587 DOCTEST_CREATE_AND_REGISTER_FUNCTION(DOCTEST_ANONYMOUS(DOCTEST_ANON_FUNC_), name)
2588
2589// for registering tests with a fixture
2590#define DOCTEST_TEST_CASE_FIXTURE(x, name) \
2591 DOCTEST_IMPLEMENT_FIXTURE(DOCTEST_ANONYMOUS(DOCTEST_ANON_CLASS_), x, \
2592 DOCTEST_ANONYMOUS(DOCTEST_ANON_FUNC_), name)
2593
2594// for converting types to strings without the <typeinfo> header and demangling
2595#define DOCTEST_TYPE_TO_STRING_AS(str, ...) static_assert(true, "")
2596#define DOCTEST_TYPE_TO_STRING(...) static_assert(true, "")
2597
2598// for typed tests
2599#define DOCTEST_TEST_CASE_TEMPLATE(name, type, ...) \
2600 template <typename type> \
2601 inline void DOCTEST_ANONYMOUS(DOCTEST_ANON_TMP_)()
2602
2603#define DOCTEST_TEST_CASE_TEMPLATE_DEFINE(name, type, id) \
2604 template <typename type> \
2605 inline void DOCTEST_ANONYMOUS(DOCTEST_ANON_TMP_)()
2606
2607#define DOCTEST_TEST_CASE_TEMPLATE_INVOKE(id, ...) static_assert(true, "")
2608#define DOCTEST_TEST_CASE_TEMPLATE_APPLY(id, ...) static_assert(true, "")
2609
2610// for subcases
2611#define DOCTEST_SUBCASE(name)
2612
2613// for a testsuite block
2614#define DOCTEST_TEST_SUITE(name) namespace // NOLINT
2615
2616// for starting a testsuite block
2617#define DOCTEST_TEST_SUITE_BEGIN(name) static_assert(true, "")
2618
2619// for ending a testsuite block
2620#define DOCTEST_TEST_SUITE_END using DOCTEST_ANONYMOUS(DOCTEST_ANON_FOR_SEMICOLON_) = int
2621
2622#define DOCTEST_REGISTER_EXCEPTION_TRANSLATOR(signature) \
2623 template <typename DOCTEST_UNUSED_TEMPLATE_TYPE> \
2624 static inline doctest::String DOCTEST_ANONYMOUS(DOCTEST_ANON_TRANSLATOR_)(signature)
2625
2626#define DOCTEST_REGISTER_REPORTER(name, priority, reporter)
2627#define DOCTEST_REGISTER_LISTENER(name, priority, reporter)
2628
2629#define DOCTEST_INFO(...) (static_cast<void>(0))
2630#define DOCTEST_CAPTURE(x) (static_cast<void>(0))
2631#define DOCTEST_ADD_MESSAGE_AT(file, line, ...) (static_cast<void>(0))
2632#define DOCTEST_ADD_FAIL_CHECK_AT(file, line, ...) (static_cast<void>(0))
2633#define DOCTEST_ADD_FAIL_AT(file, line, ...) (static_cast<void>(0))
2634#define DOCTEST_MESSAGE(...) (static_cast<void>(0))
2635#define DOCTEST_FAIL_CHECK(...) (static_cast<void>(0))
2636#define DOCTEST_FAIL(...) (static_cast<void>(0))
2637
2638#if defined(DOCTEST_CONFIG_EVALUATE_ASSERTS_EVEN_WHEN_DISABLED) \
2639 && defined(DOCTEST_CONFIG_ASSERTS_RETURN_VALUES)
2640
2641#define DOCTEST_WARN(...) [&] { return __VA_ARGS__; }()
2642#define DOCTEST_CHECK(...) [&] { return __VA_ARGS__; }()
2643#define DOCTEST_REQUIRE(...) [&] { return __VA_ARGS__; }()
2644#define DOCTEST_WARN_FALSE(...) [&] { return !(__VA_ARGS__); }()
2645#define DOCTEST_CHECK_FALSE(...) [&] { return !(__VA_ARGS__); }()
2646#define DOCTEST_REQUIRE_FALSE(...) [&] { return !(__VA_ARGS__); }()
2647
2648#define DOCTEST_WARN_MESSAGE(cond, ...) [&] { return cond; }()
2649#define DOCTEST_CHECK_MESSAGE(cond, ...) [&] { return cond; }()
2650#define DOCTEST_REQUIRE_MESSAGE(cond, ...) [&] { return cond; }()
2651#define DOCTEST_WARN_FALSE_MESSAGE(cond, ...) [&] { return !(cond); }()
2652#define DOCTEST_CHECK_FALSE_MESSAGE(cond, ...) [&] { return !(cond); }()
2653#define DOCTEST_REQUIRE_FALSE_MESSAGE(cond, ...) [&] { return !(cond); }()
2654
2655namespace doctest {
2656namespace detail {
2657#define DOCTEST_RELATIONAL_OP(name, op) \
2658 template <typename L, typename R> \
2659 bool name(const DOCTEST_REF_WRAP(L) lhs, const DOCTEST_REF_WRAP(R) rhs) { return lhs op rhs; }
2660
2661 DOCTEST_RELATIONAL_OP(eq, ==)
2662 DOCTEST_RELATIONAL_OP(ne, !=)
2663 DOCTEST_RELATIONAL_OP(lt, <)
2664 DOCTEST_RELATIONAL_OP(gt, >)
2665 DOCTEST_RELATIONAL_OP(le, <=)
2666 DOCTEST_RELATIONAL_OP(ge, >=)
2667} // namespace detail
2668} // namespace doctest
2669
2670#define DOCTEST_WARN_EQ(...) [&] { return doctest::detail::eq(__VA_ARGS__); }()
2671#define DOCTEST_CHECK_EQ(...) [&] { return doctest::detail::eq(__VA_ARGS__); }()
2672#define DOCTEST_REQUIRE_EQ(...) [&] { return doctest::detail::eq(__VA_ARGS__); }()
2673#define DOCTEST_WARN_NE(...) [&] { return doctest::detail::ne(__VA_ARGS__); }()
2674#define DOCTEST_CHECK_NE(...) [&] { return doctest::detail::ne(__VA_ARGS__); }()
2675#define DOCTEST_REQUIRE_NE(...) [&] { return doctest::detail::ne(__VA_ARGS__); }()
2676#define DOCTEST_WARN_LT(...) [&] { return doctest::detail::lt(__VA_ARGS__); }()
2677#define DOCTEST_CHECK_LT(...) [&] { return doctest::detail::lt(__VA_ARGS__); }()
2678#define DOCTEST_REQUIRE_LT(...) [&] { return doctest::detail::lt(__VA_ARGS__); }()
2679#define DOCTEST_WARN_GT(...) [&] { return doctest::detail::gt(__VA_ARGS__); }()
2680#define DOCTEST_CHECK_GT(...) [&] { return doctest::detail::gt(__VA_ARGS__); }()
2681#define DOCTEST_REQUIRE_GT(...) [&] { return doctest::detail::gt(__VA_ARGS__); }()
2682#define DOCTEST_WARN_LE(...) [&] { return doctest::detail::le(__VA_ARGS__); }()
2683#define DOCTEST_CHECK_LE(...) [&] { return doctest::detail::le(__VA_ARGS__); }()
2684#define DOCTEST_REQUIRE_LE(...) [&] { return doctest::detail::le(__VA_ARGS__); }()
2685#define DOCTEST_WARN_GE(...) [&] { return doctest::detail::ge(__VA_ARGS__); }()
2686#define DOCTEST_CHECK_GE(...) [&] { return doctest::detail::ge(__VA_ARGS__); }()
2687#define DOCTEST_REQUIRE_GE(...) [&] { return doctest::detail::ge(__VA_ARGS__); }()
2688#define DOCTEST_WARN_UNARY(...) [&] { return __VA_ARGS__; }()
2689#define DOCTEST_CHECK_UNARY(...) [&] { return __VA_ARGS__; }()
2690#define DOCTEST_REQUIRE_UNARY(...) [&] { return __VA_ARGS__; }()
2691#define DOCTEST_WARN_UNARY_FALSE(...) [&] { return !(__VA_ARGS__); }()
2692#define DOCTEST_CHECK_UNARY_FALSE(...) [&] { return !(__VA_ARGS__); }()
2693#define DOCTEST_REQUIRE_UNARY_FALSE(...) [&] { return !(__VA_ARGS__); }()
2694
2695#ifndef DOCTEST_CONFIG_NO_EXCEPTIONS
2696
2697#define DOCTEST_WARN_THROWS_WITH(expr, with, ...) [] { static_assert(false, "Exception translation is not available when doctest is disabled."); return false; }()
2698#define DOCTEST_CHECK_THROWS_WITH(expr, with, ...) DOCTEST_WARN_THROWS_WITH(,,)
2699#define DOCTEST_REQUIRE_THROWS_WITH(expr, with, ...) DOCTEST_WARN_THROWS_WITH(,,)
2700#define DOCTEST_WARN_THROWS_WITH_AS(expr, with, ex, ...) DOCTEST_WARN_THROWS_WITH(,,)
2701#define DOCTEST_CHECK_THROWS_WITH_AS(expr, with, ex, ...) DOCTEST_WARN_THROWS_WITH(,,)
2702#define DOCTEST_REQUIRE_THROWS_WITH_AS(expr, with, ex, ...) DOCTEST_WARN_THROWS_WITH(,,)
2703
2704#define DOCTEST_WARN_THROWS_WITH_MESSAGE(expr, with, ...) DOCTEST_WARN_THROWS_WITH(,,)
2705#define DOCTEST_CHECK_THROWS_WITH_MESSAGE(expr, with, ...) DOCTEST_WARN_THROWS_WITH(,,)
2706#define DOCTEST_REQUIRE_THROWS_WITH_MESSAGE(expr, with, ...) DOCTEST_WARN_THROWS_WITH(,,)
2707#define DOCTEST_WARN_THROWS_WITH_AS_MESSAGE(expr, with, ex, ...) DOCTEST_WARN_THROWS_WITH(,,)
2708#define DOCTEST_CHECK_THROWS_WITH_AS_MESSAGE(expr, with, ex, ...) DOCTEST_WARN_THROWS_WITH(,,)
2709#define DOCTEST_REQUIRE_THROWS_WITH_AS_MESSAGE(expr, with, ex, ...) DOCTEST_WARN_THROWS_WITH(,,)
2710
2711#define DOCTEST_WARN_THROWS(...) [&] { try { __VA_ARGS__; return false; } catch (...) { return true; } }()
2712#define DOCTEST_CHECK_THROWS(...) [&] { try { __VA_ARGS__; return false; } catch (...) { return true; } }()
2713#define DOCTEST_REQUIRE_THROWS(...) [&] { try { __VA_ARGS__; return false; } catch (...) { return true; } }()
2714#define DOCTEST_WARN_THROWS_AS(expr, ...) [&] { try { expr; } catch (__VA_ARGS__) { return true; } catch (...) { } return false; }()
2715#define DOCTEST_CHECK_THROWS_AS(expr, ...) [&] { try { expr; } catch (__VA_ARGS__) { return true; } catch (...) { } return false; }()
2716#define DOCTEST_REQUIRE_THROWS_AS(expr, ...) [&] { try { expr; } catch (__VA_ARGS__) { return true; } catch (...) { } return false; }()
2717#define DOCTEST_WARN_NOTHROW(...) [&] { try { __VA_ARGS__; return true; } catch (...) { return false; } }()
2718#define DOCTEST_CHECK_NOTHROW(...) [&] { try { __VA_ARGS__; return true; } catch (...) { return false; } }()
2719#define DOCTEST_REQUIRE_NOTHROW(...) [&] { try { __VA_ARGS__; return true; } catch (...) { return false; } }()
2720
2721#define DOCTEST_WARN_THROWS_MESSAGE(expr, ...) [&] { try { __VA_ARGS__; return false; } catch (...) { return true; } }()
2722#define DOCTEST_CHECK_THROWS_MESSAGE(expr, ...) [&] { try { __VA_ARGS__; return false; } catch (...) { return true; } }()
2723#define DOCTEST_REQUIRE_THROWS_MESSAGE(expr, ...) [&] { try { __VA_ARGS__; return false; } catch (...) { return true; } }()
2724#define DOCTEST_WARN_THROWS_AS_MESSAGE(expr, ex, ...) [&] { try { expr; } catch (__VA_ARGS__) { return true; } catch (...) { } return false; }()
2725#define DOCTEST_CHECK_THROWS_AS_MESSAGE(expr, ex, ...) [&] { try { expr; } catch (__VA_ARGS__) { return true; } catch (...) { } return false; }()
2726#define DOCTEST_REQUIRE_THROWS_AS_MESSAGE(expr, ex, ...) [&] { try { expr; } catch (__VA_ARGS__) { return true; } catch (...) { } return false; }()
2727#define DOCTEST_WARN_NOTHROW_MESSAGE(expr, ...) [&] { try { __VA_ARGS__; return true; } catch (...) { return false; } }()
2728#define DOCTEST_CHECK_NOTHROW_MESSAGE(expr, ...) [&] { try { __VA_ARGS__; return true; } catch (...) { return false; } }()
2729#define DOCTEST_REQUIRE_NOTHROW_MESSAGE(expr, ...) [&] { try { __VA_ARGS__; return true; } catch (...) { return false; } }()
2730
2731#endif // DOCTEST_CONFIG_NO_EXCEPTIONS
2732
2733#else // DOCTEST_CONFIG_EVALUATE_ASSERTS_EVEN_WHEN_DISABLED
2734
2735#define DOCTEST_WARN(...) DOCTEST_FUNC_EMPTY
2736#define DOCTEST_CHECK(...) DOCTEST_FUNC_EMPTY
2737#define DOCTEST_REQUIRE(...) DOCTEST_FUNC_EMPTY
2738#define DOCTEST_WARN_FALSE(...) DOCTEST_FUNC_EMPTY
2739#define DOCTEST_CHECK_FALSE(...) DOCTEST_FUNC_EMPTY
2740#define DOCTEST_REQUIRE_FALSE(...) DOCTEST_FUNC_EMPTY
2741
2742#define DOCTEST_WARN_MESSAGE(cond, ...) DOCTEST_FUNC_EMPTY
2743#define DOCTEST_CHECK_MESSAGE(cond, ...) DOCTEST_FUNC_EMPTY
2744#define DOCTEST_REQUIRE_MESSAGE(cond, ...) DOCTEST_FUNC_EMPTY
2745#define DOCTEST_WARN_FALSE_MESSAGE(cond, ...) DOCTEST_FUNC_EMPTY
2746#define DOCTEST_CHECK_FALSE_MESSAGE(cond, ...) DOCTEST_FUNC_EMPTY
2747#define DOCTEST_REQUIRE_FALSE_MESSAGE(cond, ...) DOCTEST_FUNC_EMPTY
2748
2749#define DOCTEST_WARN_EQ(...) DOCTEST_FUNC_EMPTY
2750#define DOCTEST_CHECK_EQ(...) DOCTEST_FUNC_EMPTY
2751#define DOCTEST_REQUIRE_EQ(...) DOCTEST_FUNC_EMPTY
2752#define DOCTEST_WARN_NE(...) DOCTEST_FUNC_EMPTY
2753#define DOCTEST_CHECK_NE(...) DOCTEST_FUNC_EMPTY
2754#define DOCTEST_REQUIRE_NE(...) DOCTEST_FUNC_EMPTY
2755#define DOCTEST_WARN_GT(...) DOCTEST_FUNC_EMPTY
2756#define DOCTEST_CHECK_GT(...) DOCTEST_FUNC_EMPTY
2757#define DOCTEST_REQUIRE_GT(...) DOCTEST_FUNC_EMPTY
2758#define DOCTEST_WARN_LT(...) DOCTEST_FUNC_EMPTY
2759#define DOCTEST_CHECK_LT(...) DOCTEST_FUNC_EMPTY
2760#define DOCTEST_REQUIRE_LT(...) DOCTEST_FUNC_EMPTY
2761#define DOCTEST_WARN_GE(...) DOCTEST_FUNC_EMPTY
2762#define DOCTEST_CHECK_GE(...) DOCTEST_FUNC_EMPTY
2763#define DOCTEST_REQUIRE_GE(...) DOCTEST_FUNC_EMPTY
2764#define DOCTEST_WARN_LE(...) DOCTEST_FUNC_EMPTY
2765#define DOCTEST_CHECK_LE(...) DOCTEST_FUNC_EMPTY
2766#define DOCTEST_REQUIRE_LE(...) DOCTEST_FUNC_EMPTY
2767
2768#define DOCTEST_WARN_UNARY(...) DOCTEST_FUNC_EMPTY
2769#define DOCTEST_CHECK_UNARY(...) DOCTEST_FUNC_EMPTY
2770#define DOCTEST_REQUIRE_UNARY(...) DOCTEST_FUNC_EMPTY
2771#define DOCTEST_WARN_UNARY_FALSE(...) DOCTEST_FUNC_EMPTY
2772#define DOCTEST_CHECK_UNARY_FALSE(...) DOCTEST_FUNC_EMPTY
2773#define DOCTEST_REQUIRE_UNARY_FALSE(...) DOCTEST_FUNC_EMPTY
2774
2775#ifndef DOCTEST_CONFIG_NO_EXCEPTIONS
2776
2777#define DOCTEST_WARN_THROWS(...) DOCTEST_FUNC_EMPTY
2778#define DOCTEST_CHECK_THROWS(...) DOCTEST_FUNC_EMPTY
2779#define DOCTEST_REQUIRE_THROWS(...) DOCTEST_FUNC_EMPTY
2780#define DOCTEST_WARN_THROWS_AS(expr, ...) DOCTEST_FUNC_EMPTY
2781#define DOCTEST_CHECK_THROWS_AS(expr, ...) DOCTEST_FUNC_EMPTY
2782#define DOCTEST_REQUIRE_THROWS_AS(expr, ...) DOCTEST_FUNC_EMPTY
2783#define DOCTEST_WARN_THROWS_WITH(expr, ...) DOCTEST_FUNC_EMPTY
2784#define DOCTEST_CHECK_THROWS_WITH(expr, ...) DOCTEST_FUNC_EMPTY
2785#define DOCTEST_REQUIRE_THROWS_WITH(expr, ...) DOCTEST_FUNC_EMPTY
2786#define DOCTEST_WARN_THROWS_WITH_AS(expr, with, ...) DOCTEST_FUNC_EMPTY
2787#define DOCTEST_CHECK_THROWS_WITH_AS(expr, with, ...) DOCTEST_FUNC_EMPTY
2788#define DOCTEST_REQUIRE_THROWS_WITH_AS(expr, with, ...) DOCTEST_FUNC_EMPTY
2789#define DOCTEST_WARN_NOTHROW(...) DOCTEST_FUNC_EMPTY
2790#define DOCTEST_CHECK_NOTHROW(...) DOCTEST_FUNC_EMPTY
2791#define DOCTEST_REQUIRE_NOTHROW(...) DOCTEST_FUNC_EMPTY
2792
2793#define DOCTEST_WARN_THROWS_MESSAGE(expr, ...) DOCTEST_FUNC_EMPTY
2794#define DOCTEST_CHECK_THROWS_MESSAGE(expr, ...) DOCTEST_FUNC_EMPTY
2795#define DOCTEST_REQUIRE_THROWS_MESSAGE(expr, ...) DOCTEST_FUNC_EMPTY
2796#define DOCTEST_WARN_THROWS_AS_MESSAGE(expr, ex, ...) DOCTEST_FUNC_EMPTY
2797#define DOCTEST_CHECK_THROWS_AS_MESSAGE(expr, ex, ...) DOCTEST_FUNC_EMPTY
2798#define DOCTEST_REQUIRE_THROWS_AS_MESSAGE(expr, ex, ...) DOCTEST_FUNC_EMPTY
2799#define DOCTEST_WARN_THROWS_WITH_MESSAGE(expr, with, ...) DOCTEST_FUNC_EMPTY
2800#define DOCTEST_CHECK_THROWS_WITH_MESSAGE(expr, with, ...) DOCTEST_FUNC_EMPTY
2801#define DOCTEST_REQUIRE_THROWS_WITH_MESSAGE(expr, with, ...) DOCTEST_FUNC_EMPTY
2802#define DOCTEST_WARN_THROWS_WITH_AS_MESSAGE(expr, with, ex, ...) DOCTEST_FUNC_EMPTY
2803#define DOCTEST_CHECK_THROWS_WITH_AS_MESSAGE(expr, with, ex, ...) DOCTEST_FUNC_EMPTY
2804#define DOCTEST_REQUIRE_THROWS_WITH_AS_MESSAGE(expr, with, ex, ...) DOCTEST_FUNC_EMPTY
2805#define DOCTEST_WARN_NOTHROW_MESSAGE(expr, ...) DOCTEST_FUNC_EMPTY
2806#define DOCTEST_CHECK_NOTHROW_MESSAGE(expr, ...) DOCTEST_FUNC_EMPTY
2807#define DOCTEST_REQUIRE_NOTHROW_MESSAGE(expr, ...) DOCTEST_FUNC_EMPTY
2808
2809#endif // DOCTEST_CONFIG_NO_EXCEPTIONS
2810
2811#endif // DOCTEST_CONFIG_EVALUATE_ASSERTS_EVEN_WHEN_DISABLED
2812
2813#endif // DOCTEST_CONFIG_DISABLE
2814
2815#ifdef DOCTEST_CONFIG_NO_EXCEPTIONS
2816
2817#ifdef DOCTEST_CONFIG_NO_EXCEPTIONS_BUT_WITH_ALL_ASSERTS
2818#define DOCTEST_EXCEPTION_EMPTY_FUNC DOCTEST_FUNC_EMPTY
2819#else // DOCTEST_CONFIG_NO_EXCEPTIONS_BUT_WITH_ALL_ASSERTS
2820#define DOCTEST_EXCEPTION_EMPTY_FUNC [] { static_assert(false, "Exceptions are disabled! " \
2821 "Use DOCTEST_CONFIG_NO_EXCEPTIONS_BUT_WITH_ALL_ASSERTS if you want to compile with exceptions disabled."); return false; }()
2822
2823#undef DOCTEST_REQUIRE
2824#undef DOCTEST_REQUIRE_FALSE
2825#undef DOCTEST_REQUIRE_MESSAGE
2826#undef DOCTEST_REQUIRE_FALSE_MESSAGE
2827#undef DOCTEST_REQUIRE_EQ
2828#undef DOCTEST_REQUIRE_NE
2829#undef DOCTEST_REQUIRE_GT
2830#undef DOCTEST_REQUIRE_LT
2831#undef DOCTEST_REQUIRE_GE
2832#undef DOCTEST_REQUIRE_LE
2833#undef DOCTEST_REQUIRE_UNARY
2834#undef DOCTEST_REQUIRE_UNARY_FALSE
2835
2836#define DOCTEST_REQUIRE DOCTEST_EXCEPTION_EMPTY_FUNC
2837#define DOCTEST_REQUIRE_FALSE DOCTEST_EXCEPTION_EMPTY_FUNC
2838#define DOCTEST_REQUIRE_MESSAGE DOCTEST_EXCEPTION_EMPTY_FUNC
2839#define DOCTEST_REQUIRE_FALSE_MESSAGE DOCTEST_EXCEPTION_EMPTY_FUNC
2840#define DOCTEST_REQUIRE_EQ DOCTEST_EXCEPTION_EMPTY_FUNC
2841#define DOCTEST_REQUIRE_NE DOCTEST_EXCEPTION_EMPTY_FUNC
2842#define DOCTEST_REQUIRE_GT DOCTEST_EXCEPTION_EMPTY_FUNC
2843#define DOCTEST_REQUIRE_LT DOCTEST_EXCEPTION_EMPTY_FUNC
2844#define DOCTEST_REQUIRE_GE DOCTEST_EXCEPTION_EMPTY_FUNC
2845#define DOCTEST_REQUIRE_LE DOCTEST_EXCEPTION_EMPTY_FUNC
2846#define DOCTEST_REQUIRE_UNARY DOCTEST_EXCEPTION_EMPTY_FUNC
2847#define DOCTEST_REQUIRE_UNARY_FALSE DOCTEST_EXCEPTION_EMPTY_FUNC
2848
2849#endif // DOCTEST_CONFIG_NO_EXCEPTIONS_BUT_WITH_ALL_ASSERTS
2850
2851#define DOCTEST_WARN_THROWS(...) DOCTEST_EXCEPTION_EMPTY_FUNC
2852#define DOCTEST_CHECK_THROWS(...) DOCTEST_EXCEPTION_EMPTY_FUNC
2853#define DOCTEST_REQUIRE_THROWS(...) DOCTEST_EXCEPTION_EMPTY_FUNC
2854#define DOCTEST_WARN_THROWS_AS(expr, ...) DOCTEST_EXCEPTION_EMPTY_FUNC
2855#define DOCTEST_CHECK_THROWS_AS(expr, ...) DOCTEST_EXCEPTION_EMPTY_FUNC
2856#define DOCTEST_REQUIRE_THROWS_AS(expr, ...) DOCTEST_EXCEPTION_EMPTY_FUNC
2857#define DOCTEST_WARN_THROWS_WITH(expr, ...) DOCTEST_EXCEPTION_EMPTY_FUNC
2858#define DOCTEST_CHECK_THROWS_WITH(expr, ...) DOCTEST_EXCEPTION_EMPTY_FUNC
2859#define DOCTEST_REQUIRE_THROWS_WITH(expr, ...) DOCTEST_EXCEPTION_EMPTY_FUNC
2860#define DOCTEST_WARN_THROWS_WITH_AS(expr, with, ...) DOCTEST_EXCEPTION_EMPTY_FUNC
2861#define DOCTEST_CHECK_THROWS_WITH_AS(expr, with, ...) DOCTEST_EXCEPTION_EMPTY_FUNC
2862#define DOCTEST_REQUIRE_THROWS_WITH_AS(expr, with, ...) DOCTEST_EXCEPTION_EMPTY_FUNC
2863#define DOCTEST_WARN_NOTHROW(...) DOCTEST_EXCEPTION_EMPTY_FUNC
2864#define DOCTEST_CHECK_NOTHROW(...) DOCTEST_EXCEPTION_EMPTY_FUNC
2865#define DOCTEST_REQUIRE_NOTHROW(...) DOCTEST_EXCEPTION_EMPTY_FUNC
2866
2867#define DOCTEST_WARN_THROWS_MESSAGE(expr, ...) DOCTEST_EXCEPTION_EMPTY_FUNC
2868#define DOCTEST_CHECK_THROWS_MESSAGE(expr, ...) DOCTEST_EXCEPTION_EMPTY_FUNC
2869#define DOCTEST_REQUIRE_THROWS_MESSAGE(expr, ...) DOCTEST_EXCEPTION_EMPTY_FUNC
2870#define DOCTEST_WARN_THROWS_AS_MESSAGE(expr, ex, ...) DOCTEST_EXCEPTION_EMPTY_FUNC
2871#define DOCTEST_CHECK_THROWS_AS_MESSAGE(expr, ex, ...) DOCTEST_EXCEPTION_EMPTY_FUNC
2872#define DOCTEST_REQUIRE_THROWS_AS_MESSAGE(expr, ex, ...) DOCTEST_EXCEPTION_EMPTY_FUNC
2873#define DOCTEST_WARN_THROWS_WITH_MESSAGE(expr, with, ...) DOCTEST_EXCEPTION_EMPTY_FUNC
2874#define DOCTEST_CHECK_THROWS_WITH_MESSAGE(expr, with, ...) DOCTEST_EXCEPTION_EMPTY_FUNC
2875#define DOCTEST_REQUIRE_THROWS_WITH_MESSAGE(expr, with, ...) DOCTEST_EXCEPTION_EMPTY_FUNC
2876#define DOCTEST_WARN_THROWS_WITH_AS_MESSAGE(expr, with, ex, ...) DOCTEST_EXCEPTION_EMPTY_FUNC
2877#define DOCTEST_CHECK_THROWS_WITH_AS_MESSAGE(expr, with, ex, ...) DOCTEST_EXCEPTION_EMPTY_FUNC
2878#define DOCTEST_REQUIRE_THROWS_WITH_AS_MESSAGE(expr, with, ex, ...) DOCTEST_EXCEPTION_EMPTY_FUNC
2879#define DOCTEST_WARN_NOTHROW_MESSAGE(expr, ...) DOCTEST_EXCEPTION_EMPTY_FUNC
2880#define DOCTEST_CHECK_NOTHROW_MESSAGE(expr, ...) DOCTEST_EXCEPTION_EMPTY_FUNC
2881#define DOCTEST_REQUIRE_NOTHROW_MESSAGE(expr, ...) DOCTEST_EXCEPTION_EMPTY_FUNC
2882
2883#endif // DOCTEST_CONFIG_NO_EXCEPTIONS
2884
2885// clang-format off
2886// KEPT FOR BACKWARDS COMPATIBILITY - FORWARDING TO THE RIGHT MACROS
2887#define DOCTEST_FAST_WARN_EQ DOCTEST_WARN_EQ
2888#define DOCTEST_FAST_CHECK_EQ DOCTEST_CHECK_EQ
2889#define DOCTEST_FAST_REQUIRE_EQ DOCTEST_REQUIRE_EQ
2890#define DOCTEST_FAST_WARN_NE DOCTEST_WARN_NE
2891#define DOCTEST_FAST_CHECK_NE DOCTEST_CHECK_NE
2892#define DOCTEST_FAST_REQUIRE_NE DOCTEST_REQUIRE_NE
2893#define DOCTEST_FAST_WARN_GT DOCTEST_WARN_GT
2894#define DOCTEST_FAST_CHECK_GT DOCTEST_CHECK_GT
2895#define DOCTEST_FAST_REQUIRE_GT DOCTEST_REQUIRE_GT
2896#define DOCTEST_FAST_WARN_LT DOCTEST_WARN_LT
2897#define DOCTEST_FAST_CHECK_LT DOCTEST_CHECK_LT
2898#define DOCTEST_FAST_REQUIRE_LT DOCTEST_REQUIRE_LT
2899#define DOCTEST_FAST_WARN_GE DOCTEST_WARN_GE
2900#define DOCTEST_FAST_CHECK_GE DOCTEST_CHECK_GE
2901#define DOCTEST_FAST_REQUIRE_GE DOCTEST_REQUIRE_GE
2902#define DOCTEST_FAST_WARN_LE DOCTEST_WARN_LE
2903#define DOCTEST_FAST_CHECK_LE DOCTEST_CHECK_LE
2904#define DOCTEST_FAST_REQUIRE_LE DOCTEST_REQUIRE_LE
2905
2906#define DOCTEST_FAST_WARN_UNARY DOCTEST_WARN_UNARY
2907#define DOCTEST_FAST_CHECK_UNARY DOCTEST_CHECK_UNARY
2908#define DOCTEST_FAST_REQUIRE_UNARY DOCTEST_REQUIRE_UNARY
2909#define DOCTEST_FAST_WARN_UNARY_FALSE DOCTEST_WARN_UNARY_FALSE
2910#define DOCTEST_FAST_CHECK_UNARY_FALSE DOCTEST_CHECK_UNARY_FALSE
2911#define DOCTEST_FAST_REQUIRE_UNARY_FALSE DOCTEST_REQUIRE_UNARY_FALSE
2912
2913#define DOCTEST_TEST_CASE_TEMPLATE_INSTANTIATE(id, ...) DOCTEST_TEST_CASE_TEMPLATE_INVOKE(id,__VA_ARGS__)
2914// clang-format on
2915
2916// BDD style macros
2917// clang-format off
2918#define DOCTEST_SCENARIO(name) DOCTEST_TEST_CASE(" Scenario: " name)
2919#define DOCTEST_SCENARIO_CLASS(name) DOCTEST_TEST_CASE_CLASS(" Scenario: " name)
2920#define DOCTEST_SCENARIO_TEMPLATE(name, T, ...) DOCTEST_TEST_CASE_TEMPLATE(" Scenario: " name, T, __VA_ARGS__)
2921#define DOCTEST_SCENARIO_TEMPLATE_DEFINE(name, T, id) DOCTEST_TEST_CASE_TEMPLATE_DEFINE(" Scenario: " name, T, id)
2922
2923#define DOCTEST_GIVEN(name) DOCTEST_SUBCASE(" Given: " name)
2924#define DOCTEST_WHEN(name) DOCTEST_SUBCASE(" When: " name)
2925#define DOCTEST_AND_WHEN(name) DOCTEST_SUBCASE("And when: " name)
2926#define DOCTEST_THEN(name) DOCTEST_SUBCASE(" Then: " name)
2927#define DOCTEST_AND_THEN(name) DOCTEST_SUBCASE(" And: " name)
2928// clang-format on
2929
2930// == SHORT VERSIONS OF THE MACROS
2931#ifndef DOCTEST_CONFIG_NO_SHORT_MACRO_NAMES
2932
2933#define TEST_CASE(name) DOCTEST_TEST_CASE(name)
2934#define TEST_CASE_CLASS(name) DOCTEST_TEST_CASE_CLASS(name)
2935#define TEST_CASE_FIXTURE(x, name) DOCTEST_TEST_CASE_FIXTURE(x, name)
2936#define TYPE_TO_STRING_AS(str, ...) DOCTEST_TYPE_TO_STRING_AS(str, __VA_ARGS__)
2937#define TYPE_TO_STRING(...) DOCTEST_TYPE_TO_STRING(__VA_ARGS__)
2938#define TEST_CASE_TEMPLATE(name, T, ...) DOCTEST_TEST_CASE_TEMPLATE(name, T, __VA_ARGS__)
2939#define TEST_CASE_TEMPLATE_DEFINE(name, T, id) DOCTEST_TEST_CASE_TEMPLATE_DEFINE(name, T, id)
2940#define TEST_CASE_TEMPLATE_INVOKE(id, ...) DOCTEST_TEST_CASE_TEMPLATE_INVOKE(id, __VA_ARGS__)
2941#define TEST_CASE_TEMPLATE_APPLY(id, ...) DOCTEST_TEST_CASE_TEMPLATE_APPLY(id, __VA_ARGS__)
2942#define SUBCASE(name) DOCTEST_SUBCASE(name)
2943#define TEST_SUITE(decorators) DOCTEST_TEST_SUITE(decorators)
2944#define TEST_SUITE_BEGIN(name) DOCTEST_TEST_SUITE_BEGIN(name)
2945#define TEST_SUITE_END DOCTEST_TEST_SUITE_END
2946#define REGISTER_EXCEPTION_TRANSLATOR(signature) DOCTEST_REGISTER_EXCEPTION_TRANSLATOR(signature)
2947#define REGISTER_REPORTER(name, priority, reporter) DOCTEST_REGISTER_REPORTER(name, priority, reporter)
2948#define REGISTER_LISTENER(name, priority, reporter) DOCTEST_REGISTER_LISTENER(name, priority, reporter)
2949#define INFO(...) DOCTEST_INFO(__VA_ARGS__)
2950#define CAPTURE(x) DOCTEST_CAPTURE(x)
2951#define ADD_MESSAGE_AT(file, line, ...) DOCTEST_ADD_MESSAGE_AT(file, line, __VA_ARGS__)
2952#define ADD_FAIL_CHECK_AT(file, line, ...) DOCTEST_ADD_FAIL_CHECK_AT(file, line, __VA_ARGS__)
2953#define ADD_FAIL_AT(file, line, ...) DOCTEST_ADD_FAIL_AT(file, line, __VA_ARGS__)
2954#define MESSAGE(...) DOCTEST_MESSAGE(__VA_ARGS__)
2955#define FAIL_CHECK(...) DOCTEST_FAIL_CHECK(__VA_ARGS__)
2956#define FAIL(...) DOCTEST_FAIL(__VA_ARGS__)
2957#define TO_LVALUE(...) DOCTEST_TO_LVALUE(__VA_ARGS__)
2958
2959#define WARN(...) DOCTEST_WARN(__VA_ARGS__)
2960#define WARN_FALSE(...) DOCTEST_WARN_FALSE(__VA_ARGS__)
2961#define WARN_THROWS(...) DOCTEST_WARN_THROWS(__VA_ARGS__)
2962#define WARN_THROWS_AS(expr, ...) DOCTEST_WARN_THROWS_AS(expr, __VA_ARGS__)
2963#define WARN_THROWS_WITH(expr, ...) DOCTEST_WARN_THROWS_WITH(expr, __VA_ARGS__)
2964#define WARN_THROWS_WITH_AS(expr, with, ...) DOCTEST_WARN_THROWS_WITH_AS(expr, with, __VA_ARGS__)
2965#define WARN_NOTHROW(...) DOCTEST_WARN_NOTHROW(__VA_ARGS__)
2966#define CHECK(...) DOCTEST_CHECK(__VA_ARGS__)
2967#define CHECK_FALSE(...) DOCTEST_CHECK_FALSE(__VA_ARGS__)
2968#define CHECK_THROWS(...) DOCTEST_CHECK_THROWS(__VA_ARGS__)
2969#define CHECK_THROWS_AS(expr, ...) DOCTEST_CHECK_THROWS_AS(expr, __VA_ARGS__)
2970#define CHECK_THROWS_WITH(expr, ...) DOCTEST_CHECK_THROWS_WITH(expr, __VA_ARGS__)
2971#define CHECK_THROWS_WITH_AS(expr, with, ...) DOCTEST_CHECK_THROWS_WITH_AS(expr, with, __VA_ARGS__)
2972#define CHECK_NOTHROW(...) DOCTEST_CHECK_NOTHROW(__VA_ARGS__)
2973#define REQUIRE(...) DOCTEST_REQUIRE(__VA_ARGS__)
2974#define REQUIRE_FALSE(...) DOCTEST_REQUIRE_FALSE(__VA_ARGS__)
2975#define REQUIRE_THROWS(...) DOCTEST_REQUIRE_THROWS(__VA_ARGS__)
2976#define REQUIRE_THROWS_AS(expr, ...) DOCTEST_REQUIRE_THROWS_AS(expr, __VA_ARGS__)
2977#define REQUIRE_THROWS_WITH(expr, ...) DOCTEST_REQUIRE_THROWS_WITH(expr, __VA_ARGS__)
2978#define REQUIRE_THROWS_WITH_AS(expr, with, ...) DOCTEST_REQUIRE_THROWS_WITH_AS(expr, with, __VA_ARGS__)
2979#define REQUIRE_NOTHROW(...) DOCTEST_REQUIRE_NOTHROW(__VA_ARGS__)
2980
2981#define WARN_MESSAGE(cond, ...) DOCTEST_WARN_MESSAGE(cond, __VA_ARGS__)
2982#define WARN_FALSE_MESSAGE(cond, ...) DOCTEST_WARN_FALSE_MESSAGE(cond, __VA_ARGS__)
2983#define WARN_THROWS_MESSAGE(expr, ...) DOCTEST_WARN_THROWS_MESSAGE(expr, __VA_ARGS__)
2984#define WARN_THROWS_AS_MESSAGE(expr, ex, ...) DOCTEST_WARN_THROWS_AS_MESSAGE(expr, ex, __VA_ARGS__)
2985#define WARN_THROWS_WITH_MESSAGE(expr, with, ...) DOCTEST_WARN_THROWS_WITH_MESSAGE(expr, with, __VA_ARGS__)
2986#define WARN_THROWS_WITH_AS_MESSAGE(expr, with, ex, ...) DOCTEST_WARN_THROWS_WITH_AS_MESSAGE(expr, with, ex, __VA_ARGS__)
2987#define WARN_NOTHROW_MESSAGE(expr, ...) DOCTEST_WARN_NOTHROW_MESSAGE(expr, __VA_ARGS__)
2988#define CHECK_MESSAGE(cond, ...) DOCTEST_CHECK_MESSAGE(cond, __VA_ARGS__)
2989#define CHECK_FALSE_MESSAGE(cond, ...) DOCTEST_CHECK_FALSE_MESSAGE(cond, __VA_ARGS__)
2990#define CHECK_THROWS_MESSAGE(expr, ...) DOCTEST_CHECK_THROWS_MESSAGE(expr, __VA_ARGS__)
2991#define CHECK_THROWS_AS_MESSAGE(expr, ex, ...) DOCTEST_CHECK_THROWS_AS_MESSAGE(expr, ex, __VA_ARGS__)
2992#define CHECK_THROWS_WITH_MESSAGE(expr, with, ...) DOCTEST_CHECK_THROWS_WITH_MESSAGE(expr, with, __VA_ARGS__)
2993#define CHECK_THROWS_WITH_AS_MESSAGE(expr, with, ex, ...) DOCTEST_CHECK_THROWS_WITH_AS_MESSAGE(expr, with, ex, __VA_ARGS__)
2994#define CHECK_NOTHROW_MESSAGE(expr, ...) DOCTEST_CHECK_NOTHROW_MESSAGE(expr, __VA_ARGS__)
2995#define REQUIRE_MESSAGE(cond, ...) DOCTEST_REQUIRE_MESSAGE(cond, __VA_ARGS__)
2996#define REQUIRE_FALSE_MESSAGE(cond, ...) DOCTEST_REQUIRE_FALSE_MESSAGE(cond, __VA_ARGS__)
2997#define REQUIRE_THROWS_MESSAGE(expr, ...) DOCTEST_REQUIRE_THROWS_MESSAGE(expr, __VA_ARGS__)
2998#define REQUIRE_THROWS_AS_MESSAGE(expr, ex, ...) DOCTEST_REQUIRE_THROWS_AS_MESSAGE(expr, ex, __VA_ARGS__)
2999#define REQUIRE_THROWS_WITH_MESSAGE(expr, with, ...) DOCTEST_REQUIRE_THROWS_WITH_MESSAGE(expr, with, __VA_ARGS__)
3000#define REQUIRE_THROWS_WITH_AS_MESSAGE(expr, with, ex, ...) DOCTEST_REQUIRE_THROWS_WITH_AS_MESSAGE(expr, with, ex, __VA_ARGS__)
3001#define REQUIRE_NOTHROW_MESSAGE(expr, ...) DOCTEST_REQUIRE_NOTHROW_MESSAGE(expr, __VA_ARGS__)
3002
3003#define SCENARIO(name) DOCTEST_SCENARIO(name)
3004#define SCENARIO_CLASS(name) DOCTEST_SCENARIO_CLASS(name)
3005#define SCENARIO_TEMPLATE(name, T, ...) DOCTEST_SCENARIO_TEMPLATE(name, T, __VA_ARGS__)
3006#define SCENARIO_TEMPLATE_DEFINE(name, T, id) DOCTEST_SCENARIO_TEMPLATE_DEFINE(name, T, id)
3007#define GIVEN(name) DOCTEST_GIVEN(name)
3008#define WHEN(name) DOCTEST_WHEN(name)
3009#define AND_WHEN(name) DOCTEST_AND_WHEN(name)
3010#define THEN(name) DOCTEST_THEN(name)
3011#define AND_THEN(name) DOCTEST_AND_THEN(name)
3012
3013#define WARN_EQ(...) DOCTEST_WARN_EQ(__VA_ARGS__)
3014#define CHECK_EQ(...) DOCTEST_CHECK_EQ(__VA_ARGS__)
3015#define REQUIRE_EQ(...) DOCTEST_REQUIRE_EQ(__VA_ARGS__)
3016#define WARN_NE(...) DOCTEST_WARN_NE(__VA_ARGS__)
3017#define CHECK_NE(...) DOCTEST_CHECK_NE(__VA_ARGS__)
3018#define REQUIRE_NE(...) DOCTEST_REQUIRE_NE(__VA_ARGS__)
3019#define WARN_GT(...) DOCTEST_WARN_GT(__VA_ARGS__)
3020#define CHECK_GT(...) DOCTEST_CHECK_GT(__VA_ARGS__)
3021#define REQUIRE_GT(...) DOCTEST_REQUIRE_GT(__VA_ARGS__)
3022#define WARN_LT(...) DOCTEST_WARN_LT(__VA_ARGS__)
3023#define CHECK_LT(...) DOCTEST_CHECK_LT(__VA_ARGS__)
3024#define REQUIRE_LT(...) DOCTEST_REQUIRE_LT(__VA_ARGS__)
3025#define WARN_GE(...) DOCTEST_WARN_GE(__VA_ARGS__)
3026#define CHECK_GE(...) DOCTEST_CHECK_GE(__VA_ARGS__)
3027#define REQUIRE_GE(...) DOCTEST_REQUIRE_GE(__VA_ARGS__)
3028#define WARN_LE(...) DOCTEST_WARN_LE(__VA_ARGS__)
3029#define CHECK_LE(...) DOCTEST_CHECK_LE(__VA_ARGS__)
3030#define REQUIRE_LE(...) DOCTEST_REQUIRE_LE(__VA_ARGS__)
3031#define WARN_UNARY(...) DOCTEST_WARN_UNARY(__VA_ARGS__)
3032#define CHECK_UNARY(...) DOCTEST_CHECK_UNARY(__VA_ARGS__)
3033#define REQUIRE_UNARY(...) DOCTEST_REQUIRE_UNARY(__VA_ARGS__)
3034#define WARN_UNARY_FALSE(...) DOCTEST_WARN_UNARY_FALSE(__VA_ARGS__)
3035#define CHECK_UNARY_FALSE(...) DOCTEST_CHECK_UNARY_FALSE(__VA_ARGS__)
3036#define REQUIRE_UNARY_FALSE(...) DOCTEST_REQUIRE_UNARY_FALSE(__VA_ARGS__)
3037
3038// KEPT FOR BACKWARDS COMPATIBILITY
3039#define FAST_WARN_EQ(...) DOCTEST_FAST_WARN_EQ(__VA_ARGS__)
3040#define FAST_CHECK_EQ(...) DOCTEST_FAST_CHECK_EQ(__VA_ARGS__)
3041#define FAST_REQUIRE_EQ(...) DOCTEST_FAST_REQUIRE_EQ(__VA_ARGS__)
3042#define FAST_WARN_NE(...) DOCTEST_FAST_WARN_NE(__VA_ARGS__)
3043#define FAST_CHECK_NE(...) DOCTEST_FAST_CHECK_NE(__VA_ARGS__)
3044#define FAST_REQUIRE_NE(...) DOCTEST_FAST_REQUIRE_NE(__VA_ARGS__)
3045#define FAST_WARN_GT(...) DOCTEST_FAST_WARN_GT(__VA_ARGS__)
3046#define FAST_CHECK_GT(...) DOCTEST_FAST_CHECK_GT(__VA_ARGS__)
3047#define FAST_REQUIRE_GT(...) DOCTEST_FAST_REQUIRE_GT(__VA_ARGS__)
3048#define FAST_WARN_LT(...) DOCTEST_FAST_WARN_LT(__VA_ARGS__)
3049#define FAST_CHECK_LT(...) DOCTEST_FAST_CHECK_LT(__VA_ARGS__)
3050#define FAST_REQUIRE_LT(...) DOCTEST_FAST_REQUIRE_LT(__VA_ARGS__)
3051#define FAST_WARN_GE(...) DOCTEST_FAST_WARN_GE(__VA_ARGS__)
3052#define FAST_CHECK_GE(...) DOCTEST_FAST_CHECK_GE(__VA_ARGS__)
3053#define FAST_REQUIRE_GE(...) DOCTEST_FAST_REQUIRE_GE(__VA_ARGS__)
3054#define FAST_WARN_LE(...) DOCTEST_FAST_WARN_LE(__VA_ARGS__)
3055#define FAST_CHECK_LE(...) DOCTEST_FAST_CHECK_LE(__VA_ARGS__)
3056#define FAST_REQUIRE_LE(...) DOCTEST_FAST_REQUIRE_LE(__VA_ARGS__)
3057
3058#define FAST_WARN_UNARY(...) DOCTEST_FAST_WARN_UNARY(__VA_ARGS__)
3059#define FAST_CHECK_UNARY(...) DOCTEST_FAST_CHECK_UNARY(__VA_ARGS__)
3060#define FAST_REQUIRE_UNARY(...) DOCTEST_FAST_REQUIRE_UNARY(__VA_ARGS__)
3061#define FAST_WARN_UNARY_FALSE(...) DOCTEST_FAST_WARN_UNARY_FALSE(__VA_ARGS__)
3062#define FAST_CHECK_UNARY_FALSE(...) DOCTEST_FAST_CHECK_UNARY_FALSE(__VA_ARGS__)
3063#define FAST_REQUIRE_UNARY_FALSE(...) DOCTEST_FAST_REQUIRE_UNARY_FALSE(__VA_ARGS__)
3064
3065#define TEST_CASE_TEMPLATE_INSTANTIATE(id, ...) DOCTEST_TEST_CASE_TEMPLATE_INSTANTIATE(id, __VA_ARGS__)
3066
3067#endif // DOCTEST_CONFIG_NO_SHORT_MACRO_NAMES
3068
3069#ifndef DOCTEST_CONFIG_DISABLE
3070
3071// this is here to clear the 'current test suite' for the current translation unit - at the top
3072DOCTEST_TEST_SUITE_END();
3073
3074#endif // DOCTEST_CONFIG_DISABLE
3075
3076DOCTEST_CLANG_SUPPRESS_WARNING_POP
3077DOCTEST_MSVC_SUPPRESS_WARNING_POP
3078DOCTEST_GCC_SUPPRESS_WARNING_POP
3079
3080DOCTEST_SUPPRESS_COMMON_WARNINGS_POP
3081
3082#endif // DOCTEST_LIBRARY_INCLUDED
Definition doctest.h:530
Definition how_subcases_work.cpp:32
Definition doctest.h:1571
Definition doctest.h:1500
DOCTEST_NOINLINE bool unary_assert(const DOCTEST_REF_WRAP(L) val)
Definition doctest_fwd.h:1699
Definition doctest.h:1396
Definition doctest.h:1592
Definition doctest_fwd.h:1147