41 #ifndef DOCTEST_LIBRARY_INCLUDED
42 #define DOCTEST_LIBRARY_INCLUDED
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"
53 #define DOCTEST_VERSION \
54 (DOCTEST_VERSION_MAJOR * 10000 + DOCTEST_VERSION_MINOR * 100 + DOCTEST_VERSION_PATCH)
62 #define DOCTEST_COMPILER(MAJOR, MINOR, PATCH) ((MAJOR)*10000000 + (MINOR)*100000 + (PATCH))
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)
68 #define DOCTEST_MSVC \
69 DOCTEST_COMPILER(_MSC_VER / 100, (_MSC_FULL_VER / 100000) % 100, _MSC_FULL_VER % 100000)
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__)
79 #define DOCTEST_MSVC 0
82 #define DOCTEST_CLANG 0
94 #define DOCTEST_CLANG_HAS_WARNING(x) __has_warning(x)
97 #define DOCTEST_CLANG_HAS_FEATURE(x) __has_feature(x)
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)
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)
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)
145 #ifndef DOCTEST_CLANG_HAS_WARNING
146 #define DOCTEST_CLANG_HAS_WARNING(x) 1
149 #ifndef DOCTEST_CLANG_HAS_FEATURE
150 #define DOCTEST_CLANG_HAS_FEATURE(x) 0
157 DOCTEST_CLANG_SUPPRESS_WARNING_PUSH
166 #if DOCTEST_CLANG && DOCTEST_CLANG_HAS_WARNING("-Wzero-as-null-pointer-constant")
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")
187 DOCTEST_MSVC_SUPPRESS_WARNING_PUSH
188 DOCTEST_MSVC_SUPPRESS_WARNING(4616)
189 DOCTEST_MSVC_SUPPRESS_WARNING(4619)
190 DOCTEST_MSVC_SUPPRESS_WARNING(4996)
191 DOCTEST_MSVC_SUPPRESS_WARNING(4706)
192 DOCTEST_MSVC_SUPPRESS_WARNING(4512)
193 DOCTEST_MSVC_SUPPRESS_WARNING(4127)
194 DOCTEST_MSVC_SUPPRESS_WARNING(4820)
195 DOCTEST_MSVC_SUPPRESS_WARNING(4625)
196 DOCTEST_MSVC_SUPPRESS_WARNING(4626)
197 DOCTEST_MSVC_SUPPRESS_WARNING(5027)
198 DOCTEST_MSVC_SUPPRESS_WARNING(5026)
199 DOCTEST_MSVC_SUPPRESS_WARNING(4623)
200 DOCTEST_MSVC_SUPPRESS_WARNING(4640)
202 DOCTEST_MSVC_SUPPRESS_WARNING(26439)
203 DOCTEST_MSVC_SUPPRESS_WARNING(26495)
204 DOCTEST_MSVC_SUPPRESS_WARNING(26451)
205 DOCTEST_MSVC_SUPPRESS_WARNING(26444)
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)
239 #define DOCTEST_MAKE_STD_HEADERS_CLEAN_FROM_WARNINGS_ON_WALL_END DOCTEST_MSVC_SUPPRESS_WARNING_POP
257 #if DOCTEST_MSVC && !defined(DOCTEST_CONFIG_WINDOWS_SEH)
258 #define DOCTEST_CONFIG_WINDOWS_SEH
260 #if defined(DOCTEST_CONFIG_NO_WINDOWS_SEH) && defined(DOCTEST_CONFIG_WINDOWS_SEH)
261 #undef DOCTEST_CONFIG_WINDOWS_SEH
264 #if !defined(_WIN32) && !defined(__QNX__) && !defined(DOCTEST_CONFIG_POSIX_SIGNALS)
265 #define DOCTEST_CONFIG_POSIX_SIGNALS
267 #if defined(DOCTEST_CONFIG_NO_POSIX_SIGNALS) && defined(DOCTEST_CONFIG_POSIX_SIGNALS)
268 #undef DOCTEST_CONFIG_POSIX_SIGNALS
271 #ifndef DOCTEST_CONFIG_NO_EXCEPTIONS
272 #if(DOCTEST_GCC || DOCTEST_CLANG) && !defined(__EXCEPTIONS)
273 #define DOCTEST_CONFIG_NO_EXCEPTIONS
279 #ifdef DOCTEST_CONFIG_NO_EXCEPTIONS_BUT_WITH_ALL_ASSERTS
280 #ifndef DOCTEST_CONFIG_NO_EXCEPTIONS
281 #define DOCTEST_CONFIG_NO_EXCEPTIONS
285 #if defined(DOCTEST_CONFIG_NO_EXCEPTIONS) && !defined(DOCTEST_CONFIG_NO_TRY_CATCH_IN_ASSERTS)
286 #define DOCTEST_CONFIG_NO_TRY_CATCH_IN_ASSERTS
289 #if defined(DOCTEST_CONFIG_IMPLEMENT_WITH_MAIN) && !defined(DOCTEST_CONFIG_IMPLEMENT)
290 #define DOCTEST_CONFIG_IMPLEMENT
293 #if defined _WIN32 || defined __CYGWIN__
295 #define DOCTEST_SYMBOL_EXPORT __declspec(dllexport)
296 #define DOCTEST_SYMBOL_IMPORT __declspec(dllimport)
298 #define DOCTEST_SYMBOL_EXPORT __attribute__((dllexport))
299 #define DOCTEST_SYMBOL_IMPORT __attribute__((dllimport))
302 #define DOCTEST_SYMBOL_EXPORT __attribute__((visibility("default")))
303 #define DOCTEST_SYMBOL_IMPORT
306 #ifdef DOCTEST_CONFIG_IMPLEMENTATION_IN_DLL
307 #ifdef DOCTEST_CONFIG_IMPLEMENT
308 #define DOCTEST_INTERFACE DOCTEST_SYMBOL_EXPORT
310 #define DOCTEST_INTERFACE DOCTEST_SYMBOL_IMPORT
313 #define DOCTEST_INTERFACE
317 #define DOCTEST_NOINLINE __declspec(noinline)
318 #define DOCTEST_UNUSED
319 #define DOCTEST_ALIGNMENT(x)
321 #define DOCTEST_NOINLINE __attribute__((noinline))
322 #define DOCTEST_UNUSED __attribute__((unused))
323 #define DOCTEST_ALIGNMENT(x) __attribute__((aligned(x)))
326 #ifndef DOCTEST_CONFIG_NUM_CAPTURES_ON_STACK
327 #define DOCTEST_CONFIG_NUM_CAPTURES_ON_STACK 5
335 #define DOCTEST_CAT_IMPL(s1, s2) s1##s2
336 #define DOCTEST_CAT(s1, s2) DOCTEST_CAT_IMPL(s1, s2)
338 #define DOCTEST_ANONYMOUS(x) DOCTEST_CAT(x, __COUNTER__)
340 #define DOCTEST_ANONYMOUS(x) DOCTEST_CAT(x, __LINE__)
344 #define DOCTEST_TOSTR_IMPL(...) #__VA_ARGS__
345 #define DOCTEST_TOSTR(...) DOCTEST_TOSTR_IMPL(__VA_ARGS__)
347 #ifndef DOCTEST_CONFIG_ASSERTION_PARAMETERS_BY_VALUE
348 #define DOCTEST_REF_WRAP(x) x&
350 #define DOCTEST_REF_WRAP(x) x
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
361 #define DOCTEST_PLATFORM_LINUX
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
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
377 #ifdef DOCTEST_PLATFORM_MAC
378 #define DOCTEST_BREAK_INTO_DEBUGGER() __asm__("int $3\n" : :)
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()
385 #define DOCTEST_BREAK_INTO_DEBUGGER() ((void)0)
393 #if defined(_LIBCPP_VERSION) || defined(DOCTEST_CONFIG_USE_IOSFWD)
399 template <
class charT>
402 struct char_traits<char>;
403 template <
class charT,
class traits>
405 typedef basic_ostream<char, char_traits<char> > ostream;
409 #ifdef _LIBCPP_VERSION
417 #ifdef DOCTEST_CONFIG_INCLUDE_TYPE_TRAITS
418 #include <type_traits>
449 static const unsigned len = 24;
450 static const unsigned last = len - 1;
465 bool isOnStack()
const {
return (buf[last] & 128) == 0; }
493 return reinterpret_cast<char*
>(buf);
500 int compare(
const char* other,
bool no_case =
false)
const;
536 namespace assertType {
769 #if defined(DOCTEST_CONFIG_TREAT_CHAR_STAR_AS_STRING) || defined(DOCTEST_CONFIG_INCLUDE_TYPE_TRAITS)
770 template <
bool CONDITION,
typename TYPE =
void>
774 template <
typename TYPE>
775 struct enable_if<true, TYPE>
776 {
typedef TYPE type; };
779 template <
typename T>
782 {
static const bool value =
false; };
787 namespace has_insertion_operator_impl {
793 template <
typename T>
803 template <
typename T>
806 static std::ostream&
s;
812 template <
typename T>
825 template <
typename T>
834 template <
typename T>
846 template <
typename T>
851 template <
typename T>
857 template <
typename T>
861 template <
typename T>
864 template <
typename U>
872 template <
typename R,
typename C>
882 template <
typename T>
887 #ifdef DOCTEST_CONFIG_TREAT_CHAR_STAR_AS_STRING
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* =
923 *
this =
Approx(
static_cast<double>(value));
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);
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(
944 m_scale =
static_cast<double>(newScale);
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
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
994 #if !defined(DOCTEST_CONFIG_DISABLE)
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; };
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 }; };
1007 template<
class T>
struct can_use_op :
public not_char_pointer<typename decay_array<T>::type> {};
1025 bool m_entered =
false;
1027 Subcase(
const char* name,
const char* file,
int line);
1032 operator bool()
const;
1035 template <
typename L,
typename R>
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) \
1047 if(!res || doctest::detail::getContextOptions()->success) \
1048 return Result(res, stringifyBinaryExpr(lhs, op_str, rhs)); \
1049 return Result(res); \
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!"); \
1095 #ifndef DOCTEST_CONFIG_NO_COMPARISON_WARNING_SUPPRESSION
1097 DOCTEST_CLANG_SUPPRESS_WARNING_PUSH
1104 DOCTEST_GCC_SUPPRESS_WARNING_PUSH
1105 DOCTEST_GCC_SUPPRESS_WARNING("-Wsign-conversion")
1106 DOCTEST_GCC_SUPPRESS_WARNING("-Wsign-
compare")
1111 DOCTEST_MSVC_SUPPRESS_WARNING_PUSH
1113 DOCTEST_MSVC_SUPPRESS_WARNING(4388)
1114 DOCTEST_MSVC_SUPPRESS_WARNING(4389)
1115 DOCTEST_MSVC_SUPPRESS_WARNING(4018)
1121 #ifndef DOCTEST_CONFIG_TREAT_CHAR_STAR_AS_STRING
1122 #define DOCTEST_COMPARISON_RETURN_TYPE bool
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); }
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; \
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
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)
1164 template <
typename L>
1217 #ifndef DOCTEST_CONFIG_NO_COMPARISON_WARNING_SUPPRESSION
1219 DOCTEST_CLANG_SUPPRESS_WARNING_POP
1220 DOCTEST_MSVC_SUPPRESS_WARNING_POP
1221 DOCTEST_GCC_SUPPRESS_WARNING_POP
1238 template <
typename L>
1259 template <
typename T>
1275 const char* type =
"",
int template_id = -1);
1283 DOCTEST_MSVC_SUPPRESS_WARNING_POP
1287 template <typename
T>
1300 namespace binaryAssertComparison {
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); } };
1329 const char* exception_type =
"");
1336 template <
int comparison,
typename L,
typename R>
1344 template <
typename L>
1349 m_failed = !m_failed;
1361 namespace assertAction {
1370 template <
int comparison,
typename L,
typename R>
1389 #ifdef DOCTEST_CONFIG_SUPER_FAST_ASSERTS
1402 template <
typename L>
1423 #ifdef DOCTEST_CONFIG_SUPER_FAST_ASSERTS
1445 template <
typename T>
1450 : m_translateFunction(translateFunction) {}
1453 #ifndef DOCTEST_CONFIG_NO_EXCEPTIONS
1458 res = m_translateFunction(ex);
1480 template <
typename T>
1493 template <
typename T>
1499 template <
typename T>
1503 template <
typename T>
1508 #ifdef DOCTEST_CONFIG_TREAT_CHAR_STAR_AS_STRING
1541 template <
typename T>
1570 int numCaptures = 0;
1584 template <
typename T>
1594 auto curr =
new Node;
1609 template <
typename T>
1612 "Cannot pass temporaries or rvalues to the streaming operator because it "
1613 "caches pointers to the passed objects for lazy evaluation!");
1642 template <
typename T>
1653 #define DOCTEST_DEFINE_DECORATOR(name, type, def) \
1657 name(type in = def) \
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; } \
1671 template <
typename T>
1675 DOCTEST_CLANG_SUPPRESS_WARNING_POP
1690 template <
typename T>
1699 struct ContextState;
1705 detail::ContextState*
p;
1707 void parseArgs(
int argc,
const char*
const* argv,
bool withDefaults =
false);
1710 explicit Context(
int argc = 0,
const char*
const* argv = 0);
1728 namespace TestCaseFailureReason {
1815 #if !defined(DOCTEST_CONFIG_DISABLE)
1817 #define DOCTEST_EXPAND_VA_ARGS(...) __VA_ARGS__
1820 #define DOCTEST_ASSERT_LOG_AND_REACT(b) \
1822 DOCTEST_BREAK_INTO_DEBUGGER(); \
1825 #ifdef DOCTEST_CONFIG_NO_TRY_CATCH_IN_ASSERTS
1826 #define DOCTEST_WRAP_IN_TRY(x) x;
1828 #define DOCTEST_WRAP_IN_TRY(x) \
1831 } catch(...) { _DOCTEST_RB.unexpectedExceptionOccurred(); }
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()) * \
1840 DOCTEST_GLOBAL_NO_WARNINGS_END()
1842 #define DOCTEST_IMPLEMENT_FIXTURE(der, base, func, decorators) \
1844 struct der : public base \
1848 static void func() { \
1852 DOCTEST_REGISTER_FUNCTION(func, decorators) \
1854 inline DOCTEST_NOINLINE void der::f()
1856 #define DOCTEST_CREATE_AND_REGISTER_FUNCTION(f, decorators) \
1858 DOCTEST_REGISTER_FUNCTION(f, decorators) \
1862 #define DOCTEST_TEST_CASE(decorators) \
1863 DOCTEST_CREATE_AND_REGISTER_FUNCTION(DOCTEST_ANONYMOUS(_DOCTEST_ANON_FUNC_), decorators)
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)
1871 #define DOCTEST_TYPE_TO_STRING_IMPL(...) \
1873 inline const char* type_to_string<__VA_ARGS__>() { \
1874 return "<" #__VA_ARGS__ ">"; \
1876 #define DOCTEST_TYPE_TO_STRING(...) \
1877 namespace doctest { namespace detail { \
1878 DOCTEST_TYPE_TO_STRING_IMPL(__VA_ARGS__) \
1881 typedef int DOCTEST_ANONYMOUS(_DOCTEST_ANON_FOR_SEMICOLON_)
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) * \
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) \
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); \
1905 DOCTEST_CLANG_SUPPRESS_WARNING_POP \
1906 template <typename Type> \
1907 struct DOCTEST_CAT(id, ITERATOR)<Type> \
1909 DOCTEST_CAT(id, ITERATOR)(int line, int index) { \
1910 DOCTEST_REGISTER_TYPED_TEST_CASE_IMPL(anon<Type>, Type, dec, line * 1000 + index); \
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> \
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_))
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)( \
1931 DOCTEST_GLOBAL_NO_WARNINGS_END() \
1932 DOCTEST_CLANG_SUPPRESS_WARNING_POP
1934 #define DOCTEST_TEST_CASE_TEMPLATE_INSTANTIATE(id, ...) \
1935 DOCTEST_TEST_CASE_TEMPLATE_INSTANTIATE_IMPL(id, DOCTEST_ANONYMOUS(_DOCTEST_ANON_TMP_), \
1937 typedef int DOCTEST_ANONYMOUS(_DOCTEST_ANON_FOR_SEMICOLON_)
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> \
1945 #define DOCTEST_TEST_CASE_TEMPLATE(dec, T, ...) \
1946 DOCTEST_TEST_CASE_TEMPLATE_IMPL(dec, T, DOCTEST_ANONYMOUS(_DOCTEST_ANON_TMP_), __VA_ARGS__)
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)
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 \
1976 #define DOCTEST_TEST_SUITE(decorators) \
1977 DOCTEST_TEST_SUITE_IMPL(decorators, DOCTEST_ANONYMOUS(_DOCTEST_ANON_SUITE_))
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_)
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_)
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)
2001 #define DOCTEST_REGISTER_EXCEPTION_TRANSLATOR(signature) \
2002 DOCTEST_REGISTER_EXCEPTION_TRANSLATOR_IMPL(DOCTEST_ANONYMOUS(_DOCTEST_ANON_TRANSLATOR_), \
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_)
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)
2017 #define DOCTEST_ADD_AT_IMPL(type, file, line, mb, x) \
2019 doctest::detail::MessageBuilder mb(file, line, doctest::assertType::type); \
2021 DOCTEST_ASSERT_LOG_AND_REACT(mb); \
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)
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)
2034 #if __cplusplus >= 201402L || (DOCTEST_MSVC >= DOCTEST_COMPILER(19, 10, 0))
2035 template <
class T, T x>
2037 #define DOCTEST_TO_LVALUE(...) to_lvalue<decltype(__VA_ARGS__), __VA_ARGS__>
2039 #define DOCTEST_TO_LVALUE(...) TO_LVALUE_CAN_BE_USED_ONLY_IN_CPP14_MODE_OR_WITH_VS_2017_OR_NEWER
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) \
2049 DOCTEST_ASSERT_LOG_AND_REACT(_DOCTEST_RB) \
2050 DOCTEST_CLANG_SUPPRESS_WARNING_POP
2052 #define DOCTEST_ASSERT_IMPLEMENT_1(assert_type, ...) \
2054 DOCTEST_ASSERT_IMPLEMENT_2(assert_type, __VA_ARGS__); \
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__)
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)
2073 #define DOCTEST_ASSERT_THROWS(expr, assert_type) \
2075 if(!doctest::detail::getContextOptions()->no_throw) { \
2076 doctest::detail::ResultBuilder _DOCTEST_RB(doctest::assertType::assert_type, __FILE__, \
2080 } catch(...) { _DOCTEST_RB.m_threw = true; } \
2081 DOCTEST_ASSERT_LOG_AND_REACT(_DOCTEST_RB); \
2085 #define DOCTEST_ASSERT_THROWS_AS(expr, assert_type, ...) \
2087 if(!doctest::detail::getContextOptions()->no_throw) { \
2088 doctest::detail::ResultBuilder _DOCTEST_RB(doctest::assertType::assert_type, __FILE__, \
2090 DOCTEST_TOSTR(__VA_ARGS__)); \
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); \
2101 #define DOCTEST_ASSERT_NOTHROW(expr, assert_type) \
2103 if(!doctest::detail::getContextOptions()->no_throw) { \
2104 doctest::detail::ResultBuilder _DOCTEST_RB(doctest::assertType::assert_type, __FILE__, \
2108 } catch(...) { _DOCTEST_RB.unexpectedExceptionOccurred(); } \
2109 DOCTEST_ASSERT_LOG_AND_REACT(_DOCTEST_RB); \
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)
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__)
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)
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)
2137 #define DOCTEST_BINARY_ASSERT(assert_type, comp, ...) \
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>( \
2144 DOCTEST_ASSERT_LOG_AND_REACT(_DOCTEST_RB); \
2147 #define DOCTEST_UNARY_ASSERT(assert_type, ...) \
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); \
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__)
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__)
2181 #ifndef DOCTEST_CONFIG_SUPER_FAST_ASSERTS
2183 #define DOCTEST_FAST_BINARY_ASSERT(assert_type, comparison, ...) \
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__), \
2189 if(_DOCTEST_FAST_RES & doctest::detail::assertAction::dbgbreak) \
2190 DOCTEST_BREAK_INTO_DEBUGGER(); \
2191 doctest::detail::fastAssertThrowIfFlagSet(_DOCTEST_FAST_RES); \
2194 #define DOCTEST_FAST_UNARY_ASSERT(assert_type, ...) \
2196 int _DOCTEST_FAST_RES = doctest::detail::fast_unary_assert( \
2197 doctest::assertType::assert_type, __FILE__, __LINE__, DOCTEST_TOSTR(__VA_ARGS__), \
2199 if(_DOCTEST_FAST_RES & doctest::detail::assertAction::dbgbreak) \
2200 DOCTEST_BREAK_INTO_DEBUGGER(); \
2201 doctest::detail::fastAssertThrowIfFlagSet(_DOCTEST_FAST_RES); \
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__), \
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__)
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__)
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__)
2245 #ifdef DOCTEST_CONFIG_NO_EXCEPTIONS
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
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
2267 #ifdef DOCTEST_CONFIG_NO_EXCEPTIONS_BUT_WITH_ALL_ASSERTS
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)
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)
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
2322 #define DOCTEST_IMPLEMENT_FIXTURE(der, base, func, name) \
2324 template <typename DOCTEST_UNUSED_TEMPLATE_TYPE> \
2325 struct der : public base \
2328 template <typename DOCTEST_UNUSED_TEMPLATE_TYPE> \
2329 inline void der<DOCTEST_UNUSED_TEMPLATE_TYPE>::f()
2331 #define DOCTEST_CREATE_AND_REGISTER_FUNCTION(f, name) \
2332 template <typename DOCTEST_UNUSED_TEMPLATE_TYPE> \
2333 static inline void f()
2336 #define DOCTEST_TEST_CASE(name) \
2337 DOCTEST_CREATE_AND_REGISTER_FUNCTION(DOCTEST_ANONYMOUS(_DOCTEST_ANON_FUNC_), name)
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)
2345 #define DOCTEST_TYPE_TO_STRING(...) typedef int DOCTEST_ANONYMOUS(_DOCTEST_ANON_FOR_SEMICOLON_)
2346 #define DOCTEST_TYPE_TO_STRING_IMPL(...)
2349 #define DOCTEST_TEST_CASE_TEMPLATE(name, type, ...) \
2350 template <typename type> \
2351 inline void DOCTEST_ANONYMOUS(_DOCTEST_ANON_TMP_)()
2353 #define DOCTEST_TEST_CASE_TEMPLATE_DEFINE(name, type, id) \
2354 template <typename type> \
2355 inline void DOCTEST_ANONYMOUS(_DOCTEST_ANON_TMP_)()
2357 #define DOCTEST_TEST_CASE_TEMPLATE_INSTANTIATE(id, ...) \
2358 typedef int DOCTEST_ANONYMOUS(_DOCTEST_ANON_FOR_SEMICOLON_)
2361 #define DOCTEST_SUBCASE(name)
2364 #define DOCTEST_TEST_SUITE(name) namespace
2367 #define DOCTEST_TEST_SUITE_BEGIN(name) typedef int DOCTEST_ANONYMOUS(_DOCTEST_ANON_FOR_SEMICOLON_)
2370 #define DOCTEST_TEST_SUITE_END typedef int DOCTEST_ANONYMOUS(_DOCTEST_ANON_FOR_SEMICOLON_)
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)
2376 #define DOCTEST_REGISTER_REPORTER(name, priority, reporter)
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)
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)
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)
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)
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)
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)
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)
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)
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)
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)
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)
2489 #if !defined(DOCTEST_CONFIG_NO_SHORT_MACRO_NAMES)
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
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
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
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
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
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
2606 #if !defined(DOCTEST_CONFIG_DISABLE)
2612 namespace doctest {
namespace detail {
2633 DOCTEST_CLANG_SUPPRESS_WARNING_POP
2634 DOCTEST_MSVC_SUPPRESS_WARNING_POP
2635 DOCTEST_GCC_SUPPRESS_WARNING_POP
2639 #ifndef DOCTEST_SINGLE_HEADER
2640 #define DOCTEST_SINGLE_HEADER
2643 #if defined(DOCTEST_CONFIG_IMPLEMENT) || !defined(DOCTEST_SINGLE_HEADER)
2644 #ifndef DOCTEST_LIBRARY_IMPLEMENTATION
2645 #define DOCTEST_LIBRARY_IMPLEMENTATION
2647 #ifndef DOCTEST_SINGLE_HEADER
2648 #include "doctest_fwd.h"
2651 DOCTEST_CLANG_SUPPRESS_WARNING_PUSH
2670 #if DOCTEST_CLANG && DOCTEST_CLANG_HAS_WARNING("-Wzero-as-null-pointer-constant")
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")
2698 DOCTEST_MSVC_SUPPRESS_WARNING_PUSH
2699 DOCTEST_MSVC_SUPPRESS_WARNING(4616)
2700 DOCTEST_MSVC_SUPPRESS_WARNING(4619)
2701 DOCTEST_MSVC_SUPPRESS_WARNING(4996)
2702 DOCTEST_MSVC_SUPPRESS_WARNING(4267)
2703 DOCTEST_MSVC_SUPPRESS_WARNING(4706)
2704 DOCTEST_MSVC_SUPPRESS_WARNING(4512)
2705 DOCTEST_MSVC_SUPPRESS_WARNING(4127)
2706 DOCTEST_MSVC_SUPPRESS_WARNING(4530)
2707 DOCTEST_MSVC_SUPPRESS_WARNING(4577)
2708 DOCTEST_MSVC_SUPPRESS_WARNING(4774)
2709 DOCTEST_MSVC_SUPPRESS_WARNING(4365)
2710 DOCTEST_MSVC_SUPPRESS_WARNING(4820)
2711 DOCTEST_MSVC_SUPPRESS_WARNING(4640)
2712 DOCTEST_MSVC_SUPPRESS_WARNING(5039)
2713 DOCTEST_MSVC_SUPPRESS_WARNING(5045)
2714 DOCTEST_MSVC_SUPPRESS_WARNING(4626)
2715 DOCTEST_MSVC_SUPPRESS_WARNING(5027)
2716 DOCTEST_MSVC_SUPPRESS_WARNING(5026)
2717 DOCTEST_MSVC_SUPPRESS_WARNING(4625)
2718 DOCTEST_MSVC_SUPPRESS_WARNING(4800)
2720 DOCTEST_MSVC_SUPPRESS_WARNING(26439)
2721 DOCTEST_MSVC_SUPPRESS_WARNING(26495)
2722 DOCTEST_MSVC_SUPPRESS_WARNING(26451)
2723 DOCTEST_MSVC_SUPPRESS_WARNING(26444)
2743 #include <algorithm>
2750 #include <exception>
2751 #include <stdexcept>
2762 #define DOCTEST_COUNTOF(x) (sizeof(x) / sizeof(x[0]))
2764 #ifdef DOCTEST_CONFIG_DISABLE
2765 #define DOCTEST_BRANCH_ON_DISABLED(if_disabled, if_not_disabled) if_disabled
2767 #define DOCTEST_BRANCH_ON_DISABLED(if_disabled, if_not_disabled) if_not_disabled
2772 using namespace detail;
2774 int stricmp(
const char* a,
const char* b) {
2776 const int d = tolower(*a) - tolower(*b);
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) {
2791 d = d.substr(0, i + 1);
2804 static Arch which() {
2808 char asChar[
sizeof(int)];
2812 return (u.asChar[
sizeof(
int) - 1] == 1) ? Big : Little;
2818 void my_memcpy(
void* dest,
const void* src,
unsigned num) { memcpy(dest, src, num); }
2822 int i = 0, end =
static_cast<int>(
size), inc = 1;
2823 if(Endianness::which() == Endianness::Little) {
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();
2836 std::ostream*
createStream() {
return new std::ostringstream(); }
2838 return static_cast<std::ostringstream*
>(s)->str().
c_str();
2840 void freeStream(std::ostream* s) {
delete s; }
2842 #ifndef DOCTEST_CONFIG_DISABLE
2844 struct ContextState : ContextOptions, TestRunStats, CurrentTestCaseStats
2846 std::vector<std::vector<String> > filters = decltype(filters)(9);
2848 std::vector<IReporter*> reporters_currently_used;
2850 const TestCase* currentTest;
2852 std::vector<IContextScope*> contexts;
2853 std::vector<String> stringifiedContexts;
2856 std::set<SubcaseSignature> subcasesPassed;
2857 std::set<int> subcasesEnteredLevels;
2858 int subcasesCurrentLevel;
2860 void resetRunData() {
2862 numTestCasesPassingFilters = 0;
2863 numTestSuitesPassingFilters = 0;
2864 numTestCasesFailed = 0;
2866 numAssertsFailed = 0;
2870 ContextState* g_contextState = 0;
2874 void String::setOnHeap() { *
reinterpret_cast<unsigned char*
>(&buf[last]) = 128; }
2875 void String::setLast(
unsigned in) { buf[last] = char(in); }
2877 void String::copy(
const String& other) {
2878 if(other.isOnStack()) {
2879 memcpy(buf, other.buf, len);
2882 data.size = other.data.size;
2884 data.ptr =
new char[
data.capacity];
2885 memcpy(
data.ptr, other.data.ptr,
data.size + 1);
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);
2908 data.ptr =
new char[
data.capacity];
2909 memcpy(
data.ptr, in, in_len + 1);
2913 String::String(
const String& other) { copy(other); }
2915 String& String::operator=(
const String& other) {
2916 if(
this != &other) {
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;
2931 if(total_size < len) {
2933 memcpy(buf + my_old_size, other.c_str(), other_size + 1);
2934 setLast(last - total_size);
2937 char* temp =
new char[total_size + 1];
2939 memcpy(temp, buf, my_old_size);
2942 data.size = total_size;
2946 memcpy(
data.ptr + my_old_size, other.c_str(), other_size + 1);
2949 if(
data.capacity > total_size) {
2951 data.size = total_size;
2952 memcpy(
data.ptr + my_old_size, other.c_str(), other_size + 1);
2956 if(
data.capacity <= total_size)
2957 data.capacity = total_size + 1;
2959 char* temp =
new char[
data.capacity];
2961 memcpy(temp,
data.ptr, my_old_size);
2965 data.size = total_size;
2968 memcpy(
data.ptr + my_old_size, other.c_str(), other_size + 1);
2975 String
String::operator+(
const String& other)
const {
return String(*
this) += other; }
2977 String::String(String&& other) {
2978 memcpy(buf, other.buf, len);
2979 other.buf[0] =
'\0';
2983 String& String::operator=(String&& other) {
2984 if(
this != &other) {
2987 memcpy(buf, other.buf, len);
2988 other.buf[0] =
'\0';
2994 char String::operator[](
unsigned i)
const {
2995 return const_cast<String*
>(
this)->
operator[](i);
2998 char& String::operator[](
unsigned i) {
3000 return reinterpret_cast<char*
>(buf)[i];
3004 DOCTEST_GCC_SUPPRESS_WARNING_WITH_PUSH(
"-Wmaybe-uninitialized")
3007 return last - (unsigned(buf[last]) & 31);
3010 DOCTEST_GCC_SUPPRESS_WARNING_POP
3012 unsigned String::capacity()
const {
3015 return data.capacity;
3020 return stricmp(c_str(), other);
3021 return std::strcmp(c_str(), other);
3025 return compare(other.c_str(), no_case);
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; }
3037 std::ostream&
operator<<(std::ostream& s,
const String& in) {
return s << in.c_str(); }
3040 void color_to_stream(std::ostream&,
Color::Enum) DOCTEST_BRANCH_ON_DISABLED({}, ;)
3045 color_to_stream(s, code);
3052 DOCTEST_MSVC_SUPPRESS_WARNING_WITH_PUSH(4062)
3126 DOCTEST_MSVC_SUPPRESS_WARNING_POP
3138 SubcaseSignature::SubcaseSignature(
const char* name,
const char* file,
int line)
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;
3154 IContextScope::IContextScope() =
default;
3155 IContextScope::~IContextScope() =
default;
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}") +
"\""; }
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); }
3168 #define DOCTEST_TO_STRING_OVERLOAD(type, fmt) \
3169 String toString(type in) { \
3171 std::sprintf(buf, fmt, in); \
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")
3189 Approx::Approx(
double value)
3190 : m_epsilon(
static_cast<double>(std::numeric_limits<float>::epsilon()) * 100)
3196 Approx Approx::operator()(
double value)
const {
3197 Approx approx(value);
3198 approx.epsilon(m_epsilon);
3199 approx.scale(m_scale);
3203 Approx& Approx::epsilon(
double newEpsilon) {
3204 m_epsilon = newEpsilon;
3207 Approx& Approx::scale(
double newScale) {
3212 bool operator==(
double lhs,
const Approx& rhs) {
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)));
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; }
3229 String
toString(
const Approx& in) {
3235 #ifdef DOCTEST_CONFIG_DISABLE
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; }
3252 IReporter::~IReporter() =
default;
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; }
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
3269 #define DOCTEST_CONFIG_COLORS_ANSI
3274 #if DOCTEST_MSVC || defined(__MINGW32__)
3276 #define DOCTEST_WINDOWS_SAL_IN_OPT _In_opt_
3278 #define DOCTEST_WINDOWS_SAL_IN_OPT
3280 extern "C" __declspec(dllimport)
void __stdcall OutputDebugStringA(
3281 DOCTEST_WINDOWS_SAL_IN_OPT
const char*);
3282 extern "C" __declspec(dllimport)
int __stdcall IsDebuggerPresent();
3285 #ifdef DOCTEST_CONFIG_COLORS_ANSI
3289 #ifdef DOCTEST_PLATFORM_WINDOWS
3292 #ifndef WIN32_LEAN_AND_MEAN
3293 #define WIN32_LEAN_AND_MEAN
3295 #ifndef VC_EXTRA_LEAN
3296 #define VC_EXTRA_LEAN
3308 #include <windows.h>
3316 #include <sys/time.h>
3330 using namespace detail;
3331 typedef std::map<std::pair<int, String>, IReporter*> reporterMap;
3332 reporterMap& getReporters() {
3333 static reporterMap
data;
3337 void throwException() {
3338 #ifndef DOCTEST_CONFIG_NO_EXCEPTIONS
3339 throw TestFailureException();
3344 #define DOCTEST_ITERATE_THROUGH_REPORTERS(function, args) \
3345 for(auto& curr_rep : g_contextState->reporters_currently_used) \
3346 curr_rep->function(args)
3355 && g_contextState->abort_after > 0 &&
3356 g_contextState->numAssertsFailed >= g_contextState->abort_after)
3369 using namespace detail;
3372 int wildcmp(
const char* str,
const char* wild,
bool caseSensitive) {
3376 while((*str) && (*wild !=
'*')) {
3377 if((caseSensitive ? (*wild != *str) : (tolower(*wild) != tolower(*str))) &&
3392 }
else if((caseSensitive ? (*wild == *str) : (tolower(*wild) == tolower(*str))) ||
3402 while(*wild ==
'*') {
3418 bool matchesAny(
const char* name,
const std::vector<String>& filters,
bool matchEmpty,
3419 bool caseSensitive) {
3420 if(filters.empty() && matchEmpty)
3422 for(
auto& curr : filters)
3423 if(wildcmp(name, curr.c_str(), caseSensitive))
3428 #ifdef DOCTEST_PLATFORM_WINDOWS
3430 typedef unsigned long long UInt64;
3432 UInt64 getCurrentTicks() {
3433 static UInt64 hz = 0, hzo = 0;
3435 QueryPerformanceFrequency(
reinterpret_cast<LARGE_INTEGER*
>(&hz));
3436 QueryPerformanceCounter(
reinterpret_cast<LARGE_INTEGER*
>(&hzo));
3439 QueryPerformanceCounter(
reinterpret_cast<LARGE_INTEGER*
>(&t));
3440 return ((t - hzo) * 1000000) / hz;
3444 typedef uint64_t UInt64;
3446 UInt64 getCurrentTicks() {
3448 gettimeofday(&t, 0);
3449 return static_cast<UInt64
>(t.tv_sec) * 1000000 +
static_cast<UInt64
>(t.tv_usec);
3455 void start() { m_ticks = getCurrentTicks(); }
3456 unsigned int getElapsedMicroseconds()
const {
3457 return static_cast<unsigned int>(getCurrentTicks() - m_ticks);
3462 double getElapsedSeconds()
const {
return getElapsedMicroseconds() / 1000000.0; }
3473 Subcase::Subcase(
const char* name,
const char* file,
int line)
3474 : m_signature(name, file, line) {
3475 ContextState* s = g_contextState;
3478 if(s->subcasesPassed.count(m_signature) != 0)
3482 if(s->subcasesCurrentLevel < s->subcase_filter_levels) {
3483 if(!matchesAny(m_signature.m_name, s->filters[6],
true, s->case_sensitive))
3485 if(matchesAny(m_signature.m_name, s->filters[7],
false, s->case_sensitive))
3490 if(s->subcasesEnteredLevels.count(s->subcasesCurrentLevel) != 0) {
3491 s->should_reenter =
true;
3495 s->subcasesEnteredLevels.insert(s->subcasesCurrentLevel++);
3498 DOCTEST_ITERATE_THROUGH_REPORTERS(subcase_start, m_signature);
3501 Subcase::~Subcase() {
3503 ContextState* s = g_contextState;
3505 s->subcasesCurrentLevel--;
3507 if(s->should_reenter ==
false)
3508 s->subcasesPassed.insert(m_signature);
3510 DOCTEST_ITERATE_THROUGH_REPORTERS(subcase_end, m_signature);
3514 Subcase::operator bool()
const {
return m_entered; }
3516 Result::Result(
bool passed,
const String& decomposition)
3518 , m_decomposition(decomposition) {}
3537 m_should_fail =
false;
3538 m_expected_failures = 0;
3543 TestCase::TestCase(
funcType test,
const char* file,
unsigned line,
const TestSuite& test_suite,
3544 const char* type,
int template_id) {
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;
3558 m_template_id = template_id;
3563 TestCase::TestCase(
const TestCase& other)
3568 DOCTEST_MSVC_SUPPRESS_WARNING_WITH_PUSH(26434)
3569 DOCTEST_MSVC_SUPPRESS_WARNING(26437)
3570 TestCase& TestCase::operator=(const TestCase& other) {
3571 static_cast<TestCaseData&
>(*this) =
static_cast<const TestCaseData&
>(other);
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;
3578 if(m_template_id != -1)
3579 m_name = m_full_name.c_str();
3582 DOCTEST_MSVC_SUPPRESS_WARNING_POP
3587 if(m_template_id != -1) {
3588 m_full_name = String(m_name) + m_type;
3590 m_name = m_full_name.c_str();
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);
3600 return file_cmp < 0;
3601 return m_template_id < other.m_template_id;
3605 using namespace detail;
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);
3613 const int res = stricmp(lhs->m_file, rhs->m_file);
3615 const int res = std::strcmp(lhs->m_file, rhs->m_file);
3619 return static_cast<int>(lhs->m_line - rhs->m_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);
3627 const int res = std::strcmp(lhs->m_test_suite, rhs->m_test_suite);
3630 return fileOrderComparator(a, b);
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);
3638 const int res_name = std::strcmp(lhs->m_name, rhs->m_name);
3641 return suiteOrderComparator(a, b);
3645 std::set<TestCase>& getRegisteredTests() {
3646 static std::set<TestCase>
data;
3650 #ifdef DOCTEST_CONFIG_COLORS_WINDOWS
3651 HANDLE g_stdoutHandle;
3654 bool g_attrsInitted =
false;
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);
3670 int dumy_init_console_colors = colors_init();
3673 void color_to_stream(std::ostream& s,
Color::Enum code) {
3676 #ifdef DOCTEST_CONFIG_COLORS_ANSI
3677 if(g_contextState->no_colors ||
3678 (isatty(STDOUT_FILENO) ==
false && g_contextState->force_colors ==
false))
3697 default: col =
"[0m";
3703 #ifdef DOCTEST_CONFIG_COLORS_WINDOWS
3704 if(g_contextState->no_colors ||
3705 (isatty(fileno(stdout)) ==
false && g_contextState->force_colors ==
false))
3708 #define DOCTEST_SET_ATTR(x) SetConsoleTextAttribute(g_stdoutHandle, x | g_origBgAttrs)
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;
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;
3725 default: DOCTEST_SET_ATTR(g_origFgAttrs);
3731 std::vector<const IExceptionTranslator*>& getExceptionTranslators() {
3732 static std::vector<const IExceptionTranslator*>
data;
3737 #ifndef DOCTEST_CONFIG_NO_EXCEPTIONS
3739 auto& translators = getExceptionTranslators();
3740 for(
auto& curr : translators)
3741 if(curr->translate(res))
3746 }
catch(std::exception& ex) {
3748 }
catch(std::string&
msg) {
3750 }
catch(
const char*
msg) {
3753 return "unknown exception";
3764 int regTest(
const TestCase& tc) {
3765 getRegisteredTests().insert(tc);
3776 if(
std::find(getExceptionTranslators().begin(), getExceptionTranslators().end(),
3777 translateFunction) == getExceptionTranslators().end())
3778 getExceptionTranslators().push_back(translateFunction);
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; }
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; }
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; }
3804 ContextBuilder::ICapture::ICapture() =
default;
3805 ContextBuilder::ICapture::~ICapture() =
default;
3807 ContextBuilder::Chunk::Chunk() =
default;
3808 ContextBuilder::Chunk::~Chunk() =
default;
3810 ContextBuilder::Node::Node() =
default;
3811 ContextBuilder::Node::~Node() =
default;
3814 ContextBuilder::ContextBuilder(ContextBuilder& other)
3815 : numCaptures(other.numCaptures)
3817 , tail(other.tail) {
3818 other.numCaptures = 0;
3821 memcpy(stackChunks, other.stackChunks,
3825 DOCTEST_GCC_SUPPRESS_WARNING_WITH_PUSH(
"-Wcast-align")
3826 void ContextBuilder::stringify(
std::ostream* s)
const {
3830 reinterpret_cast<const ICapture*
>(stackChunks[curr++].buf)->
toStream(s);
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;
3839 DOCTEST_GCC_SUPPRESS_WARNING_POP
3841 ContextBuilder::ContextBuilder() =
default;
3843 ContextBuilder::~ContextBuilder() {
3847 auto next = head->next;
3853 ContextScope::ContextScope(ContextBuilder& temp)
3854 : contextBuilder(temp) {
3855 g_contextState->contexts.push_back(
this);
3858 DOCTEST_MSVC_SUPPRESS_WARNING_WITH_PUSH(4996)
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());
3866 g_contextState->contexts.pop_back();
3868 DOCTEST_GCC_SUPPRESS_WARNING_POP
3869 DOCTEST_MSVC_SUPPRESS_WARNING_POP
3871 void ContextScope::stringify(std::ostream* s)
const { contextBuilder.stringify(s); }
3874 using namespace detail;
3875 #if !defined(DOCTEST_CONFIG_POSIX_SIGNALS) && !defined(DOCTEST_CONFIG_WINDOWS_SEH)
3876 struct FatalConditionHandler
3882 void reportFatal(
const std::string&);
3884 #ifdef DOCTEST_PLATFORM_WINDOWS
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"},
3901 struct FatalConditionHandler
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);
3911 return EXCEPTION_CONTINUE_SEARCH;
3914 FatalConditionHandler() {
3918 guaranteeSize = 32 * 1024;
3919 exceptionHandlerHandle = 0;
3921 exceptionHandlerHandle = AddVectoredExceptionHandler(1, handleVectoredException);
3923 SetThreadStackGuarantee(&guaranteeSize);
3926 static void reset() {
3929 RemoveVectoredExceptionHandler(exceptionHandlerHandle);
3930 SetThreadStackGuarantee(&guaranteeSize);
3931 exceptionHandlerHandle = 0;
3936 ~FatalConditionHandler() { reset(); }
3940 static ULONG guaranteeSize;
3941 static PVOID exceptionHandlerHandle;
3944 bool FatalConditionHandler::isSet =
false;
3945 ULONG FatalConditionHandler::guaranteeSize = 0;
3946 PVOID FatalConditionHandler::exceptionHandlerHandle = 0;
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"}};
3962 struct FatalConditionHandler
3965 static struct sigaction oldSigActions[DOCTEST_COUNTOF(signalDefs)];
3966 static stack_t oldSigStack;
3967 static char altStackMem[4 * SIGSTKSZ];
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];
3983 FatalConditionHandler() {
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};
3992 sa.sa_handler = handleSignal;
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]);
3999 ~FatalConditionHandler() { reset(); }
4000 static void reset() {
4003 for(std::size_t i = 0; i < DOCTEST_COUNTOF(signalDefs); ++i) {
4004 sigaction(signalDefs[i].
id, &oldSigActions[i], 0);
4007 sigaltstack(&oldSigStack, 0);
4013 bool FatalConditionHandler::isSet =
false;
4014 struct sigaction FatalConditionHandler::oldSigActions[DOCTEST_COUNTOF(signalDefs)] = {};
4015 stack_t FatalConditionHandler::oldSigStack = {};
4016 char FatalConditionHandler::altStackMem[] = {};
4024 #ifdef DOCTEST_PLATFORM_MAC
4025 #include <sys/types.h>
4027 #include <sys/sysctl.h>
4031 using namespace detail;
4032 #ifdef DOCTEST_PLATFORM_MAC
4043 info.kp_proc.p_flag = 0;
4048 mib[2] = KERN_PROC_PID;
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 "
4058 return ((
info.kp_proc.p_flag & P_TRACED) != 0);
4060 #elif DOCTEST_MSVC || defined(__MINGW32__)
4066 #ifdef DOCTEST_PLATFORM_WINDOWS
4067 #define DOCTEST_OUTPUT_DEBUG_STRING(text) ::OutputDebugStringA(text)
4070 #define DOCTEST_OUTPUT_DEBUG_STRING(text)
4075 g_contextState->numAsserts++;
4076 g_contextState->numAssertsForCurrentTestCase++;
4082 g_contextState->numAssertsFailed++;
4083 g_contextState->numAssertsFailedForCurrentTestCase++;
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();
4091 g_contextState->error_string = message.c_str();
4092 g_contextState->should_reenter =
false;
4096 DOCTEST_ITERATE_THROUGH_REPORTERS(test_case_end, *g_contextState);
4098 g_contextState->numTestCasesFailed++;
4100 DOCTEST_ITERATE_THROUGH_REPORTERS(test_run_end, *g_contextState);
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;
4115 m_exception_type = exception_type;
4117 if(m_expr[0] ==
' ')
4124 void ResultBuilder::setResult(
const Result& res) {
4125 m_decomposition = res.m_decomposition;
4126 m_failed = !res.m_passed;
4129 void ResultBuilder::unexpectedExceptionOccurred() {
4134 bool ResultBuilder::log() {
4138 m_failed = !m_threw;
4140 m_failed = !m_threw_as;
4145 DOCTEST_ITERATE_THROUGH_REPORTERS(log_assert, *
this);
4148 addFailedAssert(m_at);
4153 void ResultBuilder::react()
const {
4158 MessageBuilder::MessageBuilder(
const char* file,
int line,
assertType::Enum severity) {
4162 m_severity = severity;
4165 IExceptionTranslator::IExceptionTranslator() =
default;
4166 IExceptionTranslator::~IExceptionTranslator() =
default;
4168 bool MessageBuilder::log() {
4170 DOCTEST_ITERATE_THROUGH_REPORTERS(log_message, *
this);
4176 addAssert(m_severity);
4177 addFailedAssert(m_severity);
4183 void MessageBuilder::react() {
4188 MessageBuilder::~MessageBuilder() {
freeStream(m_stream); }
4191 using namespace detail;
4192 struct ConsoleReporter :
public IReporter
4195 bool hasLoggedCurrentTestStart;
4196 std::vector<SubcaseSignature> subcasesStack;
4199 const ContextOptions* opt;
4200 const TestCaseData* tc;
4202 ConsoleReporter(std::ostream& in)
4209 void separator_to_stream() {
4211 <<
"============================================================================="
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) {
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)
4233 << (opt->gnu_file_line ?
":" :
"):") << tail;
4237 const char* success_str) {
4245 return "FATAL ERROR: ";
4255 const char* success_str =
"SUCCESS: ") {
4256 s << getSuccessOrFailColor(success, at)
4257 << getSuccessOrFailString(success, at, success_str);
4260 void log_contexts() {
4261 int num_contexts = get_num_active_contexts();
4263 auto contexts = get_active_contexts();
4266 for(
int i = 0; i < num_contexts; ++i) {
4267 s << (i == 0 ?
"" :
" ");
4268 contexts[i]->stringify(&s);
4276 void logTestStart() {
4277 if(hasLoggedCurrentTestStart)
4280 separator_to_stream();
4281 file_line_to_stream(tc->m_file, tc->m_line,
"\n");
4282 if(tc->m_description)
4284 if(tc->m_test_suite && tc->m_test_suite[0] !=
'\0')
4286 if(strncmp(tc->m_name,
" Scenario:", 11) != 0)
4290 for(
auto& curr : subcasesStack)
4291 if(curr.m_name[0] !=
'\0')
4292 s <<
" " << curr.m_name <<
"\n";
4296 hasLoggedCurrentTestStart =
true;
4303 void test_run_start(
const ContextOptions& o)
override { opt = &o; }
4305 void test_run_end(
const TestRunStats& p)
override {
4306 separator_to_stream();
4308 const bool anythingFailed = p.numTestCasesFailed > 0 || p.numAssertsFailed > 0;
4310 << p.numTestCasesPassingFilters <<
" | "
4311 << ((p.numTestCasesPassingFilters == 0 || anythingFailed) ?
Color::None :
4313 << std::setw(6) << p.numTestCasesPassingFilters - p.numTestCasesFailed <<
" passed"
4315 << std::setw(6) << p.numTestCasesFailed <<
" failed" <<
Color::None <<
" | ";
4316 if(opt->no_skipped_summary ==
false) {
4317 const int numSkipped = p.numTestCases - p.numTestCasesPassingFilters;
4323 << p.numAsserts <<
" | "
4325 << std::setw(6) << (p.numAsserts - p.numAssertsFailed) <<
" passed" <<
Color::None
4327 << p.numAssertsFailed <<
" failed" <<
Color::None <<
" |\n";
4330 << ((p.numTestCasesFailed > 0) ?
"FAILURE!\n" :
"SUCCESS!\n") <<
Color::None;
4333 void test_case_start(
const TestCaseData& in)
override {
4334 hasLoggedCurrentTestStart =
false;
4338 void test_case_end(
const CurrentTestCaseStats& st)
override {
4348 file_line_to_stream(tc->m_file, tc->m_line,
" ");
4351 s <<
Color::Red << (crashed ?
"test case CRASHED: " :
"test case THREW exception: ")
4354 int num_stringified_contexts = get_num_stringified_contexts();
4355 if(num_stringified_contexts) {
4356 auto stringified_contexts = get_stringified_contexts();
4358 for(
int i = num_stringified_contexts - 1; i >= 0; --i) {
4359 s << (i == num_stringified_contexts - 1 ?
"" :
" ")
4360 << stringified_contexts[i] <<
"\n";
4367 if(st.should_reenter)
4371 s <<
Color::None << std::setprecision(6) << std::fixed << st.seconds_so_far
4372 <<
" s: " << tc->m_name <<
"\n";
4375 s <<
Color::Red <<
"Test case exceeded time limit of " << std::setprecision(6)
4376 << std::fixed << tc->m_timeout <<
"!\n";
4379 s <<
Color::Red <<
"Should have failed but didn't! Marking it as failed!\n";
4381 s <<
Color::Yellow <<
"Failed as expected so marking it as not failed\n";
4383 s <<
Color::Yellow <<
"Allowed to fail so marking it as not failed\n";
4385 s <<
Color::Red <<
"Didn't fail exactly " << tc->m_expected_failures
4386 <<
" times so marking it as failed!\n";
4388 s <<
Color::Yellow <<
"Failed exactly " << tc->m_expected_failures
4389 <<
" times as expected so marking it as not failed!\n";
4392 s <<
Color::Red <<
"Aborting - too many failed asserts!\n";
4397 void subcase_start(
const SubcaseSignature& subc)
override {
4398 subcasesStack.push_back(subc);
4399 hasLoggedCurrentTestStart =
false;
4402 void subcase_end(
const SubcaseSignature& )
override {
4403 subcasesStack.pop_back();
4404 hasLoggedCurrentTestStart =
false;
4407 void log_assert(
const AssertData& rb)
override {
4408 if(!rb.m_failed && !opt->success)
4413 file_line_to_stream(rb.m_file, rb.m_line,
" ");
4414 successOrFailColoredStringToStream(!rb.m_failed, rb.m_at);
4420 s << (rb.m_threw ?
"threw as expected!" :
"did NOT throw at all!") <<
"\n";
4425 << (rb.m_threw ? (rb.m_threw_as ?
"threw as expected!" :
4426 "threw a DIFFERENT exception: ") :
4427 "did NOT throw at all!")
4430 s << (rb.m_threw ?
"THREW exception: " :
"didn't throw!") <<
Color::Cyan
4431 << rb.m_exception <<
"\n";
4433 s << (rb.m_threw ?
"THREW exception: " :
4434 (!rb.m_failed ?
"is correct!\n" :
"is NOT correct!\n"));
4436 s << rb.m_exception <<
"\n";
4438 s <<
" values: " <<
assertString(rb.m_at) <<
"( " << rb.m_decomposition
4445 void log_message(
const MessageData& mb)
override {
4448 file_line_to_stream(mb.m_file, mb.m_line,
" ");
4449 s << getSuccessOrFailColor(
false, mb.m_severity)
4456 void test_case_skipped(
const TestCaseData&)
override {}
4460 struct ConsoleReporterWithHelpers :
public ConsoleReporter
4462 ConsoleReporterWithHelpers(std::ostream& in)
4463 : ConsoleReporter(in) {}
4466 if(g_contextState->no_version ==
false)
4481 s <<
"boolean values: \"1/on/yes/true\" or \"0/off/no/false\"\n";
4483 s <<
"filter values: \"str1,str2,str3\" (comma separated strings)\n";
4486 s <<
"filters use wildcards for matching strings\n";
4488 s <<
"something passes a filter if any of the strings in a filter matches\n";
4491 s <<
"ALL FLAGS, OPTIONS AND FILTERS ALSO AVAILABLE WITH A \"dt-\" PREFIX!!!\n";
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";
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";
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";
4543 s <<
"for more information visit the project documentation\n\n";
4546 void printRegisteredReporters() {
4549 for(
auto& curr : getReporters())
4550 s <<
"priority: " << std::setw(5) << curr.first.first
4551 <<
" name: " << curr.first.second <<
"\n";
4554 void output_query_results() {
4555 separator_to_stream();
4556 if(g_contextState->count || g_contextState->list_test_cases) {
4558 <<
"unskipped test cases passing the current filters: "
4559 << g_contextState->numTestCasesPassingFilters <<
"\n";
4560 }
else if(g_contextState->list_test_suites) {
4562 <<
"unskipped test cases passing the current filters: "
4563 << g_contextState->numTestCasesPassingFilters <<
"\n";
4565 <<
"test suites with unskipped test cases passing the current filters: "
4566 << g_contextState->numTestSuitesPassingFilters <<
"\n";
4570 void output_query_preamble_test_cases() {
4572 separator_to_stream();
4575 void output_query_preamble_test_suites() {
4577 separator_to_stream();
4580 void output_c_string_with_newline(
const char* str) { s <<
Color::None << str <<
"\n"; }
4583 #ifdef DOCTEST_PLATFORM_WINDOWS
4584 struct DebugOutputWindowReporter :
public ConsoleReporter
4586 std::ostringstream oss;
4588 DebugOutputWindowReporter()
4589 : ConsoleReporter(oss) {}
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()); \
4599 g_contextState->no_colors = with_col; \
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&)
4614 DebugOutputWindowReporter g_debug_output_rep;
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)) {
4623 bool noBadCharsFound =
true;
4624 while(temp != argv[i]) {
4625 if(*--temp !=
'-') {
4626 noBadCharsFound =
false;
4630 if(noBadCharsFound && argv[i][0] ==
'-')
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))
4643 return parseFlagImpl(argc, argv, pattern);
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);
4652 bool noBadCharsFound =
true;
4653 auto curr = argv[i];
4654 while(curr != temp) {
4655 if(*curr++ !=
'-') {
4656 noBadCharsFound =
false;
4660 if(noBadCharsFound && argv[i][0] ==
'-') {
4661 temp += strlen(pattern);
4662 const unsigned len = strlen(temp);
4674 bool parseOption(
int argc,
const char*
const* argv,
const char* pattern, String& res,
4675 const String& defaultVal = String()) {
4677 #ifndef DOCTEST_CONFIG_NO_UNPREFIXED_OPTIONS
4678 if(parseOptionImpl(argc, argv, pattern + 3, res))
4681 return parseOptionImpl(argc, argv, pattern, res);
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)) {
4691 auto pch = std::strtok(filtersString.c_str(),
",");
4697 pch = std::strtok(0,
",");
4711 bool parseIntOption(
int argc,
const char*
const* argv,
const char* pattern, optionType type,
4714 if(!parseOption(argc, argv, pattern, parsedValue))
4719 const char positive[][5] = {
"1",
"true",
"on",
"yes"};
4720 const char negative[][6] = {
"0",
"false",
"off",
"no"};
4723 for(
unsigned i = 0; i < 4; i++) {
4724 if(parsedValue.compare(positive[i],
true) == 0) {
4728 if(parsedValue.compare(negative[i],
true) == 0) {
4736 int theInt = std::atoi(parsedValue.c_str());
4748 Context::Context(
int argc,
const char*
const* argv)
4749 : p(
new detail::ContextState) {
4750 parseArgs(argc, argv,
true);
4753 Context::~Context() {
delete p; }
4755 void Context::applyCommandLine(
int argc,
const char*
const* argv) { parseArgs(argc, argv); }
4758 void Context::parseArgs(
int argc,
const char*
const* argv,
bool withDefaults) {
4759 using namespace detail;
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]);
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)) \
4791 else if(withDefaults) \
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)) \
4798 else if(withDefaults) \
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) \
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);
4810 DOCTEST_PARSE_INT_OPTION(
"dt-first",
"dt-f", first, 0);
4811 DOCTEST_PARSE_INT_OPTION(
"dt-last",
"dt-l", last, UINT_MAX);
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);
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);
4838 p->list_test_cases =
false;
4839 p->list_test_suites =
false;
4840 p->list_reporters =
false;
4842 if(parseFlag(argc, argv,
"dt-help") || parseFlag(argc, argv,
"dt-h") ||
4843 parseFlag(argc, argv,
"dt-?")) {
4847 if(parseFlag(argc, argv,
"dt-version") || parseFlag(argc, argv,
"dt-v")) {
4851 if(parseFlag(argc, argv,
"dt-count") || parseFlag(argc, argv,
"dt-c")) {
4855 if(parseFlag(argc, argv,
"dt-list-test-cases") || parseFlag(argc, argv,
"dt-ltc")) {
4856 p->list_test_cases =
true;
4859 if(parseFlag(argc, argv,
"dt-list-test-suites") || parseFlag(argc, argv,
"dt-lts")) {
4860 p->list_test_suites =
true;
4863 if(parseFlag(argc, argv,
"dt-list-reporters") || parseFlag(argc, argv,
"dt-lr")) {
4864 p->list_reporters =
true;
4870 void Context::addFilter(
const char* filter,
const char* value) { setOption(filter, value); }
4873 void Context::clearFilters() {
4874 for(
auto& curr : p->filters)
4879 void Context::setOption(
const char* option,
int value) {
4880 setOption(option,
toString(value).c_str());
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);
4891 bool Context::shouldExit() {
return p->exit; }
4894 int Context::run() {
4895 using namespace detail;
4900 ConsoleReporterWithHelpers g_con_rep(std::cout);
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")]);
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);
4915 #ifdef DOCTEST_PLATFORM_WINDOWS
4917 p->reporters_currently_used.push_back(&g_debug_output_rep);
4921 if(p->no_run || p->version || p->help || p->list_reporters) {
4923 g_con_rep.printVersion();
4925 g_con_rep.printHelp();
4926 if(p->list_reporters)
4927 g_con_rep.printRegisteredReporters();
4931 return EXIT_SUCCESS;
4934 g_con_rep.printIntro();
4936 std::vector<const TestCase*> testArray;
4937 for(
auto& curr : getRegisteredTests())
4938 testArray.push_back(&curr);
4939 p->numTestCases = testArray.size();
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);
4953 const auto first = &testArray[0];
4954 for(
size_t i = testArray.size() - 1; i > 0; --i) {
4955 int idxToSwap = std::rand() % (i + 1);
4957 const auto temp = first[i];
4959 first[i] = first[idxToSwap];
4960 first[idxToSwap] = temp;
4965 if(p->list_test_cases)
4966 g_con_rep.output_query_preamble_test_cases();
4968 std::set<String> testSuitesPassingFilt;
4969 if(p->list_test_suites)
4970 g_con_rep.output_query_preamble_test_suites();
4972 bool query_mode = p->count || p->list_test_cases || p->list_test_suites;
4975 DOCTEST_ITERATE_THROUGH_REPORTERS(test_run_start, *g_contextState);
4978 for(
auto& curr : testArray) {
4979 const auto tc = *curr;
4981 bool skip_me =
false;
4982 if(tc.m_skip && !p->no_skip)
4985 if(!matchesAny(tc.m_file, p->filters[0],
true, p->case_sensitive))
4987 if(matchesAny(tc.m_file, p->filters[1],
false, p->case_sensitive))
4989 if(!matchesAny(tc.m_test_suite, p->filters[2],
true, p->case_sensitive))
4991 if(matchesAny(tc.m_test_suite, p->filters[3],
false, p->case_sensitive))
4993 if(!matchesAny(tc.m_name, p->filters[4],
true, p->case_sensitive))
4995 if(matchesAny(tc.m_name, p->filters[5],
false, p->case_sensitive))
4999 p->numTestCasesPassingFilters++;
5002 if((p->last < p->numTestCasesPassingFilters && p->first <= p->last) ||
5003 (p->first > p->numTestCasesPassingFilters))
5008 DOCTEST_ITERATE_THROUGH_REPORTERS(test_case_skipped, tc);
5017 if(p->list_test_cases) {
5018 g_con_rep.output_c_string_with_newline(tc.m_name);
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++;
5034 p->currentTest = &tc;
5037 p->numAssertsFailedForCurrentTestCase = 0;
5038 p->numAssertsForCurrentTestCase = 0;
5039 p->seconds_so_far = 0;
5040 p->error_string =
"";
5042 p->subcasesPassed.clear();
5045 p->should_reenter =
false;
5046 p->subcasesCurrentLevel = 0;
5047 p->subcasesEnteredLevels.clear();
5050 p->stringifiedContexts.clear();
5052 DOCTEST_ITERATE_THROUGH_REPORTERS(test_case_start, tc);
5056 #ifndef DOCTEST_CONFIG_NO_EXCEPTIONS
5059 FatalConditionHandler fatalConditionHandler;
5062 fatalConditionHandler.reset();
5063 #ifndef DOCTEST_CONFIG_NO_EXCEPTIONS
5064 }
catch(
const TestFailureException&) {
5072 p->seconds_so_far += g_timer.getElapsedSeconds();
5075 if(p->abort_after > 0 && p->numAssertsFailed >= p->abort_after) {
5076 p->should_reenter =
false;
5082 if(p->should_reenter ==
true)
5083 DOCTEST_ITERATE_THROUGH_REPORTERS(test_case_end, *g_contextState);
5084 }
while(p->should_reenter ==
true);
5086 if(g_contextState->numAssertsFailedForCurrentTestCase)
5089 if(Approx(p->currentTest->m_timeout).epsilon(DBL_EPSILON) != 0 &&
5090 Approx(p->seconds_so_far).epsilon(DBL_EPSILON) > p->currentTest->m_timeout)
5093 if(tc.m_should_fail) {
5094 if(p->failure_flags) {
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) {
5114 if(p->failure_flags && !ok_to_fail)
5115 p->numTestCasesFailed++;
5117 DOCTEST_ITERATE_THROUGH_REPORTERS(test_case_end, *g_contextState);
5120 if(p->abort_after > 0 && p->numAssertsFailed >= p->abort_after)
5126 DOCTEST_ITERATE_THROUGH_REPORTERS(test_run_end, *g_contextState);
5128 g_con_rep.output_query_results();
5132 if(p->numTestCasesFailed && !p->no_exitcode)
5133 return EXIT_FAILURE;
5134 return EXIT_SUCCESS;
5141 IReporter::~IReporter() =
default;
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;
5148 int IReporter::get_num_stringified_contexts() {
5149 return detail::g_contextState->stringifiedContexts.size();
5151 const String* IReporter::get_stringified_contexts() {
5152 return get_num_stringified_contexts() ? &detail::g_contextState->stringifiedContexts[0] : 0;
5156 getReporters().insert(reporterMap::value_type(reporterMap::key_type(priority, name), r));
5164 #ifdef DOCTEST_CONFIG_IMPLEMENT_WITH_MAIN
5168 DOCTEST_CLANG_SUPPRESS_WARNING_POP
5169 DOCTEST_MSVC_SUPPRESS_WARNING_POP
5170 DOCTEST_GCC_SUPPRESS_WARNING_POP
friend bool operator==(double lhs, const Approx &rhs)
friend bool operator!=(double lhs, const Approx &rhs)
Approx & scale(double newScale)
friend bool operator!=(const Approx &lhs, double rhs)
friend bool operator<=(const Approx &lhs, double rhs)
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)
Approx & epsilon(double newEpsilon)
friend bool operator>=(double lhs, const Approx &rhs)
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)
const char * c_str() const
String & operator=(String &&other)
String operator+(const String &other) const
void setLast(unsigned in=last)
void copy(const String &other)
char & operator[](unsigned i)
String & operator+=(const String &other)
unsigned capacity() const
int compare(const String &other, bool no_case=false) const
char operator[](unsigned i) const
int compare(const char *other, bool no_case=false) const
ContextBuilder & operator<<(const T &&)
void stringify(std::ostream *s) const
ContextBuilder(ContextBuilder &other)
ContextBuilder & operator=(const ContextBuilder &)=delete
ContextScope(ContextBuilder &temp)
ContextBuilder contextBuilder
void stringify(std::ostream *s) const
OCLINT destructor of virtual class.
ExceptionTranslator(String(*translateFunction)(T))
bool translate(String &res) const
static void printVersion()
#define DOCTEST_FORBIT_EXPRESSION(rt, op)
DOCTEST_CLANG_SUPPRESS_WARNING_PUSH DOCTEST_CLANG_SUPPRESS_WARNING("-Wunknown-pragmas") DOCTEST_CLANG_SUPPRESS_WARNING("-Wnon-virtual-dtor") DOCTEST_CLANG_SUPPRESS_WARNING("-Wweak-vtables") DOCTEST_CLANG_SUPPRESS_WARNING("-Wpadded") DOCTEST_CLANG_SUPPRESS_WARNING("-Wdeprecated") DOCTEST_CLANG_SUPPRESS_WARNING("-Wmissing-prototypes") DOCTEST_CLANG_SUPPRESS_WARNING("-Wunused-local-typedef") DOCTEST_CLANG_SUPPRESS_WARNING("-Wc++11-long-long") DOCTEST_CLANG_SUPPRESS_WARNING("-Wc++98-compat") DOCTEST_CLANG_SUPPRESS_WARNING("-Wc++98-compat-pedantic") DOCTEST_GCC_SUPPRESS_WARNING_PUSH DOCTEST_GCC_SUPPRESS_WARNING("-Wunknown-pragmas") DOCTEST_GCC_SUPPRESS_WARNING("-Wpragmas") DOCTEST_GCC_SUPPRESS_WARNING("-Weffc++") DOCTEST_GCC_SUPPRESS_WARNING("-Wstrict-overflow") DOCTEST_GCC_SUPPRESS_WARNING("-Wstrict-aliasing") DOCTEST_GCC_SUPPRESS_WARNING("-Wctor-dtor-privacy") DOCTEST_GCC_SUPPRESS_WARNING("-Wmissing-declarations") DOCTEST_GCC_SUPPRESS_WARNING("-Wnon-virtual-dtor") DOCTEST_GCC_SUPPRESS_WARNING("-Winline") DOCTEST_GCC_SUPPRESS_WARNING("-Wlong-long") DOCTEST_GCC_SUPPRESS_WARNING("-Wzero-as-null-pointer-constant") DOCTEST_GCC_SUPPRESS_WARNING("-Wunused-local-typedefs") DOCTEST_GCC_SUPPRESS_WARNING("-Wuseless-cast") DOCTEST_MSVC_SUPPRESS_WARNING_PUSH DOCTEST_MSVC_SUPPRESS_WARNING(4616) DOCTEST_MSVC_SUPPRESS_WARNING(4619) DOCTEST_MSVC_SUPPRESS_WARNING(4996) DOCTEST_MSVC_SUPPRESS_WARNING(4706) DOCTEST_MSVC_SUPPRESS_WARNING(4512) DOCTEST_MSVC_SUPPRESS_WARNING(4127) DOCTEST_MSVC_SUPPRESS_WARNING(4820) DOCTEST_MSVC_SUPPRESS_WARNING(4625) DOCTEST_MSVC_SUPPRESS_WARNING(4626) DOCTEST_MSVC_SUPPRESS_WARNING(5027) DOCTEST_MSVC_SUPPRESS_WARNING(5026) DOCTEST_MSVC_SUPPRESS_WARNING(4623) DOCTEST_MSVC_SUPPRESS_WARNING(4640) DOCTEST_MSVC_SUPPRESS_WARNING(26439) DOCTEST_MSVC_SUPPRESS_WARNING(26495) DOCTEST_MSVC_SUPPRESS_WARNING(26451) DOCTEST_MSVC_SUPPRESS_WARNING(26444) namespace std
#define DOCTEST_BREAK_INTO_DEBUGGER()
DOCTEST_CLANG_SUPPRESS_WARNING_WITH_PUSH("-Wglobal-constructors") static int _DOCTEST_ANON_VAR___LINE__ __attribute__((unused))
#define DOCTEST_VERSION_STR
#define DOCTEST_RELATIONAL_OP(name, op)
#define DOCTEST_CMP_LE(l, r)
#define DOCTEST_TYPE_TO_STRING_IMPL(...)
#define DOCTEST_DECLARE_DEFAULTS(type)
#define DOCTEST_CMP_NE(l, r)
#define DOCTEST_CONFIG_NUM_CAPTURES_ON_STACK
#define DOCTEST_DELETE_COPIES(type)
#define DOCTEST_DEFINE_DEFAULTS(type)
#define DOCTEST_CMP_GT(l, r)
#define DOCTEST_BINARY_RELATIONAL_OP(n, op)
#define DOCTEST_DEFINE_DECORATOR(name, type, def)
#define DOCTEST_ALIGNMENT(x)
#define DOCTEST_CMP_GE(l, r)
#define DOCTEST_DO_BINARY_EXPRESSION_COMPARISON(op, op_str, op_macro)
#define DOCTEST_INTERFACE
#define DOCTEST_TEST_SUITE_END
#define DOCTEST_MAKE_STD_HEADERS_CLEAN_FROM_WARNINGS_ON_WALL_END
#define DOCTEST_DEFINE_COPIES(type)
#define DOCTEST_CMP_LT(l, r)
#define DOCTEST_MAKE_STD_HEADERS_CLEAN_FROM_WARNINGS_ON_WALL_BEGIN
#define DOCTEST_DECLARE_COPIES(type)
#define DOCTEST_REF_WRAP(x)
#define DOCTEST_CMP_EQ(l, r)
int main(int argc, char *argv[])
bool msg(InputEvent &event)
bool info(InputEvent &event)
bool find(const std::string &key)
bool compare(T1 const &lhs, T2 const &rhs)
std::string translateActiveException()
@ ShouldHaveFailedButDidnt
@ DidntFailExactlyNumTimes
@ DT_FAST_CHECK_UNARY_FALSE
@ DT_FAST_REQUIRE_UNARY_FALSE
@ DT_FAST_WARN_UNARY_FALSE
no operator<<(const std::ostream &, const any_t &)
void fastAssertThrowIfFlagSet(int flags)
void registerExceptionTranslatorImpl(const IExceptionTranslator *translateFunction)
bool checkIfShouldThrow(assertType::Enum at)
void writeStringToStream(std::ostream *s, const String &str)
int setTestSuite(const TestSuite &ts)
String getStreamResult(std::ostream *)
bool gt(const L &lhs, const R &rhs)
void freeStream(std::ostream *)
DOCTEST_CLANG_SUPPRESS_WARNING_PUSH R bool eq(const L &lhs, const R &rhs)
bool lt(const L &lhs, const R &rhs)
const ContextOptions * getContextOptions()
std::ostream * createStream()
void my_memcpy(void *dest, const void *src, unsigned num)
int regTest(const TestCase &tc)
const char * type_to_string()
String stringifyBinaryExpr(const L &lhs, const char *op, const R &rhs)
bool le(const L &lhs, const R &rhs)
bool ne(const L &lhs, const R &rhs)
bool ge(const L &lhs, const R &rhs)
String rawMemoryToString(const T &object)
void toStream(std::ostream *s, int long long unsigned in)
doctest::detail::TestSuite & getCurrentTestSuite()
bool operator<(const String &lhs, const String &rhs)
bool operator>(const String &lhs, const String &rhs)
const char * assertString(assertType::Enum at)
String toString(const Approx &in)
int registerReporter(const char *name, int priority, IReporter *r)
bool operator==(const String &lhs, const String &rhs)
int registerExceptionTranslator(String(*translateFunction)(T))
bool operator>=(const String &lhs, const String &rhs)
String toString(const T &value)
bool operator!=(const String &lhs, const String &rhs)
bool operator<=(const String &lhs, const String &rhs)
CInt operator*(size_t lhs, const CInt &rhs)
CInt operator+(size_t lhs, const CInt &rhs)
decltype(nullptr) typedef nullptr_t
const char * m_exception_type
const TestCaseData * m_test_case
bool no_path_in_filenames
int subcase_filter_levels
int numAssertsFailedForCurrentTestCase
int numAssertsForCurrentTestCase
virtual void stringify(std::ostream *) const =0
virtual void subcase_start(const SubcaseSignature &)=0
virtual void test_run_start(const ContextOptions &)=0
virtual void log_message(const MessageData &)=0
virtual void test_case_end(const CurrentTestCaseStats &)=0
virtual void log_assert(const AssertData &)=0
virtual void test_run_end(const TestRunStats &)=0
static const IContextScope *const * get_active_contexts()
static int get_num_active_contexts()
virtual void subcase_end(const SubcaseSignature &)=0
virtual void test_case_skipped(const TestCaseData &)=0
static int get_num_stringified_contexts()
static const String * get_stringified_contexts()
virtual void test_case_start(const TestCaseData &)=0
assertType::Enum m_severity
static String convert(R C::*p)
static String convert(U *p)
OCLINT avoid private static members.
bool operator<(const SubcaseSignature &other) const
SubcaseSignature(const char *name, const char *file, int line)
const char * m_description
const char * m_test_suite
unsigned numTestCasesFailed
unsigned numTestSuitesPassingFilters
unsigned numTestCasesPassingFilters
OCLINT destructor of virtual class.
void toStream(std::ostream *s) const override
virtual void toStream(std::ostream *) const =0
ExpressionDecomposer(assertType::Enum at)
Expression_lhs(L in, assertType::Enum at)
virtual ~IExceptionTranslator()
virtual bool translate(String &) const =0
MessageBuilder(const char *file, int line, assertType::Enum severity)
MessageBuilder & operator<<(const T &in)
bool operator()(const L &, const R &) const
void unexpectedExceptionOccurred()
void setResult(const Result &res)
ResultBuilder(assertType::Enum at, const char *file, int line, const char *expr, const char *exception_type="")
Result(bool passed, const String &decomposition=String())
static String convert(const T &in)
static String convert(const T &)
static void convert(std::ostream *s, const T &in)
static void convert(std::ostream *s, const T &in)
static void convert(std::ostream *s, const char *in)
Subcase(const char *name, const char *file, int line)
SubcaseSignature m_signature
TestCase(const TestCase &other)
DOCTEST_MSVC_SUPPRESS_WARNING_WITH_PUSH(26434) TestCase &operator
TestCase(funcType test, const char *file, unsigned line, const TestSuite &test_suite, const char *type="", int template_id=-1)
bool operator<(const TestCase &other) const
const char * m_description
TestSuite & operator*(const T &in)
TestSuite & operator*(const char *in)
const char * m_test_suite