ManaPlus
doctest.h
Go to the documentation of this file.
1 // ======================================================================
2 // == DO NOT MODIFY THIS FILE BY HAND - IT IS AUTO GENERATED BY CMAKE! ==
3 // ======================================================================
4 //
5 // doctest.h - the lightest feature-rich C++ single-header testing framework for unit tests and TDD
6 //
7 // Copyright (c) 2016-2018 Viktor Kirilov
8 //
9 // Distributed under the MIT Software License
10 // See accompanying file LICENSE.txt or copy at
11 // https://opensource.org/licenses/MIT
12 //
13 // The documentation can be found at the library's page:
14 // https://github.com/onqtam/doctest/blob/master/doc/markdown/readme.md
15 //
16 // =================================================================================================
17 // =================================================================================================
18 // =================================================================================================
19 //
20 // The library is heavily influenced by Catch - https://github.com/philsquared/Catch
21 // which uses the Boost Software License - Version 1.0
22 // see here - https://github.com/philsquared/Catch/blob/master/LICENSE.txt
23 //
24 // The concept of subcases (sections in Catch) and expression decomposition are from there.
25 // Some parts of the code are taken directly:
26 // - stringification - the detection of "ostream& operator<<(ostream&, const T&)" and StringMaker<>
27 // - the Approx() helper class for floating point comparison
28 // - colors in the console
29 // - breaking into a debugger
30 // - signal / SEH handling
31 // - timer
32 //
33 // The expression decomposing templates are taken from lest - https://github.com/martinmoene/lest
34 // which uses the Boost Software License - Version 1.0
35 // see here - https://github.com/martinmoene/lest/blob/master/LICENSE.txt
36 //
37 // =================================================================================================
38 // =================================================================================================
39 // =================================================================================================
40 
41 #ifndef DOCTEST_LIBRARY_INCLUDED
42 #define DOCTEST_LIBRARY_INCLUDED
43 
44 // =================================================================================================
45 // == VERSION ======================================================================================
46 // =================================================================================================
47 
48 #define DOCTEST_VERSION_MAJOR 1
49 #define DOCTEST_VERSION_MINOR 2
50 #define DOCTEST_VERSION_PATCH 9
51 #define DOCTEST_VERSION_STR "1.2.9"
52 
53 #define DOCTEST_VERSION \
54  (DOCTEST_VERSION_MAJOR * 10000 + DOCTEST_VERSION_MINOR * 100 + DOCTEST_VERSION_PATCH)
55 
56 // =================================================================================================
57 // == COMPILER VERSION =============================================================================
58 // =================================================================================================
59 
60 // ideas for the version stuff are taken from here: https://github.com/cxxstuff/cxx_detect
61 
62 #define DOCTEST_COMPILER(MAJOR, MINOR, PATCH) ((MAJOR)*10000000 + (MINOR)*100000 + (PATCH))
63 
64 #if defined(_MSC_VER) && defined(_MSC_FULL_VER)
65 #if _MSC_VER == _MSC_FULL_VER / 10000
66 #define DOCTEST_MSVC DOCTEST_COMPILER(_MSC_VER / 100, _MSC_VER % 100, _MSC_FULL_VER % 10000)
67 #else
68 #define DOCTEST_MSVC \
69  DOCTEST_COMPILER(_MSC_VER / 100, (_MSC_FULL_VER / 100000) % 100, _MSC_FULL_VER % 100000)
70 #endif
71 #elif defined(__clang__) && defined(__clang_minor__)
72 #define DOCTEST_CLANG DOCTEST_COMPILER(__clang_major__, __clang_minor__, __clang_patchlevel__)
73 #elif defined(__GNUC__) && defined(__GNUC_MINOR__) && defined(__GNUC_PATCHLEVEL__) && \
74  !defined(__INTEL_COMPILER)
75 #define DOCTEST_GCC DOCTEST_COMPILER(__GNUC__, __GNUC_MINOR__, __GNUC_PATCHLEVEL__)
76 #endif
77 
78 #ifndef DOCTEST_MSVC
79 #define DOCTEST_MSVC 0
80 #endif // DOCTEST_MSVC
81 #ifndef DOCTEST_CLANG
82 #define DOCTEST_CLANG 0
83 #endif // DOCTEST_CLANG
84 #ifndef DOCTEST_GCC
85 #define DOCTEST_GCC 0
86 #endif // DOCTEST_GCC
87 
88 // =================================================================================================
89 // == COMPILER WARNINGS HELPERS ====================================================================
90 // =================================================================================================
91 
92 #if DOCTEST_CLANG
93 #ifdef __has_warning
94 #define DOCTEST_CLANG_HAS_WARNING(x) __has_warning(x)
95 #endif // __has_warning
96 #ifdef __has_feature
97 #define DOCTEST_CLANG_HAS_FEATURE(x) __has_feature(x)
98 #endif // __has_feature
99 #define DOCTEST_PRAGMA_TO_STR(x) _Pragma(#x)
100 #define DOCTEST_CLANG_SUPPRESS_WARNING_PUSH _Pragma("clang diagnostic push")
101 #define DOCTEST_MSVC_SUPPRESS_WARNING_PUSH
102 #define DOCTEST_GCC_SUPPRESS_WARNING_PUSH
103 #define DOCTEST_CLANG_SUPPRESS_WARNING(w) DOCTEST_PRAGMA_TO_STR(clang diagnostic ignored w)
104 #define DOCTEST_MSVC_SUPPRESS_WARNING(w)
105 #define DOCTEST_GCC_SUPPRESS_WARNING(w)
106 #define DOCTEST_CLANG_SUPPRESS_WARNING_POP _Pragma("clang diagnostic pop")
107 #define DOCTEST_MSVC_SUPPRESS_WARNING_POP
108 #define DOCTEST_GCC_SUPPRESS_WARNING_POP
109 #define DOCTEST_CLANG_SUPPRESS_WARNING_WITH_PUSH(w) \
110  DOCTEST_CLANG_SUPPRESS_WARNING_PUSH DOCTEST_CLANG_SUPPRESS_WARNING(w)
111 #define DOCTEST_MSVC_SUPPRESS_WARNING_WITH_PUSH(w)
112 #define DOCTEST_GCC_SUPPRESS_WARNING_WITH_PUSH(w)
113 #elif DOCTEST_GCC
114 #define DOCTEST_PRAGMA_TO_STR(x) _Pragma(#x)
115 #define DOCTEST_CLANG_SUPPRESS_WARNING_PUSH
116 #define DOCTEST_MSVC_SUPPRESS_WARNING_PUSH
117 #define DOCTEST_GCC_SUPPRESS_WARNING_PUSH _Pragma("GCC diagnostic push")
118 #define DOCTEST_CLANG_SUPPRESS_WARNING(w)
119 #define DOCTEST_MSVC_SUPPRESS_WARNING(w)
120 #define DOCTEST_GCC_SUPPRESS_WARNING(w) DOCTEST_PRAGMA_TO_STR(GCC diagnostic ignored w)
121 #define DOCTEST_CLANG_SUPPRESS_WARNING_POP
122 #define DOCTEST_MSVC_SUPPRESS_WARNING_POP
123 #define DOCTEST_GCC_SUPPRESS_WARNING_POP _Pragma("GCC diagnostic pop")
124 #define DOCTEST_CLANG_SUPPRESS_WARNING_WITH_PUSH(w)
125 #define DOCTEST_MSVC_SUPPRESS_WARNING_WITH_PUSH(w)
126 #define DOCTEST_GCC_SUPPRESS_WARNING_WITH_PUSH(w) \
127  DOCTEST_GCC_SUPPRESS_WARNING_PUSH DOCTEST_GCC_SUPPRESS_WARNING(w)
128 #elif DOCTEST_MSVC
129 #define DOCTEST_PRAGMA_TO_STR(x)
130 #define DOCTEST_CLANG_SUPPRESS_WARNING_PUSH
131 #define DOCTEST_MSVC_SUPPRESS_WARNING_PUSH __pragma(warning(push))
132 #define DOCTEST_GCC_SUPPRESS_WARNING_PUSH
133 #define DOCTEST_CLANG_SUPPRESS_WARNING(w)
134 #define DOCTEST_MSVC_SUPPRESS_WARNING(w) __pragma(warning(disable : w))
135 #define DOCTEST_GCC_SUPPRESS_WARNING(w)
136 #define DOCTEST_CLANG_SUPPRESS_WARNING_POP
137 #define DOCTEST_MSVC_SUPPRESS_WARNING_POP __pragma(warning(pop))
138 #define DOCTEST_GCC_SUPPRESS_WARNING_POP
139 #define DOCTEST_CLANG_SUPPRESS_WARNING_WITH_PUSH(w)
140 #define DOCTEST_MSVC_SUPPRESS_WARNING_WITH_PUSH(w) \
141  DOCTEST_MSVC_SUPPRESS_WARNING_PUSH DOCTEST_MSVC_SUPPRESS_WARNING(w)
142 #define DOCTEST_GCC_SUPPRESS_WARNING_WITH_PUSH(w)
143 #endif // different compilers - warning suppression macros
144 
145 #ifndef DOCTEST_CLANG_HAS_WARNING
146 #define DOCTEST_CLANG_HAS_WARNING(x) 1
147 #endif // DOCTEST_CLANG_HAS_WARNING
148 
149 #ifndef DOCTEST_CLANG_HAS_FEATURE
150 #define DOCTEST_CLANG_HAS_FEATURE(x) 0
151 #endif // DOCTEST_CLANG_HAS_FEATURE
152 
153 // =================================================================================================
154 // == COMPILER WARNINGS ============================================================================
155 // =================================================================================================
156 
157 DOCTEST_CLANG_SUPPRESS_WARNING_PUSH
158 DOCTEST_CLANG_SUPPRESS_WARNING("-Wunknown-pragmas")
159 DOCTEST_CLANG_SUPPRESS_WARNING("-Wnon-virtual-dtor")
160 DOCTEST_CLANG_SUPPRESS_WARNING("-Wweak-vtables")
162 DOCTEST_CLANG_SUPPRESS_WARNING("-Wdeprecated")
163 DOCTEST_CLANG_SUPPRESS_WARNING("-Wmissing-prototypes")
164 DOCTEST_CLANG_SUPPRESS_WARNING("-Wunused-local-typedef")
165 DOCTEST_CLANG_SUPPRESS_WARNING("-Wc++11-long-long")
166 #if DOCTEST_CLANG && DOCTEST_CLANG_HAS_WARNING("-Wzero-as-null-pointer-constant")
167 DOCTEST_CLANG_SUPPRESS_WARNING("-Wzero-as-null-pointer-constant")
168 #endif // clang - 0 as null
169 DOCTEST_CLANG_SUPPRESS_WARNING("-Wc++98-compat")
170 DOCTEST_CLANG_SUPPRESS_WARNING("-Wc++98-compat-pedantic")
171 
172 DOCTEST_GCC_SUPPRESS_WARNING_PUSH
173 DOCTEST_GCC_SUPPRESS_WARNING("-Wunknown-pragmas")
174 DOCTEST_GCC_SUPPRESS_WARNING("-Wpragmas")
175 DOCTEST_GCC_SUPPRESS_WARNING("-Weffc++")
176 DOCTEST_GCC_SUPPRESS_WARNING("-Wstrict-overflow")
177 DOCTEST_GCC_SUPPRESS_WARNING("-Wstrict-aliasing")
178 DOCTEST_GCC_SUPPRESS_WARNING("-Wctor-dtor-privacy")
179 DOCTEST_GCC_SUPPRESS_WARNING("-Wmissing-declarations")
180 DOCTEST_GCC_SUPPRESS_WARNING("-Wnon-virtual-dtor")
181 DOCTEST_GCC_SUPPRESS_WARNING("-Winline")
182 DOCTEST_GCC_SUPPRESS_WARNING("-Wlong-long")
183 DOCTEST_GCC_SUPPRESS_WARNING("-Wzero-as-null-pointer-constant")
184 DOCTEST_GCC_SUPPRESS_WARNING("-Wunused-local-typedefs")
185 DOCTEST_GCC_SUPPRESS_WARNING("-Wuseless-cast")
186 
187 DOCTEST_MSVC_SUPPRESS_WARNING_PUSH
188 DOCTEST_MSVC_SUPPRESS_WARNING(4616) // invalid compiler warning
189 DOCTEST_MSVC_SUPPRESS_WARNING(4619) // invalid compiler warning
190 DOCTEST_MSVC_SUPPRESS_WARNING(4996) // The compiler encountered a deprecated declaration
191 DOCTEST_MSVC_SUPPRESS_WARNING(4706) // assignment within conditional expression
192 DOCTEST_MSVC_SUPPRESS_WARNING(4512) // 'class' : assignment operator could not be generated
193 DOCTEST_MSVC_SUPPRESS_WARNING(4127) // conditional expression is constant
194 DOCTEST_MSVC_SUPPRESS_WARNING(4820) // padding
195 DOCTEST_MSVC_SUPPRESS_WARNING(4625) // copy constructor was implicitly defined as deleted
196 DOCTEST_MSVC_SUPPRESS_WARNING(4626) // assignment operator was implicitly defined as deleted
197 DOCTEST_MSVC_SUPPRESS_WARNING(5027) // move assignment operator was implicitly defined as deleted
198 DOCTEST_MSVC_SUPPRESS_WARNING(5026) // move constructor was implicitly defined as deleted
199 DOCTEST_MSVC_SUPPRESS_WARNING(4623) // default constructor was implicitly defined as deleted
200 DOCTEST_MSVC_SUPPRESS_WARNING(4640) // construction of local static object is not thread-safe
201 // static analysis
202 DOCTEST_MSVC_SUPPRESS_WARNING(26439) // This kind of function may not throw. Declare it 'noexcept'
203 DOCTEST_MSVC_SUPPRESS_WARNING(26495) // Always initialize a member variable
204 DOCTEST_MSVC_SUPPRESS_WARNING(26451) // Arithmetic overflow ...
205 DOCTEST_MSVC_SUPPRESS_WARNING(26444) // Avoid unnamed objects with custom construction and dtr...
206 
207 // 4548 - expression before comma has no effect; expected expression with side - effect
208 // 4265 - class has virtual functions, but destructor is not virtual
209 // 4986 - exception specification does not match previous declaration
210 // 4350 - behavior change: 'member1' called instead of 'member2'
211 // 4668 - 'x' is not defined as a preprocessor macro, replacing with '0' for '#if/#elif'
212 // 4365 - conversion from 'int' to 'unsigned long', signed/unsigned mismatch
213 // 4774 - format string expected in argument 'x' is not a string literal
214 // 4820 - padding in structs
215 
216 // only 4 should be disabled globally:
217 // - 4514 # unreferenced inline function has been removed
218 // - 4571 # SEH related
219 // - 4710 # function not inlined
220 // - 4711 # function 'x' selected for automatic inline expansion
221 
222 #define DOCTEST_MAKE_STD_HEADERS_CLEAN_FROM_WARNINGS_ON_WALL_BEGIN \
223  DOCTEST_MSVC_SUPPRESS_WARNING_PUSH \
224  DOCTEST_MSVC_SUPPRESS_WARNING(4548) \
225  DOCTEST_MSVC_SUPPRESS_WARNING(4265) \
226  DOCTEST_MSVC_SUPPRESS_WARNING(4986) \
227  DOCTEST_MSVC_SUPPRESS_WARNING(4350) \
228  DOCTEST_MSVC_SUPPRESS_WARNING(4668) \
229  DOCTEST_MSVC_SUPPRESS_WARNING(4365) \
230  DOCTEST_MSVC_SUPPRESS_WARNING(4774) \
231  DOCTEST_MSVC_SUPPRESS_WARNING(4820) \
232  DOCTEST_MSVC_SUPPRESS_WARNING(4625) \
233  DOCTEST_MSVC_SUPPRESS_WARNING(4626) \
234  DOCTEST_MSVC_SUPPRESS_WARNING(5027) \
235  DOCTEST_MSVC_SUPPRESS_WARNING(5026) \
236  DOCTEST_MSVC_SUPPRESS_WARNING(4623) \
237  DOCTEST_MSVC_SUPPRESS_WARNING(5039)
238 
239 #define DOCTEST_MAKE_STD_HEADERS_CLEAN_FROM_WARNINGS_ON_WALL_END DOCTEST_MSVC_SUPPRESS_WARNING_POP
240 
241 // =================================================================================================
242 // == FEATURE DETECTION ============================================================================
243 // =================================================================================================
244 
245 // general compiler feature support table: https://en.cppreference.com/w/cpp/compiler_support
246 // MSVC C++11 feature support table: https://msdn.microsoft.com/en-us/library/hh567368.aspx
247 // GCC C++11 feature support table: https://gcc.gnu.org/projects/cxx-status.html
248 // MSVC version table:
249 // MSVC++ 15.0 _MSC_VER == 1910 (Visual Studio 2017)
250 // MSVC++ 14.0 _MSC_VER == 1900 (Visual Studio 2015)
251 // MSVC++ 12.0 _MSC_VER == 1800 (Visual Studio 2013)
252 // MSVC++ 11.0 _MSC_VER == 1700 (Visual Studio 2012)
253 // MSVC++ 10.0 _MSC_VER == 1600 (Visual Studio 2010)
254 // MSVC++ 9.0 _MSC_VER == 1500 (Visual Studio 2008)
255 // MSVC++ 8.0 _MSC_VER == 1400 (Visual Studio 2005)
256 
257 #if DOCTEST_MSVC && !defined(DOCTEST_CONFIG_WINDOWS_SEH)
258 #define DOCTEST_CONFIG_WINDOWS_SEH
259 #endif // MSVC
260 #if defined(DOCTEST_CONFIG_NO_WINDOWS_SEH) && defined(DOCTEST_CONFIG_WINDOWS_SEH)
261 #undef DOCTEST_CONFIG_WINDOWS_SEH
262 #endif // DOCTEST_CONFIG_NO_WINDOWS_SEH
263 
264 #if !defined(_WIN32) && !defined(__QNX__) && !defined(DOCTEST_CONFIG_POSIX_SIGNALS)
265 #define DOCTEST_CONFIG_POSIX_SIGNALS
266 #endif // _WIN32
267 #if defined(DOCTEST_CONFIG_NO_POSIX_SIGNALS) && defined(DOCTEST_CONFIG_POSIX_SIGNALS)
268 #undef DOCTEST_CONFIG_POSIX_SIGNALS
269 #endif // DOCTEST_CONFIG_NO_POSIX_SIGNALS
270 
271 #ifndef DOCTEST_CONFIG_NO_EXCEPTIONS
272 #if(DOCTEST_GCC || DOCTEST_CLANG) && !defined(__EXCEPTIONS)
273 #define DOCTEST_CONFIG_NO_EXCEPTIONS
274 #endif // clang and gcc
275 // in MSVC _HAS_EXCEPTIONS is defined in a header instead of as a project define
276 // so we can't do the automatic detection for MSVC without including some header
277 #endif // DOCTEST_CONFIG_NO_EXCEPTIONS
278 
279 #ifdef DOCTEST_CONFIG_NO_EXCEPTIONS_BUT_WITH_ALL_ASSERTS
280 #ifndef DOCTEST_CONFIG_NO_EXCEPTIONS
281 #define DOCTEST_CONFIG_NO_EXCEPTIONS
282 #endif // DOCTEST_CONFIG_NO_EXCEPTIONS
283 #endif // DOCTEST_CONFIG_NO_EXCEPTIONS_BUT_WITH_ALL_ASSERTS
284 
285 #if defined(DOCTEST_CONFIG_NO_EXCEPTIONS) && !defined(DOCTEST_CONFIG_NO_TRY_CATCH_IN_ASSERTS)
286 #define DOCTEST_CONFIG_NO_TRY_CATCH_IN_ASSERTS
287 #endif // DOCTEST_CONFIG_NO_EXCEPTIONS && !DOCTEST_CONFIG_NO_TRY_CATCH_IN_ASSERTS
288 
289 #if defined(DOCTEST_CONFIG_IMPLEMENT_WITH_MAIN) && !defined(DOCTEST_CONFIG_IMPLEMENT)
290 #define DOCTEST_CONFIG_IMPLEMENT
291 #endif // DOCTEST_CONFIG_IMPLEMENT_WITH_MAIN
292 
293 #if defined _WIN32 || defined __CYGWIN__
294 #if DOCTEST_MSVC
295 #define DOCTEST_SYMBOL_EXPORT __declspec(dllexport)
296 #define DOCTEST_SYMBOL_IMPORT __declspec(dllimport)
297 #else // MSVC
298 #define DOCTEST_SYMBOL_EXPORT __attribute__((dllexport))
299 #define DOCTEST_SYMBOL_IMPORT __attribute__((dllimport))
300 #endif // MSVC
301 #else // _WIN32
302 #define DOCTEST_SYMBOL_EXPORT __attribute__((visibility("default")))
303 #define DOCTEST_SYMBOL_IMPORT
304 #endif // _WIN32
305 
306 #ifdef DOCTEST_CONFIG_IMPLEMENTATION_IN_DLL
307 #ifdef DOCTEST_CONFIG_IMPLEMENT
308 #define DOCTEST_INTERFACE DOCTEST_SYMBOL_EXPORT
309 #else // DOCTEST_CONFIG_IMPLEMENT
310 #define DOCTEST_INTERFACE DOCTEST_SYMBOL_IMPORT
311 #endif // DOCTEST_CONFIG_IMPLEMENT
312 #else // DOCTEST_CONFIG_IMPLEMENTATION_IN_DLL
313 #define DOCTEST_INTERFACE
314 #endif // DOCTEST_CONFIG_IMPLEMENTATION_IN_DLL
315 
316 #if DOCTEST_MSVC
317 #define DOCTEST_NOINLINE __declspec(noinline)
318 #define DOCTEST_UNUSED
319 #define DOCTEST_ALIGNMENT(x)
320 #else // MSVC
321 #define DOCTEST_NOINLINE __attribute__((noinline))
322 #define DOCTEST_UNUSED __attribute__((unused))
323 #define DOCTEST_ALIGNMENT(x) __attribute__((aligned(x)))
324 #endif // MSVC
325 
326 #ifndef DOCTEST_CONFIG_NUM_CAPTURES_ON_STACK
327 #define DOCTEST_CONFIG_NUM_CAPTURES_ON_STACK 5
328 #endif // DOCTEST_CONFIG_NUM_CAPTURES_ON_STACK
329 
330 // =================================================================================================
331 // == FEATURE DETECTION END ========================================================================
332 // =================================================================================================
333 
334 // internal macros for string concatenation and anonymous variable name generation
335 #define DOCTEST_CAT_IMPL(s1, s2) s1##s2
336 #define DOCTEST_CAT(s1, s2) DOCTEST_CAT_IMPL(s1, s2)
337 #ifdef __COUNTER__ // not standard and may be missing for some compilers
338 #define DOCTEST_ANONYMOUS(x) DOCTEST_CAT(x, __COUNTER__)
339 #else // __COUNTER__
340 #define DOCTEST_ANONYMOUS(x) DOCTEST_CAT(x, __LINE__)
341 #endif // __COUNTER__
342 
343 // macro for making a string out of an identifier
344 #define DOCTEST_TOSTR_IMPL(...) #__VA_ARGS__
345 #define DOCTEST_TOSTR(...) DOCTEST_TOSTR_IMPL(__VA_ARGS__)
346 
347 #ifndef DOCTEST_CONFIG_ASSERTION_PARAMETERS_BY_VALUE
348 #define DOCTEST_REF_WRAP(x) x&
349 #else // DOCTEST_CONFIG_ASSERTION_PARAMETERS_BY_VALUE
350 #define DOCTEST_REF_WRAP(x) x
351 #endif // DOCTEST_CONFIG_ASSERTION_PARAMETERS_BY_VALUE
352 
353 // not using __APPLE__ because... this is how Catch does it
354 #if defined(__MAC_OS_X_VERSION_MIN_REQUIRED)
355 #define DOCTEST_PLATFORM_MAC
356 #elif defined(__IPHONE_OS_VERSION_MIN_REQUIRED)
357 #define DOCTEST_PLATFORM_IPHONE
358 #elif defined(_WIN32)
359 #define DOCTEST_PLATFORM_WINDOWS
360 #else
361 #define DOCTEST_PLATFORM_LINUX
362 #endif
363 
364 // clang-format off
365 #define DOCTEST_DELETE_COPIES(type) type(const type&) = delete; type& operator=(const type&) = delete
366 #define DOCTEST_DECLARE_COPIES(type) type(const type&); type& operator=(const type&)
367 #define DOCTEST_DEFINE_COPIES(type) type::type(const type&) = default; type& type::operator=(const type&) = default
368 #define DOCTEST_DECLARE_DEFAULTS(type) type(); ~type()
369 #define DOCTEST_DEFINE_DEFAULTS(type) type::type() = default; type::~type() = default
370 // clang-format on
371 
372 #define DOCTEST_GLOBAL_NO_WARNINGS(var) \
373  DOCTEST_CLANG_SUPPRESS_WARNING_WITH_PUSH("-Wglobal-constructors") static int var DOCTEST_UNUSED
374 #define DOCTEST_GLOBAL_NO_WARNINGS_END() DOCTEST_CLANG_SUPPRESS_WARNING_POP
375 
376 // should probably take a look at https://github.com/scottt/debugbreak
377 #ifdef DOCTEST_PLATFORM_MAC
378 #define DOCTEST_BREAK_INTO_DEBUGGER() __asm__("int $3\n" : :)
379 #elif DOCTEST_MSVC
380 #define DOCTEST_BREAK_INTO_DEBUGGER() __debugbreak()
381 #elif defined(__MINGW32__)
382 extern "C" __declspec(dllimport) void __stdcall DebugBreak();
383 #define DOCTEST_BREAK_INTO_DEBUGGER() ::DebugBreak()
384 #else // linux
385 #define DOCTEST_BREAK_INTO_DEBUGGER() ((void)0)
386 #endif // linux
387 
388 #if DOCTEST_CLANG
389 // to detect if libc++ is being used with clang (the _LIBCPP_VERSION identifier)
390 #include <ciso646>
391 #endif // clang
392 
393 #if defined(_LIBCPP_VERSION) || defined(DOCTEST_CONFIG_USE_IOSFWD)
394 // not forward declaring ostream for libc++ because I had some problems (inline namespaces vs c++98)
395 // so the <iosfwd> header is used - also it is very light and doesn't drag a ton of stuff
396 #include <iosfwd>
397 #else // _LIBCPP_VERSION
398 namespace std {
399 template <class charT>
400 struct char_traits;
401 template <>
402 struct char_traits<char>;
403 template <class charT, class traits>
404 class basic_ostream;
405 typedef basic_ostream<char, char_traits<char> > ostream;
406 } // namespace std
407 #endif // _LIBCPP_VERSION || DOCTEST_CONFIG_USE_IOSFWD
408 
409 #ifdef _LIBCPP_VERSION
410 #include <cstddef>
411 #else // _LIBCPP_VERSION
412 namespace std {
413 typedef decltype(nullptr) nullptr_t;
414 }
415 #endif // _LIBCPP_VERSION
416 
417 #ifdef DOCTEST_CONFIG_INCLUDE_TYPE_TRAITS
418 #include <type_traits>
419 #endif // DOCTEST_CONFIG_INCLUDE_TYPE_TRAITS
420 
421 namespace doctest {
422 namespace detail {
423  // the function type this library works with
424  typedef void (*funcType)();
425 } // namespace detail
426 
427 // A 24 byte string class (can be as small as 17 for x64 and 13 for x86) that can hold strings with length
428 // of up to 23 chars on the stack before going on the heap - the last byte of the buffer is used for:
429 // - "is small" bit - the highest bit - if "0" then it is small - otherwise its "1" (128)
430 // - if small - capacity left before going on the heap - using the lowest 5 bits
431 // - if small - 2 bits are left unused - the second and third highest ones
432 // - if small - acts as a null terminator if strlen() is 23 (24 including the null terminator)
433 // and the "is small" bit remains "0" ("as well as the capacity left") so its OK
434 // Idea taken from this lecture about the string implementation of facebook/folly - fbstring
435 // https://www.youtube.com/watch?v=kPR8h4-qZdk
436 // TODO:
437 // - optimizations - like not deleting memory unnecessarily in operator= and etc.
438 // - resize/reserve/clear
439 // - substr
440 // - replace
441 // - back/front
442 // - iterator stuff
443 // - find & friends
444 // - push_back/pop_back
445 // - assign/insert/erase
446 // - relational operators as free functions - taking const char* as one of the params
448 {
449  static const unsigned len = 24;
450  static const unsigned last = len - 1;
451 
452  struct view // len should be more than sizeof(view) - because of the final byte for flags
453  {
454  char* ptr;
455  unsigned size;
456  unsigned capacity;
457  };
458 
459  union
460  {
461  char buf[len];
463  };
464 
465  bool isOnStack() const { return (buf[last] & 128) == 0; }
466  void setOnHeap();
467  void setLast(unsigned in = last);
468 
469  void copy(const String& other);
470 
471 public:
474 
475  String(const char* in);
476 
477  String(const String& other);
478  String& operator=(const String& other);
479 
480  String& operator+=(const String& other);
481  String operator+(const String& other) const;
482 
483  String(String&& other);
485 
486  char operator[](unsigned i) const;
487  char& operator[](unsigned i);
488 
489  // the only functions I'm willing to leave in the interface - available for inlining
490  const char* c_str() const { return const_cast<String*>(this)->c_str(); } // NOLINT
491  char* c_str() {
492  if(isOnStack())
493  return reinterpret_cast<char*>(buf);
494  return data.ptr;
495  }
496 
497  unsigned size() const;
498  unsigned capacity() const;
499 
500  int compare(const char* other, bool no_case = false) const;
501  int compare(const String& other, bool no_case = false) const;
502 };
503 
504 DOCTEST_INTERFACE bool operator==(const String& lhs, const String& rhs);
505 DOCTEST_INTERFACE bool operator!=(const String& lhs, const String& rhs);
506 DOCTEST_INTERFACE bool operator<(const String& lhs, const String& rhs);
507 DOCTEST_INTERFACE bool operator>(const String& lhs, const String& rhs);
508 DOCTEST_INTERFACE bool operator<=(const String& lhs, const String& rhs);
509 DOCTEST_INTERFACE bool operator>=(const String& lhs, const String& rhs);
510 
511 DOCTEST_INTERFACE std::ostream& operator<<(std::ostream& s, const String& in);
512 
513 namespace Color {
514  enum Enum
515  {
516  None = 0,
524 
525  Bright = 0x10,
526 
531  };
532 
533  DOCTEST_INTERFACE std::ostream& operator<<(std::ostream& s, Color::Enum code);
534 } // namespace Color
535 
536 namespace assertType {
537  enum Enum
538  {
539  // macro traits
540 
541  is_warn = 1,
542  is_check = 2,
544 
548 
549  is_fast = 64, // not checked anywhere - used just to distinguish the types
550  is_false = 128,
551  is_unary = 256,
552 
553  is_eq = 512,
554  is_ne = 1024,
555 
556  is_lt = 2048,
557  is_gt = 4096,
558 
559  is_ge = 8192,
560  is_le = 16384,
561 
562  // macro types
563 
567 
571 
575 
579 
583 
587 
591 
595 
599 
603 
607 
611 
615 
619 
623 
627 
631 
635 
639 
643 
647  };
648 } // namespace assertType
649 
651 
653 {
654  const char* m_file; // the file in which the test was registered
655  unsigned m_line; // the line where the test was registered
656  const char* m_name; // name of the test case
657  const char* m_test_suite; // the test suite in which the test was added
658  const char* m_description;
659  bool m_skip;
663  double m_timeout;
664 
667 };
668 
670 {
671  // common - for all asserts
674  const char* m_file;
675  int m_line;
676  const char* m_expr;
677  bool m_failed;
678 
679  // exception-related - for all asserts
680  bool m_threw;
682 
683  // for normal asserts
685 
686  // for specific exception-related asserts
688  const char* m_exception_type;
689 
692 };
693 
695 {
697  const char* m_file;
698  int m_line;
700 
703 };
704 
706 {
707  const char* m_name;
708  const char* m_file;
709  int m_line;
710 
711  SubcaseSignature(const char* name, const char* file, int line);
712 
713  bool operator<(const SubcaseSignature& other) const;
714 
717 };
718 
720 {
722 
724  virtual ~IContextScope();
725  virtual void stringify(std::ostream*) const = 0;
726 };
727 
729 {
730  // == parameters from the command line
731  String order_by; // how tests should be ordered
732  unsigned rand_seed; // the seed for rand ordering
733 
734  unsigned first; // the first (matching) test to be executed
735  unsigned last; // the last (matching) test to be executed
736 
737  int abort_after; // stop tests after this many failed assertions
738  int subcase_filter_levels; // apply the subcase filters for the first N levels
739 
740  bool success; // include successful assertions in output
741  bool case_sensitive; // if filtering should be case sensitive
742  bool exit; // if the program should be exited after the tests are ran/whatever
743  bool duration; // print the time duration of each test case
744  bool no_throw; // to skip exceptions-related assertion macros
745  bool no_exitcode; // if the framework should return 0 as the exitcode
746  bool no_run; // to not run the tests at all (can be done with an "*" exclude)
747  bool no_version; // to not print the version of the framework
748  bool no_colors; // if output to the console should be colorized
749  bool force_colors; // forces the use of colors even when a tty cannot be detected
750  bool no_breaks; // to not break into the debugger
751  bool no_skip; // don't skip test cases which are marked to be skipped
752  bool gnu_file_line; // if line numbers should be surrounded with :x: and not (x):
753  bool no_path_in_filenames; // if the path to files should be removed from the output
754  bool no_line_numbers; // if source code line numbers should be omitted from the output
755  bool no_skipped_summary; // don't print "skipped" in the summary !!! UNDOCUMENTED !!!
756 
757  bool help; // to print the help
758  bool version; // to print the version
759  bool count; // if only the count of matching tests is to be retreived
760  bool list_test_cases; // to list all tests matching the filters
761  bool list_test_suites; // to list all suites matching the filters
762  bool list_reporters; // lists all registered reporters
763 
766 };
767 
768 namespace detail {
769 #if defined(DOCTEST_CONFIG_TREAT_CHAR_STAR_AS_STRING) || defined(DOCTEST_CONFIG_INCLUDE_TYPE_TRAITS)
770  template <bool CONDITION, typename TYPE = void>
771  struct enable_if
772  {};
773 
774  template <typename TYPE>
775  struct enable_if<true, TYPE>
776  { typedef TYPE type; };
777 #endif // DOCTEST_CONFIG_TREAT_CHAR_STAR_AS_STRING) || DOCTEST_CONFIG_INCLUDE_TYPE_TRAITS
778 
779  template <typename T>
781  // cppcheck-suppress unusedStructMember
782  { static const bool value = false; };
783 
784  // to silence the warning "-Wzero-as-null-pointer-constant" only for gcc 5 for the Approx template ctor - pragmas don't work for it...
785  inline void* getNull() { return 0; }
786 
787  namespace has_insertion_operator_impl {
788  typedef char no;
789  typedef char yes[2];
790 
791  struct any_t
792  {
793  template <typename T>
794  // cppcheck-suppress noExplicitConstructor
796  };
797 
798  yes& testStreamable(std::ostream&);
800 
801  no operator<<(const std::ostream&, const any_t&);
802 
803  template <typename T>
805  {
806  static std::ostream& s;
807  static const DOCTEST_REF_WRAP(T) t;
808  static const bool value = sizeof(testStreamable(s << t)) == sizeof(yes);
809  };
810  } // namespace has_insertion_operator_impl
811 
812  template <typename T>
814  {};
815 
816  DOCTEST_INTERFACE void my_memcpy(void* dest, const void* src, unsigned num);
817 
820  DOCTEST_INTERFACE void freeStream(std::ostream*);
821 
822  template <bool C>
824  {
825  template <typename T>
826  static String convert(const DOCTEST_REF_WRAP(T)) {
827  return "{?}";
828  }
829  };
830 
831  template <>
832  struct StringMakerBase<true>
833  {
834  template <typename T>
835  static String convert(const DOCTEST_REF_WRAP(T) in) {
836  auto s = createStream();
837  *s << in;
838  auto result = getStreamResult(s);
839  freeStream(s);
840  return result;
841  }
842  };
843 
844  DOCTEST_INTERFACE String rawMemoryToString(const void* object, unsigned size);
845 
846  template <typename T>
848  return rawMemoryToString(&object, sizeof(object));
849  }
850 
851  template <typename T>
852  const char* type_to_string() {
853  return "<>";
854  }
855 } // namespace detail
856 
857 template <typename T>
858 struct StringMaker : public detail::StringMakerBase<detail::has_insertion_operator<T>::value>
859 {};
860 
861 template <typename T>
862 struct StringMaker<T*>
863 {
864  template <typename U>
865  static String convert(U* p) {
866  if(p)
867  return detail::rawMemoryToString(p);
868  return "NULL";
869  }
870 };
871 
872 template <typename R, typename C>
873 struct StringMaker<R C::*>
874 {
875  static String convert(R C::*p) {
876  if(p)
877  return detail::rawMemoryToString(p);
878  return "NULL";
879  }
880 };
881 
882 template <typename T>
884  return StringMaker<T>::convert(value);
885 }
886 
887 #ifdef DOCTEST_CONFIG_TREAT_CHAR_STAR_AS_STRING
888 DOCTEST_INTERFACE String toString(char* in);
889 DOCTEST_INTERFACE String toString(const char* in);
890 #endif // DOCTEST_CONFIG_TREAT_CHAR_STAR_AS_STRING
895 
900 DOCTEST_INTERFACE String toString(int short unsigned in);
904 DOCTEST_INTERFACE String toString(int long unsigned in);
906 DOCTEST_INTERFACE String toString(int long long unsigned in);
908 
910 {
911 public:
912  explicit Approx(double value);
913 
915 
916  Approx operator()(double value) const;
917 
918 #ifdef DOCTEST_CONFIG_INCLUDE_TYPE_TRAITS
919  template <typename T>
920  explicit Approx(const T& value,
921  typename detail::enable_if<std::is_constructible<double, T>::value>::type* =
922  static_cast<T*>(detail::getNull())) {
923  *this = Approx(static_cast<double>(value));
924  }
925 #endif // DOCTEST_CONFIG_INCLUDE_TYPE_TRAITS
926 
927  Approx& epsilon(double newEpsilon);
928 
929 #ifdef DOCTEST_CONFIG_INCLUDE_TYPE_TRAITS
930  template <typename T>
931  typename detail::enable_if<std::is_constructible<double, T>::value, Approx&>::type epsilon(
932  const T& newEpsilon) {
933  m_epsilon = static_cast<double>(newEpsilon);
934  return *this;
935  }
936 #endif // DOCTEST_CONFIG_INCLUDE_TYPE_TRAITS
937 
938  Approx& scale(double newScale);
939 
940 #ifdef DOCTEST_CONFIG_INCLUDE_TYPE_TRAITS
941  template <typename T>
942  typename detail::enable_if<std::is_constructible<double, T>::value, Approx&>::type scale(
943  const T& newScale) {
944  m_scale = static_cast<double>(newScale);
945  return *this;
946  }
947 #endif // DOCTEST_CONFIG_INCLUDE_TYPE_TRAITS
948 
949  // clang-format off
950  DOCTEST_INTERFACE friend bool operator==(double lhs, const Approx & rhs);
951  DOCTEST_INTERFACE friend bool operator==(const Approx & lhs, double rhs);
952  DOCTEST_INTERFACE friend bool operator!=(double lhs, const Approx & rhs);
953  DOCTEST_INTERFACE friend bool operator!=(const Approx & lhs, double rhs);
954  DOCTEST_INTERFACE friend bool operator<=(double lhs, const Approx & rhs);
955  DOCTEST_INTERFACE friend bool operator<=(const Approx & lhs, double rhs);
956  DOCTEST_INTERFACE friend bool operator>=(double lhs, const Approx & rhs);
957  DOCTEST_INTERFACE friend bool operator>=(const Approx & lhs, double rhs);
958  DOCTEST_INTERFACE friend bool operator< (double lhs, const Approx & rhs);
959  DOCTEST_INTERFACE friend bool operator< (const Approx & lhs, double rhs);
960  DOCTEST_INTERFACE friend bool operator> (double lhs, const Approx & rhs);
961  DOCTEST_INTERFACE friend bool operator> (const Approx & lhs, double rhs);
962 
964 
965 #ifdef DOCTEST_CONFIG_INCLUDE_TYPE_TRAITS
966 #define DOCTEST_APPROX_PREFIX \
967  template <typename T> friend typename detail::enable_if<std::is_constructible<double, T>::value, bool>::type
968 
969  DOCTEST_APPROX_PREFIX operator==(const T& lhs, const Approx& rhs) { return operator==(double(lhs), rhs); }
970  DOCTEST_APPROX_PREFIX operator==(const Approx& lhs, const T& rhs) { return operator==(rhs, lhs); }
971  DOCTEST_APPROX_PREFIX operator!=(const T& lhs, const Approx& rhs) { return !operator==(lhs, rhs); }
972  DOCTEST_APPROX_PREFIX operator!=(const Approx& lhs, const T& rhs) { return !operator==(rhs, lhs); }
973  DOCTEST_APPROX_PREFIX operator<=(const T& lhs, const Approx& rhs) { return double(lhs) < rhs.m_value || lhs == rhs; }
974  DOCTEST_APPROX_PREFIX operator<=(const Approx& lhs, const T& rhs) { return lhs.m_value < double(rhs) || lhs == rhs; }
975  DOCTEST_APPROX_PREFIX operator>=(const T& lhs, const Approx& rhs) { return double(lhs) > rhs.m_value || lhs == rhs; }
976  DOCTEST_APPROX_PREFIX operator>=(const Approx& lhs, const T& rhs) { return lhs.m_value > double(rhs) || lhs == rhs; }
977  DOCTEST_APPROX_PREFIX operator< (const T& lhs, const Approx& rhs) { return double(lhs) < rhs.m_value && lhs != rhs; }
978  DOCTEST_APPROX_PREFIX operator< (const Approx& lhs, const T& rhs) { return lhs.m_value < double(rhs) && lhs != rhs; }
979  DOCTEST_APPROX_PREFIX operator> (const T& lhs, const Approx& rhs) { return double(lhs) > rhs.m_value && lhs != rhs; }
980  DOCTEST_APPROX_PREFIX operator> (const Approx& lhs, const T& rhs) { return lhs.m_value > double(rhs) && lhs != rhs; }
981 #undef DOCTEST_APPROX_PREFIX
982 #endif // DOCTEST_CONFIG_INCLUDE_TYPE_TRAITS
983 
984  // clang-format on
985 
986 private:
987  double m_epsilon;
988  double m_scale;
989  double m_value;
990 };
991 
993 
994 #if !defined(DOCTEST_CONFIG_DISABLE)
995 
996 namespace detail {
997  // clang-format off
998 #ifdef DOCTEST_CONFIG_TREAT_CHAR_STAR_AS_STRING
999  template<class T> struct decay_array { typedef T type; };
1000  template<class T, unsigned N> struct decay_array<T[N]> { typedef T* type; };
1001  template<class T> struct decay_array<T[]> { typedef T* type; };
1002 
1003  template<class T> struct not_char_pointer { enum { value = 1 }; };
1004  template<> struct not_char_pointer<char*> { enum { value = 0 }; };
1005  template<> struct not_char_pointer<const char*> { enum { value = 0 }; };
1006 
1007  template<class T> struct can_use_op : public not_char_pointer<typename decay_array<T>::type> {};
1008 #endif // DOCTEST_CONFIG_TREAT_CHAR_STAR_AS_STRING
1009  // clang-format on
1010 
1012  {
1015  };
1016 
1019 
1021 
1023  {
1025  bool m_entered = false;
1026 
1027  Subcase(const char* name, const char* file, int line);
1029 
1031 
1032  operator bool() const;
1033  };
1034 
1035  template <typename L, typename R>
1036  String stringifyBinaryExpr(const DOCTEST_REF_WRAP(L) lhs, const char* op,
1037  const DOCTEST_REF_WRAP(R) rhs) {
1038  return toString(lhs) + op + toString(rhs);
1039  }
1040 
1041 #define DOCTEST_DO_BINARY_EXPRESSION_COMPARISON(op, op_str, op_macro) \
1042  template <typename R> \
1043  DOCTEST_NOINLINE Result operator op(const DOCTEST_REF_WRAP(R) rhs) { \
1044  bool res = op_macro(lhs, rhs); \
1045  if(m_at & assertType::is_false) \
1046  res = !res; \
1047  if(!res || doctest::detail::getContextOptions()->success) \
1048  return Result(res, stringifyBinaryExpr(lhs, op_str, rhs)); \
1049  return Result(res); \
1050  }
1051 
1052 #define DOCTEST_FORBIT_EXPRESSION(rt, op) \
1053  template <typename R> \
1054  rt& operator op(const R&) { \
1055  static_assert(deferred_false<R>::value, \
1056  "Expression Too Complex Please Rewrite As Binary Comparison!"); \
1057  return *this; \
1058  }
1059 
1061  {
1062  bool m_passed;
1064 
1065  Result(bool passed, const String& decomposition = String());
1066 
1069 
1070  // forbidding some expressions based on this table: http://en.cppreference.com/w/cpp/language/operator_precedence
1093  };
1094 
1095 #ifndef DOCTEST_CONFIG_NO_COMPARISON_WARNING_SUPPRESSION
1096 
1097  DOCTEST_CLANG_SUPPRESS_WARNING_PUSH
1098  DOCTEST_CLANG_SUPPRESS_WARNING("-Wsign-conversion")
1100  //DOCTEST_CLANG_SUPPRESS_WARNING("-Wdouble-promotion")
1101  //DOCTEST_CLANG_SUPPRESS_WARNING("-Wconversion")
1102  //DOCTEST_CLANG_SUPPRESS_WARNING("-Wfloat-equal")
1103 
1104  DOCTEST_GCC_SUPPRESS_WARNING_PUSH
1105  DOCTEST_GCC_SUPPRESS_WARNING("-Wsign-conversion")
1106  DOCTEST_GCC_SUPPRESS_WARNING("-Wsign-compare")
1107  //DOCTEST_GCC_SUPPRESS_WARNING("-Wdouble-promotion")
1108  //DOCTEST_GCC_SUPPRESS_WARNING("-Wconversion")
1109  //DOCTEST_GCC_SUPPRESS_WARNING("-Wfloat-equal")
1110 
1111  DOCTEST_MSVC_SUPPRESS_WARNING_PUSH
1112  // http://stackoverflow.com/questions/39479163 what's the difference between 4018 and 4389
1113  DOCTEST_MSVC_SUPPRESS_WARNING(4388) // signed/unsigned mismatch
1114  DOCTEST_MSVC_SUPPRESS_WARNING(4389) // 'operator' : signed/unsigned mismatch
1115  DOCTEST_MSVC_SUPPRESS_WARNING(4018) // 'expression' : signed/unsigned mismatch
1116  //DOCTEST_MSVC_SUPPRESS_WARNING(4805) // 'operation' : unsafe mix of type 'type' and type 'type' in operation
1117 
1118 #endif // DOCTEST_CONFIG_NO_COMPARISON_WARNING_SUPPRESSION
1119 
1120  // clang-format off
1121 #ifndef DOCTEST_CONFIG_TREAT_CHAR_STAR_AS_STRING
1122 #define DOCTEST_COMPARISON_RETURN_TYPE bool
1123 #else // DOCTEST_CONFIG_TREAT_CHAR_STAR_AS_STRING
1124 #define DOCTEST_COMPARISON_RETURN_TYPE typename enable_if<can_use_op<L>::value || can_use_op<R>::value, bool>::type
1125  inline bool eq(const char* lhs, const char* rhs) { return String(lhs) == String(rhs); }
1126  inline bool ne(const char* lhs, const char* rhs) { return String(lhs) != String(rhs); }
1127  inline bool lt(const char* lhs, const char* rhs) { return String(lhs) < String(rhs); }
1128  inline bool gt(const char* lhs, const char* rhs) { return String(lhs) > String(rhs); }
1129  inline bool le(const char* lhs, const char* rhs) { return String(lhs) <= String(rhs); }
1130  inline bool ge(const char* lhs, const char* rhs) { return String(lhs) >= String(rhs); }
1131 #endif // DOCTEST_CONFIG_TREAT_CHAR_STAR_AS_STRING
1132  // clang-format on
1133 
1134 #define DOCTEST_RELATIONAL_OP(name, op) \
1135  template <typename L, typename R> \
1136  DOCTEST_COMPARISON_RETURN_TYPE name(const DOCTEST_REF_WRAP(L) lhs, \
1137  const DOCTEST_REF_WRAP(R) rhs) { \
1138  return lhs op rhs; \
1139  }
1140 
1147 
1148 #ifndef DOCTEST_CONFIG_TREAT_CHAR_STAR_AS_STRING
1149 #define DOCTEST_CMP_EQ(l, r) l == r
1150 #define DOCTEST_CMP_NE(l, r) l != r
1151 #define DOCTEST_CMP_GT(l, r) l > r
1152 #define DOCTEST_CMP_LT(l, r) l < r
1153 #define DOCTEST_CMP_GE(l, r) l >= r
1154 #define DOCTEST_CMP_LE(l, r) l <= r
1155 #else // DOCTEST_CONFIG_TREAT_CHAR_STAR_AS_STRING
1156 #define DOCTEST_CMP_EQ(l, r) eq(l, r)
1157 #define DOCTEST_CMP_NE(l, r) ne(l, r)
1158 #define DOCTEST_CMP_GT(l, r) gt(l, r)
1159 #define DOCTEST_CMP_LT(l, r) lt(l, r)
1160 #define DOCTEST_CMP_GE(l, r) ge(l, r)
1161 #define DOCTEST_CMP_LE(l, r) le(l, r)
1162 #endif // DOCTEST_CONFIG_TREAT_CHAR_STAR_AS_STRING
1163 
1164  template <typename L>
1165  // cppcheck-suppress copyCtorAndEqOperator
1167  {
1168  L lhs;
1170 
1172  : lhs(in)
1173  , m_at(at) {}
1174 
1176  bool res = !!lhs;
1177  if(m_at & assertType::is_false)
1178  res = !res;
1179 
1180  if(!res || getContextOptions()->success)
1181  return Result(res, toString(lhs));
1182  return Result(res);
1183  }
1184 
1185  // clang-format off
1192  // clang-format on
1193 
1194  // forbidding some expressions based on this table: http://en.cppreference.com/w/cpp/language/operator_precedence
1211  // these 2 are unfortunate because they should be allowed - they have higher precedence over the comparisons, but the
1212  // ExpressionDecomposer class uses the left shift operator to capture the left operand of the binary expression...
1215  };
1216 
1217 #ifndef DOCTEST_CONFIG_NO_COMPARISON_WARNING_SUPPRESSION
1218 
1219  DOCTEST_CLANG_SUPPRESS_WARNING_POP
1220  DOCTEST_MSVC_SUPPRESS_WARNING_POP
1221  DOCTEST_GCC_SUPPRESS_WARNING_POP
1222 
1223 #endif // DOCTEST_CONFIG_NO_COMPARISON_WARNING_SUPPRESSION
1224 
1226  {
1228 
1230 
1233 
1234  // The right operator for capturing expressions is "<=" instead of "<<" (based on the operator precedence table)
1235  // but then there will be warnings from GCC about "-Wparentheses" and since "_Pragma()" is problematic this will stay for now...
1236  // https://github.com/philsquared/Catch/issues/870
1237  // https://github.com/philsquared/Catch/issues/565
1238  template <typename L>
1239  Expression_lhs<const DOCTEST_REF_WRAP(L)> operator<<(const DOCTEST_REF_WRAP(L) operand) {
1240  return Expression_lhs<const DOCTEST_REF_WRAP(L)>(operand, m_at);
1241  }
1242  };
1243 
1245  {
1246  const char* m_test_suite;
1247  const char* m_description;
1248  bool m_skip;
1252  double m_timeout;
1253 
1256 
1257  TestSuite& operator*(const char* in);
1258 
1259  template <typename T>
1260  TestSuite& operator*(const T& in) {
1261  in.fill(*this);
1262  return *this;
1263  }
1264  };
1265 
1267  {
1268  detail::funcType m_test; // a function pointer to the test case
1269 
1270  const char* m_type; // for templated test cases - gets appended to the real name
1271  int m_template_id; // an ID used to distinguish between the different versions of a templated test case
1272  String m_full_name; // contains the name (only for templated test cases!) + the template type
1273 
1274  TestCase(funcType test, const char* file, unsigned line, const TestSuite& test_suite,
1275  const char* type = "", int template_id = -1);
1276 
1278 
1279  TestCase(const TestCase& other);
1280 
1281  DOCTEST_MSVC_SUPPRESS_WARNING_WITH_PUSH(26434) // hides a non-virtual function
1282  TestCase& operator=(const TestCase& other);
1283  DOCTEST_MSVC_SUPPRESS_WARNING_POP
1284 
1285  TestCase& operator*(const char* in);
1286 
1287  template <typename T>
1288  TestCase& operator*(const T& in) {
1289  in.fill(*this);
1290  return *this;
1291  }
1292 
1293  bool operator<(const TestCase& other) const;
1294  };
1295 
1296  // forward declarations of functions used by the macros
1299 
1300  namespace binaryAssertComparison {
1301  enum Enum
1302  {
1303  eq = 0,
1308  le
1309  };
1310  } // namespace binaryAssertComparison
1311 
1312  // clang-format off
1313  template <int, class L, class R> struct RelationalComparator { bool operator()(const DOCTEST_REF_WRAP(L), const DOCTEST_REF_WRAP(R) ) const { return false; } };
1314 
1315 #define DOCTEST_BINARY_RELATIONAL_OP(n, op) \
1316  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); } };
1317  // clang-format on
1318 
1325 
1327  {
1328  ResultBuilder(assertType::Enum at, const char* file, int line, const char* expr,
1329  const char* exception_type = "");
1330 
1333 
1334  void setResult(const Result& res);
1335 
1336  template <int comparison, typename L, typename R>
1337  DOCTEST_NOINLINE void binary_assert(const DOCTEST_REF_WRAP(L) lhs,
1338  const DOCTEST_REF_WRAP(R) rhs) {
1339  m_failed = !RelationalComparator<comparison, L, R>()(lhs, rhs);
1340  if(m_failed || getContextOptions()->success)
1341  m_decomposition = stringifyBinaryExpr(lhs, ", ", rhs);
1342  }
1343 
1344  template <typename L>
1345  DOCTEST_NOINLINE void unary_assert(const DOCTEST_REF_WRAP(L) val) {
1346  m_failed = !val;
1347 
1348  if(m_at & assertType::is_false)
1349  m_failed = !m_failed;
1350 
1351  if(m_failed || getContextOptions()->success)
1352  m_decomposition = toString(val);
1353  }
1354 
1356 
1357  bool log();
1358  void react() const;
1359  };
1360 
1361  namespace assertAction {
1362  enum Enum
1363  {
1364  nothing = 0,
1366  shouldthrow = 2
1367  };
1368  } // namespace assertAction
1369 
1370  template <int comparison, typename L, typename R>
1371  DOCTEST_NOINLINE int fast_binary_assert(assertType::Enum at, const char* file, int line,
1372  const char* expr, const DOCTEST_REF_WRAP(L) lhs,
1373  const DOCTEST_REF_WRAP(R) rhs) {
1374  ResultBuilder rb(at, file, line, expr);
1375 
1377 
1378  if(rb.m_failed || getContextOptions()->success)
1379  rb.m_decomposition = stringifyBinaryExpr(lhs, ", ", rhs);
1380 
1381  int res = 0;
1382 
1383  if(rb.log())
1384  res |= assertAction::dbgbreak;
1385 
1386  if(rb.m_failed && checkIfShouldThrow(at))
1388 
1389 #ifdef DOCTEST_CONFIG_SUPER_FAST_ASSERTS
1390  // #########################################################################################
1391  // IF THE DEBUGGER BREAKS HERE - GO 1 LEVEL UP IN THE CALLSTACK TO SEE THE FAILING ASSERTION
1392  // THIS IS THE EFFECT OF HAVING 'DOCTEST_CONFIG_SUPER_FAST_ASSERTS' DEFINED
1393  // #########################################################################################
1394  if(res & assertAction::dbgbreak)
1397 #endif // DOCTEST_CONFIG_SUPER_FAST_ASSERTS
1398 
1399  return res;
1400  }
1401 
1402  template <typename L>
1403  DOCTEST_NOINLINE int fast_unary_assert(assertType::Enum at, const char* file, int line,
1404  const char* val_str, const DOCTEST_REF_WRAP(L) val) {
1405  ResultBuilder rb(at, file, line, val_str);
1406 
1407  rb.m_failed = !val;
1408 
1409  if(at & assertType::is_false)
1410  rb.m_failed = !rb.m_failed;
1411 
1412  if(rb.m_failed || getContextOptions()->success)
1413  rb.m_decomposition = toString(val);
1414 
1415  int res = 0;
1416 
1417  if(rb.log())
1418  res |= assertAction::dbgbreak;
1419 
1420  if(rb.m_failed && checkIfShouldThrow(at))
1422 
1423 #ifdef DOCTEST_CONFIG_SUPER_FAST_ASSERTS
1424  // #########################################################################################
1425  // IF THE DEBUGGER BREAKS HERE - GO 1 LEVEL UP IN THE CALLSTACK TO SEE THE FAILING ASSERTION
1426  // THIS IS THE EFFECT OF HAVING 'DOCTEST_CONFIG_SUPER_FAST_ASSERTS' DEFINED
1427  // #########################################################################################
1428  if(res & assertAction::dbgbreak)
1431 #endif // DOCTEST_CONFIG_SUPER_FAST_ASSERTS
1432 
1433  return res;
1434  }
1435 
1437  {
1439 
1442  virtual bool translate(String&) const = 0;
1443  };
1444 
1445  template <typename T>
1447  {
1448  public:
1449  explicit ExceptionTranslator(String (*translateFunction)(T))
1450  : m_translateFunction(translateFunction) {}
1451 
1452  bool translate(String& res) const {
1453 #ifndef DOCTEST_CONFIG_NO_EXCEPTIONS
1454  try {
1455  throw;
1456  // cppcheck-suppress catchExceptionByValue
1457  } catch(T ex) { // NOLINT
1458  res = m_translateFunction(ex);
1459  return true;
1460  } catch(...) {}
1461 #endif // DOCTEST_CONFIG_NO_EXCEPTIONS
1462  ((void)res); // to silence -Wunused-parameter
1463  return false;
1464  }
1465 
1466  private:
1467  String (*m_translateFunction)(T);
1468  };
1469 
1471  const IExceptionTranslator* translateFunction);
1472 
1473  // FIX FOR VISUAL STUDIO VERSIONS PRIOR TO 2015 - they failed to compile the call to operator<< with
1474  // std::ostream passed as a reference noting that there is a use of an undefined type (which there isn't)
1475  DOCTEST_INTERFACE void writeStringToStream(std::ostream* s, const String& str);
1476 
1477  template <bool C>
1479  {
1480  template <typename T>
1481  static void convert(std::ostream* s, const T& in) {
1482  writeStringToStream(s, toString(in));
1483  }
1484 
1485  // always treat char* as a string in this context - no matter
1486  // if DOCTEST_CONFIG_TREAT_CHAR_STAR_AS_STRING is defined
1487  static void convert(std::ostream* s, const char* in) { writeStringToStream(s, String(in)); }
1488  };
1489 
1490  template <>
1491  struct StringStreamBase<true>
1492  {
1493  template <typename T>
1494  static void convert(std::ostream* s, const T& in) {
1495  *s << in;
1496  }
1497  };
1498 
1499  template <typename T>
1500  struct StringStream : public StringStreamBase<has_insertion_operator<T>::value>
1501  {};
1502 
1503  template <typename T>
1504  void toStream(std::ostream* s, const T& value) {
1505  StringStream<T>::convert(s, value);
1506  }
1507 
1508 #ifdef DOCTEST_CONFIG_TREAT_CHAR_STAR_AS_STRING
1509  DOCTEST_INTERFACE void toStream(std::ostream* s, char* in);
1510  DOCTEST_INTERFACE void toStream(std::ostream* s, const char* in);
1511 #endif // DOCTEST_CONFIG_TREAT_CHAR_STAR_AS_STRING
1512  DOCTEST_INTERFACE void toStream(std::ostream* s, bool in);
1513  DOCTEST_INTERFACE void toStream(std::ostream* s, float in);
1514  DOCTEST_INTERFACE void toStream(std::ostream* s, double in);
1515  DOCTEST_INTERFACE void toStream(std::ostream* s, double long in);
1516 
1517  DOCTEST_INTERFACE void toStream(std::ostream* s, char in);
1518  DOCTEST_INTERFACE void toStream(std::ostream* s, char signed in);
1519  DOCTEST_INTERFACE void toStream(std::ostream* s, char unsigned in);
1520  DOCTEST_INTERFACE void toStream(std::ostream* s, int short in);
1521  DOCTEST_INTERFACE void toStream(std::ostream* s, int short unsigned in);
1522  DOCTEST_INTERFACE void toStream(std::ostream* s, int in);
1523  DOCTEST_INTERFACE void toStream(std::ostream* s, int unsigned in);
1524  DOCTEST_INTERFACE void toStream(std::ostream* s, int long in);
1525  DOCTEST_INTERFACE void toStream(std::ostream* s, int long unsigned in);
1526  DOCTEST_INTERFACE void toStream(std::ostream* s, int long long in);
1527  DOCTEST_INTERFACE void toStream(std::ostream* s, int long long unsigned in);
1528 
1530  {
1531  friend class ContextScope;
1532 
1534  {
1537  virtual ~ICapture();
1538  virtual void toStream(std::ostream*) const = 0;
1539  };
1540 
1541  template <typename T>
1542  struct Capture : public ICapture
1543  {
1544  const T* capture;
1545 
1546  explicit Capture(const T* in)
1547  : capture(in) {}
1548  void toStream(std::ostream* s) const override { detail::toStream(s, *capture); }
1549  };
1550 
1552  {
1553  char buf[sizeof(Capture<char>)] DOCTEST_ALIGNMENT(
1554  2 * sizeof(void*)); // place to construct a Capture<T>
1555 
1558  };
1559 
1561  {
1564 
1567  };
1568 
1570  int numCaptures = 0;
1571  Node* head = 0;
1572  Node* tail = 0;
1573 
1575 
1577 
1578  void stringify(std::ostream* s) const;
1579 
1580  public:
1583 
1584  template <typename T>
1586  Capture<T> temp(&in);
1587 
1588  // construct either on stack or on heap
1589  // copy the bytes for the whole object - including the vtable because we cant construct
1590  // the object directly in the buffer using placement new - need the <new> header...
1591  if(numCaptures < DOCTEST_CONFIG_NUM_CAPTURES_ON_STACK) {
1592  my_memcpy(stackChunks[numCaptures].buf, &temp, sizeof(Chunk));
1593  } else {
1594  auto curr = new Node;
1595  curr->next = 0;
1596  if(tail) {
1597  tail->next = curr;
1598  tail = curr;
1599  } else {
1600  head = tail = curr;
1601  }
1602 
1603  my_memcpy(tail->chunk.buf, &temp, sizeof(Chunk));
1604  }
1605  ++numCaptures;
1606  return *this;
1607  }
1608 
1609  template <typename T>
1611  static_assert(deferred_false<T>::value,
1612  "Cannot pass temporaries or rvalues to the streaming operator because it "
1613  "caches pointers to the passed objects for lazy evaluation!");
1614  return *this;
1615  }
1616  };
1617 
1619  {
1621 
1622  public:
1623  explicit ContextScope(ContextBuilder& temp);
1624 
1626 
1628 
1629  void stringify(std::ostream* s) const;
1630  };
1631 
1633  {
1634  std::ostream* m_stream;
1635 
1636  MessageBuilder(const char* file, int line, assertType::Enum severity);
1637  MessageBuilder() = delete;
1639 
1641 
1642  template <typename T>
1644  toStream(m_stream, in);
1645  return *this;
1646  }
1647 
1648  bool log();
1649  void react();
1650  };
1651 } // namespace detail
1652 
1653 #define DOCTEST_DEFINE_DECORATOR(name, type, def) \
1654  struct name \
1655  { \
1656  type data; \
1657  name(type in = def) \
1658  : data(in) {} \
1659  void fill(detail::TestCase& state) const { state.DOCTEST_CAT(m_, name) = data; } \
1660  void fill(detail::TestSuite& state) const { state.DOCTEST_CAT(m_, name) = data; } \
1661  }
1662 
1670 
1671 template <typename T>
1672 int registerExceptionTranslator(String (*translateFunction)(T)) {
1673  DOCTEST_CLANG_SUPPRESS_WARNING_WITH_PUSH("-Wexit-time-destructors")
1674  static detail::ExceptionTranslator<T> exceptionTranslator(translateFunction);
1675  DOCTEST_CLANG_SUPPRESS_WARNING_POP
1676  detail::registerExceptionTranslatorImpl(&exceptionTranslator);
1677  return 0;
1678 }
1679 
1680 } // namespace doctest
1681 
1682 // in a separate namespace outside of doctest because the DOCTEST_TEST_SUITE macro
1683 // introduces an anonymous namespace in which getCurrentTestSuite gets overridden
1686 } // namespace doctest_detail_test_suite_ns
1687 
1688 namespace doctest {
1689 #else // DOCTEST_CONFIG_DISABLE
1690 template <typename T>
1691 int registerExceptionTranslator(String (*)(T)) {
1692  return 0;
1693 }
1694 #endif // DOCTEST_CONFIG_DISABLE
1695 
1697 
1698 namespace detail {
1699  struct ContextState;
1700 } // namespace detail
1701 
1702 // cppcheck-suppress noCopyConstructor
1704 {
1705  detail::ContextState* p;
1706 
1707  void parseArgs(int argc, const char* const* argv, bool withDefaults = false);
1708 
1709 public:
1710  explicit Context(int argc = 0, const char* const* argv = 0);
1711 
1713 
1715 
1716  void applyCommandLine(int argc, const char* const* argv);
1717 
1718  void addFilter(const char* filter, const char* value);
1720  void setOption(const char* option, int value);
1721  void setOption(const char* option, const char* value);
1722 
1723  bool shouldExit();
1724 
1725  int run();
1726 };
1727 
1728 namespace TestCaseFailureReason {
1729  enum Enum
1730  {
1731  None = 0,
1732  AssertFailure = 1, // an assertion has failed in the test case
1733  Exception = 2, // test case threw an exception
1734  Crash = 4, // a crash...
1735  TooManyFailedAsserts = 8, // the abort-after option
1736  Timeout = 16, // see the timeout decorator
1737  ShouldHaveFailedButDidnt = 32, // see the should_fail decorator
1738  ShouldHaveFailedAndDid = 64, // see the should_fail decorator
1739  DidntFailExactlyNumTimes = 128, // see the expected_failures decorator
1740  FailedExactlyNumTimes = 256, // see the expected_failures decorator
1741  CouldHaveFailedAndDid = 512 // see the may_fail decorator
1742  };
1743 } // namespace TestCaseFailureReason
1744 
1746 {
1750  int failure_flags; // use TestCaseFailureReason::Enum
1752  bool should_reenter; // means we are not done with the test case because of subcases
1753 
1756 };
1757 
1759 {
1760  unsigned numTestCases;
1766 
1769 };
1770 
1772 {
1773  // called when the whole test run starts (safe to cache a pointer to the input)
1774  virtual void test_run_start(const ContextOptions&) = 0;
1775  // called when the whole test run ends (caching a pointer to the input doesn't make sense here)
1776  virtual void test_run_end(const TestRunStats&) = 0;
1777 
1778  // called when a test case is started (safe to cache a pointer to the input)
1779  virtual void test_case_start(const TestCaseData&) = 0;
1780  // called when a test case has ended - could be re-entered if more subcases have to be
1781  // traversed - check CurrentTestCaseStats::should_reenter (caching a pointer to the input doesn't make sense here)
1782  virtual void test_case_end(const CurrentTestCaseStats&) = 0;
1783 
1784  // called whenever a subcase is entered (don't cache pointers to the input)
1785  virtual void subcase_start(const SubcaseSignature&) = 0;
1786  // called whenever a subcase is exited (don't cache pointers to the input)
1787  virtual void subcase_end(const SubcaseSignature&) = 0;
1788 
1789  // called for each assert (don't cache pointers to the input)
1790  virtual void log_assert(const AssertData&) = 0;
1791  // called for each message (don't cache pointers to the input)
1792  virtual void log_message(const MessageData&) = 0;
1793 
1794  // called when a test case is skipped either because it doesn't pass the filters, has a skip decorator
1795  // or isn't in the execution range (between first and last) (safe to cache a pointer to the input)
1796  virtual void test_case_skipped(const TestCaseData&) = 0;
1797 
1798  // doctest will not be managing the lifetimes of reporters given to it but this would still be nice to have
1799  virtual ~IReporter();
1800 
1801  // can obtain all currently active contexts and stringify them if one wishes to do so
1803  static const IContextScope* const* get_active_contexts();
1804 
1805  // can iterate through contexts which have been stringified automatically in their destructors when an exception has been thrown
1808 };
1809 
1810 int registerReporter(const char* name, int priority, IReporter* r);
1811 
1812 } // namespace doctest
1813 
1814 // if registering is not disabled
1815 #if !defined(DOCTEST_CONFIG_DISABLE)
1816 
1817 #define DOCTEST_EXPAND_VA_ARGS(...) __VA_ARGS__
1818 
1819 // common code in asserts - for convenience
1820 #define DOCTEST_ASSERT_LOG_AND_REACT(b) \
1821  if(b.log()) \
1822  DOCTEST_BREAK_INTO_DEBUGGER(); \
1823  b.react()
1824 
1825 #ifdef DOCTEST_CONFIG_NO_TRY_CATCH_IN_ASSERTS
1826 #define DOCTEST_WRAP_IN_TRY(x) x;
1827 #else // DOCTEST_CONFIG_NO_TRY_CATCH_IN_ASSERTS
1828 #define DOCTEST_WRAP_IN_TRY(x) \
1829  try { \
1830  x; \
1831  } catch(...) { _DOCTEST_RB.unexpectedExceptionOccurred(); }
1832 #endif // DOCTEST_CONFIG_NO_TRY_CATCH_IN_ASSERTS
1833 
1834 // registers the test by initializing a dummy var with a function
1835 #define DOCTEST_REGISTER_FUNCTION(f, decorators) \
1836  DOCTEST_GLOBAL_NO_WARNINGS(DOCTEST_ANONYMOUS(_DOCTEST_ANON_VAR_)) = doctest::detail::regTest( \
1837  doctest::detail::TestCase(f, __FILE__, __LINE__, \
1838  doctest_detail_test_suite_ns::getCurrentTestSuite()) * \
1839  decorators); \
1840  DOCTEST_GLOBAL_NO_WARNINGS_END()
1841 
1842 #define DOCTEST_IMPLEMENT_FIXTURE(der, base, func, decorators) \
1843  namespace { \
1844  struct der : public base \
1845  { \
1846  void f(); \
1847  }; \
1848  static void func() { \
1849  der v; \
1850  v.f(); \
1851  } \
1852  DOCTEST_REGISTER_FUNCTION(func, decorators) \
1853  } \
1854  inline DOCTEST_NOINLINE void der::f()
1855 
1856 #define DOCTEST_CREATE_AND_REGISTER_FUNCTION(f, decorators) \
1857  static void f(); \
1858  DOCTEST_REGISTER_FUNCTION(f, decorators) \
1859  static void f()
1860 
1861 // for registering tests
1862 #define DOCTEST_TEST_CASE(decorators) \
1863  DOCTEST_CREATE_AND_REGISTER_FUNCTION(DOCTEST_ANONYMOUS(_DOCTEST_ANON_FUNC_), decorators)
1864 
1865 // for registering tests with a fixture
1866 #define DOCTEST_TEST_CASE_FIXTURE(c, decorators) \
1867  DOCTEST_IMPLEMENT_FIXTURE(DOCTEST_ANONYMOUS(_DOCTEST_ANON_CLASS_), c, \
1868  DOCTEST_ANONYMOUS(_DOCTEST_ANON_FUNC_), decorators)
1869 
1870 // for converting types to strings without the <typeinfo> header and demangling
1871 #define DOCTEST_TYPE_TO_STRING_IMPL(...) \
1872  template <> \
1873  inline const char* type_to_string<__VA_ARGS__>() { \
1874  return "<" #__VA_ARGS__ ">"; \
1875  }
1876 #define DOCTEST_TYPE_TO_STRING(...) \
1877  namespace doctest { namespace detail { \
1878  DOCTEST_TYPE_TO_STRING_IMPL(__VA_ARGS__) \
1879  } \
1880  } \
1881  typedef int DOCTEST_ANONYMOUS(_DOCTEST_ANON_FOR_SEMICOLON_)
1882 
1883 // for typed tests
1884 #define DOCTEST_REGISTER_TYPED_TEST_CASE_IMPL(func, type, decorators, idx) \
1885  doctest::detail::regTest( \
1886  doctest::detail::TestCase(func, __FILE__, __LINE__, \
1887  doctest_detail_test_suite_ns::getCurrentTestSuite(), \
1888  doctest::detail::type_to_string<type>(), idx) * \
1889  decorators)
1890 
1891 #define DOCTEST_TEST_CASE_TEMPLATE_DEFINE_IMPL(dec, T, id, anon) \
1892  template <typename T> \
1893  inline void anon(); \
1894  DOCTEST_CLANG_SUPPRESS_WARNING_PUSH \
1895  DOCTEST_CLANG_SUPPRESS_WARNING("-Wc++98-compat") \
1896  DOCTEST_CLANG_SUPPRESS_WARNING("-Wc++98-compat-pedantic") \
1897  template <typename Type, typename... Rest> \
1898  struct DOCTEST_CAT(id, ITERATOR) \
1899  { \
1900  DOCTEST_CAT(id, ITERATOR)(int line, int index) { \
1901  DOCTEST_REGISTER_TYPED_TEST_CASE_IMPL(anon<Type>, Type, dec, line * 1000 + index); \
1902  DOCTEST_CAT(id, ITERATOR)<Rest...>(line, index + 1); \
1903  } \
1904  }; \
1905  DOCTEST_CLANG_SUPPRESS_WARNING_POP \
1906  template <typename Type> \
1907  struct DOCTEST_CAT(id, ITERATOR)<Type> \
1908  { \
1909  DOCTEST_CAT(id, ITERATOR)(int line, int index) { \
1910  DOCTEST_REGISTER_TYPED_TEST_CASE_IMPL(anon<Type>, Type, dec, line * 1000 + index); \
1911  } \
1912  }
1913 
1914 #define DOCTEST_TEST_CASE_TEMPLATE_DEFINE_IMPL_PROXY(dec, T, id, anon) \
1915  DOCTEST_TEST_CASE_TEMPLATE_DEFINE_IMPL(dec, T, id, anon); \
1916  template <typename T> \
1917  inline void anon()
1918 
1919 #define DOCTEST_TEST_CASE_TEMPLATE_DEFINE(dec, T, id) \
1920  DOCTEST_TEST_CASE_TEMPLATE_DEFINE_IMPL_PROXY(dec, T, id, DOCTEST_ANONYMOUS(_DOCTEST_ANON_TMP_))
1921 
1922 #define DOCTEST_TEST_CASE_TEMPLATE_INSTANTIATE_IMPL(id, anon, ...) \
1923  DOCTEST_CLANG_SUPPRESS_WARNING_PUSH \
1924  DOCTEST_CLANG_SUPPRESS_WARNING("-Wc++98-compat") \
1925  DOCTEST_CLANG_SUPPRESS_WARNING("-Wc++98-compat-pedantic") \
1926  DOCTEST_GLOBAL_NO_WARNINGS(DOCTEST_CAT(anon, DUMMY)) = []() { \
1927  DOCTEST_CAT(id, ITERATOR)<__VA_ARGS__> DOCTEST_UNUSED DOCTEST_CAT(anon, inner_dummy)( \
1928  __LINE__, 0); \
1929  return 0; \
1930  }(); \
1931  DOCTEST_GLOBAL_NO_WARNINGS_END() \
1932  DOCTEST_CLANG_SUPPRESS_WARNING_POP
1933 
1934 #define DOCTEST_TEST_CASE_TEMPLATE_INSTANTIATE(id, ...) \
1935  DOCTEST_TEST_CASE_TEMPLATE_INSTANTIATE_IMPL(id, DOCTEST_ANONYMOUS(_DOCTEST_ANON_TMP_), \
1936  __VA_ARGS__) \
1937  typedef int DOCTEST_ANONYMOUS(_DOCTEST_ANON_FOR_SEMICOLON_)
1938 
1939 #define DOCTEST_TEST_CASE_TEMPLATE_IMPL(dec, T, anon, ...) \
1940  DOCTEST_TEST_CASE_TEMPLATE_DEFINE_IMPL_PROXY(dec, T, anon, anon); \
1941  DOCTEST_TEST_CASE_TEMPLATE_INSTANTIATE_IMPL(anon, anon, __VA_ARGS__) \
1942  template <typename T> \
1943  inline void anon()
1944 
1945 #define DOCTEST_TEST_CASE_TEMPLATE(dec, T, ...) \
1946  DOCTEST_TEST_CASE_TEMPLATE_IMPL(dec, T, DOCTEST_ANONYMOUS(_DOCTEST_ANON_TMP_), __VA_ARGS__)
1947 
1948 // for subcases
1949 #define DOCTEST_SUBCASE(name) \
1950  if(DOCTEST_CLANG_SUPPRESS_WARNING_WITH_PUSH("-Wc++98-compat-bind-to-temporary-copy") \
1951  const doctest::detail::Subcase & \
1952  DOCTEST_ANONYMOUS(_DOCTEST_ANON_SUBCASE_) DOCTEST_UNUSED = \
1953  doctest::detail::Subcase(name, __FILE__, __LINE__) \
1954  DOCTEST_CLANG_SUPPRESS_WARNING_POP)
1955 
1956 // for grouping tests in test suites by using code blocks
1957 #define DOCTEST_TEST_SUITE_IMPL(decorators, ns_name) \
1958  namespace ns_name { namespace doctest_detail_test_suite_ns { \
1959  static DOCTEST_NOINLINE doctest::detail::TestSuite& getCurrentTestSuite() { \
1960  DOCTEST_MSVC_SUPPRESS_WARNING_WITH_PUSH(4640) \
1961  DOCTEST_CLANG_SUPPRESS_WARNING_WITH_PUSH("-Wexit-time-destructors") \
1962  static doctest::detail::TestSuite data; \
1963  static bool inited = false; \
1964  DOCTEST_MSVC_SUPPRESS_WARNING_POP \
1965  DOCTEST_CLANG_SUPPRESS_WARNING_POP \
1966  if(!inited) { \
1967  data* decorators; \
1968  inited = true; \
1969  } \
1970  return data; \
1971  } \
1972  } \
1973  } \
1974  namespace ns_name
1975 
1976 #define DOCTEST_TEST_SUITE(decorators) \
1977  DOCTEST_TEST_SUITE_IMPL(decorators, DOCTEST_ANONYMOUS(_DOCTEST_ANON_SUITE_))
1978 
1979 // for starting a testsuite block
1980 #define DOCTEST_TEST_SUITE_BEGIN(decorators) \
1981  DOCTEST_GLOBAL_NO_WARNINGS(DOCTEST_ANONYMOUS(_DOCTEST_ANON_VAR_)) = \
1982  doctest::detail::setTestSuite(doctest::detail::TestSuite() * decorators); \
1983  DOCTEST_GLOBAL_NO_WARNINGS_END() \
1984  typedef int DOCTEST_ANONYMOUS(_DOCTEST_ANON_FOR_SEMICOLON_)
1985 
1986 // for ending a testsuite block
1987 #define DOCTEST_TEST_SUITE_END \
1988  DOCTEST_GLOBAL_NO_WARNINGS(DOCTEST_ANONYMOUS(_DOCTEST_ANON_VAR_)) = \
1989  doctest::detail::setTestSuite(doctest::detail::TestSuite() * ""); \
1990  DOCTEST_GLOBAL_NO_WARNINGS_END() \
1991  typedef int DOCTEST_ANONYMOUS(_DOCTEST_ANON_FOR_SEMICOLON_)
1992 
1993 // for registering exception translators
1994 #define DOCTEST_REGISTER_EXCEPTION_TRANSLATOR_IMPL(translatorName, signature) \
1995  inline doctest::String translatorName(signature); \
1996  DOCTEST_GLOBAL_NO_WARNINGS(DOCTEST_ANONYMOUS(_DOCTEST_ANON_TRANSLATOR_)) = \
1997  doctest::registerExceptionTranslator(translatorName); \
1998  DOCTEST_GLOBAL_NO_WARNINGS_END() \
1999  doctest::String translatorName(signature)
2000 
2001 #define DOCTEST_REGISTER_EXCEPTION_TRANSLATOR(signature) \
2002  DOCTEST_REGISTER_EXCEPTION_TRANSLATOR_IMPL(DOCTEST_ANONYMOUS(_DOCTEST_ANON_TRANSLATOR_), \
2003  signature)
2004 
2005 // for registering
2006 #define DOCTEST_REGISTER_REPORTER(name, priority, reporter) \
2007  DOCTEST_GLOBAL_NO_WARNINGS(DOCTEST_ANONYMOUS(_DOCTEST_ANON_REPORTER_)) = \
2008  doctest::registerReporter(name, priority, reporter); \
2009  DOCTEST_GLOBAL_NO_WARNINGS_END() typedef int DOCTEST_ANONYMOUS(_DOCTEST_ANON_FOR_SEMICOLON_)
2010 
2011 // for logging
2012 #define DOCTEST_INFO(x) \
2013  doctest::detail::ContextScope DOCTEST_ANONYMOUS(_DOCTEST_CAPTURE_)( \
2014  doctest::detail::ContextBuilder() << x)
2015 #define DOCTEST_CAPTURE(x) DOCTEST_INFO(#x " := " << x)
2016 
2017 #define DOCTEST_ADD_AT_IMPL(type, file, line, mb, x) \
2018  do { \
2019  doctest::detail::MessageBuilder mb(file, line, doctest::assertType::type); \
2020  mb << x; \
2021  DOCTEST_ASSERT_LOG_AND_REACT(mb); \
2022  } while((void)0, 0)
2023 
2024 // clang-format off
2025 #define DOCTEST_ADD_MESSAGE_AT(file, line, x) DOCTEST_ADD_AT_IMPL(is_warn, file, line, DOCTEST_ANONYMOUS(_DOCTEST_MESSAGE_), x)
2026 #define DOCTEST_ADD_FAIL_CHECK_AT(file, line, x) DOCTEST_ADD_AT_IMPL(is_check, file, line, DOCTEST_ANONYMOUS(_DOCTEST_MESSAGE_), x)
2027 #define DOCTEST_ADD_FAIL_AT(file, line, x) DOCTEST_ADD_AT_IMPL(is_require, file, line, DOCTEST_ANONYMOUS(_DOCTEST_MESSAGE_), x)
2028 // clang-format on
2029 
2030 #define DOCTEST_MESSAGE(x) DOCTEST_ADD_MESSAGE_AT(__FILE__, __LINE__, x)
2031 #define DOCTEST_FAIL_CHECK(x) DOCTEST_ADD_FAIL_CHECK_AT(__FILE__, __LINE__, x)
2032 #define DOCTEST_FAIL(x) DOCTEST_ADD_FAIL_AT(__FILE__, __LINE__, x)
2033 
2034 #if __cplusplus >= 201402L || (DOCTEST_MSVC >= DOCTEST_COMPILER(19, 10, 0))
2035 template <class T, T x>
2036 constexpr T to_lvalue = x;
2037 #define DOCTEST_TO_LVALUE(...) to_lvalue<decltype(__VA_ARGS__), __VA_ARGS__>
2038 #else
2039 #define DOCTEST_TO_LVALUE(...) TO_LVALUE_CAN_BE_USED_ONLY_IN_CPP14_MODE_OR_WITH_VS_2017_OR_NEWER
2040 #endif // TO_LVALUE hack for logging macros like INFO()
2041 
2042 #define DOCTEST_ASSERT_IMPLEMENT_2(assert_type, ...) \
2043  DOCTEST_CLANG_SUPPRESS_WARNING_WITH_PUSH("-Woverloaded-shift-op-parentheses") \
2044  doctest::detail::ResultBuilder _DOCTEST_RB(doctest::assertType::assert_type, __FILE__, \
2045  __LINE__, DOCTEST_TOSTR(__VA_ARGS__)); \
2046  DOCTEST_WRAP_IN_TRY(_DOCTEST_RB.setResult( \
2047  doctest::detail::ExpressionDecomposer(doctest::assertType::assert_type) \
2048  << __VA_ARGS__)) \
2049  DOCTEST_ASSERT_LOG_AND_REACT(_DOCTEST_RB) \
2050  DOCTEST_CLANG_SUPPRESS_WARNING_POP
2051 
2052 #define DOCTEST_ASSERT_IMPLEMENT_1(assert_type, ...) \
2053  do { \
2054  DOCTEST_ASSERT_IMPLEMENT_2(assert_type, __VA_ARGS__); \
2055  } while((void)0, 0)
2056 
2057 #define DOCTEST_WARN(...) DOCTEST_ASSERT_IMPLEMENT_1(DT_WARN, __VA_ARGS__)
2058 #define DOCTEST_CHECK(...) DOCTEST_ASSERT_IMPLEMENT_1(DT_CHECK, __VA_ARGS__)
2059 #define DOCTEST_REQUIRE(...) DOCTEST_ASSERT_IMPLEMENT_1(DT_REQUIRE, __VA_ARGS__)
2060 #define DOCTEST_WARN_FALSE(...) DOCTEST_ASSERT_IMPLEMENT_1(DT_WARN_FALSE, __VA_ARGS__)
2061 #define DOCTEST_CHECK_FALSE(...) DOCTEST_ASSERT_IMPLEMENT_1(DT_CHECK_FALSE, __VA_ARGS__)
2062 #define DOCTEST_REQUIRE_FALSE(...) DOCTEST_ASSERT_IMPLEMENT_1(DT_REQUIRE_FALSE, __VA_ARGS__)
2063 
2064 // clang-format off
2065 #define DOCTEST_WARN_MESSAGE(cond, msg) do { DOCTEST_INFO(msg); DOCTEST_ASSERT_IMPLEMENT_2(DT_WARN, cond); } while((void)0, 0)
2066 #define DOCTEST_CHECK_MESSAGE(cond, msg) do { DOCTEST_INFO(msg); DOCTEST_ASSERT_IMPLEMENT_2(DT_CHECK, cond); } while((void)0, 0)
2067 #define DOCTEST_REQUIRE_MESSAGE(cond, msg) do { DOCTEST_INFO(msg); DOCTEST_ASSERT_IMPLEMENT_2(DT_REQUIRE, cond); } while((void)0, 0)
2068 #define DOCTEST_WARN_FALSE_MESSAGE(cond, msg) do { DOCTEST_INFO(msg); DOCTEST_ASSERT_IMPLEMENT_2(DT_WARN_FALSE, cond); } while((void)0, 0)
2069 #define DOCTEST_CHECK_FALSE_MESSAGE(cond, msg) do { DOCTEST_INFO(msg); DOCTEST_ASSERT_IMPLEMENT_2(DT_CHECK_FALSE, cond); } while((void)0, 0)
2070 #define DOCTEST_REQUIRE_FALSE_MESSAGE(cond, msg) do { DOCTEST_INFO(msg); DOCTEST_ASSERT_IMPLEMENT_2(DT_REQUIRE_FALSE, cond); } while((void)0, 0)
2071 // clang-format on
2072 
2073 #define DOCTEST_ASSERT_THROWS(expr, assert_type) \
2074  do { \
2075  if(!doctest::detail::getContextOptions()->no_throw) { \
2076  doctest::detail::ResultBuilder _DOCTEST_RB(doctest::assertType::assert_type, __FILE__, \
2077  __LINE__, #expr); \
2078  try { \
2079  expr; \
2080  } catch(...) { _DOCTEST_RB.m_threw = true; } \
2081  DOCTEST_ASSERT_LOG_AND_REACT(_DOCTEST_RB); \
2082  } \
2083  } while((void)0, 0)
2084 
2085 #define DOCTEST_ASSERT_THROWS_AS(expr, assert_type, ...) \
2086  do { \
2087  if(!doctest::detail::getContextOptions()->no_throw) { \
2088  doctest::detail::ResultBuilder _DOCTEST_RB(doctest::assertType::assert_type, __FILE__, \
2089  __LINE__, #expr, \
2090  DOCTEST_TOSTR(__VA_ARGS__)); \
2091  try { \
2092  expr; \
2093  } catch(const __VA_ARGS__&) { \
2094  _DOCTEST_RB.m_threw = true; \
2095  _DOCTEST_RB.m_threw_as = true; \
2096  } catch(...) { _DOCTEST_RB.unexpectedExceptionOccurred(); } \
2097  DOCTEST_ASSERT_LOG_AND_REACT(_DOCTEST_RB); \
2098  } \
2099  } while((void)0, 0)
2100 
2101 #define DOCTEST_ASSERT_NOTHROW(expr, assert_type) \
2102  do { \
2103  if(!doctest::detail::getContextOptions()->no_throw) { \
2104  doctest::detail::ResultBuilder _DOCTEST_RB(doctest::assertType::assert_type, __FILE__, \
2105  __LINE__, #expr); \
2106  try { \
2107  expr; \
2108  } catch(...) { _DOCTEST_RB.unexpectedExceptionOccurred(); } \
2109  DOCTEST_ASSERT_LOG_AND_REACT(_DOCTEST_RB); \
2110  } \
2111  } while((void)0, 0)
2112 
2113 // clang-format off
2114 #define DOCTEST_WARN_THROWS(expr) DOCTEST_ASSERT_THROWS(expr, DT_WARN_THROWS)
2115 #define DOCTEST_CHECK_THROWS(expr) DOCTEST_ASSERT_THROWS(expr, DT_CHECK_THROWS)
2116 #define DOCTEST_REQUIRE_THROWS(expr) DOCTEST_ASSERT_THROWS(expr, DT_REQUIRE_THROWS)
2117 
2118 #define DOCTEST_WARN_THROWS_AS(expr, ...) DOCTEST_ASSERT_THROWS_AS(expr, DT_WARN_THROWS_AS, __VA_ARGS__)
2119 #define DOCTEST_CHECK_THROWS_AS(expr, ...) DOCTEST_ASSERT_THROWS_AS(expr, DT_CHECK_THROWS_AS, __VA_ARGS__)
2120 #define DOCTEST_REQUIRE_THROWS_AS(expr, ...) DOCTEST_ASSERT_THROWS_AS(expr, DT_REQUIRE_THROWS_AS, __VA_ARGS__)
2121 
2122 #define DOCTEST_WARN_NOTHROW(expr) DOCTEST_ASSERT_NOTHROW(expr, DT_WARN_NOTHROW)
2123 #define DOCTEST_CHECK_NOTHROW(expr) DOCTEST_ASSERT_NOTHROW(expr, DT_CHECK_NOTHROW)
2124 #define DOCTEST_REQUIRE_NOTHROW(expr) DOCTEST_ASSERT_NOTHROW(expr, DT_REQUIRE_NOTHROW)
2125 
2126 #define DOCTEST_WARN_THROWS_MESSAGE(expr, msg) do { DOCTEST_INFO(msg); DOCTEST_WARN_THROWS(expr); } while((void)0, 0)
2127 #define DOCTEST_CHECK_THROWS_MESSAGE(expr, msg) do { DOCTEST_INFO(msg); DOCTEST_CHECK_THROWS(expr); } while((void)0, 0)
2128 #define DOCTEST_REQUIRE_THROWS_MESSAGE(expr, msg) do { DOCTEST_INFO(msg); DOCTEST_REQUIRE_THROWS(expr); } while((void)0, 0)
2129 #define DOCTEST_WARN_THROWS_AS_MESSAGE(expr, ex, msg) do { DOCTEST_INFO(msg); DOCTEST_WARN_THROWS_AS(expr, ex); } while((void)0, 0)
2130 #define DOCTEST_CHECK_THROWS_AS_MESSAGE(expr, ex, msg) do { DOCTEST_INFO(msg); DOCTEST_CHECK_THROWS_AS(expr, ex); } while((void)0, 0)
2131 #define DOCTEST_REQUIRE_THROWS_AS_MESSAGE(expr, ex, msg) do { DOCTEST_INFO(msg); DOCTEST_REQUIRE_THROWS_AS(expr, ex); } while((void)0, 0)
2132 #define DOCTEST_WARN_NOTHROW_MESSAGE(expr, msg) do { DOCTEST_INFO(msg); DOCTEST_WARN_NOTHROW(expr); } while((void)0, 0)
2133 #define DOCTEST_CHECK_NOTHROW_MESSAGE(expr, msg) do { DOCTEST_INFO(msg); DOCTEST_CHECK_NOTHROW(expr); } while((void)0, 0)
2134 #define DOCTEST_REQUIRE_NOTHROW_MESSAGE(expr, msg) do { DOCTEST_INFO(msg); DOCTEST_REQUIRE_NOTHROW(expr); } while((void)0, 0)
2135 // clang-format on
2136 
2137 #define DOCTEST_BINARY_ASSERT(assert_type, comp, ...) \
2138  do { \
2139  doctest::detail::ResultBuilder _DOCTEST_RB(doctest::assertType::assert_type, __FILE__, \
2140  __LINE__, DOCTEST_TOSTR(__VA_ARGS__)); \
2141  DOCTEST_WRAP_IN_TRY( \
2142  _DOCTEST_RB.binary_assert<doctest::detail::binaryAssertComparison::comp>( \
2143  __VA_ARGS__)) \
2144  DOCTEST_ASSERT_LOG_AND_REACT(_DOCTEST_RB); \
2145  } while((void)0, 0)
2146 
2147 #define DOCTEST_UNARY_ASSERT(assert_type, ...) \
2148  do { \
2149  doctest::detail::ResultBuilder _DOCTEST_RB(doctest::assertType::assert_type, __FILE__, \
2150  __LINE__, DOCTEST_TOSTR(__VA_ARGS__)); \
2151  DOCTEST_WRAP_IN_TRY(_DOCTEST_RB.unary_assert(__VA_ARGS__)) \
2152  DOCTEST_ASSERT_LOG_AND_REACT(_DOCTEST_RB); \
2153  } while((void)0, 0)
2154 
2155 #define DOCTEST_WARN_EQ(...) DOCTEST_BINARY_ASSERT(DT_WARN_EQ, eq, __VA_ARGS__)
2156 #define DOCTEST_CHECK_EQ(...) DOCTEST_BINARY_ASSERT(DT_CHECK_EQ, eq, __VA_ARGS__)
2157 #define DOCTEST_REQUIRE_EQ(...) DOCTEST_BINARY_ASSERT(DT_REQUIRE_EQ, eq, __VA_ARGS__)
2158 #define DOCTEST_WARN_NE(...) DOCTEST_BINARY_ASSERT(DT_WARN_NE, ne, __VA_ARGS__)
2159 #define DOCTEST_CHECK_NE(...) DOCTEST_BINARY_ASSERT(DT_CHECK_NE, ne, __VA_ARGS__)
2160 #define DOCTEST_REQUIRE_NE(...) DOCTEST_BINARY_ASSERT(DT_REQUIRE_NE, ne, __VA_ARGS__)
2161 #define DOCTEST_WARN_GT(...) DOCTEST_BINARY_ASSERT(DT_WARN_GT, gt, __VA_ARGS__)
2162 #define DOCTEST_CHECK_GT(...) DOCTEST_BINARY_ASSERT(DT_CHECK_GT, gt, __VA_ARGS__)
2163 #define DOCTEST_REQUIRE_GT(...) DOCTEST_BINARY_ASSERT(DT_REQUIRE_GT, gt, __VA_ARGS__)
2164 #define DOCTEST_WARN_LT(...) DOCTEST_BINARY_ASSERT(DT_WARN_LT, lt, __VA_ARGS__)
2165 #define DOCTEST_CHECK_LT(...) DOCTEST_BINARY_ASSERT(DT_CHECK_LT, lt, __VA_ARGS__)
2166 #define DOCTEST_REQUIRE_LT(...) DOCTEST_BINARY_ASSERT(DT_REQUIRE_LT, lt, __VA_ARGS__)
2167 #define DOCTEST_WARN_GE(...) DOCTEST_BINARY_ASSERT(DT_WARN_GE, ge, __VA_ARGS__)
2168 #define DOCTEST_CHECK_GE(...) DOCTEST_BINARY_ASSERT(DT_CHECK_GE, ge, __VA_ARGS__)
2169 #define DOCTEST_REQUIRE_GE(...) DOCTEST_BINARY_ASSERT(DT_REQUIRE_GE, ge, __VA_ARGS__)
2170 #define DOCTEST_WARN_LE(...) DOCTEST_BINARY_ASSERT(DT_WARN_LE, le, __VA_ARGS__)
2171 #define DOCTEST_CHECK_LE(...) DOCTEST_BINARY_ASSERT(DT_CHECK_LE, le, __VA_ARGS__)
2172 #define DOCTEST_REQUIRE_LE(...) DOCTEST_BINARY_ASSERT(DT_REQUIRE_LE, le, __VA_ARGS__)
2173 
2174 #define DOCTEST_WARN_UNARY(...) DOCTEST_UNARY_ASSERT(DT_WARN_UNARY, __VA_ARGS__)
2175 #define DOCTEST_CHECK_UNARY(...) DOCTEST_UNARY_ASSERT(DT_CHECK_UNARY, __VA_ARGS__)
2176 #define DOCTEST_REQUIRE_UNARY(...) DOCTEST_UNARY_ASSERT(DT_REQUIRE_UNARY, __VA_ARGS__)
2177 #define DOCTEST_WARN_UNARY_FALSE(...) DOCTEST_UNARY_ASSERT(DT_WARN_UNARY_FALSE, __VA_ARGS__)
2178 #define DOCTEST_CHECK_UNARY_FALSE(...) DOCTEST_UNARY_ASSERT(DT_CHECK_UNARY_FALSE, __VA_ARGS__)
2179 #define DOCTEST_REQUIRE_UNARY_FALSE(...) DOCTEST_UNARY_ASSERT(DT_REQUIRE_UNARY_FALSE, __VA_ARGS__)
2180 
2181 #ifndef DOCTEST_CONFIG_SUPER_FAST_ASSERTS
2182 
2183 #define DOCTEST_FAST_BINARY_ASSERT(assert_type, comparison, ...) \
2184  do { \
2185  int _DOCTEST_FAST_RES = doctest::detail::fast_binary_assert< \
2186  doctest::detail::binaryAssertComparison::comparison>( \
2187  doctest::assertType::assert_type, __FILE__, __LINE__, DOCTEST_TOSTR(__VA_ARGS__), \
2188  __VA_ARGS__); \
2189  if(_DOCTEST_FAST_RES & doctest::detail::assertAction::dbgbreak) \
2190  DOCTEST_BREAK_INTO_DEBUGGER(); \
2191  doctest::detail::fastAssertThrowIfFlagSet(_DOCTEST_FAST_RES); \
2192  } while((void)0, 0)
2193 
2194 #define DOCTEST_FAST_UNARY_ASSERT(assert_type, ...) \
2195  do { \
2196  int _DOCTEST_FAST_RES = doctest::detail::fast_unary_assert( \
2197  doctest::assertType::assert_type, __FILE__, __LINE__, DOCTEST_TOSTR(__VA_ARGS__), \
2198  __VA_ARGS__); \
2199  if(_DOCTEST_FAST_RES & doctest::detail::assertAction::dbgbreak) \
2200  DOCTEST_BREAK_INTO_DEBUGGER(); \
2201  doctest::detail::fastAssertThrowIfFlagSet(_DOCTEST_FAST_RES); \
2202  } while((void)0, 0)
2203 
2204 #else // DOCTEST_CONFIG_SUPER_FAST_ASSERTS
2205 
2206 #define DOCTEST_FAST_BINARY_ASSERT(assert_type, comparison, ...) \
2207  doctest::detail::fast_binary_assert<doctest::detail::binaryAssertComparison::comparison>( \
2208  doctest::assertType::assert_type, __FILE__, __LINE__, DOCTEST_TOSTR(__VA_ARGS__), \
2209  __VA_ARGS__)
2210 
2211 #define DOCTEST_FAST_UNARY_ASSERT(assert_type, ...) \
2212  doctest::detail::fast_unary_assert(doctest::assertType::assert_type, __FILE__, __LINE__, \
2213  DOCTEST_TOSTR(__VA_ARGS__), __VA_ARGS__)
2214 
2215 #endif // DOCTEST_CONFIG_SUPER_FAST_ASSERTS
2216 
2217 // clang-format off
2218 #define DOCTEST_FAST_WARN_EQ(...) DOCTEST_FAST_BINARY_ASSERT(DT_FAST_WARN_EQ, eq, __VA_ARGS__)
2219 #define DOCTEST_FAST_CHECK_EQ(...) DOCTEST_FAST_BINARY_ASSERT(DT_FAST_CHECK_EQ, eq, __VA_ARGS__)
2220 #define DOCTEST_FAST_REQUIRE_EQ(...) DOCTEST_FAST_BINARY_ASSERT(DT_FAST_REQUIRE_EQ, eq, __VA_ARGS__)
2221 #define DOCTEST_FAST_WARN_NE(...) DOCTEST_FAST_BINARY_ASSERT(DT_FAST_WARN_NE, ne, __VA_ARGS__)
2222 #define DOCTEST_FAST_CHECK_NE(...) DOCTEST_FAST_BINARY_ASSERT(DT_FAST_CHECK_NE, ne, __VA_ARGS__)
2223 #define DOCTEST_FAST_REQUIRE_NE(...) DOCTEST_FAST_BINARY_ASSERT(DT_FAST_REQUIRE_NE, ne, __VA_ARGS__)
2224 #define DOCTEST_FAST_WARN_GT(...) DOCTEST_FAST_BINARY_ASSERT(DT_FAST_WARN_GT, gt, __VA_ARGS__)
2225 #define DOCTEST_FAST_CHECK_GT(...) DOCTEST_FAST_BINARY_ASSERT(DT_FAST_CHECK_GT, gt, __VA_ARGS__)
2226 #define DOCTEST_FAST_REQUIRE_GT(...) DOCTEST_FAST_BINARY_ASSERT(DT_FAST_REQUIRE_GT, gt, __VA_ARGS__)
2227 #define DOCTEST_FAST_WARN_LT(...) DOCTEST_FAST_BINARY_ASSERT(DT_FAST_WARN_LT, lt, __VA_ARGS__)
2228 #define DOCTEST_FAST_CHECK_LT(...) DOCTEST_FAST_BINARY_ASSERT(DT_FAST_CHECK_LT, lt, __VA_ARGS__)
2229 #define DOCTEST_FAST_REQUIRE_LT(...) DOCTEST_FAST_BINARY_ASSERT(DT_FAST_REQUIRE_LT, lt, __VA_ARGS__)
2230 #define DOCTEST_FAST_WARN_GE(...) DOCTEST_FAST_BINARY_ASSERT(DT_FAST_WARN_GE, ge, __VA_ARGS__)
2231 #define DOCTEST_FAST_CHECK_GE(...) DOCTEST_FAST_BINARY_ASSERT(DT_FAST_CHECK_GE, ge, __VA_ARGS__)
2232 #define DOCTEST_FAST_REQUIRE_GE(...) DOCTEST_FAST_BINARY_ASSERT(DT_FAST_REQUIRE_GE, ge, __VA_ARGS__)
2233 #define DOCTEST_FAST_WARN_LE(...) DOCTEST_FAST_BINARY_ASSERT(DT_FAST_WARN_LE, le, __VA_ARGS__)
2234 #define DOCTEST_FAST_CHECK_LE(...) DOCTEST_FAST_BINARY_ASSERT(DT_FAST_CHECK_LE, le, __VA_ARGS__)
2235 #define DOCTEST_FAST_REQUIRE_LE(...) DOCTEST_FAST_BINARY_ASSERT(DT_FAST_REQUIRE_LE, le, __VA_ARGS__)
2236 
2237 #define DOCTEST_FAST_WARN_UNARY(...) DOCTEST_FAST_UNARY_ASSERT(DT_FAST_WARN_UNARY, __VA_ARGS__)
2238 #define DOCTEST_FAST_CHECK_UNARY(...) DOCTEST_FAST_UNARY_ASSERT(DT_FAST_CHECK_UNARY, __VA_ARGS__)
2239 #define DOCTEST_FAST_REQUIRE_UNARY(...) DOCTEST_FAST_UNARY_ASSERT(DT_FAST_REQUIRE_UNARY, __VA_ARGS__)
2240 #define DOCTEST_FAST_WARN_UNARY_FALSE(...) DOCTEST_FAST_UNARY_ASSERT(DT_FAST_WARN_UNARY_FALSE, __VA_ARGS__)
2241 #define DOCTEST_FAST_CHECK_UNARY_FALSE(...) DOCTEST_FAST_UNARY_ASSERT(DT_FAST_CHECK_UNARY_FALSE, __VA_ARGS__)
2242 #define DOCTEST_FAST_REQUIRE_UNARY_FALSE(...) DOCTEST_FAST_UNARY_ASSERT(DT_FAST_REQUIRE_UNARY_FALSE, __VA_ARGS__)
2243 // clang-format on
2244 
2245 #ifdef DOCTEST_CONFIG_NO_EXCEPTIONS
2246 
2247 #undef DOCTEST_WARN_THROWS
2248 #undef DOCTEST_CHECK_THROWS
2249 #undef DOCTEST_REQUIRE_THROWS
2250 #undef DOCTEST_WARN_THROWS_AS
2251 #undef DOCTEST_CHECK_THROWS_AS
2252 #undef DOCTEST_REQUIRE_THROWS_AS
2253 #undef DOCTEST_WARN_NOTHROW
2254 #undef DOCTEST_CHECK_NOTHROW
2255 #undef DOCTEST_REQUIRE_NOTHROW
2256 
2257 #undef DOCTEST_WARN_THROWS_MESSAGE
2258 #undef DOCTEST_CHECK_THROWS_MESSAGE
2259 #undef DOCTEST_REQUIRE_THROWS_MESSAGE
2260 #undef DOCTEST_WARN_THROWS_AS_MESSAGE
2261 #undef DOCTEST_CHECK_THROWS_AS_MESSAGE
2262 #undef DOCTEST_REQUIRE_THROWS_AS_MESSAGE
2263 #undef DOCTEST_WARN_NOTHROW_MESSAGE
2264 #undef DOCTEST_CHECK_NOTHROW_MESSAGE
2265 #undef DOCTEST_REQUIRE_NOTHROW_MESSAGE
2266 
2267 #ifdef DOCTEST_CONFIG_NO_EXCEPTIONS_BUT_WITH_ALL_ASSERTS
2268 
2269 #define DOCTEST_WARN_THROWS(expr) ((void)0)
2270 #define DOCTEST_CHECK_THROWS(expr) ((void)0)
2271 #define DOCTEST_REQUIRE_THROWS(expr) ((void)0)
2272 #define DOCTEST_WARN_THROWS_AS(expr, ...) ((void)0)
2273 #define DOCTEST_CHECK_THROWS_AS(expr, ...) ((void)0)
2274 #define DOCTEST_REQUIRE_THROWS_AS(expr, ...) ((void)0)
2275 #define DOCTEST_WARN_NOTHROW(expr) ((void)0)
2276 #define DOCTEST_CHECK_NOTHROW(expr) ((void)0)
2277 #define DOCTEST_REQUIRE_NOTHROW(expr) ((void)0)
2278 
2279 #define DOCTEST_WARN_THROWS_MESSAGE(expr, msg) ((void)0)
2280 #define DOCTEST_CHECK_THROWS_MESSAGE(expr, msg) ((void)0)
2281 #define DOCTEST_REQUIRE_THROWS_MESSAGE(expr, msg) ((void)0)
2282 #define DOCTEST_WARN_THROWS_AS_MESSAGE(expr, ex, msg) ((void)0)
2283 #define DOCTEST_CHECK_THROWS_AS_MESSAGE(expr, ex, msg) ((void)0)
2284 #define DOCTEST_REQUIRE_THROWS_AS_MESSAGE(expr, ex, msg) ((void)0)
2285 #define DOCTEST_WARN_NOTHROW_MESSAGE(expr, msg) ((void)0)
2286 #define DOCTEST_CHECK_NOTHROW_MESSAGE(expr, msg) ((void)0)
2287 #define DOCTEST_REQUIRE_NOTHROW_MESSAGE(expr, msg) ((void)0)
2288 
2289 #else // DOCTEST_CONFIG_NO_EXCEPTIONS_BUT_WITH_ALL_ASSERTS
2290 
2291 #undef DOCTEST_REQUIRE
2292 #undef DOCTEST_REQUIRE_FALSE
2293 #undef DOCTEST_REQUIRE_MESSAGE
2294 #undef DOCTEST_REQUIRE_FALSE_MESSAGE
2295 #undef DOCTEST_REQUIRE_EQ
2296 #undef DOCTEST_REQUIRE_NE
2297 #undef DOCTEST_REQUIRE_GT
2298 #undef DOCTEST_REQUIRE_LT
2299 #undef DOCTEST_REQUIRE_GE
2300 #undef DOCTEST_REQUIRE_LE
2301 #undef DOCTEST_REQUIRE_UNARY
2302 #undef DOCTEST_REQUIRE_UNARY_FALSE
2303 #undef DOCTEST_FAST_REQUIRE_EQ
2304 #undef DOCTEST_FAST_REQUIRE_NE
2305 #undef DOCTEST_FAST_REQUIRE_GT
2306 #undef DOCTEST_FAST_REQUIRE_LT
2307 #undef DOCTEST_FAST_REQUIRE_GE
2308 #undef DOCTEST_FAST_REQUIRE_LE
2309 #undef DOCTEST_FAST_REQUIRE_UNARY
2310 #undef DOCTEST_FAST_REQUIRE_UNARY_FALSE
2311 
2312 #endif // DOCTEST_CONFIG_NO_EXCEPTIONS_BUT_WITH_ALL_ASSERTS
2313 
2314 #endif // DOCTEST_CONFIG_NO_EXCEPTIONS
2315 
2316 // =================================================================================================
2317 // == WHAT FOLLOWS IS VERSIONS OF THE MACROS THAT DO NOT DO ANY REGISTERING! ==
2318 // == THIS CAN BE ENABLED BY DEFINING DOCTEST_CONFIG_DISABLE GLOBALLY! ==
2319 // =================================================================================================
2320 #else // DOCTEST_CONFIG_DISABLE
2321 
2322 #define DOCTEST_IMPLEMENT_FIXTURE(der, base, func, name) \
2323  namespace { \
2324  template <typename DOCTEST_UNUSED_TEMPLATE_TYPE> \
2325  struct der : public base \
2326  { void f(); }; \
2327  } \
2328  template <typename DOCTEST_UNUSED_TEMPLATE_TYPE> \
2329  inline void der<DOCTEST_UNUSED_TEMPLATE_TYPE>::f()
2330 
2331 #define DOCTEST_CREATE_AND_REGISTER_FUNCTION(f, name) \
2332  template <typename DOCTEST_UNUSED_TEMPLATE_TYPE> \
2333  static inline void f()
2334 
2335 // for registering tests
2336 #define DOCTEST_TEST_CASE(name) \
2337  DOCTEST_CREATE_AND_REGISTER_FUNCTION(DOCTEST_ANONYMOUS(_DOCTEST_ANON_FUNC_), name)
2338 
2339 // for registering tests with a fixture
2340 #define DOCTEST_TEST_CASE_FIXTURE(x, name) \
2341  DOCTEST_IMPLEMENT_FIXTURE(DOCTEST_ANONYMOUS(_DOCTEST_ANON_CLASS_), x, \
2342  DOCTEST_ANONYMOUS(_DOCTEST_ANON_FUNC_), name)
2343 
2344 // for converting types to strings without the <typeinfo> header and demangling
2345 #define DOCTEST_TYPE_TO_STRING(...) typedef int DOCTEST_ANONYMOUS(_DOCTEST_ANON_FOR_SEMICOLON_)
2346 #define DOCTEST_TYPE_TO_STRING_IMPL(...)
2347 
2348 // for typed tests
2349 #define DOCTEST_TEST_CASE_TEMPLATE(name, type, ...) \
2350  template <typename type> \
2351  inline void DOCTEST_ANONYMOUS(_DOCTEST_ANON_TMP_)()
2352 
2353 #define DOCTEST_TEST_CASE_TEMPLATE_DEFINE(name, type, id) \
2354  template <typename type> \
2355  inline void DOCTEST_ANONYMOUS(_DOCTEST_ANON_TMP_)()
2356 
2357 #define DOCTEST_TEST_CASE_TEMPLATE_INSTANTIATE(id, ...) \
2358  typedef int DOCTEST_ANONYMOUS(_DOCTEST_ANON_FOR_SEMICOLON_)
2359 
2360 // for subcases
2361 #define DOCTEST_SUBCASE(name)
2362 
2363 // for a testsuite block
2364 #define DOCTEST_TEST_SUITE(name) namespace
2365 
2366 // for starting a testsuite block
2367 #define DOCTEST_TEST_SUITE_BEGIN(name) typedef int DOCTEST_ANONYMOUS(_DOCTEST_ANON_FOR_SEMICOLON_)
2368 
2369 // for ending a testsuite block
2370 #define DOCTEST_TEST_SUITE_END typedef int DOCTEST_ANONYMOUS(_DOCTEST_ANON_FOR_SEMICOLON_)
2371 
2372 #define DOCTEST_REGISTER_EXCEPTION_TRANSLATOR(signature) \
2373  template <typename DOCTEST_UNUSED_TEMPLATE_TYPE> \
2374  static inline doctest::String DOCTEST_ANONYMOUS(_DOCTEST_ANON_TRANSLATOR_)(signature)
2375 
2376 #define DOCTEST_REGISTER_REPORTER(name, priority, reporter)
2377 
2378 #define DOCTEST_INFO(x) ((void)0)
2379 #define DOCTEST_CAPTURE(x) ((void)0)
2380 #define DOCTEST_ADD_MESSAGE_AT(file, line, x) ((void)0)
2381 #define DOCTEST_ADD_FAIL_CHECK_AT(file, line, x) ((void)0)
2382 #define DOCTEST_ADD_FAIL_AT(file, line, x) ((void)0)
2383 #define DOCTEST_MESSAGE(x) ((void)0)
2384 #define DOCTEST_FAIL_CHECK(x) ((void)0)
2385 #define DOCTEST_FAIL(x) ((void)0)
2386 
2387 #define DOCTEST_WARN(...) ((void)0)
2388 #define DOCTEST_CHECK(...) ((void)0)
2389 #define DOCTEST_REQUIRE(...) ((void)0)
2390 #define DOCTEST_WARN_FALSE(...) ((void)0)
2391 #define DOCTEST_CHECK_FALSE(...) ((void)0)
2392 #define DOCTEST_REQUIRE_FALSE(...) ((void)0)
2393 
2394 #define DOCTEST_WARN_MESSAGE(cond, msg) ((void)0)
2395 #define DOCTEST_CHECK_MESSAGE(cond, msg) ((void)0)
2396 #define DOCTEST_REQUIRE_MESSAGE(cond, msg) ((void)0)
2397 #define DOCTEST_WARN_FALSE_MESSAGE(cond, msg) ((void)0)
2398 #define DOCTEST_CHECK_FALSE_MESSAGE(cond, msg) ((void)0)
2399 #define DOCTEST_REQUIRE_FALSE_MESSAGE(cond, msg) ((void)0)
2400 
2401 #define DOCTEST_WARN_THROWS(expr) ((void)0)
2402 #define DOCTEST_CHECK_THROWS(expr) ((void)0)
2403 #define DOCTEST_REQUIRE_THROWS(expr) ((void)0)
2404 #define DOCTEST_WARN_THROWS_AS(expr, ...) ((void)0)
2405 #define DOCTEST_CHECK_THROWS_AS(expr, ...) ((void)0)
2406 #define DOCTEST_REQUIRE_THROWS_AS(expr, ...) ((void)0)
2407 #define DOCTEST_WARN_NOTHROW(expr) ((void)0)
2408 #define DOCTEST_CHECK_NOTHROW(expr) ((void)0)
2409 #define DOCTEST_REQUIRE_NOTHROW(expr) ((void)0)
2410 
2411 #define DOCTEST_WARN_THROWS_MESSAGE(expr, msg) ((void)0)
2412 #define DOCTEST_CHECK_THROWS_MESSAGE(expr, msg) ((void)0)
2413 #define DOCTEST_REQUIRE_THROWS_MESSAGE(expr, msg) ((void)0)
2414 #define DOCTEST_WARN_THROWS_AS_MESSAGE(expr, ex, msg) ((void)0)
2415 #define DOCTEST_CHECK_THROWS_AS_MESSAGE(expr, ex, msg) ((void)0)
2416 #define DOCTEST_REQUIRE_THROWS_AS_MESSAGE(expr, ex, msg) ((void)0)
2417 #define DOCTEST_WARN_NOTHROW_MESSAGE(expr, msg) ((void)0)
2418 #define DOCTEST_CHECK_NOTHROW_MESSAGE(expr, msg) ((void)0)
2419 #define DOCTEST_REQUIRE_NOTHROW_MESSAGE(expr, msg) ((void)0)
2420 
2421 #define DOCTEST_WARN_EQ(...) ((void)0)
2422 #define DOCTEST_CHECK_EQ(...) ((void)0)
2423 #define DOCTEST_REQUIRE_EQ(...) ((void)0)
2424 #define DOCTEST_WARN_NE(...) ((void)0)
2425 #define DOCTEST_CHECK_NE(...) ((void)0)
2426 #define DOCTEST_REQUIRE_NE(...) ((void)0)
2427 #define DOCTEST_WARN_GT(...) ((void)0)
2428 #define DOCTEST_CHECK_GT(...) ((void)0)
2429 #define DOCTEST_REQUIRE_GT(...) ((void)0)
2430 #define DOCTEST_WARN_LT(...) ((void)0)
2431 #define DOCTEST_CHECK_LT(...) ((void)0)
2432 #define DOCTEST_REQUIRE_LT(...) ((void)0)
2433 #define DOCTEST_WARN_GE(...) ((void)0)
2434 #define DOCTEST_CHECK_GE(...) ((void)0)
2435 #define DOCTEST_REQUIRE_GE(...) ((void)0)
2436 #define DOCTEST_WARN_LE(...) ((void)0)
2437 #define DOCTEST_CHECK_LE(...) ((void)0)
2438 #define DOCTEST_REQUIRE_LE(...) ((void)0)
2439 
2440 #define DOCTEST_WARN_UNARY(...) ((void)0)
2441 #define DOCTEST_CHECK_UNARY(...) ((void)0)
2442 #define DOCTEST_REQUIRE_UNARY(...) ((void)0)
2443 #define DOCTEST_WARN_UNARY_FALSE(...) ((void)0)
2444 #define DOCTEST_CHECK_UNARY_FALSE(...) ((void)0)
2445 #define DOCTEST_REQUIRE_UNARY_FALSE(...) ((void)0)
2446 
2447 #define DOCTEST_FAST_WARN_EQ(...) ((void)0)
2448 #define DOCTEST_FAST_CHECK_EQ(...) ((void)0)
2449 #define DOCTEST_FAST_REQUIRE_EQ(...) ((void)0)
2450 #define DOCTEST_FAST_WARN_NE(...) ((void)0)
2451 #define DOCTEST_FAST_CHECK_NE(...) ((void)0)
2452 #define DOCTEST_FAST_REQUIRE_NE(...) ((void)0)
2453 #define DOCTEST_FAST_WARN_GT(...) ((void)0)
2454 #define DOCTEST_FAST_CHECK_GT(...) ((void)0)
2455 #define DOCTEST_FAST_REQUIRE_GT(...) ((void)0)
2456 #define DOCTEST_FAST_WARN_LT(...) ((void)0)
2457 #define DOCTEST_FAST_CHECK_LT(...) ((void)0)
2458 #define DOCTEST_FAST_REQUIRE_LT(...) ((void)0)
2459 #define DOCTEST_FAST_WARN_GE(...) ((void)0)
2460 #define DOCTEST_FAST_CHECK_GE(...) ((void)0)
2461 #define DOCTEST_FAST_REQUIRE_GE(...) ((void)0)
2462 #define DOCTEST_FAST_WARN_LE(...) ((void)0)
2463 #define DOCTEST_FAST_CHECK_LE(...) ((void)0)
2464 #define DOCTEST_FAST_REQUIRE_LE(...) ((void)0)
2465 
2466 #define DOCTEST_FAST_WARN_UNARY(...) ((void)0)
2467 #define DOCTEST_FAST_CHECK_UNARY(...) ((void)0)
2468 #define DOCTEST_FAST_REQUIRE_UNARY(...) ((void)0)
2469 #define DOCTEST_FAST_WARN_UNARY_FALSE(...) ((void)0)
2470 #define DOCTEST_FAST_CHECK_UNARY_FALSE(...) ((void)0)
2471 #define DOCTEST_FAST_REQUIRE_UNARY_FALSE(...) ((void)0)
2472 
2473 #endif // DOCTEST_CONFIG_DISABLE
2474 
2475 // BDD style macros
2476 // clang-format off
2477 #define DOCTEST_SCENARIO(name) DOCTEST_TEST_CASE(" Scenario: " name)
2478 #define DOCTEST_SCENARIO_TEMPLATE(name, T, ...) DOCTEST_TEST_CASE_TEMPLATE(" Scenario: " name, T, __VA_ARGS__)
2479 #define DOCTEST_SCENARIO_TEMPLATE_DEFINE(name, T, id) DOCTEST_TEST_CASE_TEMPLATE_DEFINE(" Scenario: " name, T, id)
2480 
2481 #define DOCTEST_GIVEN(name) SUBCASE(" Given: " name)
2482 #define DOCTEST_WHEN(name) SUBCASE(" When: " name)
2483 #define DOCTEST_AND_WHEN(name) SUBCASE("And when: " name)
2484 #define DOCTEST_THEN(name) SUBCASE(" Then: " name)
2485 #define DOCTEST_AND_THEN(name) SUBCASE(" And: " name)
2486 // clang-format on
2487 
2488 // == SHORT VERSIONS OF THE MACROS
2489 #if !defined(DOCTEST_CONFIG_NO_SHORT_MACRO_NAMES)
2490 
2491 #define TEST_CASE DOCTEST_TEST_CASE
2492 #define TEST_CASE_FIXTURE DOCTEST_TEST_CASE_FIXTURE
2493 #define TYPE_TO_STRING DOCTEST_TYPE_TO_STRING
2494 #define TEST_CASE_TEMPLATE DOCTEST_TEST_CASE_TEMPLATE
2495 #define TEST_CASE_TEMPLATE_DEFINE DOCTEST_TEST_CASE_TEMPLATE_DEFINE
2496 #define TEST_CASE_TEMPLATE_INSTANTIATE DOCTEST_TEST_CASE_TEMPLATE_INSTANTIATE
2497 #define SUBCASE DOCTEST_SUBCASE
2498 #define TEST_SUITE DOCTEST_TEST_SUITE
2499 #define TEST_SUITE_BEGIN DOCTEST_TEST_SUITE_BEGIN
2500 #define TEST_SUITE_END DOCTEST_TEST_SUITE_END
2501 #define REGISTER_EXCEPTION_TRANSLATOR DOCTEST_REGISTER_EXCEPTION_TRANSLATOR
2502 #define REGISTER_REPORTER DOCTEST_REGISTER_REPORTER
2503 #define INFO DOCTEST_INFO
2504 #define CAPTURE DOCTEST_CAPTURE
2505 #define ADD_MESSAGE_AT DOCTEST_ADD_MESSAGE_AT
2506 #define ADD_FAIL_CHECK_AT DOCTEST_ADD_FAIL_CHECK_AT
2507 #define ADD_FAIL_AT DOCTEST_ADD_FAIL_AT
2508 #define MESSAGE DOCTEST_MESSAGE
2509 #define FAIL_CHECK DOCTEST_FAIL_CHECK
2510 #define FAIL DOCTEST_FAIL
2511 #define TO_LVALUE DOCTEST_TO_LVALUE
2512 
2513 #define WARN DOCTEST_WARN
2514 #define WARN_FALSE DOCTEST_WARN_FALSE
2515 #define WARN_THROWS DOCTEST_WARN_THROWS
2516 #define WARN_THROWS_AS DOCTEST_WARN_THROWS_AS
2517 #define WARN_NOTHROW DOCTEST_WARN_NOTHROW
2518 #define CHECK DOCTEST_CHECK
2519 #define CHECK_FALSE DOCTEST_CHECK_FALSE
2520 #define CHECK_THROWS DOCTEST_CHECK_THROWS
2521 #define CHECK_THROWS_AS DOCTEST_CHECK_THROWS_AS
2522 #define CHECK_NOTHROW DOCTEST_CHECK_NOTHROW
2523 #define REQUIRE DOCTEST_REQUIRE
2524 #define REQUIRE_FALSE DOCTEST_REQUIRE_FALSE
2525 #define REQUIRE_THROWS DOCTEST_REQUIRE_THROWS
2526 #define REQUIRE_THROWS_AS DOCTEST_REQUIRE_THROWS_AS
2527 #define REQUIRE_NOTHROW DOCTEST_REQUIRE_NOTHROW
2528 
2529 #define WARN_MESSAGE DOCTEST_WARN_MESSAGE
2530 #define WARN_FALSE_MESSAGE DOCTEST_WARN_FALSE_MESSAGE
2531 #define WARN_THROWS_MESSAGE DOCTEST_WARN_THROWS_MESSAGE
2532 #define WARN_THROWS_AS_MESSAGE DOCTEST_WARN_THROWS_AS_MESSAGE
2533 #define WARN_NOTHROW_MESSAGE DOCTEST_WARN_NOTHROW_MESSAGE
2534 #define CHECK_MESSAGE DOCTEST_CHECK_MESSAGE
2535 #define CHECK_FALSE_MESSAGE DOCTEST_CHECK_FALSE_MESSAGE
2536 #define CHECK_THROWS_MESSAGE DOCTEST_CHECK_THROWS_MESSAGE
2537 #define CHECK_THROWS_AS_MESSAGE DOCTEST_CHECK_THROWS_AS_MESSAGE
2538 #define CHECK_NOTHROW_MESSAGE DOCTEST_CHECK_NOTHROW_MESSAGE
2539 #define REQUIRE_MESSAGE DOCTEST_REQUIRE_MESSAGE
2540 #define REQUIRE_FALSE_MESSAGE DOCTEST_REQUIRE_FALSE_MESSAGE
2541 #define REQUIRE_THROWS_MESSAGE DOCTEST_REQUIRE_THROWS_MESSAGE
2542 #define REQUIRE_THROWS_AS_MESSAGE DOCTEST_REQUIRE_THROWS_AS_MESSAGE
2543 #define REQUIRE_NOTHROW_MESSAGE DOCTEST_REQUIRE_NOTHROW_MESSAGE
2544 
2545 #define SCENARIO DOCTEST_SCENARIO
2546 #define SCENARIO_TEMPLATE DOCTEST_SCENARIO_TEMPLATE
2547 #define SCENARIO_TEMPLATE_DEFINE DOCTEST_SCENARIO_TEMPLATE_DEFINE
2548 #define GIVEN DOCTEST_GIVEN
2549 #define WHEN DOCTEST_WHEN
2550 #define AND_WHEN DOCTEST_AND_WHEN
2551 #define THEN DOCTEST_THEN
2552 #define AND_THEN DOCTEST_AND_THEN
2553 
2554 #define WARN_EQ DOCTEST_WARN_EQ
2555 #define CHECK_EQ DOCTEST_CHECK_EQ
2556 #define REQUIRE_EQ DOCTEST_REQUIRE_EQ
2557 #define WARN_NE DOCTEST_WARN_NE
2558 #define CHECK_NE DOCTEST_CHECK_NE
2559 #define REQUIRE_NE DOCTEST_REQUIRE_NE
2560 #define WARN_GT DOCTEST_WARN_GT
2561 #define CHECK_GT DOCTEST_CHECK_GT
2562 #define REQUIRE_GT DOCTEST_REQUIRE_GT
2563 #define WARN_LT DOCTEST_WARN_LT
2564 #define CHECK_LT DOCTEST_CHECK_LT
2565 #define REQUIRE_LT DOCTEST_REQUIRE_LT
2566 #define WARN_GE DOCTEST_WARN_GE
2567 #define CHECK_GE DOCTEST_CHECK_GE
2568 #define REQUIRE_GE DOCTEST_REQUIRE_GE
2569 #define WARN_LE DOCTEST_WARN_LE
2570 #define CHECK_LE DOCTEST_CHECK_LE
2571 #define REQUIRE_LE DOCTEST_REQUIRE_LE
2572 #define WARN_UNARY DOCTEST_WARN_UNARY
2573 #define CHECK_UNARY DOCTEST_CHECK_UNARY
2574 #define REQUIRE_UNARY DOCTEST_REQUIRE_UNARY
2575 #define WARN_UNARY_FALSE DOCTEST_WARN_UNARY_FALSE
2576 #define CHECK_UNARY_FALSE DOCTEST_CHECK_UNARY_FALSE
2577 #define REQUIRE_UNARY_FALSE DOCTEST_REQUIRE_UNARY_FALSE
2578 
2579 #define FAST_WARN_EQ DOCTEST_FAST_WARN_EQ
2580 #define FAST_CHECK_EQ DOCTEST_FAST_CHECK_EQ
2581 #define FAST_REQUIRE_EQ DOCTEST_FAST_REQUIRE_EQ
2582 #define FAST_WARN_NE DOCTEST_FAST_WARN_NE
2583 #define FAST_CHECK_NE DOCTEST_FAST_CHECK_NE
2584 #define FAST_REQUIRE_NE DOCTEST_FAST_REQUIRE_NE
2585 #define FAST_WARN_GT DOCTEST_FAST_WARN_GT
2586 #define FAST_CHECK_GT DOCTEST_FAST_CHECK_GT
2587 #define FAST_REQUIRE_GT DOCTEST_FAST_REQUIRE_GT
2588 #define FAST_WARN_LT DOCTEST_FAST_WARN_LT
2589 #define FAST_CHECK_LT DOCTEST_FAST_CHECK_LT
2590 #define FAST_REQUIRE_LT DOCTEST_FAST_REQUIRE_LT
2591 #define FAST_WARN_GE DOCTEST_FAST_WARN_GE
2592 #define FAST_CHECK_GE DOCTEST_FAST_CHECK_GE
2593 #define FAST_REQUIRE_GE DOCTEST_FAST_REQUIRE_GE
2594 #define FAST_WARN_LE DOCTEST_FAST_WARN_LE
2595 #define FAST_CHECK_LE DOCTEST_FAST_CHECK_LE
2596 #define FAST_REQUIRE_LE DOCTEST_FAST_REQUIRE_LE
2597 #define FAST_WARN_UNARY DOCTEST_FAST_WARN_UNARY
2598 #define FAST_CHECK_UNARY DOCTEST_FAST_CHECK_UNARY
2599 #define FAST_REQUIRE_UNARY DOCTEST_FAST_REQUIRE_UNARY
2600 #define FAST_WARN_UNARY_FALSE DOCTEST_FAST_WARN_UNARY_FALSE
2601 #define FAST_CHECK_UNARY_FALSE DOCTEST_FAST_CHECK_UNARY_FALSE
2602 #define FAST_REQUIRE_UNARY_FALSE DOCTEST_FAST_REQUIRE_UNARY_FALSE
2603 
2604 #endif // DOCTEST_CONFIG_NO_SHORT_MACRO_NAMES
2605 
2606 #if !defined(DOCTEST_CONFIG_DISABLE)
2607 
2608 // this is here to clear the 'current test suite' for the current translation unit - at the top
2610 
2611 // add stringification for primitive/fundamental types
2612 namespace doctest { namespace detail {
2622  DOCTEST_TYPE_TO_STRING_IMPL(unsigned short int)
2626  DOCTEST_TYPE_TO_STRING_IMPL(unsigned long int)
2628  DOCTEST_TYPE_TO_STRING_IMPL(unsigned long long int)
2629 }} // namespace doctest::detail
2630 
2631 #endif // DOCTEST_CONFIG_DISABLE
2632 
2633 DOCTEST_CLANG_SUPPRESS_WARNING_POP
2634 DOCTEST_MSVC_SUPPRESS_WARNING_POP
2635 DOCTEST_GCC_SUPPRESS_WARNING_POP
2636 
2637 #endif // DOCTEST_LIBRARY_INCLUDED
2638 
2639 #ifndef DOCTEST_SINGLE_HEADER
2640 #define DOCTEST_SINGLE_HEADER
2641 #endif // DOCTEST_SINGLE_HEADER
2642 
2643 #if defined(DOCTEST_CONFIG_IMPLEMENT) || !defined(DOCTEST_SINGLE_HEADER)
2644 #ifndef DOCTEST_LIBRARY_IMPLEMENTATION
2645 #define DOCTEST_LIBRARY_IMPLEMENTATION
2646 
2647 #ifndef DOCTEST_SINGLE_HEADER
2648 #include "doctest_fwd.h"
2649 #endif // DOCTEST_SINGLE_HEADER
2650 
2651 DOCTEST_CLANG_SUPPRESS_WARNING_PUSH
2652 DOCTEST_CLANG_SUPPRESS_WARNING("-Wunknown-pragmas")
2654 DOCTEST_CLANG_SUPPRESS_WARNING("-Wweak-vtables")
2655 DOCTEST_CLANG_SUPPRESS_WARNING("-Wglobal-constructors")
2656 DOCTEST_CLANG_SUPPRESS_WARNING("-Wexit-time-destructors")
2657 DOCTEST_CLANG_SUPPRESS_WARNING("-Wmissing-prototypes")
2658 DOCTEST_CLANG_SUPPRESS_WARNING("-Wsign-conversion")
2659 DOCTEST_CLANG_SUPPRESS_WARNING("-Wshorten-64-to-32")
2660 DOCTEST_CLANG_SUPPRESS_WARNING("-Wmissing-variable-declarations")
2662 DOCTEST_CLANG_SUPPRESS_WARNING("-Wswitch-enum")
2663 DOCTEST_CLANG_SUPPRESS_WARNING("-Wcovered-switch-default")
2664 DOCTEST_CLANG_SUPPRESS_WARNING("-Wmissing-noreturn")
2665 DOCTEST_CLANG_SUPPRESS_WARNING("-Wunused-local-typedef")
2666 DOCTEST_CLANG_SUPPRESS_WARNING("-Wdisabled-macro-expansion")
2667 DOCTEST_CLANG_SUPPRESS_WARNING("-Wmissing-braces")
2668 DOCTEST_CLANG_SUPPRESS_WARNING("-Wmissing-field-initializers")
2669 DOCTEST_CLANG_SUPPRESS_WARNING("-Wc++11-long-long")
2670 #if DOCTEST_CLANG && DOCTEST_CLANG_HAS_WARNING("-Wzero-as-null-pointer-constant")
2671 DOCTEST_CLANG_SUPPRESS_WARNING("-Wzero-as-null-pointer-constant")
2672 #endif // clang - 0 as null
2673 DOCTEST_CLANG_SUPPRESS_WARNING("-Wc++98-compat")
2674 DOCTEST_CLANG_SUPPRESS_WARNING("-Wc++98-compat-pedantic")
2675 
2676 DOCTEST_GCC_SUPPRESS_WARNING_PUSH
2677 DOCTEST_GCC_SUPPRESS_WARNING("-Wunknown-pragmas")
2678 DOCTEST_GCC_SUPPRESS_WARNING("-Wpragmas")
2679 DOCTEST_GCC_SUPPRESS_WARNING("-Wconversion")
2680 DOCTEST_GCC_SUPPRESS_WARNING("-Weffc++")
2681 DOCTEST_GCC_SUPPRESS_WARNING("-Wsign-conversion")
2682 DOCTEST_GCC_SUPPRESS_WARNING("-Wstrict-overflow")
2683 DOCTEST_GCC_SUPPRESS_WARNING("-Wstrict-aliasing")
2684 DOCTEST_GCC_SUPPRESS_WARNING("-Wmissing-field-initializers")
2685 DOCTEST_GCC_SUPPRESS_WARNING("-Wmissing-braces")
2686 DOCTEST_GCC_SUPPRESS_WARNING("-Wmissing-declarations")
2687 DOCTEST_GCC_SUPPRESS_WARNING("-Winline")
2688 DOCTEST_GCC_SUPPRESS_WARNING("-Wswitch")
2689 DOCTEST_GCC_SUPPRESS_WARNING("-Wswitch-enum")
2690 DOCTEST_GCC_SUPPRESS_WARNING("-Wswitch-default")
2691 DOCTEST_GCC_SUPPRESS_WARNING("-Wunsafe-loop-optimizations")
2692 DOCTEST_GCC_SUPPRESS_WARNING("-Wlong-long")
2693 DOCTEST_GCC_SUPPRESS_WARNING("-Wold-style-cast")
2694 DOCTEST_GCC_SUPPRESS_WARNING("-Wzero-as-null-pointer-constant")
2695 DOCTEST_GCC_SUPPRESS_WARNING("-Wunused-local-typedefs")
2696 DOCTEST_GCC_SUPPRESS_WARNING("-Wuseless-cast")
2697 
2698 DOCTEST_MSVC_SUPPRESS_WARNING_PUSH
2699 DOCTEST_MSVC_SUPPRESS_WARNING(4616) // invalid compiler warning
2700 DOCTEST_MSVC_SUPPRESS_WARNING(4619) // invalid compiler warning
2701 DOCTEST_MSVC_SUPPRESS_WARNING(4996) // The compiler encountered a deprecated declaration
2702 DOCTEST_MSVC_SUPPRESS_WARNING(4267) // 'var' : conversion from 'x' to 'y', possible loss of data
2703 DOCTEST_MSVC_SUPPRESS_WARNING(4706) // assignment within conditional expression
2704 DOCTEST_MSVC_SUPPRESS_WARNING(4512) // 'class' : assignment operator could not be generated
2705 DOCTEST_MSVC_SUPPRESS_WARNING(4127) // conditional expression is constant
2706 DOCTEST_MSVC_SUPPRESS_WARNING(4530) // C++ exception handler used, but unwind semantics not enabled
2707 DOCTEST_MSVC_SUPPRESS_WARNING(4577) // 'noexcept' used with no exception handling mode specified
2708 DOCTEST_MSVC_SUPPRESS_WARNING(4774) // format string expected in argument is not a string literal
2709 DOCTEST_MSVC_SUPPRESS_WARNING(4365) // conversion from 'int' to 'unsigned', signed/unsigned mismatch
2710 DOCTEST_MSVC_SUPPRESS_WARNING(4820) // padding in structs
2711 DOCTEST_MSVC_SUPPRESS_WARNING(4640) // construction of local static object is not thread-safe
2712 DOCTEST_MSVC_SUPPRESS_WARNING(5039) // pointer to potentially throwing function passed to extern C
2713 DOCTEST_MSVC_SUPPRESS_WARNING(5045) // Spectre mitigation stuff
2714 DOCTEST_MSVC_SUPPRESS_WARNING(4626) // assignment operator was implicitly defined as deleted
2715 DOCTEST_MSVC_SUPPRESS_WARNING(5027) // move assignment operator was implicitly defined as deleted
2716 DOCTEST_MSVC_SUPPRESS_WARNING(5026) // move constructor was implicitly defined as deleted
2717 DOCTEST_MSVC_SUPPRESS_WARNING(4625) // copy constructor was implicitly defined as deleted
2718 DOCTEST_MSVC_SUPPRESS_WARNING(4800) // forcing value to bool 'true' or 'false' (performance warning)
2719 // static analysis
2720 DOCTEST_MSVC_SUPPRESS_WARNING(26439) // This kind of function may not throw. Declare it 'noexcept'
2721 DOCTEST_MSVC_SUPPRESS_WARNING(26495) // Always initialize a member variable
2722 DOCTEST_MSVC_SUPPRESS_WARNING(26451) // Arithmetic overflow ...
2723 DOCTEST_MSVC_SUPPRESS_WARNING(26444) // Avoid unnamed objects with custom construction and dtr...
2724 
2726 
2727 // required includes - will go only in one translation unit!
2728 #include <ctime>
2729 #include <cmath>
2730 #include <climits>
2731 // borland (Embarcadero) compiler requires math.h and not cmath - https://github.com/onqtam/doctest/pull/37
2732 #ifdef __BORLANDC__
2733 #include <math.h>
2734 #endif // __BORLANDC__
2735 #include <new>
2736 #include <cstdio>
2737 #include <cstdlib>
2738 #include <cstring>
2739 #include <limits>
2740 #include <utility>
2741 #include <sstream>
2742 #include <iostream>
2743 #include <algorithm>
2744 #include <iomanip>
2745 #include <vector>
2746 #include <atomic>
2747 #include <mutex>
2748 #include <set>
2749 #include <map>
2750 #include <exception>
2751 #include <stdexcept>
2752 #include <csignal>
2753 #include <cfloat>
2754 #include <cctype>
2755 #if !DOCTEST_MSVC
2756 #include <stdint.h>
2757 #endif // !MSVC
2758 
2760 
2761 // counts the number of elements in a C array
2762 #define DOCTEST_COUNTOF(x) (sizeof(x) / sizeof(x[0]))
2763 
2764 #ifdef DOCTEST_CONFIG_DISABLE
2765 #define DOCTEST_BRANCH_ON_DISABLED(if_disabled, if_not_disabled) if_disabled
2766 #else // DOCTEST_CONFIG_DISABLE
2767 #define DOCTEST_BRANCH_ON_DISABLED(if_disabled, if_not_disabled) if_not_disabled
2768 #endif // DOCTEST_CONFIG_DISABLE
2769 
2770 namespace doctest {
2771 namespace {
2772  using namespace detail;
2773  // case insensitive strcmp
2774  int stricmp(const char* a, const char* b) {
2775  for(;; a++, b++) {
2776  const int d = tolower(*a) - tolower(*b);
2777  if(d != 0 || !*a)
2778  return d;
2779  }
2780  }
2781 
2782  template <typename T>
2783  String fpToString(T value, int precision) {
2784  std::ostringstream oss;
2785  oss << std::setprecision(precision) << std::fixed << value;
2786  std::string d = oss.str();
2787  size_t i = d.find_last_not_of('0');
2788  if(i != std::string::npos && i != d.size() - 1) {
2789  if(d[i] == '.')
2790  i++;
2791  d = d.substr(0, i + 1);
2792  }
2793  return d.c_str();
2794  }
2795 
2796  struct Endianness
2797  {
2798  enum Arch
2799  {
2800  Big,
2801  Little
2802  };
2803 
2804  static Arch which() {
2805  union _
2806  {
2807  int asInt;
2808  char asChar[sizeof(int)];
2809  } u;
2810 
2811  u.asInt = 1; // NOLINT
2812  return (u.asChar[sizeof(int) - 1] == 1) ? Big : Little; // NOLINT
2813  }
2814  };
2815 } // namespace
2816 
2817 namespace detail {
2818  void my_memcpy(void* dest, const void* src, unsigned num) { memcpy(dest, src, num); }
2819 
2820  String rawMemoryToString(const void* object, unsigned size) {
2821  // Reverse order for little endian architectures
2822  int i = 0, end = static_cast<int>(size), inc = 1;
2823  if(Endianness::which() == Endianness::Little) {
2824  i = end - 1;
2825  end = inc = -1;
2826  }
2827 
2828  unsigned const char* bytes = static_cast<unsigned const char*>(object);
2829  std::ostringstream oss;
2830  oss << "0x" << std::setfill('0') << std::hex;
2831  for(; i != end; i += inc)
2832  oss << std::setw(2) << static_cast<unsigned>(bytes[i]);
2833  return oss.str().c_str();
2834  }
2835 
2836  std::ostream* createStream() { return new std::ostringstream(); }
2837  String getStreamResult(std::ostream* s) {
2838  return static_cast<std::ostringstream*>(s)->str().c_str(); // NOLINT
2839  }
2840  void freeStream(std::ostream* s) { delete s; }
2841 
2842 #ifndef DOCTEST_CONFIG_DISABLE
2843  // this holds both parameters from the command line and runtime data for tests
2844  struct ContextState : ContextOptions, TestRunStats, CurrentTestCaseStats
2845  {
2846  std::vector<std::vector<String> > filters = decltype(filters)(9); // 9 different filters
2847 
2848  std::vector<IReporter*> reporters_currently_used;
2849 
2850  const TestCase* currentTest;
2851 
2852  std::vector<IContextScope*> contexts; // for logging with INFO() and friends
2853  std::vector<String> stringifiedContexts; // logging from INFO() due to an exception
2854 
2855  // stuff for subcases
2856  std::set<SubcaseSignature> subcasesPassed;
2857  std::set<int> subcasesEnteredLevels;
2858  int subcasesCurrentLevel;
2859 
2860  void resetRunData() {
2861  numTestCases = 0;
2862  numTestCasesPassingFilters = 0;
2863  numTestSuitesPassingFilters = 0;
2864  numTestCasesFailed = 0;
2865  numAsserts = 0;
2866  numAssertsFailed = 0;
2867  }
2868  };
2869 
2870  ContextState* g_contextState = 0;
2871 #endif // DOCTEST_CONFIG_DISABLE
2872 } // namespace detail
2873 
2874 void String::setOnHeap() { *reinterpret_cast<unsigned char*>(&buf[last]) = 128; }
2875 void String::setLast(unsigned in) { buf[last] = char(in); }
2876 
2877 void String::copy(const String& other) {
2878  if(other.isOnStack()) {
2879  memcpy(buf, other.buf, len);
2880  } else {
2881  setOnHeap();
2882  data.size = other.data.size;
2883  data.capacity = data.size + 1;
2884  data.ptr = new char[data.capacity];
2885  memcpy(data.ptr, other.data.ptr, data.size + 1);
2886  }
2887 }
2888 
2889 String::String() {
2890  buf[0] = '\0';
2891  setLast();
2892 }
2893 
2894 String::~String() {
2895  if(!isOnStack())
2896  delete[] data.ptr;
2897 }
2898 
2899 String::String(const char* in) {
2900  unsigned in_len = strlen(in);
2901  if(in_len <= last) {
2902  memcpy(buf, in, in_len + 1);
2903  setLast(last - in_len);
2904  } else {
2905  setOnHeap();
2906  data.size = in_len;
2907  data.capacity = data.size + 1;
2908  data.ptr = new char[data.capacity];
2909  memcpy(data.ptr, in, in_len + 1);
2910  }
2911 }
2912 
2913 String::String(const String& other) { copy(other); }
2914 
2915 String& String::operator=(const String& other) {
2916  if(this != &other) {
2917  if(!isOnStack())
2918  delete[] data.ptr;
2919 
2920  copy(other);
2921  }
2922 
2923  return *this;
2924 }
2925 
2926 String& String::operator+=(const String& other) {
2927  const unsigned my_old_size = size();
2928  const unsigned other_size = other.size();
2929  const unsigned total_size = my_old_size + other_size;
2930  if(isOnStack()) {
2931  if(total_size < len) {
2932  // append to the current stack space
2933  memcpy(buf + my_old_size, other.c_str(), other_size + 1);
2934  setLast(last - total_size);
2935  } else {
2936  // alloc new chunk
2937  char* temp = new char[total_size + 1];
2938  // copy current data to new location before writing in the union
2939  memcpy(temp, buf, my_old_size); // skip the +1 ('\0') for speed
2940  // update data in union
2941  setOnHeap();
2942  data.size = total_size;
2943  data.capacity = data.size + 1;
2944  data.ptr = temp;
2945  // transfer the rest of the data
2946  memcpy(data.ptr + my_old_size, other.c_str(), other_size + 1);
2947  }
2948  } else {
2949  if(data.capacity > total_size) {
2950  // append to the current heap block
2951  data.size = total_size;
2952  memcpy(data.ptr + my_old_size, other.c_str(), other_size + 1);
2953  } else {
2954  // resize
2955  data.capacity *= 2;
2956  if(data.capacity <= total_size)
2957  data.capacity = total_size + 1;
2958  // alloc new chunk
2959  char* temp = new char[data.capacity];
2960  // copy current data to new location before releasing it
2961  memcpy(temp, data.ptr, my_old_size); // skip the +1 ('\0') for speed
2962  // release old chunk
2963  delete[] data.ptr;
2964  // update the rest of the union members
2965  data.size = total_size;
2966  data.ptr = temp;
2967  // transfer the rest of the data
2968  memcpy(data.ptr + my_old_size, other.c_str(), other_size + 1);
2969  }
2970  }
2971 
2972  return *this;
2973 }
2974 
2975 String String::operator+(const String& other) const { return String(*this) += other; }
2976 
2977 String::String(String&& other) {
2978  memcpy(buf, other.buf, len);
2979  other.buf[0] = '\0';
2980  other.setLast();
2981 }
2982 
2983 String& String::operator=(String&& other) {
2984  if(this != &other) {
2985  if(!isOnStack())
2986  delete[] data.ptr;
2987  memcpy(buf, other.buf, len);
2988  other.buf[0] = '\0';
2989  other.setLast();
2990  }
2991  return *this;
2992 }
2993 
2994 char String::operator[](unsigned i) const {
2995  return const_cast<String*>(this)->operator[](i); // NOLINT
2996 }
2997 
2998 char& String::operator[](unsigned i) {
2999  if(isOnStack())
3000  return reinterpret_cast<char*>(buf)[i];
3001  return data.ptr[i];
3002 }
3003 
3004 DOCTEST_GCC_SUPPRESS_WARNING_WITH_PUSH("-Wmaybe-uninitialized")
3005 unsigned String::size() const {
3006  if(isOnStack())
3007  return last - (unsigned(buf[last]) & 31); // using "last" would work only if "len" is 32
3008  return data.size;
3009 }
3010 DOCTEST_GCC_SUPPRESS_WARNING_POP
3011 
3012 unsigned String::capacity() const {
3013  if(isOnStack())
3014  return len;
3015  return data.capacity;
3016 }
3017 
3018 int String::compare(const char* other, bool no_case) const {
3019  if(no_case)
3020  return stricmp(c_str(), other);
3021  return std::strcmp(c_str(), other);
3022 }
3023 
3024 int String::compare(const String& other, bool no_case) const {
3025  return compare(other.c_str(), no_case);
3026 }
3027 
3028 // clang-format off
3029 bool operator==(const String& lhs, const String& rhs) { return lhs.compare(rhs) == 0; }
3030 bool operator!=(const String& lhs, const String& rhs) { return lhs.compare(rhs) != 0; }
3031 bool operator< (const String& lhs, const String& rhs) { return lhs.compare(rhs) < 0; }
3032 bool operator> (const String& lhs, const String& rhs) { return lhs.compare(rhs) > 0; }
3033 bool operator<=(const String& lhs, const String& rhs) { return (lhs != rhs) ? lhs.compare(rhs) < 0 : true; }
3034 bool operator>=(const String& lhs, const String& rhs) { return (lhs != rhs) ? lhs.compare(rhs) > 0 : true; }
3035 // clang-format on
3036 
3037 std::ostream& operator<<(std::ostream& s, const String& in) { return s << in.c_str(); }
3038 
3039 namespace {
3040  void color_to_stream(std::ostream&, Color::Enum) DOCTEST_BRANCH_ON_DISABLED({}, ;)
3041 } // namespace
3042 
3043 namespace Color {
3044  std::ostream& operator<<(std::ostream& s, Color::Enum code) {
3045  color_to_stream(s, code);
3046  return s;
3047  }
3048 } // namespace Color
3049 
3050 // clang-format off
3051 const char* assertString(assertType::Enum at) {
3052  DOCTEST_MSVC_SUPPRESS_WARNING_WITH_PUSH(4062) // enum 'x' in switch of enum 'y' is not handled
3053  switch(at) {
3054  case assertType::DT_WARN : return "WARN";
3055  case assertType::DT_CHECK : return "CHECK";
3056  case assertType::DT_REQUIRE : return "REQUIRE";
3057 
3058  case assertType::DT_WARN_FALSE : return "WARN_FALSE";
3059  case assertType::DT_CHECK_FALSE : return "CHECK_FALSE";
3060  case assertType::DT_REQUIRE_FALSE : return "REQUIRE_FALSE";
3061 
3062  case assertType::DT_WARN_THROWS : return "WARN_THROWS";
3063  case assertType::DT_CHECK_THROWS : return "CHECK_THROWS";
3064  case assertType::DT_REQUIRE_THROWS : return "REQUIRE_THROWS";
3065 
3066  case assertType::DT_WARN_THROWS_AS : return "WARN_THROWS_AS";
3067  case assertType::DT_CHECK_THROWS_AS : return "CHECK_THROWS_AS";
3068  case assertType::DT_REQUIRE_THROWS_AS : return "REQUIRE_THROWS_AS";
3069 
3070  case assertType::DT_WARN_NOTHROW : return "WARN_NOTHROW";
3071  case assertType::DT_CHECK_NOTHROW : return "CHECK_NOTHROW";
3072  case assertType::DT_REQUIRE_NOTHROW : return "REQUIRE_NOTHROW";
3073 
3074  case assertType::DT_WARN_EQ : return "WARN_EQ";
3075  case assertType::DT_CHECK_EQ : return "CHECK_EQ";
3076  case assertType::DT_REQUIRE_EQ : return "REQUIRE_EQ";
3077  case assertType::DT_WARN_NE : return "WARN_NE";
3078  case assertType::DT_CHECK_NE : return "CHECK_NE";
3079  case assertType::DT_REQUIRE_NE : return "REQUIRE_NE";
3080  case assertType::DT_WARN_GT : return "WARN_GT";
3081  case assertType::DT_CHECK_GT : return "CHECK_GT";
3082  case assertType::DT_REQUIRE_GT : return "REQUIRE_GT";
3083  case assertType::DT_WARN_LT : return "WARN_LT";
3084  case assertType::DT_CHECK_LT : return "CHECK_LT";
3085  case assertType::DT_REQUIRE_LT : return "REQUIRE_LT";
3086  case assertType::DT_WARN_GE : return "WARN_GE";
3087  case assertType::DT_CHECK_GE : return "CHECK_GE";
3088  case assertType::DT_REQUIRE_GE : return "REQUIRE_GE";
3089  case assertType::DT_WARN_LE : return "WARN_LE";
3090  case assertType::DT_CHECK_LE : return "CHECK_LE";
3091  case assertType::DT_REQUIRE_LE : return "REQUIRE_LE";
3092 
3093  case assertType::DT_WARN_UNARY : return "WARN_UNARY";
3094  case assertType::DT_CHECK_UNARY : return "CHECK_UNARY";
3095  case assertType::DT_REQUIRE_UNARY : return "REQUIRE_UNARY";
3096  case assertType::DT_WARN_UNARY_FALSE : return "WARN_UNARY_FALSE";
3097  case assertType::DT_CHECK_UNARY_FALSE : return "CHECK_UNARY_FALSE";
3098  case assertType::DT_REQUIRE_UNARY_FALSE : return "REQUIRE_UNARY_FALSE";
3099 
3100  case assertType::DT_FAST_WARN_EQ : return "FAST_WARN_EQ";
3101  case assertType::DT_FAST_CHECK_EQ : return "FAST_CHECK_EQ";
3102  case assertType::DT_FAST_REQUIRE_EQ : return "FAST_REQUIRE_EQ";
3103  case assertType::DT_FAST_WARN_NE : return "FAST_WARN_NE";
3104  case assertType::DT_FAST_CHECK_NE : return "FAST_CHECK_NE";
3105  case assertType::DT_FAST_REQUIRE_NE : return "FAST_REQUIRE_NE";
3106  case assertType::DT_FAST_WARN_GT : return "FAST_WARN_GT";
3107  case assertType::DT_FAST_CHECK_GT : return "FAST_CHECK_GT";
3108  case assertType::DT_FAST_REQUIRE_GT : return "FAST_REQUIRE_GT";
3109  case assertType::DT_FAST_WARN_LT : return "FAST_WARN_LT";
3110  case assertType::DT_FAST_CHECK_LT : return "FAST_CHECK_LT";
3111  case assertType::DT_FAST_REQUIRE_LT : return "FAST_REQUIRE_LT";
3112  case assertType::DT_FAST_WARN_GE : return "FAST_WARN_GE";
3113  case assertType::DT_FAST_CHECK_GE : return "FAST_CHECK_GE";
3114  case assertType::DT_FAST_REQUIRE_GE : return "FAST_REQUIRE_GE";
3115  case assertType::DT_FAST_WARN_LE : return "FAST_WARN_LE";
3116  case assertType::DT_FAST_CHECK_LE : return "FAST_CHECK_LE";
3117  case assertType::DT_FAST_REQUIRE_LE : return "FAST_REQUIRE_LE";
3118 
3119  case assertType::DT_FAST_WARN_UNARY : return "FAST_WARN_UNARY";
3120  case assertType::DT_FAST_CHECK_UNARY : return "FAST_CHECK_UNARY";
3121  case assertType::DT_FAST_REQUIRE_UNARY : return "FAST_REQUIRE_UNARY";
3122  case assertType::DT_FAST_WARN_UNARY_FALSE : return "FAST_WARN_UNARY_FALSE";
3123  case assertType::DT_FAST_CHECK_UNARY_FALSE : return "FAST_CHECK_UNARY_FALSE";
3124  case assertType::DT_FAST_REQUIRE_UNARY_FALSE: return "FAST_REQUIRE_UNARY_FALSE";
3125  }
3126  DOCTEST_MSVC_SUPPRESS_WARNING_POP
3127  return "";
3128 }
3129 // clang-format on
3130 
3131 DOCTEST_DEFINE_DEFAULTS(TestCaseData);
3132 DOCTEST_DEFINE_COPIES(TestCaseData);
3133 
3134 DOCTEST_DEFINE_DEFAULTS(AssertData);
3135 
3136 DOCTEST_DEFINE_DEFAULTS(MessageData);
3137 
3138 SubcaseSignature::SubcaseSignature(const char* name, const char* file, int line)
3139  : m_name(name)
3140  , m_file(file)
3141  , m_line(line) {}
3142 
3143 DOCTEST_DEFINE_DEFAULTS(SubcaseSignature);
3144 DOCTEST_DEFINE_COPIES(SubcaseSignature);
3145 
3146 bool SubcaseSignature::operator<(const SubcaseSignature& other) const {
3147  if(m_line != other.m_line)
3148  return m_line < other.m_line;
3149  if(std::strcmp(m_file, other.m_file) != 0)
3150  return std::strcmp(m_file, other.m_file) < 0;
3151  return std::strcmp(m_name, other.m_name) < 0;
3152 }
3153 
3154 IContextScope::IContextScope() = default;
3155 IContextScope::~IContextScope() = default;
3156 
3157 DOCTEST_DEFINE_DEFAULTS(ContextOptions);
3158 
3159 #ifdef DOCTEST_CONFIG_TREAT_CHAR_STAR_AS_STRING
3160 String toString(char* in) { return toString(static_cast<const char*>(in)); }
3161 String toString(const char* in) { return String("\"") + (in ? in : "{null string}") + "\""; }
3162 #endif // DOCTEST_CONFIG_TREAT_CHAR_STAR_AS_STRING
3163 String toString(bool in) { return in ? "true" : "false"; }
3164 String toString(float in) { return fpToString(in, 5) + "f"; }
3165 String toString(double in) { return fpToString(in, 10); }
3166 String toString(double long in) { return fpToString(in, 15); }
3167 
3168 #define DOCTEST_TO_STRING_OVERLOAD(type, fmt) \
3169  String toString(type in) { \
3170  char buf[64]; \
3171  std::sprintf(buf, fmt, in); \
3172  return buf; \
3173  }
3174 
3175 DOCTEST_TO_STRING_OVERLOAD(char, "%d")
3176 DOCTEST_TO_STRING_OVERLOAD(char signed, "%d")
3177 DOCTEST_TO_STRING_OVERLOAD(char unsigned, "%ud")
3178 DOCTEST_TO_STRING_OVERLOAD(int short, "%d")
3179 DOCTEST_TO_STRING_OVERLOAD(int short unsigned, "%u")
3180 DOCTEST_TO_STRING_OVERLOAD(int, "%d")
3181 DOCTEST_TO_STRING_OVERLOAD(unsigned, "%u")
3182 DOCTEST_TO_STRING_OVERLOAD(int long, "%ld")
3183 DOCTEST_TO_STRING_OVERLOAD(int long unsigned, "%lu")
3184 DOCTEST_TO_STRING_OVERLOAD(int long long, "%lld")
3185 DOCTEST_TO_STRING_OVERLOAD(int long long unsigned, "%llu")
3186 
3187 String toString(std::nullptr_t) { return "NULL"; }
3188 
3189 Approx::Approx(double value)
3190  : m_epsilon(static_cast<double>(std::numeric_limits<float>::epsilon()) * 100)
3191  , m_scale(1.0)
3192  , m_value(value) {}
3193 
3194 DOCTEST_DEFINE_COPIES(Approx);
3195 
3196 Approx Approx::operator()(double value) const {
3197  Approx approx(value);
3198  approx.epsilon(m_epsilon);
3199  approx.scale(m_scale);
3200  return approx;
3201 }
3202 
3203 Approx& Approx::epsilon(double newEpsilon) {
3204  m_epsilon = newEpsilon;
3205  return *this;
3206 }
3207 Approx& Approx::scale(double newScale) {
3208  m_scale = newScale;
3209  return *this;
3210 }
3211 
3212 bool operator==(double lhs, const Approx& rhs) {
3213  // Thanks to Richard Harris for his help refining this formula
3214  return std::fabs(lhs - rhs.m_value) <
3215  rhs.m_epsilon * (rhs.m_scale + std::max(std::fabs(lhs), std::fabs(rhs.m_value)));
3216 }
3217 bool operator==(const Approx& lhs, double rhs) { return operator==(rhs, lhs); }
3218 bool operator!=(double lhs, const Approx& rhs) { return !operator==(lhs, rhs); }
3219 bool operator!=(const Approx& lhs, double rhs) { return !operator==(rhs, lhs); }
3220 bool operator<=(double lhs, const Approx& rhs) { return lhs < rhs.m_value || lhs == rhs; }
3221 bool operator<=(const Approx& lhs, double rhs) { return lhs.m_value < rhs || lhs == rhs; }
3222 bool operator>=(double lhs, const Approx& rhs) { return lhs > rhs.m_value || lhs == rhs; }
3223 bool operator>=(const Approx& lhs, double rhs) { return lhs.m_value > rhs || lhs == rhs; }
3224 bool operator<(double lhs, const Approx& rhs) { return lhs < rhs.m_value && lhs != rhs; }
3225 bool operator<(const Approx& lhs, double rhs) { return lhs.m_value < rhs && lhs != rhs; }
3226 bool operator>(double lhs, const Approx& rhs) { return lhs > rhs.m_value && lhs != rhs; }
3227 bool operator>(const Approx& lhs, double rhs) { return lhs.m_value > rhs && lhs != rhs; }
3228 
3229 String toString(const Approx& in) {
3230  return String("Approx( ") + doctest::toString(in.m_value) + " )";
3231 }
3232 
3233 } // namespace doctest
3234 
3235 #ifdef DOCTEST_CONFIG_DISABLE
3236 namespace doctest {
3237 bool isRunningInTest() { return false; }
3238 Context::Context(int, const char* const*) {}
3239 Context::~Context() = default;
3240 void Context::applyCommandLine(int, const char* const*) {}
3241 void Context::addFilter(const char*, const char*) {}
3242 void Context::clearFilters() {}
3243 void Context::setOption(const char*, int) {}
3244 void Context::setOption(const char*, const char*) {}
3245 bool Context::shouldExit() { return false; }
3246 int Context::run() { return 0; }
3247 
3248 DOCTEST_DEFINE_DEFAULTS(CurrentTestCaseStats);
3249 
3250 DOCTEST_DEFINE_DEFAULTS(TestRunStats);
3251 
3252 IReporter::~IReporter() = default;
3253 
3254 int IReporter::get_num_active_contexts() { return 0; }
3255 const IContextScope* const* IReporter::get_active_contexts() { return 0; }
3256 int IReporter::get_num_stringified_contexts() { return 0; }
3257 const String* IReporter::get_stringified_contexts() { return 0; }
3258 
3259 int registerReporter(const char*, int, IReporter*) { return 0; }
3260 
3261 } // namespace doctest
3262 #else // DOCTEST_CONFIG_DISABLE
3263 
3264 #if !defined(DOCTEST_CONFIG_COLORS_NONE)
3265 #if !defined(DOCTEST_CONFIG_COLORS_WINDOWS) && !defined(DOCTEST_CONFIG_COLORS_ANSI)
3266 #ifdef DOCTEST_PLATFORM_WINDOWS
3267 #define DOCTEST_CONFIG_COLORS_WINDOWS
3268 #else // linux
3269 #define DOCTEST_CONFIG_COLORS_ANSI
3270 #endif // platform
3271 #endif // DOCTEST_CONFIG_COLORS_WINDOWS && DOCTEST_CONFIG_COLORS_ANSI
3272 #endif // DOCTEST_CONFIG_COLORS_NONE
3273 
3274 #if DOCTEST_MSVC || defined(__MINGW32__)
3275 #if DOCTEST_MSVC
3276 #define DOCTEST_WINDOWS_SAL_IN_OPT _In_opt_
3277 #else // MSVC
3278 #define DOCTEST_WINDOWS_SAL_IN_OPT
3279 #endif // MSVC
3280 extern "C" __declspec(dllimport) void __stdcall OutputDebugStringA(
3281  DOCTEST_WINDOWS_SAL_IN_OPT const char*);
3282 extern "C" __declspec(dllimport) int __stdcall IsDebuggerPresent();
3283 #endif // MSVC || __MINGW32__
3284 
3285 #ifdef DOCTEST_CONFIG_COLORS_ANSI
3286 #include <unistd.h>
3287 #endif // DOCTEST_CONFIG_COLORS_ANSI
3288 
3289 #ifdef DOCTEST_PLATFORM_WINDOWS
3290 
3291 // defines for a leaner windows.h
3292 #ifndef WIN32_LEAN_AND_MEAN
3293 #define WIN32_LEAN_AND_MEAN
3294 #endif // WIN32_LEAN_AND_MEAN
3295 #ifndef VC_EXTRA_LEAN
3296 #define VC_EXTRA_LEAN
3297 #endif // VC_EXTRA_LEAN
3298 #ifndef NOMINMAX
3299 #define NOMINMAX
3300 #endif // NOMINMAX
3301 
3303 
3304 // not sure what AfxWin.h is for - here I do what Catch does
3305 #ifdef __AFXDLL
3306 #include <AfxWin.h>
3307 #else
3308 #include <windows.h>
3309 #endif
3310 #include <io.h>
3311 
3313 
3314 #else // DOCTEST_PLATFORM_WINDOWS
3315 
3316 #include <sys/time.h>
3317 
3318 #endif // DOCTEST_PLATFORM_WINDOWS
3319 
3320 namespace doctest_detail_test_suite_ns {
3321 // holds the current test suite
3324  return data;
3325 }
3326 } // namespace doctest_detail_test_suite_ns
3327 
3328 namespace doctest {
3329 namespace {
3330  using namespace detail;
3331  typedef std::map<std::pair<int, String>, IReporter*> reporterMap;
3332  reporterMap& getReporters() {
3333  static reporterMap data;
3334  return data;
3335  }
3336 
3337  void throwException() {
3338 #ifndef DOCTEST_CONFIG_NO_EXCEPTIONS
3339  throw TestFailureException();
3340 #endif // DOCTEST_CONFIG_NO_EXCEPTIONS
3341  }
3342 } // namespace
3343 namespace detail {
3344 #define DOCTEST_ITERATE_THROUGH_REPORTERS(function, args) \
3345  for(auto& curr_rep : g_contextState->reporters_currently_used) \
3346  curr_rep->function(args)
3347 
3348  DOCTEST_DEFINE_DEFAULTS(TestFailureException);
3349  DOCTEST_DEFINE_COPIES(TestFailureException);
3351  if(at & assertType::is_require)
3352  return true;
3353 
3354  if((at & assertType::is_check)
3355  && g_contextState->abort_after > 0 &&
3356  g_contextState->numAssertsFailed >= g_contextState->abort_after)
3357  return true;
3358 
3359  return false;
3360  }
3361 
3362  void fastAssertThrowIfFlagSet(int flags) {
3363  if(flags & assertAction::shouldthrow)
3364  throwException();
3365  }
3366 } // namespace detail
3367 
3368 namespace {
3369  using namespace detail;
3370  // matching of a string against a wildcard mask (case sensitivity configurable) taken from
3371  // https://www.codeproject.com/Articles/1088/Wildcard-string-compare-globbing
3372  int wildcmp(const char* str, const char* wild, bool caseSensitive) {
3373  const char* cp = 0;
3374  const char* mp = 0;
3375 
3376  while((*str) && (*wild != '*')) {
3377  if((caseSensitive ? (*wild != *str) : (tolower(*wild) != tolower(*str))) &&
3378  (*wild != '?')) {
3379  return 0;
3380  }
3381  wild++;
3382  str++;
3383  }
3384 
3385  while(*str) {
3386  if(*wild == '*') {
3387  if(!*++wild) {
3388  return 1;
3389  }
3390  mp = wild;
3391  cp = str + 1;
3392  } else if((caseSensitive ? (*wild == *str) : (tolower(*wild) == tolower(*str))) ||
3393  (*wild == '?')) {
3394  wild++;
3395  str++;
3396  } else {
3397  wild = mp;
3398  str = cp++;
3399  }
3400  }
3401 
3402  while(*wild == '*') {
3403  wild++;
3404  }
3405  return !*wild;
3406  }
3407 
3409  //unsigned hashStr(unsigned const char* str) {
3410  // unsigned long hash = 5381;
3411  // char c;
3412  // while((c = *str++))
3413  // hash = ((hash << 5) + hash) + c; // hash * 33 + c
3414  // return hash;
3415  //}
3416 
3417  // checks if the name matches any of the filters (and can be configured what to do when empty)
3418  bool matchesAny(const char* name, const std::vector<String>& filters, bool matchEmpty,
3419  bool caseSensitive) {
3420  if(filters.empty() && matchEmpty)
3421  return true;
3422  for(auto& curr : filters)
3423  if(wildcmp(name, curr.c_str(), caseSensitive))
3424  return true;
3425  return false;
3426  }
3427 
3428 #ifdef DOCTEST_PLATFORM_WINDOWS
3429 
3430  typedef unsigned long long UInt64;
3431 
3432  UInt64 getCurrentTicks() {
3433  static UInt64 hz = 0, hzo = 0;
3434  if(!hz) {
3435  QueryPerformanceFrequency(reinterpret_cast<LARGE_INTEGER*>(&hz));
3436  QueryPerformanceCounter(reinterpret_cast<LARGE_INTEGER*>(&hzo));
3437  }
3438  UInt64 t;
3439  QueryPerformanceCounter(reinterpret_cast<LARGE_INTEGER*>(&t));
3440  return ((t - hzo) * 1000000) / hz;
3441  }
3442 #else // DOCTEST_PLATFORM_WINDOWS
3443 
3444  typedef uint64_t UInt64;
3445 
3446  UInt64 getCurrentTicks() {
3447  timeval t;
3448  gettimeofday(&t, 0);
3449  return static_cast<UInt64>(t.tv_sec) * 1000000 + static_cast<UInt64>(t.tv_usec);
3450  }
3451 #endif // DOCTEST_PLATFORM_WINDOWS
3452 
3453  struct Timer
3454  {
3455  void start() { m_ticks = getCurrentTicks(); }
3456  unsigned int getElapsedMicroseconds() const {
3457  return static_cast<unsigned int>(getCurrentTicks() - m_ticks);
3458  }
3459  //unsigned int getElapsedMilliseconds() const {
3460  // return static_cast<unsigned int>(getElapsedMicroseconds() / 1000);
3461  //}
3462  double getElapsedSeconds() const { return getElapsedMicroseconds() / 1000000.0; }
3463 
3464  private:
3465  UInt64 m_ticks = 0;
3466  };
3467 
3468  Timer g_timer;
3469 } // namespace
3470 namespace detail {
3471  const ContextOptions* getContextOptions() { return g_contextState; }
3472 
3473  Subcase::Subcase(const char* name, const char* file, int line)
3474  : m_signature(name, file, line) {
3475  ContextState* s = g_contextState;
3476 
3477  // if we have already completed it
3478  if(s->subcasesPassed.count(m_signature) != 0)
3479  return;
3480 
3481  // check subcase filters
3482  if(s->subcasesCurrentLevel < s->subcase_filter_levels) {
3483  if(!matchesAny(m_signature.m_name, s->filters[6], true, s->case_sensitive))
3484  return;
3485  if(matchesAny(m_signature.m_name, s->filters[7], false, s->case_sensitive))
3486  return;
3487  }
3488 
3489  // if a Subcase on the same level has already been entered
3490  if(s->subcasesEnteredLevels.count(s->subcasesCurrentLevel) != 0) {
3491  s->should_reenter = true;
3492  return;
3493  }
3494 
3495  s->subcasesEnteredLevels.insert(s->subcasesCurrentLevel++);
3496  m_entered = true;
3497 
3498  DOCTEST_ITERATE_THROUGH_REPORTERS(subcase_start, m_signature);
3499  }
3500 
3501  Subcase::~Subcase() {
3502  if(m_entered) {
3503  ContextState* s = g_contextState;
3504 
3505  s->subcasesCurrentLevel--;
3506  // only mark the subcase as passed if no subcases have been skipped
3507  if(s->should_reenter == false)
3508  s->subcasesPassed.insert(m_signature);
3509 
3510  DOCTEST_ITERATE_THROUGH_REPORTERS(subcase_end, m_signature);
3511  }
3512  }
3513 
3514  Subcase::operator bool() const { return m_entered; }
3515 
3516  Result::Result(bool passed, const String& decomposition)
3517  : m_passed(passed)
3518  , m_decomposition(decomposition) {}
3519 
3520  DOCTEST_DEFINE_DEFAULTS(Result);
3521  DOCTEST_DEFINE_COPIES(Result);
3522 
3523  ExpressionDecomposer::ExpressionDecomposer(assertType::Enum at)
3524  : m_at(at) {}
3525 
3526  DOCTEST_DEFINE_DEFAULTS(ExpressionDecomposer);
3527 
3528  DOCTEST_DEFINE_DEFAULTS(TestSuite);
3529  DOCTEST_DEFINE_COPIES(TestSuite);
3530 
3531  TestSuite& TestSuite::operator*(const char* in) {
3532  m_test_suite = in;
3533  // clear state
3534  m_description = 0;
3535  m_skip = false;
3536  m_may_fail = false;
3537  m_should_fail = false;
3538  m_expected_failures = 0;
3539  m_timeout = 0;
3540  return *this;
3541  }
3542 
3543  TestCase::TestCase(funcType test, const char* file, unsigned line, const TestSuite& test_suite,
3544  const char* type, int template_id) {
3545  m_file = file;
3546  m_line = line;
3547  m_name = 0;
3548  m_test_suite = test_suite.m_test_suite;
3549  m_description = test_suite.m_description;
3550  m_skip = test_suite.m_skip;
3551  m_may_fail = test_suite.m_may_fail;
3552  m_should_fail = test_suite.m_should_fail;
3553  m_expected_failures = test_suite.m_expected_failures;
3554  m_timeout = test_suite.m_timeout;
3555 
3556  m_test = test;
3557  m_type = type;
3558  m_template_id = template_id;
3559  }
3560 
3561  DOCTEST_DEFINE_DEFAULTS(TestCase);
3562 
3563  TestCase::TestCase(const TestCase& other)
3564  : TestCaseData() {
3565  *this = other;
3566  }
3567 
3568  DOCTEST_MSVC_SUPPRESS_WARNING_WITH_PUSH(26434) // hides a non-virtual function
3569  DOCTEST_MSVC_SUPPRESS_WARNING(26437) // Do not slice
3570  TestCase& TestCase::operator=(const TestCase& other) {
3571  static_cast<TestCaseData&>(*this) = static_cast<const TestCaseData&>(other);
3572 
3573  m_test = other.m_test;
3574  m_type = other.m_type;
3575  m_template_id = other.m_template_id;
3576  m_full_name = other.m_full_name;
3577 
3578  if(m_template_id != -1)
3579  m_name = m_full_name.c_str();
3580  return *this;
3581  }
3582  DOCTEST_MSVC_SUPPRESS_WARNING_POP
3583 
3584  TestCase& TestCase::operator*(const char* in) {
3585  m_name = in;
3586  // make a new name with an appended type for templated test case
3587  if(m_template_id != -1) {
3588  m_full_name = String(m_name) + m_type;
3589  // redirect the name to point to the newly constructed full name
3590  m_name = m_full_name.c_str();
3591  }
3592  return *this;
3593  }
3594 
3595  bool TestCase::operator<(const TestCase& other) const {
3596  if(m_line != other.m_line)
3597  return m_line < other.m_line;
3598  const int file_cmp = std::strcmp(m_file, other.m_file);
3599  if(file_cmp != 0)
3600  return file_cmp < 0;
3601  return m_template_id < other.m_template_id;
3602  }
3603 } // namespace detail
3604 namespace {
3605  using namespace detail;
3606  // for sorting tests by file/line
3607  int fileOrderComparator(const void* a, const void* b) {
3608  auto lhs = *static_cast<TestCase* const*>(a);
3609  auto rhs = *static_cast<TestCase* const*>(b);
3610 #if DOCTEST_MSVC
3611  // this is needed because MSVC gives different case for drive letters
3612  // for __FILE__ when evaluated in a header and a source file
3613  const int res = stricmp(lhs->m_file, rhs->m_file);
3614 #else // MSVC
3615  const int res = std::strcmp(lhs->m_file, rhs->m_file);
3616 #endif // MSVC
3617  if(res != 0)
3618  return res;
3619  return static_cast<int>(lhs->m_line - rhs->m_line);
3620  }
3621 
3622  // for sorting tests by suite/file/line
3623  int suiteOrderComparator(const void* a, const void* b) {
3624  auto lhs = *static_cast<TestCase* const*>(a);
3625  auto rhs = *static_cast<TestCase* const*>(b);
3626 
3627  const int res = std::strcmp(lhs->m_test_suite, rhs->m_test_suite);
3628  if(res != 0)
3629  return res;
3630  return fileOrderComparator(a, b);
3631  }
3632 
3633  // for sorting tests by name/suite/file/line
3634  int nameOrderComparator(const void* a, const void* b) {
3635  auto lhs = *static_cast<TestCase* const*>(a);
3636  auto rhs = *static_cast<TestCase* const*>(b);
3637 
3638  const int res_name = std::strcmp(lhs->m_name, rhs->m_name);
3639  if(res_name != 0)
3640  return res_name;
3641  return suiteOrderComparator(a, b);
3642  }
3643 
3644  // all the registered tests
3645  std::set<TestCase>& getRegisteredTests() {
3646  static std::set<TestCase> data;
3647  return data;
3648  }
3649 
3650 #ifdef DOCTEST_CONFIG_COLORS_WINDOWS
3651  HANDLE g_stdoutHandle;
3652  WORD g_origFgAttrs;
3653  WORD g_origBgAttrs;
3654  bool g_attrsInitted = false;
3655 
3656  int colors_init() {
3657  if(!g_attrsInitted) {
3658  g_stdoutHandle = GetStdHandle(STD_OUTPUT_HANDLE);
3659  g_attrsInitted = true;
3660  CONSOLE_SCREEN_BUFFER_INFO csbiInfo;
3661  GetConsoleScreenBufferInfo(g_stdoutHandle, &csbiInfo);
3662  g_origFgAttrs = csbiInfo.wAttributes & ~(BACKGROUND_GREEN | BACKGROUND_RED |
3663  BACKGROUND_BLUE | BACKGROUND_INTENSITY);
3664  g_origBgAttrs = csbiInfo.wAttributes & ~(FOREGROUND_GREEN | FOREGROUND_RED |
3665  FOREGROUND_BLUE | FOREGROUND_INTENSITY);
3666  }
3667  return 0;
3668  }
3669 
3670  int dumy_init_console_colors = colors_init();
3671 #endif // DOCTEST_CONFIG_COLORS_WINDOWS
3672 
3673  void color_to_stream(std::ostream& s, Color::Enum code) {
3674  ((void)s); // for DOCTEST_CONFIG_COLORS_NONE or DOCTEST_CONFIG_COLORS_WINDOWS
3675  ((void)code); // for DOCTEST_CONFIG_COLORS_NONE
3676 #ifdef DOCTEST_CONFIG_COLORS_ANSI
3677  if(g_contextState->no_colors ||
3678  (isatty(STDOUT_FILENO) == false && g_contextState->force_colors == false))
3679  return;
3680 
3681  auto col = "";
3682  // clang-format off
3683  switch(code) {
3684  case Color::Red: col = "[0;31m"; break;
3685  case Color::Green: col = "[0;32m"; break;
3686  case Color::Blue: col = "[0;34m"; break;
3687  case Color::Cyan: col = "[0;36m"; break;
3688  case Color::Yellow: col = "[0;33m"; break;
3689  case Color::Grey: col = "[1;30m"; break;
3690  case Color::LightGrey: col = "[0;37m"; break;
3691  case Color::BrightRed: col = "[1;31m"; break;
3692  case Color::BrightGreen: col = "[1;32m"; break;
3693  case Color::BrightWhite: col = "[1;37m"; break;
3694  case Color::Bright: // invalid
3695  case Color::None:
3696  case Color::White:
3697  default: col = "[0m";
3698  }
3699  // clang-format on
3700  s << "\033" << col;
3701 #endif // DOCTEST_CONFIG_COLORS_ANSI
3702 
3703 #ifdef DOCTEST_CONFIG_COLORS_WINDOWS
3704  if(g_contextState->no_colors ||
3705  (isatty(fileno(stdout)) == false && g_contextState->force_colors == false))
3706  return;
3707 
3708 #define DOCTEST_SET_ATTR(x) SetConsoleTextAttribute(g_stdoutHandle, x | g_origBgAttrs)
3709 
3710  // clang-format off
3711  switch (code) {
3712  case Color::White: DOCTEST_SET_ATTR(FOREGROUND_GREEN | FOREGROUND_RED | FOREGROUND_BLUE); break;
3713  case Color::Red: DOCTEST_SET_ATTR(FOREGROUND_RED); break;
3714  case Color::Green: DOCTEST_SET_ATTR(FOREGROUND_GREEN); break;
3715  case Color::Blue: DOCTEST_SET_ATTR(FOREGROUND_BLUE); break;
3716  case Color::Cyan: DOCTEST_SET_ATTR(FOREGROUND_BLUE | FOREGROUND_GREEN); break;
3717  case Color::Yellow: DOCTEST_SET_ATTR(FOREGROUND_RED | FOREGROUND_GREEN); break;
3718  case Color::Grey: DOCTEST_SET_ATTR(0); break;
3719  case Color::LightGrey: DOCTEST_SET_ATTR(FOREGROUND_INTENSITY); break;
3720  case Color::BrightRed: DOCTEST_SET_ATTR(FOREGROUND_INTENSITY | FOREGROUND_RED); break;
3721  case Color::BrightGreen: DOCTEST_SET_ATTR(FOREGROUND_INTENSITY | FOREGROUND_GREEN); break;
3722  case Color::BrightWhite: DOCTEST_SET_ATTR(FOREGROUND_INTENSITY | FOREGROUND_GREEN | FOREGROUND_RED | FOREGROUND_BLUE); break;
3723  case Color::None:
3724  case Color::Bright: // invalid
3725  default: DOCTEST_SET_ATTR(g_origFgAttrs);
3726  }
3727  // clang-format on
3728 #endif // DOCTEST_CONFIG_COLORS_WINDOWS
3729  }
3730 
3731  std::vector<const IExceptionTranslator*>& getExceptionTranslators() {
3732  static std::vector<const IExceptionTranslator*> data;
3733  return data;
3734  }
3735 
3736  String translateActiveException() {
3737 #ifndef DOCTEST_CONFIG_NO_EXCEPTIONS
3738  String res;
3739  auto& translators = getExceptionTranslators();
3740  for(auto& curr : translators)
3741  if(curr->translate(res))
3742  return res;
3743  // clang-format off
3744  try {
3745  throw;
3746  } catch(std::exception& ex) {
3747  return ex.what();
3748  } catch(std::string& msg) {
3749  return msg.c_str();
3750  } catch(const char* msg) {
3751  return msg;
3752  } catch(...) {
3753  return "unknown exception";
3754  }
3755 // clang-format on
3756 #else // DOCTEST_CONFIG_NO_EXCEPTIONS
3757  return "";
3758 #endif // DOCTEST_CONFIG_NO_EXCEPTIONS
3759  }
3760 } // namespace
3761 
3762 namespace detail {
3763  // used by the macros for registering tests
3764  int regTest(const TestCase& tc) {
3765  getRegisteredTests().insert(tc);
3766  return 0;
3767  }
3768 
3769  // sets the current test suite
3770  int setTestSuite(const TestSuite& ts) {
3772  return 0;
3773  }
3774 
3775  void registerExceptionTranslatorImpl(const IExceptionTranslator* translateFunction) {
3776  if(std::find(getExceptionTranslators().begin(), getExceptionTranslators().end(),
3777  translateFunction) == getExceptionTranslators().end())
3778  getExceptionTranslators().push_back(translateFunction);
3779  }
3780 
3781  void writeStringToStream(std::ostream* s, const String& str) { *s << str; }
3782 
3783 #ifdef DOCTEST_CONFIG_TREAT_CHAR_STAR_AS_STRING
3784  void toStream(std::ostream* s, char* in) { *s << in; }
3785  void toStream(std::ostream* s, const char* in) { *s << in; }
3786 #endif // DOCTEST_CONFIG_TREAT_CHAR_STAR_AS_STRING
3787  void toStream(std::ostream* s, bool in) { *s << std::boolalpha << in << std::noboolalpha; }
3788  void toStream(std::ostream* s, float in) { *s << in; }
3789  void toStream(std::ostream* s, double in) { *s << in; }
3790  void toStream(std::ostream* s, double long in) { *s << in; }
3791 
3792  void toStream(std::ostream* s, char in) { *s << in; }
3793  void toStream(std::ostream* s, char signed in) { *s << in; }
3794  void toStream(std::ostream* s, char unsigned in) { *s << in; }
3795  void toStream(std::ostream* s, int short in) { *s << in; }
3796  void toStream(std::ostream* s, int short unsigned in) { *s << in; }
3797  void toStream(std::ostream* s, int in) { *s << in; }
3798  void toStream(std::ostream* s, int unsigned in) { *s << in; }
3799  void toStream(std::ostream* s, int long in) { *s << in; }
3800  void toStream(std::ostream* s, int long unsigned in) { *s << in; }
3801  void toStream(std::ostream* s, int long long in) { *s << in; }
3802  void toStream(std::ostream* s, int long long unsigned in) { *s << in; }
3803 
3804  ContextBuilder::ICapture::ICapture() = default;
3805  ContextBuilder::ICapture::~ICapture() = default;
3806 
3807  ContextBuilder::Chunk::Chunk() = default;
3808  ContextBuilder::Chunk::~Chunk() = default;
3809 
3810  ContextBuilder::Node::Node() = default;
3811  ContextBuilder::Node::~Node() = default;
3812 
3813  // steal the contents of the other - acting as a move constructor...
3814  ContextBuilder::ContextBuilder(ContextBuilder& other)
3815  : numCaptures(other.numCaptures)
3816  , head(other.head)
3817  , tail(other.tail) {
3818  other.numCaptures = 0;
3819  other.head = 0;
3820  other.tail = 0;
3821  memcpy(stackChunks, other.stackChunks,
3822  unsigned(int(sizeof(Chunk)) * DOCTEST_CONFIG_NUM_CAPTURES_ON_STACK));
3823  }
3824 
3825  DOCTEST_GCC_SUPPRESS_WARNING_WITH_PUSH("-Wcast-align")
3826  void ContextBuilder::stringify(std::ostream* s) const {
3827  int curr = 0;
3828  // iterate over small buffer
3829  while(curr < numCaptures && curr < DOCTEST_CONFIG_NUM_CAPTURES_ON_STACK)
3830  reinterpret_cast<const ICapture*>(stackChunks[curr++].buf)->toStream(s);
3831  // iterate over list
3832  auto curr_elem = head;
3833  while(curr < numCaptures) {
3834  reinterpret_cast<const ICapture*>(curr_elem->chunk.buf)->toStream(s);
3835  curr_elem = curr_elem->next;
3836  ++curr;
3837  }
3838  }
3839  DOCTEST_GCC_SUPPRESS_WARNING_POP
3840 
3841  ContextBuilder::ContextBuilder() = default;
3842 
3843  ContextBuilder::~ContextBuilder() {
3844  // free the linked list - the ones on the stack are left as-is
3845  // no destructors are called at all - there is no need
3846  while(head) {
3847  auto next = head->next;
3848  delete head;
3849  head = next;
3850  }
3851  }
3852 
3853  ContextScope::ContextScope(ContextBuilder& temp)
3854  : contextBuilder(temp) {
3855  g_contextState->contexts.push_back(this);
3856  }
3857 
3858  DOCTEST_MSVC_SUPPRESS_WARNING_WITH_PUSH(4996) // std::uncaught_exception is deprecated in C++17
3859  DOCTEST_GCC_SUPPRESS_WARNING_WITH_PUSH("-Wdeprecated-declarations")
3860  ContextScope::~ContextScope() {
3861  if(std::uncaught_exception()) {
3862  std::ostringstream s;
3863  this->stringify(&s);
3864  g_contextState->stringifiedContexts.push_back(s.str().c_str());
3865  }
3866  g_contextState->contexts.pop_back();
3867  }
3868  DOCTEST_GCC_SUPPRESS_WARNING_POP
3869  DOCTEST_MSVC_SUPPRESS_WARNING_POP
3870 
3871  void ContextScope::stringify(std::ostream* s) const { contextBuilder.stringify(s); }
3872 } // namespace detail
3873 namespace {
3874  using namespace detail;
3875 #if !defined(DOCTEST_CONFIG_POSIX_SIGNALS) && !defined(DOCTEST_CONFIG_WINDOWS_SEH)
3876  struct FatalConditionHandler
3877  {
3878  void reset() {}
3879  };
3880 #else // DOCTEST_CONFIG_POSIX_SIGNALS || DOCTEST_CONFIG_WINDOWS_SEH
3881 
3882  void reportFatal(const std::string&);
3883 
3884 #ifdef DOCTEST_PLATFORM_WINDOWS
3885 
3886  struct SignalDefs
3887  {
3888  DWORD id;
3889  const char* name;
3890  };
3891  // There is no 1-1 mapping between signals and windows exceptions.
3892  // Windows can easily distinguish between SO and SigSegV,
3893  // but SigInt, SigTerm, etc are handled differently.
3894  SignalDefs signalDefs[] = {
3895  {EXCEPTION_ILLEGAL_INSTRUCTION, "SIGILL - Illegal instruction signal"},
3896  {EXCEPTION_STACK_OVERFLOW, "SIGSEGV - Stack overflow"},
3897  {EXCEPTION_ACCESS_VIOLATION, "SIGSEGV - Segmentation violation signal"},
3898  {EXCEPTION_INT_DIVIDE_BY_ZERO, "Divide by zero error"},
3899  };
3900 
3901  struct FatalConditionHandler
3902  {
3903  static LONG CALLBACK handleVectoredException(PEXCEPTION_POINTERS ExceptionInfo) {
3904  for(size_t i = 0; i < DOCTEST_COUNTOF(signalDefs); ++i) {
3905  if(ExceptionInfo->ExceptionRecord->ExceptionCode == signalDefs[i].id) {
3906  reportFatal(signalDefs[i].name);
3907  }
3908  }
3909  // If its not an exception we care about, pass it along.
3910  // This stops us from eating debugger breaks etc.
3911  return EXCEPTION_CONTINUE_SEARCH;
3912  }
3913 
3914  FatalConditionHandler() {
3915  isSet = true;
3916  // 32k seems enough for doctest to handle stack overflow,
3917  // but the value was found experimentally, so there is no strong guarantee
3918  guaranteeSize = 32 * 1024;
3919  exceptionHandlerHandle = 0;
3920  // Register as first handler in current chain
3921  exceptionHandlerHandle = AddVectoredExceptionHandler(1, handleVectoredException);
3922  // Pass in guarantee size to be filled
3923  SetThreadStackGuarantee(&guaranteeSize);
3924  }
3925 
3926  static void reset() {
3927  if(isSet) {
3928  // Unregister handler and restore the old guarantee
3929  RemoveVectoredExceptionHandler(exceptionHandlerHandle);
3930  SetThreadStackGuarantee(&guaranteeSize);
3931  exceptionHandlerHandle = 0;
3932  isSet = false;
3933  }
3934  }
3935 
3936  ~FatalConditionHandler() { reset(); }
3937 
3938  private:
3939  static bool isSet;
3940  static ULONG guaranteeSize;
3941  static PVOID exceptionHandlerHandle;
3942  };
3943 
3944  bool FatalConditionHandler::isSet = false;
3945  ULONG FatalConditionHandler::guaranteeSize = 0;
3946  PVOID FatalConditionHandler::exceptionHandlerHandle = 0;
3947 
3948 #else // DOCTEST_PLATFORM_WINDOWS
3949 
3950  struct SignalDefs
3951  {
3952  int id;
3953  const char* name;
3954  };
3955  SignalDefs signalDefs[] = {{SIGINT, "SIGINT - Terminal interrupt signal"},
3956  {SIGILL, "SIGILL - Illegal instruction signal"},
3957  {SIGFPE, "SIGFPE - Floating point error signal"},
3958  {SIGSEGV, "SIGSEGV - Segmentation violation signal"},
3959  {SIGTERM, "SIGTERM - Termination request signal"},
3960  {SIGABRT, "SIGABRT - Abort (abnormal termination) signal"}};
3961 
3962  struct FatalConditionHandler
3963  {
3964  static bool isSet;
3965  static struct sigaction oldSigActions[DOCTEST_COUNTOF(signalDefs)];
3966  static stack_t oldSigStack;
3967  static char altStackMem[4 * SIGSTKSZ];
3968 
3969  static void handleSignal(int sig) {
3970  std::string name = "<unknown signal>";
3971  for(std::size_t i = 0; i < DOCTEST_COUNTOF(signalDefs); ++i) {
3972  SignalDefs& def = signalDefs[i];
3973  if(sig == def.id) {
3974  name = def.name;
3975  break;
3976  }
3977  }
3978  reset();
3979  reportFatal(name);
3980  raise(sig);
3981  }
3982 
3983  FatalConditionHandler() {
3984  isSet = true;
3985  stack_t sigStack;
3986  sigStack.ss_sp = altStackMem;
3987  sigStack.ss_size = sizeof(altStackMem);
3988  sigStack.ss_flags = 0;
3989  sigaltstack(&sigStack, &oldSigStack);
3990  struct sigaction sa = {0};
3991 
3992  sa.sa_handler = handleSignal; // NOLINT
3993  sa.sa_flags = SA_ONSTACK;
3994  for(std::size_t i = 0; i < DOCTEST_COUNTOF(signalDefs); ++i) {
3995  sigaction(signalDefs[i].id, &sa, &oldSigActions[i]);
3996  }
3997  }
3998 
3999  ~FatalConditionHandler() { reset(); }
4000  static void reset() {
4001  if(isSet) {
4002  // Set signals back to previous values -- hopefully nobody overwrote them in the meantime
4003  for(std::size_t i = 0; i < DOCTEST_COUNTOF(signalDefs); ++i) {
4004  sigaction(signalDefs[i].id, &oldSigActions[i], 0);
4005  }
4006  // Return the old stack
4007  sigaltstack(&oldSigStack, 0);
4008  isSet = false;
4009  }
4010  }
4011  };
4012 
4013  bool FatalConditionHandler::isSet = false;
4014  struct sigaction FatalConditionHandler::oldSigActions[DOCTEST_COUNTOF(signalDefs)] = {};
4015  stack_t FatalConditionHandler::oldSigStack = {};
4016  char FatalConditionHandler::altStackMem[] = {};
4017 
4018 #endif // DOCTEST_PLATFORM_WINDOWS
4019 #endif // DOCTEST_CONFIG_POSIX_SIGNALS || DOCTEST_CONFIG_WINDOWS_SEH
4020 
4021 } // namespace
4022 
4023 // TODO: wtf? these are in namespace doctest::detail - and don't error ?!?! perhaps it's all C externs..
4024 #ifdef DOCTEST_PLATFORM_MAC
4025 #include <sys/types.h>
4026 #include <unistd.h>
4027 #include <sys/sysctl.h>
4028 #endif // DOCTEST_PLATFORM_MAC
4029 
4030 namespace {
4031  using namespace detail;
4032 #ifdef DOCTEST_PLATFORM_MAC
4033  // The following function is taken directly from the following technical note:
4034  // http://developer.apple.com/library/mac/#qa/qa2004/qa1361.html
4035  // Returns true if the current process is being debugged (either
4036  // running under the debugger or has a debugger attached post facto).
4037  bool isDebuggerActive() {
4038  int mib[4];
4039  kinfo_proc info;
4040  size_t size;
4041  // Initialize the flags so that, if sysctl fails for some bizarre
4042  // reason, we get a predictable result.
4043  info.kp_proc.p_flag = 0;
4044  // Initialize mib, which tells sysctl the info we want, in this case
4045  // we're looking for information about a specific process ID.
4046  mib[0] = CTL_KERN;
4047  mib[1] = KERN_PROC;
4048  mib[2] = KERN_PROC_PID;
4049  mib[3] = getpid();
4050  // Call sysctl.
4051  size = sizeof(info);
4052  if(sysctl(mib, DOCTEST_COUNTOF(mib), &info, &size, 0, 0) != 0) {
4053  fprintf(stderr, "\n** Call to sysctl failed - unable to determine if debugger is "
4054  "active **\n\n");
4055  return false;
4056  }
4057  // We're being debugged if the P_TRACED flag is set.
4058  return ((info.kp_proc.p_flag & P_TRACED) != 0);
4059  }
4060 #elif DOCTEST_MSVC || defined(__MINGW32__)
4061  bool isDebuggerActive() { return ::IsDebuggerPresent() != 0; }
4062 #else
4063  bool isDebuggerActive() { return false; }
4064 #endif // Platform
4065 
4066 #ifdef DOCTEST_PLATFORM_WINDOWS
4067 #define DOCTEST_OUTPUT_DEBUG_STRING(text) ::OutputDebugStringA(text)
4068 #else
4069  // TODO: integration with XCode and other IDEs
4070 #define DOCTEST_OUTPUT_DEBUG_STRING(text)
4071 #endif // Platform
4072 
4073  void addAssert(assertType::Enum at) {
4074  if((at & assertType::is_warn) == 0) {
4075  g_contextState->numAsserts++;
4076  g_contextState->numAssertsForCurrentTestCase++;
4077  }
4078  }
4079 
4080  void addFailedAssert(assertType::Enum at) {
4081  if((at & assertType::is_warn) == 0) {
4082  g_contextState->numAssertsFailed++;
4083  g_contextState->numAssertsFailedForCurrentTestCase++;
4084  }
4085  }
4086 
4087 #if defined(DOCTEST_CONFIG_POSIX_SIGNALS) || defined(DOCTEST_CONFIG_WINDOWS_SEH)
4088  void reportFatal(const std::string& message) {
4089  g_contextState->seconds_so_far += g_timer.getElapsedSeconds();
4090  g_contextState->failure_flags |= TestCaseFailureReason::Crash;
4091  g_contextState->error_string = message.c_str();
4092  g_contextState->should_reenter = false;
4093 
4094  // TODO: end all currently opened subcases...?
4095 
4096  DOCTEST_ITERATE_THROUGH_REPORTERS(test_case_end, *g_contextState);
4097 
4098  g_contextState->numTestCasesFailed++;
4099 
4100  DOCTEST_ITERATE_THROUGH_REPORTERS(test_run_end, *g_contextState);
4101  }
4102 #endif // DOCTEST_CONFIG_POSIX_SIGNALS || DOCTEST_CONFIG_WINDOWS_SEH
4103 } // namespace
4104 namespace detail {
4105  ResultBuilder::ResultBuilder(assertType::Enum at, const char* file, int line, const char* expr,
4106  const char* exception_type) {
4107  m_test_case = g_contextState->currentTest;
4108  m_at = at;
4109  m_file = file;
4110  m_line = line;
4111  m_expr = expr;
4112  m_failed = true;
4113  m_threw = false;
4114  m_threw_as = false;
4115  m_exception_type = exception_type;
4116 #if DOCTEST_MSVC
4117  if(m_expr[0] == ' ') // this happens when variadic macros are disabled under MSVC
4118  ++m_expr;
4119 #endif // MSVC
4120  }
4121 
4122  DOCTEST_DEFINE_DEFAULTS(ResultBuilder);
4123 
4124  void ResultBuilder::setResult(const Result& res) {
4125  m_decomposition = res.m_decomposition;
4126  m_failed = !res.m_passed;
4127  }
4128 
4129  void ResultBuilder::unexpectedExceptionOccurred() {
4130  m_threw = true;
4131  m_exception = translateActiveException();
4132  }
4133 
4134  bool ResultBuilder::log() {
4135  addAssert(m_at);
4136 
4137  if(m_at & assertType::is_throws) {
4138  m_failed = !m_threw;
4139  } else if(m_at & assertType::is_throws_as) {
4140  m_failed = !m_threw_as;
4141  } else if(m_at & assertType::is_nothrow) {
4142  m_failed = m_threw;
4143  }
4144 
4145  DOCTEST_ITERATE_THROUGH_REPORTERS(log_assert, *this);
4146 
4147  if(m_failed)
4148  addFailedAssert(m_at);
4149 
4150  return m_failed && isDebuggerActive() && !g_contextState->no_breaks; // break into debugger
4151  }
4152 
4153  void ResultBuilder::react() const {
4154  if(m_failed && checkIfShouldThrow(m_at))
4155  throwException();
4156  }
4157 
4158  MessageBuilder::MessageBuilder(const char* file, int line, assertType::Enum severity) {
4159  m_stream = createStream();
4160  m_file = file;
4161  m_line = line;
4162  m_severity = severity;
4163  }
4164 
4165  IExceptionTranslator::IExceptionTranslator() = default;
4166  IExceptionTranslator::~IExceptionTranslator() = default;
4167 
4168  bool MessageBuilder::log() {
4169  m_string = getStreamResult(m_stream);
4170  DOCTEST_ITERATE_THROUGH_REPORTERS(log_message, *this);
4171 
4172  const bool isWarn = m_severity & assertType::is_warn;
4173 
4174  // warn is just a message in this context so we dont treat it as an assert
4175  if(!isWarn) {
4176  addAssert(m_severity);
4177  addFailedAssert(m_severity);
4178  }
4179 
4180  return isDebuggerActive() && !g_contextState->no_breaks && !isWarn; // break into debugger
4181  }
4182 
4183  void MessageBuilder::react() {
4184  if(m_severity & assertType::is_require)
4185  throwException();
4186  }
4187 
4188  MessageBuilder::~MessageBuilder() { freeStream(m_stream); }
4189 } // namespace detail
4190 namespace {
4191  using namespace detail;
4192  struct ConsoleReporter : public IReporter
4193  {
4194  std::ostream& s;
4195  bool hasLoggedCurrentTestStart;
4196  std::vector<SubcaseSignature> subcasesStack;
4197 
4198  // caching pointers to objects of these types - safe to do
4199  const ContextOptions* opt;
4200  const TestCaseData* tc;
4201 
4202  ConsoleReporter(std::ostream& in)
4203  : s(in) {}
4204 
4205  // =========================================================================================
4206  // WHAT FOLLOWS ARE HELPERS USED BY THE OVERRIDES OF THE VIRTUAL METHODS OF THE INTERFACE
4207  // =========================================================================================
4208 
4209  void separator_to_stream() {
4210  s << Color::Yellow
4211  << "============================================================================="
4212  "=="
4213  "\n";
4214  }
4215 
4216  // depending on the current options this will remove the path of filenames
4217  const char* file_for_output(const char* file) {
4218  if(opt->no_path_in_filenames) {
4219  auto back = std::strrchr(file, '\\');
4220  auto forward = std::strrchr(file, '/');
4221  if(back || forward) {
4222  if(back > forward)
4223  forward = back;
4224  return forward + 1;
4225  }
4226  }
4227  return file;
4228  }
4229 
4230  void file_line_to_stream(const char* file, int line, const char* tail = "") {
4231  s << Color::LightGrey << file_for_output(file) << (opt->gnu_file_line ? ":" : "(")
4232  << (opt->no_line_numbers ? 0 : line) // 0 or the real num depending on the option
4233  << (opt->gnu_file_line ? ":" : "):") << tail;
4234  }
4235 
4236  const char* getSuccessOrFailString(bool success, assertType::Enum at,
4237  const char* success_str) {
4238  if(success)
4239  return success_str;
4240  if(at & assertType::is_warn)
4241  return "WARNING: ";
4242  if(at & assertType::is_check)
4243  return "ERROR: ";
4244  if(at & assertType::is_require)
4245  return "FATAL ERROR: ";
4246  return "";
4247  }
4248 
4249  Color::Enum getSuccessOrFailColor(bool success, assertType::Enum at) {
4250  return success ? Color::BrightGreen :
4252  }
4253 
4254  void successOrFailColoredStringToStream(bool success, assertType::Enum at,
4255  const char* success_str = "SUCCESS: ") {
4256  s << getSuccessOrFailColor(success, at)
4257  << getSuccessOrFailString(success, at, success_str);
4258  }
4259 
4260  void log_contexts() {
4261  int num_contexts = get_num_active_contexts();
4262  if(num_contexts) {
4263  auto contexts = get_active_contexts();
4264 
4265  s << Color::None << " logged: ";
4266  for(int i = 0; i < num_contexts; ++i) {
4267  s << (i == 0 ? "" : " ");
4268  contexts[i]->stringify(&s);
4269  s << "\n";
4270  }
4271  }
4272 
4273  s << "\n";
4274  }
4275 
4276  void logTestStart() {
4277  if(hasLoggedCurrentTestStart)
4278  return;
4279 
4280  separator_to_stream();
4281  file_line_to_stream(tc->m_file, tc->m_line, "\n");
4282  if(tc->m_description)
4283  s << Color::Yellow << "DESCRIPTION: " << Color::None << tc->m_description << "\n";
4284  if(tc->m_test_suite && tc->m_test_suite[0] != '\0')
4285  s << Color::Yellow << "TEST SUITE: " << Color::None << tc->m_test_suite << "\n";
4286  if(strncmp(tc->m_name, " Scenario:", 11) != 0)
4287  s << Color::None << "TEST CASE: ";
4288  s << Color::None << tc->m_name << "\n";
4289 
4290  for(auto& curr : subcasesStack)
4291  if(curr.m_name[0] != '\0')
4292  s << " " << curr.m_name << "\n";
4293 
4294  s << "\n";
4295 
4296  hasLoggedCurrentTestStart = true;
4297  }
4298 
4299  // =========================================================================================
4300  // WHAT FOLLOWS ARE OVERRIDES OF THE VIRTUAL METHODS OF THE REPORTER INTERFACE
4301  // =========================================================================================
4302 
4303  void test_run_start(const ContextOptions& o) override { opt = &o; }
4304 
4305  void test_run_end(const TestRunStats& p) override {
4306  separator_to_stream();
4307 
4308  const bool anythingFailed = p.numTestCasesFailed > 0 || p.numAssertsFailed > 0;
4309  s << Color::Cyan << "[doctest] " << Color::None << "test cases: " << std::setw(6)
4310  << p.numTestCasesPassingFilters << " | "
4311  << ((p.numTestCasesPassingFilters == 0 || anythingFailed) ? Color::None :
4312  Color::Green)
4313  << std::setw(6) << p.numTestCasesPassingFilters - p.numTestCasesFailed << " passed"
4314  << Color::None << " | " << (p.numTestCasesFailed > 0 ? Color::Red : Color::None)
4315  << std::setw(6) << p.numTestCasesFailed << " failed" << Color::None << " | ";
4316  if(opt->no_skipped_summary == false) {
4317  const int numSkipped = p.numTestCases - p.numTestCasesPassingFilters;
4318  s << (numSkipped == 0 ? Color::None : Color::Yellow) << std::setw(6) << numSkipped
4319  << " skipped" << Color::None;
4320  }
4321  s << "\n";
4322  s << Color::Cyan << "[doctest] " << Color::None << "assertions: " << std::setw(6)
4323  << p.numAsserts << " | "
4324  << ((p.numAsserts == 0 || anythingFailed) ? Color::None : Color::Green)
4325  << std::setw(6) << (p.numAsserts - p.numAssertsFailed) << " passed" << Color::None
4326  << " | " << (p.numAssertsFailed > 0 ? Color::Red : Color::None) << std::setw(6)
4327  << p.numAssertsFailed << " failed" << Color::None << " |\n";
4328  s << Color::Cyan << "[doctest] " << Color::None
4329  << "Status: " << (p.numTestCasesFailed > 0 ? Color::Red : Color::Green)
4330  << ((p.numTestCasesFailed > 0) ? "FAILURE!\n" : "SUCCESS!\n") << Color::None;
4331  }
4332 
4333  void test_case_start(const TestCaseData& in) override {
4334  hasLoggedCurrentTestStart = false;
4335  tc = &in;
4336  }
4337 
4338  void test_case_end(const CurrentTestCaseStats& st) override {
4339  // log the preamble of the test case only if there is something
4340  // else to print - something other than that an assert has failed
4341  if(opt->duration ||
4342  (st.failure_flags && st.failure_flags != TestCaseFailureReason::AssertFailure))
4343  logTestStart();
4344 
4345  // report test case exceptions and crashes
4346  bool crashed = st.failure_flags & TestCaseFailureReason::Crash;
4347  if(crashed || (st.failure_flags & TestCaseFailureReason::Exception)) {
4348  file_line_to_stream(tc->m_file, tc->m_line, " ");
4349  successOrFailColoredStringToStream(false, crashed ? assertType::is_require :
4351  s << Color::Red << (crashed ? "test case CRASHED: " : "test case THREW exception: ")
4352  << Color::Cyan << st.error_string << "\n";
4353 
4354  int num_stringified_contexts = get_num_stringified_contexts();
4355  if(num_stringified_contexts) {
4356  auto stringified_contexts = get_stringified_contexts();
4357  s << Color::None << " logged: ";
4358  for(int i = num_stringified_contexts - 1; i >= 0; --i) {
4359  s << (i == num_stringified_contexts - 1 ? "" : " ")
4360  << stringified_contexts[i] << "\n";
4361  }
4362  }
4363  s << "\n";
4364  }
4365 
4366  // means the test case will be re-entered because there are untraversed (but discovered) subcases
4367  if(st.should_reenter)
4368  return;
4369 
4370  if(opt->duration)
4371  s << Color::None << std::setprecision(6) << std::fixed << st.seconds_so_far
4372  << " s: " << tc->m_name << "\n";
4373 
4374  if(st.failure_flags & TestCaseFailureReason::Timeout)
4375  s << Color::Red << "Test case exceeded time limit of " << std::setprecision(6)
4376  << std::fixed << tc->m_timeout << "!\n";
4377 
4378  if(st.failure_flags & TestCaseFailureReason::ShouldHaveFailedButDidnt) {
4379  s << Color::Red << "Should have failed but didn't! Marking it as failed!\n";
4380  } else if(st.failure_flags & TestCaseFailureReason::ShouldHaveFailedAndDid) {
4381  s << Color::Yellow << "Failed as expected so marking it as not failed\n";
4382  } else if(st.failure_flags & TestCaseFailureReason::CouldHaveFailedAndDid) {
4383  s << Color::Yellow << "Allowed to fail so marking it as not failed\n";
4384  } else if(st.failure_flags & TestCaseFailureReason::DidntFailExactlyNumTimes) {
4385  s << Color::Red << "Didn't fail exactly " << tc->m_expected_failures
4386  << " times so marking it as failed!\n";
4387  } else if(st.failure_flags & TestCaseFailureReason::FailedExactlyNumTimes) {
4388  s << Color::Yellow << "Failed exactly " << tc->m_expected_failures
4389  << " times as expected so marking it as not failed!\n";
4390  }
4391  if(st.failure_flags & TestCaseFailureReason::TooManyFailedAsserts) {
4392  s << Color::Red << "Aborting - too many failed asserts!\n";
4393  }
4394  s << Color::None;
4395  }
4396 
4397  void subcase_start(const SubcaseSignature& subc) override {
4398  subcasesStack.push_back(subc);
4399  hasLoggedCurrentTestStart = false;
4400  }
4401 
4402  void subcase_end(const SubcaseSignature& /*subc*/) override {
4403  subcasesStack.pop_back();
4404  hasLoggedCurrentTestStart = false;
4405  }
4406 
4407  void log_assert(const AssertData& rb) override {
4408  if(!rb.m_failed && !opt->success)
4409  return;
4410 
4411  logTestStart();
4412 
4413  file_line_to_stream(rb.m_file, rb.m_line, " ");
4414  successOrFailColoredStringToStream(!rb.m_failed, rb.m_at);
4415  if((rb.m_at & assertType::is_throws_as) == 0)
4416  s << Color::Cyan << assertString(rb.m_at) << "( " << rb.m_expr << " ) "
4417  << Color::None;
4418 
4419  if(rb.m_at & assertType::is_throws) {
4420  s << (rb.m_threw ? "threw as expected!" : "did NOT throw at all!") << "\n";
4421  } else if(rb.m_at &
4423  s << Color::Cyan << assertString(rb.m_at) << "( " << rb.m_expr << ", "
4424  << rb.m_exception_type << " ) " << Color::None
4425  << (rb.m_threw ? (rb.m_threw_as ? "threw as expected!" :
4426  "threw a DIFFERENT exception: ") :
4427  "did NOT throw at all!")
4428  << Color::Cyan << rb.m_exception << "\n";
4429  } else if(rb.m_at & assertType::is_nothrow) {
4430  s << (rb.m_threw ? "THREW exception: " : "didn't throw!") << Color::Cyan
4431  << rb.m_exception << "\n";
4432  } else {
4433  s << (rb.m_threw ? "THREW exception: " :
4434  (!rb.m_failed ? "is correct!\n" : "is NOT correct!\n"));
4435  if(rb.m_threw)
4436  s << rb.m_exception << "\n";
4437  else
4438  s << " values: " << assertString(rb.m_at) << "( " << rb.m_decomposition
4439  << " )\n";
4440  }
4441 
4442  log_contexts();
4443  }
4444 
4445  void log_message(const MessageData& mb) override {
4446  logTestStart();
4447 
4448  file_line_to_stream(mb.m_file, mb.m_line, " ");
4449  s << getSuccessOrFailColor(false, mb.m_severity)
4450  << getSuccessOrFailString(mb.m_severity & assertType::is_warn, mb.m_severity,
4451  "MESSAGE: ");
4452  s << Color::None << mb.m_string << "\n";
4453  log_contexts();
4454  }
4455 
4456  void test_case_skipped(const TestCaseData&) override {}
4457  };
4458 
4459  // extension of the console reporter - with a bunch of helpers for the stdout stream redirection
4460  struct ConsoleReporterWithHelpers : public ConsoleReporter
4461  {
4462  ConsoleReporterWithHelpers(std::ostream& in)
4463  : ConsoleReporter(in) {}
4464 
4465  void printVersion() {
4466  if(g_contextState->no_version == false)
4467  s << Color::Cyan << "[doctest] " << Color::None << "doctest version is \""
4468  << DOCTEST_VERSION_STR << "\"\n";
4469  }
4470 
4471  void printIntro() {
4472  printVersion();
4473  s << Color::Cyan << "[doctest] " << Color::None << "run with \"--help\" for options\n";
4474  }
4475 
4476  void printHelp() {
4477  printVersion();
4478  // clang-format off
4479  s << Color::Cyan << "[doctest]\n" << Color::None;
4480  s << Color::Cyan << "[doctest] " << Color::None;
4481  s << "boolean values: \"1/on/yes/true\" or \"0/off/no/false\"\n";
4482  s << Color::Cyan << "[doctest] " << Color::None;
4483  s << "filter values: \"str1,str2,str3\" (comma separated strings)\n";
4484  s << Color::Cyan << "[doctest]\n" << Color::None;
4485  s << Color::Cyan << "[doctest] " << Color::None;
4486  s << "filters use wildcards for matching strings\n";
4487  s << Color::Cyan << "[doctest] " << Color::None;
4488  s << "something passes a filter if any of the strings in a filter matches\n";
4489  s << Color::Cyan << "[doctest]\n" << Color::None;
4490  s << Color::Cyan << "[doctest] " << Color::None;
4491  s << "ALL FLAGS, OPTIONS AND FILTERS ALSO AVAILABLE WITH A \"dt-\" PREFIX!!!\n";
4492  s << Color::Cyan << "[doctest]\n" << Color::None;
4493  s << Color::Cyan << "[doctest] " << Color::None;
4494  s << "Query flags - the program quits after them. Available:\n\n";
4495  s << " -?, --help, -h prints this message\n";
4496  s << " -v, --version prints the version\n";
4497  s << " -c, --count prints the number of matching tests\n";
4498  s << " -ltc, --list-test-cases lists all matching tests by name\n";
4499  s << " -lts, --list-test-suites lists all matching test suites\n";
4500  s << " -lr, --list-reporters lists all registered reporters\n\n";
4501  // ================================================================================== << 79
4502  s << Color::Cyan << "[doctest] " << Color::None;
4503  s << "The available <int>/<string> options/filters are:\n\n";
4504  s << " -tc, --test-case=<filters> filters tests by their name\n";
4505  s << " -tce, --test-case-exclude=<filters> filters OUT tests by their name\n";
4506  s << " -sf, --source-file=<filters> filters tests by their file\n";
4507  s << " -sfe, --source-file-exclude=<filters> filters OUT tests by their file\n";
4508  s << " -ts, --test-suite=<filters> filters tests by their test suite\n";
4509  s << " -tse, --test-suite-exclude=<filters> filters OUT tests by their test suite\n";
4510  s << " -sc, --subcase=<filters> filters subcases by their name\n";
4511  s << " -sce, --subcase-exclude=<filters> filters OUT subcases by their name\n";
4512  s << " -r, --reporters=<filters> reporters to use (console is default)\n";
4513  s << " -ob, --order-by=<string> how the tests should be ordered\n";
4514  s << " <string> - by [file/suite/name/rand]\n";
4515  s << " -rs, --rand-seed=<int> seed for random ordering\n";
4516  s << " -f, --first=<int> the first test passing the filters to\n";
4517  s << " execute - for range-based execution\n";
4518  s << " -l, --last=<int> the last test passing the filters to\n";
4519  s << " execute - for range-based execution\n";
4520  s << " -aa, --abort-after=<int> stop after <int> failed assertions\n";
4521  s << " -scfl,--subcase-filter-levels=<int> apply filters for the first <int> levels\n";
4522  s << Color::Cyan << "\n[doctest] " << Color::None;
4523  s << "Bool options - can be used like flags and true is assumed. Available:\n\n";
4524  s << " -s, --success=<bool> include successful assertions in output\n";
4525  s << " -cs, --case-sensitive=<bool> filters being treated as case sensitive\n";
4526  s << " -e, --exit=<bool> exits after the tests finish\n";
4527  s << " -d, --duration=<bool> prints the time duration of each test\n";
4528  s << " -nt, --no-throw=<bool> skips exceptions-related assert checks\n";
4529  s << " -ne, --no-exitcode=<bool> returns (or exits) always with success\n";
4530  s << " -nr, --no-run=<bool> skips all runtime doctest operations\n";
4531  s << " -nv, --no-version=<bool> omit the framework version in the output\n";
4532  s << " -nc, --no-colors=<bool> disables colors in output\n";
4533  s << " -fc, --force-colors=<bool> use colors even when not in a tty\n";
4534  s << " -nb, --no-breaks=<bool> disables breakpoints in debuggers\n";
4535  s << " -ns, --no-skip=<bool> don't skip test cases marked as skip\n";
4536  s << " -gfl, --gnu-file-line=<bool> :n: vs (n): for line numbers in output\n";
4537  s << " -npf, --no-path-filenames=<bool> only filenames and no paths in output\n";
4538  s << " -nln, --no-line-numbers=<bool> 0 instead of real line numbers in output\n";
4539  // ================================================================================== << 79
4540  // clang-format on
4541 
4542  s << Color::Cyan << "\n[doctest] " << Color::None;
4543  s << "for more information visit the project documentation\n\n";
4544  }
4545 
4546  void printRegisteredReporters() {
4547  printVersion();
4548  s << Color::Cyan << "[doctest] " << Color::None << "listing all registered reporters\n";
4549  for(auto& curr : getReporters())
4550  s << "priority: " << std::setw(5) << curr.first.first
4551  << " name: " << curr.first.second << "\n";
4552  }
4553 
4554  void output_query_results() {
4555  separator_to_stream();
4556  if(g_contextState->count || g_contextState->list_test_cases) {
4557  s << Color::Cyan << "[doctest] " << Color::None
4558  << "unskipped test cases passing the current filters: "
4559  << g_contextState->numTestCasesPassingFilters << "\n";
4560  } else if(g_contextState->list_test_suites) {
4561  s << Color::Cyan << "[doctest] " << Color::None
4562  << "unskipped test cases passing the current filters: "
4563  << g_contextState->numTestCasesPassingFilters << "\n";
4564  s << Color::Cyan << "[doctest] " << Color::None
4565  << "test suites with unskipped test cases passing the current filters: "
4566  << g_contextState->numTestSuitesPassingFilters << "\n";
4567  }
4568  }
4569 
4570  void output_query_preamble_test_cases() {
4571  s << Color::Cyan << "[doctest] " << Color::None << "listing all test case names\n";
4572  separator_to_stream();
4573  }
4574 
4575  void output_query_preamble_test_suites() {
4576  s << Color::Cyan << "[doctest] " << Color::None << "listing all test suites\n";
4577  separator_to_stream();
4578  }
4579 
4580  void output_c_string_with_newline(const char* str) { s << Color::None << str << "\n"; }
4581  };
4582 
4583 #ifdef DOCTEST_PLATFORM_WINDOWS
4584  struct DebugOutputWindowReporter : public ConsoleReporter
4585  {
4586  std::ostringstream oss;
4587 
4588  DebugOutputWindowReporter()
4589  : ConsoleReporter(oss) {}
4590 
4591 #define DOCTEST_DEBUG_OUTPUT_WINDOW_REPORTER_OVERRIDE(func, type) \
4592  void func(type in) override { \
4593  if(isDebuggerActive()) { \
4594  bool with_col = g_contextState->no_colors; \
4595  g_contextState->no_colors = false; \
4596  ConsoleReporter::func(in); \
4597  DOCTEST_OUTPUT_DEBUG_STRING(oss.str().c_str()); \
4598  oss.str(""); \
4599  g_contextState->no_colors = with_col; \
4600  } \
4601  }
4602 
4603  DOCTEST_DEBUG_OUTPUT_WINDOW_REPORTER_OVERRIDE(test_run_start, const ContextOptions&)
4604  DOCTEST_DEBUG_OUTPUT_WINDOW_REPORTER_OVERRIDE(test_run_end, const TestRunStats&)
4605  DOCTEST_DEBUG_OUTPUT_WINDOW_REPORTER_OVERRIDE(test_case_start, const TestCaseData&)
4606  DOCTEST_DEBUG_OUTPUT_WINDOW_REPORTER_OVERRIDE(test_case_end, const CurrentTestCaseStats&)
4607  DOCTEST_DEBUG_OUTPUT_WINDOW_REPORTER_OVERRIDE(subcase_start, const SubcaseSignature&)
4608  DOCTEST_DEBUG_OUTPUT_WINDOW_REPORTER_OVERRIDE(subcase_end, const SubcaseSignature&)
4609  DOCTEST_DEBUG_OUTPUT_WINDOW_REPORTER_OVERRIDE(log_assert, const AssertData&)
4610  DOCTEST_DEBUG_OUTPUT_WINDOW_REPORTER_OVERRIDE(log_message, const MessageData&)
4611  DOCTEST_DEBUG_OUTPUT_WINDOW_REPORTER_OVERRIDE(test_case_skipped, const TestCaseData&)
4612  };
4613 
4614  DebugOutputWindowReporter g_debug_output_rep;
4615 #endif // DOCTEST_PLATFORM_WINDOWS
4616 
4617  // the implementation of parseFlag()
4618  bool parseFlagImpl(int argc, const char* const* argv, const char* pattern) {
4619  for(int i = argc - 1; i >= 0; --i) {
4620  auto temp = std::strstr(argv[i], pattern);
4621  if(temp && strlen(temp) == strlen(pattern)) {
4622  // eliminate strings in which the chars before the option are not '-'
4623  bool noBadCharsFound = true;
4624  while(temp != argv[i]) {
4625  if(*--temp != '-') {
4626  noBadCharsFound = false;
4627  break;
4628  }
4629  }
4630  if(noBadCharsFound && argv[i][0] == '-')
4631  return true;
4632  }
4633  }
4634  return false;
4635  }
4636 
4637  // locates a flag on the command line
4638  bool parseFlag(int argc, const char* const* argv, const char* pattern) {
4639 #ifndef DOCTEST_CONFIG_NO_UNPREFIXED_OPTIONS
4640  if(parseFlagImpl(argc, argv, pattern + 3)) // 3 to skip "dt-"
4641  return true;
4642 #endif // DOCTEST_CONFIG_NO_UNPREFIXED_OPTIONS
4643  return parseFlagImpl(argc, argv, pattern);
4644  }
4645 
4646  // the implementation of parseOption()
4647  bool parseOptionImpl(int argc, const char* const* argv, const char* pattern, String& res) {
4648  for(int i = argc - 1; i >= 0; --i) {
4649  auto temp = std::strstr(argv[i], pattern);
4650  if(temp) {
4651  // eliminate matches in which the chars before the option are not '-'
4652  bool noBadCharsFound = true;
4653  auto curr = argv[i];
4654  while(curr != temp) {
4655  if(*curr++ != '-') {
4656  noBadCharsFound = false;
4657  break;
4658  }
4659  }
4660  if(noBadCharsFound && argv[i][0] == '-') {
4661  temp += strlen(pattern);
4662  const unsigned len = strlen(temp);
4663  if(len) {
4664  res = temp;
4665  return true;
4666  }
4667  }
4668  }
4669  }
4670  return false;
4671  }
4672 
4673  // parses an option and returns the string after the '=' character
4674  bool parseOption(int argc, const char* const* argv, const char* pattern, String& res,
4675  const String& defaultVal = String()) {
4676  res = defaultVal;
4677 #ifndef DOCTEST_CONFIG_NO_UNPREFIXED_OPTIONS
4678  if(parseOptionImpl(argc, argv, pattern + 3, res)) // 3 to skip "dt-"
4679  return true;
4680 #endif // DOCTEST_CONFIG_NO_UNPREFIXED_OPTIONS
4681  return parseOptionImpl(argc, argv, pattern, res);
4682  }
4683 
4684  // parses a comma separated list of words after a pattern in one of the arguments in argv
4685  bool parseCommaSepArgs(int argc, const char* const* argv, const char* pattern,
4686  std::vector<String>& res) {
4687  String filtersString;
4688  if(parseOption(argc, argv, pattern, filtersString)) {
4689  // tokenize with "," as a separator
4690  // cppcheck-suppress strtokCalled
4691  auto pch = std::strtok(filtersString.c_str(), ","); // modifies the string
4692  while(pch != 0) {
4693  if(strlen(pch))
4694  res.push_back(pch);
4695  // uses the strtok() internal state to go to the next token
4696  // cppcheck-suppress strtokCalled
4697  pch = std::strtok(0, ",");
4698  }
4699  return true;
4700  }
4701  return false;
4702  }
4703 
4704  enum optionType
4705  {
4706  option_bool,
4707  option_int
4708  };
4709 
4710  // parses an int/bool option from the command line
4711  bool parseIntOption(int argc, const char* const* argv, const char* pattern, optionType type,
4712  int& res) {
4713  String parsedValue;
4714  if(!parseOption(argc, argv, pattern, parsedValue))
4715  return false;
4716 
4717  if(type == 0) {
4718  // boolean
4719  const char positive[][5] = {"1", "true", "on", "yes"}; // 5 - strlen("true") + 1
4720  const char negative[][6] = {"0", "false", "off", "no"}; // 6 - strlen("false") + 1
4721 
4722  // if the value matches any of the positive/negative possibilities
4723  for(unsigned i = 0; i < 4; i++) {
4724  if(parsedValue.compare(positive[i], true) == 0) {
4725  res = 1;
4726  return true;
4727  }
4728  if(parsedValue.compare(negative[i], true) == 0) {
4729  res = 0;
4730  return true;
4731  }
4732  }
4733  } else {
4734  // integer
4735  // TODO: change this to use std::stoi or something else! currently it uses undefined behavior - assumes '0' on unsuccessful parse...
4736  int theInt = std::atoi(parsedValue.c_str()); // NOLINT
4737  if(theInt != 0) {
4738  res = theInt;
4739  return true;
4740  }
4741  }
4742  return false;
4743  }
4744 } // namespace
4745 
4746 bool isRunningInTest() { return detail::g_contextState != 0; }
4747 
4748 Context::Context(int argc, const char* const* argv)
4749  : p(new detail::ContextState) {
4750  parseArgs(argc, argv, true);
4751 }
4752 
4753 Context::~Context() { delete p; }
4754 
4755 void Context::applyCommandLine(int argc, const char* const* argv) { parseArgs(argc, argv); }
4756 
4757 // parses args
4758 void Context::parseArgs(int argc, const char* const* argv, bool withDefaults) {
4759  using namespace detail;
4760 
4761  // clang-format off
4762  parseCommaSepArgs(argc, argv, "dt-source-file=", p->filters[0]);
4763  parseCommaSepArgs(argc, argv, "dt-sf=", p->filters[0]);
4764  parseCommaSepArgs(argc, argv, "dt-source-file-exclude=",p->filters[1]);
4765  parseCommaSepArgs(argc, argv, "dt-sfe=", p->filters[1]);
4766  parseCommaSepArgs(argc, argv, "dt-test-suite=", p->filters[2]);
4767  parseCommaSepArgs(argc, argv, "dt-ts=", p->filters[2]);
4768  parseCommaSepArgs(argc, argv, "dt-test-suite-exclude=", p->filters[3]);
4769  parseCommaSepArgs(argc, argv, "dt-tse=", p->filters[3]);
4770  parseCommaSepArgs(argc, argv, "dt-test-case=", p->filters[4]);
4771  parseCommaSepArgs(argc, argv, "dt-tc=", p->filters[4]);
4772  parseCommaSepArgs(argc, argv, "dt-test-case-exclude=", p->filters[5]);
4773  parseCommaSepArgs(argc, argv, "dt-tce=", p->filters[5]);
4774  parseCommaSepArgs(argc, argv, "dt-subcase=", p->filters[6]);
4775  parseCommaSepArgs(argc, argv, "dt-sc=", p->filters[6]);
4776  parseCommaSepArgs(argc, argv, "dt-subcase-exclude=", p->filters[7]);
4777  parseCommaSepArgs(argc, argv, "dt-sce=", p->filters[7]);
4778  parseCommaSepArgs(argc, argv, "dt-reporters=", p->filters[8]);
4779  parseCommaSepArgs(argc, argv, "dt-r=", p->filters[8]);
4780  // clang-format on
4781 
4782  int intRes = 0;
4783  String strRes;
4784 
4785 #define DOCTEST_PARSE_AS_BOOL_OR_FLAG(name, sname, var, default) \
4786  if(parseIntOption(argc, argv, name "=", option_bool, intRes) || \
4787  parseIntOption(argc, argv, sname "=", option_bool, intRes)) \
4788  p->var = !!intRes; \
4789  else if(parseFlag(argc, argv, name) || parseFlag(argc, argv, sname)) \
4790  p->var = true; \
4791  else if(withDefaults) \
4792  p->var = default
4793 
4794 #define DOCTEST_PARSE_INT_OPTION(name, sname, var, default) \
4795  if(parseIntOption(argc, argv, name "=", option_int, intRes) || \
4796  parseIntOption(argc, argv, sname "=", option_int, intRes)) \
4797  p->var = intRes; \
4798  else if(withDefaults) \
4799  p->var = default
4800 
4801 #define DOCTEST_PARSE_STR_OPTION(name, sname, var, default) \
4802  if(parseOption(argc, argv, name "=", strRes, default) || \
4803  parseOption(argc, argv, sname "=", strRes, default) || withDefaults) \
4804  p->var = strRes
4805 
4806  // clang-format off
4807  DOCTEST_PARSE_STR_OPTION("dt-order-by", "dt-ob", order_by, "file");
4808  DOCTEST_PARSE_INT_OPTION("dt-rand-seed", "dt-rs", rand_seed, 0);
4809 
4810  DOCTEST_PARSE_INT_OPTION("dt-first", "dt-f", first, 0);
4811  DOCTEST_PARSE_INT_OPTION("dt-last", "dt-l", last, UINT_MAX);
4812 
4813  DOCTEST_PARSE_INT_OPTION("dt-abort-after", "dt-aa", abort_after, 0);
4814  DOCTEST_PARSE_INT_OPTION("dt-subcase-filter-levels", "dt-scfl", subcase_filter_levels, 2000000000);
4815 
4816  DOCTEST_PARSE_AS_BOOL_OR_FLAG("dt-success", "dt-s", success, false);
4817  DOCTEST_PARSE_AS_BOOL_OR_FLAG("dt-case-sensitive", "dt-cs", case_sensitive, false);
4818  DOCTEST_PARSE_AS_BOOL_OR_FLAG("dt-exit", "dt-e", exit, false);
4819  DOCTEST_PARSE_AS_BOOL_OR_FLAG("dt-duration", "dt-d", duration, false);
4820  DOCTEST_PARSE_AS_BOOL_OR_FLAG("dt-no-throw", "dt-nt", no_throw, false);
4821  DOCTEST_PARSE_AS_BOOL_OR_FLAG("dt-no-exitcode", "dt-ne", no_exitcode, false);
4822  DOCTEST_PARSE_AS_BOOL_OR_FLAG("dt-no-run", "dt-nr", no_run, false);
4823  DOCTEST_PARSE_AS_BOOL_OR_FLAG("dt-no-version", "dt-nv", no_version, false);
4824  DOCTEST_PARSE_AS_BOOL_OR_FLAG("dt-no-colors", "dt-nc", no_colors, false);
4825  DOCTEST_PARSE_AS_BOOL_OR_FLAG("dt-force-colors", "dt-fc", force_colors, false);
4826  DOCTEST_PARSE_AS_BOOL_OR_FLAG("dt-no-breaks", "dt-nb", no_breaks, false);
4827  DOCTEST_PARSE_AS_BOOL_OR_FLAG("dt-no-skip", "dt-ns", no_skip, false);
4828  DOCTEST_PARSE_AS_BOOL_OR_FLAG("dt-gnu-file-line", "dt-gfl", gnu_file_line, bool(DOCTEST_GCC) || bool(DOCTEST_CLANG));
4829  DOCTEST_PARSE_AS_BOOL_OR_FLAG("dt-no-path-filenames", "dt-npf", no_path_in_filenames, false);
4830  DOCTEST_PARSE_AS_BOOL_OR_FLAG("dt-no-line-numbers", "dt-nln", no_line_numbers, false);
4831  DOCTEST_PARSE_AS_BOOL_OR_FLAG("dt-no-skipped-summary", "dt-nss", no_skipped_summary, false);
4832  // clang-format on
4833 
4834  if(withDefaults) {
4835  p->help = false;
4836  p->version = false;
4837  p->count = false;
4838  p->list_test_cases = false;
4839  p->list_test_suites = false;
4840  p->list_reporters = false;
4841  }
4842  if(parseFlag(argc, argv, "dt-help") || parseFlag(argc, argv, "dt-h") ||
4843  parseFlag(argc, argv, "dt-?")) {
4844  p->help = true;
4845  p->exit = true;
4846  }
4847  if(parseFlag(argc, argv, "dt-version") || parseFlag(argc, argv, "dt-v")) {
4848  p->version = true;
4849  p->exit = true;
4850  }
4851  if(parseFlag(argc, argv, "dt-count") || parseFlag(argc, argv, "dt-c")) {
4852  p->count = true;
4853  p->exit = true;
4854  }
4855  if(parseFlag(argc, argv, "dt-list-test-cases") || parseFlag(argc, argv, "dt-ltc")) {
4856  p->list_test_cases = true;
4857  p->exit = true;
4858  }
4859  if(parseFlag(argc, argv, "dt-list-test-suites") || parseFlag(argc, argv, "dt-lts")) {
4860  p->list_test_suites = true;
4861  p->exit = true;
4862  }
4863  if(parseFlag(argc, argv, "dt-list-reporters") || parseFlag(argc, argv, "dt-lr")) {
4864  p->list_reporters = true;
4865  p->exit = true;
4866  }
4867 }
4868 
4869 // allows the user to add procedurally to the filters from the command line
4870 void Context::addFilter(const char* filter, const char* value) { setOption(filter, value); }
4871 
4872 // allows the user to clear all filters from the command line
4873 void Context::clearFilters() {
4874  for(auto& curr : p->filters)
4875  curr.clear();
4876 }
4877 
4878 // allows the user to override procedurally the int/bool options from the command line
4879 void Context::setOption(const char* option, int value) {
4880  setOption(option, toString(value).c_str());
4881 }
4882 
4883 // allows the user to override procedurally the string options from the command line
4884 void Context::setOption(const char* option, const char* value) {
4885  auto argv = String("-") + option + "=" + value;
4886  auto lvalue = argv.c_str();
4887  parseArgs(1, &lvalue);
4888 }
4889 
4890 // users should query this in their main() and exit the program if true
4891 bool Context::shouldExit() { return p->exit; }
4892 
4893 // the main function that does all the filtering and test running
4894 int Context::run() {
4895  using namespace detail;
4896 
4897  g_contextState = p;
4898  p->resetRunData();
4899 
4900  ConsoleReporterWithHelpers g_con_rep(std::cout);
4901  registerReporter("console", 0, &g_con_rep);
4902 
4903  // setup default reporter if none is given through the command line
4904  p->reporters_currently_used.clear();
4905  if(p->filters[8].empty())
4906  p->reporters_currently_used.push_back(getReporters()[reporterMap::key_type(0, "console")]);
4907 
4908  // check to see if any of the registered reporters has been selected
4909  for(auto& curr : getReporters()) {
4910  if(matchesAny(curr.first.second.c_str(), p->filters[8], false, p->case_sensitive))
4911  p->reporters_currently_used.push_back(curr.second);
4912  }
4913 
4914  // always use the debug output window reporter
4915 #ifdef DOCTEST_PLATFORM_WINDOWS
4916  if(isDebuggerActive())
4917  p->reporters_currently_used.push_back(&g_debug_output_rep);
4918 #endif // DOCTEST_PLATFORM_WINDOWS
4919 
4920  // handle version, help and no_run
4921  if(p->no_run || p->version || p->help || p->list_reporters) {
4922  if(p->version)
4923  g_con_rep.printVersion();
4924  if(p->help)
4925  g_con_rep.printHelp();
4926  if(p->list_reporters)
4927  g_con_rep.printRegisteredReporters();
4928 
4929  g_contextState = 0;
4930 
4931  return EXIT_SUCCESS;
4932  }
4933 
4934  g_con_rep.printIntro();
4935 
4936  std::vector<const TestCase*> testArray;
4937  for(auto& curr : getRegisteredTests())
4938  testArray.push_back(&curr);
4939  p->numTestCases = testArray.size();
4940 
4941  // sort the collected records
4942  if(!testArray.empty()) {
4943  if(p->order_by.compare("file", true) == 0) {
4944  std::qsort(&testArray[0], testArray.size(), sizeof(TestCase*), fileOrderComparator);
4945  } else if(p->order_by.compare("suite", true) == 0) {
4946  std::qsort(&testArray[0], testArray.size(), sizeof(TestCase*), suiteOrderComparator);
4947  } else if(p->order_by.compare("name", true) == 0) {
4948  std::qsort(&testArray[0], testArray.size(), sizeof(TestCase*), nameOrderComparator);
4949  } else if(p->order_by.compare("rand", true) == 0) {
4950  std::srand(p->rand_seed);
4951 
4952  // random_shuffle implementation
4953  const auto first = &testArray[0];
4954  for(size_t i = testArray.size() - 1; i > 0; --i) {
4955  int idxToSwap = std::rand() % (i + 1); // NOLINT
4956 
4957  const auto temp = first[i];
4958 
4959  first[i] = first[idxToSwap];
4960  first[idxToSwap] = temp;
4961  }
4962  }
4963  }
4964 
4965  if(p->list_test_cases)
4966  g_con_rep.output_query_preamble_test_cases();
4967 
4968  std::set<String> testSuitesPassingFilt;
4969  if(p->list_test_suites)
4970  g_con_rep.output_query_preamble_test_suites();
4971 
4972  bool query_mode = p->count || p->list_test_cases || p->list_test_suites;
4973 
4974  if(!query_mode)
4975  DOCTEST_ITERATE_THROUGH_REPORTERS(test_run_start, *g_contextState);
4976 
4977  // invoke the registered functions if they match the filter criteria (or just count them)
4978  for(auto& curr : testArray) {
4979  const auto tc = *curr;
4980 
4981  bool skip_me = false;
4982  if(tc.m_skip && !p->no_skip)
4983  skip_me = true;
4984 
4985  if(!matchesAny(tc.m_file, p->filters[0], true, p->case_sensitive))
4986  skip_me = true;
4987  if(matchesAny(tc.m_file, p->filters[1], false, p->case_sensitive))
4988  skip_me = true;
4989  if(!matchesAny(tc.m_test_suite, p->filters[2], true, p->case_sensitive))
4990  skip_me = true;
4991  if(matchesAny(tc.m_test_suite, p->filters[3], false, p->case_sensitive))
4992  skip_me = true;
4993  if(!matchesAny(tc.m_name, p->filters[4], true, p->case_sensitive))
4994  skip_me = true;
4995  if(matchesAny(tc.m_name, p->filters[5], false, p->case_sensitive))
4996  skip_me = true;
4997 
4998  if(!skip_me)
4999  p->numTestCasesPassingFilters++;
5000 
5001  // skip the test if it is not in the execution range
5002  if((p->last < p->numTestCasesPassingFilters && p->first <= p->last) ||
5003  (p->first > p->numTestCasesPassingFilters))
5004  skip_me = true;
5005 
5006  if(skip_me) {
5007  if(!query_mode)
5008  DOCTEST_ITERATE_THROUGH_REPORTERS(test_case_skipped, tc);
5009  continue;
5010  }
5011 
5012  // do not execute the test if we are to only count the number of filter passing tests
5013  if(p->count)
5014  continue;
5015 
5016  // print the name of the test and don't execute it
5017  if(p->list_test_cases) {
5018  g_con_rep.output_c_string_with_newline(tc.m_name);
5019  continue;
5020  }
5021 
5022  // print the name of the test suite if not done already and don't execute it
5023  if(p->list_test_suites) {
5024  if((testSuitesPassingFilt.count(tc.m_test_suite) == 0) && tc.m_test_suite[0] != '\0') {
5025  g_con_rep.output_c_string_with_newline(tc.m_test_suite);
5026  testSuitesPassingFilt.insert(tc.m_test_suite);
5027  p->numTestSuitesPassingFilters++;
5028  }
5029  continue;
5030  }
5031 
5032  // execute the test if it passes all the filtering
5033  {
5034  p->currentTest = &tc;
5035 
5036  p->failure_flags = TestCaseFailureReason::None;
5037  p->numAssertsFailedForCurrentTestCase = 0;
5038  p->numAssertsForCurrentTestCase = 0;
5039  p->seconds_so_far = 0;
5040  p->error_string = "";
5041 
5042  p->subcasesPassed.clear();
5043  do {
5044  // reset some of the fields for subcases (except for the set of fully passed ones)
5045  p->should_reenter = false;
5046  p->subcasesCurrentLevel = 0;
5047  p->subcasesEnteredLevels.clear();
5048 
5049  // reset stuff for logging with INFO()
5050  p->stringifiedContexts.clear();
5051 
5052  DOCTEST_ITERATE_THROUGH_REPORTERS(test_case_start, tc);
5053 
5054  g_timer.start();
5055 
5056 #ifndef DOCTEST_CONFIG_NO_EXCEPTIONS
5057  try {
5058 #endif // DOCTEST_CONFIG_NO_EXCEPTIONS
5059  FatalConditionHandler fatalConditionHandler; // Handle signals
5060  // execute the test
5061  tc.m_test();
5062  fatalConditionHandler.reset();
5063 #ifndef DOCTEST_CONFIG_NO_EXCEPTIONS
5064  } catch(const TestFailureException&) {
5065  p->failure_flags |= TestCaseFailureReason::AssertFailure;
5066  } catch(...) {
5067  p->error_string = translateActiveException();
5068  p->failure_flags |= TestCaseFailureReason::Exception;
5069  }
5070 #endif // DOCTEST_CONFIG_NO_EXCEPTIONS
5071 
5072  p->seconds_so_far += g_timer.getElapsedSeconds();
5073 
5074  // exit this loop if enough assertions have failed - even if there are more subcases
5075  if(p->abort_after > 0 && p->numAssertsFailed >= p->abort_after) {
5076  p->should_reenter = false;
5077  p->failure_flags |= TestCaseFailureReason::TooManyFailedAsserts;
5078  }
5079 
5080  // call it from here only if we will continue looping for other subcases and
5081  // call it again outside of the loop for one final time - with updated flags
5082  if(p->should_reenter == true)
5083  DOCTEST_ITERATE_THROUGH_REPORTERS(test_case_end, *g_contextState);
5084  } while(p->should_reenter == true);
5085 
5086  if(g_contextState->numAssertsFailedForCurrentTestCase)
5087  p->failure_flags |= TestCaseFailureReason::AssertFailure;
5088 
5089  if(Approx(p->currentTest->m_timeout).epsilon(DBL_EPSILON) != 0 &&
5090  Approx(p->seconds_so_far).epsilon(DBL_EPSILON) > p->currentTest->m_timeout)
5091  p->failure_flags |= TestCaseFailureReason::Timeout;
5092 
5093  if(tc.m_should_fail) {
5094  if(p->failure_flags) {
5096  } else {
5098  }
5099  } else if(p->failure_flags && tc.m_may_fail) {
5101  } else if(tc.m_expected_failures > 0) {
5102  if(p->numAssertsFailedForCurrentTestCase == tc.m_expected_failures) {
5104  } else {
5106  }
5107  }
5108 
5109  bool ok_to_fail = (TestCaseFailureReason::ShouldHaveFailedAndDid & p->failure_flags) ||
5110  (TestCaseFailureReason::CouldHaveFailedAndDid & p->failure_flags) ||
5111  (TestCaseFailureReason::FailedExactlyNumTimes & p->failure_flags);
5112 
5113  // if any subcase has failed - the whole test case has failed
5114  if(p->failure_flags && !ok_to_fail)
5115  p->numTestCasesFailed++;
5116 
5117  DOCTEST_ITERATE_THROUGH_REPORTERS(test_case_end, *g_contextState);
5118 
5119  // stop executing tests if enough assertions have failed
5120  if(p->abort_after > 0 && p->numAssertsFailed >= p->abort_after)
5121  break;
5122  }
5123  }
5124 
5125  if(!query_mode)
5126  DOCTEST_ITERATE_THROUGH_REPORTERS(test_run_end, *g_contextState);
5127  else
5128  g_con_rep.output_query_results();
5129 
5130  g_contextState = 0;
5131 
5132  if(p->numTestCasesFailed && !p->no_exitcode)
5133  return EXIT_FAILURE;
5134  return EXIT_SUCCESS;
5135 }
5136 
5137 DOCTEST_DEFINE_DEFAULTS(CurrentTestCaseStats);
5138 
5139 DOCTEST_DEFINE_DEFAULTS(TestRunStats);
5140 
5141 IReporter::~IReporter() = default;
5142 
5143 int IReporter::get_num_active_contexts() { return detail::g_contextState->contexts.size(); }
5144 const IContextScope* const* IReporter::get_active_contexts() {
5145  return get_num_active_contexts() ? &detail::g_contextState->contexts[0] : 0;
5146 }
5147 
5148 int IReporter::get_num_stringified_contexts() {
5149  return detail::g_contextState->stringifiedContexts.size();
5150 }
5151 const String* IReporter::get_stringified_contexts() {
5152  return get_num_stringified_contexts() ? &detail::g_contextState->stringifiedContexts[0] : 0;
5153 }
5154 
5155 int registerReporter(const char* name, int priority, IReporter* r) {
5156  getReporters().insert(reporterMap::value_type(reporterMap::key_type(priority, name), r));
5157  return 0;
5158 }
5159 
5160 } // namespace doctest
5161 
5162 #endif // DOCTEST_CONFIG_DISABLE
5163 
5164 #ifdef DOCTEST_CONFIG_IMPLEMENT_WITH_MAIN
5165 int main(int argc, char** argv) { return doctest::Context(argc, argv).run(); }
5166 #endif // DOCTEST_CONFIG_IMPLEMENT_WITH_MAIN
5167 
5168 DOCTEST_CLANG_SUPPRESS_WARNING_POP
5169 DOCTEST_MSVC_SUPPRESS_WARNING_POP
5170 DOCTEST_GCC_SUPPRESS_WARNING_POP
5171 
5172 #endif // DOCTEST_LIBRARY_IMPLEMENTATION
5173 #endif // DOCTEST_CONFIG_IMPLEMENT
Definition: color.h:76
friend bool operator==(double lhs, const Approx &rhs)
double m_epsilon
Definition: doctest.h:987
friend bool operator!=(double lhs, const Approx &rhs)
Approx & scale(double newScale)
friend bool operator!=(const Approx &lhs, double rhs)
Approx(double value)
friend bool operator<=(const Approx &lhs, double rhs)
double m_scale
Definition: doctest.h:988
friend String toString(const Approx &in)
Approx operator()(double value) const
friend bool operator<=(double lhs, const Approx &rhs)
friend bool operator==(const Approx &lhs, double rhs)
friend bool operator>=(const Approx &lhs, double rhs)
double m_value
Definition: doctest.h:989
Approx & epsilon(double newEpsilon)
friend bool operator>=(double lhs, const Approx &rhs)
detail::ContextState * p
Definition: doctest.h:1705
void setOption(const char *option, const char *value)
void addFilter(const char *filter, const char *value)
Context(int argc=0, const char *const *argv=0)
void parseArgs(int argc, const char *const *argv, bool withDefaults=false)
void setOption(const char *option, int value)
void applyCommandLine(int argc, const char *const *argv)
String & operator=(const String &other)
String(const String &other)
char * c_str()
Definition: doctest.h:491
String(String &&other)
const char * c_str() const
Definition: doctest.h:490
String & operator=(String &&other)