11 #ifndef TWOBLUECUBES_SINGLE_INCLUDE_CATCH_HPP_INCLUDED
12 #define TWOBLUECUBES_SINGLE_INCLUDE_CATCH_HPP_INCLUDED
16 #define CATCH_VERSION_MAJOR 2
17 #define CATCH_VERSION_MINOR 13
18 #define CATCH_VERSION_PATCH 10
21 # pragma clang system_header
22 #elif defined __GNUC__
23 # pragma GCC system_header
30 # pragma warning(push)
31 # pragma warning(disable: 161 1682)
33 # pragma clang diagnostic push
34 # pragma clang diagnostic ignored "-Wpadded"
35 # pragma clang diagnostic ignored "-Wswitch-enum"
36 # pragma clang diagnostic ignored "-Wcovered-switch-default"
38 #elif defined __GNUC__
42 # pragma GCC diagnostic ignored "-Wparentheses"
44 # pragma GCC diagnostic push
45 # pragma GCC diagnostic ignored "-Wunused-variable"
46 # pragma GCC diagnostic ignored "-Wpadded"
49 #if defined(CATCH_CONFIG_MAIN) || defined(CATCH_CONFIG_RUNNER)
51 # define CATCH_CONFIG_ALL_PARTS
56 #if defined(CATCH_CONFIG_ALL_PARTS)
57 # define CATCH_CONFIG_EXTERNAL_INTERFACES
58 # if defined(CATCH_CONFIG_DISABLE_MATCHERS)
59 # undef CATCH_CONFIG_DISABLE_MATCHERS
61 # if !defined(CATCH_CONFIG_ENABLE_CHRONO_STRINGMAKER)
62 # define CATCH_CONFIG_ENABLE_CHRONO_STRINGMAKER
66 #if !defined(CATCH_CONFIG_IMPL_ONLY)
72 # include <TargetConditionals.h>
73 # if (defined(TARGET_OS_OSX) && TARGET_OS_OSX == 1) || \
74 (defined(TARGET_OS_MAC) && TARGET_OS_MAC == 1)
75 # define CATCH_PLATFORM_MAC
76 # elif (defined(TARGET_OS_IPHONE) && TARGET_OS_IPHONE == 1)
77 # define CATCH_PLATFORM_IPHONE
80 #elif defined(linux) || defined(__linux) || defined(__linux__)
81 # define CATCH_PLATFORM_LINUX
83 #elif defined(WIN32) || defined(__WIN32__) || defined(_WIN32) || defined(_MSC_VER) || defined(__MINGW32__)
84 # define CATCH_PLATFORM_WINDOWS
90 # ifndef CLARA_CONFIG_MAIN
91 # define CLARA_CONFIG_MAIN_NOT_DEFINED
92 # define CLARA_CONFIG_MAIN
128 # if (__cplusplus >= 201402L) || (defined(_MSVC_LANG) && _MSVC_LANG >= 201402L)
129 # define CATCH_CPP14_OR_GREATER
132 # if (__cplusplus >= 201703L) || (defined(_MSVC_LANG) && _MSVC_LANG >= 201703L)
133 # define CATCH_CPP17_OR_GREATER
140 #if defined(__GNUC__) && !defined(__clang__) && !defined(__ICC) && !defined(__CUDACC__) && !defined(__LCC__)
141 # define CATCH_INTERNAL_START_WARNINGS_SUPPRESSION _Pragma( "GCC diagnostic push" )
142 # define CATCH_INTERNAL_STOP_WARNINGS_SUPPRESSION _Pragma( "GCC diagnostic pop" )
144 # define CATCH_INTERNAL_IGNORE_BUT_WARN(...) (void)__builtin_constant_p(__VA_ARGS__)
148 #if defined(__clang__)
150 # define CATCH_INTERNAL_START_WARNINGS_SUPPRESSION _Pragma( "clang diagnostic push" )
151 # define CATCH_INTERNAL_STOP_WARNINGS_SUPPRESSION _Pragma( "clang diagnostic pop" )
164 # if !defined(__ibmxl__) && !defined(__CUDACC__)
165 # define CATCH_INTERNAL_IGNORE_BUT_WARN(...) (void)__builtin_constant_p(__VA_ARGS__)
168 # define CATCH_INTERNAL_SUPPRESS_GLOBALS_WARNINGS \
169 _Pragma( "clang diagnostic ignored \"-Wexit-time-destructors\"" ) \
170 _Pragma( "clang diagnostic ignored \"-Wglobal-constructors\"")
172 # define CATCH_INTERNAL_SUPPRESS_PARENTHESES_WARNINGS \
173 _Pragma( "clang diagnostic ignored \"-Wparentheses\"" )
175 # define CATCH_INTERNAL_SUPPRESS_UNUSED_WARNINGS \
176 _Pragma( "clang diagnostic ignored \"-Wunused-variable\"" )
178 # define CATCH_INTERNAL_SUPPRESS_ZERO_VARIADIC_WARNINGS \
179 _Pragma( "clang diagnostic ignored \"-Wgnu-zero-variadic-macro-arguments\"" )
181 # define CATCH_INTERNAL_SUPPRESS_UNUSED_TEMPLATE_WARNINGS \
182 _Pragma( "clang diagnostic ignored \"-Wunused-template\"" )
188 #if !defined(CATCH_PLATFORM_WINDOWS)
189 #define CATCH_INTERNAL_CONFIG_POSIX_SIGNALS
194 #if defined(__CYGWIN__) || defined(__QNX__) || defined(__EMSCRIPTEN__) || defined(__DJGPP__)
195 #define CATCH_INTERNAL_CONFIG_NO_POSIX_SIGNALS
199 # define CATCH_INTERNAL_CONFIG_NO_POSIX_SIGNALS
200 # define CATCH_CONFIG_COLOUR_NONE
205 #if defined(__ANDROID__)
206 # define CATCH_INTERNAL_CONFIG_NO_CPP11_TO_STRING
207 # define CATCH_INTERNAL_CONFIG_ANDROID_LOGWRITE
212 #if defined(__MINGW32__)
213 # define CATCH_INTERNAL_CONFIG_NO_WINDOWS_SEH
218 #if defined(__ORBIS__)
219 # define CATCH_INTERNAL_CONFIG_NO_NEW_CAPTURE
231 # if !((__cplusplus >= 201103L) && defined(_GLIBCXX_USE_C99) \
232 && !defined(_GLIBCXX_HAVE_BROKEN_VSWPRINTF))
234 # define CATCH_INTERNAL_CONFIG_NO_CPP11_TO_STRING
241 #if defined(_MSC_VER)
245 # if defined(WINAPI_FAMILY) && (WINAPI_FAMILY == WINAPI_FAMILY_APP)
246 # define CATCH_CONFIG_COLOUR_NONE
248 # define CATCH_INTERNAL_CONFIG_WINDOWS_SEH
251 # if !defined(__clang__)
256 # if !defined(_MSVC_TRADITIONAL) || (defined(_MSVC_TRADITIONAL) && _MSVC_TRADITIONAL)
257 # define CATCH_INTERNAL_CONFIG_TRADITIONAL_MSVC_PREPROCESSOR
261 # define CATCH_INTERNAL_START_WARNINGS_SUPPRESSION __pragma( warning(push) )
262 # define CATCH_INTERNAL_STOP_WARNINGS_SUPPRESSION __pragma( warning(pop) )
267 #if defined(_REENTRANT) || defined(_MSC_VER)
269 # define CATCH_INTERNAL_CONFIG_USE_ASYNC
274 #if defined(__EXCEPTIONS) || defined(__cpp_exceptions) || defined(_CPPUNWIND)
275 # define CATCH_INTERNAL_CONFIG_EXCEPTIONS_ENABLED
281 # define CATCH_INTERNAL_CONFIG_NO_WCHAR
286 #if defined(__BORLANDC__)
287 #define CATCH_INTERNAL_CONFIG_POLYFILL_ISNAN
297 #if ( !defined(__JETBRAINS_IDE__) || __JETBRAINS_IDE__ >= 20170300L )
298 #define CATCH_INTERNAL_CONFIG_COUNTER
306 #if defined(UNDER_RTSS) || defined(RTX64_BUILD)
307 #define CATCH_INTERNAL_CONFIG_NO_WINDOWS_SEH
308 #define CATCH_INTERNAL_CONFIG_NO_ASYNC
309 #define CATCH_CONFIG_COLOUR_NONE
312 #if !defined(_GLIBCXX_USE_C99_MATH_TR1)
313 #define CATCH_INTERNAL_CONFIG_GLOBAL_NEXTAFTER
317 #if defined(__has_include)
319 #if __has_include(<string_view>) && defined(CATCH_CPP17_OR_GREATER)
320 # define CATCH_INTERNAL_CONFIG_CPP17_STRING_VIEW
324 # if __has_include(<optional>) && defined(CATCH_CPP17_OR_GREATER)
325 # define CATCH_INTERNAL_CONFIG_CPP17_OPTIONAL
329 # if __has_include(<cstddef>) && defined(CATCH_CPP17_OR_GREATER)
331 # if defined(__cpp_lib_byte) && (__cpp_lib_byte > 0)
332 # define CATCH_INTERNAL_CONFIG_CPP17_BYTE
337 # if __has_include(<variant>) && defined(CATCH_CPP17_OR_GREATER)
338 # if defined(__clang__) && (__clang_major__ < 8)
342 # if defined(__GLIBCXX__) && defined(_GLIBCXX_RELEASE) && (_GLIBCXX_RELEASE < 9)
343 # define CATCH_CONFIG_NO_CPP17_VARIANT
345 # define CATCH_INTERNAL_CONFIG_CPP17_VARIANT
348 # define CATCH_INTERNAL_CONFIG_CPP17_VARIANT
353 #if defined(CATCH_INTERNAL_CONFIG_COUNTER) && !defined(CATCH_CONFIG_NO_COUNTER) && !defined(CATCH_CONFIG_COUNTER)
354 # define CATCH_CONFIG_COUNTER
356 #if defined(CATCH_INTERNAL_CONFIG_WINDOWS_SEH) && !defined(CATCH_CONFIG_NO_WINDOWS_SEH) && !defined(CATCH_CONFIG_WINDOWS_SEH) && !defined(CATCH_INTERNAL_CONFIG_NO_WINDOWS_SEH)
357 # define CATCH_CONFIG_WINDOWS_SEH
360 #if defined(CATCH_INTERNAL_CONFIG_POSIX_SIGNALS) && !defined(CATCH_INTERNAL_CONFIG_NO_POSIX_SIGNALS) && !defined(CATCH_CONFIG_NO_POSIX_SIGNALS) && !defined(CATCH_CONFIG_POSIX_SIGNALS)
361 # define CATCH_CONFIG_POSIX_SIGNALS
364 #if !defined(CATCH_INTERNAL_CONFIG_NO_WCHAR) && !defined(CATCH_CONFIG_NO_WCHAR) && !defined(CATCH_CONFIG_WCHAR)
365 # define CATCH_CONFIG_WCHAR
368 #if !defined(CATCH_INTERNAL_CONFIG_NO_CPP11_TO_STRING) && !defined(CATCH_CONFIG_NO_CPP11_TO_STRING) && !defined(CATCH_CONFIG_CPP11_TO_STRING)
369 # define CATCH_CONFIG_CPP11_TO_STRING
372 #if defined(CATCH_INTERNAL_CONFIG_CPP17_OPTIONAL) && !defined(CATCH_CONFIG_NO_CPP17_OPTIONAL) && !defined(CATCH_CONFIG_CPP17_OPTIONAL)
373 # define CATCH_CONFIG_CPP17_OPTIONAL
376 #if defined(CATCH_INTERNAL_CONFIG_CPP17_STRING_VIEW) && !defined(CATCH_CONFIG_NO_CPP17_STRING_VIEW) && !defined(CATCH_CONFIG_CPP17_STRING_VIEW)
377 # define CATCH_CONFIG_CPP17_STRING_VIEW
380 #if defined(CATCH_INTERNAL_CONFIG_CPP17_VARIANT) && !defined(CATCH_CONFIG_NO_CPP17_VARIANT) && !defined(CATCH_CONFIG_CPP17_VARIANT)
381 # define CATCH_CONFIG_CPP17_VARIANT
384 #if defined(CATCH_INTERNAL_CONFIG_CPP17_BYTE) && !defined(CATCH_CONFIG_NO_CPP17_BYTE) && !defined(CATCH_CONFIG_CPP17_BYTE)
385 # define CATCH_CONFIG_CPP17_BYTE
388 #if defined(CATCH_CONFIG_EXPERIMENTAL_REDIRECT)
389 # define CATCH_INTERNAL_CONFIG_NEW_CAPTURE
392 #if defined(CATCH_INTERNAL_CONFIG_NEW_CAPTURE) && !defined(CATCH_INTERNAL_CONFIG_NO_NEW_CAPTURE) && !defined(CATCH_CONFIG_NO_NEW_CAPTURE) && !defined(CATCH_CONFIG_NEW_CAPTURE)
393 # define CATCH_CONFIG_NEW_CAPTURE
396 #if !defined(CATCH_INTERNAL_CONFIG_EXCEPTIONS_ENABLED) && !defined(CATCH_CONFIG_DISABLE_EXCEPTIONS)
397 # define CATCH_CONFIG_DISABLE_EXCEPTIONS
400 #if defined(CATCH_INTERNAL_CONFIG_POLYFILL_ISNAN) && !defined(CATCH_CONFIG_NO_POLYFILL_ISNAN) && !defined(CATCH_CONFIG_POLYFILL_ISNAN)
401 # define CATCH_CONFIG_POLYFILL_ISNAN
404 #if defined(CATCH_INTERNAL_CONFIG_USE_ASYNC) && !defined(CATCH_INTERNAL_CONFIG_NO_ASYNC) && !defined(CATCH_CONFIG_NO_USE_ASYNC) && !defined(CATCH_CONFIG_USE_ASYNC)
405 # define CATCH_CONFIG_USE_ASYNC
408 #if defined(CATCH_INTERNAL_CONFIG_ANDROID_LOGWRITE) && !defined(CATCH_CONFIG_NO_ANDROID_LOGWRITE) && !defined(CATCH_CONFIG_ANDROID_LOGWRITE)
409 # define CATCH_CONFIG_ANDROID_LOGWRITE
412 #if defined(CATCH_INTERNAL_CONFIG_GLOBAL_NEXTAFTER) && !defined(CATCH_CONFIG_NO_GLOBAL_NEXTAFTER) && !defined(CATCH_CONFIG_GLOBAL_NEXTAFTER)
413 # define CATCH_CONFIG_GLOBAL_NEXTAFTER
418 #if !defined(CATCH_INTERNAL_START_WARNINGS_SUPPRESSION)
419 # define CATCH_INTERNAL_START_WARNINGS_SUPPRESSION
421 #if !defined(CATCH_INTERNAL_STOP_WARNINGS_SUPPRESSION)
422 # define CATCH_INTERNAL_STOP_WARNINGS_SUPPRESSION
424 #if !defined(CATCH_INTERNAL_SUPPRESS_PARENTHESES_WARNINGS)
425 # define CATCH_INTERNAL_SUPPRESS_PARENTHESES_WARNINGS
427 #if !defined(CATCH_INTERNAL_SUPPRESS_GLOBALS_WARNINGS)
428 # define CATCH_INTERNAL_SUPPRESS_GLOBALS_WARNINGS
430 #if !defined(CATCH_INTERNAL_SUPPRESS_UNUSED_WARNINGS)
431 # define CATCH_INTERNAL_SUPPRESS_UNUSED_WARNINGS
433 #if !defined(CATCH_INTERNAL_SUPPRESS_ZERO_VARIADIC_WARNINGS)
434 # define CATCH_INTERNAL_SUPPRESS_ZERO_VARIADIC_WARNINGS
439 #if !defined(CATCH_INTERNAL_IGNORE_BUT_WARN)
440 # define CATCH_INTERNAL_IGNORE_BUT_WARN(...)
443 #if defined(__APPLE__) && defined(__apple_build_version__) && (__clang_major__ < 10)
444 # undef CATCH_INTERNAL_SUPPRESS_UNUSED_TEMPLATE_WARNINGS
445 #elif defined(__clang__) && (__clang_major__ < 5)
446 # undef CATCH_INTERNAL_SUPPRESS_UNUSED_TEMPLATE_WARNINGS
449 #if !defined(CATCH_INTERNAL_SUPPRESS_UNUSED_TEMPLATE_WARNINGS)
450 # define CATCH_INTERNAL_SUPPRESS_UNUSED_TEMPLATE_WARNINGS
453 #if defined(CATCH_CONFIG_DISABLE_EXCEPTIONS)
454 #define CATCH_TRY if ((true))
455 #define CATCH_CATCH_ALL if ((false))
456 #define CATCH_CATCH_ANON(type) if ((false))
458 #define CATCH_TRY try
459 #define CATCH_CATCH_ALL catch (...)
460 #define CATCH_CATCH_ANON(type) catch (type)
463 #if defined(CATCH_INTERNAL_CONFIG_TRADITIONAL_MSVC_PREPROCESSOR) && !defined(CATCH_CONFIG_NO_TRADITIONAL_MSVC_PREPROCESSOR) && !defined(CATCH_CONFIG_TRADITIONAL_MSVC_PREPROCESSOR)
464 #define CATCH_CONFIG_TRADITIONAL_MSVC_PREPROCESSOR
468 #define INTERNAL_CATCH_UNIQUE_NAME_LINE2( name, line ) name##line
469 #define INTERNAL_CATCH_UNIQUE_NAME_LINE( name, line ) INTERNAL_CATCH_UNIQUE_NAME_LINE2( name, line )
470 #ifdef CATCH_CONFIG_COUNTER
471 # define INTERNAL_CATCH_UNIQUE_NAME( name ) INTERNAL_CATCH_UNIQUE_NAME_LINE( name, __COUNTER__ )
473 # define INTERNAL_CATCH_UNIQUE_NAME( name ) INTERNAL_CATCH_UNIQUE_NAME_LINE( name, __LINE__ )
543 #define CATCH_INTERNAL_LINEINFO \
544 ::Catch::SourceLineInfo( __FILE__, static_cast<std::size_t>( __LINE__ ) )
555 #define CATCH_REGISTER_TAG_ALIAS( alias, spec ) \
556 CATCH_INTERNAL_START_WARNINGS_SUPPRESSION \
557 CATCH_INTERNAL_SUPPRESS_GLOBALS_WARNINGS \
558 namespace{ Catch::RegistrarForTagAliases INTERNAL_CATCH_UNIQUE_NAME( AutoRegisterTagAlias )( alias, spec, CATCH_INTERNAL_LINEINFO ); } \
559 CATCH_INTERNAL_STOP_WARNINGS_SUPPRESSION
588 std::vector<TestCase>
filterTests( std::vector<TestCase>
const& testCases, TestSpec
const& testSpec,
IConfig const& config );
612 static constexpr
char const*
const s_empty =
"";
628 :
m_start( stdString.c_str() ),
629 m_size( stdString.size() )
632 explicit operator std::string()
const {
639 return !(*
this == other);
648 constexpr
auto empty() const noexcept ->
bool {
666 auto
data() const noexcept ->
char const*;
680 constexpr
auto operator "" _sr(
char const* rawChars, std::size_t size ) noexcept ->
StringRef {
685 constexpr
auto operator "" _catch_sr(
char const* rawChars, std::size_t size ) noexcept ->
Catch::StringRef {
693 #define CATCH_RECURSION_LEVEL0(...) __VA_ARGS__
694 #define CATCH_RECURSION_LEVEL1(...) CATCH_RECURSION_LEVEL0(CATCH_RECURSION_LEVEL0(CATCH_RECURSION_LEVEL0(__VA_ARGS__)))
695 #define CATCH_RECURSION_LEVEL2(...) CATCH_RECURSION_LEVEL1(CATCH_RECURSION_LEVEL1(CATCH_RECURSION_LEVEL1(__VA_ARGS__)))
696 #define CATCH_RECURSION_LEVEL3(...) CATCH_RECURSION_LEVEL2(CATCH_RECURSION_LEVEL2(CATCH_RECURSION_LEVEL2(__VA_ARGS__)))
697 #define CATCH_RECURSION_LEVEL4(...) CATCH_RECURSION_LEVEL3(CATCH_RECURSION_LEVEL3(CATCH_RECURSION_LEVEL3(__VA_ARGS__)))
698 #define CATCH_RECURSION_LEVEL5(...) CATCH_RECURSION_LEVEL4(CATCH_RECURSION_LEVEL4(CATCH_RECURSION_LEVEL4(__VA_ARGS__)))
700 #ifdef CATCH_CONFIG_TRADITIONAL_MSVC_PREPROCESSOR
701 #define INTERNAL_CATCH_EXPAND_VARGS(...) __VA_ARGS__
703 #define CATCH_RECURSION_LEVEL6(...) CATCH_RECURSION_LEVEL5(CATCH_RECURSION_LEVEL5(CATCH_RECURSION_LEVEL5(__VA_ARGS__)))
704 #define CATCH_RECURSE(...) CATCH_RECURSION_LEVEL6(CATCH_RECURSION_LEVEL6(__VA_ARGS__))
706 #define CATCH_RECURSE(...) CATCH_RECURSION_LEVEL5(__VA_ARGS__)
709 #define CATCH_REC_END(...)
710 #define CATCH_REC_OUT
712 #define CATCH_EMPTY()
713 #define CATCH_DEFER(id) id CATCH_EMPTY()
715 #define CATCH_REC_GET_END2() 0, CATCH_REC_END
716 #define CATCH_REC_GET_END1(...) CATCH_REC_GET_END2
717 #define CATCH_REC_GET_END(...) CATCH_REC_GET_END1
718 #define CATCH_REC_NEXT0(test, next, ...) next CATCH_REC_OUT
719 #define CATCH_REC_NEXT1(test, next) CATCH_DEFER ( CATCH_REC_NEXT0 ) ( test, next, 0)
720 #define CATCH_REC_NEXT(test, next) CATCH_REC_NEXT1(CATCH_REC_GET_END test, next)
722 #define CATCH_REC_LIST0(f, x, peek, ...) , f(x) CATCH_DEFER ( CATCH_REC_NEXT(peek, CATCH_REC_LIST1) ) ( f, peek, __VA_ARGS__ )
723 #define CATCH_REC_LIST1(f, x, peek, ...) , f(x) CATCH_DEFER ( CATCH_REC_NEXT(peek, CATCH_REC_LIST0) ) ( f, peek, __VA_ARGS__ )
724 #define CATCH_REC_LIST2(f, x, peek, ...) f(x) CATCH_DEFER ( CATCH_REC_NEXT(peek, CATCH_REC_LIST1) ) ( f, peek, __VA_ARGS__ )
726 #define CATCH_REC_LIST0_UD(f, userdata, x, peek, ...) , f(userdata, x) CATCH_DEFER ( CATCH_REC_NEXT(peek, CATCH_REC_LIST1_UD) ) ( f, userdata, peek, __VA_ARGS__ )
727 #define CATCH_REC_LIST1_UD(f, userdata, x, peek, ...) , f(userdata, x) CATCH_DEFER ( CATCH_REC_NEXT(peek, CATCH_REC_LIST0_UD) ) ( f, userdata, peek, __VA_ARGS__ )
728 #define CATCH_REC_LIST2_UD(f, userdata, x, peek, ...) f(userdata, x) CATCH_DEFER ( CATCH_REC_NEXT(peek, CATCH_REC_LIST1_UD) ) ( f, userdata, peek, __VA_ARGS__ )
733 #define CATCH_REC_LIST_UD(f, userdata, ...) CATCH_RECURSE(CATCH_REC_LIST2_UD(f, userdata, __VA_ARGS__, ()()(), ()()(), ()()(), 0))
735 #define CATCH_REC_LIST(f, ...) CATCH_RECURSE(CATCH_REC_LIST2(f, __VA_ARGS__, ()()(), ()()(), ()()(), 0))
737 #define INTERNAL_CATCH_EXPAND1(param) INTERNAL_CATCH_EXPAND2(param)
738 #define INTERNAL_CATCH_EXPAND2(...) INTERNAL_CATCH_NO## __VA_ARGS__
739 #define INTERNAL_CATCH_DEF(...) INTERNAL_CATCH_DEF __VA_ARGS__
740 #define INTERNAL_CATCH_NOINTERNAL_CATCH_DEF
741 #define INTERNAL_CATCH_STRINGIZE(...) INTERNAL_CATCH_STRINGIZE2(__VA_ARGS__)
742 #ifndef CATCH_CONFIG_TRADITIONAL_MSVC_PREPROCESSOR
743 #define INTERNAL_CATCH_STRINGIZE2(...) #__VA_ARGS__
744 #define INTERNAL_CATCH_STRINGIZE_WITHOUT_PARENS(param) INTERNAL_CATCH_STRINGIZE(INTERNAL_CATCH_REMOVE_PARENS(param))
747 #define INTERNAL_CATCH_STRINGIZE2(...) INTERNAL_CATCH_STRINGIZE3(__VA_ARGS__)
748 #define INTERNAL_CATCH_STRINGIZE3(...) #__VA_ARGS__
749 #define INTERNAL_CATCH_STRINGIZE_WITHOUT_PARENS(param) (INTERNAL_CATCH_STRINGIZE(INTERNAL_CATCH_REMOVE_PARENS(param)) + 1)
752 #define INTERNAL_CATCH_MAKE_NAMESPACE2(...) ns_##__VA_ARGS__
753 #define INTERNAL_CATCH_MAKE_NAMESPACE(name) INTERNAL_CATCH_MAKE_NAMESPACE2(name)
755 #define INTERNAL_CATCH_REMOVE_PARENS(...) INTERNAL_CATCH_EXPAND1(INTERNAL_CATCH_DEF __VA_ARGS__)
757 #ifndef CATCH_CONFIG_TRADITIONAL_MSVC_PREPROCESSOR
758 #define INTERNAL_CATCH_MAKE_TYPE_LIST2(...) decltype(get_wrapper<INTERNAL_CATCH_REMOVE_PARENS_GEN(__VA_ARGS__)>())
759 #define INTERNAL_CATCH_MAKE_TYPE_LIST(...) INTERNAL_CATCH_MAKE_TYPE_LIST2(INTERNAL_CATCH_REMOVE_PARENS(__VA_ARGS__))
761 #define INTERNAL_CATCH_MAKE_TYPE_LIST2(...) INTERNAL_CATCH_EXPAND_VARGS(decltype(get_wrapper<INTERNAL_CATCH_REMOVE_PARENS_GEN(__VA_ARGS__)>()))
762 #define INTERNAL_CATCH_MAKE_TYPE_LIST(...) INTERNAL_CATCH_EXPAND_VARGS(INTERNAL_CATCH_MAKE_TYPE_LIST2(INTERNAL_CATCH_REMOVE_PARENS(__VA_ARGS__)))
765 #define INTERNAL_CATCH_MAKE_TYPE_LISTS_FROM_TYPES(...)\
766 CATCH_REC_LIST(INTERNAL_CATCH_MAKE_TYPE_LIST,__VA_ARGS__)
768 #define INTERNAL_CATCH_REMOVE_PARENS_1_ARG(_0) INTERNAL_CATCH_REMOVE_PARENS(_0)
769 #define INTERNAL_CATCH_REMOVE_PARENS_2_ARG(_0, _1) INTERNAL_CATCH_REMOVE_PARENS(_0), INTERNAL_CATCH_REMOVE_PARENS_1_ARG(_1)
770 #define INTERNAL_CATCH_REMOVE_PARENS_3_ARG(_0, _1, _2) INTERNAL_CATCH_REMOVE_PARENS(_0), INTERNAL_CATCH_REMOVE_PARENS_2_ARG(_1, _2)
771 #define INTERNAL_CATCH_REMOVE_PARENS_4_ARG(_0, _1, _2, _3) INTERNAL_CATCH_REMOVE_PARENS(_0), INTERNAL_CATCH_REMOVE_PARENS_3_ARG(_1, _2, _3)
772 #define INTERNAL_CATCH_REMOVE_PARENS_5_ARG(_0, _1, _2, _3, _4) INTERNAL_CATCH_REMOVE_PARENS(_0), INTERNAL_CATCH_REMOVE_PARENS_4_ARG(_1, _2, _3, _4)
773 #define INTERNAL_CATCH_REMOVE_PARENS_6_ARG(_0, _1, _2, _3, _4, _5) INTERNAL_CATCH_REMOVE_PARENS(_0), INTERNAL_CATCH_REMOVE_PARENS_5_ARG(_1, _2, _3, _4, _5)
774 #define INTERNAL_CATCH_REMOVE_PARENS_7_ARG(_0, _1, _2, _3, _4, _5, _6) INTERNAL_CATCH_REMOVE_PARENS(_0), INTERNAL_CATCH_REMOVE_PARENS_6_ARG(_1, _2, _3, _4, _5, _6)
775 #define INTERNAL_CATCH_REMOVE_PARENS_8_ARG(_0, _1, _2, _3, _4, _5, _6, _7) INTERNAL_CATCH_REMOVE_PARENS(_0), INTERNAL_CATCH_REMOVE_PARENS_7_ARG(_1, _2, _3, _4, _5, _6, _7)
776 #define INTERNAL_CATCH_REMOVE_PARENS_9_ARG(_0, _1, _2, _3, _4, _5, _6, _7, _8) INTERNAL_CATCH_REMOVE_PARENS(_0), INTERNAL_CATCH_REMOVE_PARENS_8_ARG(_1, _2, _3, _4, _5, _6, _7, _8)
777 #define INTERNAL_CATCH_REMOVE_PARENS_10_ARG(_0, _1, _2, _3, _4, _5, _6, _7, _8, _9) INTERNAL_CATCH_REMOVE_PARENS(_0), INTERNAL_CATCH_REMOVE_PARENS_9_ARG(_1, _2, _3, _4, _5, _6, _7, _8, _9)
778 #define INTERNAL_CATCH_REMOVE_PARENS_11_ARG(_0, _1, _2, _3, _4, _5, _6, _7, _8, _9, _10) INTERNAL_CATCH_REMOVE_PARENS(_0), INTERNAL_CATCH_REMOVE_PARENS_10_ARG(_1, _2, _3, _4, _5, _6, _7, _8, _9, _10)
780 #define INTERNAL_CATCH_VA_NARGS_IMPL(_0, _1, _2, _3, _4, _5, _6, _7, _8, _9, _10, N, ...) N
782 #define INTERNAL_CATCH_TYPE_GEN\
783 template<typename...> struct TypeList {};\
784 template<typename...Ts>\
785 constexpr auto get_wrapper() noexcept -> TypeList<Ts...> { return {}; }\
786 template<template<typename...> class...> struct TemplateTypeList{};\
787 template<template<typename...> class...Cs>\
788 constexpr auto get_wrapper() noexcept -> TemplateTypeList<Cs...> { return {}; }\
789 template<typename...>\
791 template<typename...>\
793 template<template<typename...> class, typename...>\
795 template<template<typename...> class, typename>\
798 template<typename T> \
799 struct append<T> { using type = T; };\
800 template< template<typename...> class L1, typename...E1, template<typename...> class L2, typename...E2, typename...Rest>\
801 struct append<L1<E1...>, L2<E2...>, Rest...> { using type = typename append<L1<E1...,E2...>, Rest...>::type; };\
802 template< template<typename...> class L1, typename...E1, typename...Rest>\
803 struct append<L1<E1...>, TypeList<mpl_::na>, Rest...> { using type = L1<E1...>; };\
805 template< template<typename...> class Container, template<typename...> class List, typename...elems>\
806 struct rewrap<TemplateTypeList<Container>, List<elems...>> { using type = TypeList<Container<elems...>>; };\
807 template< template<typename...> class Container, template<typename...> class List, class...Elems, typename...Elements>\
808 struct rewrap<TemplateTypeList<Container>, List<Elems...>, Elements...> { using type = typename append<TypeList<Container<Elems...>>, typename rewrap<TemplateTypeList<Container>, Elements...>::type>::type; };\
810 template<template <typename...> class Final, template< typename...> class...Containers, typename...Types>\
811 struct create<Final, TemplateTypeList<Containers...>, TypeList<Types...>> { using type = typename append<Final<>, typename rewrap<TemplateTypeList<Containers>, Types...>::type...>::type; };\
812 template<template <typename...> class Final, template <typename...> class List, typename...Ts>\
813 struct convert<Final, List<Ts...>> { using type = typename append<Final<>,TypeList<Ts>...>::type; };
815 #define INTERNAL_CATCH_NTTP_1(signature, ...)\
816 template<INTERNAL_CATCH_REMOVE_PARENS(signature)> struct Nttp{};\
817 template<INTERNAL_CATCH_REMOVE_PARENS(signature)>\
818 constexpr auto get_wrapper() noexcept -> Nttp<__VA_ARGS__> { return {}; } \
819 template<template<INTERNAL_CATCH_REMOVE_PARENS(signature)> class...> struct NttpTemplateTypeList{};\
820 template<template<INTERNAL_CATCH_REMOVE_PARENS(signature)> class...Cs>\
821 constexpr auto get_wrapper() noexcept -> NttpTemplateTypeList<Cs...> { return {}; } \
823 template< template<INTERNAL_CATCH_REMOVE_PARENS(signature)> class Container, template<INTERNAL_CATCH_REMOVE_PARENS(signature)> class List, INTERNAL_CATCH_REMOVE_PARENS(signature)>\
824 struct rewrap<NttpTemplateTypeList<Container>, List<__VA_ARGS__>> { using type = TypeList<Container<__VA_ARGS__>>; };\
825 template< template<INTERNAL_CATCH_REMOVE_PARENS(signature)> class Container, template<INTERNAL_CATCH_REMOVE_PARENS(signature)> class List, INTERNAL_CATCH_REMOVE_PARENS(signature), typename...Elements>\
826 struct rewrap<NttpTemplateTypeList<Container>, List<__VA_ARGS__>, Elements...> { using type = typename append<TypeList<Container<__VA_ARGS__>>, typename rewrap<NttpTemplateTypeList<Container>, Elements...>::type>::type; };\
827 template<template <typename...> class Final, template<INTERNAL_CATCH_REMOVE_PARENS(signature)> class...Containers, typename...Types>\
828 struct create<Final, NttpTemplateTypeList<Containers...>, TypeList<Types...>> { using type = typename append<Final<>, typename rewrap<NttpTemplateTypeList<Containers>, Types...>::type...>::type; };
830 #define INTERNAL_CATCH_DECLARE_SIG_TEST0(TestName)
831 #define INTERNAL_CATCH_DECLARE_SIG_TEST1(TestName, signature)\
832 template<INTERNAL_CATCH_REMOVE_PARENS(signature)>\
833 static void TestName()
834 #define INTERNAL_CATCH_DECLARE_SIG_TEST_X(TestName, signature, ...)\
835 template<INTERNAL_CATCH_REMOVE_PARENS(signature)>\
836 static void TestName()
838 #define INTERNAL_CATCH_DEFINE_SIG_TEST0(TestName)
839 #define INTERNAL_CATCH_DEFINE_SIG_TEST1(TestName, signature)\
840 template<INTERNAL_CATCH_REMOVE_PARENS(signature)>\
841 static void TestName()
842 #define INTERNAL_CATCH_DEFINE_SIG_TEST_X(TestName, signature,...)\
843 template<INTERNAL_CATCH_REMOVE_PARENS(signature)>\
844 static void TestName()
846 #define INTERNAL_CATCH_NTTP_REGISTER0(TestFunc, signature)\
847 template<typename Type>\
848 void reg_test(TypeList<Type>, Catch::NameAndTags nameAndTags)\
850 Catch::AutoReg( Catch::makeTestInvoker(&TestFunc<Type>), CATCH_INTERNAL_LINEINFO, Catch::StringRef(), nameAndTags);\
853 #define INTERNAL_CATCH_NTTP_REGISTER(TestFunc, signature, ...)\
854 template<INTERNAL_CATCH_REMOVE_PARENS(signature)>\
855 void reg_test(Nttp<__VA_ARGS__>, Catch::NameAndTags nameAndTags)\
857 Catch::AutoReg( Catch::makeTestInvoker(&TestFunc<__VA_ARGS__>), CATCH_INTERNAL_LINEINFO, Catch::StringRef(), nameAndTags);\
860 #define INTERNAL_CATCH_NTTP_REGISTER_METHOD0(TestName, signature, ...)\
861 template<typename Type>\
862 void reg_test(TypeList<Type>, Catch::StringRef className, Catch::NameAndTags nameAndTags)\
864 Catch::AutoReg( Catch::makeTestInvoker(&TestName<Type>::test), CATCH_INTERNAL_LINEINFO, className, nameAndTags);\
867 #define INTERNAL_CATCH_NTTP_REGISTER_METHOD(TestName, signature, ...)\
868 template<INTERNAL_CATCH_REMOVE_PARENS(signature)>\
869 void reg_test(Nttp<__VA_ARGS__>, Catch::StringRef className, Catch::NameAndTags nameAndTags)\
871 Catch::AutoReg( Catch::makeTestInvoker(&TestName<__VA_ARGS__>::test), CATCH_INTERNAL_LINEINFO, className, nameAndTags);\
874 #define INTERNAL_CATCH_DECLARE_SIG_TEST_METHOD0(TestName, ClassName)
875 #define INTERNAL_CATCH_DECLARE_SIG_TEST_METHOD1(TestName, ClassName, signature)\
876 template<typename TestType> \
877 struct TestName : INTERNAL_CATCH_REMOVE_PARENS(ClassName)<TestType> { \
881 #define INTERNAL_CATCH_DECLARE_SIG_TEST_METHOD_X(TestName, ClassName, signature, ...)\
882 template<INTERNAL_CATCH_REMOVE_PARENS(signature)> \
883 struct TestName : INTERNAL_CATCH_REMOVE_PARENS(ClassName)<__VA_ARGS__> { \
887 #define INTERNAL_CATCH_DEFINE_SIG_TEST_METHOD0(TestName)
888 #define INTERNAL_CATCH_DEFINE_SIG_TEST_METHOD1(TestName, signature)\
889 template<typename TestType> \
890 void INTERNAL_CATCH_MAKE_NAMESPACE(TestName)::TestName<TestType>::test()
891 #define INTERNAL_CATCH_DEFINE_SIG_TEST_METHOD_X(TestName, signature, ...)\
892 template<INTERNAL_CATCH_REMOVE_PARENS(signature)> \
893 void INTERNAL_CATCH_MAKE_NAMESPACE(TestName)::TestName<__VA_ARGS__>::test()
895 #ifndef CATCH_CONFIG_TRADITIONAL_MSVC_PREPROCESSOR
896 #define INTERNAL_CATCH_NTTP_0
897 #define INTERNAL_CATCH_NTTP_GEN(...) INTERNAL_CATCH_VA_NARGS_IMPL(__VA_ARGS__, INTERNAL_CATCH_NTTP_1(__VA_ARGS__), INTERNAL_CATCH_NTTP_1(__VA_ARGS__), INTERNAL_CATCH_NTTP_1(__VA_ARGS__), INTERNAL_CATCH_NTTP_1(__VA_ARGS__), INTERNAL_CATCH_NTTP_1(__VA_ARGS__), INTERNAL_CATCH_NTTP_1( __VA_ARGS__), INTERNAL_CATCH_NTTP_1( __VA_ARGS__), INTERNAL_CATCH_NTTP_1( __VA_ARGS__), INTERNAL_CATCH_NTTP_1( __VA_ARGS__),INTERNAL_CATCH_NTTP_1( __VA_ARGS__), INTERNAL_CATCH_NTTP_0)
898 #define INTERNAL_CATCH_DEFINE_SIG_TEST_METHOD(TestName, ...) INTERNAL_CATCH_VA_NARGS_IMPL( "dummy", __VA_ARGS__, INTERNAL_CATCH_DEFINE_SIG_TEST_METHOD_X,INTERNAL_CATCH_DEFINE_SIG_TEST_METHOD_X, INTERNAL_CATCH_DEFINE_SIG_TEST_METHOD_X, INTERNAL_CATCH_DEFINE_SIG_TEST_METHOD_X, INTERNAL_CATCH_DEFINE_SIG_TEST_METHOD_X, INTERNAL_CATCH_DEFINE_SIG_TEST_METHOD_X, INTERNAL_CATCH_DEFINE_SIG_TEST_METHOD_X,INTERNAL_CATCH_DEFINE_SIG_TEST_METHOD_X,INTERNAL_CATCH_DEFINE_SIG_TEST_METHOD_X, INTERNAL_CATCH_DEFINE_SIG_TEST_METHOD1, INTERNAL_CATCH_DEFINE_SIG_TEST_METHOD0)(TestName, __VA_ARGS__)
899 #define INTERNAL_CATCH_DECLARE_SIG_TEST_METHOD(TestName, ClassName, ...) INTERNAL_CATCH_VA_NARGS_IMPL( "dummy", __VA_ARGS__, INTERNAL_CATCH_DECLARE_SIG_TEST_METHOD_X,INTERNAL_CATCH_DECLARE_SIG_TEST_METHOD_X, INTERNAL_CATCH_DECLARE_SIG_TEST_METHOD_X, INTERNAL_CATCH_DECLARE_SIG_TEST_METHOD_X, INTERNAL_CATCH_DECLARE_SIG_TEST_METHOD_X, INTERNAL_CATCH_DECLARE_SIG_TEST_METHOD_X, INTERNAL_CATCH_DECLARE_SIG_TEST_METHOD_X,INTERNAL_CATCH_DECLARE_SIG_TEST_METHOD_X,INTERNAL_CATCH_DECLARE_SIG_TEST_METHOD_X, INTERNAL_CATCH_DECLARE_SIG_TEST_METHOD1, INTERNAL_CATCH_DECLARE_SIG_TEST_METHOD0)(TestName, ClassName, __VA_ARGS__)
900 #define INTERNAL_CATCH_NTTP_REG_METHOD_GEN(TestName, ...) INTERNAL_CATCH_VA_NARGS_IMPL( "dummy", __VA_ARGS__, INTERNAL_CATCH_NTTP_REGISTER_METHOD, INTERNAL_CATCH_NTTP_REGISTER_METHOD, INTERNAL_CATCH_NTTP_REGISTER_METHOD, INTERNAL_CATCH_NTTP_REGISTER_METHOD, INTERNAL_CATCH_NTTP_REGISTER_METHOD, INTERNAL_CATCH_NTTP_REGISTER_METHOD, INTERNAL_CATCH_NTTP_REGISTER_METHOD, INTERNAL_CATCH_NTTP_REGISTER_METHOD, INTERNAL_CATCH_NTTP_REGISTER_METHOD, INTERNAL_CATCH_NTTP_REGISTER_METHOD0, INTERNAL_CATCH_NTTP_REGISTER_METHOD0)(TestName, __VA_ARGS__)
901 #define INTERNAL_CATCH_NTTP_REG_GEN(TestFunc, ...) INTERNAL_CATCH_VA_NARGS_IMPL( "dummy", __VA_ARGS__, INTERNAL_CATCH_NTTP_REGISTER, INTERNAL_CATCH_NTTP_REGISTER, INTERNAL_CATCH_NTTP_REGISTER, INTERNAL_CATCH_NTTP_REGISTER, INTERNAL_CATCH_NTTP_REGISTER, INTERNAL_CATCH_NTTP_REGISTER, INTERNAL_CATCH_NTTP_REGISTER, INTERNAL_CATCH_NTTP_REGISTER, INTERNAL_CATCH_NTTP_REGISTER, INTERNAL_CATCH_NTTP_REGISTER0, INTERNAL_CATCH_NTTP_REGISTER0)(TestFunc, __VA_ARGS__)
902 #define INTERNAL_CATCH_DEFINE_SIG_TEST(TestName, ...) INTERNAL_CATCH_VA_NARGS_IMPL( "dummy", __VA_ARGS__, INTERNAL_CATCH_DEFINE_SIG_TEST_X, INTERNAL_CATCH_DEFINE_SIG_TEST_X, INTERNAL_CATCH_DEFINE_SIG_TEST_X, INTERNAL_CATCH_DEFINE_SIG_TEST_X, INTERNAL_CATCH_DEFINE_SIG_TEST_X, INTERNAL_CATCH_DEFINE_SIG_TEST_X, INTERNAL_CATCH_DEFINE_SIG_TEST_X, INTERNAL_CATCH_DEFINE_SIG_TEST_X,INTERNAL_CATCH_DEFINE_SIG_TEST_X,INTERNAL_CATCH_DEFINE_SIG_TEST1, INTERNAL_CATCH_DEFINE_SIG_TEST0)(TestName, __VA_ARGS__)
903 #define INTERNAL_CATCH_DECLARE_SIG_TEST(TestName, ...) INTERNAL_CATCH_VA_NARGS_IMPL( "dummy", __VA_ARGS__, INTERNAL_CATCH_DECLARE_SIG_TEST_X,INTERNAL_CATCH_DECLARE_SIG_TEST_X, INTERNAL_CATCH_DECLARE_SIG_TEST_X, INTERNAL_CATCH_DECLARE_SIG_TEST_X, INTERNAL_CATCH_DECLARE_SIG_TEST_X, INTERNAL_CATCH_DECLARE_SIG_TEST_X, INTERNAL_CATCH_DEFINE_SIG_TEST_X,INTERNAL_CATCH_DECLARE_SIG_TEST_X,INTERNAL_CATCH_DECLARE_SIG_TEST_X, INTERNAL_CATCH_DECLARE_SIG_TEST1, INTERNAL_CATCH_DECLARE_SIG_TEST0)(TestName, __VA_ARGS__)
904 #define INTERNAL_CATCH_REMOVE_PARENS_GEN(...) INTERNAL_CATCH_VA_NARGS_IMPL(__VA_ARGS__, INTERNAL_CATCH_REMOVE_PARENS_11_ARG,INTERNAL_CATCH_REMOVE_PARENS_10_ARG,INTERNAL_CATCH_REMOVE_PARENS_9_ARG,INTERNAL_CATCH_REMOVE_PARENS_8_ARG,INTERNAL_CATCH_REMOVE_PARENS_7_ARG,INTERNAL_CATCH_REMOVE_PARENS_6_ARG,INTERNAL_CATCH_REMOVE_PARENS_5_ARG,INTERNAL_CATCH_REMOVE_PARENS_4_ARG,INTERNAL_CATCH_REMOVE_PARENS_3_ARG,INTERNAL_CATCH_REMOVE_PARENS_2_ARG,INTERNAL_CATCH_REMOVE_PARENS_1_ARG)(__VA_ARGS__)
906 #define INTERNAL_CATCH_NTTP_0(signature)
907 #define INTERNAL_CATCH_NTTP_GEN(...) INTERNAL_CATCH_EXPAND_VARGS(INTERNAL_CATCH_VA_NARGS_IMPL(__VA_ARGS__, INTERNAL_CATCH_NTTP_1, INTERNAL_CATCH_NTTP_1, INTERNAL_CATCH_NTTP_1, INTERNAL_CATCH_NTTP_1, INTERNAL_CATCH_NTTP_1, INTERNAL_CATCH_NTTP_1, INTERNAL_CATCH_NTTP_1, INTERNAL_CATCH_NTTP_1, INTERNAL_CATCH_NTTP_1,INTERNAL_CATCH_NTTP_1, INTERNAL_CATCH_NTTP_0)( __VA_ARGS__))
908 #define INTERNAL_CATCH_DEFINE_SIG_TEST_METHOD(TestName, ...) INTERNAL_CATCH_EXPAND_VARGS(INTERNAL_CATCH_VA_NARGS_IMPL( "dummy", __VA_ARGS__, INTERNAL_CATCH_DEFINE_SIG_TEST_METHOD_X,INTERNAL_CATCH_DEFINE_SIG_TEST_METHOD_X, INTERNAL_CATCH_DEFINE_SIG_TEST_METHOD_X, INTERNAL_CATCH_DEFINE_SIG_TEST_METHOD_X, INTERNAL_CATCH_DEFINE_SIG_TEST_METHOD_X, INTERNAL_CATCH_DEFINE_SIG_TEST_METHOD_X, INTERNAL_CATCH_DEFINE_SIG_TEST_METHOD_X,INTERNAL_CATCH_DEFINE_SIG_TEST_METHOD_X,INTERNAL_CATCH_DEFINE_SIG_TEST_METHOD_X, INTERNAL_CATCH_DEFINE_SIG_TEST_METHOD1, INTERNAL_CATCH_DEFINE_SIG_TEST_METHOD0)(TestName, __VA_ARGS__))
909 #define INTERNAL_CATCH_DECLARE_SIG_TEST_METHOD(TestName, ClassName, ...) INTERNAL_CATCH_EXPAND_VARGS(INTERNAL_CATCH_VA_NARGS_IMPL( "dummy", __VA_ARGS__, INTERNAL_CATCH_DECLARE_SIG_TEST_METHOD_X,INTERNAL_CATCH_DECLARE_SIG_TEST_METHOD_X, INTERNAL_CATCH_DECLARE_SIG_TEST_METHOD_X, INTERNAL_CATCH_DECLARE_SIG_TEST_METHOD_X, INTERNAL_CATCH_DECLARE_SIG_TEST_METHOD_X, INTERNAL_CATCH_DECLARE_SIG_TEST_METHOD_X, INTERNAL_CATCH_DECLARE_SIG_TEST_METHOD_X,INTERNAL_CATCH_DECLARE_SIG_TEST_METHOD_X,INTERNAL_CATCH_DECLARE_SIG_TEST_METHOD_X, INTERNAL_CATCH_DECLARE_SIG_TEST_METHOD1, INTERNAL_CATCH_DECLARE_SIG_TEST_METHOD0)(TestName, ClassName, __VA_ARGS__))
910 #define INTERNAL_CATCH_NTTP_REG_METHOD_GEN(TestName, ...) INTERNAL_CATCH_EXPAND_VARGS(INTERNAL_CATCH_VA_NARGS_IMPL( "dummy", __VA_ARGS__, INTERNAL_CATCH_NTTP_REGISTER_METHOD, INTERNAL_CATCH_NTTP_REGISTER_METHOD, INTERNAL_CATCH_NTTP_REGISTER_METHOD, INTERNAL_CATCH_NTTP_REGISTER_METHOD, INTERNAL_CATCH_NTTP_REGISTER_METHOD, INTERNAL_CATCH_NTTP_REGISTER_METHOD, INTERNAL_CATCH_NTTP_REGISTER_METHOD, INTERNAL_CATCH_NTTP_REGISTER_METHOD, INTERNAL_CATCH_NTTP_REGISTER_METHOD, INTERNAL_CATCH_NTTP_REGISTER_METHOD0, INTERNAL_CATCH_NTTP_REGISTER_METHOD0)(TestName, __VA_ARGS__))
911 #define INTERNAL_CATCH_NTTP_REG_GEN(TestFunc, ...) INTERNAL_CATCH_EXPAND_VARGS(INTERNAL_CATCH_VA_NARGS_IMPL( "dummy", __VA_ARGS__, INTERNAL_CATCH_NTTP_REGISTER, INTERNAL_CATCH_NTTP_REGISTER, INTERNAL_CATCH_NTTP_REGISTER, INTERNAL_CATCH_NTTP_REGISTER, INTERNAL_CATCH_NTTP_REGISTER, INTERNAL_CATCH_NTTP_REGISTER, INTERNAL_CATCH_NTTP_REGISTER, INTERNAL_CATCH_NTTP_REGISTER, INTERNAL_CATCH_NTTP_REGISTER, INTERNAL_CATCH_NTTP_REGISTER0, INTERNAL_CATCH_NTTP_REGISTER0)(TestFunc, __VA_ARGS__))
912 #define INTERNAL_CATCH_DEFINE_SIG_TEST(TestName, ...) INTERNAL_CATCH_EXPAND_VARGS(INTERNAL_CATCH_VA_NARGS_IMPL( "dummy", __VA_ARGS__, INTERNAL_CATCH_DEFINE_SIG_TEST_X, INTERNAL_CATCH_DEFINE_SIG_TEST_X, INTERNAL_CATCH_DEFINE_SIG_TEST_X, INTERNAL_CATCH_DEFINE_SIG_TEST_X, INTERNAL_CATCH_DEFINE_SIG_TEST_X, INTERNAL_CATCH_DEFINE_SIG_TEST_X, INTERNAL_CATCH_DEFINE_SIG_TEST_X, INTERNAL_CATCH_DEFINE_SIG_TEST_X,INTERNAL_CATCH_DEFINE_SIG_TEST_X,INTERNAL_CATCH_DEFINE_SIG_TEST1, INTERNAL_CATCH_DEFINE_SIG_TEST0)(TestName, __VA_ARGS__))
913 #define INTERNAL_CATCH_DECLARE_SIG_TEST(TestName, ...) INTERNAL_CATCH_EXPAND_VARGS(INTERNAL_CATCH_VA_NARGS_IMPL( "dummy", __VA_ARGS__, INTERNAL_CATCH_DECLARE_SIG_TEST_X,INTERNAL_CATCH_DECLARE_SIG_TEST_X, INTERNAL_CATCH_DECLARE_SIG_TEST_X, INTERNAL_CATCH_DECLARE_SIG_TEST_X, INTERNAL_CATCH_DECLARE_SIG_TEST_X, INTERNAL_CATCH_DECLARE_SIG_TEST_X, INTERNAL_CATCH_DEFINE_SIG_TEST_X,INTERNAL_CATCH_DECLARE_SIG_TEST_X,INTERNAL_CATCH_DECLARE_SIG_TEST_X, INTERNAL_CATCH_DECLARE_SIG_TEST1, INTERNAL_CATCH_DECLARE_SIG_TEST0)(TestName, __VA_ARGS__))
914 #define INTERNAL_CATCH_REMOVE_PARENS_GEN(...) INTERNAL_CATCH_EXPAND_VARGS(INTERNAL_CATCH_VA_NARGS_IMPL(__VA_ARGS__, INTERNAL_CATCH_REMOVE_PARENS_11_ARG,INTERNAL_CATCH_REMOVE_PARENS_10_ARG,INTERNAL_CATCH_REMOVE_PARENS_9_ARG,INTERNAL_CATCH_REMOVE_PARENS_8_ARG,INTERNAL_CATCH_REMOVE_PARENS_7_ARG,INTERNAL_CATCH_REMOVE_PARENS_6_ARG,INTERNAL_CATCH_REMOVE_PARENS_5_ARG,INTERNAL_CATCH_REMOVE_PARENS_4_ARG,INTERNAL_CATCH_REMOVE_PARENS_3_ARG,INTERNAL_CATCH_REMOVE_PARENS_2_ARG,INTERNAL_CATCH_REMOVE_PARENS_1_ARG)(__VA_ARGS__))
921 #include <type_traits>
929 template <
typename Fun,
typename... Args>
931 template <
typename...>
932 std::false_type
static test(...);
935 template <
typename T>
938 template <
typename Fun,
typename... Args>
939 struct is_callable<Fun(Args...)> : decltype(is_callable_tester::test<Fun, Args...>(0)) {};
941 #if defined(__cpp_lib_is_invocable) && __cpp_lib_is_invocable >= 201703
944 template <
typename Func,
typename... U>
945 using FunctionReturnType = std::remove_reference_t<std::remove_cv_t<std::invoke_result_t<Func, U...>>>;
948 template <
typename Func,
typename... U>
949 using FunctionReturnType =
typename std::remove_reference<
typename std::remove_cv<
typename std::result_of<Func(U...)>::type>::type>::type;
993 #if defined(CATCH_CONFIG_DISABLE)
994 #define INTERNAL_CATCH_TESTCASE_NO_REGISTRATION( TestName, ... ) \
995 static void TestName()
996 #define INTERNAL_CATCH_TESTCASE_METHOD_NO_REGISTRATION( TestName, ClassName, ... ) \
998 struct TestName : INTERNAL_CATCH_REMOVE_PARENS(ClassName) { \
1002 void TestName::test()
1003 #define INTERNAL_CATCH_TEMPLATE_TEST_CASE_NO_REGISTRATION_2( TestName, TestFunc, Name, Tags, Signature, ... ) \
1004 INTERNAL_CATCH_DEFINE_SIG_TEST(TestFunc, INTERNAL_CATCH_REMOVE_PARENS(Signature))
1005 #define INTERNAL_CATCH_TEMPLATE_TEST_CASE_METHOD_NO_REGISTRATION_2( TestNameClass, TestName, ClassName, Name, Tags, Signature, ... ) \
1007 namespace INTERNAL_CATCH_MAKE_NAMESPACE(TestName) { \
1008 INTERNAL_CATCH_DECLARE_SIG_TEST_METHOD(TestName, ClassName, INTERNAL_CATCH_REMOVE_PARENS(Signature));\
1011 INTERNAL_CATCH_DEFINE_SIG_TEST_METHOD(TestName, INTERNAL_CATCH_REMOVE_PARENS(Signature))
1013 #ifndef CATCH_CONFIG_TRADITIONAL_MSVC_PREPROCESSOR
1014 #define INTERNAL_CATCH_TEMPLATE_TEST_CASE_NO_REGISTRATION(Name, Tags, ...) \
1015 INTERNAL_CATCH_TEMPLATE_TEST_CASE_NO_REGISTRATION_2( INTERNAL_CATCH_UNIQUE_NAME( C_A_T_C_H_T_E_M_P_L_A_T_E_T_E_S_T_ ), INTERNAL_CATCH_UNIQUE_NAME( C_A_T_C_H_T_E_M_P_L_A_T_E_T_E_S_T_F_U_N_C_ ), Name, Tags, typename TestType, __VA_ARGS__ )
1017 #define INTERNAL_CATCH_TEMPLATE_TEST_CASE_NO_REGISTRATION(Name, Tags, ...) \
1018 INTERNAL_CATCH_EXPAND_VARGS( INTERNAL_CATCH_TEMPLATE_TEST_CASE_NO_REGISTRATION_2( INTERNAL_CATCH_UNIQUE_NAME( C_A_T_C_H_T_E_M_P_L_A_T_E_T_E_S_T_ ), INTERNAL_CATCH_UNIQUE_NAME( C_A_T_C_H_T_E_M_P_L_A_T_E_T_E_S_T_F_U_N_C_ ), Name, Tags, typename TestType, __VA_ARGS__ ) )
1021 #ifndef CATCH_CONFIG_TRADITIONAL_MSVC_PREPROCESSOR
1022 #define INTERNAL_CATCH_TEMPLATE_TEST_CASE_SIG_NO_REGISTRATION(Name, Tags, Signature, ...) \
1023 INTERNAL_CATCH_TEMPLATE_TEST_CASE_NO_REGISTRATION_2( INTERNAL_CATCH_UNIQUE_NAME( C_A_T_C_H_T_E_M_P_L_A_T_E_T_E_S_T_ ), INTERNAL_CATCH_UNIQUE_NAME( C_A_T_C_H_T_E_M_P_L_A_T_E_T_E_S_T_F_U_N_C_ ), Name, Tags, Signature, __VA_ARGS__ )
1025 #define INTERNAL_CATCH_TEMPLATE_TEST_CASE_SIG_NO_REGISTRATION(Name, Tags, Signature, ...) \
1026 INTERNAL_CATCH_EXPAND_VARGS( INTERNAL_CATCH_TEMPLATE_TEST_CASE_NO_REGISTRATION_2( INTERNAL_CATCH_UNIQUE_NAME( C_A_T_C_H_T_E_M_P_L_A_T_E_T_E_S_T_ ), INTERNAL_CATCH_UNIQUE_NAME( C_A_T_C_H_T_E_M_P_L_A_T_E_T_E_S_T_F_U_N_C_ ), Name, Tags, Signature, __VA_ARGS__ ) )
1029 #ifndef CATCH_CONFIG_TRADITIONAL_MSVC_PREPROCESSOR
1030 #define INTERNAL_CATCH_TEMPLATE_TEST_CASE_METHOD_NO_REGISTRATION( ClassName, Name, Tags,... ) \
1031 INTERNAL_CATCH_TEMPLATE_TEST_CASE_METHOD_NO_REGISTRATION_2( INTERNAL_CATCH_UNIQUE_NAME( C_A_T_C_H_T_E_M_P_L_A_T_E_T_E_S_T_C_L_A_S_S_ ), INTERNAL_CATCH_UNIQUE_NAME( C_A_T_C_H_T_E_M_P_L_A_T_E_T_E_S_T_ ) , ClassName, Name, Tags, typename T, __VA_ARGS__ )
1033 #define INTERNAL_CATCH_TEMPLATE_TEST_CASE_METHOD_NO_REGISTRATION( ClassName, Name, Tags,... ) \
1034 INTERNAL_CATCH_EXPAND_VARGS( INTERNAL_CATCH_TEMPLATE_TEST_CASE_METHOD_NO_REGISTRATION_2( INTERNAL_CATCH_UNIQUE_NAME( C_A_T_C_H_T_E_M_P_L_A_T_E_T_E_S_T_C_L_A_S_S_ ), INTERNAL_CATCH_UNIQUE_NAME( C_A_T_C_H_T_E_M_P_L_A_T_E_T_E_S_T_ ) , ClassName, Name, Tags, typename T, __VA_ARGS__ ) )
1037 #ifndef CATCH_CONFIG_TRADITIONAL_MSVC_PREPROCESSOR
1038 #define INTERNAL_CATCH_TEMPLATE_TEST_CASE_METHOD_SIG_NO_REGISTRATION( ClassName, Name, Tags, Signature, ... ) \
1039 INTERNAL_CATCH_TEMPLATE_TEST_CASE_METHOD_NO_REGISTRATION_2( INTERNAL_CATCH_UNIQUE_NAME( C_A_T_C_H_T_E_M_P_L_A_T_E_T_E_S_T_C_L_A_S_S_ ), INTERNAL_CATCH_UNIQUE_NAME( C_A_T_C_H_T_E_M_P_L_A_T_E_T_E_S_T_ ) , ClassName, Name, Tags, Signature, __VA_ARGS__ )
1041 #define INTERNAL_CATCH_TEMPLATE_TEST_CASE_METHOD_SIG_NO_REGISTRATION( ClassName, Name, Tags, Signature, ... ) \
1042 INTERNAL_CATCH_EXPAND_VARGS( INTERNAL_CATCH_TEMPLATE_TEST_CASE_METHOD_NO_REGISTRATION_2( INTERNAL_CATCH_UNIQUE_NAME( C_A_T_C_H_T_E_M_P_L_A_T_E_T_E_S_T_C_L_A_S_S_ ), INTERNAL_CATCH_UNIQUE_NAME( C_A_T_C_H_T_E_M_P_L_A_T_E_T_E_S_T_ ) , ClassName, Name, Tags, Signature, __VA_ARGS__ ) )
1047 #define INTERNAL_CATCH_TESTCASE2( TestName, ... ) \
1048 static void TestName(); \
1049 CATCH_INTERNAL_START_WARNINGS_SUPPRESSION \
1050 CATCH_INTERNAL_SUPPRESS_GLOBALS_WARNINGS \
1051 namespace{ Catch::AutoReg INTERNAL_CATCH_UNIQUE_NAME( autoRegistrar )( Catch::makeTestInvoker( &TestName ), CATCH_INTERNAL_LINEINFO, Catch::StringRef(), Catch::NameAndTags{ __VA_ARGS__ } ); } \
1052 CATCH_INTERNAL_STOP_WARNINGS_SUPPRESSION \
1053 static void TestName()
1054 #define INTERNAL_CATCH_TESTCASE( ... ) \
1055 INTERNAL_CATCH_TESTCASE2( INTERNAL_CATCH_UNIQUE_NAME( C_A_T_C_H_T_E_S_T_ ), __VA_ARGS__ )
1058 #define INTERNAL_CATCH_METHOD_AS_TEST_CASE( QualifiedMethod, ... ) \
1059 CATCH_INTERNAL_START_WARNINGS_SUPPRESSION \
1060 CATCH_INTERNAL_SUPPRESS_GLOBALS_WARNINGS \
1061 namespace{ Catch::AutoReg INTERNAL_CATCH_UNIQUE_NAME( autoRegistrar )( Catch::makeTestInvoker( &QualifiedMethod ), CATCH_INTERNAL_LINEINFO, "&" #QualifiedMethod, Catch::NameAndTags{ __VA_ARGS__ } ); }
\
1062 CATCH_INTERNAL_STOP_WARNINGS_SUPPRESSION
1065 #define INTERNAL_CATCH_TEST_CASE_METHOD2( TestName, ClassName, ... )\
1066 CATCH_INTERNAL_START_WARNINGS_SUPPRESSION \
1067 CATCH_INTERNAL_SUPPRESS_GLOBALS_WARNINGS \
1069 struct TestName : INTERNAL_CATCH_REMOVE_PARENS(ClassName) { \
1072 Catch::AutoReg INTERNAL_CATCH_UNIQUE_NAME( autoRegistrar ) ( Catch::makeTestInvoker( &TestName::test ), CATCH_INTERNAL_LINEINFO, #ClassName, Catch::NameAndTags{ __VA_ARGS__ } ); \
1074 CATCH_INTERNAL_STOP_WARNINGS_SUPPRESSION \
1075 void TestName::test()
1076 #define INTERNAL_CATCH_TEST_CASE_METHOD( ClassName, ... ) \
1077 INTERNAL_CATCH_TEST_CASE_METHOD2( INTERNAL_CATCH_UNIQUE_NAME( C_A_T_C_H_T_E_S_T_ ), ClassName, __VA_ARGS__ )
1080 #define INTERNAL_CATCH_REGISTER_TESTCASE( Function, ... ) \
1081 CATCH_INTERNAL_START_WARNINGS_SUPPRESSION \
1082 CATCH_INTERNAL_SUPPRESS_GLOBALS_WARNINGS \
1083 Catch::AutoReg INTERNAL_CATCH_UNIQUE_NAME( autoRegistrar )( Catch::makeTestInvoker( Function ), CATCH_INTERNAL_LINEINFO, Catch::StringRef(), Catch::NameAndTags{ __VA_ARGS__ } ); \
1084 CATCH_INTERNAL_STOP_WARNINGS_SUPPRESSION
1087 #define INTERNAL_CATCH_TEMPLATE_TEST_CASE_2(TestName, TestFunc, Name, Tags, Signature, ... )\
1088 CATCH_INTERNAL_START_WARNINGS_SUPPRESSION \
1089 CATCH_INTERNAL_SUPPRESS_GLOBALS_WARNINGS \
1090 CATCH_INTERNAL_SUPPRESS_ZERO_VARIADIC_WARNINGS \
1091 CATCH_INTERNAL_SUPPRESS_UNUSED_TEMPLATE_WARNINGS \
1092 INTERNAL_CATCH_DECLARE_SIG_TEST(TestFunc, INTERNAL_CATCH_REMOVE_PARENS(Signature));\
1094 namespace INTERNAL_CATCH_MAKE_NAMESPACE(TestName){\
1095 INTERNAL_CATCH_TYPE_GEN\
1096 INTERNAL_CATCH_NTTP_GEN(INTERNAL_CATCH_REMOVE_PARENS(Signature))\
1097 INTERNAL_CATCH_NTTP_REG_GEN(TestFunc,INTERNAL_CATCH_REMOVE_PARENS(Signature))\
1098 template<typename...Types> \
1102 constexpr char const* tmpl_types[] = {CATCH_REC_LIST(INTERNAL_CATCH_STRINGIZE_WITHOUT_PARENS, __VA_ARGS__)};\
1103 using expander = int[];\
1104 (void)expander{(reg_test(Types{}, Catch::NameAndTags{ Name " - " + std::string(tmpl_types[index]), Tags } ), index++)... };
\
1107 static int INTERNAL_CATCH_UNIQUE_NAME( globalRegistrar ) = [](){\
1108 TestName<INTERNAL_CATCH_MAKE_TYPE_LISTS_FROM_TYPES(__VA_ARGS__)>();\
1113 CATCH_INTERNAL_STOP_WARNINGS_SUPPRESSION \
1114 INTERNAL_CATCH_DEFINE_SIG_TEST(TestFunc,INTERNAL_CATCH_REMOVE_PARENS(Signature))
1116 #ifndef CATCH_CONFIG_TRADITIONAL_MSVC_PREPROCESSOR
1117 #define INTERNAL_CATCH_TEMPLATE_TEST_CASE(Name, Tags, ...) \
1118 INTERNAL_CATCH_TEMPLATE_TEST_CASE_2( INTERNAL_CATCH_UNIQUE_NAME( C_A_T_C_H_T_E_M_P_L_A_T_E_T_E_S_T_ ), INTERNAL_CATCH_UNIQUE_NAME( C_A_T_C_H_T_E_M_P_L_A_T_E_T_E_S_T_F_U_N_C_ ), Name, Tags, typename TestType, __VA_ARGS__ )
1120 #define INTERNAL_CATCH_TEMPLATE_TEST_CASE(Name, Tags, ...) \
1121 INTERNAL_CATCH_EXPAND_VARGS( INTERNAL_CATCH_TEMPLATE_TEST_CASE_2( INTERNAL_CATCH_UNIQUE_NAME( C_A_T_C_H_T_E_M_P_L_A_T_E_T_E_S_T_ ), INTERNAL_CATCH_UNIQUE_NAME( C_A_T_C_H_T_E_M_P_L_A_T_E_T_E_S_T_F_U_N_C_ ), Name, Tags, typename TestType, __VA_ARGS__ ) )
1124 #ifndef CATCH_CONFIG_TRADITIONAL_MSVC_PREPROCESSOR
1125 #define INTERNAL_CATCH_TEMPLATE_TEST_CASE_SIG(Name, Tags, Signature, ...) \
1126 INTERNAL_CATCH_TEMPLATE_TEST_CASE_2( INTERNAL_CATCH_UNIQUE_NAME( C_A_T_C_H_T_E_M_P_L_A_T_E_T_E_S_T_ ), INTERNAL_CATCH_UNIQUE_NAME( C_A_T_C_H_T_E_M_P_L_A_T_E_T_E_S_T_F_U_N_C_ ), Name, Tags, Signature, __VA_ARGS__ )
1128 #define INTERNAL_CATCH_TEMPLATE_TEST_CASE_SIG(Name, Tags, Signature, ...) \
1129 INTERNAL_CATCH_EXPAND_VARGS( INTERNAL_CATCH_TEMPLATE_TEST_CASE_2( INTERNAL_CATCH_UNIQUE_NAME( C_A_T_C_H_T_E_M_P_L_A_T_E_T_E_S_T_ ), INTERNAL_CATCH_UNIQUE_NAME( C_A_T_C_H_T_E_M_P_L_A_T_E_T_E_S_T_F_U_N_C_ ), Name, Tags, Signature, __VA_ARGS__ ) )
1132 #define INTERNAL_CATCH_TEMPLATE_PRODUCT_TEST_CASE2(TestName, TestFuncName, Name, Tags, Signature, TmplTypes, TypesList) \
1133 CATCH_INTERNAL_START_WARNINGS_SUPPRESSION \
1134 CATCH_INTERNAL_SUPPRESS_GLOBALS_WARNINGS \
1135 CATCH_INTERNAL_SUPPRESS_ZERO_VARIADIC_WARNINGS \
1136 CATCH_INTERNAL_SUPPRESS_UNUSED_TEMPLATE_WARNINGS \
1137 template<typename TestType> static void TestFuncName(); \
1139 namespace INTERNAL_CATCH_MAKE_NAMESPACE(TestName) { \
1140 INTERNAL_CATCH_TYPE_GEN \
1141 INTERNAL_CATCH_NTTP_GEN(INTERNAL_CATCH_REMOVE_PARENS(Signature)) \
1142 template<typename... Types> \
1144 void reg_tests() { \
1146 using expander = int[]; \
1147 constexpr char const* tmpl_types[] = {CATCH_REC_LIST(INTERNAL_CATCH_STRINGIZE_WITHOUT_PARENS, INTERNAL_CATCH_REMOVE_PARENS(TmplTypes))};\
1148 constexpr char const* types_list[] = {CATCH_REC_LIST(INTERNAL_CATCH_STRINGIZE_WITHOUT_PARENS, INTERNAL_CATCH_REMOVE_PARENS(TypesList))};\
1149 constexpr auto num_types = sizeof(types_list) / sizeof(types_list[0]);\
1150 (void)expander{(Catch::AutoReg( Catch::makeTestInvoker( &TestFuncName<Types> ), CATCH_INTERNAL_LINEINFO, Catch::StringRef(), Catch::NameAndTags{ Name " - " + std::string(tmpl_types[index / num_types]) + "<" + std::string(types_list[index % num_types]) + ">", Tags } ), index++)... };
\
1153 static int INTERNAL_CATCH_UNIQUE_NAME( globalRegistrar ) = [](){ \
1154 using TestInit = typename create<TestName, decltype(get_wrapper<INTERNAL_CATCH_REMOVE_PARENS(TmplTypes)>()), TypeList<INTERNAL_CATCH_MAKE_TYPE_LISTS_FROM_TYPES(INTERNAL_CATCH_REMOVE_PARENS(TypesList))>>::type; \
1161 CATCH_INTERNAL_STOP_WARNINGS_SUPPRESSION \
1162 template<typename TestType> \
1163 static void TestFuncName()
1165 #ifndef CATCH_CONFIG_TRADITIONAL_MSVC_PREPROCESSOR
1166 #define INTERNAL_CATCH_TEMPLATE_PRODUCT_TEST_CASE(Name, Tags, ...)\
1167 INTERNAL_CATCH_TEMPLATE_PRODUCT_TEST_CASE2(INTERNAL_CATCH_UNIQUE_NAME( C_A_T_C_H_T_E_M_P_L_A_T_E_T_E_S_T_ ), INTERNAL_CATCH_UNIQUE_NAME( C_A_T_C_H_T_E_M_P_L_A_T_E_T_E_S_T_F_U_N_C_ ), Name, Tags, typename T,__VA_ARGS__)
1169 #define INTERNAL_CATCH_TEMPLATE_PRODUCT_TEST_CASE(Name, Tags, ...)\
1170 INTERNAL_CATCH_EXPAND_VARGS( INTERNAL_CATCH_TEMPLATE_PRODUCT_TEST_CASE2( INTERNAL_CATCH_UNIQUE_NAME( C_A_T_C_H_T_E_M_P_L_A_T_E_T_E_S_T_ ), INTERNAL_CATCH_UNIQUE_NAME( C_A_T_C_H_T_E_M_P_L_A_T_E_T_E_S_T_F_U_N_C_ ), Name, Tags, typename T, __VA_ARGS__ ) )
1173 #ifndef CATCH_CONFIG_TRADITIONAL_MSVC_PREPROCESSOR
1174 #define INTERNAL_CATCH_TEMPLATE_PRODUCT_TEST_CASE_SIG(Name, Tags, Signature, ...)\
1175 INTERNAL_CATCH_TEMPLATE_PRODUCT_TEST_CASE2(INTERNAL_CATCH_UNIQUE_NAME( C_A_T_C_H_T_E_M_P_L_A_T_E_T_E_S_T_ ), INTERNAL_CATCH_UNIQUE_NAME( C_A_T_C_H_T_E_M_P_L_A_T_E_T_E_S_T_F_U_N_C_ ), Name, Tags, Signature, __VA_ARGS__)
1177 #define INTERNAL_CATCH_TEMPLATE_PRODUCT_TEST_CASE_SIG(Name, Tags, Signature, ...)\
1178 INTERNAL_CATCH_EXPAND_VARGS( INTERNAL_CATCH_TEMPLATE_PRODUCT_TEST_CASE2( INTERNAL_CATCH_UNIQUE_NAME( C_A_T_C_H_T_E_M_P_L_A_T_E_T_E_S_T_ ), INTERNAL_CATCH_UNIQUE_NAME( C_A_T_C_H_T_E_M_P_L_A_T_E_T_E_S_T_F_U_N_C_ ), Name, Tags, Signature, __VA_ARGS__ ) )
1181 #define INTERNAL_CATCH_TEMPLATE_LIST_TEST_CASE_2(TestName, TestFunc, Name, Tags, TmplList)\
1182 CATCH_INTERNAL_START_WARNINGS_SUPPRESSION \
1183 CATCH_INTERNAL_SUPPRESS_GLOBALS_WARNINGS \
1184 CATCH_INTERNAL_SUPPRESS_UNUSED_TEMPLATE_WARNINGS \
1185 template<typename TestType> static void TestFunc(); \
1187 namespace INTERNAL_CATCH_MAKE_NAMESPACE(TestName){\
1188 INTERNAL_CATCH_TYPE_GEN\
1189 template<typename... Types> \
1191 void reg_tests() { \
1193 using expander = int[]; \
1194 (void)expander{(Catch::AutoReg( Catch::makeTestInvoker( &TestFunc<Types> ), CATCH_INTERNAL_LINEINFO, Catch::StringRef(), Catch::NameAndTags{ Name " - " + std::string(INTERNAL_CATCH_STRINGIZE(TmplList)) + " - " + std::to_string(index), Tags } ), index++)... };
\
1197 static int INTERNAL_CATCH_UNIQUE_NAME( globalRegistrar ) = [](){ \
1198 using TestInit = typename convert<TestName, TmplList>::type; \
1204 CATCH_INTERNAL_STOP_WARNINGS_SUPPRESSION \
1205 template<typename TestType> \
1206 static void TestFunc()
1208 #define INTERNAL_CATCH_TEMPLATE_LIST_TEST_CASE(Name, Tags, TmplList) \
1209 INTERNAL_CATCH_TEMPLATE_LIST_TEST_CASE_2( INTERNAL_CATCH_UNIQUE_NAME( C_A_T_C_H_T_E_M_P_L_A_T_E_T_E_S_T_ ), INTERNAL_CATCH_UNIQUE_NAME( C_A_T_C_H_T_E_M_P_L_A_T_E_T_E_S_T_F_U_N_C_ ), Name, Tags, TmplList )
1211 #define INTERNAL_CATCH_TEMPLATE_TEST_CASE_METHOD_2( TestNameClass, TestName, ClassName, Name, Tags, Signature, ... ) \
1212 CATCH_INTERNAL_START_WARNINGS_SUPPRESSION \
1213 CATCH_INTERNAL_SUPPRESS_GLOBALS_WARNINGS \
1214 CATCH_INTERNAL_SUPPRESS_ZERO_VARIADIC_WARNINGS \
1215 CATCH_INTERNAL_SUPPRESS_UNUSED_TEMPLATE_WARNINGS \
1217 namespace INTERNAL_CATCH_MAKE_NAMESPACE(TestName){ \
1218 INTERNAL_CATCH_TYPE_GEN\
1219 INTERNAL_CATCH_NTTP_GEN(INTERNAL_CATCH_REMOVE_PARENS(Signature))\
1220 INTERNAL_CATCH_DECLARE_SIG_TEST_METHOD(TestName, ClassName, INTERNAL_CATCH_REMOVE_PARENS(Signature));\
1221 INTERNAL_CATCH_NTTP_REG_METHOD_GEN(TestName, INTERNAL_CATCH_REMOVE_PARENS(Signature))\
1222 template<typename...Types> \
1223 struct TestNameClass{\
1226 constexpr char const* tmpl_types[] = {CATCH_REC_LIST(INTERNAL_CATCH_STRINGIZE_WITHOUT_PARENS, __VA_ARGS__)};\
1227 using expander = int[];\
1228 (void)expander{(reg_test(Types{}, #ClassName, Catch::NameAndTags{ Name " - " + std::string(tmpl_types[index]), Tags } ), index++)... };
\
1231 static int INTERNAL_CATCH_UNIQUE_NAME( globalRegistrar ) = [](){\
1232 TestNameClass<INTERNAL_CATCH_MAKE_TYPE_LISTS_FROM_TYPES(__VA_ARGS__)>();\
1237 CATCH_INTERNAL_STOP_WARNINGS_SUPPRESSION \
1238 INTERNAL_CATCH_DEFINE_SIG_TEST_METHOD(TestName, INTERNAL_CATCH_REMOVE_PARENS(Signature))
1240 #ifndef CATCH_CONFIG_TRADITIONAL_MSVC_PREPROCESSOR
1241 #define INTERNAL_CATCH_TEMPLATE_TEST_CASE_METHOD( ClassName, Name, Tags,... ) \
1242 INTERNAL_CATCH_TEMPLATE_TEST_CASE_METHOD_2( INTERNAL_CATCH_UNIQUE_NAME( C_A_T_C_H_T_E_M_P_L_A_T_E_T_E_S_T_C_L_A_S_S_ ), INTERNAL_CATCH_UNIQUE_NAME( C_A_T_C_H_T_E_M_P_L_A_T_E_T_E_S_T_ ) , ClassName, Name, Tags, typename T, __VA_ARGS__ )
1244 #define INTERNAL_CATCH_TEMPLATE_TEST_CASE_METHOD( ClassName, Name, Tags,... ) \
1245 INTERNAL_CATCH_EXPAND_VARGS( INTERNAL_CATCH_TEMPLATE_TEST_CASE_METHOD_2( INTERNAL_CATCH_UNIQUE_NAME( C_A_T_C_H_T_E_M_P_L_A_T_E_T_E_S_T_C_L_A_S_S_ ), INTERNAL_CATCH_UNIQUE_NAME( C_A_T_C_H_T_E_M_P_L_A_T_E_T_E_S_T_ ) , ClassName, Name, Tags, typename T, __VA_ARGS__ ) )
1248 #ifndef CATCH_CONFIG_TRADITIONAL_MSVC_PREPROCESSOR
1249 #define INTERNAL_CATCH_TEMPLATE_TEST_CASE_METHOD_SIG( ClassName, Name, Tags, Signature, ... ) \
1250 INTERNAL_CATCH_TEMPLATE_TEST_CASE_METHOD_2( INTERNAL_CATCH_UNIQUE_NAME( C_A_T_C_H_T_E_M_P_L_A_T_E_T_E_S_T_C_L_A_S_S_ ), INTERNAL_CATCH_UNIQUE_NAME( C_A_T_C_H_T_E_M_P_L_A_T_E_T_E_S_T_ ) , ClassName, Name, Tags, Signature, __VA_ARGS__ )
1252 #define INTERNAL_CATCH_TEMPLATE_TEST_CASE_METHOD_SIG( ClassName, Name, Tags, Signature, ... ) \
1253 INTERNAL_CATCH_EXPAND_VARGS( INTERNAL_CATCH_TEMPLATE_TEST_CASE_METHOD_2( INTERNAL_CATCH_UNIQUE_NAME( C_A_T_C_H_T_E_M_P_L_A_T_E_T_E_S_T_C_L_A_S_S_ ), INTERNAL_CATCH_UNIQUE_NAME( C_A_T_C_H_T_E_M_P_L_A_T_E_T_E_S_T_ ) , ClassName, Name, Tags, Signature, __VA_ARGS__ ) )
1256 #define INTERNAL_CATCH_TEMPLATE_PRODUCT_TEST_CASE_METHOD_2(TestNameClass, TestName, ClassName, Name, Tags, Signature, TmplTypes, TypesList)\
1257 CATCH_INTERNAL_START_WARNINGS_SUPPRESSION \
1258 CATCH_INTERNAL_SUPPRESS_GLOBALS_WARNINGS \
1259 CATCH_INTERNAL_SUPPRESS_ZERO_VARIADIC_WARNINGS \
1260 CATCH_INTERNAL_SUPPRESS_UNUSED_TEMPLATE_WARNINGS \
1261 template<typename TestType> \
1262 struct TestName : INTERNAL_CATCH_REMOVE_PARENS(ClassName <TestType>) { \
1266 namespace INTERNAL_CATCH_MAKE_NAMESPACE(TestNameClass) {\
1267 INTERNAL_CATCH_TYPE_GEN \
1268 INTERNAL_CATCH_NTTP_GEN(INTERNAL_CATCH_REMOVE_PARENS(Signature))\
1269 template<typename...Types>\
1270 struct TestNameClass{\
1273 using expander = int[];\
1274 constexpr char const* tmpl_types[] = {CATCH_REC_LIST(INTERNAL_CATCH_STRINGIZE_WITHOUT_PARENS, INTERNAL_CATCH_REMOVE_PARENS(TmplTypes))};\
1275 constexpr char const* types_list[] = {CATCH_REC_LIST(INTERNAL_CATCH_STRINGIZE_WITHOUT_PARENS, INTERNAL_CATCH_REMOVE_PARENS(TypesList))};\
1276 constexpr auto num_types = sizeof(types_list) / sizeof(types_list[0]);\
1277 (void)expander{(Catch::AutoReg( Catch::makeTestInvoker( &TestName<Types>::test ), CATCH_INTERNAL_LINEINFO, #ClassName, Catch::NameAndTags{ Name " - " + std::string(tmpl_types[index / num_types]) + "<" + std::string(types_list[index % num_types]) + ">", Tags } ), index++)... };
\
1280 static int INTERNAL_CATCH_UNIQUE_NAME( globalRegistrar ) = [](){\
1281 using TestInit = typename create<TestNameClass, decltype(get_wrapper<INTERNAL_CATCH_REMOVE_PARENS(TmplTypes)>()), TypeList<INTERNAL_CATCH_MAKE_TYPE_LISTS_FROM_TYPES(INTERNAL_CATCH_REMOVE_PARENS(TypesList))>>::type;\
1288 CATCH_INTERNAL_STOP_WARNINGS_SUPPRESSION \
1289 template<typename TestType> \
1290 void TestName<TestType>::test()
1292 #ifndef CATCH_CONFIG_TRADITIONAL_MSVC_PREPROCESSOR
1293 #define INTERNAL_CATCH_TEMPLATE_PRODUCT_TEST_CASE_METHOD( ClassName, Name, Tags, ... )\
1294 INTERNAL_CATCH_TEMPLATE_PRODUCT_TEST_CASE_METHOD_2( INTERNAL_CATCH_UNIQUE_NAME( C_A_T_C_H_T_E_M_P_L_A_T_E_T_E_S_T_ ), INTERNAL_CATCH_UNIQUE_NAME( C_A_T_C_H_T_E_M_P_L_A_T_E_T_E_S_T_F_U_N_C_ ), ClassName, Name, Tags, typename T, __VA_ARGS__ )
1296 #define INTERNAL_CATCH_TEMPLATE_PRODUCT_TEST_CASE_METHOD( ClassName, Name, Tags, ... )\
1297 INTERNAL_CATCH_EXPAND_VARGS( INTERNAL_CATCH_TEMPLATE_PRODUCT_TEST_CASE_METHOD_2( INTERNAL_CATCH_UNIQUE_NAME( C_A_T_C_H_T_E_M_P_L_A_T_E_T_E_S_T_ ), INTERNAL_CATCH_UNIQUE_NAME( C_A_T_C_H_T_E_M_P_L_A_T_E_T_E_S_T_F_U_N_C_ ), ClassName, Name, Tags, typename T,__VA_ARGS__ ) )
1300 #ifndef CATCH_CONFIG_TRADITIONAL_MSVC_PREPROCESSOR
1301 #define INTERNAL_CATCH_TEMPLATE_PRODUCT_TEST_CASE_METHOD_SIG( ClassName, Name, Tags, Signature, ... )\
1302 INTERNAL_CATCH_TEMPLATE_PRODUCT_TEST_CASE_METHOD_2( INTERNAL_CATCH_UNIQUE_NAME( C_A_T_C_H_T_E_M_P_L_A_T_E_T_E_S_T_ ), INTERNAL_CATCH_UNIQUE_NAME( C_A_T_C_H_T_E_M_P_L_A_T_E_T_E_S_T_F_U_N_C_ ), ClassName, Name, Tags, Signature, __VA_ARGS__ )
1304 #define INTERNAL_CATCH_TEMPLATE_PRODUCT_TEST_CASE_METHOD_SIG( ClassName, Name, Tags, Signature, ... )\
1305 INTERNAL_CATCH_EXPAND_VARGS( INTERNAL_CATCH_TEMPLATE_PRODUCT_TEST_CASE_METHOD_2( INTERNAL_CATCH_UNIQUE_NAME( C_A_T_C_H_T_E_M_P_L_A_T_E_T_E_S_T_ ), INTERNAL_CATCH_UNIQUE_NAME( C_A_T_C_H_T_E_M_P_L_A_T_E_T_E_S_T_F_U_N_C_ ), ClassName, Name, Tags, Signature,__VA_ARGS__ ) )
1308 #define INTERNAL_CATCH_TEMPLATE_LIST_TEST_CASE_METHOD_2( TestNameClass, TestName, ClassName, Name, Tags, TmplList) \
1309 CATCH_INTERNAL_START_WARNINGS_SUPPRESSION \
1310 CATCH_INTERNAL_SUPPRESS_GLOBALS_WARNINGS \
1311 CATCH_INTERNAL_SUPPRESS_UNUSED_TEMPLATE_WARNINGS \
1312 template<typename TestType> \
1313 struct TestName : INTERNAL_CATCH_REMOVE_PARENS(ClassName <TestType>) { \
1317 namespace INTERNAL_CATCH_MAKE_NAMESPACE(TestName){ \
1318 INTERNAL_CATCH_TYPE_GEN\
1319 template<typename...Types>\
1320 struct TestNameClass{\
1323 using expander = int[];\
1324 (void)expander{(Catch::AutoReg( Catch::makeTestInvoker( &TestName<Types>::test ), CATCH_INTERNAL_LINEINFO, #ClassName, Catch::NameAndTags{ Name " - " + std::string(INTERNAL_CATCH_STRINGIZE(TmplList)) + " - " + std::to_string(index), Tags } ), index++)... };
\
1327 static int INTERNAL_CATCH_UNIQUE_NAME( globalRegistrar ) = [](){\
1328 using TestInit = typename convert<TestNameClass, TmplList>::type;\
1334 CATCH_INTERNAL_STOP_WARNINGS_SUPPRESSION \
1335 template<typename TestType> \
1336 void TestName<TestType>::test()
1338 #define INTERNAL_CATCH_TEMPLATE_LIST_TEST_CASE_METHOD(ClassName, Name, Tags, TmplList) \
1339 INTERNAL_CATCH_TEMPLATE_LIST_TEST_CASE_METHOD_2( INTERNAL_CATCH_UNIQUE_NAME( C_A_T_C_H_T_E_M_P_L_A_T_E_T_E_S_T_ ), INTERNAL_CATCH_UNIQUE_NAME( C_A_T_C_H_T_E_M_P_L_A_T_E_T_E_S_T_F_U_N_C_ ), ClassName, Name, Tags, TmplList )
1417 #include <type_traits>
1447 auto str() const -> std::
string;
1449 template<typename T>
1481 template<
typename E>
1483 static_assert(
sizeof(
int) >=
sizeof(E),
"Cannot serialize enum to int");
1484 std::vector<int> intValues;
1485 intValues.reserve(
values.size() );
1486 for(
auto enumValue :
values )
1487 intValues.push_back(
static_cast<int>( enumValue ) );
1496 #ifdef CATCH_CONFIG_CPP17_STRING_VIEW
1497 #include <string_view>
1503 #import <Foundation/Foundation.h>
1505 #ifdef __has_feature
1506 #define CATCH_ARC_ENABLED __has_feature(objc_arc)
1508 #define CATCH_ARC_ENABLED 0
1511 void arcSafeRelease( NSObject* obj );
1512 id performOptionalSelector(
id obj,
SEL sel );
1514 #if !CATCH_ARC_ENABLED
1515 inline void arcSafeRelease( NSObject* obj ) {
1518 inline id performOptionalSelector(
id obj,
SEL sel ) {
1519 if( [obj respondsToSelector: sel] )
1520 return [obj performSelector: sel];
1523 #define CATCH_UNSAFE_UNRETAINED
1524 #define CATCH_ARC_STRONG
1526 inline void arcSafeRelease( NSObject* ){}
1527 inline id performOptionalSelector(
id obj,
SEL sel ) {
1529 #pragma clang diagnostic push
1530 #pragma clang diagnostic ignored "-Warc-performSelector-leaks"
1532 if( [obj respondsToSelector: sel] )
1533 return [obj performSelector: sel];
1535 #pragma clang diagnostic pop
1539 #define CATCH_UNSAFE_UNRETAINED __unsafe_unretained
1540 #define CATCH_ARC_STRONG __strong
1547 #pragma warning(push)
1548 #pragma warning(disable:4180)
1558 template<
typename T>
1563 template<
typename T>
1565 template<
typename Stream,
typename U>
1567 -> decltype(std::declval<Stream&>() << std::declval<U>(), std::true_type());
1569 template<
typename,
typename>
1570 static auto test(...)->std::false_type;
1573 static const bool value = decltype(test<std::ostream, const T&>(0))::
value;
1576 template<
typename E>
1579 template<
typename T>
1580 typename std::enable_if<
1585 template<
typename T>
1586 typename std::enable_if<
1592 template<
typename T>
1593 typename std::enable_if<
1599 #if defined(_MANAGED)
1601 template<
typename T>
1602 std::string clrReferenceToString( T^ ref ) {
1604 return std::string(
"null");
1605 auto bytes = System::Text::Encoding::UTF8->GetBytes(ref->ToString());
1606 cli::pin_ptr<System::Byte> p = &bytes[0];
1607 return std::string(
reinterpret_cast<char const *
>(p), bytes->Length);
1614 template <
typename T,
typename =
void>
1616 template <
typename Fake = T>
1623 rss.operator<<(
value);
1627 template <
typename Fake = T>
1631 #if !defined(CATCH_CONFIG_FALLBACK_STRINGIFIER)
1634 return CATCH_CONFIG_FALLBACK_STRINGIFIER(
value);
1643 template <
typename T>
1645 return ::Catch::StringMaker<typename std::remove_cv<typename std::remove_reference<T>::type>::type>::convert(e);
1648 template<
typename E>
1653 #if defined(_MANAGED)
1654 template <
typename T>
1656 return ::Catch::StringMaker<T^>::convert(e);
1666 static std::string
convert(
const std::string& str);
1669 #ifdef CATCH_CONFIG_CPP17_STRING_VIEW
1672 static std::string
convert(std::string_view str);
1685 #ifdef CATCH_CONFIG_WCHAR
1688 static std::string
convert(
const std::wstring& wstr);
1691 # ifdef CATCH_CONFIG_CPP17_STRING_VIEW
1694 static std::string
convert(std::wstring_view str);
1718 static std::string
convert(
signed char const* str) {
1724 static std::string
convert(
unsigned char const* str) {
1729 #if defined(CATCH_CONFIG_CPP17_BYTE)
1731 struct StringMaker<std::byte> {
1795 template <
typename T>
1797 template <
typename U>
1807 template <
typename R,
typename C>
1818 #if defined(_MANAGED)
1819 template <
typename T>
1820 struct StringMaker<T^> {
1821 static std::string convert( T^ ref ) {
1822 return ::Catch::Detail::clrReferenceToString(ref);
1828 template<
typename InputIterator,
typename Sentinel = InputIterator>
1832 if (first != last) {
1834 for (++first; first != last; ++first)
1844 struct StringMaker<NSString*> {
1845 static std::string convert(NSString * nsstring) {
1848 return std::string(
"@") + [nsstring UTF8String];
1852 struct StringMaker<NSObject*> {
1853 static std::string convert(NSObject* nsObject) {
1859 inline std::string
stringify( NSString* nsstring ) {
1872 #if defined(CATCH_CONFIG_ENABLE_ALL_STRINGMAKERS)
1873 # define CATCH_CONFIG_ENABLE_PAIR_STRINGMAKER
1874 # define CATCH_CONFIG_ENABLE_TUPLE_STRINGMAKER
1875 # define CATCH_CONFIG_ENABLE_VARIANT_STRINGMAKER
1876 # define CATCH_CONFIG_ENABLE_CHRONO_STRINGMAKER
1877 # define CATCH_CONFIG_ENABLE_OPTIONAL_STRINGMAKER
1881 #if defined(CATCH_CONFIG_ENABLE_PAIR_STRINGMAKER)
1884 template<
typename T1,
typename T2>
1885 struct StringMaker<std::pair<T1, T2> > {
1886 static std::string
convert(
const std::pair<T1, T2>& pair) {
1887 ReusableStringStream rss;
1899 #if defined(CATCH_CONFIG_ENABLE_OPTIONAL_STRINGMAKER) && defined(CATCH_CONFIG_CPP17_OPTIONAL)
1902 template<
typename T>
1903 struct StringMaker<std::optional<T> > {
1904 static std::string
convert(
const std::optional<T>& optional) {
1905 ReusableStringStream rss;
1906 if (optional.has_value()) {
1918 #if defined(CATCH_CONFIG_ENABLE_TUPLE_STRINGMAKER)
1927 struct TupleElementPrinter {
1928 static void print(
const Tuple& tuple, std::ostream& os) {
1929 os << (N ?
", " :
" ")
1931 TupleElementPrinter<Tuple, N + 1>::print(tuple, os);
1939 struct TupleElementPrinter<Tuple, N, false> {
1940 static void print(
const Tuple&, std::ostream&) {}
1945 template<
typename ...Types>
1946 struct StringMaker<std::tuple<Types...>> {
1947 static std::string
convert(
const std::tuple<Types...>& tuple) {
1948 ReusableStringStream rss;
1950 Detail::TupleElementPrinter<std::tuple<Types...>>::print(tuple, rss.get());
1958 #if defined(CATCH_CONFIG_ENABLE_VARIANT_STRINGMAKER) && defined(CATCH_CONFIG_CPP17_VARIANT)
1962 struct StringMaker<std::monostate> {
1963 static std::string
convert(
const std::monostate&) {
1968 template<
typename... Elements>
1969 struct StringMaker<std::variant<Elements...>> {
1970 static std::string
convert(
const std::variant<Elements...>& variant) {
1971 if (variant.valueless_by_exception()) {
1972 return "{valueless variant}";
1975 [](
const auto&
value) {
1992 template <
typename...>
1997 template <
typename T,
typename =
void>
2001 template <
typename T>
2006 template <
typename T>
2010 #if defined(_MANAGED)
2011 template <
typename T>
2013 static const bool value =
false;
2017 template<
typename Range>
2023 template<
typename Allocator>
2039 template<
typename R>
2040 struct StringMaker<R, typename std::enable_if<is_range<R>::value && !::Catch::Detail::IsStreamInsertable<R>::value>::type> {
2046 template <
typename T,
int SZ>
2056 #if defined(CATCH_CONFIG_ENABLE_CHRONO_STRINGMAKER)
2063 template <
class Ratio>
2064 struct ratio_string {
2065 static std::string symbol();
2068 template <
class Ratio>
2069 std::string ratio_string<Ratio>::symbol() {
2071 rss <<
'[' << Ratio::num <<
'/'
2072 << Ratio::den <<
']';
2076 struct ratio_string<std::atto> {
2077 static std::string symbol();
2080 struct ratio_string<std::femto> {
2081 static std::string symbol();
2084 struct ratio_string<std::pico> {
2085 static std::string symbol();
2088 struct ratio_string<std::nano> {
2089 static std::string symbol();
2092 struct ratio_string<std::micro> {
2093 static std::string symbol();
2096 struct ratio_string<std::milli> {
2097 static std::string symbol();
2102 template<
typename Value,
typename Ratio>
2103 struct StringMaker<std::chrono::duration<Value, Ratio>> {
2104 static std::string
convert(std::chrono::duration<Value, Ratio>
const& duration) {
2105 ReusableStringStream rss;
2106 rss << duration.count() <<
' ' << ratio_string<Ratio>::symbol() <<
's';
2110 template<
typename Value>
2111 struct StringMaker<std::chrono::duration<Value, std::ratio<1>>> {
2112 static std::string
convert(std::chrono::duration<Value, std::ratio<1>>
const& duration) {
2113 ReusableStringStream rss;
2114 rss << duration.count() <<
" s";
2118 template<
typename Value>
2119 struct StringMaker<std::chrono::duration<Value, std::ratio<60>>> {
2120 static std::string
convert(std::chrono::duration<Value, std::ratio<60>>
const& duration) {
2121 ReusableStringStream rss;
2122 rss << duration.count() <<
" m";
2126 template<
typename Value>
2127 struct StringMaker<std::chrono::duration<Value, std::ratio<3600>>> {
2128 static std::string
convert(std::chrono::duration<Value, std::ratio<3600>>
const& duration) {
2129 ReusableStringStream rss;
2130 rss << duration.count() <<
" h";
2138 template<
typename Clock,
typename Duration>
2139 struct StringMaker<std::chrono::time_point<Clock, Duration>> {
2140 static std::string
convert(std::chrono::time_point<Clock, Duration>
const& time_point) {
2145 template<
typename Duration>
2146 struct StringMaker<std::chrono::time_point<std::chrono::system_clock, Duration>> {
2147 static std::string
convert(std::chrono::time_point<std::chrono::system_clock, Duration>
const& time_point) {
2148 auto converted = std::chrono::system_clock::to_time_t(time_point);
2151 std::tm timeInfo = {};
2152 gmtime_s(&timeInfo, &converted);
2154 std::tm* timeInfo = std::gmtime(&converted);
2157 auto const timeStampSize =
sizeof(
"2017-01-16T17:06:45Z");
2158 char timeStamp[timeStampSize];
2159 const char *
const fmt =
"%Y-%m-%dT%H:%M:%SZ";
2162 std::strftime(timeStamp, timeStampSize, fmt, &timeInfo);
2164 std::strftime(timeStamp, timeStampSize, fmt, timeInfo);
2166 return std::string(timeStamp);
2172 #define INTERNAL_CATCH_REGISTER_ENUM( enumName, ... ) \
2174 template<> struct StringMaker<enumName> { \
2175 static std::string convert( enumName value ) { \
2176 static const auto& enumInfo = ::Catch::getMutableRegistryHub().getMutableEnumValuesRegistry().registerEnum( #enumName, #__VA_ARGS__, { __VA_ARGS__ } ); \
2177 return static_cast<std::string>(enumInfo.lookup( static_cast<int>( value ) )); \
2182 #define CATCH_REGISTER_ENUM( enumName, ... ) INTERNAL_CATCH_REGISTER_ENUM( enumName, __VA_ARGS__ )
2185 #pragma warning(pop)
2192 #pragma warning(push)
2193 #pragma warning(disable:4389)
2194 #pragma warning(disable:4018)
2195 #pragma warning(disable:4312)
2196 #pragma warning(disable:4180)
2197 #pragma warning(disable:4800)
2223 template<
typename LhsT,
typename RhsT>
2242 template<
typename T>
2245 "chained comparisons are not supported inside assertions, "
2246 "wrap the expression inside parentheses, or decompose it");
2249 template<
typename T>
2252 "chained comparisons are not supported inside assertions, "
2253 "wrap the expression inside parentheses, or decompose it");
2256 template<
typename T>
2259 "chained comparisons are not supported inside assertions, "
2260 "wrap the expression inside parentheses, or decompose it");
2263 template<
typename T>
2266 "chained comparisons are not supported inside assertions, "
2267 "wrap the expression inside parentheses, or decompose it");
2270 template<
typename T>
2273 "chained comparisons are not supported inside assertions, "
2274 "wrap the expression inside parentheses, or decompose it");
2277 template<
typename T>
2280 "chained comparisons are not supported inside assertions, "
2281 "wrap the expression inside parentheses, or decompose it");
2284 template<
typename T>
2287 "chained comparisons are not supported inside assertions, "
2288 "wrap the expression inside parentheses, or decompose it");
2291 template<
typename T>
2294 "chained comparisons are not supported inside assertions, "
2295 "wrap the expression inside parentheses, or decompose it");
2299 template<
typename LhsT>
2315 template<
typename LhsT,
typename RhsT>
2316 auto compareEqual( LhsT
const& lhs, RhsT
const& rhs ) ->
bool {
return static_cast<bool>(lhs == rhs); }
2317 template<
typename T>
2318 auto compareEqual( T*
const& lhs,
int rhs ) ->
bool {
return lhs ==
reinterpret_cast<void const*
>( rhs ); }
2319 template<
typename T>
2320 auto compareEqual( T*
const& lhs,
long rhs ) ->
bool {
return lhs ==
reinterpret_cast<void const*
>( rhs ); }
2321 template<
typename T>
2322 auto compareEqual(
int lhs, T*
const& rhs ) ->
bool {
return reinterpret_cast<void const*
>( lhs ) == rhs; }
2323 template<
typename T>
2324 auto compareEqual(
long lhs, T*
const& rhs ) ->
bool {
return reinterpret_cast<void const*
>( lhs ) == rhs; }
2326 template<
typename LhsT,
typename RhsT>
2327 auto compareNotEqual( LhsT
const& lhs, RhsT&& rhs ) ->
bool {
return static_cast<bool>(lhs != rhs); }
2328 template<
typename T>
2329 auto compareNotEqual( T*
const& lhs,
int rhs ) ->
bool {
return lhs !=
reinterpret_cast<void const*
>( rhs ); }
2330 template<
typename T>
2331 auto compareNotEqual( T*
const& lhs,
long rhs ) ->
bool {
return lhs !=
reinterpret_cast<void const*
>( rhs ); }
2332 template<
typename T>
2333 auto compareNotEqual(
int lhs, T*
const& rhs ) ->
bool {
return reinterpret_cast<void const*
>( lhs ) != rhs; }
2334 template<
typename T>
2335 auto compareNotEqual(
long lhs, T*
const& rhs ) ->
bool {
return reinterpret_cast<void const*
>( lhs ) != rhs; }
2337 template<
typename LhsT>
2343 template<
typename RhsT>
2351 template<
typename RhsT>
2359 template<
typename RhsT>
2361 return {
static_cast<bool>(
m_lhs > rhs),
m_lhs,
">", rhs };
2363 template<
typename RhsT>
2365 return {
static_cast<bool>(
m_lhs < rhs),
m_lhs,
"<", rhs };
2367 template<
typename RhsT>
2369 return {
static_cast<bool>(
m_lhs >= rhs),
m_lhs,
">=", rhs };
2371 template<
typename RhsT>
2373 return {
static_cast<bool>(
m_lhs <= rhs),
m_lhs,
"<=", rhs };
2375 template <
typename RhsT>
2377 return {
static_cast<bool>(
m_lhs | rhs),
m_lhs,
"|", rhs };
2379 template <
typename RhsT>
2381 return {
static_cast<bool>(
m_lhs & rhs),
m_lhs,
"&", rhs };
2383 template <
typename RhsT>
2385 return {
static_cast<bool>(
m_lhs ^ rhs),
m_lhs,
"^", rhs };
2388 template<
typename RhsT>
2391 "operator&& is not supported inside assertions, "
2392 "wrap the expression inside parentheses, or decompose it");
2395 template<
typename RhsT>
2398 "operator|| is not supported inside assertions, "
2399 "wrap the expression inside parentheses, or decompose it");
2409 template<
typename T>
2415 template<
typename T>
2428 #pragma warning(pop)
2439 class AssertionResult;
2440 struct AssertionInfo;
2442 struct SectionEndInfo;
2444 struct MessageBuilder;
2446 struct AssertionReaction;
2447 struct SourceLineInfo;
2449 struct ITransientExpression;
2450 struct IGeneratorTracker;
2452 #if defined(CATCH_CONFIG_ENABLE_BENCHMARKING)
2453 struct BenchmarkInfo;
2454 template <
typename Duration = std::chrono::duration<
double, std::nano>>
2455 struct BenchmarkStats;
2463 Counts& assertions ) = 0;
2469 #if defined(CATCH_CONFIG_ENABLE_BENCHMARKING)
2470 virtual void benchmarkPreparing( std::string
const& name ) = 0;
2471 virtual void benchmarkStarting( BenchmarkInfo
const& info ) = 0;
2472 virtual void benchmarkEnded( BenchmarkStats<>
const& stats ) = 0;
2473 virtual void benchmarkFailed( std::string
const& error ) = 0;
2497 std::string
const& message,
2522 struct AssertionResultData;
2538 explicit operator bool()
const;
2566 template<
typename T>
2618 template<
typename T>
2632 template<
typename T>
2655 size_t m_captured = 0;
2662 template<
typename T>
2667 template<
typename T,
typename... Ts>
2670 captureValues( index+1,
values... );
2677 #if !defined(CATCH_CONFIG_DISABLE)
2679 #if !defined(CATCH_CONFIG_DISABLE_STRINGIFICATION)
2680 #define CATCH_INTERNAL_STRINGIFY(...) #__VA_ARGS__
2682 #define CATCH_INTERNAL_STRINGIFY(...) "Disabled by CATCH_CONFIG_DISABLE_STRINGIFICATION"
2685 #if defined(CATCH_CONFIG_FAST_COMPILE) || defined(CATCH_CONFIG_DISABLE_EXCEPTIONS)
2690 #define INTERNAL_CATCH_TRY
2691 #define INTERNAL_CATCH_CATCH( capturer )
2695 #define INTERNAL_CATCH_TRY try
2696 #define INTERNAL_CATCH_CATCH( handler ) catch(...) { handler.handleUnexpectedInflightException(); }
2700 #define INTERNAL_CATCH_REACT( handler ) handler.complete();
2703 #define INTERNAL_CATCH_TEST( macroName, resultDisposition, ... ) \
2705 CATCH_INTERNAL_IGNORE_BUT_WARN(__VA_ARGS__); \
2706 Catch::AssertionHandler catchAssertionHandler( macroName##_catch_sr, CATCH_INTERNAL_LINEINFO, CATCH_INTERNAL_STRINGIFY(__VA_ARGS__), resultDisposition ); \
2707 INTERNAL_CATCH_TRY { \
2708 CATCH_INTERNAL_START_WARNINGS_SUPPRESSION \
2709 CATCH_INTERNAL_SUPPRESS_PARENTHESES_WARNINGS \
2710 catchAssertionHandler.handleExpr( Catch::Decomposer() <= __VA_ARGS__ ); \
2711 CATCH_INTERNAL_STOP_WARNINGS_SUPPRESSION \
2712 } INTERNAL_CATCH_CATCH( catchAssertionHandler ) \
2713 INTERNAL_CATCH_REACT( catchAssertionHandler ) \
2714 } while( (void)0, (false) && static_cast<bool>( !!(__VA_ARGS__) ) )
2717 #define INTERNAL_CATCH_IF( macroName, resultDisposition, ... ) \
2718 INTERNAL_CATCH_TEST( macroName, resultDisposition, __VA_ARGS__ ); \
2719 if( Catch::getResultCapture().lastAssertionPassed() )
2722 #define INTERNAL_CATCH_ELSE( macroName, resultDisposition, ... ) \
2723 INTERNAL_CATCH_TEST( macroName, resultDisposition, __VA_ARGS__ ); \
2724 if( !Catch::getResultCapture().lastAssertionPassed() )
2727 #define INTERNAL_CATCH_NO_THROW( macroName, resultDisposition, ... ) \
2729 Catch::AssertionHandler catchAssertionHandler( macroName##_catch_sr, CATCH_INTERNAL_LINEINFO, CATCH_INTERNAL_STRINGIFY(__VA_ARGS__), resultDisposition ); \
2731 static_cast<void>(__VA_ARGS__); \
2732 catchAssertionHandler.handleExceptionNotThrownAsExpected(); \
2735 catchAssertionHandler.handleUnexpectedInflightException(); \
2737 INTERNAL_CATCH_REACT( catchAssertionHandler ) \
2741 #define INTERNAL_CATCH_THROWS( macroName, resultDisposition, ... ) \
2743 Catch::AssertionHandler catchAssertionHandler( macroName##_catch_sr, CATCH_INTERNAL_LINEINFO, CATCH_INTERNAL_STRINGIFY(__VA_ARGS__), resultDisposition); \
2744 if( catchAssertionHandler.allowThrows() ) \
2746 static_cast<void>(__VA_ARGS__); \
2747 catchAssertionHandler.handleUnexpectedExceptionNotThrown(); \
2750 catchAssertionHandler.handleExceptionThrownAsExpected(); \
2753 catchAssertionHandler.handleThrowingCallSkipped(); \
2754 INTERNAL_CATCH_REACT( catchAssertionHandler ) \
2758 #define INTERNAL_CATCH_THROWS_AS( macroName, exceptionType, resultDisposition, expr ) \
2760 Catch::AssertionHandler catchAssertionHandler( macroName##_catch_sr, CATCH_INTERNAL_LINEINFO, CATCH_INTERNAL_STRINGIFY(expr) ", " CATCH_INTERNAL_STRINGIFY(exceptionType), resultDisposition ); \
2761 if( catchAssertionHandler.allowThrows() ) \
2763 static_cast<void>(expr); \
2764 catchAssertionHandler.handleUnexpectedExceptionNotThrown(); \
2766 catch( exceptionType const& ) { \
2767 catchAssertionHandler.handleExceptionThrownAsExpected(); \
2770 catchAssertionHandler.handleUnexpectedInflightException(); \
2773 catchAssertionHandler.handleThrowingCallSkipped(); \
2774 INTERNAL_CATCH_REACT( catchAssertionHandler ) \
2778 #define INTERNAL_CATCH_MSG( macroName, messageType, resultDisposition, ... ) \
2780 Catch::AssertionHandler catchAssertionHandler( macroName##_catch_sr, CATCH_INTERNAL_LINEINFO, Catch::StringRef(), resultDisposition ); \
2781 catchAssertionHandler.handleMessage( messageType, ( Catch::MessageStream() << __VA_ARGS__ + ::Catch::StreamEndStop() ).m_stream.str() ); \
2782 INTERNAL_CATCH_REACT( catchAssertionHandler ) \
2786 #define INTERNAL_CATCH_CAPTURE( varName, macroName, ... ) \
2787 auto varName = Catch::Capturer( macroName, CATCH_INTERNAL_LINEINFO, Catch::ResultWas::Info, #__VA_ARGS__ ); \
2788 varName.captureValues( 0, __VA_ARGS__ )
2791 #define INTERNAL_CATCH_INFO( macroName, log ) \
2792 Catch::ScopedMessage INTERNAL_CATCH_UNIQUE_NAME( scopedMessage )( Catch::MessageBuilder( macroName##_catch_sr, CATCH_INTERNAL_LINEINFO, Catch::ResultWas::Info ) << log );
2795 #define INTERNAL_CATCH_UNSCOPED_INFO( macroName, log ) \
2796 Catch::getResultCapture().emplaceUnscopedMessage( Catch::MessageBuilder( macroName##_catch_sr, CATCH_INTERNAL_LINEINFO, Catch::ResultWas::Info ) << log )
2800 #define INTERNAL_CATCH_THROWS_STR_MATCHES( macroName, resultDisposition, matcher, ... ) \
2802 Catch::AssertionHandler catchAssertionHandler( macroName##_catch_sr, CATCH_INTERNAL_LINEINFO, CATCH_INTERNAL_STRINGIFY(__VA_ARGS__) ", " CATCH_INTERNAL_STRINGIFY(matcher), resultDisposition ); \
2803 if( catchAssertionHandler.allowThrows() ) \
2805 static_cast<void>(__VA_ARGS__); \
2806 catchAssertionHandler.handleUnexpectedExceptionNotThrown(); \
2809 Catch::handleExceptionMatchExpr( catchAssertionHandler, matcher, #matcher##_catch_sr ); \
2812 catchAssertionHandler.handleThrowingCallSkipped(); \
2813 INTERNAL_CATCH_REACT( catchAssertionHandler ) \
2837 std::size_t passed = 0;
2838 std::size_t failed = 0;
2839 std::size_t failedButOk = 0;
2863 std::string
const& _name );
2868 std::string
const& _name,
2869 std::string
const& ) :
SectionInfo( _lineInfo, _name ) {}
2895 uint64_t m_nanoseconds = 0;
2899 auto getElapsedMicroseconds() const -> uint64_t;
2900 auto getElapsedMilliseconds() const ->
unsigned int;
2901 auto getElapsedSeconds() const ->
double;
2917 explicit operator bool()
const;
2930 #define INTERNAL_CATCH_SECTION( ... ) \
2931 CATCH_INTERNAL_START_WARNINGS_SUPPRESSION \
2932 CATCH_INTERNAL_SUPPRESS_UNUSED_WARNINGS \
2933 if( Catch::Section const& INTERNAL_CATCH_UNIQUE_NAME( catch_internal_Section ) = Catch::SectionInfo( CATCH_INTERNAL_LINEINFO, __VA_ARGS__ ) ) \
2934 CATCH_INTERNAL_STOP_WARNINGS_SUPPRESSION
2936 #define INTERNAL_CATCH_DYNAMIC_SECTION( ... ) \
2937 CATCH_INTERNAL_START_WARNINGS_SUPPRESSION \
2938 CATCH_INTERNAL_SUPPRESS_UNUSED_WARNINGS \
2939 if( Catch::Section const& INTERNAL_CATCH_UNIQUE_NAME( catch_internal_Section ) = Catch::SectionInfo( CATCH_INTERNAL_LINEINFO, (Catch::ReusableStringStream() << __VA_ARGS__).str() ) ) \
2940 CATCH_INTERNAL_STOP_WARNINGS_SUPPRESSION
2953 struct ITestCaseRegistry;
2954 struct IExceptionTranslatorRegistry;
2955 struct IExceptionTranslator;
2956 struct IReporterRegistry;
2957 struct IReporterFactory;
2958 struct ITagAliasRegistry;
2959 struct IMutableEnumValuesRegistry;
2961 class StartupExceptionRegistry;
2995 #if defined(CATCH_CONFIG_DISABLE)
2996 #define INTERNAL_CATCH_TRANSLATE_EXCEPTION_NO_REG( translatorName, signature) \
2997 static std::string translatorName( signature )
3000 #include <exception>
3012 virtual std::string
translate( ExceptionTranslators::const_iterator
it, ExceptionTranslators::const_iterator itEnd )
const = 0;
3022 template<
typename T>
3027 : m_translateFunction( translateFunction )
3030 std::string
translate( ExceptionTranslators::const_iterator
it, ExceptionTranslators::const_iterator itEnd )
const override {
3031 #if defined(CATCH_CONFIG_DISABLE_EXCEPTIONS)
3036 std::rethrow_exception(std::current_exception());
3038 return (*it)->translate(
it+1, itEnd );
3041 return m_translateFunction( ex );
3047 std::string(*m_translateFunction)( T& );
3051 template<
typename T>
3060 #define INTERNAL_CATCH_TRANSLATE_EXCEPTION2( translatorName, signature ) \
3061 static std::string translatorName( signature ); \
3062 CATCH_INTERNAL_START_WARNINGS_SUPPRESSION \
3063 CATCH_INTERNAL_SUPPRESS_GLOBALS_WARNINGS \
3064 namespace{ Catch::ExceptionTranslatorRegistrar INTERNAL_CATCH_UNIQUE_NAME( catch_internal_ExceptionRegistrar )( &translatorName ); } \
3065 CATCH_INTERNAL_STOP_WARNINGS_SUPPRESSION \
3066 static std::string translatorName( signature )
3068 #define INTERNAL_CATCH_TRANSLATE_EXCEPTION( signature ) INTERNAL_CATCH_TRANSLATE_EXCEPTION2( INTERNAL_CATCH_UNIQUE_NAME( catch_internal_ExceptionTranslator ), signature )
3073 #include <type_traits>
3110 auto lhs_v =
static_cast<double>(lhs);
3120 friend bool operator != ( T
const& lhs,
Approx const& rhs ) {
3125 friend bool operator != (
Approx const& lhs, T
const& rhs ) {
3131 return static_cast<double>(lhs) < rhs.
m_value || lhs == rhs;
3136 return lhs.
m_value <
static_cast<double>(rhs) || lhs == rhs;
3141 return static_cast<double>(lhs) > rhs.
m_value || lhs == rhs;
3146 return lhs.
m_value >
static_cast<double>(rhs) || lhs == rhs;
3151 double epsilonAsDouble =
static_cast<double>(newEpsilon);
3152 setEpsilon(epsilonAsDouble);
3158 double marginAsDouble =
static_cast<double>(newMargin);
3159 setMargin(marginAsDouble);
3165 m_scale =
static_cast<double>(newScale);
3179 namespace literals {
3200 bool startsWith( std::string
const& s, std::string
const& prefix );
3202 bool endsWith( std::string
const& s, std::string
const& suffix );
3204 bool contains( std::string
const& s, std::string
const& infix );
3208 std::string
trim( std::string
const& str );
3214 bool replaceInPlace( std::string& str, std::string
const& replaceThis, std::string
const& withThis );
3227 #ifndef CATCH_CONFIG_DISABLE_MATCHERS
3236 namespace Matchers {
3257 # pragma clang diagnostic push
3258 # pragma clang diagnostic ignored "-Wnon-virtual-dtor"
3261 template<
typename ObjectT>
3263 virtual bool match( ObjectT
const& arg )
const = 0;
3266 #if defined(__OBJC__)
3271 virtual bool match( NSString* arg )
const = 0;
3276 # pragma clang diagnostic pop
3279 template<
typename T>
3287 template<
typename ArgT>
3289 bool match( ArgT
const& arg )
const override {
3290 for(
auto matcher : m_matchers ) {
3291 if (!matcher->match(arg))
3297 std::string description;
3298 description.reserve( 4 + m_matchers.size()*32 );
3299 description +=
"( ";
3301 for(
auto matcher : m_matchers ) {
3305 description +=
" and ";
3306 description += matcher->toString();
3308 description +=
" )";
3314 copy.m_matchers.push_back( &other );
3320 template<
typename ArgT>
3323 bool match( ArgT
const& arg )
const override {
3324 for(
auto matcher : m_matchers ) {
3325 if (matcher->match(arg))
3331 std::string description;
3332 description.reserve( 4 + m_matchers.size()*32 );
3333 description +=
"( ";
3335 for(
auto matcher : m_matchers ) {
3339 description +=
" or ";
3340 description += matcher->toString();
3342 description +=
" )";
3348 copy.m_matchers.push_back( &other );
3355 template<
typename ArgT>
3360 bool match( ArgT
const& arg )
const override {
3361 return !m_underlyingMatcher.match( arg );
3365 return "not " + m_underlyingMatcher.toString();
3370 template<
typename T>
3374 template<
typename T>
3378 template<
typename T>
3387 using namespace Matchers;
3396 namespace Matchers {
3397 namespace Exception {
3407 bool match(std::exception
const& ex)
const override;
3423 namespace Matchers {
3425 namespace Floating {
3427 enum class FloatingPointKind : uint8_t;
3431 bool match(
double const& matchee)
const override;
3440 bool match(
double const& matchee)
const override;
3456 bool match(
double const& matchee)
const override;
3483 #include <functional>
3487 namespace Matchers {
3494 template <
typename T>
3501 :m_predicate(std::move(elem)),
3505 bool match( T
const& item )
const override {
3506 return m_predicate(item);
3510 return m_description;
3520 template<
typename T>
3534 namespace Matchers {
3536 namespace StdString {
3558 bool match( std::string
const& source )
const override;
3562 bool match( std::string
const& source )
const override;
3566 bool match( std::string
const& source )
const override;
3570 bool match( std::string
const& source )
const override;
3575 bool match( std::string
const& matchee )
const override;
3600 #include <algorithm>
3603 namespace Matchers {
3606 template<
typename T,
typename Alloc>
3611 bool match(std::vector<T, Alloc>
const &v)
const override {
3612 for (
auto const& el : v) {
3613 if (el == m_comparator) {
3627 template<
typename T,
typename AllocComp,
typename AllocMatch>
3630 ContainsMatcher(std::vector<T, AllocComp>
const &comparator) : m_comparator( comparator ) {}
3632 bool match(std::vector<T, AllocMatch>
const &v)
const override {
3634 if (m_comparator.size() > v.size())
3636 for (
auto const& comparator : m_comparator) {
3637 auto present =
false;
3638 for (
const auto& el : v) {
3639 if (el == comparator) {
3657 template<
typename T,
typename AllocComp,
typename AllocMatch>
3660 EqualsMatcher(std::vector<T, AllocComp>
const &comparator) : m_comparator( comparator ) {}
3662 bool match(std::vector<T, AllocMatch>
const &v)
const override {
3667 if (m_comparator.size() != v.size())
3669 for (std::size_t i = 0; i < v.size(); ++i)
3670 if (m_comparator[i] != v[i])
3680 template<
typename T,
typename AllocComp,
typename AllocMatch>
3683 ApproxMatcher(std::vector<T, AllocComp>
const& comparator) : m_comparator( comparator ) {}
3685 bool match(std::vector<T, AllocMatch>
const &v)
const override {
3686 if (m_comparator.size() != v.size())
3688 for (std::size_t i = 0; i < v.size(); ++i)
3689 if (m_comparator[i] != approx(v[i]))
3703 approx.
margin(newMargin);
3708 approx.
scale(newScale);
3716 template<
typename T,
typename AllocComp,
typename AllocMatch>
3719 bool match(std::vector<T, AllocMatch>
const& vec)
const override {
3720 if (m_target.size() != vec.size()) {
3723 return std::is_permutation(m_target.begin(), m_target.end(), vec.begin());
3738 template<
typename T,
typename AllocComp = std::allocator<T>,
typename AllocMatch = AllocComp>
3743 template<
typename T,
typename Alloc = std::allocator<T>>
3748 template<
typename T,
typename AllocComp = std::allocator<T>,
typename AllocMatch = AllocComp>
3753 template<
typename T,
typename AllocComp = std::allocator<T>,
typename AllocMatch = AllocComp>
3758 template<
typename T,
typename AllocComp = std::allocator<T>,
typename AllocMatch = AllocComp>
3769 template<
typename ArgT,
typename MatcherT>
3778 m_matcher( matcher ),
3779 m_matcherString( matcherString )
3783 auto matcherAsString = m_matcher.toString();
3786 os << m_matcherString;
3788 os << matcherAsString;
3796 template<
typename ArgT,
typename MatcherT>
3804 #define INTERNAL_CHECK_THAT( macroName, matcher, resultDisposition, arg ) \
3806 Catch::AssertionHandler catchAssertionHandler( macroName##_catch_sr, CATCH_INTERNAL_LINEINFO, CATCH_INTERNAL_STRINGIFY(arg) ", " CATCH_INTERNAL_STRINGIFY(matcher), resultDisposition ); \
3807 INTERNAL_CATCH_TRY { \
3808 catchAssertionHandler.handleExpr( Catch::makeMatchExpr( arg, matcher, #matcher##_catch_sr ) ); \
3809 } INTERNAL_CATCH_CATCH( catchAssertionHandler ) \
3810 INTERNAL_CATCH_REACT( catchAssertionHandler ) \
3814 #define INTERNAL_CATCH_THROWS_MATCHES( macroName, exceptionType, resultDisposition, matcher, ... ) \
3816 Catch::AssertionHandler catchAssertionHandler( macroName##_catch_sr, CATCH_INTERNAL_LINEINFO, CATCH_INTERNAL_STRINGIFY(__VA_ARGS__) ", " CATCH_INTERNAL_STRINGIFY(exceptionType) ", " CATCH_INTERNAL_STRINGIFY(matcher), resultDisposition ); \
3817 if( catchAssertionHandler.allowThrows() ) \
3819 static_cast<void>(__VA_ARGS__ ); \
3820 catchAssertionHandler.handleUnexpectedExceptionNotThrown(); \
3822 catch( exceptionType const& ex ) { \
3823 catchAssertionHandler.handleExpr( Catch::makeMatchExpr( ex, matcher, #matcher##_catch_sr ) ); \
3826 catchAssertionHandler.handleUnexpectedInflightException(); \
3829 catchAssertionHandler.handleThrowingCallSkipped(); \
3830 INTERNAL_CATCH_REACT( catchAssertionHandler ) \
3871 #include <exception>
3874 #if !defined(CATCH_CONFIG_DISABLE_EXCEPTIONS)
3875 template <
typename Ex>
3894 #define CATCH_MAKE_MSG(...) \
3895 (Catch::ReusableStringStream() << __VA_ARGS__).str()
3897 #define CATCH_INTERNAL_ERROR(...) \
3898 Catch::throw_logic_error(CATCH_MAKE_MSG( CATCH_INTERNAL_LINEINFO << ": Internal Catch2 error: " << __VA_ARGS__))
3900 #define CATCH_ERROR(...) \
3901 Catch::throw_domain_error(CATCH_MAKE_MSG( __VA_ARGS__ ))
3903 #define CATCH_RUNTIME_ERROR(...) \
3904 Catch::throw_runtime_error(CATCH_MAKE_MSG( __VA_ARGS__ ))
3906 #define CATCH_ENFORCE( condition, ... ) \
3907 do{ if( !(condition) ) CATCH_ERROR( __VA_ARGS__ ); } while(false)
3915 #include <exception>
3920 const char*
const m_msg =
"";
3927 const char*
what() const noexcept override final;
3930 namespace Generators {
3934 template<
typename T,
typename... Args>
3936 return std::unique_ptr<T>(
new T(std::forward<Args>(args)...));
3940 template<
typename T>
3948 virtual T
const&
get()
const = 0;
3952 template<
typename T>
3958 T
const&
get()
const override {
3966 template<
typename T>
3969 "FixedValuesGenerator does not support bools because of std::vector<bool>"
3970 "specialization, use SingleValue Generator instead.");
3976 T
const&
get()
const override {
3977 return m_values[m_idx];
3981 return m_idx < m_values.size();
3985 template <
typename T>
3990 m_generator(std::move(generator))
3993 return m_generator->get();
3996 return m_generator->next();
4000 template <
typename T>
4004 template <
typename T>
4009 template<
typename T>
4012 size_t m_current = 0;
4015 m_generators.emplace_back(std::move(generator));
4018 m_generators.emplace_back(
value(std::forward<T>(val)));
4020 template<
typename U>
4022 populate(T(std::forward<U>(val)));
4024 template<
typename U,
typename... Gs>
4025 void populate(U&& valueOrGenerator, Gs &&... moreGenerators) {
4026 populate(std::forward<U>(valueOrGenerator));
4027 populate(std::forward<Gs>(moreGenerators)...);
4031 template <
typename... Gs>
4033 m_generators.reserve(
sizeof...(Gs));
4034 populate(std::forward<Gs>(moreGenerators)...);
4037 T
const&
get()
const override {
4038 return m_generators[m_current].get();
4042 if (m_current >= m_generators.size()) {
4045 const bool current_status = m_generators[m_current].next();
4046 if (!current_status) {
4049 return m_current < m_generators.size();
4053 template<
typename... Ts>
4054 GeneratorWrapper<std::tuple<Ts...>>
table( std::initializer_list<std::tuple<
typename std::decay<Ts>::type...>> tuples ) {
4055 return values<std::tuple<Ts...>>( tuples );
4059 template <
typename T>
4062 template<
typename T,
typename... Gs>
4064 return Generators<T>(std::move(generator), std::forward<Gs>(moreGenerators)...);
4066 template<
typename T>
4070 template<
typename T,
typename... Gs>
4072 return makeGenerators(
value( std::forward<T>( val ) ), std::forward<Gs>( moreGenerators )... );
4074 template<
typename T,
typename U,
typename... Gs>
4076 return makeGenerators(
value( T( std::forward<U>( val ) ) ), std::forward<Gs>( moreGenerators )... );
4081 template<
typename L>
4085 auto generate(
StringRef generatorName,
SourceLineInfo const& lineInfo, L
const& generatorExpression ) -> decltype(std::declval<decltype(generatorExpression())>().get()) {
4086 using UnderlyingType =
typename decltype(generatorExpression())::type;
4094 return generator.
get();
4100 #define GENERATE( ... ) \
4101 Catch::Generators::generate( INTERNAL_CATCH_STRINGIZE(INTERNAL_CATCH_UNIQUE_NAME(generator)), \
4102 CATCH_INTERNAL_LINEINFO, \
4103 [ ]{ using namespace Catch::Generators; return makeGenerators( __VA_ARGS__ ); } )
4104 #define GENERATE_COPY( ... ) \
4105 Catch::Generators::generate( INTERNAL_CATCH_STRINGIZE(INTERNAL_CATCH_UNIQUE_NAME(generator)), \
4106 CATCH_INTERNAL_LINEINFO, \
4107 [=]{ using namespace Catch::Generators; return makeGenerators( __VA_ARGS__ ); } )
4108 #define GENERATE_REF( ... ) \
4109 Catch::Generators::generate( INTERNAL_CATCH_STRINGIZE(INTERNAL_CATCH_UNIQUE_NAME(generator)), \
4110 CATCH_INTERNAL_LINEINFO, \
4111 [&]{ using namespace Catch::Generators; return makeGenerators( __VA_ARGS__ ); } )
4117 namespace Generators {
4119 template <
typename T>
4122 size_t m_returned = 0;
4126 m_generator(std::move(generator)),
4129 assert(target != 0 &&
"Empty generators are not allowed");
4131 T
const&
get()
const override {
4132 return m_generator.
get();
4136 if (m_returned >= m_target) {
4140 const auto success = m_generator.
next();
4144 m_returned = m_target;
4150 template <
typename T>
4155 template <
typename T,
typename Predicate>
4160 template <
typename P = Predicate>
4162 m_generator(std::move(generator)),
4163 m_predicate(std::forward<P>(pred))
4165 if (!m_predicate(m_generator.
get())) {
4168 auto has_initial_value = nextImpl();
4169 if (!has_initial_value) {
4175 T
const&
get()
const override {
4176 return m_generator.
get();
4185 bool success = m_generator.
next();
4189 while (!m_predicate(m_generator.
get()) && (success = m_generator.
next()) ==
true);
4194 template <
typename T,
typename Predicate>
4199 template <
typename T>
4202 "RepeatGenerator currently does not support bools"
4203 "because of std::vector<bool> specialization");
4207 size_t m_current_repeat = 0;
4208 size_t m_repeat_index = 0;
4211 m_generator(std::move(generator)),
4212 m_target_repeats(repeats)
4214 assert(m_target_repeats > 0 &&
"Repeat generator must repeat at least once");
4217 T
const&
get()
const override {
4218 if (m_current_repeat == 0) {
4219 m_returned.push_back(m_generator.
get());
4220 return m_returned.back();
4222 return m_returned[m_repeat_index];
4232 if (m_current_repeat == 0) {
4233 const auto success = m_generator.
next();
4237 return m_current_repeat < m_target_repeats;
4242 if (m_repeat_index == m_returned.size()) {
4246 return m_current_repeat < m_target_repeats;
4250 template <
typename T>
4255 template <
typename T,
typename U,
typename Func>
4263 template <
typename F2 = Func>
4265 m_generator(std::move(generator)),
4266 m_function(std::forward<F2>(function)),
4267 m_cache(m_function(m_generator.get()))
4270 T
const&
get()
const override {
4274 const auto success = m_generator.
next();
4276 m_cache = m_function(m_generator.
get());
4282 template <
typename Func,
typename U,
typename T = FunctionReturnType<Func, U>>
4289 template <
typename T,
typename U,
typename Func>
4290 GeneratorWrapper<T>
map(Func&&
function, GeneratorWrapper<U>&& generator) {
4291 return GeneratorWrapper<T>(
4292 pf::make_unique<MapGenerator<T, U, Func>>(std::forward<Func>(
function), std::move(generator))
4296 template <
typename T>
4301 bool m_used_up =
false;
4304 m_chunk_size(size), m_generator(std::move(generator))
4306 m_chunk.reserve(m_chunk_size);
4307 if (m_chunk_size != 0) {
4308 m_chunk.push_back(m_generator.
get());
4309 for (
size_t i = 1; i < m_chunk_size; ++i) {
4310 if (!m_generator.
next()) {
4313 m_chunk.push_back(m_generator.
get());
4317 std::vector<T>
const&
get()
const override {
4322 for (
size_t idx = 0; idx < m_chunk_size; ++idx) {
4323 if (!m_generator.
next()) {
4326 m_chunk.push_back(m_generator.
get());
4332 template <
typename T>
4335 pf::make_unique<ChunkGenerator<T>>(size, std::move(generator))
4351 struct IResultCapture;
4354 struct IMutableContext;
4408 template<
typename T>
4413 : nullableValue( new( storage ) T( _value ) )
4416 : nullableValue( _other ? new( storage ) T( *_other ) : nullptr )
4424 if( &_other !=
this ) {
4427 nullableValue =
new( storage ) T( *_other );
4433 nullableValue =
new( storage ) T( _value );
4439 nullableValue->~T();
4440 nullableValue =
nullptr;
4449 return nullableValue ? *nullableValue : defaultValue;
4452 bool some()
const {
return nullableValue !=
nullptr; }
4453 bool none()
const {
return nullableValue ==
nullptr; }
4455 bool operator !()
const {
return nullableValue ==
nullptr; }
4456 explicit operator bool()
const {
4462 alignas(
alignof(T))
char storage[
sizeof(T)];
4484 NoAssertions = 0x01,
4507 BeforeStartAndExit = BeforeStart | BeforeExit
4518 virtual std::string
name()
const = 0;
4543 using IConfigPtr = std::shared_ptr<IConfig const>;
4591 static const std::uint64_t s_inc = (0x13ed0cc53f939476ULL << 1ULL) | 1ULL;
4600 namespace Generators {
4602 template <
typename Float>
4605 std::uniform_real_distribution<Float>
m_dist;
4612 static_cast<void>(next());
4615 Float
const&
get()
const override {
4616 return m_current_number;
4619 m_current_number = m_dist(m_rng);
4624 template <
typename Integer>
4627 std::uniform_int_distribution<Integer>
m_dist;
4634 static_cast<void>(next());
4637 Integer
const&
get()
const override {
4638 return m_current_number;
4641 m_current_number = m_dist(m_rng);
4648 template <
typename T>
4650 GeneratorWrapper<T>>::type
4657 template <
typename T>
4659 GeneratorWrapper<T>>::type
4666 template <
typename T>
4678 m_positive(m_step > T(0))
4680 assert(m_current != m_end &&
"Range start and end cannot be equal");
4681 assert(m_step != T(0) &&
"Step size cannot be zero");
4682 assert(((m_positive && m_current <= m_end) || (!m_positive && m_current >= m_end)) &&
"Step moves away from end");
4689 T
const&
get()
const override {
4694 m_current += m_step;
4695 return (m_positive) ? (m_current < m_end) : (m_current > m_end);
4699 template <
typename T>
4705 template <
typename T>
4711 template <
typename T>
4714 "IteratorGenerator currently does not support bools"
4715 "because of std::vector<bool> specialization");
4718 size_t m_current = 0;
4720 template <
typename InputIterator,
typename InputSentinel>
4722 if (m_elems.empty()) {
4727 T
const&
get()
const override {
4728 return m_elems[m_current];
4733 return m_current != m_elems.size();
4737 template <
typename InputIterator,
4738 typename InputSentinel,
4739 typename ResultType =
typename std::iterator_traits<InputIterator>::value_type>
4744 template <
typename Container,
4745 typename ResultType =
typename Container::value_type>
4764 #pragma clang diagnostic push
4765 #pragma clang diagnostic ignored "-Wpadded"
4770 struct ITestInvoker;
4776 ShouldFail = 1 << 2,
4779 NonPortable = 1 << 5,
4784 std::string
const& _className,
4785 std::string
const& _description,
4786 std::vector<std::string>
const& _tags,
4792 bool throws()
const;
4822 std::shared_ptr<ITestInvoker>
test;
4826 std::string
const& className,
4832 #pragma clang diagnostic pop
4851 #import <objc/runtime.h>
4873 class OcMethod :
public ITestInvoker {
4876 OcMethod( Class cls,
SEL sel ) : m_cls( cls ), m_sel( sel ) {}
4878 virtual void invoke()
const {
4879 id obj = [[m_cls alloc] init];
4881 performOptionalSelector( obj,
@selector(setUp) );
4882 performOptionalSelector( obj, m_sel );
4883 performOptionalSelector( obj,
@selector(tearDown) );
4885 arcSafeRelease( obj );
4888 virtual ~OcMethod() {}
4896 inline std::string getAnnotation( Class cls,
4897 std::string
const& annotationName,
4898 std::string
const& testCaseName ) {
4899 NSString* selStr = [[NSString alloc] initWithFormat:@"Catch_%s_%s", annotationName.c_str(), testCaseName.c_str()];
4900 SEL sel = NSSelectorFromString( selStr );
4901 arcSafeRelease( selStr );
4902 id value = performOptionalSelector( cls, sel );
4904 return [(NSString*)value UTF8String];
4909 inline std::size_t registerTestMethods() {
4910 std::size_t noTestMethods = 0;
4911 int noClasses = objc_getClassList(
nullptr, 0 );
4913 Class* classes = (CATCH_UNSAFE_UNRETAINED Class *)malloc(
sizeof(Class) * noClasses);
4914 objc_getClassList( classes, noClasses );
4916 for(
int c = 0; c < noClasses; c++ ) {
4917 Class cls = classes[c];
4920 Method* methods = class_copyMethodList( cls, &count );
4921 for( u_int m = 0; m < count ; m++ ) {
4922 SEL selector = method_getName(methods[m]);
4923 std::string methodName = sel_getName(selector);
4924 if(
startsWith( methodName,
"Catch_TestCase_" ) ) {
4925 std::string testCaseName = methodName.substr( 15 );
4926 std::string name = Detail::getAnnotation( cls,
"Name", testCaseName );
4927 std::string desc = Detail::getAnnotation( cls,
"Description", testCaseName );
4928 const char* className = class_getName( cls );
4937 return noTestMethods;
4940 #if !defined(CATCH_CONFIG_DISABLE_MATCHERS)
4942 namespace Matchers {
4944 namespace NSStringMatchers {
4946 struct StringHolder : MatcherBase<NSString*>{
4947 StringHolder( NSString* substr ) : m_substr( [substr copy] ){}
4948 StringHolder( StringHolder
const& other ) : m_substr( [other.m_substr copy] ){}
4950 arcSafeRelease( m_substr );
4953 bool match( NSString* str )
const override {
4957 NSString* CATCH_ARC_STRONG m_substr;
4960 struct Equals : StringHolder {
4961 Equals( NSString* substr ) : StringHolder( substr ){}
4963 bool match( NSString* str )
const override {
4964 return (str != nil || m_substr == nil ) &&
4965 [str isEqualToString:m_substr];
4968 std::string describe()
const override {
4969 return "equals string: " +
Catch::Detail::stringify( m_substr );
4974 Contains( NSString* substr ) : StringHolder( substr ){}
4976 bool match( NSString* str )
const override {
4977 return (str != nil || m_substr == nil ) &&
4978 [str rangeOfString:m_substr].location != NSNotFound;
4981 std::string describe()
const override {
4982 return "contains string: " +
Catch::Detail::stringify( m_substr );
4987 StartsWith( NSString* substr ) : StringHolder( substr ){}
4989 bool match( NSString* str )
const override {
4990 return (str != nil || m_substr == nil ) &&
4991 [str rangeOfString:m_substr].location == 0;
4994 std::string describe()
const override {
4995 return "starts with: " +
Catch::Detail::stringify( m_substr );
4999 EndsWith( NSString* substr ) : StringHolder( substr ){}
5001 bool match( NSString* str )
const override {
5002 return (str != nil || m_substr == nil ) &&
5003 [str rangeOfString:m_substr].location == [str length] - [m_substr length];
5006 std::string describe()
const override {
5007 return "ends with: " +
Catch::Detail::stringify( m_substr );
5028 using namespace Matchers;
5035 #define OC_MAKE_UNIQUE_NAME( root, uniqueSuffix ) root##uniqueSuffix
5036 #define OC_TEST_CASE2( name, desc, uniqueSuffix ) \
5037 +(NSString*) OC_MAKE_UNIQUE_NAME( Catch_Name_test_, uniqueSuffix ) \
5041 +(NSString*) OC_MAKE_UNIQUE_NAME( Catch_Description_test_, uniqueSuffix ) \
5045 -(void) OC_MAKE_UNIQUE_NAME( Catch_TestCase_test_, uniqueSuffix )
5047 #define OC_TEST_CASE( name, desc ) OC_TEST_CASE2( name, desc, __LINE__ )
5053 #if defined(CATCH_CONFIG_EXTERNAL_INTERFACES) || defined(CATCH_CONFIG_ENABLE_BENCHMARKING)
5065 #pragma clang diagnostic push
5066 #pragma clang diagnostic ignored "-Wpadded"
5072 #pragma clang diagnostic push
5073 #pragma clang diagnostic ignored "-Wpadded"
5080 class WildcardPattern {
5081 enum WildcardPosition {
5083 WildcardAtStart = 1,
5085 WildcardAtBothEnds = WildcardAtStart | WildcardAtEnd
5091 virtual ~WildcardPattern() =
default;
5092 virtual bool matches( std::string
const& str )
const;
5095 std::string normaliseString( std::string
const& str )
const;
5097 WildcardPosition m_wildcard = NoWildcard;
5098 std::string m_pattern;
5114 explicit Pattern( std::string
const& name );
5116 virtual bool matches( TestCaseInfo
const& testCase )
const = 0;
5117 std::string
const& name()
const;
5119 std::string
const m_name;
5121 using PatternPtr = std::shared_ptr<Pattern>;
5123 class NamePattern :
public Pattern {
5125 explicit NamePattern( std::string
const& name, std::string
const& filterString );
5126 bool matches( TestCaseInfo
const& testCase )
const override;
5128 WildcardPattern m_wildcardPattern;
5131 class TagPattern :
public Pattern {
5133 explicit TagPattern( std::string
const& tag, std::string
const& filterString );
5134 bool matches( TestCaseInfo
const& testCase )
const override;
5139 class ExcludedPattern :
public Pattern {
5141 explicit ExcludedPattern( PatternPtr
const& underlyingPattern );
5142 bool matches( TestCaseInfo
const& testCase )
const override;
5144 PatternPtr m_underlyingPattern;
5148 std::vector<PatternPtr> m_patterns;
5150 bool matches( TestCaseInfo
const& testCase )
const;
5151 std::string name()
const;
5155 struct FilterMatch {
5157 std::vector<TestCase const*> tests;
5159 using Matches = std::vector<FilterMatch>;
5160 using vectorStrings = std::vector<std::string>;
5162 bool hasFilters()
const;
5163 bool matches( TestCaseInfo
const& testCase )
const;
5164 Matches matchesByFilter( std::vector<TestCase>
const& testCases, IConfig
const& config )
const;
5165 const vectorStrings & getInvalidArgs()
const;
5168 std::vector<Filter> m_filters;
5169 std::vector<std::string> m_invalidArgs;
5170 friend class TestSpecParser;
5175 #pragma clang diagnostic pop
5187 struct ITagAliasRegistry {
5188 virtual ~ITagAliasRegistry();
5190 virtual TagAlias
const* find( std::string
const& alias )
const = 0;
5191 virtual std::string expandAliases( std::string
const& unexpandedTestSpec )
const = 0;
5193 static ITagAliasRegistry
const& get();
5201 class TestSpecParser {
5202 enum Mode{ None, Name, QuotedName, Tag, EscapedName };
5204 Mode lastMode = None;
5205 bool m_exclusion =
false;
5206 std::size_t m_pos = 0;
5207 std::size_t m_realPatternPos = 0;
5209 std::string m_substring;
5210 std::string m_patternName;
5211 std::vector<std::size_t> m_escapeChars;
5212 TestSpec::Filter m_currentFilter;
5213 TestSpec m_testSpec;
5214 ITagAliasRegistry
const* m_tagAliases =
nullptr;
5217 TestSpecParser( ITagAliasRegistry
const& tagAliases );
5219 TestSpecParser& parse( std::string
const& arg );
5220 TestSpec testSpec();
5223 bool visitChar(
char c );
5224 void startNewMode( Mode mode );
5225 bool processNoneChar(
char c );
5226 void processNameChar(
char c );
5227 bool processOtherChar(
char c );
5230 bool isControlChar(
char c )
const;
5231 void saveLastMode();
5232 void revertBackToLastMode();
5237 std::string preprocessPattern();
5239 void addNamePattern();
5241 void addTagPattern();
5243 inline void addCharToPattern(
char c) {
5250 TestSpec parseTestSpec( std::string
const& arg );
5255 #pragma clang diagnostic pop
5265 #ifndef CATCH_CONFIG_CONSOLE_WIDTH
5266 #define CATCH_CONFIG_CONSOLE_WIDTH 80
5274 bool listTests =
false;
5275 bool listTags =
false;
5276 bool listReporters =
false;
5277 bool listTestNamesOnly =
false;
5279 bool showSuccessfulTests =
false;
5280 bool shouldDebugBreak =
false;
5281 bool noThrow =
false;
5282 bool showHelp =
false;
5283 bool showInvisibles =
false;
5284 bool filenamesAsTags =
false;
5285 bool libIdentify =
false;
5287 int abortAfter = -1;
5290 bool benchmarkNoAnalysis =
false;
5291 unsigned int benchmarkSamples = 100;
5292 double benchmarkConfidenceInterval = 0.95;
5293 unsigned int benchmarkResamples = 100000;
5294 std::chrono::milliseconds::rep benchmarkWarmupTime = 100;
5299 double minDuration = -1;
5304 std::string outputFilename;
5306 std::string processName;
5307 #ifndef CATCH_CONFIG_DEFAULT_REPORTER
5308 #define CATCH_CONFIG_DEFAULT_REPORTER "console"
5310 std::string reporterName = CATCH_CONFIG_DEFAULT_REPORTER;
5311 #undef CATCH_CONFIG_DEFAULT_REPORTER
5313 std::vector<std::string> testsOrTags;
5314 std::vector<std::string> sectionsToRun;
5317 class Config :
public IConfig {
5321 Config( ConfigData
const& data );
5322 virtual ~Config() =
default;
5324 std::string
const& getFilename()
const;
5326 bool listTests()
const;
5327 bool listTestNamesOnly()
const;
5328 bool listTags()
const;
5329 bool listReporters()
const;
5331 std::string getProcessName()
const;
5332 std::string
const& getReporterName()
const;
5334 std::vector<std::string>
const& getTestsOrTags()
const override;
5335 std::vector<std::string>
const& getSectionsToRun()
const override;
5337 TestSpec
const& testSpec()
const override;
5338 bool hasTestFilters()
const override;
5340 bool showHelp()
const;
5344 std::ostream& stream()
const override;
5345 std::string name()
const override;
5346 bool includeSuccessfulResults()
const override;
5347 bool warnAboutMissingAssertions()
const override;
5348 bool warnAboutNoTests()
const override;
5350 double minDuration()
const override;
5352 unsigned int rngSeed()
const override;
5354 bool shouldDebugBreak()
const override;
5355 int abortAfter()
const override;
5356 bool showInvisibles()
const override;
5358 bool benchmarkNoAnalysis()
const override;
5359 int benchmarkSamples()
const override;
5360 double benchmarkConfidenceInterval()
const override;
5361 unsigned int benchmarkResamples()
const override;
5362 std::chrono::milliseconds benchmarkWarmupTime()
const override;
5366 IStream
const* openStream();
5369 std::unique_ptr<IStream const> m_stream;
5370 TestSpec m_testSpec;
5371 bool m_hasTestFilters =
false;
5383 struct AssertionResultData
5385 AssertionResultData() =
delete;
5387 AssertionResultData(
ResultWas::OfType _resultType, LazyExpression
const& _lazyExpression );
5389 std::string message;
5390 mutable std::string reconstructedExpression;
5391 LazyExpression lazyExpression;
5394 std::string reconstructExpression()
const;
5397 class AssertionResult {
5399 AssertionResult() =
delete;
5400 AssertionResult( AssertionInfo
const& info, AssertionResultData
const& data );
5403 bool succeeded()
const;
5405 bool hasExpression()
const;
5406 bool hasMessage()
const;
5407 std::string getExpression()
const;
5408 std::string getExpressionInMacro()
const;
5409 bool hasExpandedExpression()
const;
5410 std::string getExpandedExpression()
const;
5411 std::string getMessage()
const;
5412 SourceLineInfo getSourceInfo()
const;
5413 StringRef getTestMacroName()
const;
5416 AssertionInfo m_info;
5417 AssertionResultData m_resultData;
5423 #if defined(CATCH_CONFIG_ENABLE_BENCHMARKING)
5430 namespace Benchmark {
5431 template <
typename Duration>
5434 Duration lower_bound;
5435 Duration upper_bound;
5436 double confidence_interval;
5438 template <
typename Duration2>
5439 operator Estimate<Duration2>()
const {
5440 return { point, lower_bound, upper_bound, confidence_interval };
5452 namespace Benchmark {
5453 struct OutlierClassification {
5454 int samples_seen = 0;
5458 int high_severe = 0;
5461 return low_severe + low_mild + high_mild + high_severe;
5477 #include <algorithm>
5481 struct ReporterConfig {
5482 explicit ReporterConfig(
IConfigPtr const& _fullConfig );
5484 ReporterConfig(
IConfigPtr const& _fullConfig, std::ostream& _stream );
5486 std::ostream& stream()
const;
5490 std::ostream* m_stream;
5494 struct ReporterPreferences {
5495 bool shouldRedirectStdOut =
false;
5496 bool shouldReportAllAssertions =
false;
5499 template<
typename T>
5500 struct LazyStat : Option<T> {
5501 LazyStat& operator=( T
const& _value ) {
5513 struct TestRunInfo {
5514 TestRunInfo( std::string
const& _name );
5518 GroupInfo( std::string
const& _name,
5519 std::size_t _groupIndex,
5520 std::size_t _groupsCount );
5523 std::size_t groupIndex;
5524 std::size_t groupsCounts;
5527 struct AssertionStats {
5528 AssertionStats( AssertionResult
const& _assertionResult,
5529 std::vector<MessageInfo>
const& _infoMessages,
5530 Totals
const& _totals );
5532 AssertionStats( AssertionStats
const& ) =
default;
5533 AssertionStats( AssertionStats && ) =
default;
5534 AssertionStats& operator = ( AssertionStats
const& ) =
delete;
5535 AssertionStats& operator = ( AssertionStats && ) =
delete;
5536 virtual ~AssertionStats();
5538 AssertionResult assertionResult;
5539 std::vector<MessageInfo> infoMessages;
5543 struct SectionStats {
5544 SectionStats( SectionInfo
const& _sectionInfo,
5545 Counts
const& _assertions,
5546 double _durationInSeconds,
5547 bool _missingAssertions );
5548 SectionStats( SectionStats
const& ) =
default;
5549 SectionStats( SectionStats && ) =
default;
5550 SectionStats& operator = ( SectionStats
const& ) =
default;
5551 SectionStats& operator = ( SectionStats && ) =
default;
5552 virtual ~SectionStats();
5554 SectionInfo sectionInfo;
5556 double durationInSeconds;
5557 bool missingAssertions;
5560 struct TestCaseStats {
5561 TestCaseStats( TestCaseInfo
const& _testInfo,
5562 Totals
const& _totals,
5563 std::string
const& _stdOut,
5564 std::string
const& _stdErr,
5567 TestCaseStats( TestCaseStats
const& ) =
default;
5568 TestCaseStats( TestCaseStats && ) =
default;
5569 TestCaseStats& operator = ( TestCaseStats
const& ) =
default;
5570 TestCaseStats& operator = ( TestCaseStats && ) =
default;
5571 virtual ~TestCaseStats();
5573 TestCaseInfo testInfo;
5580 struct TestGroupStats {
5581 TestGroupStats( GroupInfo
const& _groupInfo,
5582 Totals
const& _totals,
5584 TestGroupStats( GroupInfo
const& _groupInfo );
5586 TestGroupStats( TestGroupStats
const& ) =
default;
5587 TestGroupStats( TestGroupStats && ) =
default;
5588 TestGroupStats& operator = ( TestGroupStats
const& ) =
default;
5589 TestGroupStats& operator = ( TestGroupStats && ) =
default;
5590 virtual ~TestGroupStats();
5592 GroupInfo groupInfo;
5597 struct TestRunStats {
5598 TestRunStats( TestRunInfo
const& _runInfo,
5599 Totals
const& _totals,
5602 TestRunStats( TestRunStats
const& ) =
default;
5603 TestRunStats( TestRunStats && ) =
default;
5604 TestRunStats& operator = ( TestRunStats
const& ) =
default;
5605 TestRunStats& operator = ( TestRunStats && ) =
default;
5606 virtual ~TestRunStats();
5608 TestRunInfo runInfo;
5613 #if defined(CATCH_CONFIG_ENABLE_BENCHMARKING)
5614 struct BenchmarkInfo {
5616 double estimatedDuration;
5619 unsigned int resamples;
5620 double clockResolution;
5624 template <
class Duration>
5625 struct BenchmarkStats {
5628 std::vector<Duration> samples;
5629 Benchmark::Estimate<Duration> mean;
5630 Benchmark::Estimate<Duration> standardDeviation;
5631 Benchmark::OutlierClassification outliers;
5632 double outlierVariance;
5634 template <
typename Duration2>
5635 operator BenchmarkStats<Duration2>()
const {
5636 std::vector<Duration2> samples2;
5637 samples2.reserve(samples.size());
5638 std::transform(samples.begin(), samples.end(), std::back_inserter(samples2), [](Duration d) { return Duration2(d); });
5641 std::move(samples2),
5651 struct IStreamingReporter {
5652 virtual ~IStreamingReporter() =
default;
5658 virtual ReporterPreferences getPreferences()
const = 0;
5660 virtual void noMatchingTestCases( std::string
const& spec ) = 0;
5662 virtual void reportInvalidArguments(std::string
const&) {}
5664 virtual void testRunStarting( TestRunInfo
const& testRunInfo ) = 0;
5665 virtual void testGroupStarting( GroupInfo
const& groupInfo ) = 0;
5667 virtual void testCaseStarting( TestCaseInfo
const& testInfo ) = 0;
5668 virtual void sectionStarting( SectionInfo
const& sectionInfo ) = 0;
5670 #if defined(CATCH_CONFIG_ENABLE_BENCHMARKING)
5671 virtual void benchmarkPreparing( std::string
const& ) {}
5672 virtual void benchmarkStarting( BenchmarkInfo
const& ) {}
5673 virtual void benchmarkEnded( BenchmarkStats<>
const& ) {}
5674 virtual void benchmarkFailed( std::string
const& ) {}
5677 virtual void assertionStarting( AssertionInfo
const& assertionInfo ) = 0;
5680 virtual bool assertionEnded( AssertionStats
const& assertionStats ) = 0;
5682 virtual void sectionEnded( SectionStats
const& sectionStats ) = 0;
5683 virtual void testCaseEnded( TestCaseStats
const& testCaseStats ) = 0;
5684 virtual void testGroupEnded( TestGroupStats
const& testGroupStats ) = 0;
5685 virtual void testRunEnded( TestRunStats
const& testRunStats ) = 0;
5687 virtual void skipTest( TestCaseInfo
const& testInfo ) = 0;
5690 virtual void fatalErrorEncountered( StringRef name );
5692 virtual bool isMulti()
const;
5694 using IStreamingReporterPtr = std::unique_ptr<IStreamingReporter>;
5696 struct IReporterFactory {
5697 virtual ~IReporterFactory();
5698 virtual IStreamingReporterPtr create( ReporterConfig
const& config )
const = 0;
5699 virtual std::string getDescription()
const = 0;
5703 struct IReporterRegistry {
5704 using FactoryMap = std::map<std::string, IReporterFactoryPtr>;
5705 using Listeners = std::vector<IReporterFactoryPtr>;
5707 virtual ~IReporterRegistry();
5708 virtual IStreamingReporterPtr create( std::string
const& name,
IConfigPtr const& config )
const = 0;
5709 virtual FactoryMap
const& getFactories()
const = 0;
5710 virtual Listeners
const& getListeners()
const = 0;
5716 #include <algorithm>
5725 void prepareExpandedExpression(AssertionResult& result);
5728 std::string getFormattedDuration(
double duration );
5731 bool shouldShowDuration( IConfig
const& config,
double duration );
5733 std::string serializeFilters( std::vector<std::string>
const& container );
5735 template<
typename DerivedT>
5736 struct StreamingReporterBase : IStreamingReporter {
5738 StreamingReporterBase( ReporterConfig
const& _config )
5739 : m_config( _config.fullConfig() ),
5740 stream( _config.stream() )
5742 m_reporterPrefs.shouldRedirectStdOut =
false;
5743 if( !DerivedT::getSupportedVerbosities().count( m_config->verbosity() ) )
5744 CATCH_ERROR(
"Verbosity level not supported by this reporter" );
5747 ReporterPreferences getPreferences()
const override {
5748 return m_reporterPrefs;
5751 static std::set<Verbosity> getSupportedVerbosities() {
5755 ~StreamingReporterBase()
override =
default;
5757 void noMatchingTestCases(std::string
const&)
override {}
5759 void reportInvalidArguments(std::string
const&)
override {}
5761 void testRunStarting(TestRunInfo
const& _testRunInfo)
override {
5762 currentTestRunInfo = _testRunInfo;
5765 void testGroupStarting(GroupInfo
const& _groupInfo)
override {
5766 currentGroupInfo = _groupInfo;
5769 void testCaseStarting(TestCaseInfo
const& _testInfo)
override {
5770 currentTestCaseInfo = _testInfo;
5772 void sectionStarting(SectionInfo
const& _sectionInfo)
override {
5773 m_sectionStack.push_back(_sectionInfo);
5776 void sectionEnded(SectionStats
const& )
override {
5777 m_sectionStack.pop_back();
5779 void testCaseEnded(TestCaseStats
const& )
override {
5780 currentTestCaseInfo.reset();
5782 void testGroupEnded(TestGroupStats
const& )
override {
5783 currentGroupInfo.reset();
5785 void testRunEnded(TestRunStats
const& )
override {
5786 currentTestCaseInfo.reset();
5787 currentGroupInfo.reset();
5788 currentTestRunInfo.reset();
5791 void skipTest(TestCaseInfo
const&)
override {
5797 std::ostream& stream;
5799 LazyStat<TestRunInfo> currentTestRunInfo;
5800 LazyStat<GroupInfo> currentGroupInfo;
5801 LazyStat<TestCaseInfo> currentTestCaseInfo;
5803 std::vector<SectionInfo> m_sectionStack;
5804 ReporterPreferences m_reporterPrefs;
5807 template<
typename DerivedT>
5808 struct CumulativeReporterBase : IStreamingReporter {
5809 template<
typename T,
typename ChildNodeT>
5811 explicit Node( T
const& _value ) :
value( _value ) {}
5814 using ChildNodes = std::vector<std::shared_ptr<ChildNodeT>>;
5816 ChildNodes children;
5818 struct SectionNode {
5819 explicit SectionNode(SectionStats
const& _stats) : stats(_stats) {}
5820 virtual ~SectionNode() =
default;
5822 bool operator == (SectionNode
const& other)
const {
5823 return stats.sectionInfo.lineInfo == other.stats.sectionInfo.lineInfo;
5825 bool operator == (std::shared_ptr<SectionNode>
const& other)
const {
5830 using ChildSections = std::vector<std::shared_ptr<SectionNode>>;
5831 using Assertions = std::vector<AssertionStats>;
5832 ChildSections childSections;
5833 Assertions assertions;
5838 struct BySectionInfo {
5839 BySectionInfo( SectionInfo
const& other ) : m_other( other ) {}
5840 BySectionInfo( BySectionInfo
const& other ) : m_other( other.m_other ) {}
5841 bool operator() (std::shared_ptr<SectionNode>
const& node)
const {
5842 return ((node->stats.sectionInfo.name == m_other.name) &&
5843 (node->stats.sectionInfo.lineInfo == m_other.lineInfo));
5845 void operator=(BySectionInfo
const&) =
delete;
5848 SectionInfo
const& m_other;
5851 using TestCaseNode = Node<TestCaseStats, SectionNode>;
5852 using TestGroupNode = Node<TestGroupStats, TestCaseNode>;
5853 using TestRunNode = Node<TestRunStats, TestGroupNode>;
5855 CumulativeReporterBase( ReporterConfig
const& _config )
5856 : m_config( _config.fullConfig() ),
5857 stream( _config.stream() )
5859 m_reporterPrefs.shouldRedirectStdOut =
false;
5860 if( !DerivedT::getSupportedVerbosities().count( m_config->verbosity() ) )
5861 CATCH_ERROR(
"Verbosity level not supported by this reporter" );
5863 ~CumulativeReporterBase()
override =
default;
5865 ReporterPreferences getPreferences()
const override {
5866 return m_reporterPrefs;
5869 static std::set<Verbosity> getSupportedVerbosities() {
5873 void testRunStarting( TestRunInfo
const& )
override {}
5874 void testGroupStarting( GroupInfo
const& )
override {}
5876 void testCaseStarting( TestCaseInfo
const& )
override {}
5878 void sectionStarting( SectionInfo
const& sectionInfo )
override {
5879 SectionStats incompleteStats( sectionInfo, Counts(), 0,
false );
5880 std::shared_ptr<SectionNode> node;
5881 if( m_sectionStack.empty() ) {
5882 if( !m_rootSection )
5883 m_rootSection = std::make_shared<SectionNode>( incompleteStats );
5884 node = m_rootSection;
5887 SectionNode& parentNode = *m_sectionStack.back();
5889 std::find_if( parentNode.childSections.begin(),
5890 parentNode.childSections.end(),
5891 BySectionInfo( sectionInfo ) );
5892 if(
it == parentNode.childSections.end() ) {
5893 node = std::make_shared<SectionNode>( incompleteStats );
5894 parentNode.childSections.push_back( node );
5899 m_sectionStack.push_back( node );
5900 m_deepestSection = std::move(node);
5903 void assertionStarting(AssertionInfo
const&)
override {}
5905 bool assertionEnded(AssertionStats
const& assertionStats)
override {
5906 assert(!m_sectionStack.empty());
5912 prepareExpandedExpression(
const_cast<AssertionResult&
>( assertionStats.assertionResult ) );
5913 SectionNode& sectionNode = *m_sectionStack.back();
5914 sectionNode.assertions.push_back(assertionStats);
5917 void sectionEnded(SectionStats
const& sectionStats)
override {
5918 assert(!m_sectionStack.empty());
5919 SectionNode& node = *m_sectionStack.back();
5920 node.stats = sectionStats;
5921 m_sectionStack.pop_back();
5923 void testCaseEnded(TestCaseStats
const& testCaseStats)
override {
5924 auto node = std::make_shared<TestCaseNode>(testCaseStats);
5925 assert(m_sectionStack.size() == 0);
5926 node->children.push_back(m_rootSection);
5927 m_testCases.push_back(node);
5928 m_rootSection.reset();
5930 assert(m_deepestSection);
5931 m_deepestSection->stdOut = testCaseStats.stdOut;
5932 m_deepestSection->stdErr = testCaseStats.stdErr;
5934 void testGroupEnded(TestGroupStats
const& testGroupStats)
override {
5935 auto node = std::make_shared<TestGroupNode>(testGroupStats);
5936 node->children.swap(m_testCases);
5937 m_testGroups.push_back(node);
5939 void testRunEnded(TestRunStats
const& testRunStats)
override {
5940 auto node = std::make_shared<TestRunNode>(testRunStats);
5941 node->children.swap(m_testGroups);
5942 m_testRuns.push_back(node);
5943 testRunEndedCumulative();
5945 virtual void testRunEndedCumulative() = 0;
5947 void skipTest(TestCaseInfo
const&)
override {}
5950 std::ostream& stream;
5951 std::vector<AssertionStats> m_assertions;
5952 std::vector<std::vector<std::shared_ptr<SectionNode>>> m_sections;
5953 std::vector<std::shared_ptr<TestCaseNode>> m_testCases;
5954 std::vector<std::shared_ptr<TestGroupNode>> m_testGroups;
5956 std::vector<std::shared_ptr<TestRunNode>> m_testRuns;
5958 std::shared_ptr<SectionNode> m_rootSection;
5959 std::shared_ptr<SectionNode> m_deepestSection;
5960 std::vector<std::shared_ptr<SectionNode>> m_sectionStack;
5961 ReporterPreferences m_reporterPrefs;
5965 char const* getLineOfChars() {
5966 static char line[CATCH_CONFIG_CONSOLE_WIDTH] = {0};
5968 std::memset( line, C, CATCH_CONFIG_CONSOLE_WIDTH-1 );
5969 line[CATCH_CONFIG_CONSOLE_WIDTH-1] = 0;
5974 struct TestEventListenerBase : StreamingReporterBase<TestEventListenerBase> {
5975 TestEventListenerBase( ReporterConfig
const& _config );
5977 static std::set<Verbosity> getSupportedVerbosities();
5979 void assertionStarting(AssertionInfo
const&)
override;
5980 bool assertionEnded(AssertionStats
const&)
override;
6004 BrightRed = Bright | Red,
6005 BrightGreen = Bright | Green,
6006 LightGrey = Bright | Grey,
6007 BrightWhite = Bright | White,
6008 BrightYellow = Bright | Yellow,
6011 FileName = LightGrey,
6012 Warning = BrightYellow,
6013 ResultError = BrightRed,
6014 ResultSuccess = BrightGreen,
6015 ResultExpectedFailure = Warning,
6020 OriginalExpression = Cyan,
6021 ReconstructedExpression = BrightYellow,
6023 SecondaryText = LightGrey,
6028 Colour( Code _colourCode );
6029 Colour( Colour&& other ) noexcept;
6030 Colour& operator=( Colour&& other ) noexcept;
6034 static void use( Code _colourCode );
6037 bool m_moved =
false;
6040 std::ostream&
operator << ( std::ostream& os, Colour
const& );
6050 template<
typename T>
6051 class ReporterRegistrar {
6053 class ReporterFactory :
public IReporterFactory {
6055 IStreamingReporterPtr create( ReporterConfig
const& config )
const override {
6056 return std::unique_ptr<T>(
new T( config ) );
6059 std::string getDescription()
const override {
6060 return T::getDescription();
6066 explicit ReporterRegistrar( std::string
const& name ) {
6071 template<
typename T>
6072 class ListenerRegistrar {
6074 class ListenerFactory :
public IReporterFactory {
6076 IStreamingReporterPtr create( ReporterConfig
const& config )
const override {
6077 return std::unique_ptr<T>(
new T( config ) );
6079 std::string getDescription()
const override {
6080 return std::string();
6086 ListenerRegistrar() {
6092 #if !defined(CATCH_CONFIG_DISABLE)
6094 #define CATCH_REGISTER_REPORTER( name, reporterType ) \
6095 CATCH_INTERNAL_START_WARNINGS_SUPPRESSION \
6096 CATCH_INTERNAL_SUPPRESS_GLOBALS_WARNINGS \
6097 namespace{ Catch::ReporterRegistrar<reporterType> catch_internal_RegistrarFor##reporterType( name ); } \
6098 CATCH_INTERNAL_STOP_WARNINGS_SUPPRESSION
6100 #define CATCH_REGISTER_LISTENER( listenerType ) \
6101 CATCH_INTERNAL_START_WARNINGS_SUPPRESSION \
6102 CATCH_INTERNAL_SUPPRESS_GLOBALS_WARNINGS \
6103 namespace{ Catch::ListenerRegistrar<listenerType> catch_internal_RegistrarFor##listenerType; } \
6104 CATCH_INTERNAL_STOP_WARNINGS_SUPPRESSION
6107 #define CATCH_REGISTER_REPORTER(name, reporterType)
6108 #define CATCH_REGISTER_LISTENER(listenerType)
6118 struct CompactReporter : StreamingReporterBase<CompactReporter> {
6120 using StreamingReporterBase::StreamingReporterBase;
6122 ~CompactReporter()
override;
6124 static std::string getDescription();
6126 void noMatchingTestCases(std::string
const& spec)
override;
6128 void assertionStarting(AssertionInfo
const&)
override;
6130 bool assertionEnded(AssertionStats
const& _assertionStats)
override;
6132 void sectionEnded(SectionStats
const& _sectionStats)
override;
6134 void testRunEnded(TestRunStats
const& _testRunStats)
override;
6143 #if defined(_MSC_VER)
6144 #pragma warning(push)
6145 #pragma warning(disable:4061)
6152 struct SummaryColumn;
6155 struct ConsoleReporter : StreamingReporterBase<ConsoleReporter> {
6156 std::unique_ptr<TablePrinter> m_tablePrinter;
6158 ConsoleReporter(ReporterConfig
const& config);
6159 ~ConsoleReporter()
override;
6160 static std::string getDescription();
6162 void noMatchingTestCases(std::string
const& spec)
override;
6164 void reportInvalidArguments(std::string
const&arg)
override;
6166 void assertionStarting(AssertionInfo
const&)
override;
6168 bool assertionEnded(AssertionStats
const& _assertionStats)
override;
6170 void sectionStarting(SectionInfo
const& _sectionInfo)
override;
6171 void sectionEnded(SectionStats
const& _sectionStats)
override;
6173 #if defined(CATCH_CONFIG_ENABLE_BENCHMARKING)
6174 void benchmarkPreparing(std::string
const& name)
override;
6175 void benchmarkStarting(BenchmarkInfo
const& info)
override;
6176 void benchmarkEnded(BenchmarkStats<>
const& stats)
override;
6177 void benchmarkFailed(std::string
const& error)
override;
6180 void testCaseEnded(TestCaseStats
const& _testCaseStats)
override;
6181 void testGroupEnded(TestGroupStats
const& _testGroupStats)
override;
6182 void testRunEnded(TestRunStats
const& _testRunStats)
override;
6183 void testRunStarting(TestRunInfo
const& _testRunInfo)
override;
6188 void lazyPrintWithoutClosingBenchmarkTable();
6189 void lazyPrintRunInfo();
6190 void lazyPrintGroupInfo();
6191 void printTestCaseAndSectionHeader();
6193 void printClosedHeader(std::string
const& _name);
6194 void printOpenHeader(std::string
const& _name);
6198 void printHeaderString(std::string
const& _string, std::size_t indent = 0);
6200 void printTotals(Totals
const& totals);
6201 void printSummaryRow(std::string
const& label, std::vector<SummaryColumn>
const& cols, std::size_t row);
6203 void printTotalsDivider(Totals
const& totals);
6204 void printSummaryDivider();
6205 void printTestFilters();
6208 bool m_headerPrinted =
false;
6213 #if defined(_MSC_VER)
6214 #pragma warning(pop)
6225 enum class XmlFormatting {
6231 XmlFormatting
operator | (XmlFormatting lhs, XmlFormatting rhs);
6232 XmlFormatting operator & (XmlFormatting lhs, XmlFormatting rhs);
6236 enum ForWhat { ForTextNodes, ForAttributes };
6238 XmlEncode( std::string
const& str, ForWhat forWhat = ForTextNodes );
6240 void encodeTo( std::ostream& os )
const;
6242 friend std::ostream&
operator << ( std::ostream& os, XmlEncode
const& xmlEncode );
6252 class ScopedElement {
6254 ScopedElement( XmlWriter* writer, XmlFormatting fmt );
6256 ScopedElement( ScopedElement&& other ) noexcept;
6257 ScopedElement& operator=( ScopedElement&& other ) noexcept;
6261 ScopedElement& writeText( std::string
const& text, XmlFormatting fmt = XmlFormatting::Newline | XmlFormatting::Indent );
6263 template<
typename T>
6264 ScopedElement& writeAttribute( std::string
const& name, T
const& attribute ) {
6265 m_writer->writeAttribute( name, attribute );
6270 mutable XmlWriter* m_writer =
nullptr;
6271 XmlFormatting m_fmt;
6277 XmlWriter( XmlWriter
const& ) =
delete;
6278 XmlWriter& operator=( XmlWriter
const& ) =
delete;
6280 XmlWriter& startElement( std::string
const& name, XmlFormatting fmt = XmlFormatting::Newline | XmlFormatting::Indent);
6282 ScopedElement scopedElement( std::string
const& name, XmlFormatting fmt = XmlFormatting::Newline | XmlFormatting::Indent);
6284 XmlWriter& endElement(XmlFormatting fmt = XmlFormatting::Newline | XmlFormatting::Indent);
6286 XmlWriter& writeAttribute( std::string
const& name, std::string
const& attribute );
6288 XmlWriter& writeAttribute( std::string
const& name,
bool attribute );
6290 template<
typename T>
6291 XmlWriter& writeAttribute( std::string
const& name, T
const& attribute ) {
6292 ReusableStringStream rss;
6294 return writeAttribute( name, rss.str() );
6297 XmlWriter& writeText( std::string
const& text, XmlFormatting fmt = XmlFormatting::Newline | XmlFormatting::Indent);
6299 XmlWriter& writeComment(std::string
const& text, XmlFormatting fmt = XmlFormatting::Newline | XmlFormatting::Indent);
6301 void writeStylesheetRef( std::string
const& url );
6303 XmlWriter& writeBlankLine();
6305 void ensureTagClosed();
6309 void applyFormatting(XmlFormatting fmt);
6311 void writeDeclaration();
6313 void newlineIfNecessary();
6315 bool m_tagIsOpen =
false;
6316 bool m_needsNewline =
false;
6317 std::vector<std::string> m_tags;
6318 std::string m_indent;
6327 class JunitReporter :
public CumulativeReporterBase<JunitReporter> {
6329 JunitReporter(ReporterConfig
const& _config);
6331 ~JunitReporter()
override;
6333 static std::string getDescription();
6335 void noMatchingTestCases(std::string
const& )
override;
6337 void testRunStarting(TestRunInfo
const& runInfo)
override;
6339 void testGroupStarting(GroupInfo
const& groupInfo)
override;
6341 void testCaseStarting(TestCaseInfo
const& testCaseInfo)
override;
6342 bool assertionEnded(AssertionStats
const& assertionStats)
override;
6344 void testCaseEnded(TestCaseStats
const& testCaseStats)
override;
6346 void testGroupEnded(TestGroupStats
const& testGroupStats)
override;
6348 void testRunEndedCumulative()
override;
6350 void writeGroup(TestGroupNode
const& groupNode,
double suiteTime);
6352 void writeTestCase(TestCaseNode
const& testCaseNode);
6354 void writeSection( std::string
const& className,
6355 std::string
const& rootName,
6356 SectionNode
const& sectionNode,
6357 bool testOkToFail );
6359 void writeAssertions(SectionNode
const& sectionNode);
6360 void writeAssertion(AssertionStats
const& stats);
6364 std::string stdOutForSuite;
6365 std::string stdErrForSuite;
6366 unsigned int unexpectedExceptions = 0;
6367 bool m_okToFail =
false;
6376 class XmlReporter :
public StreamingReporterBase<XmlReporter> {
6378 XmlReporter(ReporterConfig
const& _config);
6380 ~XmlReporter()
override;
6382 static std::string getDescription();
6384 virtual std::string getStylesheetRef()
const;
6386 void writeSourceInfo(SourceLineInfo
const& sourceInfo);
6390 void noMatchingTestCases(std::string
const& s)
override;
6392 void testRunStarting(TestRunInfo
const& testInfo)
override;
6394 void testGroupStarting(GroupInfo
const& groupInfo)
override;
6396 void testCaseStarting(TestCaseInfo
const& testInfo)
override;
6398 void sectionStarting(SectionInfo
const& sectionInfo)
override;
6400 void assertionStarting(AssertionInfo
const&)
override;
6402 bool assertionEnded(AssertionStats
const& assertionStats)
override;
6404 void sectionEnded(SectionStats
const& sectionStats)
override;
6406 void testCaseEnded(TestCaseStats
const& testCaseStats)
override;
6408 void testGroupEnded(TestGroupStats
const& testGroupStats)
override;
6410 void testRunEnded(TestRunStats
const& testRunStats)
override;
6412 #if defined(CATCH_CONFIG_ENABLE_BENCHMARKING)
6413 void benchmarkPreparing(std::string
const& name)
override;
6414 void benchmarkStarting(BenchmarkInfo
const&)
override;
6415 void benchmarkEnded(BenchmarkStats<>
const&)
override;
6416 void benchmarkFailed(std::string
const&)
override;
6420 Timer m_testCaseTimer;
6422 int m_sectionDepth = 0;
6432 #if defined(CATCH_CONFIG_ENABLE_BENCHMARKING)
6457 namespace Benchmark {
6458 template <
typename Clock>
6459 using ClockDuration =
typename Clock::duration;
6460 template <
typename Clock>
6461 using FloatDuration = std::chrono::duration<double, typename Clock::period>;
6463 template <
typename Clock>
6464 using TimePoint =
typename Clock::time_point;
6466 using default_clock = std::chrono::steady_clock;
6468 template <
typename Clock>
6470 TimePoint<Clock> operator()()
const {
6471 return Clock::now();
6475 using fp_seconds = std::chrono::duration<double, std::ratio<1>>;
6485 #if defined(_MSC_VER)
6490 namespace Benchmark {
6491 #if defined(__GNUC__) || defined(__clang__)
6492 template <
typename T>
6493 inline void keep_memory(T* p) {
6494 asm volatile(
"" : :
"g"(p) :
"memory");
6496 inline void keep_memory() {
6497 asm volatile(
"" : : :
"memory");
6501 inline void optimizer_barrier() { keep_memory(); }
6503 #elif defined(_MSC_VER)
6505 #pragma optimize("", off)
6506 template <
typename T>
6507 inline void keep_memory(T* p) {
6509 *
reinterpret_cast<char volatile*
>(p) = *
reinterpret_cast<char const volatile*
>(p);
6512 #pragma optimize("", on)
6515 inline void optimizer_barrier() {
6516 std::atomic_thread_fence(std::memory_order_seq_cst);
6522 template <
typename T>
6523 inline void deoptimize_value(T&& x) {
6527 template <
typename Fn,
typename... Args>
6528 inline auto invoke_deoptimized(Fn&& fn, Args&&... args) ->
typename std::enable_if<!std::is_same<void, decltype(fn(args...))>
::value>::type {
6529 deoptimize_value(std::forward<Fn>(fn) (std::forward<Args...>(args...)));
6532 template <
typename Fn,
typename... Args>
6533 inline auto invoke_deoptimized(Fn&& fn, Args&&... args) ->
typename std::enable_if<std::is_same<void, decltype(fn(args...))>
::value>::type {
6534 std::forward<Fn>(fn) (std::forward<Args...>(args...));
6545 #include <type_traits>
6549 namespace Benchmark {
6551 template <
typename T>
6552 struct CompleteType {
using type = T; };
6554 struct CompleteType<void> {
struct type {}; };
6556 template <
typename T>
6557 using CompleteType_t =
typename CompleteType<T>::type;
6559 template <
typename Result>
6560 struct CompleteInvoker {
6561 template <
typename Fun,
typename... Args>
6562 static Result invoke(Fun&& fun, Args&&... args) {
6563 return std::forward<Fun>(fun)(std::forward<Args>(args)...);
6567 struct CompleteInvoker<void> {
6568 template <
typename Fun,
typename... Args>
6569 static CompleteType_t<void> invoke(Fun&& fun, Args&&... args) {
6570 std::forward<Fun>(fun)(std::forward<Args>(args)...);
6576 template <
typename Fun,
typename... Args>
6577 CompleteType_t<
FunctionReturnType<Fun, Args...>> complete_invoke(Fun&& fun, Args&&... args) {
6578 return CompleteInvoker<
FunctionReturnType<Fun, Args...>>::invoke(std::forward<Fun>(fun), std::forward<Args>(args)...);
6581 const std::string benchmarkErrorMsg =
"a benchmark failed to run successfully";
6584 template <
typename Fun>
6585 Detail::CompleteType_t<FunctionReturnType<Fun>> user_code(Fun&& fun) {
6587 return Detail::complete_invoke(std::forward<Fun>(fun));
6598 namespace Benchmark {
6600 struct ChronometerConcept {
6601 virtual void start() = 0;
6602 virtual void finish() = 0;
6603 virtual ~ChronometerConcept() =
default;
6605 template <
typename Clock>
6606 struct ChronometerModel final :
public ChronometerConcept {
6607 void start()
override { started = Clock::now(); }
6608 void finish()
override { finished = Clock::now(); }
6610 ClockDuration<Clock> elapsed()
const {
return finished - started; }
6612 TimePoint<Clock> started;
6613 TimePoint<Clock> finished;
6617 struct Chronometer {
6619 template <
typename Fun>
6620 void measure(Fun&& fun) { measure(std::forward<Fun>(fun), is_callable<Fun(
int)>()); }
6622 int runs()
const {
return k; }
6624 Chronometer(Detail::ChronometerConcept& meter,
int k)
6629 template <
typename Fun>
6630 void measure(Fun&& fun, std::false_type) {
6631 measure([&fun](
int) {
return fun(); }, std::true_type());
6634 template <
typename Fun>
6635 void measure(Fun&& fun, std::true_type) {
6636 Detail::optimizer_barrier();
6638 for (
int i = 0; i < k; ++i) invoke_deoptimized(fun, i);
6640 Detail::optimizer_barrier();
6643 Detail::ChronometerConcept* impl;
6656 namespace Benchmark {
6657 template <
typename Duration>
6658 struct EnvironmentEstimate {
6660 OutlierClassification outliers;
6662 template <
typename Duration2>
6663 operator EnvironmentEstimate<Duration2>()
const {
6664 return { mean, outliers };
6667 template <
typename Clock>
6668 struct Environment {
6669 using clock_type = Clock;
6670 EnvironmentEstimate<FloatDuration<Clock>> clock_resolution;
6671 EnvironmentEstimate<FloatDuration<Clock>> clock_cost;
6688 #include <type_traits>
6693 namespace Benchmark {
6695 template <
typename T>
6696 using Decay =
typename std::decay<T>::type;
6697 template <
typename T,
typename U>
6699 : std::is_same<Decay<T>, Decay<U>> {};
6708 struct BenchmarkFunction {
6711 virtual void call(Chronometer meter)
const = 0;
6712 virtual callable* clone()
const = 0;
6713 virtual ~callable() =
default;
6715 template <
typename Fun>
6716 struct model :
public callable {
6717 model(Fun&& fun) : fun(std::move(fun)) {}
6718 model(Fun
const& fun) : fun(fun) {}
6720 model<Fun>* clone()
const override {
return new model<Fun>(*
this); }
6722 void call(Chronometer meter)
const override {
6723 call(meter, is_callable<Fun(Chronometer)>());
6725 void call(Chronometer meter, std::true_type)
const {
6728 void call(Chronometer meter, std::false_type)
const {
6735 struct do_nothing {
void operator()()
const {} };
6737 template <
typename T>
6738 BenchmarkFunction(model<T>* c) : f(c) {}
6742 : f(new model<do_nothing>{ {} }) {}
6744 template <
typename Fun,
6746 BenchmarkFunction(Fun&& fun)
6747 : f(new model<typename std::decay<Fun>::type>(std::forward<Fun>(fun))) {}
6749 BenchmarkFunction(BenchmarkFunction&& that)
6750 : f(std::move(that.f)) {}
6752 BenchmarkFunction(BenchmarkFunction
const& that)
6753 : f(that.f->clone()) {}
6755 BenchmarkFunction& operator=(BenchmarkFunction&& that) {
6756 f = std::move(that.f);
6760 BenchmarkFunction& operator=(BenchmarkFunction
const& that) {
6761 f.reset(that.f->clone());
6765 void operator()(Chronometer meter)
const { f->call(meter); }
6768 std::unique_ptr<callable> f;
6780 #include <type_traits>
6784 namespace Benchmark {
6786 template <
typename Fun>
6788 void operator()(
int k)
const {
6789 for (
int i = 0; i < k; ++i) {
6795 template <
typename Fun>
6796 repeater<typename std::decay<Fun>::type>
repeat(Fun&& fun) {
6797 return { std::forward<Fun>(fun) };
6820 #include <type_traits>
6823 namespace Benchmark {
6824 template <
typename Duration,
typename Result>
6830 template <
typename Clock,
typename Func,
typename... Args>
6831 using TimingOf = Timing<ClockDuration<Clock>, Detail::CompleteType_t<
FunctionReturnType<Func, Args...>>>;
6839 namespace Benchmark {
6841 template <
typename Clock,
typename Fun,
typename... Args>
6842 TimingOf<Clock, Fun, Args...> measure(Fun&& fun, Args&&... args) {
6843 auto start = Clock::now();
6844 auto&& r = Detail::complete_invoke(fun, std::forward<Args>(args)...);
6845 auto end = Clock::now();
6846 auto delta = end - start;
6847 return { delta, std::forward<decltype(r)>(r), 1 };
6855 #include <type_traits>
6858 namespace Benchmark {
6860 template <
typename Clock,
typename Fun>
6861 TimingOf<Clock, Fun, int> measure_one(Fun&& fun,
int iters, std::false_type) {
6862 return Detail::measure<Clock>(fun, iters);
6864 template <
typename Clock,
typename Fun>
6865 TimingOf<Clock, Fun, Chronometer> measure_one(Fun&& fun,
int iters, std::true_type) {
6866 Detail::ChronometerModel<Clock> meter;
6867 auto&& result = Detail::complete_invoke(fun, Chronometer(meter, iters));
6869 return { meter.elapsed(), std::move(result), iters };
6872 template <
typename Clock,
typename Fun>
6873 using run_for_at_least_argument_t =
typename std::conditional<is_callable<Fun(Chronometer)>
::value, Chronometer,
int>::type;
6875 struct optimized_away_error : std::exception {
6876 const char* what() const noexcept
override {
6877 return "could not measure benchmark, maybe it was optimized away";
6881 template <
typename Clock,
typename Fun>
6882 TimingOf<Clock, Fun, run_for_at_least_argument_t<Clock, Fun>> run_for_at_least(ClockDuration<Clock> how_long,
int seed, Fun&& fun) {
6884 while (iters < (1 << 30)) {
6885 auto&& Timing = measure_one<Clock>(fun, iters, is_callable<Fun(Chronometer)>());
6887 if (Timing.elapsed >= how_long) {
6888 return { Timing.elapsed, std::move(Timing.result), iters };
6899 #include <algorithm>
6903 namespace Benchmark {
6904 template <
typename Duration>
6905 struct ExecutionPlan {
6906 int iterations_per_sample;
6907 Duration estimated_duration;
6908 Detail::BenchmarkFunction benchmark;
6909 Duration warmup_time;
6910 int warmup_iterations;
6912 template <
typename Duration2>
6913 operator ExecutionPlan<Duration2>()
const {
6914 return { iterations_per_sample, estimated_duration, benchmark, warmup_time, warmup_iterations };
6917 template <
typename Clock>
6918 std::vector<FloatDuration<Clock>> run(
const IConfig &cfg, Environment<FloatDuration<Clock>> env)
const {
6920 Detail::run_for_at_least<Clock>(std::chrono::duration_cast<ClockDuration<Clock>>(warmup_time), warmup_iterations,
Detail::repeat(now<Clock>{}));
6922 std::vector<FloatDuration<Clock>> times;
6923 times.reserve(cfg.benchmarkSamples());
6924 std::generate_n(std::back_inserter(times), cfg.benchmarkSamples(), [
this, env] {
6925 Detail::ChronometerModel<Clock> model;
6926 this->benchmark(Chronometer(model, iterations_per_sample));
6927 auto sample_time = model.elapsed() - env.clock_cost.mean;
6928 if (sample_time < FloatDuration<Clock>::zero()) sample_time = FloatDuration<Clock>::zero();
6929 return sample_time / iterations_per_sample;
6948 #include <algorithm>
6949 #include <functional>
6960 namespace Benchmark {
6962 using sample = std::vector<double>;
6964 double weighted_average_quantile(
int k,
int q, std::vector<double>::iterator first, std::vector<double>::iterator last);
6966 template <
typename Iterator>
6967 OutlierClassification classify_outliers(Iterator first, Iterator last) {
6968 std::vector<double> copy(first, last);
6970 auto q1 = weighted_average_quantile(1, 4, copy.begin(), copy.end());
6971 auto q3 = weighted_average_quantile(3, 4, copy.begin(), copy.end());
6973 auto los = q1 - (iqr * 3.);
6974 auto lom = q1 - (iqr * 1.5);
6975 auto him = q3 + (iqr * 1.5);
6976 auto his = q3 + (iqr * 3.);
6978 OutlierClassification o;
6979 for (; first != last; ++first) {
6981 if (t < los) ++o.low_severe;
6982 else if (t < lom) ++o.low_mild;
6983 else if (t > his) ++o.high_severe;
6984 else if (t > him) ++o.high_mild;
6990 template <
typename Iterator>
6991 double mean(Iterator first, Iterator last) {
6992 auto count = last - first;
6993 double sum = std::accumulate(first, last, 0.);
6997 template <
typename URng,
typename Iterator,
typename Estimator>
6998 sample resample(URng&
rng,
int resamples, Iterator first, Iterator last, Estimator& estimator) {
6999 auto n = last - first;
7000 std::uniform_int_distribution<decltype(n)> dist(0, n - 1);
7003 out.reserve(resamples);
7004 std::generate_n(std::back_inserter(out), resamples, [n, first, &estimator, &dist, &
rng] {
7005 std::vector<double> resampled;
7006 resampled.reserve(n);
7007 std::generate_n(std::back_inserter(resampled), n, [first, &dist, &
rng] {
return first[dist(rng)]; });
7008 return estimator(resampled.begin(), resampled.end());
7010 std::sort(out.begin(), out.end());
7014 template <
typename Estimator,
typename Iterator>
7015 sample jackknife(Estimator&& estimator, Iterator first, Iterator last) {
7016 auto n = last - first;
7017 auto second = std::next(first);
7021 for (
auto it = first;
it != last; ++
it) {
7022 std::iter_swap(
it, first);
7023 results.push_back(estimator(second, last));
7029 inline double normal_cdf(
double x) {
7030 return std::erfc(-x / std::sqrt(2.0)) / 2.0;
7033 double erfc_inv(
double x);
7035 double normal_quantile(
double p);
7037 template <
typename Iterator,
typename Estimator>
7038 Estimate<double> bootstrap(
double confidence_level, Iterator first, Iterator last, sample
const& resample, Estimator&& estimator) {
7039 auto n_samples = last - first;
7041 double point = estimator(first, last);
7043 if (n_samples == 1)
return { point, point, point, confidence_level };
7045 sample jack = jackknife(estimator, first, last);
7046 double jack_mean = mean(jack.begin(), jack.end());
7047 double sum_squares, sum_cubes;
7048 std::tie(sum_squares, sum_cubes) = std::accumulate(jack.begin(), jack.end(), std::make_pair(0., 0.), [jack_mean](std::pair<double, double> sqcb,
double x) -> std::pair<double, double> {
7049 auto d = jack_mean - x;
7052 return { sqcb.first + d2, sqcb.second + d3 };
7055 double accel = sum_cubes / (6 * std::pow(sum_squares, 1.5));
7056 int n =
static_cast<int>(resample.size());
7057 double prob_n = std::count_if(resample.begin(), resample.end(), [point](
double x) { return x < point; }) / (double)n;
7059 if (prob_n == 0)
return { point, point, point, confidence_level };
7061 double bias = normal_quantile(prob_n);
7062 double z1 = normal_quantile((1. - confidence_level) / 2.);
7064 auto cumn = [n](
double x) ->
int {
7065 return std::lround(normal_cdf(x) * n); };
7066 auto a = [bias, accel](
double b) {
return bias + b / (1. - accel * b); };
7067 double b1 = bias + z1;
7068 double b2 = bias - z1;
7071 auto lo = (std::max)(cumn(a1), 0);
7072 auto hi = (std::min)(cumn(a2), n - 1);
7074 return { point, resample[lo], resample[hi], confidence_level };
7077 double outlier_variance(Estimate<double> mean, Estimate<double> stddev,
int n);
7079 struct bootstrap_analysis {
7080 Estimate<double> mean;
7081 Estimate<double> standard_deviation;
7082 double outlier_variance;
7085 bootstrap_analysis analyse_samples(
double confidence_level,
int n_resamples, std::vector<double>::iterator first, std::vector<double>::iterator last);
7091 #include <algorithm>
7098 namespace Benchmark {
7100 template <
typename Clock>
7101 std::vector<double> resolution(
int k) {
7102 std::vector<TimePoint<Clock>> times;
7103 times.reserve(k + 1);
7104 std::generate_n(std::back_inserter(times), k + 1, now<Clock>{});
7106 std::vector<double> deltas;
7108 std::transform(std::next(times.begin()), times.end(), times.begin(),
7109 std::back_inserter(deltas),
7110 [](TimePoint<Clock> a, TimePoint<Clock> b) { return static_cast<double>((a - b).count()); });
7115 const auto warmup_iterations = 10000;
7116 const auto warmup_time = std::chrono::milliseconds(100);
7117 const auto minimum_ticks = 1000;
7118 const auto warmup_seed = 10000;
7119 const auto clock_resolution_estimation_time = std::chrono::milliseconds(500);
7120 const auto clock_cost_estimation_time_limit = std::chrono::seconds(1);
7121 const auto clock_cost_estimation_tick_limit = 100000;
7122 const auto clock_cost_estimation_time = std::chrono::milliseconds(10);
7123 const auto clock_cost_estimation_iterations = 10000;
7125 template <
typename Clock>
7127 return run_for_at_least<Clock>(std::chrono::duration_cast<ClockDuration<Clock>>(warmup_time), warmup_seed, &resolution<Clock>)
7130 template <
typename Clock>
7131 EnvironmentEstimate<FloatDuration<Clock>> estimate_clock_resolution(
int iterations) {
7132 auto r = run_for_at_least<Clock>(std::chrono::duration_cast<ClockDuration<Clock>>(clock_resolution_estimation_time), iterations, &resolution<Clock>)
7135 FloatDuration<Clock>(mean(r.begin(), r.end())),
7136 classify_outliers(r.begin(), r.end()),
7139 template <
typename Clock>
7140 EnvironmentEstimate<FloatDuration<Clock>> estimate_clock_cost(FloatDuration<Clock> resolution) {
7141 auto time_limit = (std::min)(
7142 resolution * clock_cost_estimation_tick_limit,
7143 FloatDuration<Clock>(clock_cost_estimation_time_limit));
7144 auto time_clock = [](
int k) {
7145 return Detail::measure<Clock>([k] {
7146 for (
int i = 0; i < k; ++i) {
7147 volatile auto ignored = Clock::now();
7153 int iters = clock_cost_estimation_iterations;
7154 auto&& r = run_for_at_least<Clock>(std::chrono::duration_cast<ClockDuration<Clock>>(clock_cost_estimation_time), iters, time_clock);
7155 std::vector<double> times;
7156 int nsamples =
static_cast<int>(std::ceil(time_limit / r.elapsed));
7157 times.reserve(nsamples);
7158 std::generate_n(std::back_inserter(times), nsamples, [time_clock, &r] {
7159 return static_cast<double>((time_clock(r.iterations) / r.iterations).count());
7162 FloatDuration<Clock>(mean(times.begin(), times.end())),
7163 classify_outliers(times.begin(), times.end()),
7167 template <
typename Clock>
7168 Environment<FloatDuration<Clock>> measure_environment() {
7169 static Environment<FloatDuration<Clock>>* env =
nullptr;
7174 auto iters = Detail::warmup<Clock>();
7175 auto resolution = Detail::estimate_clock_resolution<Clock>(iters);
7176 auto cost = Detail::estimate_clock_cost<Clock>(resolution.mean);
7178 env =
new Environment<FloatDuration<Clock>>{ resolution, cost };
7196 #include <algorithm>
7202 namespace Benchmark {
7203 template <
typename Duration>
7204 struct SampleAnalysis {
7205 std::vector<Duration> samples;
7206 Estimate<Duration> mean;
7207 Estimate<Duration> standard_deviation;
7208 OutlierClassification outliers;
7209 double outlier_variance;
7211 template <
typename Duration2>
7212 operator SampleAnalysis<Duration2>()
const {
7213 std::vector<Duration2> samples2;
7214 samples2.reserve(samples.size());
7215 std::transform(samples.begin(), samples.end(), std::back_inserter(samples2), [](Duration d) { return Duration2(d); });
7217 std::move(samples2),
7229 #include <algorithm>
7234 namespace Benchmark {
7236 template <
typename Duration,
typename Iterator>
7237 SampleAnalysis<Duration> analyse(
const IConfig &cfg, Environment<Duration>, Iterator first, Iterator last) {
7238 if (!cfg.benchmarkNoAnalysis()) {
7239 std::vector<double> samples;
7240 samples.reserve(last - first);
7241 std::transform(first, last, std::back_inserter(samples), [](Duration d) {
return d.count(); });
7243 auto analysis = Catch::Benchmark::Detail::analyse_samples(cfg.benchmarkConfidenceInterval(), cfg.benchmarkResamples(), samples.begin(), samples.end());
7244 auto outliers = Catch::Benchmark::Detail::classify_outliers(samples.begin(), samples.end());
7246 auto wrap_estimate = [](Estimate<double> e) {
7247 return Estimate<Duration> {
7249 Duration(e.lower_bound),
7250 Duration(e.upper_bound),
7251 e.confidence_interval,
7254 std::vector<Duration> samples2;
7255 samples2.reserve(samples.size());
7256 std::transform(samples.begin(), samples.end(), std::back_inserter(samples2), [](
double d) { return Duration(d); });
7258 std::move(samples2),
7259 wrap_estimate(analysis.mean),
7260 wrap_estimate(analysis.standard_deviation),
7262 analysis.outlier_variance,
7265 std::vector<Duration> samples;
7266 samples.reserve(last - first);
7268 Duration mean = Duration(0);
7270 for (
auto it = first;
it < last; ++
it, ++i) {
7271 samples.push_back(Duration(*
it));
7272 mean += Duration(*
it);
7278 Estimate<Duration>{mean, mean, mean, 0.0},
7279 Estimate<Duration>{Duration(0), Duration(0), Duration(0), 0.0},
7280 OutlierClassification{},
7290 #include <algorithm>
7291 #include <functional>
7297 namespace Benchmark {
7299 Benchmark(std::string &&name)
7300 : name(std::move(name)) {}
7302 template <
class FUN>
7303 Benchmark(std::string &&name, FUN &&func)
7304 : fun(std::move(func)), name(std::move(name)) {}
7306 template <
typename Clock>
7307 ExecutionPlan<FloatDuration<Clock>> prepare(
const IConfig &cfg, Environment<FloatDuration<Clock>> env)
const {
7308 auto min_time = env.clock_resolution.mean * Detail::minimum_ticks;
7309 auto run_time = std::max(min_time, std::chrono::duration_cast<decltype(min_time)>(cfg.benchmarkWarmupTime()));
7310 auto&& test = Detail::run_for_at_least<Clock>(std::chrono::duration_cast<ClockDuration<Clock>>(run_time), 1, fun);
7311 int new_iters =
static_cast<int>(std::ceil(min_time * test.iterations / test.elapsed));
7312 return { new_iters, test.elapsed / test.iterations * new_iters * cfg.benchmarkSamples(), fun, std::chrono::duration_cast<FloatDuration<Clock>>(cfg.benchmarkWarmupTime()), Detail::warmup_iterations };
7315 template <
typename Clock = default_clock>
7319 auto env = Detail::measure_environment<Clock>();
7323 auto plan = user_code([&] {
7324 return prepare<Clock>(*cfg, env);
7327 BenchmarkInfo
info {
7329 plan.estimated_duration.count(),
7330 plan.iterations_per_sample,
7331 cfg->benchmarkSamples(),
7332 cfg->benchmarkResamples(),
7333 env.clock_resolution.mean.count(),
7334 env.clock_cost.mean.count()
7339 auto samples = user_code([&] {
7340 return plan.template run<Clock>(*cfg, env);
7343 auto analysis = Detail::analyse(*cfg, env, samples.begin(), samples.end());
7344 BenchmarkStats<FloatDuration<Clock>> stats{
info, analysis.samples, analysis.mean, analysis.standard_deviation, analysis.outliers, analysis.outlier_variance };
7349 std::rethrow_exception(std::current_exception());
7354 template <
typename Fun,
7356 Benchmark & operator=(Fun func) {
7357 fun = Detail::BenchmarkFunction(func);
7362 explicit operator bool() {
7367 Detail::BenchmarkFunction fun;
7373 #define INTERNAL_CATCH_GET_1_ARG(arg1, arg2, ...) arg1
7374 #define INTERNAL_CATCH_GET_2_ARG(arg1, arg2, ...) arg2
7376 #define INTERNAL_CATCH_BENCHMARK(BenchmarkName, name, benchmarkIndex)\
7377 if( Catch::Benchmark::Benchmark BenchmarkName{name} ) \
7378 BenchmarkName = [&](int benchmarkIndex)
7380 #define INTERNAL_CATCH_BENCHMARK_ADVANCED(BenchmarkName, name)\
7381 if( Catch::Benchmark::Benchmark BenchmarkName{name} ) \
7390 #include <type_traits>
7393 namespace Benchmark {
7395 template <
typename T,
bool Destruct>
7396 struct ObjectStorage
7398 ObjectStorage() : data() {}
7400 ObjectStorage(
const ObjectStorage& other)
7402 new(&data) T(other.stored_object());
7405 ObjectStorage(ObjectStorage&& other)
7407 new(&data) T(std::move(other.stored_object()));
7410 ~ObjectStorage() { destruct_on_exit<T>(); }
7412 template <
typename... Args>
7413 void construct(Args&&... args)
7415 new (&data) T(std::forward<Args>(args)...);
7418 template <
bool AllowManualDestruction = !Destruct>
7419 typename std::enable_if<AllowManualDestruction>::type destruct()
7421 stored_object().~T();
7426 template <
typename U>
7427 void destruct_on_exit(
typename std::enable_if<Destruct, U>::type* = 0) { destruct<true>(); }
7429 template <
typename U>
7430 void destruct_on_exit(
typename std::enable_if<!Destruct, U>::type* = 0) { }
7432 T& stored_object() {
7433 return *
static_cast<T*
>(
static_cast<void*
>(&data));
7436 T
const& stored_object()
const {
7437 return *
static_cast<T*
>(
static_cast<void*
>(&data));
7440 struct {
alignas(T)
unsigned char data[
sizeof(T)]; } data;
7444 template <
typename T>
7445 using storage_for = Detail::ObjectStorage<T, true>;
7447 template <
typename T>
7448 using destructable_object = Detail::ObjectStorage<T, false>;
7462 #pragma clang diagnostic push
7463 #pragma clang diagnostic ignored "-Wweak-vtables"
7474 namespace TestCaseTracking {
7476 struct NameAndLocation {
7478 SourceLineInfo location;
7480 NameAndLocation( std::string
const& _name, SourceLineInfo
const& _location );
7481 friend bool operator==(NameAndLocation
const& lhs, NameAndLocation
const& rhs) {
7482 return lhs.name == rhs.name
7483 && lhs.location == rhs.location;
7489 using ITrackerPtr = std::shared_ptr<ITracker>;
7492 NameAndLocation m_nameAndLocation;
7495 ITracker(NameAndLocation
const& nameAndLoc) :
7496 m_nameAndLocation(nameAndLoc)
7500 NameAndLocation
const& nameAndLocation()
const {
7501 return m_nameAndLocation;
7504 virtual ~ITracker();
7507 virtual bool isComplete()
const = 0;
7508 virtual bool isSuccessfullyCompleted()
const = 0;
7509 virtual bool isOpen()
const = 0;
7510 virtual bool hasChildren()
const = 0;
7511 virtual bool hasStarted()
const = 0;
7513 virtual ITracker& parent() = 0;
7516 virtual void close() = 0;
7517 virtual void fail() = 0;
7518 virtual void markAsNeedingAnotherRun() = 0;
7520 virtual void addChild( ITrackerPtr
const& child ) = 0;
7521 virtual ITrackerPtr findChild( NameAndLocation
const& nameAndLocation ) = 0;
7522 virtual void openChild() = 0;
7525 virtual bool isSectionTracker()
const = 0;
7526 virtual bool isGeneratorTracker()
const = 0;
7529 class TrackerContext {
7537 ITrackerPtr m_rootTracker;
7538 ITracker* m_currentTracker =
nullptr;
7539 RunState m_runState = NotStarted;
7543 ITracker& startRun();
7547 void completeCycle();
7549 bool completedCycle()
const;
7550 ITracker& currentTracker();
7551 void setCurrentTracker( ITracker* tracker );
7554 class TrackerBase :
public ITracker {
7561 CompletedSuccessfully,
7565 using Children = std::vector<ITrackerPtr>;
7566 TrackerContext& m_ctx;
7568 Children m_children;
7569 CycleState m_runState = NotStarted;
7572 TrackerBase( NameAndLocation
const& nameAndLocation, TrackerContext& ctx, ITracker* parent );
7574 bool isComplete()
const override;
7575 bool isSuccessfullyCompleted()
const override;
7576 bool isOpen()
const override;
7577 bool hasChildren()
const override;
7578 bool hasStarted()
const override {
7579 return m_runState != NotStarted;
7582 void addChild( ITrackerPtr
const& child )
override;
7584 ITrackerPtr findChild( NameAndLocation
const& nameAndLocation )
override;
7585 ITracker& parent()
override;
7587 void openChild()
override;
7589 bool isSectionTracker()
const override;
7590 bool isGeneratorTracker()
const override;
7594 void close()
override;
7595 void fail()
override;
7596 void markAsNeedingAnotherRun()
override;
7599 void moveToParent();
7603 class SectionTracker :
public TrackerBase {
7604 std::vector<std::string> m_filters;
7605 std::string m_trimmed_name;
7607 SectionTracker( NameAndLocation
const& nameAndLocation, TrackerContext& ctx, ITracker* parent );
7609 bool isSectionTracker()
const override;
7611 bool isComplete()
const override;
7613 static SectionTracker& acquire( TrackerContext& ctx, NameAndLocation
const& nameAndLocation );
7617 void addInitialFilters( std::vector<std::string>
const& filters );
7618 void addNextFilters( std::vector<std::string>
const& filters );
7620 std::vector<std::string>
const& getFilters()
const;
7622 std::string
const& trimmedName()
const;
7627 using TestCaseTracking::ITracker;
7628 using TestCaseTracking::TrackerContext;
7629 using TestCaseTracking::SectionTracker;
7639 struct LeakDetector {
7651 #if defined(CATCH_CONFIG_ENABLE_BENCHMARKING)
7656 #if defined(CATCH_CONFIG_USE_ASYNC)
7661 double erf_inv(
double x) {
7665 w = -
log((1.0 - x) * (1.0 + x));
7669 p = -3.6444120640178196996e-21;
7670 p = -1.685059138182016589e-19 + p * w;
7671 p = 1.2858480715256400167e-18 + p * w;
7672 p = 1.115787767802518096e-17 + p * w;
7673 p = -1.333171662854620906e-16 + p * w;
7674 p = 2.0972767875968561637e-17 + p * w;
7675 p = 6.6376381343583238325e-15 + p * w;
7676 p = -4.0545662729752068639e-14 + p * w;
7677 p = -8.1519341976054721522e-14 + p * w;
7678 p = 2.6335093153082322977e-12 + p * w;
7679 p = -1.2975133253453532498e-11 + p * w;
7680 p = -5.4154120542946279317e-11 + p * w;
7681 p = 1.051212273321532285e-09 + p * w;
7682 p = -4.1126339803469836976e-09 + p * w;
7683 p = -2.9070369957882005086e-08 + p * w;
7684 p = 4.2347877827932403518e-07 + p * w;
7685 p = -1.3654692000834678645e-06 + p * w;
7686 p = -1.3882523362786468719e-05 + p * w;
7687 p = 0.0001867342080340571352 + p * w;
7688 p = -0.00074070253416626697512 + p * w;
7689 p = -0.0060336708714301490533 + p * w;
7690 p = 0.24015818242558961693 + p * w;
7691 p = 1.6536545626831027356 + p * w;
7692 }
else if (w < 16.000000) {
7693 w = sqrt(w) - 3.250000;
7694 p = 2.2137376921775787049e-09;
7695 p = 9.0756561938885390979e-08 + p * w;
7696 p = -2.7517406297064545428e-07 + p * w;
7697 p = 1.8239629214389227755e-08 + p * w;
7698 p = 1.5027403968909827627e-06 + p * w;
7699 p = -4.013867526981545969e-06 + p * w;
7700 p = 2.9234449089955446044e-06 + p * w;
7701 p = 1.2475304481671778723e-05 + p * w;
7702 p = -4.7318229009055733981e-05 + p * w;
7703 p = 6.8284851459573175448e-05 + p * w;
7704 p = 2.4031110387097893999e-05 + p * w;
7705 p = -0.0003550375203628474796 + p * w;
7706 p = 0.00095328937973738049703 + p * w;
7707 p = -0.0016882755560235047313 + p * w;
7708 p = 0.0024914420961078508066 + p * w;
7709 p = -0.0037512085075692412107 + p * w;
7710 p = 0.005370914553590063617 + p * w;
7711 p = 1.0052589676941592334 + p * w;
7712 p = 3.0838856104922207635 + p * w;
7714 w = sqrt(w) - 5.000000;
7715 p = -2.7109920616438573243e-11;
7716 p = -2.5556418169965252055e-10 + p * w;
7717 p = 1.5076572693500548083e-09 + p * w;
7718 p = -3.7894654401267369937e-09 + p * w;
7719 p = 7.6157012080783393804e-09 + p * w;
7720 p = -1.4960026627149240478e-08 + p * w;
7721 p = 2.9147953450901080826e-08 + p * w;
7722 p = -6.7711997758452339498e-08 + p * w;
7723 p = 2.2900482228026654717e-07 + p * w;
7724 p = -9.9298272942317002539e-07 + p * w;
7725 p = 4.5260625972231537039e-06 + p * w;
7726 p = -1.9681778105531670567e-05 + p * w;
7727 p = 7.5995277030017761139e-05 + p * w;
7728 p = -0.00021503011930044477347 + p * w;
7729 p = -0.00013871931833623122026 + p * w;
7730 p = 1.0103004648645343977 + p * w;
7731 p = 4.8499064014085844221 + p * w;
7736 double standard_deviation(std::vector<double>::iterator first, std::vector<double>::iterator last) {
7737 auto m = Catch::Benchmark::Detail::mean(first, last);
7738 double variance = std::accumulate(first, last, 0., [m](
double a,
double b) {
7739 double diff = b - m;
7740 return a + diff * diff;
7741 }) / (last - first);
7742 return std::sqrt(variance);
7748 namespace Benchmark {
7751 double weighted_average_quantile(
int k,
int q, std::vector<double>::iterator first, std::vector<double>::iterator last) {
7752 auto count = last - first;
7753 double idx = (count - 1) * k / static_cast<double>(q);
7754 int j =
static_cast<int>(idx);
7756 std::nth_element(first, first + j, last);
7758 if (g == 0)
return xj;
7760 auto xj1 = *std::min_element(first + (j + 1), last);
7761 return xj + g * (xj1 - xj);
7764 double erfc_inv(
double x) {
7765 return erf_inv(1.0 - x);
7768 double normal_quantile(
double p) {
7769 static const double ROOT_TWO = std::sqrt(2.0);
7771 double result = 0.0;
7772 assert(p >= 0 && p <= 1);
7773 if (p < 0 || p > 1) {
7777 result = -erfc_inv(2.0 * p);
7784 double outlier_variance(Estimate<double> mean, Estimate<double> stddev,
int n) {
7785 double sb = stddev.point;
7786 double mn = mean.point / n;
7787 double mg_min = mn / 2.;
7788 double sg = (std::min)(mg_min / 4., sb / std::sqrt(n));
7789 double sg2 = sg * sg;
7790 double sb2 = sb * sb;
7792 auto c_max = [n, mn, sb2, sg2](
double x) ->
double {
7796 double k0 = -n * nd;
7797 double k1 = sb2 - n * sg2 + nd;
7798 double det = k1 * k1 - 4 * sg2 * k0;
7799 return (
int)(-2. * k0 / (k1 + std::sqrt(det)));
7802 auto var_out = [n, sb2, sg2](
double c) {
7804 return (nc / n) * (sb2 - nc * sg2);
7807 return (std::min)(var_out(1), var_out((std::min)(c_max(0.), c_max(mg_min)))) / sb2;
7810 bootstrap_analysis analyse_samples(
double confidence_level,
int n_resamples, std::vector<double>::iterator first, std::vector<double>::iterator last) {
7813 static std::random_device entropy;
7816 auto n =
static_cast<int>(last - first);
7818 auto mean = &Detail::mean<std::vector<double>::iterator>;
7819 auto stddev = &standard_deviation;
7821 #if defined(CATCH_CONFIG_USE_ASYNC)
7822 auto Estimate = [=](double(*f)(std::vector<double>::iterator, std::vector<double>::iterator)) {
7823 auto seed = entropy();
7824 return std::async(std::launch::async, [=] {
7825 std::mt19937
rng(seed);
7826 auto resampled = resample(
rng, n_resamples, first, last, f);
7827 return bootstrap(confidence_level, first, last, resampled, f);
7831 auto mean_future = Estimate(mean);
7832 auto stddev_future = Estimate(stddev);
7834 auto mean_estimate = mean_future.get();
7835 auto stddev_estimate = stddev_future.get();
7837 auto Estimate = [=](double(*f)(std::vector<double>::iterator, std::vector<double>::iterator)) {
7838 auto seed = entropy();
7839 std::mt19937
rng(seed);
7840 auto resampled = resample(
rng, n_resamples, first, last, f);
7841 return bootstrap(confidence_level, first, last, resampled, f);
7844 auto mean_estimate = Estimate(mean);
7845 auto stddev_estimate = Estimate(stddev);
7848 double outlier_variance = Detail::outlier_variance(mean_estimate, stddev_estimate, n);
7850 return { mean_estimate, stddev_estimate, outlier_variance };
7867 bool marginComparison(
double lhs,
double rhs,
double margin) {
7868 return (lhs + margin >= rhs) && (rhs + margin >= lhs);
7877 : m_epsilon( std::numeric_limits<float>::epsilon()*100 ),
7883 Approx Approx::custom() {
7887 Approx Approx::operator-()
const {
7889 temp.m_value = -temp.m_value;
7893 std::string Approx::toString()
const {
7894 ReusableStringStream rss;
7899 bool Approx::equalityComparisonImpl(
const double other)
const {
7902 return marginComparison(m_value, other, m_margin)
7903 || marginComparison(m_value, other, m_epsilon * (m_scale + std::fabs(std::isinf(m_value)? 0 : m_value)));
7906 void Approx::setMargin(
double newMargin) {
7908 "Invalid Approx::margin: " << newMargin <<
'.'
7909 <<
" Approx::Margin has to be non-negative.");
7910 m_margin = newMargin;
7913 void Approx::setEpsilon(
double newEpsilon) {
7915 "Invalid Approx::epsilon: " << newEpsilon <<
'.'
7916 <<
" Approx::epsilon has to be in [0, 1]");
7917 m_epsilon = newEpsilon;
7922 namespace literals {
7932 return value.toString();
7942 bool isDebuggerActive();
7945 #ifdef CATCH_PLATFORM_MAC
7947 #if defined(__i386__) || defined(__x86_64__)
7948 #define CATCH_TRAP() __asm__("int $3\n" : : )
7949 #elif defined(__aarch64__)
7950 #define CATCH_TRAP() __asm__(".inst 0xd43e0000")
7953 #elif defined(CATCH_PLATFORM_IPHONE)
7956 #if defined(__i386__) || defined(__x86_64__)
7957 #define CATCH_TRAP() __asm__("int $3")
7958 #elif defined(__aarch64__)
7959 #define CATCH_TRAP() __asm__(".inst 0xd4200000")
7960 #elif defined(__arm__) && !defined(__thumb__)
7961 #define CATCH_TRAP() __asm__(".inst 0xe7f001f0")
7962 #elif defined(__arm__) && defined(__thumb__)
7963 #define CATCH_TRAP() __asm__(".inst 0xde01")
7966 #elif defined(CATCH_PLATFORM_LINUX)
7970 #if defined(__GNUC__) && (defined(__i386) || defined(__x86_64))
7971 #define CATCH_TRAP() asm volatile ("int $3")
7975 #define CATCH_TRAP() raise(SIGTRAP)
7977 #elif defined(_MSC_VER)
7978 #define CATCH_TRAP() __debugbreak()
7979 #elif defined(__MINGW32__)
7980 extern "C" __declspec(dllimport)
void __stdcall DebugBreak();
7981 #define CATCH_TRAP() DebugBreak()
7984 #ifndef CATCH_BREAK_INTO_DEBUGGER
7986 #define CATCH_BREAK_INTO_DEBUGGER() []{ if( Catch::isDebuggerActive() ) { CATCH_TRAP(); } }()
7988 #define CATCH_BREAK_INTO_DEBUGGER() []{}()
8009 class FatalConditionHandler {
8010 bool m_started =
false;
8015 void engage_platform();
8016 void disengage_platform();
8019 FatalConditionHandler();
8020 ~FatalConditionHandler();
8023 assert(!m_started &&
"Handler cannot be installed twice.");
8029 assert(m_started &&
"Handler cannot be uninstalled without being installed first");
8031 disengage_platform();
8036 class FatalConditionHandlerGuard {
8037 FatalConditionHandler* m_handler;
8039 FatalConditionHandlerGuard(FatalConditionHandler* handler):
8040 m_handler(handler) {
8041 m_handler->engage();
8043 ~FatalConditionHandlerGuard() {
8044 m_handler->disengage();
8055 struct IMutableContext;
8059 class RunContext :
public IResultCapture,
public IRunner {
8062 RunContext( RunContext
const& ) =
delete;
8063 RunContext& operator =( RunContext
const& ) =
delete;
8065 explicit RunContext(
IConfigPtr const& _config, IStreamingReporterPtr&& reporter );
8067 ~RunContext()
override;
8069 void testGroupStarting( std::string
const& testSpec, std::size_t groupIndex, std::size_t groupsCount );
8070 void testGroupEnded( std::string
const& testSpec, Totals
const& totals, std::size_t groupIndex, std::size_t groupsCount );
8072 Totals runTest(TestCase
const& testCase);
8075 IStreamingReporter& reporter()
const;
8081 ( AssertionInfo
const& info,
8082 ITransientExpression
const& expr,
8083 AssertionReaction& reaction )
override;
8085 ( AssertionInfo
const& info,
8087 StringRef
const& message,
8088 AssertionReaction& reaction )
override;
8089 void handleUnexpectedExceptionNotThrown
8090 ( AssertionInfo
const& info,
8091 AssertionReaction& reaction )
override;
8092 void handleUnexpectedInflightException
8093 ( AssertionInfo
const& info,
8094 std::string
const& message,
8095 AssertionReaction& reaction )
override;
8096 void handleIncomplete
8097 ( AssertionInfo
const& info )
override;
8099 ( AssertionInfo
const &info,
8101 AssertionReaction &reaction )
override;
8103 bool sectionStarted( SectionInfo
const& sectionInfo, Counts& assertions )
override;
8105 void sectionEnded( SectionEndInfo
const& endInfo )
override;
8106 void sectionEndedEarly( SectionEndInfo
const& endInfo )
override;
8108 auto acquireGeneratorTracker( StringRef generatorName, SourceLineInfo
const& lineInfo ) -> IGeneratorTracker&
override;
8110 #if defined(CATCH_CONFIG_ENABLE_BENCHMARKING)
8111 void benchmarkPreparing( std::string
const& name )
override;
8112 void benchmarkStarting( BenchmarkInfo
const& info )
override;
8113 void benchmarkEnded( BenchmarkStats<>
const& stats )
override;
8114 void benchmarkFailed( std::string
const& error )
override;
8117 void pushScopedMessage( MessageInfo
const& message )
override;
8118 void popScopedMessage( MessageInfo
const& message )
override;
8120 void emplaceUnscopedMessage( MessageBuilder
const& builder )
override;
8122 std::string getCurrentTestName()
const override;
8124 const AssertionResult* getLastResult()
const override;
8126 void exceptionEarlyReported()
override;
8128 void handleFatalErrorCondition( StringRef message )
override;
8130 bool lastAssertionPassed()
override;
8132 void assertionPassed()
override;
8136 bool aborting() const final;
8140 void runCurrentTest( std::
string& redirectedCout, std::
string& redirectedCerr );
8141 void invokeActiveTestCase();
8143 void resetAssertionInfo();
8144 bool testForMissingAssertions( Counts& assertions );
8146 void assertionEnded( AssertionResult const& result );
8148 ( AssertionInfo const &info,
8149 ResultWas::OfType resultType,
8150 ITransientExpression const *expr,
8153 void populateReaction( AssertionReaction& reaction );
8157 void handleUnfinishedSections();
8159 TestRunInfo m_runInfo;
8160 IMutableContext& m_context;
8161 TestCase const* m_activeTestCase =
nullptr;
8162 ITracker* m_testCaseTracker =
nullptr;
8163 Option<AssertionResult> m_lastResult;
8167 IStreamingReporterPtr m_reporter;
8168 std::vector<MessageInfo> m_messages;
8169 std::vector<ScopedMessage> m_messageScopes;
8170 AssertionInfo m_lastAssertionInfo;
8171 std::vector<SectionEndInfo> m_unfinishedSections;
8172 std::vector<ITracker*> m_activeSections;
8173 TrackerContext m_trackerContext;
8174 FatalConditionHandler m_fatalConditionhandler;
8175 bool m_lastAssertionPassed = false;
8176 bool m_shouldReportUnexpected = true;
8177 bool m_includeSuccessfulResults;
8180 void seedRng(IConfig const& config);
8188 auto operator <<( std::ostream& os, ITransientExpression
const& expr ) -> std::ostream& {
8189 expr.streamReconstructedExpression( os );
8195 : m_isNegated( isNegated )
8200 LazyExpression::operator bool()
const {
8201 return m_transientExpression !=
nullptr;
8204 auto operator << ( std::ostream& os, LazyExpression
const& lazyExpr ) -> std::ostream& {
8205 if( lazyExpr.m_isNegated )
8209 if( lazyExpr.m_isNegated && lazyExpr.m_transientExpression->isBinaryExpression() )
8210 os <<
"(" << *lazyExpr.m_transientExpression <<
")";
8212 os << *lazyExpr.m_transientExpression;
8215 os <<
"{** error - unchecked empty expression requested **}";
8221 ( StringRef
const& macroName,
8222 SourceLineInfo
const& lineInfo,
8223 StringRef capturedExpression,
8225 : m_assertionInfo{ macroName, lineInfo, capturedExpression, resultDisposition },
8248 CATCH_BREAK_INTO_DEBUGGER();
8251 #if !defined(CATCH_CONFIG_DISABLE_EXCEPTIONS)
8254 CATCH_ERROR(
"Test failure requires aborting test!" );
8283 void handleExceptionMatchExpr( AssertionHandler& handler, std::string
const& str, StringRef
const& matcherString ) {
8292 AssertionResultData::AssertionResultData(
ResultWas::OfType _resultType, LazyExpression
const & _lazyExpression):
8293 lazyExpression(_lazyExpression),
8294 resultType(_resultType) {}
8296 std::string AssertionResultData::reconstructExpression()
const {
8298 if( reconstructedExpression.empty() ) {
8299 if( lazyExpression ) {
8300 ReusableStringStream rss;
8301 rss << lazyExpression;
8302 reconstructedExpression = rss.str();
8305 return reconstructedExpression;
8308 AssertionResult::AssertionResult( AssertionInfo
const& info, AssertionResultData
const& data )
8310 m_resultData( data )
8314 bool AssertionResult::succeeded()
const {
8324 return m_resultData.resultType;
8327 bool AssertionResult::hasExpression()
const {
8328 return !m_info.capturedExpression.empty();
8331 bool AssertionResult::hasMessage()
const {
8332 return !m_resultData.message.empty();
8335 std::string AssertionResult::getExpression()
const {
8337 std::string expr; expr.reserve(m_info.capturedExpression.size() + 3);
8341 expr += m_info.capturedExpression;
8348 std::string AssertionResult::getExpressionInMacro()
const {
8350 if( m_info.macroName.empty() )
8351 expr =
static_cast<std::string
>(m_info.capturedExpression);
8353 expr.reserve( m_info.macroName.size() + m_info.capturedExpression.size() + 4 );
8354 expr += m_info.macroName;
8356 expr += m_info.capturedExpression;
8362 bool AssertionResult::hasExpandedExpression()
const {
8363 return hasExpression() && getExpandedExpression() != getExpression();
8366 std::string AssertionResult::getExpandedExpression()
const {
8367 std::string expr = m_resultData.reconstructExpression();
8373 std::string AssertionResult::getMessage()
const {
8374 return m_resultData.message;
8376 SourceLineInfo AssertionResult::getSourceInfo()
const {
8377 return m_info.lineInfo;
8380 StringRef AssertionResult::getTestMacroName()
const {
8381 return m_info.macroName;
8390 using StringMatcher = Matchers::Impl::MatcherBase<std::string>;
8397 MatchExpr<std::string, StringMatcher const&> expr( exceptionMessage, matcher, matcherString );
8398 handler.handleExpr( expr );
8410 #ifdef CLARA_CONFIG_CONSOLE_WIDTH
8411 #define CATCH_TEMP_CLARA_CONFIG_CONSOLE_WIDTH CATCH_CLARA_TEXTFLOW_CONFIG_CONSOLE_WIDTH
8412 #undef CATCH_CLARA_TEXTFLOW_CONFIG_CONSOLE_WIDTH
8414 #define CATCH_CLARA_TEXTFLOW_CONFIG_CONSOLE_WIDTH CATCH_CONFIG_CONSOLE_WIDTH-1
8417 #pragma clang diagnostic push
8418 #pragma clang diagnostic ignored "-Wweak-vtables"
8419 #pragma clang diagnostic ignored "-Wexit-time-destructors"
8420 #pragma clang diagnostic ignored "-Wshadow"
8434 #ifndef CATCH_CLARA_CONFIG_CONSOLE_WIDTH
8435 #define CATCH_CLARA_CONFIG_CONSOLE_WIDTH 80
8438 #ifndef CATCH_CLARA_TEXTFLOW_CONFIG_CONSOLE_WIDTH
8439 #define CATCH_CLARA_TEXTFLOW_CONFIG_CONSOLE_WIDTH CATCH_CLARA_CONFIG_CONSOLE_WIDTH
8442 #ifndef CLARA_CONFIG_OPTIONAL_TYPE
8443 #ifdef __has_include
8444 #if __has_include(<optional>) && __cplusplus >= 201703L
8446 #define CLARA_CONFIG_OPTIONAL_TYPE std::optional
8468 #ifndef CATCH_CLARA_TEXTFLOW_CONFIG_CONSOLE_WIDTH
8469 #define CATCH_CLARA_TEXTFLOW_CONFIG_CONSOLE_WIDTH 80
8474 namespace TextFlow {
8476 inline auto isWhitespace(
char c) ->
bool {
8477 static std::string chars =
" \t\n\r";
8478 return chars.find(c) != std::string::npos;
8480 inline auto isBreakableBefore(
char c) ->
bool {
8481 static std::string chars =
"[({<|";
8482 return chars.find(c) != std::string::npos;
8484 inline auto isBreakableAfter(
char c) ->
bool {
8485 static std::string chars =
"])}>.,:;*+-=&/\\";
8486 return chars.find(c) != std::string::npos;
8492 std::vector<std::string> m_strings;
8493 size_t m_width = CATCH_CLARA_TEXTFLOW_CONFIG_CONSOLE_WIDTH;
8494 size_t m_indent = 0;
8495 size_t m_initialIndent = std::string::npos;
8501 Column
const& m_column;
8502 size_t m_stringIndex = 0;
8507 bool m_suffix =
false;
8509 iterator(Column
const& column,
size_t stringIndex)
8511 m_stringIndex(stringIndex) {}
8513 auto line() const -> std::
string const& {
return m_column.m_strings[m_stringIndex]; }
8515 auto isBoundary(
size_t at)
const ->
bool {
8517 assert(at <= line().size());
8519 return at == line().size() ||
8520 (isWhitespace(line()[at]) && !isWhitespace(line()[at - 1])) ||
8521 isBreakableBefore(line()[at]) ||
8522 isBreakableAfter(line()[at - 1]);
8526 assert(m_stringIndex < m_column.m_strings.size());
8529 auto width = m_column.m_width - indent();
8531 if (line()[m_pos] ==
'\n') {
8534 while (m_end < line().size() && line()[m_end] !=
'\n')
8537 if (m_end < m_pos +
width) {
8538 m_len = m_end - m_pos;
8541 while (len > 0 && !isBoundary(m_pos + len))
8543 while (len > 0 && isWhitespace(line()[m_pos + len - 1]))
8555 auto indent() const ->
size_t {
8556 auto initial = m_pos == 0 && m_stringIndex == 0 ? m_column.m_initialIndent : std::string::npos;
8557 return initial == std::string::npos ? m_column.m_indent : initial;
8560 auto addIndentAndSuffix(std::string
const &plain)
const -> std::string {
8561 return std::string(indent(),
' ') + (m_suffix ? plain + "-" : plain);
8565 using difference_type = std::ptrdiff_t;
8566 using value_type = std::string;
8567 using pointer = value_type * ;
8568 using reference = value_type & ;
8569 using iterator_category = std::forward_iterator_tag;
8571 explicit iterator(Column
const& column) : m_column(column) {
8572 assert(m_column.m_width > m_column.m_indent);
8573 assert(m_column.m_initialIndent == std::string::npos || m_column.m_width > m_column.m_initialIndent);
8579 auto operator *() const -> std::
string {
8580 assert(m_stringIndex < m_column.m_strings.size());
8581 assert(m_pos <= m_end);
8582 return addIndentAndSuffix(line().substr(m_pos, m_len));
8585 auto operator ++() -> iterator& {
8587 if (m_pos < line().size() && line()[m_pos] ==
'\n')
8590 while (m_pos < line().size() && isWhitespace(line()[m_pos]))
8593 if (m_pos == line().size()) {
8597 if (m_stringIndex < m_column.m_strings.size())
8601 auto operator ++(
int) -> iterator {
8602 iterator prev(*
this);
8607 auto operator ==(iterator
const& other)
const ->
bool {
8609 m_pos == other.m_pos &&
8610 m_stringIndex == other.m_stringIndex &&
8611 &m_column == &other.m_column;
8613 auto operator !=(iterator
const& other)
const ->
bool {
8617 using const_iterator = iterator;
8619 explicit Column(std::string
const& text) { m_strings.push_back(text); }
8621 auto width(
size_t newWidth) -> Column& {
8622 assert(newWidth > 0);
8626 auto indent(
size_t newIndent) -> Column& {
8627 m_indent = newIndent;
8630 auto initialIndent(
size_t newIndent) -> Column& {
8631 m_initialIndent = newIndent;
8635 auto width() const ->
size_t {
return m_width; }
8636 auto begin() const -> iterator {
return iterator(*
this); }
8637 auto end() const -> iterator {
return { *
this, m_strings.size() }; }
8639 inline friend std::ostream&
operator << (std::ostream& os, Column
const& col) {
8641 for (
auto line : col) {
8651 auto operator + (Column
const& other)->Columns;
8653 auto toString() const -> std::
string {
8654 std::ostringstream oss;
8660 class Spacer :
public Column {
8663 explicit Spacer(
size_t spaceWidth) : Column(
"") {
8669 std::vector<Column> m_columns;
8677 std::vector<Column>
const& m_columns;
8678 std::vector<Column::iterator> m_iterators;
8679 size_t m_activeIterators;
8681 iterator(Columns
const& columns, EndTag)
8682 : m_columns(columns.m_columns),
8683 m_activeIterators(0) {
8684 m_iterators.reserve(m_columns.size());
8686 for (
auto const& col : m_columns)
8687 m_iterators.push_back(col.end());
8691 using difference_type = std::ptrdiff_t;
8692 using value_type = std::string;
8693 using pointer = value_type * ;
8694 using reference = value_type & ;
8695 using iterator_category = std::forward_iterator_tag;
8697 explicit iterator(Columns
const& columns)
8698 : m_columns(columns.m_columns),
8699 m_activeIterators(m_columns.size()) {
8700 m_iterators.reserve(m_columns.size());
8702 for (
auto const& col : m_columns)
8703 m_iterators.push_back(col.begin());
8706 auto operator ==(iterator
const& other)
const ->
bool {
8707 return m_iterators == other.m_iterators;
8709 auto operator !=(iterator
const& other)
const ->
bool {
8710 return m_iterators != other.m_iterators;
8712 auto operator *() const -> std::
string {
8713 std::string row, padding;
8715 for (
size_t i = 0; i < m_columns.size(); ++i) {
8716 auto width = m_columns[i].width();
8717 if (m_iterators[i] != m_columns[i].end()) {
8718 std::string col = *m_iterators[i];
8719 row += padding + col;
8720 if (col.size() <
width)
8721 padding = std::string(
width - col.size(),
' ');
8725 padding += std::string(
width, ' ');
8730 auto operator ++() -> iterator& {
8731 for (
size_t i = 0; i < m_columns.size(); ++i) {
8732 if (m_iterators[i] != m_columns[i].end())
8737 auto operator ++(
int) -> iterator {
8738 iterator prev(*
this);
8743 using const_iterator = iterator;
8745 auto begin() const -> iterator {
return iterator(*
this); }
8746 auto end() const -> iterator {
return { *
this, iterator::EndTag() }; }
8748 auto operator += (Column
const& col) -> Columns& {
8749 m_columns.push_back(col);
8752 auto operator + (Column
const& col) -> Columns {
8753 Columns combined = *
this;
8758 inline friend std::ostream&
operator << (std::ostream& os, Columns
const& cols) {
8761 for (
auto line : cols) {
8771 auto toString() const -> std::
string {
8772 std::ostringstream oss;
8796 #include <algorithm>
8798 #if !defined(CATCH_PLATFORM_WINDOWS) && ( defined(WIN32) || defined(__WIN32__) || defined(_WIN32) || defined(_MSC_VER) )
8799 #define CATCH_PLATFORM_WINDOWS
8802 namespace Catch {
namespace clara {
8806 template<
typename L>
8807 struct UnaryLambdaTraits : UnaryLambdaTraits<decltype( &L::operator() )> {};
8809 template<
typename ClassT,
typename ReturnT,
typename... Args>
8810 struct UnaryLambdaTraits<ReturnT( ClassT::* )( Args... ) const> {
8811 static const bool isValid =
false;
8814 template<
typename ClassT,
typename ReturnT,
typename ArgT>
8815 struct UnaryLambdaTraits<ReturnT( ClassT::* )( ArgT ) const> {
8816 static const bool isValid =
true;
8817 using ArgType =
typename std::remove_const<typename std::remove_reference<ArgT>::type>::type;
8818 using ReturnType = ReturnT;
8826 std::string m_exeName;
8827 std::vector<std::string> m_args;
8830 Args(
int argc,
char const*
const* argv )
8831 : m_exeName(argv[0]),
8832 m_args(argv + 1, argv + argc) {}
8834 Args( std::initializer_list<std::string> args )
8835 : m_exeName( *args.begin() ),
8836 m_args( args.begin()+1, args.end() )
8839 auto exeName() const -> std::
string {
8846 enum class TokenType {
8854 inline auto isOptPrefix(
char c ) ->
bool {
8856 #ifdef CATCH_PLATFORM_WINDOWS
8864 using Iterator = std::vector<std::string>::const_iterator;
8867 std::vector<Token> m_tokenBuffer;
8870 m_tokenBuffer.resize( 0 );
8873 while(
it != itEnd &&
it->empty() )
8877 auto const &next = *
it;
8878 if( isOptPrefix( next[0] ) ) {
8879 auto delimiterPos = next.find_first_of(
" :=" );
8880 if( delimiterPos != std::string::npos ) {
8881 m_tokenBuffer.push_back( { TokenType::Option, next.substr( 0, delimiterPos ) } );
8882 m_tokenBuffer.push_back( { TokenType::Argument, next.substr( delimiterPos + 1 ) } );
8884 if( next[1] !=
'-' && next.size() > 2 ) {
8885 std::string opt =
"- ";
8886 for(
size_t i = 1; i < next.size(); ++i ) {
8888 m_tokenBuffer.push_back( { TokenType::Option, opt } );
8891 m_tokenBuffer.push_back( { TokenType::Option, next } );
8895 m_tokenBuffer.push_back( { TokenType::Argument, next } );
8901 explicit TokenStream( Args
const &args ) : TokenStream( args.m_args.begin(), args.m_args.end() ) {}
8903 TokenStream( Iterator
it, Iterator itEnd ) :
it(
it ), itEnd( itEnd ) {
8907 explicit operator bool()
const {
8908 return !m_tokenBuffer.empty() ||
it != itEnd;
8911 auto count() const ->
size_t {
return m_tokenBuffer.size() + (itEnd -
it); }
8913 auto operator*() const -> Token {
8914 assert( !m_tokenBuffer.empty() );
8915 return m_tokenBuffer.front();
8918 auto operator->() const -> Token const * {
8919 assert( !m_tokenBuffer.empty() );
8920 return &m_tokenBuffer.front();
8923 auto operator++() -> TokenStream & {
8924 if( m_tokenBuffer.size() >= 2 ) {
8925 m_tokenBuffer.erase( m_tokenBuffer.begin() );
8938 Ok, LogicError, RuntimeError
8942 ResultBase( Type type ) : m_type( type ) {}
8943 virtual ~ResultBase() =
default;
8945 virtual void enforceOk()
const = 0;
8950 template<
typename T>
8951 class ResultValueBase :
public ResultBase {
8953 auto value() const -> T const & {
8959 ResultValueBase( Type type ) : ResultBase( type ) {}
8961 ResultValueBase( ResultValueBase
const &other ) : ResultBase( other ) {
8962 if( m_type == ResultBase::Ok )
8963 new( &m_value ) T( other.m_value );
8966 ResultValueBase( Type, T
const &
value ) : ResultBase( Ok ) {
8967 new( &m_value ) T(
value );
8970 auto operator=( ResultValueBase
const &other ) -> ResultValueBase & {
8971 if( m_type == ResultBase::Ok )
8973 ResultBase::operator=(other);
8974 if( m_type == ResultBase::Ok )
8975 new( &m_value ) T( other.m_value );
8979 ~ResultValueBase()
override {
8990 class ResultValueBase<void> :
public ResultBase {
8992 using ResultBase::ResultBase;
8995 template<
typename T =
void>
8996 class BasicResult :
public ResultValueBase<T> {
8998 template<
typename U>
8999 explicit BasicResult( BasicResult<U>
const &other )
9000 : ResultValueBase<T>( other.type() ),
9001 m_errorMessage( other.errorMessage() )
9003 assert( type() != ResultBase::Ok );
9006 template<
typename U>
9007 static auto ok( U
const &
value ) -> BasicResult {
return { ResultBase::Ok,
value }; }
9008 static auto ok() -> BasicResult {
return { ResultBase::Ok }; }
9009 static auto logicError( std::string
const &message ) -> BasicResult {
return { ResultBase::LogicError, message }; }
9010 static auto runtimeError( std::string
const &message ) -> BasicResult {
return { ResultBase::RuntimeError, message }; }
9012 explicit operator bool()
const {
return m_type == ResultBase::Ok; }
9013 auto type() const -> ResultBase::Type {
return m_type; }
9014 auto errorMessage() const -> std::
string {
return m_errorMessage; }
9017 void enforceOk()
const override {
9021 assert( m_type != ResultBase::LogicError );
9022 assert( m_type != ResultBase::RuntimeError );
9023 if( m_type != ResultBase::Ok )
9027 std::string m_errorMessage;
9029 BasicResult( ResultBase::Type type, std::string
const &message )
9030 : ResultValueBase<T>(type),
9031 m_errorMessage(message)
9033 assert( m_type != ResultBase::Ok );
9036 using ResultValueBase<T>::ResultValueBase;
9037 using ResultBase::m_type;
9040 enum class ParseResultType {
9041 Matched, NoMatch, ShortCircuitAll, ShortCircuitSame
9047 ParseState( ParseResultType type, TokenStream
const &remainingTokens )
9049 m_remainingTokens( remainingTokens )
9052 auto type() const -> ParseResultType {
return m_type; }
9053 auto remainingTokens() const -> TokenStream {
return m_remainingTokens; }
9056 ParseResultType m_type;
9057 TokenStream m_remainingTokens;
9060 using Result = BasicResult<void>;
9061 using ParserResult = BasicResult<ParseResultType>;
9062 using InternalParseResult = BasicResult<ParseState>;
9064 struct HelpColumns {
9069 template<
typename T>
9070 inline auto convertInto( std::string
const &source, T& target ) -> ParserResult {
9071 std::stringstream ss;
9075 return ParserResult::runtimeError(
"Unable to convert '" + source +
"' to destination type" );
9077 return ParserResult::ok( ParseResultType::Matched );
9079 inline auto convertInto( std::string
const &source, std::string& target ) -> ParserResult {
9081 return ParserResult::ok( ParseResultType::Matched );
9083 inline auto convertInto( std::string
const &source,
bool &target ) -> ParserResult {
9084 std::string srcLC = source;
9085 std::transform( srcLC.begin(), srcLC.end(), srcLC.begin(), [](
unsigned char c ) { return static_cast<char>( std::tolower(c) ); } );
9086 if (srcLC ==
"y" || srcLC ==
"1" || srcLC ==
"true" || srcLC ==
"yes" || srcLC ==
"on")
9088 else if (srcLC ==
"n" || srcLC ==
"0" || srcLC ==
"false" || srcLC ==
"no" || srcLC ==
"off")
9091 return ParserResult::runtimeError(
"Expected a boolean value but did not recognise: '" + source +
"'" );
9092 return ParserResult::ok( ParseResultType::Matched );
9094 #ifdef CLARA_CONFIG_OPTIONAL_TYPE
9095 template<
typename T>
9096 inline auto convertInto( std::string
const &source, CLARA_CONFIG_OPTIONAL_TYPE<T>& target ) -> ParserResult {
9098 auto result = convertInto( source, temp );
9100 target = std::move(temp);
9105 struct NonCopyable {
9106 NonCopyable() =
default;
9107 NonCopyable( NonCopyable
const & ) =
delete;
9108 NonCopyable( NonCopyable && ) =
delete;
9109 NonCopyable &operator=( NonCopyable
const & ) =
delete;
9110 NonCopyable &operator=( NonCopyable && ) =
delete;
9113 struct BoundRef : NonCopyable {
9114 virtual ~BoundRef() =
default;
9115 virtual auto isContainer() const ->
bool {
return false; }
9116 virtual auto isFlag() const ->
bool {
return false; }
9118 struct BoundValueRefBase : BoundRef {
9119 virtual auto setValue( std::string
const &arg ) -> ParserResult = 0;
9121 struct BoundFlagRefBase : BoundRef {
9122 virtual auto setFlag(
bool flag ) -> ParserResult = 0;
9123 virtual auto isFlag() const ->
bool {
return true; }
9126 template<
typename T>
9127 struct BoundValueRef : BoundValueRefBase {
9130 explicit BoundValueRef( T &ref ) : m_ref( ref ) {}
9132 auto setValue( std::string
const &arg ) -> ParserResult
override {
9133 return convertInto( arg, m_ref );
9137 template<
typename T>
9138 struct BoundValueRef<std::vector<T>> : BoundValueRefBase {
9139 std::vector<T> &m_ref;
9141 explicit BoundValueRef( std::vector<T> &ref ) : m_ref( ref ) {}
9143 auto isContainer() const ->
bool override {
return true; }
9145 auto setValue( std::string
const &arg ) -> ParserResult
override {
9147 auto result = convertInto( arg, temp );
9149 m_ref.push_back( temp );
9154 struct BoundFlagRef : BoundFlagRefBase {
9157 explicit BoundFlagRef(
bool &ref ) : m_ref( ref ) {}
9159 auto setFlag(
bool flag ) -> ParserResult
override {
9161 return ParserResult::ok( ParseResultType::Matched );
9165 template<
typename ReturnType>
9166 struct LambdaInvoker {
9169 template<
typename L,
typename ArgType>
9170 static auto invoke( L
const &lambda, ArgType
const &arg ) -> ParserResult {
9171 return lambda( arg );
9176 struct LambdaInvoker<void> {
9177 template<
typename L,
typename ArgType>
9178 static auto invoke( L
const &lambda, ArgType
const &arg ) -> ParserResult {
9180 return ParserResult::ok( ParseResultType::Matched );
9184 template<
typename ArgType,
typename L>
9185 inline auto invokeLambda( L
const &lambda, std::string
const &arg ) -> ParserResult {
9187 auto result = convertInto( arg, temp );
9190 : LambdaInvoker<typename UnaryLambdaTraits<L>::ReturnType>::invoke( lambda, temp );
9193 template<
typename L>
9194 struct BoundLambda : BoundValueRefBase {
9197 static_assert( UnaryLambdaTraits<L>::isValid,
"Supplied lambda must take exactly one argument" );
9198 explicit BoundLambda( L
const &lambda ) : m_lambda( lambda ) {}
9200 auto setValue( std::string
const &arg ) -> ParserResult
override {
9201 return invokeLambda<typename UnaryLambdaTraits<L>::ArgType>( m_lambda, arg );
9205 template<
typename L>
9206 struct BoundFlagLambda : BoundFlagRefBase {
9209 static_assert( UnaryLambdaTraits<L>::isValid,
"Supplied lambda must take exactly one argument" );
9210 static_assert( std::is_same<
typename UnaryLambdaTraits<L>::ArgType,
bool>::
value,
"flags must be boolean" );
9212 explicit BoundFlagLambda( L
const &lambda ) : m_lambda( lambda ) {}
9214 auto setFlag(
bool flag ) -> ParserResult
override {
9215 return LambdaInvoker<typename UnaryLambdaTraits<L>::ReturnType>::invoke( m_lambda, flag );
9219 enum class Optionality { Optional, Required };
9225 virtual ~ParserBase() =
default;
9226 virtual auto validate() const -> Result {
return Result::ok(); }
9227 virtual auto parse( std::string
const& exeName, TokenStream
const &tokens)
const -> InternalParseResult = 0;
9228 virtual auto cardinality() const ->
size_t {
return 1; }
9230 auto parse( Args
const &args )
const -> InternalParseResult {
9231 return parse( args.exeName(), TokenStream( args ) );
9235 template<
typename DerivedT>
9236 class ComposableParserImpl :
public ParserBase {
9238 template<
typename T>
9239 auto operator|( T
const &other )
const -> Parser;
9241 template<
typename T>
9242 auto operator+( T
const &other )
const -> Parser;
9246 template<
typename DerivedT>
9247 class ParserRefImpl :
public ComposableParserImpl<DerivedT> {
9249 Optionality m_optionality = Optionality::Optional;
9250 std::shared_ptr<BoundRef> m_ref;
9252 std::string m_description;
9254 explicit ParserRefImpl( std::shared_ptr<BoundRef>
const &ref ) : m_ref( ref ) {}
9257 template<
typename T>
9258 ParserRefImpl( T &ref, std::string
const &hint )
9259 : m_ref( std::make_shared<BoundValueRef<T>>( ref ) ),
9263 template<
typename LambdaT>
9264 ParserRefImpl( LambdaT
const &ref, std::string
const &hint )
9265 : m_ref( std::make_shared<BoundLambda<LambdaT>>( ref ) ),
9269 auto operator()( std::string
const &description ) -> DerivedT & {
9270 m_description = description;
9271 return static_cast<DerivedT &
>( *this );
9274 auto optional() -> DerivedT & {
9275 m_optionality = Optionality::Optional;
9276 return static_cast<DerivedT &
>( *this );
9279 auto required() -> DerivedT & {
9280 m_optionality = Optionality::Required;
9281 return static_cast<DerivedT &
>( *this );
9284 auto isOptional() const ->
bool {
9285 return m_optionality == Optionality::Optional;
9288 auto cardinality() const ->
size_t override {
9289 if( m_ref->isContainer() )
9295 auto hint() const -> std::
string {
return m_hint; }
9298 class ExeName :
public ComposableParserImpl<ExeName> {
9299 std::shared_ptr<std::string> m_name;
9300 std::shared_ptr<BoundValueRefBase> m_ref;
9302 template<
typename LambdaT>
9303 static auto makeRef(LambdaT
const &lambda) -> std::shared_ptr<BoundValueRefBase> {
9304 return std::make_shared<BoundLambda<LambdaT>>( lambda) ;
9308 ExeName() : m_name( std::make_shared<std::string>(
"<executable>" ) ) {}
9310 explicit ExeName( std::string &ref ) : ExeName() {
9311 m_ref = std::make_shared<BoundValueRef<std::string>>( ref );
9314 template<
typename LambdaT>
9315 explicit ExeName( LambdaT
const& lambda ) : ExeName() {
9316 m_ref = std::make_shared<BoundLambda<LambdaT>>( lambda );
9320 auto parse( std::string
const&, TokenStream
const &tokens )
const -> InternalParseResult
override {
9321 return InternalParseResult::ok( ParseState( ParseResultType::NoMatch, tokens ) );
9324 auto name() const -> std::
string {
return *m_name; }
9325 auto set( std::string
const& newName ) -> ParserResult {
9327 auto lastSlash = newName.find_last_of(
"\\/" );
9328 auto filename = ( lastSlash == std::string::npos )
9330 : newName.substr( lastSlash+1 );
9334 return m_ref->setValue( filename );
9336 return ParserResult::ok( ParseResultType::Matched );
9340 class Arg :
public ParserRefImpl<Arg> {
9342 using ParserRefImpl::ParserRefImpl;
9344 auto parse( std::string
const &, TokenStream
const &tokens )
const -> InternalParseResult
override {
9345 auto validationResult = validate();
9346 if( !validationResult )
9347 return InternalParseResult( validationResult );
9349 auto remainingTokens = tokens;
9350 auto const &token = *remainingTokens;
9351 if( token.type != TokenType::Argument )
9352 return InternalParseResult::ok( ParseState( ParseResultType::NoMatch, remainingTokens ) );
9354 assert( !m_ref->isFlag() );
9355 auto valueRef =
static_cast<detail::BoundValueRefBase*
>( m_ref.get() );
9357 auto result = valueRef->setValue( remainingTokens->token );
9359 return InternalParseResult( result );
9361 return InternalParseResult::ok( ParseState( ParseResultType::Matched, ++remainingTokens ) );
9365 inline auto normaliseOpt( std::string
const &optName ) -> std::string {
9366 #ifdef CATCH_PLATFORM_WINDOWS
9367 if( optName[0] ==
'/' )
9368 return "-" + optName.substr( 1 );
9374 class Opt :
public ParserRefImpl<Opt> {
9376 std::vector<std::string> m_optNames;
9379 template<
typename LambdaT>
9380 explicit Opt( LambdaT
const &ref ) : ParserRefImpl( std::make_shared<BoundFlagLambda<LambdaT>>( ref ) ) {}
9382 explicit Opt(
bool &ref ) : ParserRefImpl( std::make_shared<BoundFlagRef>( ref ) ) {}
9384 template<
typename LambdaT>
9385 Opt( LambdaT
const &ref, std::string
const &hint ) : ParserRefImpl( ref, hint ) {}
9387 template<
typename T>
9388 Opt( T &ref, std::string
const &hint ) : ParserRefImpl( ref, hint ) {}
9390 auto operator[]( std::string
const &optName ) -> Opt & {
9391 m_optNames.push_back( optName );
9395 auto getHelpColumns() const -> std::vector<HelpColumns> {
9396 std::ostringstream oss;
9398 for(
auto const &opt : m_optNames ) {
9405 if( !m_hint.empty() )
9406 oss <<
" <" << m_hint <<
">";
9407 return { { oss.str(), m_description } };
9410 auto isMatch( std::string
const &optToken )
const ->
bool {
9411 auto normalisedToken = normaliseOpt( optToken );
9412 for(
auto const &name : m_optNames ) {
9413 if( normaliseOpt( name ) == normalisedToken )
9419 using ParserBase::parse;
9421 auto parse( std::string
const&, TokenStream
const &tokens )
const -> InternalParseResult
override {
9422 auto validationResult = validate();
9423 if( !validationResult )
9424 return InternalParseResult( validationResult );
9426 auto remainingTokens = tokens;
9427 if( remainingTokens && remainingTokens->type == TokenType::Option ) {
9428 auto const &token = *remainingTokens;
9429 if( isMatch(token.token ) ) {
9430 if( m_ref->isFlag() ) {
9431 auto flagRef =
static_cast<detail::BoundFlagRefBase*
>( m_ref.get() );
9432 auto result = flagRef->setFlag(
true );
9434 return InternalParseResult( result );
9435 if( result.value() == ParseResultType::ShortCircuitAll )
9436 return InternalParseResult::ok( ParseState( result.value(), remainingTokens ) );
9438 auto valueRef =
static_cast<detail::BoundValueRefBase*
>( m_ref.get() );
9440 if( !remainingTokens )
9441 return InternalParseResult::runtimeError(
"Expected argument following " + token.token );
9442 auto const &argToken = *remainingTokens;
9443 if( argToken.type != TokenType::Argument )
9444 return InternalParseResult::runtimeError(
"Expected argument following " + token.token );
9445 auto result = valueRef->setValue( argToken.token );
9447 return InternalParseResult( result );
9448 if( result.value() == ParseResultType::ShortCircuitAll )
9449 return InternalParseResult::ok( ParseState( result.value(), remainingTokens ) );
9451 return InternalParseResult::ok( ParseState( ParseResultType::Matched, ++remainingTokens ) );
9454 return InternalParseResult::ok( ParseState( ParseResultType::NoMatch, remainingTokens ) );
9457 auto validate() const -> Result
override {
9458 if( m_optNames.empty() )
9459 return Result::logicError(
"No options supplied to Opt" );
9460 for(
auto const &name : m_optNames ) {
9462 return Result::logicError(
"Option name cannot be empty" );
9463 #ifdef CATCH_PLATFORM_WINDOWS
9464 if( name[0] !=
'-' && name[0] !=
'/' )
9465 return Result::logicError(
"Option name must begin with '-' or '/'" );
9467 if( name[0] !=
'-' )
9468 return Result::logicError(
"Option name must begin with '-'" );
9471 return ParserRefImpl::validate();
9476 Help(
bool &showHelpFlag )
9477 : Opt([&]( bool flag ) {
9478 showHelpFlag = flag;
9479 return ParserResult::ok( ParseResultType::ShortCircuitAll );
9482 static_cast<Opt &
>( *this )
9483 (
"display usage information")
9484 [
"-?"][
"-h"][
"--help"]
9489 struct Parser : ParserBase {
9491 mutable ExeName m_exeName;
9492 std::vector<Opt> m_options;
9493 std::vector<Arg> m_args;
9495 auto operator|=( ExeName
const &exeName ) -> Parser & {
9496 m_exeName = exeName;
9500 auto operator|=( Arg
const &arg ) -> Parser & {
9501 m_args.push_back(arg);
9505 auto operator|=( Opt
const &opt ) -> Parser & {
9506 m_options.push_back(opt);
9510 auto operator|=( Parser
const &other ) -> Parser & {
9511 m_options.insert(m_options.end(), other.m_options.begin(), other.m_options.end());
9512 m_args.insert(m_args.end(), other.m_args.begin(), other.m_args.end());
9516 template<
typename T>
9517 auto operator|( T
const &other )
const -> Parser {
9518 return Parser( *
this ) |= other;
9522 template<
typename T>
9523 auto operator+=( T
const &other ) -> Parser & {
return operator|=( other ); }
9524 template<
typename T>
9527 auto getHelpColumns() const -> std::vector<HelpColumns> {
9528 std::vector<HelpColumns> cols;
9529 for (
auto const &o : m_options) {
9530 auto childCols = o.getHelpColumns();
9531 cols.insert( cols.end(), childCols.begin(), childCols.end() );
9536 void writeToStream( std::ostream &os )
const {
9537 if (!m_exeName.name().empty()) {
9538 os <<
"usage:\n" <<
" " << m_exeName.name() <<
" ";
9539 bool required =
true, first =
true;
9540 for(
auto const &arg : m_args ) {
9545 if( arg.isOptional() && required ) {
9549 os <<
"<" << arg.hint() <<
">";
9550 if( arg.cardinality() == 0 )
9555 if( !m_options.empty() )
9557 os <<
"\n\nwhere options are:" << std::endl;
9560 auto rows = getHelpColumns();
9561 size_t consoleWidth = CATCH_CLARA_CONFIG_CONSOLE_WIDTH;
9562 size_t optWidth = 0;
9563 for(
auto const &cols : rows )
9564 optWidth = (std::max)(optWidth, cols.left.size() + 2);
9566 optWidth = (std::min)(optWidth, consoleWidth/2);
9568 for(
auto const &cols : rows ) {
9570 TextFlow::Column( cols.left ).width( optWidth ).indent( 2 ) +
9571 TextFlow::Spacer(4) +
9572 TextFlow::Column( cols.right ).width( consoleWidth - 7 - optWidth );
9573 os << row << std::endl;
9577 friend auto operator<<( std::ostream &os, Parser
const &parser ) -> std::ostream& {
9578 parser.writeToStream( os );
9582 auto validate() const -> Result
override {
9583 for(
auto const &opt : m_options ) {
9584 auto result = opt.validate();
9588 for(
auto const &arg : m_args ) {
9589 auto result = arg.validate();
9593 return Result::ok();
9596 using ParserBase::parse;
9598 auto parse( std::string
const& exeName, TokenStream
const &tokens )
const -> InternalParseResult
override {
9601 ParserBase
const* parser =
nullptr;
9604 const size_t totalParsers = m_options.size() + m_args.size();
9605 assert( totalParsers < 512 );
9607 ParserInfo parseInfos[512];
9611 for (
auto const &opt : m_options) parseInfos[i++].parser = &opt;
9612 for (
auto const &arg : m_args) parseInfos[i++].parser = &arg;
9615 m_exeName.set( exeName );
9617 auto result = InternalParseResult::ok( ParseState( ParseResultType::NoMatch, tokens ) );
9618 while( result.value().remainingTokens() ) {
9619 bool tokenParsed =
false;
9621 for(
size_t i = 0; i < totalParsers; ++i ) {
9622 auto& parseInfo = parseInfos[i];
9623 if( parseInfo.parser->cardinality() == 0 || parseInfo.count < parseInfo.parser->cardinality() ) {
9624 result = parseInfo.parser->parse(exeName, result.value().remainingTokens());
9627 if (result.value().type() != ParseResultType::NoMatch) {
9635 if( result.value().type() == ParseResultType::ShortCircuitAll )
9638 return InternalParseResult::runtimeError(
"Unrecognised token: " + result.value().remainingTokens()->token );
9645 template<
typename DerivedT>
9646 template<
typename T>
9648 return Parser() |
static_cast<DerivedT
const &
>( *this ) | other;
9653 using detail::Parser;
9665 using detail::ExeName;
9671 using detail::ParseResultType;
9674 using detail::ParserResult;
9680 #pragma clang diagnostic pop
9684 #ifdef CATCH_TEMP_CLARA_CONFIG_CONSOLE_WIDTH
9685 #define CATCH_CLARA_TEXTFLOW_CONFIG_CONSOLE_WIDTH CATCH_TEMP_CLARA_CONFIG_CONSOLE_WIDTH
9686 #undef CATCH_TEMP_CLARA_CONFIG_CONSOLE_WIDTH
9692 clara::Parser makeCommandLineParser( ConfigData& config );
9702 clara::Parser makeCommandLineParser( ConfigData& config ) {
9704 using namespace clara;
9706 auto const setWarning = [&]( std::string
const&
warning ) {
9707 auto warningSet = [&]() {
9708 if( warning ==
"NoAssertions" )
9711 if ( warning ==
"NoTests" )
9718 return ParserResult::runtimeError(
"Unrecognised warning: '" + warning +
"'" );
9719 config.warnings =
static_cast<WarnAbout::What>( config.warnings | warningSet );
9720 return ParserResult::ok( ParseResultType::Matched );
9722 auto const loadTestNamesFromFile = [&]( std::string
const& filename ) {
9723 std::ifstream f( filename.c_str() );
9725 return ParserResult::runtimeError(
"Unable to load input file: '" + filename +
"'" );
9728 while( std::getline( f, line ) ) {
9730 if( !line.empty() && !
startsWith( line,
'#' ) ) {
9732 line =
'"' + line + '"';
9733 config.testsOrTags.push_back( line );
9734 config.testsOrTags.emplace_back(
"," );
9738 if(!config.testsOrTags.empty())
9739 config.testsOrTags.erase( config.testsOrTags.end()-1 );
9741 return ParserResult::ok( ParseResultType::Matched );
9743 auto const setTestOrder = [&]( std::string
const& order ) {
9751 return clara::ParserResult::runtimeError(
"Unrecognised ordering: '" + order +
"'" );
9752 return ParserResult::ok( ParseResultType::Matched );
9754 auto const setRngSeed = [&]( std::string
const& seed ) {
9755 if( seed !=
"time" )
9756 return clara::detail::convertInto( seed, config.rngSeed );
9757 config.rngSeed =
static_cast<unsigned int>( std::time(
nullptr) );
9758 return ParserResult::ok( ParseResultType::Matched );
9760 auto const setColourUsage = [&]( std::string
const& useColour ) {
9761 auto mode =
toLower( useColour );
9765 else if( mode ==
"no" )
9767 else if( mode ==
"auto" )
9770 return ParserResult::runtimeError(
"colour mode must be one of: auto, yes or no. '" + useColour +
"' not recognised" );
9771 return ParserResult::ok( ParseResultType::Matched );
9773 auto const setWaitForKeypress = [&]( std::string
const& keypress ) {
9774 auto keypressLc =
toLower( keypress );
9775 if (keypressLc ==
"never")
9777 else if( keypressLc ==
"start" )
9779 else if( keypressLc ==
"exit" )
9781 else if( keypressLc ==
"both" )
9784 return ParserResult::runtimeError(
"keypress argument must be one of: never, start, exit or both. '" + keypress +
"' not recognised" );
9785 return ParserResult::ok( ParseResultType::Matched );
9787 auto const setVerbosity = [&]( std::string
const& verbosity ) {
9788 auto lcVerbosity =
toLower( verbosity );
9789 if( lcVerbosity ==
"quiet" )
9791 else if( lcVerbosity ==
"normal" )
9793 else if( lcVerbosity ==
"high" )
9796 return ParserResult::runtimeError(
"Unrecognised verbosity, '" + verbosity +
"'" );
9797 return ParserResult::ok( ParseResultType::Matched );
9799 auto const setReporter = [&]( std::string
const& reporter ) {
9802 auto lcReporter =
toLower( reporter );
9803 auto result = factories.find( lcReporter );
9805 if( factories.end() != result )
9806 config.reporterName = lcReporter;
9808 return ParserResult::runtimeError(
"Unrecognized reporter, '" + reporter +
"'. Check available with --list-reporters" );
9809 return ParserResult::ok( ParseResultType::Matched );
9813 = ExeName( config.processName )
9814 | Help( config.showHelp )
9815 | Opt( config.listTests )
9816 ["-l"]["--list-tests"]
9817 (
"list all/matching test cases" )
9818 | Opt( config.listTags )
9819 ["-t"]["--list-tags"]
9820 (
"list all/matching tags" )
9821 | Opt( config.showSuccessfulTests )
9823 (
"include successful tests in output" )
9824 | Opt( config.shouldDebugBreak )
9826 (
"break into debugger on failure" )
9827 | Opt( config.noThrow )
9829 (
"skip exception tests" )
9830 | Opt( config.showInvisibles )
9831 ["-i"]["--invisibles"]
9832 (
"show invisibles (tabs, newlines)" )
9833 | Opt( config.outputFilename,
"filename" )
9835 (
"output filename" )
9836 | Opt( setReporter,
"name" )
9837 ["-r"]["--reporter"]
9838 (
"reporter to use (defaults to console)" )
9839 | Opt( config.name,
"name" )
9842 | Opt( [&](
bool ){ config.abortAfter = 1; } )
9844 (
"abort at first failure" )
9845 | Opt( [&](
int x ){ config.abortAfter = x; },
"no. failures" )
9847 (
"abort after x failures" )
9848 | Opt( setWarning,
"warning name" )
9850 (
"enable warnings" )
9852 [
"-d"][
"--durations"]
9853 (
"show test durations" )
9854 | Opt( config.minDuration,
"seconds" )
9855 ["-D"]["--min-duration"]
9856 (
"show test durations for tests taking at least the given number of seconds" )
9857 | Opt( loadTestNamesFromFile,
"filename" )
9858 ["-f"]["--input-file"]
9859 (
"load test names to run from a file" )
9860 | Opt( config.filenamesAsTags )
9861 ["-#"]["--filenames-as-tags"]
9862 (
"adds a tag for the filename" )
9863 | Opt( config.sectionsToRun,
"section name" )
9865 (
"specify section to run" )
9866 | Opt( setVerbosity,
"quiet|normal|high" )
9867 ["-v"]["--verbosity"]
9868 (
"set output verbosity" )
9869 | Opt( config.listTestNamesOnly )
9870 ["--list-test-names-only"]
9871 (
"list all/matching test cases names only" )
9872 | Opt( config.listReporters )
9873 ["--list-reporters"]
9874 (
"list all reporters" )
9875 | Opt( setTestOrder,
"decl|lex|rand" )
9877 (
"test case order (defaults to decl)" )
9878 | Opt( setRngSeed,
"'time'|number" )
9880 (
"set a specific seed for random numbers" )
9881 | Opt( setColourUsage,
"yes|no" )
9883 (
"should output be colourised" )
9884 | Opt( config.libIdentify )
9886 (
"report name and version according to libidentify standard" )
9887 | Opt( setWaitForKeypress,
"never|start|exit|both" )
9888 ["--wait-for-keypress"]
9889 (
"waits for a keypress before exiting" )
9890 | Opt( config.benchmarkSamples,
"samples" )
9891 ["--benchmark-samples"]
9892 (
"number of samples to collect (default: 100)" )
9893 | Opt( config.benchmarkResamples,
"resamples" )
9894 ["--benchmark-resamples"]
9895 (
"number of resamples for the bootstrap (default: 100000)" )
9896 | Opt( config.benchmarkConfidenceInterval,
"confidence interval" )
9897 ["--benchmark-confidence-interval"]
9898 (
"confidence interval for the bootstrap (between 0 and 1, default: 0.95)" )
9899 | Opt( config.benchmarkNoAnalysis )
9900 ["--benchmark-no-analysis"]
9901 (
"perform only measurements; do not perform any analysis" )
9902 | Opt( config.benchmarkWarmupTime,
"benchmarkWarmupTime" )
9903 ["--benchmark-warmup-time"]
9904 (
"amount of time in milliseconds spent on warming up each test (default: 100)" )
9905 | Arg( config.testsOrTags,
"test name|pattern|tags" )
9906 (
"which test or tests to use" );
9921 return line == other.line && (file == other.file || std::strcmp(file, other.file) == 0);
9926 return line < other.line || ( line == other.line && file != other.file && (std::strcmp(file, other.file) < 0));
9929 std::ostream&
operator << ( std::ostream& os, SourceLineInfo
const& info ) {
9931 os <<
info.file <<
'(' <<
info.line <<
')';
9933 os <<
info.file <<
':' <<
info.line;
9939 return std::string();
9951 Config::Config( ConfigData
const& data )
9953 m_stream( openStream() )
9959 for (
auto& elem : m_data.testsOrTags) {
9962 for (
auto& elem : m_data.sectionsToRun) {
9966 TestSpecParser parser(ITagAliasRegistry::get());
9967 if (!m_data.testsOrTags.empty()) {
9968 m_hasTestFilters =
true;
9969 for (
auto const& testOrTags : m_data.testsOrTags) {
9970 parser.parse(testOrTags);
9973 m_testSpec = parser.testSpec();
9976 std::string
const& Config::getFilename()
const {
9977 return m_data.outputFilename ;
9980 bool Config::listTests()
const {
return m_data.listTests; }
9981 bool Config::listTestNamesOnly()
const {
return m_data.listTestNamesOnly; }
9982 bool Config::listTags()
const {
return m_data.listTags; }
9983 bool Config::listReporters()
const {
return m_data.listReporters; }
9985 std::string Config::getProcessName()
const {
return m_data.processName; }
9986 std::string
const& Config::getReporterName()
const {
return m_data.reporterName; }
9988 std::vector<std::string>
const& Config::getTestsOrTags()
const {
return m_data.testsOrTags; }
9989 std::vector<std::string>
const& Config::getSectionsToRun()
const {
return m_data.sectionsToRun; }
9991 TestSpec
const& Config::testSpec()
const {
return m_testSpec; }
9992 bool Config::hasTestFilters()
const {
return m_hasTestFilters; }
9994 bool Config::showHelp()
const {
return m_data.showHelp; }
9997 bool Config::allowThrows()
const {
return !m_data.noThrow; }
9998 std::ostream& Config::stream()
const {
return m_stream->stream(); }
9999 std::string Config::name()
const {
return m_data.name.empty() ? m_data.processName : m_data.name; }
10000 bool Config::includeSuccessfulResults()
const {
return m_data.showSuccessfulTests; }
10002 bool Config::warnAboutNoTests()
const {
return !!(m_data.warnings &
WarnAbout::NoTests); }
10004 double Config::minDuration()
const {
return m_data.minDuration; }
10008 bool Config::shouldDebugBreak()
const {
return m_data.shouldDebugBreak; }
10009 int Config::abortAfter()
const {
return m_data.abortAfter; }
10010 bool Config::showInvisibles()
const {
return m_data.showInvisibles; }
10011 Verbosity Config::verbosity()
const {
return m_data.verbosity; }
10013 bool Config::benchmarkNoAnalysis()
const {
return m_data.benchmarkNoAnalysis; }
10014 int Config::benchmarkSamples()
const {
return m_data.benchmarkSamples; }
10015 double Config::benchmarkConfidenceInterval()
const {
return m_data.benchmarkConfidenceInterval; }
10016 unsigned int Config::benchmarkResamples()
const {
return m_data.benchmarkResamples; }
10017 std::chrono::milliseconds Config::benchmarkWarmupTime()
const {
return std::chrono::milliseconds(m_data.benchmarkWarmupTime); }
10019 IStream
const* Config::openStream() {
10027 #if defined(__clang__)
10028 # pragma clang diagnostic push
10029 # pragma clang diagnostic ignored "-Wexit-time-destructors"
10050 #if defined(CATCH_PLATFORM_WINDOWS)
10052 #if !defined(NOMINMAX) && !defined(CATCH_CONFIG_NO_NOMINMAX)
10053 # define CATCH_DEFINED_NOMINMAX
10056 #if !defined(WIN32_LEAN_AND_MEAN) && !defined(CATCH_CONFIG_NO_WIN32_LEAN_AND_MEAN)
10057 # define CATCH_DEFINED_WIN32_LEAN_AND_MEAN
10058 # define WIN32_LEAN_AND_MEAN
10062 #include <AfxWin.h>
10064 #include <windows.h>
10067 #ifdef CATCH_DEFINED_NOMINMAX
10070 #ifdef CATCH_DEFINED_WIN32_LEAN_AND_MEAN
10071 # undef WIN32_LEAN_AND_MEAN
10082 struct IColourImpl {
10083 virtual ~IColourImpl() =
default;
10084 virtual void use( Colour::Code _colourCode ) = 0;
10087 struct NoColourImpl : IColourImpl {
10088 void use( Colour::Code )
override {}
10090 static IColourImpl* instance() {
10091 static NoColourImpl s_instance;
10092 return &s_instance;
10099 #if !defined( CATCH_CONFIG_COLOUR_NONE ) && !defined( CATCH_CONFIG_COLOUR_WINDOWS ) && !defined( CATCH_CONFIG_COLOUR_ANSI )
10100 # ifdef CATCH_PLATFORM_WINDOWS
10101 # define CATCH_CONFIG_COLOUR_WINDOWS
10103 # define CATCH_CONFIG_COLOUR_ANSI
10107 #if defined ( CATCH_CONFIG_COLOUR_WINDOWS )
10112 class Win32ColourImpl :
public IColourImpl {
10114 Win32ColourImpl() : stdoutHandle( GetStdHandle(STD_OUTPUT_HANDLE) )
10116 CONSOLE_SCREEN_BUFFER_INFO csbiInfo;
10117 GetConsoleScreenBufferInfo( stdoutHandle, &csbiInfo );
10118 originalForegroundAttributes = csbiInfo.wAttributes & ~( BACKGROUND_GREEN | BACKGROUND_RED | BACKGROUND_BLUE | BACKGROUND_INTENSITY );
10119 originalBackgroundAttributes = csbiInfo.wAttributes & ~( FOREGROUND_GREEN | FOREGROUND_RED | FOREGROUND_BLUE | FOREGROUND_INTENSITY );
10122 void use( Colour::Code _colourCode )
override {
10123 switch( _colourCode ) {
10124 case Colour::None:
return setTextAttribute( originalForegroundAttributes );
10125 case Colour::White:
return setTextAttribute( FOREGROUND_GREEN | FOREGROUND_RED | FOREGROUND_BLUE );
10126 case Colour::Red:
return setTextAttribute( FOREGROUND_RED );
10127 case Colour::Green:
return setTextAttribute( FOREGROUND_GREEN );
10128 case Colour::Blue:
return setTextAttribute( FOREGROUND_BLUE );
10129 case Colour::Cyan:
return setTextAttribute( FOREGROUND_BLUE | FOREGROUND_GREEN );
10130 case Colour::Yellow:
return setTextAttribute( FOREGROUND_RED | FOREGROUND_GREEN );
10131 case Colour::Grey:
return setTextAttribute( 0 );
10133 case Colour::LightGrey:
return setTextAttribute( FOREGROUND_INTENSITY );
10134 case Colour::BrightRed:
return setTextAttribute( FOREGROUND_INTENSITY | FOREGROUND_RED );
10135 case Colour::BrightGreen:
return setTextAttribute( FOREGROUND_INTENSITY | FOREGROUND_GREEN );
10136 case Colour::BrightWhite:
return setTextAttribute( FOREGROUND_INTENSITY | FOREGROUND_GREEN | FOREGROUND_RED | FOREGROUND_BLUE );
10137 case Colour::BrightYellow:
return setTextAttribute( FOREGROUND_INTENSITY | FOREGROUND_RED | FOREGROUND_GREEN );
10147 void setTextAttribute( WORD _textAttribute ) {
10148 SetConsoleTextAttribute( stdoutHandle, _textAttribute | originalBackgroundAttributes );
10151 WORD originalForegroundAttributes;
10152 WORD originalBackgroundAttributes;
10155 IColourImpl* platformColourInstance() {
10156 static Win32ColourImpl s_instance;
10160 ? config->useColour()
10166 : NoColourImpl::instance();
10172 #elif defined( CATCH_CONFIG_COLOUR_ANSI )
10174 #include <unistd.h>
10183 class PosixColourImpl :
public IColourImpl {
10185 void use( Colour::Code _colourCode )
override {
10186 switch( _colourCode ) {
10188 case Colour::White:
return setColour(
"[0m" );
10189 case Colour::Red:
return setColour(
"[0;31m" );
10190 case Colour::Green:
return setColour(
"[0;32m" );
10191 case Colour::Blue:
return setColour(
"[0;34m" );
10192 case Colour::Cyan:
return setColour(
"[0;36m" );
10193 case Colour::Yellow:
return setColour(
"[0;33m" );
10194 case Colour::Grey:
return setColour(
"[1;30m" );
10196 case Colour::LightGrey:
return setColour(
"[0;37m" );
10197 case Colour::BrightRed:
return setColour(
"[1;31m" );
10198 case Colour::BrightGreen:
return setColour(
"[1;32m" );
10199 case Colour::BrightWhite:
return setColour(
"[1;37m" );
10200 case Colour::BrightYellow:
return setColour(
"[1;33m" );
10206 static IColourImpl* instance() {
10207 static PosixColourImpl s_instance;
10208 return &s_instance;
10212 void setColour(
const char* _escapeCode ) {
10214 <<
'\033' << _escapeCode;
10218 bool useColourOnPlatform() {
10220 #if defined(CATCH_PLATFORM_MAC) || defined(CATCH_PLATFORM_IPHONE)
10221 !isDebuggerActive() &&
10223 #if !(defined(__DJGPP__) && defined(__STRICT_ANSI__))
10224 isatty(STDOUT_FILENO)
10230 IColourImpl* platformColourInstance() {
10234 ? config->useColour()
10237 colourMode = useColourOnPlatform()
10241 ? PosixColourImpl::instance()
10242 : NoColourImpl::instance();
10252 static IColourImpl* platformColourInstance() {
return NoColourImpl::instance(); }
10260 Colour::Colour( Code _colourCode ) { use( _colourCode ); }
10261 Colour::Colour( Colour&& other ) noexcept {
10262 m_moved = other.m_moved;
10263 other.m_moved =
true;
10265 Colour& Colour::operator=( Colour&& other ) noexcept {
10266 m_moved = other.m_moved;
10267 other.m_moved =
true;
10271 Colour::~Colour(){
if( !m_moved ) use( None ); }
10273 void Colour::use( Code _colourCode ) {
10274 static IColourImpl* impl = platformColourInstance();
10279 if (impl !=
nullptr) {
10280 impl->use( _colourCode );
10284 std::ostream&
operator << ( std::ostream& os, Colour
const& ) {
10290 #if defined(__clang__)
10291 # pragma clang diagnostic pop
10299 class Context :
public IMutableContext, NonCopyable {
10303 return m_resultCapture;
10305 IRunner* getRunner()
override {
10309 IConfigPtr const& getConfig()
const override {
10313 ~Context()
override;
10316 void setResultCapture( IResultCapture* resultCapture )
override {
10317 m_resultCapture = resultCapture;
10319 void setRunner( IRunner* runner )
override {
10322 void setConfig(
IConfigPtr const& config )
override {
10330 IRunner* m_runner =
nullptr;
10331 IResultCapture* m_resultCapture =
nullptr;
10347 Context::~Context() =
default;
10349 SimplePcg32&
rng() {
10350 static SimplePcg32 s_rng;
10363 void writeToDebugConsole( std::string
const& text );
10367 #if defined(CATCH_CONFIG_ANDROID_LOGWRITE)
10368 #include <android/log.h>
10371 void writeToDebugConsole( std::string
const& text ) {
10372 __android_log_write( ANDROID_LOG_DEBUG,
"Catch", text.c_str() );
10376 #elif defined(CATCH_PLATFORM_WINDOWS)
10379 void writeToDebugConsole( std::string
const& text ) {
10380 ::OutputDebugStringA( text.c_str() );
10387 void writeToDebugConsole( std::string
const& text ) {
10397 #if defined(CATCH_PLATFORM_MAC) || defined(CATCH_PLATFORM_IPHONE)
10399 # include <cassert>
10400 # include <sys/types.h>
10401 # include <unistd.h>
10402 # include <cstddef>
10403 # include <ostream>
10405 #ifdef __apple_build_version__
10408 # include <sys/sysctl.h>
10412 #ifdef __apple_build_version__
10418 bool isDebuggerActive(){
10420 struct kinfo_proc
info;
10426 info.kp_proc.p_flag = 0;
10432 mib[1] = KERN_PROC;
10433 mib[2] = KERN_PROC_PID;
10438 size =
sizeof(
info);
10439 if( sysctl(mib,
sizeof(mib) /
sizeof(*mib), &
info, &size,
nullptr, 0) != 0 ) {
10440 Catch::cerr() <<
"\n** Call to sysctl failed - unable to determine if debugger is active **\n" << std::endl;
10446 return ( (
info.kp_proc.p_flag & P_TRACED) != 0 );
10449 bool isDebuggerActive() {
10456 #elif defined(CATCH_PLATFORM_LINUX)
10468 bool isDebuggerActive(){
10472 std::ifstream in(
"/proc/self/status");
10473 for( std::string line; std::getline(in, line); ) {
10474 static const int PREFIX_LEN = 11;
10475 if( line.compare(0, PREFIX_LEN,
"TracerPid:\t") == 0 ) {
10479 return line.length() > PREFIX_LEN && line[PREFIX_LEN] !=
'0';
10486 #elif defined(_MSC_VER)
10487 extern "C" __declspec(dllimport)
int __stdcall IsDebuggerPresent();
10489 bool isDebuggerActive() {
10490 return IsDebuggerPresent() != 0;
10493 #elif defined(__MINGW32__)
10494 extern "C" __declspec(dllimport)
int __stdcall IsDebuggerPresent();
10496 bool isDebuggerActive() {
10497 return IsDebuggerPresent() != 0;
10502 bool isDebuggerActive() {
return false; }
10513 if( lhs.size() + rhs.size() < 40 &&
10514 lhs.find(
'\n') == std::string::npos &&
10515 rhs.find(
'\n') == std::string::npos )
10516 os << lhs <<
" " << op <<
" " << rhs;
10518 os << lhs <<
"\n" << op <<
"\n" << rhs;
10524 #include <stdexcept>
10527 #if defined(CATCH_CONFIG_DISABLE_EXCEPTIONS) && !defined(CATCH_CONFIG_DISABLE_EXCEPTIONS_CUSTOM_HANDLER)
10530 Catch::cerr() <<
"Catch will terminate because it needed to throw an exception.\n"
10531 <<
"The message was: " << e.what() <<
'\n';
10563 std::unique_ptr<EnumInfo> makeEnumInfo( StringRef enumName, StringRef allValueNames, std::vector<int>
const&
values );
10565 class EnumValuesRegistry :
public IMutableEnumValuesRegistry {
10567 std::vector<std::unique_ptr<EnumInfo>> m_enumInfos;
10569 EnumInfo
const& registerEnum( StringRef enumName, StringRef allEnums, std::vector<int>
const&
values)
override;
10572 std::vector<StringRef> parseEnums( StringRef enums );
10592 StringRef extractInstanceName(StringRef enumInstance) {
10594 size_t name_start = enumInstance.size();
10595 while (name_start > 0 && enumInstance[name_start - 1] !=
':') {
10598 return enumInstance.substr(name_start, enumInstance.size() - name_start);
10602 std::vector<StringRef> parseEnums( StringRef enums ) {
10604 std::vector<StringRef> parsed;
10605 parsed.reserve( enumValues.size() );
10606 for(
auto const& enumValue : enumValues ) {
10607 parsed.push_back(
trim(extractInstanceName(enumValue)));
10615 for(
auto const& valueToName :
m_values ) {
10616 if( valueToName.first ==
value )
10617 return valueToName.second;
10619 return "{** unexpected enum value **}"_sr;
10622 std::unique_ptr<EnumInfo> makeEnumInfo( StringRef enumName, StringRef allValueNames, std::vector<int>
const&
values ) {
10623 std::unique_ptr<EnumInfo> enumInfo(
new EnumInfo );
10624 enumInfo->m_name = enumName;
10625 enumInfo->m_values.reserve(
values.size() );
10627 const auto valueNames = Catch::Detail::parseEnums( allValueNames );
10628 assert( valueNames.size() ==
values.size() );
10631 enumInfo->m_values.emplace_back(
value, valueNames[i++]);
10636 EnumInfo
const& EnumValuesRegistry::registerEnum( StringRef enumName, StringRef allValueNames, std::vector<int>
const&
values ) {
10637 m_enumInfos.push_back(makeEnumInfo(enumName, allValueNames,
values));
10638 return *m_enumInfos.back();
10650 ErrnoGuard::ErrnoGuard():m_oldErrno(errno){}
10651 ErrnoGuard::~ErrnoGuard() { errno = m_oldErrno; }
10664 class ExceptionTranslatorRegistry :
public IExceptionTranslatorRegistry {
10666 ~ExceptionTranslatorRegistry();
10667 virtual void registerTranslator(
const IExceptionTranslator* translator );
10669 std::string tryTranslators()
const;
10672 std::vector<std::unique_ptr<IExceptionTranslator const>> m_translators;
10678 #import "Foundation/Foundation.h"
10683 ExceptionTranslatorRegistry::~ExceptionTranslatorRegistry() {
10686 void ExceptionTranslatorRegistry::registerTranslator(
const IExceptionTranslator* translator ) {
10687 m_translators.push_back( std::unique_ptr<const IExceptionTranslator>( translator ) );
10690 #if !defined(CATCH_CONFIG_DISABLE_EXCEPTIONS)
10696 return tryTranslators();
10698 @catch (NSException *exception) {
10710 if (std::current_exception() ==
nullptr) {
10711 return "Non C++ exception. Possibly a CLR exception.";
10713 return tryTranslators();
10716 catch( TestFailureException& ) {
10717 std::rethrow_exception(std::current_exception());
10719 catch( std::exception& ex ) {
10722 catch( std::string&
msg ) {
10725 catch(
const char*
msg ) {
10729 return "Unknown exception";
10733 std::string ExceptionTranslatorRegistry::tryTranslators()
const {
10734 if (m_translators.empty()) {
10735 std::rethrow_exception(std::current_exception());
10737 return m_translators[0]->translate(m_translators.begin() + 1, m_translators.end());
10743 CATCH_INTERNAL_ERROR(
"Attempted to translate active exception under CATCH_CONFIG_DISABLE_EXCEPTIONS!");
10746 std::string ExceptionTranslatorRegistry::tryTranslators()
const {
10747 CATCH_INTERNAL_ERROR(
"Attempted to use exception translators under CATCH_CONFIG_DISABLE_EXCEPTIONS!");
10755 #include <algorithm>
10757 #if !defined( CATCH_CONFIG_WINDOWS_SEH ) && !defined( CATCH_CONFIG_POSIX_SIGNALS )
10763 void FatalConditionHandler::engage_platform() {}
10764 void FatalConditionHandler::disengage_platform() {}
10765 FatalConditionHandler::FatalConditionHandler() =
default;
10766 FatalConditionHandler::~FatalConditionHandler() =
default;
10772 #if defined( CATCH_CONFIG_WINDOWS_SEH ) && defined( CATCH_CONFIG_POSIX_SIGNALS )
10773 #error "Inconsistent configuration: Windows' SEH handling and POSIX signals cannot be enabled at the same time"
10776 #if defined( CATCH_CONFIG_WINDOWS_SEH ) || defined( CATCH_CONFIG_POSIX_SIGNALS )
10780 void reportFatal(
char const *
const message ) {
10787 constexpr std::size_t minStackSizeForErrors = 32 * 1024;
10792 #if defined( CATCH_CONFIG_WINDOWS_SEH )
10796 struct SignalDefs { DWORD id;
const char* name; };
10801 static SignalDefs signalDefs[] = {
10802 {
static_cast<DWORD
>(EXCEPTION_ILLEGAL_INSTRUCTION),
"SIGILL - Illegal instruction signal" },
10803 {
static_cast<DWORD
>(EXCEPTION_STACK_OVERFLOW),
"SIGSEGV - Stack overflow" },
10804 {
static_cast<DWORD
>(EXCEPTION_ACCESS_VIOLATION),
"SIGSEGV - Segmentation violation signal" },
10805 {
static_cast<DWORD
>(EXCEPTION_INT_DIVIDE_BY_ZERO),
"Divide by zero error" },
10808 static LONG CALLBACK handleVectoredException(PEXCEPTION_POINTERS ExceptionInfo) {
10809 for (
auto const& def : signalDefs) {
10810 if (ExceptionInfo->ExceptionRecord->ExceptionCode == def.id) {
10811 reportFatal(def.name);
10816 return EXCEPTION_CONTINUE_SEARCH;
10822 static PVOID exceptionHandlerHandle =
nullptr;
10826 FatalConditionHandler::FatalConditionHandler() {
10827 ULONG guaranteeSize =
static_cast<ULONG
>(minStackSizeForErrors);
10828 if (!SetThreadStackGuarantee(&guaranteeSize)) {
10832 <<
"Failed to reserve piece of stack."
10833 <<
" Stack overflows will not be reported successfully.";
10839 FatalConditionHandler::~FatalConditionHandler() =
default;
10841 void FatalConditionHandler::engage_platform() {
10843 exceptionHandlerHandle = AddVectoredExceptionHandler(1, handleVectoredException);
10844 if (!exceptionHandlerHandle) {
10849 void FatalConditionHandler::disengage_platform() {
10850 if (!RemoveVectoredExceptionHandler(exceptionHandlerHandle)) {
10853 exceptionHandlerHandle =
nullptr;
10860 #if defined( CATCH_CONFIG_POSIX_SIGNALS )
10862 #include <signal.h>
10866 struct SignalDefs {
10871 static SignalDefs signalDefs[] = {
10872 { SIGINT,
"SIGINT - Terminal interrupt signal" },
10873 { SIGILL,
"SIGILL - Illegal instruction signal" },
10874 { SIGFPE,
"SIGFPE - Floating point error signal" },
10875 { SIGSEGV,
"SIGSEGV - Segmentation violation signal" },
10876 { SIGTERM,
"SIGTERM - Termination request signal" },
10877 { SIGABRT,
"SIGABRT - Abort (abnormal termination) signal" }
10883 #if defined(__GNUC__)
10884 # pragma GCC diagnostic push
10885 # pragma GCC diagnostic ignored "-Wmissing-field-initializers"
10888 static char* altStackMem =
nullptr;
10889 static std::size_t altStackSize = 0;
10890 static stack_t oldSigStack{};
10891 static struct sigaction oldSigActions[sizeof(signalDefs) / sizeof(SignalDefs)]{};
10893 static void restorePreviousSignalHandlers() {
10898 for (std::size_t i = 0; i <
sizeof(signalDefs) /
sizeof(SignalDefs); ++i) {
10899 sigaction(signalDefs[i].
id, &oldSigActions[i],
nullptr);
10902 sigaltstack(&oldSigStack,
nullptr);
10905 static void handleSignal(
int sig ) {
10906 char const * name =
"<unknown signal>";
10907 for (
auto const& def : signalDefs) {
10908 if (sig == def.id) {
10916 restorePreviousSignalHandlers();
10917 reportFatal( name );
10921 FatalConditionHandler::FatalConditionHandler() {
10922 assert(!altStackMem &&
"Cannot initialize POSIX signal handler when one already exists");
10923 if (altStackSize == 0) {
10924 altStackSize = std::max(
static_cast<size_t>(SIGSTKSZ), minStackSizeForErrors);
10926 altStackMem =
new char[altStackSize]();
10929 FatalConditionHandler::~FatalConditionHandler() {
10930 delete[] altStackMem;
10933 altStackMem =
nullptr;
10936 void FatalConditionHandler::engage_platform() {
10938 sigStack.ss_sp = altStackMem;
10939 sigStack.ss_size = altStackSize;
10940 sigStack.ss_flags = 0;
10941 sigaltstack(&sigStack, &oldSigStack);
10942 struct sigaction sa = { };
10944 sa.sa_handler = handleSignal;
10945 sa.sa_flags = SA_ONSTACK;
10946 for (std::size_t i = 0; i <
sizeof(signalDefs)/
sizeof(SignalDefs); ++i) {
10947 sigaction(signalDefs[i].
id, &sa, &oldSigActions[i]);
10951 #if defined(__GNUC__)
10952 # pragma GCC diagnostic pop
10955 void FatalConditionHandler::disengage_platform() {
10956 restorePreviousSignalHandlers();
10976 namespace Generators {
10980 auto acquireGeneratorTracker( StringRef generatorName, SourceLineInfo
const& lineInfo ) -> IGeneratorTracker& {
11019 class ListeningReporter :
public IStreamingReporter {
11020 using Reporters = std::vector<IStreamingReporterPtr>;
11021 Reporters m_listeners;
11022 IStreamingReporterPtr m_reporter =
nullptr;
11023 ReporterPreferences m_preferences;
11026 ListeningReporter();
11028 void addListener( IStreamingReporterPtr&& listener );
11029 void addReporter( IStreamingReporterPtr&& reporter );
11033 ReporterPreferences getPreferences()
const override;
11035 void noMatchingTestCases( std::string
const& spec )
override;
11037 void reportInvalidArguments(std::string
const&arg)
override;
11039 static std::set<Verbosity> getSupportedVerbosities();
11041 #if defined(CATCH_CONFIG_ENABLE_BENCHMARKING)
11042 void benchmarkPreparing(std::string
const& name)
override;
11043 void benchmarkStarting( BenchmarkInfo
const& benchmarkInfo )
override;
11044 void benchmarkEnded( BenchmarkStats<>
const& benchmarkStats )
override;
11045 void benchmarkFailed(std::string
const&)
override;
11048 void testRunStarting( TestRunInfo
const& testRunInfo )
override;
11049 void testGroupStarting( GroupInfo
const& groupInfo )
override;
11050 void testCaseStarting( TestCaseInfo
const& testInfo )
override;
11051 void sectionStarting( SectionInfo
const& sectionInfo )
override;
11052 void assertionStarting( AssertionInfo
const& assertionInfo )
override;
11055 bool assertionEnded( AssertionStats
const& assertionStats )
override;
11056 void sectionEnded( SectionStats
const& sectionStats )
override;
11057 void testCaseEnded( TestCaseStats
const& testCaseStats )
override;
11058 void testGroupEnded( TestGroupStats
const& testGroupStats )
override;
11059 void testRunEnded( TestRunStats
const& testRunStats )
override;
11061 void skipTest( TestCaseInfo
const& testInfo )
override;
11062 bool isMulti()
const override;
11071 ReporterConfig::ReporterConfig(
IConfigPtr const& _fullConfig )
11072 : m_stream( &_fullConfig->stream() ), m_fullConfig( _fullConfig ) {}
11074 ReporterConfig::ReporterConfig(
IConfigPtr const& _fullConfig, std::ostream& _stream )
11075 : m_stream( &_stream ), m_fullConfig( _fullConfig ) {}
11077 std::ostream& ReporterConfig::stream()
const {
return *m_stream; }
11078 IConfigPtr ReporterConfig::fullConfig()
const {
return m_fullConfig; }
11080 TestRunInfo::TestRunInfo( std::string
const& _name ) : name( _name ) {}
11082 GroupInfo::GroupInfo( std::string
const& _name,
11083 std::size_t _groupIndex,
11084 std::size_t _groupsCount )
11086 groupIndex( _groupIndex ),
11087 groupsCounts( _groupsCount )
11090 AssertionStats::AssertionStats( AssertionResult
const& _assertionResult,
11091 std::vector<MessageInfo>
const& _infoMessages,
11092 Totals
const& _totals )
11093 : assertionResult( _assertionResult ),
11094 infoMessages( _infoMessages ),
11097 assertionResult.m_resultData.lazyExpression.m_transientExpression = _assertionResult.m_resultData.lazyExpression.m_transientExpression;
11099 if( assertionResult.hasMessage() ) {
11102 MessageBuilder builder( assertionResult.getTestMacroName(), assertionResult.getSourceInfo(), assertionResult.getResultType() );
11103 builder << assertionResult.getMessage();
11104 builder.m_info.message = builder.m_stream.str();
11106 infoMessages.push_back( builder.m_info );
11110 AssertionStats::~AssertionStats() =
default;
11112 SectionStats::SectionStats( SectionInfo
const& _sectionInfo,
11113 Counts
const& _assertions,
11114 double _durationInSeconds,
11115 bool _missingAssertions )
11116 : sectionInfo( _sectionInfo ),
11117 assertions( _assertions ),
11118 durationInSeconds( _durationInSeconds ),
11119 missingAssertions( _missingAssertions )
11122 SectionStats::~SectionStats() =
default;
11124 TestCaseStats::TestCaseStats( TestCaseInfo
const& _testInfo,
11125 Totals
const& _totals,
11126 std::string
const& _stdOut,
11127 std::string
const& _stdErr,
11129 : testInfo( _testInfo ),
11133 aborting( _aborting )
11136 TestCaseStats::~TestCaseStats() =
default;
11138 TestGroupStats::TestGroupStats( GroupInfo
const& _groupInfo,
11139 Totals
const& _totals,
11141 : groupInfo( _groupInfo ),
11143 aborting( _aborting )
11146 TestGroupStats::TestGroupStats( GroupInfo
const& _groupInfo )
11147 : groupInfo( _groupInfo ),
11151 TestGroupStats::~TestGroupStats() =
default;
11153 TestRunStats::TestRunStats( TestRunInfo
const& _runInfo,
11154 Totals
const& _totals,
11156 : runInfo( _runInfo ),
11158 aborting( _aborting )
11161 TestRunStats::~TestRunStats() =
default;
11163 void IStreamingReporter::fatalErrorEncountered( StringRef ) {}
11164 bool IStreamingReporter::isMulti()
const {
return false; }
11166 IReporterFactory::~IReporterFactory() =
default;
11167 IReporterRegistry::~IReporterRegistry() =
default;
11186 #ifdef CATCH_CONFIG_WINDOWS_CRTDBG
11187 #include <crtdbg.h>
11191 LeakDetector::LeakDetector() {
11192 int flag = _CrtSetDbgFlag(_CRTDBG_REPORT_FLAG);
11193 flag |= _CRTDBG_LEAK_CHECK_DF;
11194 flag |= _CRTDBG_ALLOC_MEM_DF;
11195 _CrtSetDbgFlag(flag);
11196 _CrtSetReportMode(_CRT_WARN, _CRTDBG_MODE_FILE | _CRTDBG_MODE_DEBUG);
11197 _CrtSetReportFile(_CRT_WARN, _CRTDBG_FILE_STDERR);
11199 _CrtSetBreakAlloc(-1);
11205 Catch::LeakDetector::LeakDetector() {}
11209 Catch::LeakDetector::~LeakDetector() {
11221 std::size_t listTests( Config
const& config );
11223 std::size_t listTestsNamesOnly( Config
const& config );
11226 void add( std::string
const& spelling );
11227 std::string all()
const;
11229 std::set<std::string> spellings;
11230 std::size_t count = 0;
11233 std::size_t listTags( Config
const& config );
11235 std::size_t listReporters();
11237 Option<std::size_t> list( std::shared_ptr<Config>
const& config );
11245 using namespace clara::TextFlow;
11250 #include <algorithm>
11255 std::size_t listTests( Config
const& config ) {
11256 TestSpec
const& testSpec = config.testSpec();
11257 if( config.hasTestFilters() )
11264 for(
auto const& testCaseInfo : matchedTestCases ) {
11265 Colour::Code colour = testCaseInfo.isHidden()
11266 ? Colour::SecondaryText
11268 Colour colourGuard( colour );
11270 Catch::cout() << Column( testCaseInfo.name ).initialIndent( 2 ).indent( 4 ) <<
"\n";
11273 std::string description = testCaseInfo.description;
11274 if( description.empty() )
11275 description =
"(NO DESCRIPTION)";
11276 Catch::cout() << Column( description ).indent(4) << std::endl;
11278 if( !testCaseInfo.tags.empty() )
11279 Catch::cout() << Column( testCaseInfo.tagsAsString() ).indent( 6 ) <<
"\n";
11282 if( !config.hasTestFilters() )
11283 Catch::cout() << pluralise( matchedTestCases.size(),
"test case" ) <<
'\n' << std::endl;
11285 Catch::cout() << pluralise( matchedTestCases.size(),
"matching test case" ) <<
'\n' << std::endl;
11286 return matchedTestCases.size();
11289 std::size_t listTestsNamesOnly( Config
const& config ) {
11290 TestSpec
const& testSpec = config.testSpec();
11291 std::size_t matchedTests = 0;
11293 for(
auto const& testCaseInfo : matchedTestCases ) {
11296 Catch::cout() <<
'"' << testCaseInfo.name <<
'"';
11303 return matchedTests;
11306 void TagInfo::add( std::string
const& spelling ) {
11308 spellings.insert( spelling );
11311 std::string TagInfo::all()
const {
11313 for (
auto const& spelling : spellings) {
11315 size += spelling.size() + 2;
11318 std::string out; out.reserve(size);
11319 for (
auto const& spelling : spellings) {
11327 std::size_t listTags( Config
const& config ) {
11328 TestSpec
const& testSpec = config.testSpec();
11329 if( config.hasTestFilters() )
11330 Catch::cout() <<
"Tags for matching test cases:\n";
11335 std::map<std::string, TagInfo> tagCounts;
11338 for(
auto const& testCase : matchedTestCases ) {
11339 for(
auto const& tagName : testCase.getTestCaseInfo().tags ) {
11340 std::string lcaseTagName =
toLower( tagName );
11341 auto countIt = tagCounts.find( lcaseTagName );
11342 if( countIt == tagCounts.end() )
11343 countIt = tagCounts.insert( std::make_pair( lcaseTagName, TagInfo() ) ).first;
11344 countIt->second.add( tagName );
11348 for(
auto const& tagCount : tagCounts ) {
11349 ReusableStringStream rss;
11350 rss <<
" " << std::setw(2) << tagCount.second.count <<
" ";
11351 auto str = rss.str();
11352 auto wrapper = Column( tagCount.second.all() )
11353 .initialIndent( 0 )
11354 .indent( str.size() )
11355 .width( CATCH_CONFIG_CONSOLE_WIDTH-10 );
11358 Catch::cout() << pluralise( tagCounts.size(),
"tag" ) <<
'\n' << std::endl;
11359 return tagCounts.size();
11362 std::size_t listReporters() {
11365 std::size_t maxNameLen = 0;
11366 for(
auto const& factoryKvp : factories )
11367 maxNameLen = (std::max)( maxNameLen, factoryKvp.first.size() );
11369 for(
auto const& factoryKvp : factories ) {
11371 << Column( factoryKvp.first +
":" )
11373 .width( 5+maxNameLen )
11374 + Column( factoryKvp.second->getDescription() )
11377 .
width( CATCH_CONFIG_CONSOLE_WIDTH - maxNameLen-8 )
11381 return factories.size();
11384 Option<std::size_t> list( std::shared_ptr<Config>
const& config ) {
11385 Option<std::size_t> listedCount;
11387 if( config->listTests() )
11388 listedCount = listedCount.valueOr(0) + listTests( *config );
11389 if( config->listTestNamesOnly() )
11390 listedCount = listedCount.valueOr(0) + listTestsNamesOnly( *config );
11391 if( config->listTags() )
11392 listedCount = listedCount.valueOr(0) + listTags( *config );
11393 if( config->listReporters() )
11394 listedCount = listedCount.valueOr(0) + listReporters();
11395 return listedCount;
11403 namespace Matchers {
11417 using namespace Matchers;
11418 using Matchers::Impl::MatcherBase;
11425 namespace Matchers {
11426 namespace Exception {
11433 return "exception message matches \"" +
m_message + "\"";
11437 Exception::ExceptionMessageMatcher
Message(std::string
const& message) {
11438 return Exception::ExceptionMessageMatcher(message);
11450 bool isnan(
float f);
11451 bool isnan(
double d);
11460 template <
typename T>
11461 std::string to_string(T
const& t) {
11462 #if defined(CATCH_CONFIG_CPP11_TO_STRING)
11463 return std::to_string(t);
11465 ReusableStringStream rss;
11473 #include <algorithm>
11479 #include <type_traits>
11486 int32_t convert(
float f) {
11487 static_assert(
sizeof(
float) ==
sizeof(int32_t),
"Important ULP matcher assumption violated");
11489 std::memcpy(&i, &f,
sizeof(f));
11493 int64_t convert(
double d) {
11494 static_assert(
sizeof(
double) ==
sizeof(int64_t),
"Important ULP matcher assumption violated");
11496 std::memcpy(&i, &d,
sizeof(d));
11500 template <
typename FP>
11501 bool almostEqualUlps(FP lhs, FP rhs, uint64_t maxUlpDiff) {
11504 if (Catch::isnan(lhs) || Catch::isnan(rhs)) {
11508 auto lc = convert(lhs);
11509 auto rc = convert(rhs);
11511 if ((lc < 0) != (rc < 0)) {
11517 auto ulpDiff = std::abs(
static_cast<FP
>(lc - rc));
11518 return static_cast<uint64_t
>(ulpDiff) <= maxUlpDiff;
11521 #if defined(CATCH_CONFIG_GLOBAL_NEXTAFTER)
11523 float nextafter(
float x,
float y) {
11524 return ::nextafterf(x, y);
11527 double nextafter(
double x,
double y) {
11528 return ::nextafter(x, y);
11533 template <
typename FP>
11534 FP step(FP start, FP direction, uint64_t steps) {
11535 for (uint64_t i = 0; i < steps; ++i) {
11536 #if defined(CATCH_CONFIG_GLOBAL_NEXTAFTER)
11537 start = Catch::nextafter(start, direction);
11539 start = std::nextafter(start, direction);
11547 bool marginComparison(
double lhs,
double rhs,
double margin) {
11548 return (lhs + margin >= rhs) && (rhs + margin >= lhs);
11551 template <
typename FloatingPo
int>
11552 void write(std::ostream& out, FloatingPoint num) {
11553 out << std::scientific
11554 << std::setprecision(std::numeric_limits<FloatingPoint>::max_digits10 - 1)
11560 namespace Matchers {
11561 namespace Floating {
11563 enum class FloatingPointKind : uint8_t {
11568 WithinAbsMatcher::WithinAbsMatcher(
double target,
double margin)
11569 :m_target{ target }, m_margin{ margin } {
11570 CATCH_ENFORCE(margin >= 0,
"Invalid margin: " << margin <<
'.'
11571 <<
" Margin has to be non-negative.");
11576 bool WithinAbsMatcher::match(
double const& matchee)
const {
11577 return (matchee + m_margin >= m_target) && (m_target + m_margin >= matchee);
11580 std::string WithinAbsMatcher::describe()
const {
11581 return "is within " + ::Catch::Detail::stringify(m_margin) + " of " + ::Catch::Detail::stringify(m_target);
11584 WithinUlpsMatcher::WithinUlpsMatcher(
double target, uint64_t ulps, FloatingPointKind baseType)
11585 :m_target{ target }, m_ulps{ ulps }, m_type{ baseType } {
11587 || m_ulps < (std::numeric_limits<uint32_t>::max)(),
11588 "Provided ULP is impossibly large for a float comparison.");
11591 #if defined(__clang__)
11592 #pragma clang diagnostic push
11594 #pragma clang diagnostic ignored "-Wunreachable-code"
11597 bool WithinUlpsMatcher::match(
double const& matchee)
const {
11599 case FloatingPointKind::Float:
11600 return almostEqualUlps<float>(
static_cast<float>(matchee),
static_cast<float>(m_target), m_ulps);
11601 case FloatingPointKind::Double:
11602 return almostEqualUlps<double>(matchee, m_target, m_ulps);
11608 #if defined(__clang__)
11609 #pragma clang diagnostic pop
11612 std::string WithinUlpsMatcher::describe()
const {
11613 std::stringstream ret;
11615 ret <<
"is within " << m_ulps <<
" ULPs of ";
11617 if (m_type == FloatingPointKind::Float) {
11618 write(ret,
static_cast<float>(m_target));
11621 write(ret, m_target);
11625 if (m_type == FloatingPointKind::Double) {
11626 write(ret, step(m_target,
static_cast<double>(-INFINITY), m_ulps));
11628 write(ret, step(m_target,
static_cast<double>( INFINITY), m_ulps));
11631 write(ret, step(
static_cast<float>(m_target),
static_cast<float>(-INFINITY), m_ulps));
11633 write(ret, step(
static_cast<float>(m_target),
static_cast<float>( INFINITY), m_ulps));
11640 WithinRelMatcher::WithinRelMatcher(
double target,
double epsilon):
11642 m_epsilon(epsilon){
11643 CATCH_ENFORCE(m_epsilon >= 0.,
"Relative comparison with epsilon < 0 does not make sense.");
11644 CATCH_ENFORCE(m_epsilon < 1., "Relative comparison with epsilon >= 1 does not make sense.
");
11647 bool WithinRelMatcher::match(double const& matchee) const {
11648 const auto relMargin = m_epsilon * (std::max)(std::fabs(matchee), std::fabs(m_target));
11649 return marginComparison(matchee, m_target,
11650 std::isinf(relMargin)? 0 : relMargin);
11653 std::string WithinRelMatcher::describe() const {
11654 Catch::ReusableStringStream sstr;
11655 sstr << "and
" << m_target << " are within
" << m_epsilon * 100. << "% of each other
";
11659 }// namespace Floating
11661 Floating::WithinUlpsMatcher WithinULP(double target, uint64_t maxUlpDiff) {
11662 return Floating::WithinUlpsMatcher(target, maxUlpDiff, Floating::FloatingPointKind::Double);
11665 Floating::WithinUlpsMatcher WithinULP(float target, uint64_t maxUlpDiff) {
11666 return Floating::WithinUlpsMatcher(target, maxUlpDiff, Floating::FloatingPointKind::Float);
11669 Floating::WithinAbsMatcher WithinAbs(double target, double margin) {
11670 return Floating::WithinAbsMatcher(target, margin);
11673 Floating::WithinRelMatcher WithinRel(double target, double eps) {
11674 return Floating::WithinRelMatcher(target, eps);
11677 Floating::WithinRelMatcher WithinRel(double target) {
11678 return Floating::WithinRelMatcher(target, std::numeric_limits<double>::epsilon() * 100);
11681 Floating::WithinRelMatcher WithinRel(float target, float eps) {
11682 return Floating::WithinRelMatcher(target, eps);
11685 Floating::WithinRelMatcher WithinRel(float target) {
11686 return Floating::WithinRelMatcher(target, std::numeric_limits<float>::epsilon() * 100);
11689 } // namespace Matchers
11690 } // namespace Catch
11691 // end catch_matchers_floating.cpp
11692 // start catch_matchers_generic.cpp
11694 std::string Catch::Matchers::Generic::Detail::finalizeDescription(const std::string& desc) {
11695 if (desc.empty()) {
11696 return "matches undescribed predicate
";
11698 return "matches predicate: \
"" + desc +
'"';
11707 namespace Matchers {
11709 namespace StdString {
11712 : m_caseSensitivity( caseSensitivity ),
11713 m_str( adjustString( str ) )
11715 std::string CasedString::adjustString( std::string
const& str )
const {
11720 std::string CasedString::caseSensitivitySuffix()
const {
11722 ?
" (case insensitive)"
11726 StringMatcherBase::StringMatcherBase( std::string
const& operation, CasedString
const& comparator )
11727 : m_comparator( comparator ),
11728 m_operation( operation ) {
11731 std::string StringMatcherBase::describe()
const {
11732 std::string description;
11733 description.reserve(5 + m_operation.size() + m_comparator.m_str.size() +
11734 m_comparator.caseSensitivitySuffix().size());
11735 description += m_operation;
11736 description += ": \"";
11737 description += m_comparator.m_str;
11738 description += "\"";
11739 description += m_comparator.caseSensitivitySuffix();
11740 return description;
11743 EqualsMatcher::EqualsMatcher( CasedString
const& comparator ) : StringMatcherBase(
"equals", comparator ) {}
11745 bool EqualsMatcher::match( std::string
const& source )
const {
11746 return m_comparator.adjustString( source ) == m_comparator.m_str;
11749 ContainsMatcher::ContainsMatcher( CasedString
const& comparator ) : StringMatcherBase(
"contains", comparator ) {}
11751 bool ContainsMatcher::match( std::string
const& source )
const {
11752 return contains( m_comparator.adjustString( source ), m_comparator.m_str );
11755 StartsWithMatcher::StartsWithMatcher( CasedString
const& comparator ) : StringMatcherBase(
"starts with", comparator ) {}
11757 bool StartsWithMatcher::match( std::string
const& source )
const {
11758 return startsWith( m_comparator.adjustString( source ), m_comparator.m_str );
11761 EndsWithMatcher::EndsWithMatcher( CasedString
const& comparator ) : StringMatcherBase(
"ends with", comparator ) {}
11763 bool EndsWithMatcher::match( std::string
const& source )
const {
11764 return endsWith( m_comparator.adjustString( source ), m_comparator.m_str );
11767 RegexMatcher::RegexMatcher(std::string regex,
CaseSensitive::Choice caseSensitivity): m_regex(std::move(regex)), m_caseSensitivity(caseSensitivity) {}
11769 bool RegexMatcher::match(std::string
const& matchee)
const {
11770 auto flags = std::regex::ECMAScript;
11771 if (m_caseSensitivity == CaseSensitive::Choice::No) {
11772 flags |= std::regex::icase;
11774 auto reg = std::regex(m_regex, flags);
11775 return std::regex_match(matchee, reg);
11778 std::string RegexMatcher::describe()
const {
11779 return "matches " + ::Catch::Detail::stringify(m_regex) + ((m_caseSensitivity == CaseSensitive::Choice::Yes)? " case sensitively" : " case insensitively");
11784 StdString::EqualsMatcher
Equals( std::string
const& str, CaseSensitive::Choice caseSensitivity ) {
11785 return StdString::EqualsMatcher( StdString::CasedString( str, caseSensitivity) );
11787 StdString::ContainsMatcher
Contains( std::string
const& str, CaseSensitive::Choice caseSensitivity ) {
11788 return StdString::ContainsMatcher( StdString::CasedString( str, caseSensitivity) );
11790 StdString::EndsWithMatcher
EndsWith( std::string
const& str, CaseSensitive::Choice caseSensitivity ) {
11791 return StdString::EndsWithMatcher( StdString::CasedString( str, caseSensitivity) );
11793 StdString::StartsWithMatcher
StartsWith( std::string
const& str, CaseSensitive::Choice caseSensitivity ) {
11794 return StdString::StartsWithMatcher( StdString::CasedString( str, caseSensitivity) );
11797 StdString::RegexMatcher
Matches(std::string
const& regex, CaseSensitive::Choice caseSensitivity) {
11798 return StdString::RegexMatcher(regex, caseSensitivity);
11809 bool uncaught_exceptions();
11819 SourceLineInfo
const& _lineInfo,
11821 : macroName( _macroName ),
11822 lineInfo( _lineInfo ),
11824 sequence( ++globalCount )
11828 return sequence == other.sequence;
11841 SourceLineInfo
const& lineInfo,
11843 :m_info(macroName, lineInfo, type) {}
11848 : m_info( builder.m_info ), m_moved()
11850 m_info.message = builder.m_stream.str();
11855 : m_info( old.m_info ), m_moved()
11857 old.m_moved =
true;
11861 if ( !uncaught_exceptions() && !
m_moved ){
11867 auto trimmed = [&] (
size_t start,
size_t end) {
11868 while (names[start] ==
',' || isspace(
static_cast<unsigned char>(names[start]))) {
11871 while (names[end] ==
',' || isspace(
static_cast<unsigned char>(names[end]))) {
11874 return names.substr(start, end - start + 1);
11876 auto skipq = [&] (
size_t start,
char quote) {
11877 for (
auto i = start + 1; i < names.size() ; ++i) {
11878 if (names[i] == quote)
11880 if (names[i] ==
'\\')
11887 std::stack<char> openings;
11888 for (
size_t pos = 0; pos < names.size(); ++pos) {
11889 char c = names[pos];
11907 pos = skipq(pos, c);
11910 if (start != pos && openings.empty()) {
11911 m_messages.emplace_back(macroName, lineInfo, resultType);
11912 m_messages.back().message =
static_cast<std::string
>(trimmed(start, pos));
11913 m_messages.back().message += " := ";
11918 assert(openings.empty() &&
"Mismatched openings");
11919 m_messages.emplace_back(macroName, lineInfo, resultType);
11920 m_messages.back().message =
static_cast<std::string
>(trimmed(start, names.size() - 1));
11921 m_messages.back().message += " := ";
11923 Capturer::~Capturer() {
11924 if ( !uncaught_exceptions() ){
11925 assert( m_captured == m_messages.size() );
11926 for(
size_t i = 0; i < m_captured; ++i )
11927 m_resultCapture.popScopedMessage( m_messages[i] );
11931 void Capturer::captureValue(
size_t index, std::string
const&
value ) {
11932 assert( index < m_messages.size() );
11933 m_messages[index].message +=
value;
11943 #ifndef TWOBLUECUBES_CATCH_OUTPUT_REDIRECT_H
11944 #define TWOBLUECUBES_CATCH_OUTPUT_REDIRECT_H
11952 class RedirectedStream {
11953 std::ostream& m_originalStream;
11954 std::ostream& m_redirectionStream;
11955 std::streambuf* m_prevBuf;
11958 RedirectedStream( std::ostream& originalStream, std::ostream& redirectionStream );
11959 ~RedirectedStream();
11962 class RedirectedStdOut {
11963 ReusableStringStream m_rss;
11964 RedirectedStream m_cout;
11966 RedirectedStdOut();
11967 auto str() const -> std::
string;
11973 class RedirectedStdErr {
11974 ReusableStringStream m_rss;
11975 RedirectedStream m_cerr;
11976 RedirectedStream m_clog;
11978 RedirectedStdErr();
11979 auto str() const -> std::
string;
11982 class RedirectedStreams {
11984 RedirectedStreams(RedirectedStreams
const&) =
delete;
11985 RedirectedStreams& operator=(RedirectedStreams
const&) =
delete;
11986 RedirectedStreams(RedirectedStreams&&) =
delete;
11987 RedirectedStreams& operator=(RedirectedStreams&&) =
delete;
11989 RedirectedStreams(std::string& redirectedCout, std::string& redirectedCerr);
11990 ~RedirectedStreams();
11992 std::string& m_redirectedCout;
11993 std::string& m_redirectedCerr;
11994 RedirectedStdOut m_redirectedStdOut;
11995 RedirectedStdErr m_redirectedStdErr;
11998 #if defined(CATCH_CONFIG_NEW_CAPTURE)
12006 TempFile(TempFile
const&) =
delete;
12007 TempFile& operator=(TempFile
const&) =
delete;
12008 TempFile(TempFile&&) =
delete;
12009 TempFile& operator=(TempFile&&) =
delete;
12014 std::FILE* getFile();
12015 std::string getContents();
12018 std::FILE* m_file =
nullptr;
12019 #if defined(_MSC_VER)
12020 char m_buffer[L_tmpnam] = { 0 };
12024 class OutputRedirect {
12026 OutputRedirect(OutputRedirect
const&) =
delete;
12027 OutputRedirect& operator=(OutputRedirect
const&) =
delete;
12028 OutputRedirect(OutputRedirect&&) =
delete;
12029 OutputRedirect& operator=(OutputRedirect&&) =
delete;
12031 OutputRedirect(std::string& stdout_dest, std::string& stderr_dest);
12035 int m_originalStdout = -1;
12036 int m_originalStderr = -1;
12037 TempFile m_stdoutFile;
12038 TempFile m_stderrFile;
12039 std::string& m_stdoutDest;
12040 std::string& m_stderrDest;
12053 #include <stdexcept>
12055 #if defined(CATCH_CONFIG_NEW_CAPTURE)
12056 #if defined(_MSC_VER)
12060 #define fileno _fileno
12062 #include <unistd.h>
12068 RedirectedStream::RedirectedStream( std::ostream& originalStream, std::ostream& redirectionStream )
12069 : m_originalStream( originalStream ),
12070 m_redirectionStream( redirectionStream ),
12071 m_prevBuf( m_originalStream.rdbuf() )
12073 m_originalStream.rdbuf( m_redirectionStream.rdbuf() );
12076 RedirectedStream::~RedirectedStream() {
12077 m_originalStream.rdbuf( m_prevBuf );
12080 RedirectedStdOut::RedirectedStdOut() : m_cout(
Catch::
cout(), m_rss.get() ) {}
12081 auto RedirectedStdOut::str() const -> std::
string {
return m_rss.str(); }
12083 RedirectedStdErr::RedirectedStdErr()
12084 : m_cerr(
Catch::
cerr(), m_rss.get() ),
12087 auto RedirectedStdErr::str() const -> std::
string {
return m_rss.str(); }
12089 RedirectedStreams::RedirectedStreams(std::string& redirectedCout, std::string& redirectedCerr)
12090 : m_redirectedCout(redirectedCout),
12091 m_redirectedCerr(redirectedCerr)
12094 RedirectedStreams::~RedirectedStreams() {
12095 m_redirectedCout += m_redirectedStdOut.str();
12096 m_redirectedCerr += m_redirectedStdErr.str();
12099 #if defined(CATCH_CONFIG_NEW_CAPTURE)
12101 #if defined(_MSC_VER)
12102 TempFile::TempFile() {
12103 if (tmpnam_s(m_buffer)) {
12106 if (fopen_s(&m_file, m_buffer,
"w+")) {
12108 if (strerror_s(buffer, errno)) {
12111 CATCH_RUNTIME_ERROR(
"Could not open the temp file: '" << m_buffer <<
"' because: " << buffer);
12115 TempFile::TempFile() {
12116 m_file = std::tmpfile();
12124 TempFile::~TempFile() {
12126 std::fclose(m_file);
12129 #if defined(_MSC_VER)
12130 std::remove(m_buffer);
12134 FILE* TempFile::getFile() {
12138 std::string TempFile::getContents() {
12139 std::stringstream sstr;
12140 char buffer[100] = {};
12141 std::rewind(m_file);
12142 while (std::fgets(buffer,
sizeof(buffer), m_file)) {
12148 OutputRedirect::OutputRedirect(std::string& stdout_dest, std::string& stderr_dest) :
12149 m_originalStdout(dup(1)),
12150 m_originalStderr(dup(2)),
12151 m_stdoutDest(stdout_dest),
12152 m_stderrDest(stderr_dest) {
12153 dup2(fileno(m_stdoutFile.getFile()), 1);
12154 dup2(fileno(m_stderrFile.getFile()), 2);
12157 OutputRedirect::~OutputRedirect() {
12166 dup2(m_originalStdout, 1);
12167 dup2(m_originalStderr, 2);
12169 m_stdoutDest += m_stdoutFile.getContents();
12170 m_stderrDest += m_stderrFile.getContents();
12177 #if defined(CATCH_CONFIG_NEW_CAPTURE)
12178 #if defined(_MSC_VER)
12191 #if !defined(CATCH_CONFIG_POLYFILL_ISNAN)
12192 bool isnan(
float f) {
12193 return std::isnan(f);
12195 bool isnan(
double d) {
12196 return std::isnan(d);
12200 bool isnan(
float f) {
12201 return std::_isnan(f);
12203 bool isnan(
double d) {
12204 return std::_isnan(d);
12216 #if defined(_MSC_VER)
12217 #pragma warning(push)
12218 #pragma warning(disable:4146)
12221 uint32_t rotate_right(uint32_t val, uint32_t count) {
12222 const uint32_t mask = 31;
12224 return (val >> count) | (val << (-count & mask));
12227 #if defined(_MSC_VER)
12228 #pragma warning(pop)
12247 for (uint64_t s = 0; s < skip; ++s) {
12248 static_cast<void>((*this)());
12252 SimplePcg32::result_type SimplePcg32::operator()() {
12254 const uint32_t xorshifted =
static_cast<uint32_t
>(((m_state >> 18u) ^ m_state) >> 27u);
12255 const auto output = rotate_right(xorshifted, m_state >> 59u);
12258 m_state = m_state * 6364136223846793005ULL + s_inc;
12263 bool operator==(SimplePcg32
const& lhs, SimplePcg32
const& rhs) {
12264 return lhs.m_state == rhs.m_state;
12267 bool operator!=(SimplePcg32
const& lhs, SimplePcg32
const& rhs) {
12268 return lhs.m_state != rhs.m_state;
12278 #include <algorithm>
12286 std::vector<TestCase> sortTests( IConfig
const& config, std::vector<TestCase>
const& unsortedTestCases );
12288 bool isThrowSafe( TestCase
const& testCase, IConfig
const& config );
12289 bool matchTest( TestCase
const& testCase, TestSpec
const& testSpec, IConfig
const& config );
12291 void enforceNoDuplicateTestCases( std::vector<TestCase>
const& functions );
12293 std::vector<TestCase>
filterTests( std::vector<TestCase>
const& testCases, TestSpec
const& testSpec, IConfig
const& config );
12296 class TestRegistry :
public ITestCaseRegistry {
12298 virtual ~TestRegistry() =
default;
12300 virtual void registerTest( TestCase
const& testCase );
12302 std::vector<TestCase>
const& getAllTests()
const override;
12303 std::vector<TestCase>
const& getAllTestsSorted( IConfig
const& config )
const override;
12306 std::vector<TestCase> m_functions;
12308 mutable std::vector<TestCase> m_sortedFunctions;
12309 std::size_t m_unnamedCount = 0;
12310 std::ios_base::Init m_ostreamInit;
12315 class TestInvokerAsFunction :
public ITestInvoker {
12316 void(*m_testAsFunction)();
12318 TestInvokerAsFunction(
void(*testAsFunction)() ) noexcept;
12320 void invoke() const override;
12323 std::
string extractClassName( StringRef const& classOrQualifiedMethodName );
12336 class ReporterRegistry :
public IReporterRegistry {
12340 ~ReporterRegistry()
override;
12342 IStreamingReporterPtr create( std::string
const& name,
IConfigPtr const& config )
const override;
12347 FactoryMap
const& getFactories()
const override;
12348 Listeners
const& getListeners()
const override;
12351 FactoryMap m_factories;
12352 Listeners m_listeners;
12366 TagAlias(std::string
const& _tag, SourceLineInfo _lineInfo);
12369 SourceLineInfo lineInfo;
12379 class TagAliasRegistry :
public ITagAliasRegistry {
12381 ~TagAliasRegistry()
override;
12382 TagAlias
const* find( std::string
const& alias )
const override;
12383 std::string expandAliases( std::string
const& unexpandedTestSpec )
const override;
12384 void add( std::string
const& alias, std::string
const& tag, SourceLineInfo
const& lineInfo );
12387 std::map<std::string, TagAlias> m_registry;
12396 #include <exception>
12400 class StartupExceptionRegistry {
12401 #if !defined(CATCH_CONFIG_DISABLE_EXCEPTIONS)
12403 void add(std::exception_ptr
const& exception) noexcept;
12404 std::vector<std::exception_ptr>
const& getExceptions() const noexcept;
12406 std::vector<std::exception_ptr> m_exceptions;
12417 struct ISingleton {
12418 virtual ~ISingleton();
12421 void addSingleton( ISingleton* singleton );
12422 void cleanupSingletons();
12424 template<
typename SingletonImplT,
typename InterfaceT = SingletonImplT,
typename MutableInterfaceT = InterfaceT>
12425 class Singleton : SingletonImplT,
public ISingleton {
12427 static auto getInternal() -> Singleton* {
12428 static Singleton* s_instance =
nullptr;
12429 if( !s_instance ) {
12430 s_instance =
new Singleton;
12431 addSingleton( s_instance );
12437 static auto get() -> InterfaceT
const& {
12438 return *getInternal();
12440 static auto getMutable() -> MutableInterfaceT& {
12441 return *getInternal();
12452 class RegistryHub :
public IRegistryHub,
public IMutableRegistryHub,
12453 private NonCopyable {
12456 RegistryHub() =
default;
12457 IReporterRegistry
const& getReporterRegistry()
const override {
12458 return m_reporterRegistry;
12460 ITestCaseRegistry
const& getTestCaseRegistry()
const override {
12461 return m_testCaseRegistry;
12463 IExceptionTranslatorRegistry
const& getExceptionTranslatorRegistry()
const override {
12464 return m_exceptionTranslatorRegistry;
12466 ITagAliasRegistry
const& getTagAliasRegistry()
const override {
12467 return m_tagAliasRegistry;
12469 StartupExceptionRegistry
const& getStartupExceptionRegistry()
const override {
12470 return m_exceptionRegistry;
12474 void registerReporter( std::string
const& name,
IReporterFactoryPtr const& factory )
override {
12475 m_reporterRegistry.registerReporter( name, factory );
12478 m_reporterRegistry.registerListener( factory );
12480 void registerTest( TestCase
const& testInfo )
override {
12481 m_testCaseRegistry.registerTest( testInfo );
12483 void registerTranslator(
const IExceptionTranslator* translator )
override {
12484 m_exceptionTranslatorRegistry.registerTranslator( translator );
12486 void registerTagAlias( std::string
const& alias, std::string
const& tag, SourceLineInfo
const& lineInfo )
override {
12487 m_tagAliasRegistry.add( alias, tag, lineInfo );
12489 void registerStartupException() noexcept
override {
12490 #if !defined(CATCH_CONFIG_DISABLE_EXCEPTIONS)
12491 m_exceptionRegistry.add(std::current_exception());
12493 CATCH_INTERNAL_ERROR(
"Attempted to register active exception under CATCH_CONFIG_DISABLE_EXCEPTIONS!");
12496 IMutableEnumValuesRegistry& getMutableEnumValuesRegistry()
override {
12497 return m_enumValuesRegistry;
12501 TestRegistry m_testCaseRegistry;
12502 ReporterRegistry m_reporterRegistry;
12503 ExceptionTranslatorRegistry m_exceptionTranslatorRegistry;
12504 TagAliasRegistry m_tagAliasRegistry;
12505 StartupExceptionRegistry m_exceptionRegistry;
12506 Detail::EnumValuesRegistry m_enumValuesRegistry;
12510 using RegistryHubSingleton = Singleton<RegistryHub, IRegistryHub, IMutableRegistryHub>;
12513 return RegistryHubSingleton::get();
12516 return RegistryHubSingleton::getMutable();
12519 cleanupSingletons();
12532 ReporterRegistry::~ReporterRegistry() =
default;
12534 IStreamingReporterPtr ReporterRegistry::create( std::string
const& name,
IConfigPtr const& config )
const {
12535 auto it = m_factories.find( name );
12536 if(
it == m_factories.end() )
12538 return it->second->create( ReporterConfig( config ) );
12541 void ReporterRegistry::registerReporter( std::string
const& name,
IReporterFactoryPtr const& factory ) {
12542 m_factories.emplace(name, factory);
12545 m_listeners.push_back( factory );
12548 IReporterRegistry::FactoryMap
const& ReporterRegistry::getFactories()
const {
12549 return m_factories;
12551 IReporterRegistry::Listeners
const& ReporterRegistry::getListeners()
const {
12552 return m_listeners;
12580 #include <algorithm>
12585 namespace Generators {
12586 struct GeneratorTracker : TestCaseTracking::TrackerBase, IGeneratorTracker {
12589 GeneratorTracker( TestCaseTracking::NameAndLocation
const& nameAndLocation, TrackerContext& ctx, ITracker* parent )
12590 : TrackerBase( nameAndLocation, ctx, parent )
12592 ~GeneratorTracker();
12594 static GeneratorTracker& acquire( TrackerContext& ctx, TestCaseTracking::NameAndLocation
const& nameAndLocation ) {
12595 std::shared_ptr<GeneratorTracker> tracker;
12597 ITracker& currentTracker = ctx.currentTracker();
12609 if (currentTracker.nameAndLocation() == nameAndLocation) {
12610 auto thisTracker = currentTracker.parent().findChild(nameAndLocation);
12611 assert(thisTracker);
12612 assert(thisTracker->isGeneratorTracker());
12613 tracker = std::static_pointer_cast<GeneratorTracker>(thisTracker);
12614 }
else if ( TestCaseTracking::ITrackerPtr childTracker = currentTracker.findChild( nameAndLocation ) ) {
12615 assert( childTracker );
12616 assert( childTracker->isGeneratorTracker() );
12617 tracker = std::static_pointer_cast<GeneratorTracker>( childTracker );
12619 tracker = std::make_shared<GeneratorTracker>( nameAndLocation, ctx, ¤tTracker );
12620 currentTracker.addChild( tracker );
12623 if( !tracker->isComplete() ) {
12631 bool isGeneratorTracker()
const override {
return true; }
12632 auto hasGenerator() const ->
bool override {
12633 return !!m_generator;
12635 void close()
override {
12636 TrackerBase::close();
12644 const bool should_wait_for_child = [&]() {
12646 if ( m_children.empty() ) {
12651 m_children.begin(),
12653 []( TestCaseTracking::ITrackerPtr tracker ) {
12654 return tracker->hasStarted();
12655 } ) != m_children.end() ) {
12662 auto* parent = m_parent;
12665 while ( !parent->isSectionTracker() ) {
12666 parent = &( parent->parent() );
12669 "Missing root (test case) level section" );
12671 auto const& parentSection =
12672 static_cast<SectionTracker&
>( *parent );
12673 auto const& filters = parentSection.getFilters();
12675 if ( filters.empty() ) {
12679 for (
auto const& child : m_children ) {
12680 if ( child->isSectionTracker() &&
12681 std::find( filters.begin(),
12683 static_cast<SectionTracker&
>( *child )
12684 .trimmedName() ) !=
12696 if ( should_wait_for_child ||
12697 ( m_runState == CompletedSuccessfully &&
12698 m_generator->next() ) ) {
12699 m_children.clear();
12700 m_runState = Executing;
12706 return m_generator;
12709 m_generator = std::move( generator );
12712 GeneratorTracker::~GeneratorTracker() {}
12715 RunContext::RunContext(
IConfigPtr const& _config, IStreamingReporterPtr&& reporter)
12716 : m_runInfo(_config->name()),
12719 m_reporter(std::move(reporter)),
12720 m_lastAssertionInfo{ StringRef(), SourceLineInfo(
"",0), StringRef(), ResultDisposition::
Normal },
12721 m_includeSuccessfulResults( m_config->includeSuccessfulResults() || m_reporter->getPreferences().shouldReportAllAssertions )
12723 m_context.setRunner(
this);
12724 m_context.setConfig(m_config);
12725 m_context.setResultCapture(
this);
12726 m_reporter->testRunStarting(m_runInfo);
12729 RunContext::~RunContext() {
12730 m_reporter->testRunEnded(TestRunStats(m_runInfo, m_totals, aborting()));
12733 void RunContext::testGroupStarting(std::string
const& testSpec, std::size_t groupIndex, std::size_t groupsCount) {
12734 m_reporter->testGroupStarting(GroupInfo(testSpec, groupIndex, groupsCount));
12737 void RunContext::testGroupEnded(std::string
const& testSpec, Totals
const& totals, std::size_t groupIndex, std::size_t groupsCount) {
12738 m_reporter->testGroupEnded(TestGroupStats(GroupInfo(testSpec, groupIndex, groupsCount), totals, aborting()));
12741 Totals RunContext::runTest(TestCase
const& testCase) {
12742 Totals prevTotals = m_totals;
12744 std::string redirectedCout;
12745 std::string redirectedCerr;
12747 auto const& testInfo = testCase.getTestCaseInfo();
12749 m_reporter->testCaseStarting(testInfo);
12751 m_activeTestCase = &testCase;
12753 ITracker& rootTracker = m_trackerContext.startRun();
12754 assert(rootTracker.isSectionTracker());
12755 static_cast<SectionTracker&
>(rootTracker).addInitialFilters(m_config->getSectionsToRun());
12757 m_trackerContext.startCycle();
12758 m_testCaseTracker = &SectionTracker::acquire(m_trackerContext, TestCaseTracking::NameAndLocation(testInfo.name, testInfo.lineInfo));
12759 runCurrentTest(redirectedCout, redirectedCerr);
12760 }
while (!m_testCaseTracker->isSuccessfullyCompleted() && !aborting());
12762 Totals deltaTotals = m_totals.delta(prevTotals);
12763 if (testInfo.expectedToFail() && deltaTotals.testCases.passed > 0) {
12764 deltaTotals.assertions.failed++;
12765 deltaTotals.testCases.passed--;
12766 deltaTotals.testCases.failed++;
12768 m_totals.testCases += deltaTotals.testCases;
12769 m_reporter->testCaseEnded(TestCaseStats(testInfo,
12775 m_activeTestCase =
nullptr;
12776 m_testCaseTracker =
nullptr;
12778 return deltaTotals;
12785 IStreamingReporter& RunContext::reporter()
const {
12786 return *m_reporter;
12789 void RunContext::assertionEnded(AssertionResult
const & result) {
12791 m_totals.assertions.passed++;
12792 m_lastAssertionPassed =
true;
12793 }
else if (!result.isOk()) {
12794 m_lastAssertionPassed =
false;
12795 if( m_activeTestCase->getTestCaseInfo().okToFail() )
12796 m_totals.assertions.failedButOk++;
12798 m_totals.assertions.failed++;
12801 m_lastAssertionPassed =
true;
12806 static_cast<void>(m_reporter->assertionEnded(AssertionStats(result, m_messages, m_totals)));
12809 m_messageScopes.clear();
12812 resetAssertionInfo();
12813 m_lastResult = result;
12815 void RunContext::resetAssertionInfo() {
12816 m_lastAssertionInfo.macroName = StringRef();
12817 m_lastAssertionInfo.capturedExpression =
"{Unknown expression after the reported line}"_sr;
12820 bool RunContext::sectionStarted(SectionInfo
const & sectionInfo, Counts & assertions) {
12821 ITracker& sectionTracker = SectionTracker::acquire(m_trackerContext, TestCaseTracking::NameAndLocation(sectionInfo.name, sectionInfo.lineInfo));
12822 if (!sectionTracker.isOpen())
12824 m_activeSections.push_back(§ionTracker);
12826 m_lastAssertionInfo.lineInfo = sectionInfo.lineInfo;
12828 m_reporter->sectionStarting(sectionInfo);
12830 assertions = m_totals.assertions;
12835 using namespace Generators;
12836 GeneratorTracker& tracker = GeneratorTracker::acquire(m_trackerContext,
12837 TestCaseTracking::NameAndLocation(
static_cast<std::string
>(generatorName), lineInfo ) );
12838 m_lastAssertionInfo.lineInfo = lineInfo;
12842 bool RunContext::testForMissingAssertions(Counts& assertions) {
12843 if (assertions.total() != 0)
12845 if (!m_config->warnAboutMissingAssertions())
12847 if (m_trackerContext.currentTracker().hasChildren())
12849 m_totals.assertions.failed++;
12850 assertions.failed++;
12854 void RunContext::sectionEnded(SectionEndInfo
const & endInfo) {
12855 Counts assertions = m_totals.assertions - endInfo.prevAssertions;
12856 bool missingAssertions = testForMissingAssertions(assertions);
12858 if (!m_activeSections.empty()) {
12859 m_activeSections.back()->close();
12860 m_activeSections.pop_back();
12863 m_reporter->sectionEnded(SectionStats(endInfo.sectionInfo, assertions, endInfo.durationInSeconds, missingAssertions));
12864 m_messages.clear();
12865 m_messageScopes.clear();
12868 void RunContext::sectionEndedEarly(SectionEndInfo
const & endInfo) {
12869 if (m_unfinishedSections.empty())
12870 m_activeSections.back()->fail();
12872 m_activeSections.back()->close();
12873 m_activeSections.pop_back();
12875 m_unfinishedSections.push_back(endInfo);
12878 #if defined(CATCH_CONFIG_ENABLE_BENCHMARKING)
12879 void RunContext::benchmarkPreparing(std::string
const& name) {
12880 m_reporter->benchmarkPreparing(name);
12882 void RunContext::benchmarkStarting( BenchmarkInfo
const& info ) {
12883 m_reporter->benchmarkStarting( info );
12885 void RunContext::benchmarkEnded( BenchmarkStats<>
const& stats ) {
12886 m_reporter->benchmarkEnded( stats );
12888 void RunContext::benchmarkFailed(std::string
const & error) {
12889 m_reporter->benchmarkFailed(error);
12893 void RunContext::pushScopedMessage(MessageInfo
const & message) {
12894 m_messages.push_back(message);
12897 void RunContext::popScopedMessage(MessageInfo
const & message) {
12898 m_messages.erase(std::remove(m_messages.begin(), m_messages.end(), message), m_messages.end());
12901 void RunContext::emplaceUnscopedMessage( MessageBuilder
const& builder ) {
12902 m_messageScopes.emplace_back( builder );
12905 std::string RunContext::getCurrentTestName()
const {
12906 return m_activeTestCase
12907 ? m_activeTestCase->getTestCaseInfo().name
12911 const AssertionResult * RunContext::getLastResult()
const {
12912 return &(*m_lastResult);
12915 void RunContext::exceptionEarlyReported() {
12916 m_shouldReportUnexpected =
false;
12919 void RunContext::handleFatalErrorCondition( StringRef message ) {
12921 m_reporter->fatalErrorEncountered(message);
12926 tempResult.message =
static_cast<std::string
>(message);
12927 AssertionResult result(m_lastAssertionInfo, tempResult);
12929 assertionEnded(result);
12931 handleUnfinishedSections();
12934 auto const& testCaseInfo = m_activeTestCase->getTestCaseInfo();
12935 SectionInfo testCaseSection(testCaseInfo.lineInfo, testCaseInfo.name);
12938 assertions.failed = 1;
12939 SectionStats testCaseSectionStats(testCaseSection, assertions, 0,
false);
12940 m_reporter->sectionEnded(testCaseSectionStats);
12942 auto const& testInfo = m_activeTestCase->getTestCaseInfo();
12944 Totals deltaTotals;
12945 deltaTotals.testCases.failed = 1;
12946 deltaTotals.assertions.failed = 1;
12947 m_reporter->testCaseEnded(TestCaseStats(testInfo,
12952 m_totals.testCases.failed++;
12953 testGroupEnded(std::string(), m_totals, 1, 1);
12954 m_reporter->testRunEnded(TestRunStats(m_runInfo, m_totals,
false));
12957 bool RunContext::lastAssertionPassed() {
12958 return m_lastAssertionPassed;
12961 void RunContext::assertionPassed() {
12962 m_lastAssertionPassed =
true;
12963 ++m_totals.assertions.passed;
12964 resetAssertionInfo();
12965 m_messageScopes.clear();
12968 bool RunContext::aborting()
const {
12969 return m_totals.assertions.failed >=
static_cast<std::size_t
>(m_config->abortAfter());
12972 void RunContext::runCurrentTest(std::string & redirectedCout, std::string & redirectedCerr) {
12973 auto const& testCaseInfo = m_activeTestCase->getTestCaseInfo();
12974 SectionInfo testCaseSection(testCaseInfo.lineInfo, testCaseInfo.name);
12975 m_reporter->sectionStarting(testCaseSection);
12976 Counts prevAssertions = m_totals.assertions;
12977 double duration = 0;
12978 m_shouldReportUnexpected =
true;
12981 seedRng(*m_config);
12985 if (m_reporter->getPreferences().shouldRedirectStdOut) {
12986 #if !defined(CATCH_CONFIG_EXPERIMENTAL_REDIRECT)
12987 RedirectedStreams redirectedStreams(redirectedCout, redirectedCerr);
12990 invokeActiveTestCase();
12992 OutputRedirect r(redirectedCout, redirectedCerr);
12994 invokeActiveTestCase();
12998 invokeActiveTestCase();
13000 duration = timer.getElapsedSeconds();
13006 if( m_shouldReportUnexpected ) {
13007 AssertionReaction dummyReaction;
13011 Counts assertions = m_totals.assertions - prevAssertions;
13012 bool missingAssertions = testForMissingAssertions(assertions);
13014 m_testCaseTracker->close();
13015 handleUnfinishedSections();
13016 m_messages.clear();
13017 m_messageScopes.clear();
13019 SectionStats testCaseSectionStats(testCaseSection, assertions, duration, missingAssertions);
13020 m_reporter->sectionEnded(testCaseSectionStats);
13023 void RunContext::invokeActiveTestCase() {
13024 FatalConditionHandlerGuard _(&m_fatalConditionhandler);
13025 m_activeTestCase->invoke();
13028 void RunContext::handleUnfinishedSections() {
13031 for (
auto it = m_unfinishedSections.rbegin(),
13032 itEnd = m_unfinishedSections.rend();
13036 m_unfinishedSections.clear();
13039 void RunContext::handleExpr(
13040 AssertionInfo
const& info,
13041 ITransientExpression
const& expr,
13042 AssertionReaction& reaction
13044 m_reporter->assertionStarting( info );
13047 bool result = expr.getResult() != negated;
13050 if (!m_includeSuccessfulResults) {
13059 populateReaction( reaction );
13062 void RunContext::reportExpr(
13063 AssertionInfo
const &info,
13065 ITransientExpression
const *expr,
13068 m_lastAssertionInfo =
info;
13069 AssertionResultData data( resultType, LazyExpression( negated ) );
13071 AssertionResult assertionResult{
info, data };
13072 assertionResult.m_resultData.lazyExpression.m_transientExpression = expr;
13074 assertionEnded( assertionResult );
13077 void RunContext::handleMessage(
13078 AssertionInfo
const& info,
13080 StringRef
const& message,
13081 AssertionReaction& reaction
13083 m_reporter->assertionStarting( info );
13085 m_lastAssertionInfo =
info;
13087 AssertionResultData data( resultType, LazyExpression(
false ) );
13088 data.message =
static_cast<std::string
>(message);
13089 AssertionResult assertionResult{ m_lastAssertionInfo, data };
13090 assertionEnded( assertionResult );
13091 if( !assertionResult.isOk() )
13092 populateReaction( reaction );
13094 void RunContext::handleUnexpectedExceptionNotThrown(
13095 AssertionInfo
const& info,
13096 AssertionReaction& reaction
13101 void RunContext::handleUnexpectedInflightException(
13102 AssertionInfo
const& info,
13103 std::string
const& message,
13104 AssertionReaction& reaction
13106 m_lastAssertionInfo =
info;
13109 data.message = message;
13110 AssertionResult assertionResult{
info, data };
13111 assertionEnded( assertionResult );
13112 populateReaction( reaction );
13115 void RunContext::populateReaction( AssertionReaction& reaction ) {
13116 reaction.shouldDebugBreak = m_config->shouldDebugBreak();
13120 void RunContext::handleIncomplete(
13121 AssertionInfo
const& info
13123 m_lastAssertionInfo =
info;
13126 data.message =
"Exception translation was disabled by CATCH_CONFIG_FAST_COMPILE";
13127 AssertionResult assertionResult{
info, data };
13128 assertionEnded( assertionResult );
13130 void RunContext::handleNonExpr(
13131 AssertionInfo
const &info,
13133 AssertionReaction &reaction
13135 m_lastAssertionInfo =
info;
13137 AssertionResultData data( resultType, LazyExpression(
false ) );
13138 AssertionResult assertionResult{
info, data };
13139 assertionEnded( assertionResult );
13141 if( !assertionResult.isOk() )
13142 populateReaction( reaction );
13152 void seedRng(IConfig
const& config) {
13153 if (config.rngSeed() != 0) {
13154 std::srand(config.rngSeed());
13155 rng().
seed(config.rngSeed());
13171 m_sectionIncluded(
getResultCapture().sectionStarted( m_info, m_assertions ) )
13179 if( uncaught_exceptions() )
13187 Section::operator bool()
const {
13188 return m_sectionIncluded;
13198 ( SourceLineInfo
const& _lineInfo,
13199 std::string
const& _name )
13201 lineInfo( _lineInfo )
13214 class Session : NonCopyable {
13218 ~Session()
override;
13220 void showHelp()
const;
13221 void libIdentify();
13223 int applyCommandLine(
int argc,
char const *
const * argv );
13224 #if defined(CATCH_CONFIG_WCHAR) && defined(_WIN32) && defined(UNICODE)
13225 int applyCommandLine(
int argc,
wchar_t const *
const * argv );
13228 void useConfigData( ConfigData
const& configData );
13230 template<
typename CharT>
13231 int run(
int argc, CharT
const *
const argv[]) {
13232 if (m_startupExceptions)
13234 int returnCode = applyCommandLine(argc, argv);
13235 if (returnCode == 0)
13236 returnCode = run();
13242 clara::Parser
const& cli()
const;
13243 void cli( clara::Parser
const& newParser );
13244 ConfigData& configData();
13249 clara::Parser m_cli;
13250 ConfigData m_configData;
13251 std::shared_ptr<Config> m_config;
13252 bool m_startupExceptions =
false;
13266 Version( Version
const& ) =
delete;
13267 Version& operator=( Version
const& ) =
delete;
13268 Version(
unsigned int _majorVersion,
13269 unsigned int _minorVersion,
13270 unsigned int _patchNumber,
13271 char const *
const _branchName,
13272 unsigned int _buildNumber );
13274 unsigned int const majorVersion;
13275 unsigned int const minorVersion;
13276 unsigned int const patchNumber;
13279 char const *
const branchName;
13280 unsigned int const buildNumber;
13282 friend std::ostream&
operator << ( std::ostream& os, Version
const& version );
13285 Version
const& libraryVersion();
13292 #include <iterator>
13297 const int MaxExitCode = 255;
13299 IStreamingReporterPtr createReporter(std::string
const& reporterName,
IConfigPtr const& config) {
13301 CATCH_ENFORCE(reporter,
"No reporter registered with name: '" << reporterName <<
"'");
13306 IStreamingReporterPtr makeReporter(std::shared_ptr<Config>
const& config) {
13308 return createReporter(config->getReporterName(), config);
13316 auto ret = std::unique_ptr<IStreamingReporter>(
new ListeningReporter);
13317 auto& multi =
static_cast<ListeningReporter&
>(*ret);
13319 for (
auto const& listener : listeners) {
13320 multi.addListener(listener->create(Catch::ReporterConfig(config)));
13322 multi.addReporter(createReporter(config->getReporterName(), config));
13328 explicit TestGroup(std::shared_ptr<Config>
const& config)
13330 , m_context{config, makeReporter(config)}
13333 m_matches = m_config->testSpec().matchesByFilter(allTestCases, *m_config);
13334 auto const& invalidArgs = m_config->testSpec().getInvalidArgs();
13336 if (m_matches.empty() && invalidArgs.empty()) {
13337 for (
auto const& test : allTestCases)
13338 if (!test.isHidden())
13339 m_tests.emplace(&test);
13341 for (
auto const& match : m_matches)
13342 m_tests.insert(match.tests.begin(), match.tests.end());
13347 auto const& invalidArgs = m_config->testSpec().getInvalidArgs();
13349 m_context.testGroupStarting(m_config->name(), 1, 1);
13350 for (
auto const& testCase : m_tests) {
13351 if (!m_context.aborting())
13352 totals += m_context.runTest(*testCase);
13354 m_context.reporter().skipTest(*testCase);
13357 for (
auto const& match : m_matches) {
13358 if (match.tests.empty()) {
13359 m_context.reporter().noMatchingTestCases(match.name);
13364 if (!invalidArgs.empty()) {
13365 for (
auto const& invalidArg: invalidArgs)
13366 m_context.reporter().reportInvalidArguments(invalidArg);
13369 m_context.testGroupEnded(m_config->name(), totals, 1, 1);
13374 using Tests = std::set<TestCase const*>;
13376 std::shared_ptr<Config> m_config;
13377 RunContext m_context;
13384 for (
auto& testCase : tests) {
13385 auto tags = testCase.tags;
13387 std::string filename = testCase.lineInfo.file;
13388 auto lastSlash = filename.find_last_of(
"\\/");
13389 if (lastSlash != std::string::npos) {
13390 filename.erase(0, lastSlash);
13395 filename.insert(0,
"#");
13398 auto lastDot = filename.find_last_of(
'.');
13399 if (lastDot != std::string::npos) {
13400 filename.erase(lastDot);
13403 tags.push_back(std::move(filename));
13404 setTags(testCase, tags);
13410 Session::Session() {
13411 static bool alreadyInstantiated =
false;
13412 if( alreadyInstantiated ) {
13418 #if !defined(CATCH_CONFIG_DISABLE_EXCEPTIONS)
13420 if ( !exceptions.empty() ) {
13424 m_startupExceptions =
true;
13425 Colour colourGuard( Colour::Red );
13426 Catch::cerr() <<
"Errors occurred during startup!" <<
'\n';
13428 for (
const auto& ex_ptr : exceptions ) {
13430 std::rethrow_exception(ex_ptr);
13431 }
catch ( std::exception
const& ex ) {
13432 Catch::cerr() << Column( ex.what() ).indent(2) <<
'\n';
13438 alreadyInstantiated =
true;
13439 m_cli = makeCommandLineParser( m_configData );
13441 Session::~Session() {
13445 void Session::showHelp()
const {
13447 <<
"\nCatch v" << libraryVersion() <<
"\n"
13448 << m_cli << std::endl
13449 <<
"For more detailed usage please see the project docs\n" << std::endl;
13451 void Session::libIdentify() {
13453 << std::left << std::setw(16) <<
"description: " <<
"A Catch2 test executable\n"
13454 << std::left << std::setw(16) <<
"category: " <<
"testframework\n"
13455 << std::left << std::setw(16) <<
"framework: " <<
"Catch Test\n"
13456 << std::left << std::setw(16) <<
"version: " << libraryVersion() << std::endl;
13459 int Session::applyCommandLine(
int argc,
char const *
const * argv ) {
13460 if( m_startupExceptions )
13463 auto result = m_cli.parse( clara::Args( argc, argv ) );
13468 << Colour( Colour::Red )
13469 <<
"\nError(s) in input:\n"
13470 << Column( result.errorMessage() ).indent( 2 )
13472 Catch::cerr() <<
"Run with -? for usage\n" << std::endl;
13473 return MaxExitCode;
13476 if( m_configData.showHelp )
13478 if( m_configData.libIdentify )
13484 #if defined(CATCH_CONFIG_WCHAR) && defined(_WIN32) && defined(UNICODE)
13485 int Session::applyCommandLine(
int argc,
wchar_t const *
const * argv ) {
13487 char **utf8Argv =
new char *[ argc ];
13489 for (
int i = 0; i < argc; ++i ) {
13490 int bufSize = WideCharToMultiByte( CP_UTF8, 0, argv[i], -1,
nullptr, 0,
nullptr,
nullptr );
13492 utf8Argv[ i ] =
new char[ bufSize ];
13494 WideCharToMultiByte( CP_UTF8, 0, argv[i], -1, utf8Argv[i], bufSize,
nullptr,
nullptr );
13497 int returnCode = applyCommandLine( argc, utf8Argv );
13499 for (
int i = 0; i < argc; ++i )
13500 delete [] utf8Argv[ i ];
13502 delete [] utf8Argv;
13508 void Session::useConfigData( ConfigData
const& configData ) {
13509 m_configData = configData;
13513 int Session::run() {
13514 if( ( m_configData.waitForKeypress & WaitForKeypress::BeforeStart ) != 0 ) {
13515 Catch::cout() <<
"...waiting for enter/ return before starting" << std::endl;
13516 static_cast<void>(std::getchar());
13518 int exitCode = runInternal();
13519 if( ( m_configData.waitForKeypress & WaitForKeypress::BeforeExit ) != 0 ) {
13520 Catch::cout() <<
"...waiting for enter/ return before exiting, with code: " << exitCode << std::endl;
13521 static_cast<void>(std::getchar());
13526 clara::Parser
const& Session::cli()
const {
13529 void Session::cli( clara::Parser
const& newParser ) {
13532 ConfigData& Session::configData() {
13533 return m_configData;
13535 Config& Session::config() {
13537 m_config = std::make_shared<Config>( m_configData );
13541 int Session::runInternal() {
13542 if( m_startupExceptions )
13545 if (m_configData.showHelp || m_configData.libIdentify) {
13552 seedRng( *m_config );
13554 if( m_configData.filenamesAsTags )
13555 applyFilenamesAsTags( *m_config );
13558 if( Option<std::size_t> listed = list( m_config ) )
13559 return (std::min) (MaxExitCode,
static_cast<int>(*listed));
13561 TestGroup tests { m_config };
13562 auto const totals = tests.execute();
13564 if( m_config->warnAboutNoTests() && totals.error == -1 )
13570 return (std::min) (MaxExitCode, (std::max) (totals.error,
static_cast<int>(totals.assertions.failed)));
13572 #if !defined(CATCH_CONFIG_DISABLE_EXCEPTIONS)
13573 catch( std::exception& ex ) {
13575 return MaxExitCode;
13589 static auto getSingletons() -> std::vector<ISingleton*>*& {
13590 static std::vector<ISingleton*>* g_singletons =
nullptr;
13591 if( !g_singletons )
13592 g_singletons =
new std::vector<ISingleton*>();
13593 return g_singletons;
13597 ISingleton::~ISingleton() {}
13599 void addSingleton(ISingleton* singleton ) {
13600 getSingletons()->push_back( singleton );
13602 void cleanupSingletons() {
13603 auto& singletons = getSingletons();
13604 for(
auto singleton : *singletons )
13607 singletons =
nullptr;
13614 #if !defined(CATCH_CONFIG_DISABLE_EXCEPTIONS)
13616 void StartupExceptionRegistry::add( std::exception_ptr
const& exception ) noexcept {
13618 m_exceptions.push_back(exception);
13625 std::vector<std::exception_ptr>
const& StartupExceptionRegistry::getExceptions() const noexcept {
13626 return m_exceptions;
13635 #include <iostream>
13645 namespace Detail {
namespace {
13646 template<
typename WriterF, std::
size_t bufferSize=256>
13647 class StreamBufImpl :
public std::streambuf {
13648 char data[bufferSize];
13653 setp( data, data +
sizeof(data) );
13656 ~StreamBufImpl() noexcept {
13657 StreamBufImpl::sync();
13661 int overflow(
int c )
override {
13665 if( pbase() == epptr() )
13666 m_writer( std::string( 1,
static_cast<char>( c ) ) );
13668 sputc(
static_cast<char>( c ) );
13673 int sync()
override {
13674 if( pbase() != pptr() ) {
13675 m_writer( std::string( pbase(),
static_cast<std::string::size_type
>( pptr() - pbase() ) ) );
13676 setp( pbase(), epptr() );
13684 struct OutputDebugWriter {
13686 void operator()( std::string
const&str ) {
13687 writeToDebugConsole( str );
13693 class FileStream :
public IStream {
13694 mutable std::ofstream m_ofs;
13696 FileStream( StringRef filename ) {
13697 m_ofs.open( filename.c_str() );
13698 CATCH_ENFORCE( !m_ofs.fail(),
"Unable to open file: '" << filename <<
"'" );
13700 ~FileStream()
override =
default;
13702 std::ostream& stream()
const override {
13709 class CoutStream :
public IStream {
13710 mutable std::ostream m_os;
13714 CoutStream() : m_os(
Catch::
cout().rdbuf() ) {}
13715 ~CoutStream()
override =
default;
13718 std::ostream& stream()
const override {
return m_os; }
13723 class DebugOutStream :
public IStream {
13724 std::unique_ptr<StreamBufImpl<OutputDebugWriter>> m_streamBuf;
13725 mutable std::ostream m_os;
13728 : m_streamBuf( new StreamBufImpl<OutputDebugWriter>() ),
13729 m_os( m_streamBuf.get() )
13732 ~DebugOutStream()
override =
default;
13735 std::ostream& stream()
const override {
return m_os; }
13742 auto makeStream( StringRef
const &filename ) -> IStream
const* {
13743 if( filename.empty() )
13744 return new Detail::CoutStream();
13745 else if( filename[0] ==
'%' ) {
13746 if( filename ==
"%debug" )
13747 return new Detail::DebugOutStream();
13749 CATCH_ERROR(
"Unrecognised stream: '" << filename <<
"'" );
13752 return new Detail::FileStream( filename );
13756 struct StringStreams {
13757 std::vector<std::unique_ptr<std::ostringstream>> m_streams;
13758 std::vector<std::size_t> m_unused;
13759 std::ostringstream m_referenceStream;
13761 auto add() -> std::size_t {
13762 if( m_unused.empty() ) {
13763 m_streams.push_back( std::unique_ptr<std::ostringstream>(
new std::ostringstream ) );
13764 return m_streams.size()-1;
13767 auto index = m_unused.back();
13768 m_unused.pop_back();
13773 void release( std::size_t index ) {
13774 m_streams[index]->copyfmt( m_referenceStream );
13775 m_unused.push_back(index);
13780 : m_index( Singleton<StringStreams>::getMutable().add() ),
13781 m_oss( Singleton<StringStreams>::getMutable().m_streams[m_index].get() )
13785 static_cast<std::ostringstream*
>(
m_oss )->
str(
"");
13787 Singleton<StringStreams>::getMutable().release(
m_index );
13791 return static_cast<std::ostringstream*
>(
m_oss )->
str();
13796 #ifndef CATCH_CONFIG_NOSTDOUT
13805 #include <algorithm>
13814 char toLowerCh(
char c) {
13815 return static_cast<char>( std::tolower(
static_cast<unsigned char>(c) ) );
13819 bool startsWith( std::string
const& s, std::string
const& prefix ) {
13820 return s.size() >= prefix.size() && std::equal(prefix.begin(), prefix.end(), s.begin());
13822 bool startsWith( std::string
const& s,
char prefix ) {
13823 return !s.empty() && s[0] == prefix;
13825 bool endsWith( std::string
const& s, std::string
const& suffix ) {
13826 return s.size() >= suffix.size() && std::equal(suffix.rbegin(), suffix.rend(), s.rbegin());
13828 bool endsWith( std::string
const& s,
char suffix ) {
13829 return !s.empty() && s[s.size()-1] == suffix;
13831 bool contains( std::string
const& s, std::string
const& infix ) {
13832 return s.find( infix ) != std::string::npos;
13835 std::transform( s.begin(), s.end(), s.begin(), toLowerCh );
13837 std::string
toLower( std::string
const& s ) {
13838 std::string lc = s;
13842 std::string
trim( std::string
const& str ) {
13843 static char const* whitespaceChars =
"\n\r\t ";
13844 std::string::size_type start = str.find_first_not_of( whitespaceChars );
13845 std::string::size_type end = str.find_last_not_of( whitespaceChars );
13847 return start != std::string::npos ? str.substr( start, 1+end-start ) : std::string();
13850 StringRef
trim(StringRef ref) {
13851 const auto is_ws = [](
char c) {
13852 return c ==
' ' || c ==
'\t' || c ==
'\n' || c ==
'\r';
13854 size_t real_begin = 0;
13855 while (real_begin < ref.size() && is_ws(ref[real_begin])) { ++real_begin; }
13856 size_t real_end = ref.size();
13857 while (real_end > real_begin && is_ws(ref[real_end - 1])) { --real_end; }
13859 return ref.substr(real_begin, real_end - real_begin);
13862 bool replaceInPlace( std::string& str, std::string
const& replaceThis, std::string
const& withThis ) {
13863 bool replaced =
false;
13864 std::size_t i = str.find( replaceThis );
13865 while( i != std::string::npos ) {
13867 str = str.substr( 0, i ) + withThis + str.substr( i+replaceThis.size() );
13868 if( i < str.size()-withThis.size() )
13869 i = str.find( replaceThis, i+withThis.size() );
13871 i = std::string::npos;
13876 std::vector<StringRef>
splitStringRef( StringRef str,
char delimiter ) {
13877 std::vector<StringRef> subStrings;
13878 std::size_t start = 0;
13879 for(std::size_t pos = 0; pos < str.size(); ++pos ) {
13880 if( str[pos] == delimiter ) {
13881 if( pos - start > 1 )
13882 subStrings.push_back( str.substr( start, pos-start ) );
13886 if( start < str.size() )
13887 subStrings.push_back( str.substr( start, str.size()-start ) );
13891 pluralise::pluralise( std::size_t count, std::string
const& label )
13892 : m_count( count ),
13896 std::ostream&
operator << ( std::ostream& os, pluralise
const& pluraliser ) {
13897 os << pluraliser.m_count <<
' ' << pluraliser.m_label;
13898 if( pluraliser.m_count != 1 )
13907 #include <algorithm>
13925 auto StringRef::substr( size_type start, size_type size )
const noexcept -> StringRef {
13926 if (start < m_size) {
13927 return StringRef(m_start + start, (std::min)(m_size - start, size));
13929 return StringRef();
13933 return m_size == other.m_size
13934 && (std::memcmp( m_start, other.m_start, m_size ) == 0);
13937 auto operator << ( std::ostream& os, StringRef
const& str ) -> std::ostream& {
13938 return os.write(str.data(), str.size());
13941 auto operator+=( std::string& lhs, StringRef
const& rhs ) -> std::string& {
13942 lhs.append(rhs.data(), rhs.size());
13951 TagAlias::TagAlias(std::string
const & _tag, SourceLineInfo _lineInfo): tag(_tag), lineInfo(_lineInfo) {}
13975 TagAliasRegistry::~TagAliasRegistry() {}
13977 TagAlias
const* TagAliasRegistry::find( std::string
const& alias )
const {
13978 auto it = m_registry.find( alias );
13979 if(
it != m_registry.end() )
13980 return &(
it->second);
13985 std::string TagAliasRegistry::expandAliases( std::string
const& unexpandedTestSpec )
const {
13986 std::string expandedTestSpec = unexpandedTestSpec;
13987 for(
auto const& registryKvp : m_registry ) {
13988 std::size_t pos = expandedTestSpec.find( registryKvp.first );
13989 if( pos != std::string::npos ) {
13990 expandedTestSpec = expandedTestSpec.substr( 0, pos ) +
13991 registryKvp.second.tag +
13992 expandedTestSpec.substr( pos + registryKvp.first.size() );
13995 return expandedTestSpec;
13998 void TagAliasRegistry::add( std::string
const& alias, std::string
const& tag, SourceLineInfo
const& lineInfo ) {
14000 "error: tag alias, '" << alias <<
"' is not of the form [@alias name].\n" << lineInfo );
14002 CATCH_ENFORCE( m_registry.insert(std::make_pair(alias, TagAlias(tag, lineInfo))).second,
14003 "error: tag alias, '" << alias <<
"' already registered.\n"
14004 <<
"\tFirst seen at: " << find(alias)->lineInfo <<
"\n"
14005 <<
"\tRedefined at: " << lineInfo );
14008 ITagAliasRegistry::~ITagAliasRegistry() {}
14010 ITagAliasRegistry
const& ITagAliasRegistry::get() {
14019 #include <exception>
14020 #include <algorithm>
14030 else if( tag ==
"!throws" )
14032 else if( tag ==
"!shouldfail" )
14034 else if( tag ==
"!mayfail" )
14036 else if( tag ==
"!nonportable" )
14038 else if( tag ==
"!benchmark" )
14043 bool isReservedTag( std::string
const& tag ) {
14044 return parseSpecialTag( tag ) ==
TestCaseInfo::None && tag.size() > 0 && !std::isalnum(
static_cast<unsigned char>(tag[0]) );
14046 void enforceNotReservedTag( std::string
const& tag, SourceLineInfo
const& _lineInfo ) {
14048 "Tag name: [" << tag <<
"] is not allowed.\n"
14049 <<
"Tag names starting with non alphanumeric characters are reserved\n"
14055 std::string
const& _className,
14056 NameAndTags
const& nameAndTags,
14057 SourceLineInfo
const& _lineInfo )
14059 bool isHidden =
false;
14062 std::vector<std::string> tags;
14063 std::string desc, tag;
14064 bool inTag =
false;
14065 for (
char c : nameAndTags.tags) {
14078 enforceNotReservedTag( tag, _lineInfo );
14083 if (
startsWith(tag,
'.') && tag.size() > 1) {
14086 tags.push_back( tag );
14096 tags.insert( tags.end(), {
".",
"!hide" } );
14099 TestCaseInfo
info(
static_cast<std::string
>(nameAndTags.name), _className, desc, tags, _lineInfo );
14100 return TestCase( _testCase, std::move(info) );
14103 void setTags( TestCaseInfo& testCaseInfo, std::vector<std::string> tags ) {
14104 std::sort(begin(tags), end(tags));
14105 tags.erase(std::unique(begin(tags), end(tags)), end(tags));
14106 testCaseInfo.lcaseTags.clear();
14108 for(
auto const& tag : tags ) {
14109 std::string lcaseTag =
toLower( tag );
14111 testCaseInfo.lcaseTags.push_back( lcaseTag );
14113 testCaseInfo.tags = std::move(tags);
14117 std::string
const& _className,
14118 std::string
const& _description,
14119 std::vector<std::string>
const& _tags,
14120 SourceLineInfo
const& _lineInfo )
14122 className( _className ),
14123 description( _description ),
14124 lineInfo( _lineInfo ),
14127 setTags( *
this, _tags );
14146 std::size_t full_size = 2 *
tags.size();
14147 for (
const auto& tag :
tags) {
14148 full_size += tag.size();
14150 ret.reserve(full_size);
14151 for (
const auto& tag :
tags) {
14152 ret.push_back(
'[');
14154 ret.push_back(
']');
14160 TestCase::TestCase( ITestInvoker* testCase, TestCaseInfo&& info ) : TestCaseInfo( std::move(
info) ), test( testCase ) {}
14164 other.name = _newName;
14173 return test.get() == other.test.get() &&
14174 name == other.name &&
14179 return name < other.name;
14191 #include <algorithm>
14197 struct TestHasher {
14198 using hash_t = uint64_t;
14200 explicit TestHasher( hash_t hashSuffix ):
14201 m_hashSuffix{ hashSuffix } {}
14203 uint32_t operator()( TestCase
const& t )
const {
14205 const hash_t prime = 1099511628211u;
14206 hash_t hash = 14695981039346656037u;
14207 for (
const char c : t.name ) {
14211 hash ^= m_hashSuffix;
14213 const uint32_t low{
static_cast<uint32_t
>( hash ) };
14214 const uint32_t high{
static_cast<uint32_t
>( hash >> 32 ) };
14219 hash_t m_hashSuffix;
14223 std::vector<TestCase> sortTests( IConfig
const& config, std::vector<TestCase>
const& unsortedTestCases ) {
14224 switch( config.runOrder() ) {
14230 std::vector<TestCase> sorted = unsortedTestCases;
14231 std::sort( sorted.begin(), sorted.end() );
14237 TestHasher h{ config.rngSeed() };
14239 using hashedTest = std::pair<TestHasher::hash_t, TestCase const*>;
14240 std::vector<hashedTest> indexed_tests;
14241 indexed_tests.reserve( unsortedTestCases.size() );
14243 for (
auto const& testCase : unsortedTestCases) {
14244 indexed_tests.emplace_back(h(testCase), &testCase);
14247 std::sort(indexed_tests.begin(), indexed_tests.end(),
14248 [](hashedTest
const& lhs, hashedTest
const& rhs) {
14249 if (lhs.first == rhs.first) {
14250 return lhs.second->name < rhs.second->name;
14252 return lhs.first < rhs.first;
14255 std::vector<TestCase> sorted;
14256 sorted.reserve( indexed_tests.size() );
14258 for (
auto const& hashed : indexed_tests) {
14259 sorted.emplace_back(*hashed.second);
14265 return unsortedTestCases;
14268 bool isThrowSafe( TestCase
const& testCase, IConfig
const& config ) {
14269 return !testCase.throws() || config.allowThrows();
14272 bool matchTest( TestCase
const& testCase, TestSpec
const& testSpec, IConfig
const& config ) {
14273 return testSpec.matches( testCase ) &&
isThrowSafe( testCase, config );
14276 void enforceNoDuplicateTestCases( std::vector<TestCase>
const& functions ) {
14277 std::set<TestCase> seenFunctions;
14278 for(
auto const&
function : functions ) {
14279 auto prev = seenFunctions.insert(
function );
14281 "error: TEST_CASE( \"" <<
function.name <<
"\" ) already defined.\n"
14282 <<
"\tFirst seen at " << prev.first->getTestCaseInfo().lineInfo <<
"\n"
14283 <<
"\tRedefined at " <<
function.getTestCaseInfo().lineInfo );
14287 std::vector<TestCase>
filterTests( std::vector<TestCase>
const& testCases, TestSpec
const& testSpec, IConfig
const& config ) {
14288 std::vector<TestCase> filtered;
14289 filtered.reserve( testCases.size() );
14290 for (
auto const& testCase : testCases) {
14291 if ((!testSpec.hasFilters() && !testCase.isHidden()) ||
14292 (testSpec.hasFilters() &&
matchTest(testCase, testSpec, config))) {
14293 filtered.push_back(testCase);
14302 void TestRegistry::registerTest( TestCase
const& testCase ) {
14303 std::string name = testCase.getTestCaseInfo().name;
14304 if( name.empty() ) {
14305 ReusableStringStream rss;
14306 rss <<
"Anonymous test case " << ++m_unnamedCount;
14307 return registerTest( testCase.withName( rss.str() ) );
14309 m_functions.push_back( testCase );
14312 std::vector<TestCase>
const& TestRegistry::getAllTests()
const {
14313 return m_functions;
14315 std::vector<TestCase>
const& TestRegistry::getAllTestsSorted( IConfig
const& config )
const {
14316 if( m_sortedFunctions.empty() )
14317 enforceNoDuplicateTestCases( m_functions );
14319 if( m_currentSortOrder != config.runOrder() || m_sortedFunctions.empty() ) {
14320 m_sortedFunctions = sortTests( config, m_functions );
14321 m_currentSortOrder = config.runOrder();
14323 return m_sortedFunctions;
14327 TestInvokerAsFunction::TestInvokerAsFunction(
void(*testAsFunction)() ) noexcept : m_testAsFunction( testAsFunction ) {}
14329 void TestInvokerAsFunction::invoke()
const {
14330 m_testAsFunction();
14333 std::string extractClassName( StringRef
const& classOrQualifiedMethodName ) {
14334 std::string className(classOrQualifiedMethodName);
14337 std::size_t lastColons = className.rfind(
"::" );
14338 std::size_t penultimateColons = className.rfind(
"::", lastColons-1 );
14339 if( penultimateColons == std::string::npos )
14340 penultimateColons = 1;
14341 className = className.substr( penultimateColons, lastColons-penultimateColons );
14350 #include <algorithm>
14352 #include <stdexcept>
14356 #if defined(__clang__)
14357 # pragma clang diagnostic push
14358 # pragma clang diagnostic ignored "-Wexit-time-destructors"
14362 namespace TestCaseTracking {
14364 NameAndLocation::NameAndLocation( std::string
const& _name, SourceLineInfo
const& _location )
14366 location( _location )
14369 ITracker::~ITracker() =
default;
14371 ITracker& TrackerContext::startRun() {
14372 m_rootTracker = std::make_shared<SectionTracker>( NameAndLocation(
"{root}",
CATCH_INTERNAL_LINEINFO ), *
this,
nullptr );
14373 m_currentTracker =
nullptr;
14374 m_runState = Executing;
14375 return *m_rootTracker;
14378 void TrackerContext::endRun() {
14379 m_rootTracker.reset();
14380 m_currentTracker =
nullptr;
14381 m_runState = NotStarted;
14384 void TrackerContext::startCycle() {
14385 m_currentTracker = m_rootTracker.get();
14386 m_runState = Executing;
14388 void TrackerContext::completeCycle() {
14389 m_runState = CompletedCycle;
14392 bool TrackerContext::completedCycle()
const {
14393 return m_runState == CompletedCycle;
14395 ITracker& TrackerContext::currentTracker() {
14396 return *m_currentTracker;
14398 void TrackerContext::setCurrentTracker( ITracker* tracker ) {
14399 m_currentTracker = tracker;
14402 TrackerBase::TrackerBase( NameAndLocation
const& nameAndLocation, TrackerContext& ctx, ITracker* parent ):
14403 ITracker(nameAndLocation),
14408 bool TrackerBase::isComplete()
const {
14409 return m_runState == CompletedSuccessfully || m_runState == Failed;
14411 bool TrackerBase::isSuccessfullyCompleted()
const {
14412 return m_runState == CompletedSuccessfully;
14414 bool TrackerBase::isOpen()
const {
14415 return m_runState != NotStarted && !isComplete();
14417 bool TrackerBase::hasChildren()
const {
14418 return !m_children.empty();
14421 void TrackerBase::addChild( ITrackerPtr
const& child ) {
14422 m_children.push_back( child );
14425 ITrackerPtr TrackerBase::findChild( NameAndLocation
const& nameAndLocation ) {
14426 auto it = std::find_if( m_children.begin(), m_children.end(),
14427 [&nameAndLocation]( ITrackerPtr
const& tracker ){
14429 tracker->nameAndLocation().location == nameAndLocation.location &&
14430 tracker->nameAndLocation().name == nameAndLocation.name;
14432 return(
it != m_children.end() )
14436 ITracker& TrackerBase::parent() {
14437 assert( m_parent );
14441 void TrackerBase::openChild() {
14442 if( m_runState != ExecutingChildren ) {
14443 m_runState = ExecutingChildren;
14445 m_parent->openChild();
14449 bool TrackerBase::isSectionTracker()
const {
return false; }
14450 bool TrackerBase::isGeneratorTracker()
const {
return false; }
14452 void TrackerBase::open() {
14453 m_runState = Executing;
14456 m_parent->openChild();
14459 void TrackerBase::close() {
14462 while( &m_ctx.currentTracker() !=
this )
14463 m_ctx.currentTracker().close();
14465 switch( m_runState ) {
14466 case NeedsAnotherRun:
14470 m_runState = CompletedSuccessfully;
14472 case ExecutingChildren:
14473 if( std::all_of(m_children.begin(), m_children.end(), [](ITrackerPtr
const& t){ return t->isComplete(); }) )
14474 m_runState = CompletedSuccessfully;
14478 case CompletedSuccessfully:
14486 m_ctx.completeCycle();
14488 void TrackerBase::fail() {
14489 m_runState = Failed;
14491 m_parent->markAsNeedingAnotherRun();
14493 m_ctx.completeCycle();
14495 void TrackerBase::markAsNeedingAnotherRun() {
14496 m_runState = NeedsAnotherRun;
14499 void TrackerBase::moveToParent() {
14500 assert( m_parent );
14501 m_ctx.setCurrentTracker( m_parent );
14503 void TrackerBase::moveToThis() {
14504 m_ctx.setCurrentTracker(
this );
14507 SectionTracker::SectionTracker( NameAndLocation
const& nameAndLocation, TrackerContext& ctx, ITracker* parent )
14508 : TrackerBase( nameAndLocation, ctx, parent ),
14509 m_trimmed_name(
trim(nameAndLocation.name))
14512 while( !parent->isSectionTracker() )
14513 parent = &parent->parent();
14515 SectionTracker& parentSection =
static_cast<SectionTracker&
>( *parent );
14516 addNextFilters( parentSection.m_filters );
14520 bool SectionTracker::isComplete()
const {
14521 bool complete =
true;
14523 if (m_filters.empty()
14524 || m_filters[0] ==
""
14525 || std::find(m_filters.begin(), m_filters.end(), m_trimmed_name) != m_filters.end()) {
14526 complete = TrackerBase::isComplete();
14531 bool SectionTracker::isSectionTracker()
const {
return true; }
14533 SectionTracker& SectionTracker::acquire( TrackerContext& ctx, NameAndLocation
const& nameAndLocation ) {
14534 std::shared_ptr<SectionTracker> section;
14536 ITracker& currentTracker = ctx.currentTracker();
14537 if( ITrackerPtr childTracker = currentTracker.findChild( nameAndLocation ) ) {
14538 assert( childTracker );
14539 assert( childTracker->isSectionTracker() );
14540 section = std::static_pointer_cast<SectionTracker>( childTracker );
14543 section = std::make_shared<SectionTracker>( nameAndLocation, ctx, ¤tTracker );
14544 currentTracker.addChild( section );
14546 if( !ctx.completedCycle() )
14547 section->tryOpen();
14551 void SectionTracker::tryOpen() {
14552 if( !isComplete() )
14556 void SectionTracker::addInitialFilters( std::vector<std::string>
const& filters ) {
14557 if( !filters.empty() ) {
14558 m_filters.reserve( m_filters.size() + filters.size() + 2 );
14559 m_filters.emplace_back(
"");
14560 m_filters.emplace_back(
"");
14561 m_filters.insert( m_filters.end(), filters.begin(), filters.end() );
14564 void SectionTracker::addNextFilters( std::vector<std::string>
const& filters ) {
14565 if( filters.size() > 1 )
14566 m_filters.insert( m_filters.end(), filters.begin()+1, filters.end() );
14569 std::vector<std::string>
const& SectionTracker::getFilters()
const {
14573 std::string
const& SectionTracker::trimmedName()
const {
14574 return m_trimmed_name;
14579 using TestCaseTracking::ITracker;
14580 using TestCaseTracking::TrackerContext;
14581 using TestCaseTracking::SectionTracker;
14585 #if defined(__clang__)
14586 # pragma clang diagnostic pop
14593 auto makeTestInvoker(
void(*testAsFunction)() ) noexcept -> ITestInvoker* {
14594 return new(std::nothrow) TestInvokerAsFunction( testAsFunction );
14597 NameAndTags::NameAndTags( StringRef
const& name_ , StringRef
const& tags_ ) noexcept : name( name_ ), tags( tags_ ) {}
14599 AutoReg::AutoReg( ITestInvoker* invoker, SourceLineInfo
const& lineInfo, StringRef
const& classOrMethod, NameAndTags
const& nameAndTags ) noexcept {
14605 extractClassName( classOrMethod ),
14619 #include <algorithm>
14626 TestSpec::Pattern::Pattern( std::string
const& name )
14630 TestSpec::Pattern::~Pattern() =
default;
14632 std::string
const& TestSpec::Pattern::name()
const {
14636 TestSpec::NamePattern::NamePattern( std::string
const& name, std::string
const& filterString )
14637 : Pattern( filterString )
14638 , m_wildcardPattern(
toLower( name ), CaseSensitive::No )
14641 bool TestSpec::NamePattern::matches( TestCaseInfo
const& testCase )
const {
14642 return m_wildcardPattern.matches( testCase.name );
14645 TestSpec::TagPattern::TagPattern( std::string
const& tag, std::string
const& filterString )
14646 : Pattern( filterString )
14650 bool TestSpec::TagPattern::matches( TestCaseInfo
const& testCase )
const {
14651 return std::find(begin(testCase.lcaseTags),
14652 end(testCase.lcaseTags),
14653 m_tag) != end(testCase.lcaseTags);
14656 TestSpec::ExcludedPattern::ExcludedPattern( PatternPtr
const& underlyingPattern )
14657 : Pattern( underlyingPattern->name() )
14658 , m_underlyingPattern( underlyingPattern )
14661 bool TestSpec::ExcludedPattern::matches( TestCaseInfo
const& testCase )
const {
14662 return !m_underlyingPattern->matches( testCase );
14665 bool TestSpec::Filter::matches( TestCaseInfo
const& testCase )
const {
14666 return std::all_of( m_patterns.begin(), m_patterns.end(), [&]( PatternPtr
const& p ){ return p->matches( testCase ); } );
14669 std::string TestSpec::Filter::name()
const {
14671 for(
auto const& p : m_patterns )
14676 bool TestSpec::hasFilters()
const {
14677 return !m_filters.empty();
14680 bool TestSpec::matches( TestCaseInfo
const& testCase )
const {
14681 return std::any_of( m_filters.begin(), m_filters.end(), [&]( Filter
const& f ){ return f.matches( testCase ); } );
14684 TestSpec::Matches TestSpec::matchesByFilter( std::vector<TestCase>
const& testCases, IConfig
const& config )
const
14686 Matches matches( m_filters.size() );
14687 std::transform( m_filters.begin(), m_filters.end(), matches.begin(), [&]( Filter
const&
filter ){
14688 std::vector<TestCase const*> currentMatches;
14689 for( auto const& test : testCases )
14690 if( isThrowSafe( test, config ) && filter.matches( test ) )
14691 currentMatches.emplace_back( &test );
14692 return FilterMatch{ filter.name(), currentMatches };
14697 const TestSpec::vectorStrings& TestSpec::getInvalidArgs()
const{
14698 return (m_invalidArgs);
14707 TestSpecParser::TestSpecParser( ITagAliasRegistry
const& tagAliases ) : m_tagAliases( &tagAliases ) {}
14709 TestSpecParser& TestSpecParser::parse( std::string
const& arg ) {
14711 m_exclusion =
false;
14712 m_arg = m_tagAliases->expandAliases( arg );
14713 m_escapeChars.clear();
14714 m_substring.reserve(m_arg.size());
14715 m_patternName.reserve(m_arg.size());
14716 m_realPatternPos = 0;
14718 for( m_pos = 0; m_pos < m_arg.size(); ++m_pos )
14720 if( !visitChar( m_arg[m_pos] ) ){
14721 m_testSpec.m_invalidArgs.push_back(arg);
14727 TestSpec TestSpecParser::testSpec() {
14731 bool TestSpecParser::visitChar(
char c ) {
14732 if( (m_mode != EscapedName) && (c ==
'\\') ) {
14734 addCharToPattern(c);
14736 }
else if((m_mode != EscapedName) && (c ==
',') ) {
14742 if( processNoneChar( c ) )
14746 processNameChar( c );
14750 addCharToPattern(c);
14755 if( processOtherChar( c ) )
14761 if( !isControlChar( c ) ) {
14762 m_patternName += c;
14763 m_realPatternPos++;
14769 bool TestSpecParser::processNoneChar(
char c ) {
14774 m_exclusion =
true;
14777 startNewMode( Tag );
14780 startNewMode( QuotedName );
14783 startNewMode( Name );
14787 void TestSpecParser::processNameChar(
char c ) {
14789 if( m_substring ==
"exclude:" )
14790 m_exclusion =
true;
14793 startNewMode( Tag );
14796 bool TestSpecParser::processOtherChar(
char c ) {
14797 if( !isControlChar( c ) )
14803 void TestSpecParser::startNewMode( Mode mode ) {
14806 void TestSpecParser::endMode() {
14810 return addNamePattern();
14812 return addTagPattern();
14814 revertBackToLastMode();
14818 return startNewMode( None );
14821 void TestSpecParser::escape() {
14823 m_mode = EscapedName;
14824 m_escapeChars.push_back(m_realPatternPos);
14826 bool TestSpecParser::isControlChar(
char c )
const {
14839 return c ==
'[' || c ==
']';
14843 void TestSpecParser::addFilter() {
14844 if( !m_currentFilter.m_patterns.empty() ) {
14845 m_testSpec.m_filters.push_back( m_currentFilter );
14846 m_currentFilter = TestSpec::Filter();
14850 void TestSpecParser::saveLastMode() {
14854 void TestSpecParser::revertBackToLastMode() {
14858 bool TestSpecParser::separate() {
14859 if( (m_mode==QuotedName) || (m_mode==Tag) ){
14862 m_pos = m_arg.size();
14863 m_substring.clear();
14864 m_patternName.clear();
14865 m_realPatternPos = 0;
14873 std::string TestSpecParser::preprocessPattern() {
14874 std::string token = m_patternName;
14875 for (std::size_t i = 0; i < m_escapeChars.size(); ++i)
14876 token = token.substr(0, m_escapeChars[i] - i) + token.substr(m_escapeChars[i] - i + 1);
14877 m_escapeChars.clear();
14879 m_exclusion =
true;
14880 token = token.substr(8);
14883 m_patternName.clear();
14884 m_realPatternPos = 0;
14889 void TestSpecParser::addNamePattern() {
14890 auto token = preprocessPattern();
14892 if (!token.empty()) {
14893 TestSpec::PatternPtr pattern = std::make_shared<TestSpec::NamePattern>(token, m_substring);
14895 pattern = std::make_shared<TestSpec::ExcludedPattern>(pattern);
14896 m_currentFilter.m_patterns.push_back(pattern);
14898 m_substring.clear();
14899 m_exclusion =
false;
14903 void TestSpecParser::addTagPattern() {
14904 auto token = preprocessPattern();
14906 if (!token.empty()) {
14909 if (token.size() > 1 && token[0] ==
'.') {
14910 token.erase(token.begin());
14911 TestSpec::PatternPtr pattern = std::make_shared<TestSpec::TagPattern>(
".", m_substring);
14913 pattern = std::make_shared<TestSpec::ExcludedPattern>(pattern);
14915 m_currentFilter.m_patterns.push_back(pattern);
14918 TestSpec::PatternPtr pattern = std::make_shared<TestSpec::TagPattern>(token, m_substring);
14921 pattern = std::make_shared<TestSpec::ExcludedPattern>(pattern);
14923 m_currentFilter.m_patterns.push_back(pattern);
14925 m_substring.clear();
14926 m_exclusion =
false;
14930 TestSpec parseTestSpec( std::string
const& arg ) {
14931 return TestSpecParser( ITagAliasRegistry::get() ).parse( arg ).testSpec();
14940 static const uint64_t nanosecondsInSecond = 1000000000;
14945 return std::chrono::duration_cast<std::chrono::nanoseconds>( std::chrono::high_resolution_clock::now().time_since_epoch() ).count();
14949 auto estimateClockResolution() -> uint64_t {
14951 static const uint64_t iterations = 1000000;
14955 for( std::size_t i = 0; i < iterations; ++i ) {
14961 }
while( ticks == baseTicks );
14963 auto delta = ticks - baseTicks;
14969 if (ticks > startTime + 3 * nanosecondsInSecond) {
14970 return sum / ( i + 1u );
14976 return sum/iterations;
14980 static auto s_resolution = estimateClockResolution();
14981 return s_resolution;
14984 void Timer::start() {
14987 auto Timer::getElapsedNanoseconds() const -> uint64_t {
14990 auto Timer::getElapsedMicroseconds() const -> uint64_t {
14991 return getElapsedNanoseconds()/1000;
14993 auto Timer::getElapsedMilliseconds() const ->
unsigned int {
14994 return static_cast<unsigned int>(getElapsedMicroseconds()/1000);
14996 auto Timer::getElapsedSeconds() const ->
double {
14997 return getElapsedMicroseconds()/1000000.0;
15004 #if defined(__clang__)
15005 # pragma clang diagnostic push
15006 # pragma clang diagnostic ignored "-Wexit-time-destructors"
15007 # pragma clang diagnostic ignored "-Wglobal-constructors"
15011 #if !defined(CATCH_CONFIG_ENABLE_CHRONO_STRINGMAKER)
15012 #define CATCH_CONFIG_ENABLE_CHRONO_STRINGMAKER
15025 const int hexThreshold = 255;
15027 struct Endianness {
15028 enum Arch { Big, Little };
15030 static Arch which() {
15034 auto value = *
reinterpret_cast<char*
>(&one);
15035 return value ? Little : Big;
15042 int i = 0, end =
static_cast<int>( size ), inc = 1;
15043 if( Endianness::which() == Endianness::Little ) {
15048 unsigned char const *bytes =
static_cast<unsigned char const *
>(object);
15049 ReusableStringStream rss;
15050 rss <<
"0x" << std::setfill(
'0') << std::hex;
15051 for( ; i != end; i += inc )
15052 rss << std::setw(2) << static_cast<unsigned>(bytes[i]);
15057 template<
typename T>
15058 std::string fpToString( T
value,
int precision ) {
15059 if (Catch::isnan(
value)) {
15063 ReusableStringStream rss;
15064 rss << std::setprecision( precision )
15067 std::string d = rss.str();
15068 std::size_t i = d.find_last_not_of(
'0' );
15069 if( i != std::string::npos && i != d.size()-1 ) {
15072 d = d.substr( 0, i+1 );
15085 return '"' + str + '"';
15088 std::string s(
"\"");
15089 for (
char c : str) {
15106 #ifdef CATCH_CONFIG_CPP17_STRING_VIEW
15116 return{
"{null string}" };
15123 return{
"{null string}" };
15127 #ifdef CATCH_CONFIG_WCHAR
15130 s.reserve(wstr.size());
15131 for (
auto c : wstr) {
15132 s += (c <= 0xff) ? static_cast<char>(c) : '?';
15137 # ifdef CATCH_CONFIG_CPP17_STRING_VIEW
15147 return{
"{null string}" };
15154 return{
"{null string}" };
15159 #if defined(CATCH_CONFIG_CPP17_BYTE)
15173 ReusableStringStream rss;
15175 if (
value > Detail::hexThreshold) {
15176 rss <<
" (0x" << std::hex <<
value <<
')';
15188 ReusableStringStream rss;
15190 if (
value > Detail::hexThreshold) {
15191 rss <<
" (0x" << std::hex <<
value <<
')';
15197 return b ?
"true" :
"false";
15201 if (
value ==
'\r') {
15203 }
else if (
value ==
'\f') {
15205 }
else if (
value ==
'\n') {
15207 }
else if (
value ==
'\t') {
15212 char chstr[] =
"' '";
15231 return fpToString(
value, precision) + 'f';
15237 return fpToString(
value, precision);
15240 std::string ratio_string<std::atto>::symbol() {
return "a"; }
15241 std::string ratio_string<std::femto>::symbol() {
return "f"; }
15242 std::string ratio_string<std::pico>::symbol() {
return "p"; }
15243 std::string ratio_string<std::nano>::symbol() {
return "n"; }
15244 std::string ratio_string<std::micro>::symbol() {
return "u"; }
15245 std::string ratio_string<std::milli>::symbol() {
return "m"; }
15249 #if defined(__clang__)
15250 # pragma clang diagnostic pop
15297 Totals diff = *
this - prevTotals;
15298 if( diff.assertions.failed > 0 )
15300 else if( diff.assertions.failedButOk > 0 )
15320 #ifndef CATCH_CONFIG_UNCAUGHT_EXCEPTIONS_HPP
15321 #define CATCH_CONFIG_UNCAUGHT_EXCEPTIONS_HPP
15323 #if defined(_MSC_VER)
15324 # if _MSC_VER >= 1900
15325 # define CATCH_INTERNAL_CONFIG_CPP17_UNCAUGHT_EXCEPTIONS
15329 #include <exception>
15331 #if defined(__cpp_lib_uncaught_exceptions) \
15332 && !defined(CATCH_INTERNAL_CONFIG_CPP17_UNCAUGHT_EXCEPTIONS)
15334 # define CATCH_INTERNAL_CONFIG_CPP17_UNCAUGHT_EXCEPTIONS
15337 #if defined(CATCH_INTERNAL_CONFIG_CPP17_UNCAUGHT_EXCEPTIONS) \
15338 && !defined(CATCH_CONFIG_NO_CPP17_UNCAUGHT_EXCEPTIONS) \
15339 && !defined(CATCH_CONFIG_CPP17_UNCAUGHT_EXCEPTIONS)
15341 # define CATCH_CONFIG_CPP17_UNCAUGHT_EXCEPTIONS
15346 #include <exception>
15349 bool uncaught_exceptions() {
15350 #if defined(CATCH_CONFIG_DISABLE_EXCEPTIONS)
15352 #elif defined(CATCH_CONFIG_CPP17_UNCAUGHT_EXCEPTIONS)
15353 return std::uncaught_exceptions() > 0;
15355 return std::uncaught_exception();
15367 (
unsigned int _majorVersion,
15368 unsigned int _minorVersion,
15369 unsigned int _patchNumber,
15370 char const *
const _branchName,
15371 unsigned int _buildNumber )
15372 : majorVersion( _majorVersion ),
15373 minorVersion( _minorVersion ),
15374 patchNumber( _patchNumber ),
15375 branchName( _branchName ),
15376 buildNumber( _buildNumber )
15379 std::ostream&
operator << ( std::ostream& os, Version
const& version ) {
15380 os << version.majorVersion <<
'.'
15381 << version.minorVersion <<
'.'
15382 << version.patchNumber;
15384 if (version.branchName[0]) {
15385 os <<
'-' << version.branchName
15386 <<
'.' << version.buildNumber;
15391 Version
const& libraryVersion() {
15392 static Version version( 2, 13, 10,
"", 0 );
15402 WildcardPattern::WildcardPattern( std::string
const& pattern,
15404 : m_caseSensitivity( caseSensitivity ),
15405 m_pattern( normaliseString( pattern ) )
15408 m_pattern = m_pattern.substr( 1 );
15409 m_wildcard = WildcardAtStart;
15411 if(
endsWith( m_pattern,
'*' ) ) {
15412 m_pattern = m_pattern.substr( 0, m_pattern.size()-1 );
15413 m_wildcard =
static_cast<WildcardPosition
>( m_wildcard | WildcardAtEnd );
15417 bool WildcardPattern::matches( std::string
const& str )
const {
15418 switch( m_wildcard ) {
15420 return m_pattern == normaliseString( str );
15421 case WildcardAtStart:
15422 return endsWith( normaliseString( str ), m_pattern );
15423 case WildcardAtEnd:
15424 return startsWith( normaliseString( str ), m_pattern );
15425 case WildcardAtBothEnds:
15426 return contains( normaliseString( str ), m_pattern );
15432 std::string WildcardPattern::normaliseString( std::string
const& str )
const {
15440 #include <type_traits>
15446 size_t trailingBytes(
unsigned char c) {
15447 if ((c & 0xE0) == 0xC0) {
15450 if ((c & 0xF0) == 0xE0) {
15453 if ((c & 0xF8) == 0xF0) {
15459 uint32_t headerValue(
unsigned char c) {
15460 if ((c & 0xE0) == 0xC0) {
15463 if ((c & 0xF0) == 0xE0) {
15466 if ((c & 0xF8) == 0xF0) {
15472 void hexEscapeChar(std::ostream& os,
unsigned char c) {
15473 std::ios_base::fmtflags f(os.flags());
15475 << std::uppercase << std::hex << std::setfill(
'0') << std::setw(2)
15476 <<
static_cast<int>(c);
15480 bool shouldNewline(XmlFormatting fmt) {
15481 return !!(
static_cast<std::underlying_type<XmlFormatting>::type
>(fmt & XmlFormatting::Newline));
15484 bool shouldIndent(XmlFormatting fmt) {
15485 return !!(
static_cast<std::underlying_type<XmlFormatting>::type
>(fmt & XmlFormatting::Indent));
15490 XmlFormatting
operator | (XmlFormatting lhs, XmlFormatting rhs) {
15491 return static_cast<XmlFormatting
>(
15492 static_cast<std::underlying_type<XmlFormatting>::type
>(lhs) |
15493 static_cast<std::underlying_type<XmlFormatting>::type
>(rhs)
15497 XmlFormatting operator & (XmlFormatting lhs, XmlFormatting rhs) {
15498 return static_cast<XmlFormatting
>(
15499 static_cast<std::underlying_type<XmlFormatting>::type
>(lhs) &
15500 static_cast<std::underlying_type<XmlFormatting>::type
>(rhs)
15504 XmlEncode::XmlEncode( std::string
const& str, ForWhat forWhat )
15506 m_forWhat( forWhat )
15509 void XmlEncode::encodeTo( std::ostream& os )
const {
15513 for( std::size_t idx = 0; idx < m_str.size(); ++ idx ) {
15514 unsigned char c = m_str[idx];
15516 case '<': os <<
"<";
break;
15517 case '&': os <<
"&";
break;
15521 if (idx > 2 && m_str[idx - 1] ==
']' && m_str[idx - 2] ==
']')
15528 if (m_forWhat == ForAttributes)
15539 if (c < 0x09 || (c > 0x0D && c < 0x20) || c == 0x7F) {
15540 hexEscapeChar(os, c);
15558 hexEscapeChar(os, c);
15562 auto encBytes = trailingBytes(c);
15564 if (idx + encBytes - 1 >= m_str.size()) {
15565 hexEscapeChar(os, c);
15572 uint32_t
value = headerValue(c);
15573 for (std::size_t n = 1; n < encBytes; ++n) {
15574 unsigned char nc = m_str[idx + n];
15575 valid &= ((nc & 0xC0) == 0x80);
15584 (0x80 <=
value && value < 0x800 && encBytes > 2) ||
15585 (0x800 <
value && value < 0x10000 && encBytes > 3) ||
15587 (
value >= 0x110000)
15589 hexEscapeChar(os, c);
15594 for (std::size_t n = 0; n < encBytes; ++n) {
15595 os << m_str[idx + n];
15597 idx += encBytes - 1;
15603 std::ostream&
operator << ( std::ostream& os, XmlEncode
const& xmlEncode ) {
15604 xmlEncode.encodeTo( os );
15608 XmlWriter::ScopedElement::ScopedElement( XmlWriter* writer, XmlFormatting fmt )
15609 : m_writer( writer ),
15613 XmlWriter::ScopedElement::ScopedElement( ScopedElement&& other ) noexcept
15614 : m_writer( other.m_writer ),
15617 other.m_writer =
nullptr;
15618 other.m_fmt = XmlFormatting::None;
15620 XmlWriter::ScopedElement& XmlWriter::ScopedElement::operator=( ScopedElement&& other ) noexcept {
15622 m_writer->endElement();
15624 m_writer = other.m_writer;
15625 other.m_writer =
nullptr;
15626 m_fmt = other.m_fmt;
15627 other.m_fmt = XmlFormatting::None;
15631 XmlWriter::ScopedElement::~ScopedElement() {
15633 m_writer->endElement(m_fmt);
15637 XmlWriter::ScopedElement& XmlWriter::ScopedElement::writeText( std::string
const& text, XmlFormatting fmt ) {
15638 m_writer->writeText( text, fmt );
15642 XmlWriter::XmlWriter( std::ostream& os ) : m_os( os )
15644 writeDeclaration();
15647 XmlWriter::~XmlWriter() {
15648 while (!m_tags.empty()) {
15651 newlineIfNecessary();
15654 XmlWriter& XmlWriter::startElement( std::string
const& name, XmlFormatting fmt ) {
15656 newlineIfNecessary();
15657 if (shouldIndent(fmt)) {
15661 m_os <<
'<' << name;
15662 m_tags.push_back( name );
15663 m_tagIsOpen =
true;
15664 applyFormatting(fmt);
15668 XmlWriter::ScopedElement XmlWriter::scopedElement( std::string
const& name, XmlFormatting fmt ) {
15669 ScopedElement scoped(
this, fmt );
15670 startElement( name, fmt );
15674 XmlWriter& XmlWriter::endElement(XmlFormatting fmt) {
15675 m_indent = m_indent.substr(0, m_indent.size() - 2);
15677 if( m_tagIsOpen ) {
15679 m_tagIsOpen =
false;
15681 newlineIfNecessary();
15682 if (shouldIndent(fmt)) {
15685 m_os <<
"</" << m_tags.back() <<
">";
15687 m_os << std::flush;
15688 applyFormatting(fmt);
15693 XmlWriter& XmlWriter::writeAttribute( std::string
const& name, std::string
const& attribute ) {
15694 if( !name.empty() && !attribute.empty() )
15695 m_os <<
' ' << name <<
"=\"" << XmlEncode( attribute, XmlEncode::ForAttributes ) <<
'"';
15699 XmlWriter& XmlWriter::writeAttribute( std::string
const& name,
bool attribute ) {
15700 m_os <<
' ' << name <<
"=\"" << ( attribute ?
"true" :
"false" ) <<
'"';
15704 XmlWriter& XmlWriter::writeText( std::string
const& text, XmlFormatting fmt) {
15705 if( !text.empty() ){
15706 bool tagWasOpen = m_tagIsOpen;
15708 if (tagWasOpen && shouldIndent(fmt)) {
15711 m_os << XmlEncode( text );
15712 applyFormatting(fmt);
15717 XmlWriter& XmlWriter::writeComment( std::string
const& text, XmlFormatting fmt) {
15719 if (shouldIndent(fmt)) {
15722 m_os <<
"<!--" << text <<
"-->";
15723 applyFormatting(fmt);
15727 void XmlWriter::writeStylesheetRef( std::string
const& url ) {
15728 m_os <<
"<?xml-stylesheet type=\"text/xsl\" href=\"" << url <<
"\"?>\n";
15731 XmlWriter& XmlWriter::writeBlankLine() {
15737 void XmlWriter::ensureTagClosed() {
15738 if( m_tagIsOpen ) {
15739 m_os << '>
' << std::flush;
15740 newlineIfNecessary();
15741 m_tagIsOpen = false;
15745 void XmlWriter::applyFormatting(XmlFormatting fmt) {
15746 m_needsNewline = shouldNewline(fmt);
15749 void XmlWriter::writeDeclaration() {
15750 m_os << "<?xml version=\"1.0\" encoding=\"UTF-8\"?>\n";
15753 void XmlWriter::newlineIfNecessary() {
15754 if( m_needsNewline ) {
15756 m_needsNewline = false;
15760 // end catch_xmlwriter.cpp
15761 // start catch_reporter_bases.cpp
15770 void prepareExpandedExpression(AssertionResult& result) {
15771 result.getExpandedExpression();
15774 // Because formatting using c++ streams is stateful, drop down to C is required
15775 // Alternatively we could use stringstream, but its performance is... not good.
15776 std::string getFormattedDuration( double duration ) {
15777 // Max exponent + 1 is required to represent the whole part
15778 // + 1 for decimal point
15779 // + 3 for the 3 decimal places
15780 // + 1 for null terminator
15781 const std::size_t maxDoubleSize = DBL_MAX_10_EXP + 1 + 1 + 3 + 1;
15782 char buffer[maxDoubleSize];
15784 // Save previous errno, to prevent sprintf from overwriting it
15787 sprintf_s(buffer, "%.3f", duration);
15789 std::sprintf(buffer, "%.3f", duration);
15791 return std::string(buffer);
15794 bool shouldShowDuration( IConfig const& config, double duration ) {
15795 if ( config.showDurations() == ShowDurations::Always ) {
15798 if ( config.showDurations() == ShowDurations::Never ) {
15801 const double min = config.minDuration();
15802 return min >= 0 && duration >= min;
15805 std::string serializeFilters( std::vector<std::string> const& container ) {
15806 ReusableStringStream oss;
15808 for (auto&& filter : container)
15820 TestEventListenerBase::TestEventListenerBase(ReporterConfig const & _config)
15821 :StreamingReporterBase(_config) {}
15823 std::set<Verbosity> TestEventListenerBase::getSupportedVerbosities() {
15824 return { Verbosity::Quiet, Verbosity::Normal, Verbosity::High };
15827 void TestEventListenerBase::assertionStarting(AssertionInfo const &) {}
15829 bool TestEventListenerBase::assertionEnded(AssertionStats const &) {
15833 } // end namespace Catch
15834 // end catch_reporter_bases.cpp
15835 // start catch_reporter_compact.cpp
15839 #ifdef CATCH_PLATFORM_MAC
15840 const char* failedString() { return "FAILED"; }
15841 const char* passedString() { return "PASSED"; }
15843 const char* failedString() { return "failed"; }
15844 const char* passedString() { return "passed"; }
15847 // Colour::LightGrey
15848 Catch::Colour::Code dimColour() { return Catch::Colour::FileName; }
15850 std::string bothOrAll( std::size_t count ) {
15851 return count == 1 ? std::string() :
15852 count == 2 ? "both " : "all " ;
15855 } // anon namespace
15859 // Colour, message variants:
15860 // - white: No tests ran.
15861 // - red: Failed [both/all] N test cases, failed [both/all] M assertions.
15862 // - white: Passed [both/all] N test cases (no assertions).
15863 // - red: Failed N tests cases, failed M assertions.
15864 // - green: Passed [both/all] N tests cases with M assertions.
15865 void printTotals(std::ostream& out, const Totals& totals) {
15866 if (totals.testCases.total() == 0) {
15867 out << "No tests ran.";
15868 } else if (totals.testCases.failed == totals.testCases.total()) {
15869 Colour colour(Colour::ResultError);
15870 const std::string qualify_assertions_failed =
15871 totals.assertions.failed == totals.assertions.total() ?
15872 bothOrAll(totals.assertions.failed) : std::string();
15874 "Failed " << bothOrAll(totals.testCases.failed)
15875 << pluralise(totals.testCases.failed, "test case") << ", "
15876 "failed " << qualify_assertions_failed <<
15877 pluralise(totals.assertions.failed, "assertion") << '.
';
15878 } else if (totals.assertions.total() == 0) {
15880 "Passed " << bothOrAll(totals.testCases.total())
15881 << pluralise(totals.testCases.total(), "test case")
15882 << " (no assertions).";
15883 } else if (totals.assertions.failed) {
15884 Colour colour(Colour::ResultError);
15886 "Failed " << pluralise(totals.testCases.failed, "test case") << ", "
15887 "failed " << pluralise(totals.assertions.failed, "assertion") << '.
';
15889 Colour colour(Colour::ResultSuccess);
15891 "Passed " << bothOrAll(totals.testCases.passed)
15892 << pluralise(totals.testCases.passed, "test case") <<
15893 " with " << pluralise(totals.assertions.passed, "assertion") << '.
';
15897 // Implementation of CompactReporter formatting
15898 class AssertionPrinter {
15900 AssertionPrinter& operator= (AssertionPrinter const&) = delete;
15901 AssertionPrinter(AssertionPrinter const&) = delete;
15902 AssertionPrinter(std::ostream& _stream, AssertionStats const& _stats, bool _printInfoMessages)
15904 , result(_stats.assertionResult)
15905 , messages(_stats.infoMessages)
15906 , itMessage(_stats.infoMessages.begin())
15907 , printInfoMessages(_printInfoMessages) {}
15912 itMessage = messages.begin();
15914 switch (result.getResultType()) {
15915 case ResultWas::Ok:
15916 printResultType(Colour::ResultSuccess, passedString());
15917 printOriginalExpression();
15918 printReconstructedExpression();
15919 if (!result.hasExpression())
15920 printRemainingMessages(Colour::None);
15922 printRemainingMessages();
15924 case ResultWas::ExpressionFailed:
15926 printResultType(Colour::ResultSuccess, failedString() + std::string(" - but was ok"));
15928 printResultType(Colour::Error, failedString());
15929 printOriginalExpression();
15930 printReconstructedExpression();
15931 printRemainingMessages();
15933 case ResultWas::ThrewException:
15934 printResultType(Colour::Error, failedString());
15935 printIssue("unexpected exception with message:");
15937 printExpressionWas();
15938 printRemainingMessages();
15940 case ResultWas::FatalErrorCondition:
15941 printResultType(Colour::Error, failedString());
15942 printIssue("fatal error condition with message:");
15944 printExpressionWas();
15945 printRemainingMessages();
15947 case ResultWas::DidntThrowException:
15948 printResultType(Colour::Error, failedString());
15949 printIssue("expected exception, got none");
15950 printExpressionWas();
15951 printRemainingMessages();
15953 case ResultWas::Info:
15954 printResultType(Colour::None, "info");
15956 printRemainingMessages();
15958 case ResultWas::Warning:
15959 printResultType(Colour::None, "warning");
15961 printRemainingMessages();
15963 case ResultWas::ExplicitFailure:
15964 printResultType(Colour::Error, failedString());
15965 printIssue("explicitly");
15966 printRemainingMessages(Colour::None);
15968 // These cases are here to prevent compiler warnings
15969 case ResultWas::Unknown:
15970 case ResultWas::FailureBit:
15971 case ResultWas::Exception:
15972 printResultType(Colour::Error, "** internal error **");
15978 void printSourceInfo() const {
15979 Colour colourGuard(Colour::FileName);
15980 stream << result.getSourceInfo() << ':
';
15983 void printResultType(Colour::Code colour, std::string const& passOrFail) const {
15984 if (!passOrFail.empty()) {
15986 Colour colourGuard(colour);
15987 stream << ' ' << passOrFail;
15993 void printIssue(std::string const& issue) const {
15994 stream << ' ' << issue;
15997 void printExpressionWas() {
15998 if (result.hasExpression()) {
16001 Colour colour(dimColour());
16002 stream << " expression was:";
16004 printOriginalExpression();
16008 void printOriginalExpression() const {
16009 if (result.hasExpression()) {
16010 stream << ' ' << result.getExpression();
16014 void printReconstructedExpression() const {
16015 if (result.hasExpandedExpression()) {
16017 Colour colour(dimColour());
16018 stream << " for: ";
16020 stream << result.getExpandedExpression();
16024 void printMessage() {
16025 if (itMessage != messages.end()) {
16026 stream << " '" << itMessage->message << '\'';
16031 void printRemainingMessages(Colour::Code colour = dimColour()) {
16032 if (itMessage == messages.end())
16035 const auto itEnd = messages.cend();
16036 const auto N = static_cast<std::size_t>(std::distance(itMessage, itEnd));
16039 Colour colourGuard(colour);
16040 stream << " with
" << pluralise(N, "message
") << ':';
16043 while (itMessage != itEnd) {
16044 // If this assertion is a warning ignore any INFO messages
16045 if (printInfoMessages || itMessage->type != ResultWas::Info) {
16047 if (itMessage != itEnd) {
16048 Colour colourGuard(dimColour());
16058 std::ostream& stream;
16059 AssertionResult const& result;
16060 std::vector<MessageInfo> messages;
16061 std::vector<MessageInfo>::const_iterator itMessage;
16062 bool printInfoMessages;
16065 } // anon namespace
16067 std::string CompactReporter::getDescription() {
16068 return "Reports test results on a
single line, suitable
for IDEs
";
16071 void CompactReporter::noMatchingTestCases( std::string const& spec ) {
16072 stream << "No test cases matched
'" << spec << '\
'' << std::endl;
16075 void CompactReporter::assertionStarting( AssertionInfo
const& ) {}
16077 bool CompactReporter::assertionEnded( AssertionStats
const& _assertionStats ) {
16078 AssertionResult
const& result = _assertionStats.assertionResult;
16080 bool printInfoMessages =
true;
16083 if( !m_config->includeSuccessfulResults() && result.isOk() ) {
16086 printInfoMessages =
false;
16089 AssertionPrinter printer( stream, _assertionStats, printInfoMessages );
16092 stream << std::endl;
16096 void CompactReporter::sectionEnded(SectionStats
const& _sectionStats) {
16097 double dur = _sectionStats.durationInSeconds;
16098 if ( shouldShowDuration( *m_config, dur ) ) {
16099 stream << getFormattedDuration( dur ) <<
" s: " << _sectionStats.sectionInfo.name << std::endl;
16103 void CompactReporter::testRunEnded( TestRunStats
const& _testRunStats ) {
16104 printTotals( stream, _testRunStats.totals );
16105 stream <<
'\n' << std::endl;
16106 StreamingReporterBase::testRunEnded( _testRunStats );
16109 CompactReporter::~CompactReporter() {}
16111 CATCH_REGISTER_REPORTER(
"compact", CompactReporter )
16120 #if defined(_MSC_VER)
16121 #pragma warning(push)
16122 #pragma warning(disable:4061)
16126 #if defined(__clang__)
16127 # pragma clang diagnostic push
16129 # pragma clang diagnostic ignored "-Wunused-function"
16137 class ConsoleAssertionPrinter {
16139 ConsoleAssertionPrinter& operator= (ConsoleAssertionPrinter
const&) =
delete;
16140 ConsoleAssertionPrinter(ConsoleAssertionPrinter
const&) =
delete;
16141 ConsoleAssertionPrinter(std::ostream& _stream, AssertionStats
const& _stats,
bool _printInfoMessages)
16144 result(_stats.assertionResult),
16145 colour(Colour::None),
16146 message(result.getMessage()),
16147 messages(_stats.infoMessages),
16148 printInfoMessages(_printInfoMessages) {
16149 switch (result.getResultType()) {
16151 colour = Colour::Success;
16152 passOrFail =
"PASSED";
16154 if (_stats.infoMessages.size() == 1)
16155 messageLabel =
"with message";
16156 if (_stats.infoMessages.size() > 1)
16157 messageLabel =
"with messages";
16160 if (result.isOk()) {
16161 colour = Colour::Success;
16162 passOrFail =
"FAILED - but was ok";
16164 colour = Colour::Error;
16165 passOrFail =
"FAILED";
16167 if (_stats.infoMessages.size() == 1)
16168 messageLabel =
"with message";
16169 if (_stats.infoMessages.size() > 1)
16170 messageLabel =
"with messages";
16173 colour = Colour::Error;
16174 passOrFail =
"FAILED";
16175 messageLabel =
"due to unexpected exception with ";
16176 if (_stats.infoMessages.size() == 1)
16177 messageLabel += "message";
16178 if (_stats.infoMessages.size() > 1)
16179 messageLabel += "messages";
16182 colour = Colour::Error;
16183 passOrFail =
"FAILED";
16184 messageLabel =
"due to a fatal error condition";
16187 colour = Colour::Error;
16188 passOrFail =
"FAILED";
16189 messageLabel =
"because no exception was thrown where one was expected";
16192 messageLabel =
"info";
16195 messageLabel =
"warning";
16198 passOrFail =
"FAILED";
16199 colour = Colour::Error;
16200 if (_stats.infoMessages.size() == 1)
16201 messageLabel =
"explicitly with message";
16202 if (_stats.infoMessages.size() > 1)
16203 messageLabel =
"explicitly with messages";
16209 passOrFail =
"** internal error **";
16210 colour = Colour::Error;
16215 void print()
const {
16217 if (stats.totals.assertions.total() > 0) {
16219 printOriginalExpression();
16220 printReconstructedExpression();
16228 void printResultType()
const {
16229 if (!passOrFail.empty()) {
16230 Colour colourGuard(colour);
16231 stream << passOrFail <<
":\n";
16234 void printOriginalExpression()
const {
16235 if (result.hasExpression()) {
16236 Colour colourGuard(Colour::OriginalExpression);
16238 stream << result.getExpressionInMacro();
16242 void printReconstructedExpression()
const {
16243 if (result.hasExpandedExpression()) {
16244 stream <<
"with expansion:\n";
16245 Colour colourGuard(Colour::ReconstructedExpression);
16246 stream << Column(result.getExpandedExpression()).indent(2) <<
'\n';
16249 void printMessage()
const {
16250 if (!messageLabel.empty())
16251 stream << messageLabel <<
':' <<
'\n';
16252 for (
auto const&
msg : messages) {
16255 stream << Column(
msg.message).indent(2) <<
'\n';
16258 void printSourceInfo()
const {
16259 Colour colourGuard(Colour::FileName);
16260 stream << result.getSourceInfo() <<
": ";
16263 std::ostream& stream;
16264 AssertionStats
const& stats;
16265 AssertionResult
const& result;
16266 Colour::Code colour;
16267 std::string passOrFail;
16268 std::string messageLabel;
16269 std::string message;
16270 std::vector<MessageInfo> messages;
16271 bool printInfoMessages;
16274 std::size_t makeRatio(std::size_t number, std::size_t total) {
16275 std::size_t ratio = total > 0 ? CATCH_CONFIG_CONSOLE_WIDTH * number / total : 0;
16276 return (ratio == 0 && number > 0) ? 1 : ratio;
16279 std::size_t& findMax(std::size_t& i, std::size_t& j, std::size_t& k) {
16280 if (i > j && i > k)
16288 struct ColumnInfo {
16289 enum Justification { Left, Right };
16292 Justification justification;
16294 struct ColumnBreak {};
16295 struct RowBreak {};
16306 static const uint64_t s_nanosecondsInAMicrosecond = 1000;
16307 static const uint64_t s_nanosecondsInAMillisecond = 1000 * s_nanosecondsInAMicrosecond;
16308 static const uint64_t s_nanosecondsInASecond = 1000 * s_nanosecondsInAMillisecond;
16309 static const uint64_t s_nanosecondsInAMinute = 60 * s_nanosecondsInASecond;
16311 double m_inNanoseconds;
16315 explicit Duration(
double inNanoseconds, Unit units = Unit::Auto)
16316 : m_inNanoseconds(inNanoseconds),
16318 if (m_units == Unit::Auto) {
16319 if (m_inNanoseconds < s_nanosecondsInAMicrosecond)
16320 m_units = Unit::Nanoseconds;
16321 else if (m_inNanoseconds < s_nanosecondsInAMillisecond)
16322 m_units = Unit::Microseconds;
16323 else if (m_inNanoseconds < s_nanosecondsInASecond)
16324 m_units = Unit::Milliseconds;
16325 else if (m_inNanoseconds < s_nanosecondsInAMinute)
16326 m_units = Unit::Seconds;
16328 m_units = Unit::Minutes;
16333 auto value() const ->
double {
16335 case Unit::Microseconds:
16336 return m_inNanoseconds /
static_cast<double>(s_nanosecondsInAMicrosecond);
16337 case Unit::Milliseconds:
16338 return m_inNanoseconds /
static_cast<double>(s_nanosecondsInAMillisecond);
16339 case Unit::Seconds:
16340 return m_inNanoseconds /
static_cast<double>(s_nanosecondsInASecond);
16341 case Unit::Minutes:
16342 return m_inNanoseconds /
static_cast<double>(s_nanosecondsInAMinute);
16344 return m_inNanoseconds;
16347 auto unitsAsString() const -> std::
string {
16349 case Unit::Nanoseconds:
16351 case Unit::Microseconds:
16353 case Unit::Milliseconds:
16355 case Unit::Seconds:
16357 case Unit::Minutes:
16360 return "** internal error **";
16364 friend auto operator << (std::ostream& os, Duration
const& duration) -> std::ostream& {
16365 return os << duration.value() <<
' ' << duration.unitsAsString();
16370 class TablePrinter {
16371 std::ostream& m_os;
16372 std::vector<ColumnInfo> m_columnInfos;
16373 std::ostringstream m_oss;
16374 int m_currentColumn = -1;
16375 bool m_isOpen =
false;
16378 TablePrinter( std::ostream& os, std::vector<ColumnInfo> columnInfos )
16380 m_columnInfos( std::move( columnInfos ) ) {}
16382 auto columnInfos() const -> std::vector<ColumnInfo> const& {
16383 return m_columnInfos;
16389 *
this << RowBreak();
16391 Columns headerCols;
16393 for (
auto const& info : m_columnInfos) {
16395 headerCols += spacer;
16397 m_os << headerCols <<
'\n';
16399 m_os << Catch::getLineOfChars<
'-'>() <<
'\n';
16404 *
this << RowBreak();
16410 template<
typename T>
16416 friend TablePrinter&
operator << (TablePrinter& tp, ColumnBreak) {
16417 auto colStr = tp.m_oss.str();
16418 const auto strSize = colStr.size();
16421 if (tp.m_currentColumn ==
static_cast<int>(tp.m_columnInfos.size() - 1)) {
16422 tp.m_currentColumn = -1;
16425 tp.m_currentColumn++;
16427 auto colInfo = tp.m_columnInfos[tp.m_currentColumn];
16428 auto padding = (strSize + 1 < static_cast<std::size_t>(colInfo.
width))
16429 ? std::string(colInfo.
width - (strSize + 1), ' ')
16431 if (colInfo.justification == ColumnInfo::Left)
16432 tp.m_os << colStr << padding <<
' ';
16434 tp.m_os << padding << colStr <<
' ';
16438 friend TablePrinter&
operator << (TablePrinter& tp, RowBreak) {
16439 if (tp.m_currentColumn > 0) {
16441 tp.m_currentColumn = -1;
16447 ConsoleReporter::ConsoleReporter(ReporterConfig
const& config)
16448 : StreamingReporterBase(config),
16449 m_tablePrinter(new TablePrinter(config.stream(),
16450 [&config]() -> std::vector<ColumnInfo> {
16451 if (config.fullConfig()->benchmarkNoAnalysis())
16454 {
"benchmark name", CATCH_CONFIG_CONSOLE_WIDTH - 43, ColumnInfo::Left },
16455 {
" samples", 14, ColumnInfo::Right },
16456 {
" iterations", 14, ColumnInfo::Right },
16457 {
" mean", 14, ColumnInfo::Right }
16463 {
"benchmark name", CATCH_CONFIG_CONSOLE_WIDTH - 43, ColumnInfo::Left },
16464 {
"samples mean std dev", 14, ColumnInfo::Right },
16465 {
"iterations low mean low std dev", 14, ColumnInfo::Right },
16466 {
"estimated high mean high std dev", 14, ColumnInfo::Right }
16470 ConsoleReporter::~ConsoleReporter() =
default;
16472 std::string ConsoleReporter::getDescription() {
16473 return "Reports test results as plain lines of text";
16476 void ConsoleReporter::noMatchingTestCases(std::string
const& spec) {
16477 stream <<
"No test cases matched '" << spec <<
'\'' << std::endl;
16480 void ConsoleReporter::reportInvalidArguments(std::string
const&arg){
16481 stream <<
"Invalid Filter: " << arg << std::endl;
16484 void ConsoleReporter::assertionStarting(AssertionInfo
const&) {}
16486 bool ConsoleReporter::assertionEnded(AssertionStats
const& _assertionStats) {
16487 AssertionResult
const& result = _assertionStats.assertionResult;
16489 bool includeResults = m_config->includeSuccessfulResults() || !result.isOk();
16497 ConsoleAssertionPrinter printer(stream, _assertionStats, includeResults);
16499 stream << std::endl;
16503 void ConsoleReporter::sectionStarting(SectionInfo
const& _sectionInfo) {
16504 m_tablePrinter->close();
16505 m_headerPrinted =
false;
16506 StreamingReporterBase::sectionStarting(_sectionInfo);
16508 void ConsoleReporter::sectionEnded(SectionStats
const& _sectionStats) {
16509 m_tablePrinter->close();
16510 if (_sectionStats.missingAssertions) {
16512 Colour colour(Colour::ResultError);
16513 if (m_sectionStack.size() > 1)
16514 stream <<
"\nNo assertions in section";
16516 stream <<
"\nNo assertions in test case";
16517 stream <<
" '" << _sectionStats.sectionInfo.name <<
"'\n" << std::endl;
16519 double dur = _sectionStats.durationInSeconds;
16520 if (shouldShowDuration(*m_config, dur)) {
16521 stream << getFormattedDuration(dur) <<
" s: " << _sectionStats.sectionInfo.name << std::endl;
16523 if (m_headerPrinted) {
16524 m_headerPrinted =
false;
16526 StreamingReporterBase::sectionEnded(_sectionStats);
16529 #if defined(CATCH_CONFIG_ENABLE_BENCHMARKING)
16530 void ConsoleReporter::benchmarkPreparing(std::string
const& name) {
16531 lazyPrintWithoutClosingBenchmarkTable();
16533 auto nameCol = Column(name).width(
static_cast<std::size_t
>(m_tablePrinter->columnInfos()[0].width - 2));
16535 bool firstLine =
true;
16536 for (
auto line : nameCol) {
16538 (*m_tablePrinter) << ColumnBreak() << ColumnBreak() << ColumnBreak();
16542 (*m_tablePrinter) << line << ColumnBreak();
16546 void ConsoleReporter::benchmarkStarting(BenchmarkInfo
const& info) {
16547 (*m_tablePrinter) <<
info.samples << ColumnBreak()
16548 <<
info.iterations << ColumnBreak();
16549 if (!m_config->benchmarkNoAnalysis())
16550 (*m_tablePrinter) << Duration(
info.estimatedDuration) << ColumnBreak();
16552 void ConsoleReporter::benchmarkEnded(BenchmarkStats<>
const& stats) {
16553 if (m_config->benchmarkNoAnalysis())
16555 (*m_tablePrinter) << Duration(stats.mean.point.count()) << ColumnBreak();
16559 (*m_tablePrinter) << ColumnBreak()
16560 << Duration(stats.mean.point.count()) << ColumnBreak()
16561 << Duration(stats.mean.lower_bound.count()) << ColumnBreak()
16562 << Duration(stats.mean.upper_bound.count()) << ColumnBreak() << ColumnBreak()
16563 << Duration(stats.standardDeviation.point.count()) << ColumnBreak()
16564 << Duration(stats.standardDeviation.lower_bound.count()) << ColumnBreak()
16565 << Duration(stats.standardDeviation.upper_bound.count()) << ColumnBreak() << ColumnBreak() << ColumnBreak() << ColumnBreak() << ColumnBreak();
16569 void ConsoleReporter::benchmarkFailed(std::string
const& error) {
16570 Colour colour(Colour::Red);
16572 <<
"Benchmark failed (" << error <<
')'
16573 << ColumnBreak() << RowBreak();
16577 void ConsoleReporter::testCaseEnded(TestCaseStats
const& _testCaseStats) {
16578 m_tablePrinter->close();
16579 StreamingReporterBase::testCaseEnded(_testCaseStats);
16580 m_headerPrinted =
false;
16582 void ConsoleReporter::testGroupEnded(TestGroupStats
const& _testGroupStats) {
16583 if (currentGroupInfo.used) {
16584 printSummaryDivider();
16585 stream <<
"Summary for group '" << _testGroupStats.groupInfo.name <<
"':\n";
16586 printTotals(_testGroupStats.totals);
16587 stream <<
'\n' << std::endl;
16589 StreamingReporterBase::testGroupEnded(_testGroupStats);
16591 void ConsoleReporter::testRunEnded(TestRunStats
const& _testRunStats) {
16592 printTotalsDivider(_testRunStats.totals);
16593 printTotals(_testRunStats.totals);
16594 stream << std::endl;
16595 StreamingReporterBase::testRunEnded(_testRunStats);
16597 void ConsoleReporter::testRunStarting(TestRunInfo
const& _testInfo) {
16598 StreamingReporterBase::testRunStarting(_testInfo);
16599 printTestFilters();
16602 void ConsoleReporter::lazyPrint() {
16604 m_tablePrinter->close();
16605 lazyPrintWithoutClosingBenchmarkTable();
16608 void ConsoleReporter::lazyPrintWithoutClosingBenchmarkTable() {
16610 if (!currentTestRunInfo.used)
16611 lazyPrintRunInfo();
16612 if (!currentGroupInfo.used)
16613 lazyPrintGroupInfo();
16615 if (!m_headerPrinted) {
16616 printTestCaseAndSectionHeader();
16617 m_headerPrinted =
true;
16620 void ConsoleReporter::lazyPrintRunInfo() {
16621 stream << '\n' << getLineOfChars<'~'>() <<
'\n';
16622 Colour colour(Colour::SecondaryText);
16623 stream << currentTestRunInfo->name
16624 <<
" is a Catch v" << libraryVersion() <<
" host application.\n"
16625 <<
"Run with -? for options\n\n";
16627 if (m_config->rngSeed() != 0)
16628 stream <<
"Randomness seeded to: " << m_config->rngSeed() <<
"\n\n";
16630 currentTestRunInfo.used =
true;
16632 void ConsoleReporter::lazyPrintGroupInfo() {
16633 if (!currentGroupInfo->name.empty() && currentGroupInfo->groupsCounts > 1) {
16634 printClosedHeader(
"Group: " + currentGroupInfo->name);
16635 currentGroupInfo.used =
true;
16638 void ConsoleReporter::printTestCaseAndSectionHeader() {
16639 assert(!m_sectionStack.empty());
16640 printOpenHeader(currentTestCaseInfo->name);
16642 if (m_sectionStack.size() > 1) {
16643 Colour colourGuard(Colour::Headers);
16646 it = m_sectionStack.begin() + 1,
16647 itEnd = m_sectionStack.end();
16648 for (;
it != itEnd; ++
it)
16649 printHeaderString(
it->name, 2);
16652 SourceLineInfo lineInfo = m_sectionStack.back().lineInfo;
16654 stream << getLineOfChars<
'-'>() <<
'\n';
16655 Colour colourGuard(Colour::FileName);
16656 stream << lineInfo <<
'\n';
16657 stream << getLineOfChars<
'.'>() <<
'\n' << std::endl;
16660 void ConsoleReporter::printClosedHeader(std::string
const& _name) {
16661 printOpenHeader(_name);
16662 stream << getLineOfChars<
'.'>() <<
'\n';
16664 void ConsoleReporter::printOpenHeader(std::string
const& _name) {
16665 stream << getLineOfChars<
'-'>() <<
'\n';
16667 Colour colourGuard(Colour::Headers);
16668 printHeaderString(_name);
16674 void ConsoleReporter::printHeaderString(std::string
const& _string, std::size_t indent) {
16675 std::size_t i = _string.find(
": ");
16676 if (i != std::string::npos)
16680 stream << Column(_string).indent(indent + i).initialIndent(indent) <<
'\n';
16683 struct SummaryColumn {
16685 SummaryColumn( std::string _label, Colour::Code _colour )
16686 : label( std::move( _label ) ),
16687 colour( _colour ) {}
16688 SummaryColumn addRow( std::size_t count ) {
16689 ReusableStringStream rss;
16691 std::string row = rss.str();
16692 for (
auto& oldRow : rows) {
16693 while (oldRow.size() < row.size())
16694 oldRow =
' ' + oldRow;
16695 while (oldRow.size() > row.size())
16698 rows.push_back(row);
16703 Colour::Code colour;
16704 std::vector<std::string> rows;
16708 void ConsoleReporter::printTotals( Totals
const& totals ) {
16709 if (totals.testCases.total() == 0) {
16710 stream << Colour(Colour::Warning) <<
"No tests ran\n";
16711 }
else if (totals.assertions.total() > 0 && totals.testCases.allPassed()) {
16712 stream << Colour(Colour::ResultSuccess) <<
"All tests passed";
16714 << pluralise(totals.assertions.passed,
"assertion") <<
" in "
16715 << pluralise(totals.testCases.passed,
"test case") <<
')'
16719 std::vector<SummaryColumn> columns;
16720 columns.push_back(SummaryColumn(
"", Colour::None)
16721 .addRow(totals.testCases.total())
16722 .addRow(totals.assertions.total()));
16723 columns.push_back(SummaryColumn(
"passed", Colour::Success)
16724 .addRow(totals.testCases.passed)
16725 .addRow(totals.assertions.passed));
16726 columns.push_back(SummaryColumn(
"failed", Colour::ResultError)
16727 .addRow(totals.testCases.failed)
16728 .addRow(totals.assertions.failed));
16729 columns.push_back(SummaryColumn(
"failed as expected", Colour::ResultExpectedFailure)
16730 .addRow(totals.testCases.failedButOk)
16731 .addRow(totals.assertions.failedButOk));
16733 printSummaryRow(
"test cases", columns, 0);
16734 printSummaryRow(
"assertions", columns, 1);
16737 void ConsoleReporter::printSummaryRow(std::string
const& label, std::vector<SummaryColumn>
const& cols, std::size_t row) {
16738 for (
auto col : cols) {
16739 std::string
value = col.rows[row];
16740 if (col.label.empty()) {
16741 stream << label <<
": ";
16745 stream << Colour(Colour::Warning) <<
"- none -";
16746 }
else if (
value !=
"0") {
16747 stream << Colour(Colour::LightGrey) <<
" | ";
16748 stream << Colour(col.colour)
16749 <<
value <<
' ' << col.label;
16755 void ConsoleReporter::printTotalsDivider(Totals
const& totals) {
16756 if (totals.testCases.total() > 0) {
16757 std::size_t failedRatio = makeRatio(totals.testCases.failed, totals.testCases.total());
16758 std::size_t failedButOkRatio = makeRatio(totals.testCases.failedButOk, totals.testCases.total());
16759 std::size_t passedRatio = makeRatio(totals.testCases.passed, totals.testCases.total());
16760 while (failedRatio + failedButOkRatio + passedRatio < CATCH_CONFIG_CONSOLE_WIDTH - 1)
16761 findMax(failedRatio, failedButOkRatio, passedRatio)++;
16762 while (failedRatio + failedButOkRatio + passedRatio > CATCH_CONFIG_CONSOLE_WIDTH - 1)
16763 findMax(failedRatio, failedButOkRatio, passedRatio)--;
16765 stream << Colour(Colour::Error) << std::string(failedRatio,
'=');
16766 stream << Colour(Colour::ResultExpectedFailure) << std::string(failedButOkRatio,
'=');
16767 if (totals.testCases.allPassed())
16768 stream << Colour(Colour::ResultSuccess) << std::string(passedRatio,
'=');
16770 stream << Colour(Colour::Success) << std::string(passedRatio,
'=');
16772 stream << Colour(Colour::Warning) << std::string(CATCH_CONFIG_CONSOLE_WIDTH - 1,
'=');
16776 void ConsoleReporter::printSummaryDivider() {
16777 stream << getLineOfChars<
'-'>() <<
'\n';
16780 void ConsoleReporter::printTestFilters() {
16781 if (m_config->testSpec().hasFilters()) {
16782 Colour guard(Colour::BrightYellow);
16783 stream <<
"Filters: " << serializeFilters(m_config->getTestsOrTags()) <<
'\n';
16787 CATCH_REGISTER_REPORTER(
"console", ConsoleReporter)
16791 #if defined(_MSC_VER)
16792 #pragma warning(pop)
16795 #if defined(__clang__)
16796 # pragma clang diagnostic pop
16804 #include <algorithm>
16810 std::string getCurrentTimestamp() {
16814 std::time(&rawtime);
16815 auto const timeStampSize =
sizeof(
"2017-01-16T17:06:45Z");
16818 std::tm timeInfo = {};
16819 gmtime_s(&timeInfo, &rawtime);
16822 timeInfo = std::gmtime(&rawtime);
16825 char timeStamp[timeStampSize];
16826 const char *
const fmt =
"%Y-%m-%dT%H:%M:%SZ";
16829 std::strftime(timeStamp, timeStampSize, fmt, &timeInfo);
16831 std::strftime(timeStamp, timeStampSize, fmt, timeInfo);
16833 return std::string(timeStamp, timeStampSize-1);
16836 std::string fileNameTag(
const std::vector<std::string> &tags) {
16837 auto it = std::find_if(begin(tags),
16839 [] (std::string
const& tag) {
return tag.front() ==
'#'; });
16840 if (
it != tags.end())
16841 return it->substr(1);
16842 return std::string();
16849 std::string formatDuration(
double seconds ) {
16850 ReusableStringStream rss;
16851 rss << std::fixed << std::setprecision( 3 ) << seconds;
16857 JunitReporter::JunitReporter( ReporterConfig
const& _config )
16858 : CumulativeReporterBase( _config ),
16859 xml( _config.stream() )
16861 m_reporterPrefs.shouldRedirectStdOut =
true;
16862 m_reporterPrefs.shouldReportAllAssertions =
true;
16865 JunitReporter::~JunitReporter() {}
16867 std::string JunitReporter::getDescription() {
16868 return "Reports test results in an XML format that looks like Ant's junitreport target";
16871 void JunitReporter::noMatchingTestCases( std::string
const& ) {}
16873 void JunitReporter::testRunStarting( TestRunInfo
const& runInfo ) {
16874 CumulativeReporterBase::testRunStarting( runInfo );
16875 xml.startElement(
"testsuites" );
16878 void JunitReporter::testGroupStarting( GroupInfo
const& groupInfo ) {
16879 suiteTimer.start();
16880 stdOutForSuite.clear();
16881 stdErrForSuite.clear();
16882 unexpectedExceptions = 0;
16883 CumulativeReporterBase::testGroupStarting( groupInfo );
16886 void JunitReporter::testCaseStarting( TestCaseInfo
const& testCaseInfo ) {
16887 m_okToFail = testCaseInfo.okToFail();
16890 bool JunitReporter::assertionEnded( AssertionStats
const& assertionStats ) {
16892 unexpectedExceptions++;
16893 return CumulativeReporterBase::assertionEnded( assertionStats );
16896 void JunitReporter::testCaseEnded( TestCaseStats
const& testCaseStats ) {
16897 stdOutForSuite += testCaseStats.stdOut;
16898 stdErrForSuite += testCaseStats.stdErr;
16899 CumulativeReporterBase::testCaseEnded( testCaseStats );
16902 void JunitReporter::testGroupEnded( TestGroupStats
const& testGroupStats ) {
16903 double suiteTime = suiteTimer.getElapsedSeconds();
16904 CumulativeReporterBase::testGroupEnded( testGroupStats );
16905 writeGroup( *m_testGroups.back(), suiteTime );
16908 void JunitReporter::testRunEndedCumulative() {
16912 void JunitReporter::writeGroup( TestGroupNode
const& groupNode,
double suiteTime ) {
16913 XmlWriter::ScopedElement e = xml.scopedElement(
"testsuite" );
16915 TestGroupStats
const& stats = groupNode.value;
16916 xml.writeAttribute(
"name", stats.groupInfo.name );
16917 xml.writeAttribute(
"errors", unexpectedExceptions );
16918 xml.writeAttribute(
"failures", stats.totals.assertions.failed-unexpectedExceptions );
16919 xml.writeAttribute(
"tests", stats.totals.assertions.total() );
16920 xml.writeAttribute(
"hostname",
"tbd" );
16922 xml.writeAttribute(
"time",
"" );
16924 xml.writeAttribute(
"time", formatDuration( suiteTime ) );
16925 xml.writeAttribute(
"timestamp", getCurrentTimestamp() );
16928 if (m_config->hasTestFilters() || m_config->rngSeed() != 0) {
16929 auto properties = xml.scopedElement(
"properties");
16930 if (m_config->hasTestFilters()) {
16931 xml.scopedElement(
"property")
16932 .writeAttribute(
"name",
"filters")
16933 .writeAttribute(
"value", serializeFilters(m_config->getTestsOrTags()));
16935 if (m_config->rngSeed() != 0) {
16936 xml.scopedElement(
"property")
16937 .writeAttribute(
"name",
"random-seed")
16938 .writeAttribute(
"value", m_config->rngSeed());
16943 for(
auto const& child : groupNode.children )
16944 writeTestCase( *child );
16946 xml.scopedElement(
"system-out" ).writeText(
trim( stdOutForSuite ), XmlFormatting::Newline );
16947 xml.scopedElement(
"system-err" ).writeText(
trim( stdErrForSuite ), XmlFormatting::Newline );
16950 void JunitReporter::writeTestCase( TestCaseNode
const& testCaseNode ) {
16951 TestCaseStats
const& stats = testCaseNode.value;
16955 assert( testCaseNode.children.size() == 1 );
16956 SectionNode
const& rootSection = *testCaseNode.children.front();
16958 std::string className = stats.testInfo.className;
16960 if( className.empty() ) {
16961 className = fileNameTag(stats.testInfo.tags);
16962 if ( className.empty() )
16963 className =
"global";
16966 if ( !m_config->name().empty() )
16967 className = m_config->name() + "." + className;
16969 writeSection( className,
"", rootSection, stats.testInfo.okToFail() );
16972 void JunitReporter::writeSection( std::string
const& className,
16973 std::string
const& rootName,
16974 SectionNode
const& sectionNode,
16975 bool testOkToFail) {
16976 std::string name =
trim( sectionNode.stats.sectionInfo.name );
16977 if( !rootName.empty() )
16978 name = rootName + '/' + name;
16980 if( !sectionNode.assertions.empty() ||
16981 !sectionNode.stdOut.empty() ||
16982 !sectionNode.stdErr.empty() ) {
16983 XmlWriter::ScopedElement e = xml.scopedElement(
"testcase" );
16984 if( className.empty() ) {
16985 xml.writeAttribute(
"classname", name );
16986 xml.writeAttribute(
"name",
"root" );
16989 xml.writeAttribute(
"classname", className );
16990 xml.writeAttribute(
"name", name );
16992 xml.writeAttribute(
"time", formatDuration( sectionNode.stats.durationInSeconds ) );
16997 xml.writeAttribute(
"status",
"run" );
16999 if (sectionNode.stats.assertions.failedButOk) {
17000 xml.scopedElement(
"skipped")
17001 .writeAttribute(
"message",
"TEST_CASE tagged with !mayfail");
17004 writeAssertions( sectionNode );
17006 if( !sectionNode.stdOut.empty() )
17007 xml.scopedElement(
"system-out" ).writeText(
trim( sectionNode.stdOut ), XmlFormatting::Newline );
17008 if( !sectionNode.stdErr.empty() )
17009 xml.scopedElement(
"system-err" ).writeText(
trim( sectionNode.stdErr ), XmlFormatting::Newline );
17011 for(
auto const& childNode : sectionNode.childSections )
17012 if( className.empty() )
17013 writeSection( name,
"", *childNode, testOkToFail );
17015 writeSection( className, name, *childNode, testOkToFail );
17018 void JunitReporter::writeAssertions( SectionNode
const& sectionNode ) {
17019 for(
auto const& assertion : sectionNode.assertions )
17020 writeAssertion( assertion );
17023 void JunitReporter::writeAssertion( AssertionStats
const& stats ) {
17024 AssertionResult
const& result = stats.assertionResult;
17025 if( !result.isOk() ) {
17026 std::string elementName;
17027 switch( result.getResultType() ) {
17030 elementName =
"error";
17035 elementName =
"failure";
17045 elementName =
"internalError";
17049 XmlWriter::ScopedElement e = xml.scopedElement( elementName );
17051 xml.writeAttribute(
"message", result.getExpression() );
17052 xml.writeAttribute(
"type", result.getTestMacroName() );
17054 ReusableStringStream rss;
17055 if (stats.totals.assertions.total() > 0) {
17056 rss <<
"FAILED" <<
":\n";
17057 if (result.hasExpression()) {
17059 rss << result.getExpressionInMacro();
17062 if (result.hasExpandedExpression()) {
17063 rss <<
"with expansion:\n";
17064 rss << Column(result.getExpandedExpression()).indent(2) <<
'\n';
17070 if( !result.getMessage().empty() )
17071 rss << result.getMessage() <<
'\n';
17072 for(
auto const&
msg : stats.infoMessages )
17074 rss <<
msg.message <<
'\n';
17076 rss <<
"at " << result.getSourceInfo();
17077 xml.writeText( rss.str(), XmlFormatting::Newline );
17081 CATCH_REGISTER_REPORTER(
"junit", JunitReporter )
17091 ListeningReporter::ListeningReporter() {
17093 m_preferences.shouldReportAllAssertions =
true;
17096 void ListeningReporter::addListener( IStreamingReporterPtr&& listener ) {
17097 m_listeners.push_back( std::move( listener ) );
17100 void ListeningReporter::addReporter(IStreamingReporterPtr&& reporter) {
17101 assert(!m_reporter &&
"Listening reporter can wrap only 1 real reporter");
17102 m_reporter = std::move( reporter );
17103 m_preferences.shouldRedirectStdOut = m_reporter->getPreferences().shouldRedirectStdOut;
17106 ReporterPreferences ListeningReporter::getPreferences()
const {
17107 return m_preferences;
17110 std::set<Verbosity> ListeningReporter::getSupportedVerbosities() {
17111 return std::set<Verbosity>{ };
17114 void ListeningReporter::noMatchingTestCases( std::string
const& spec ) {
17115 for (
auto const& listener : m_listeners ) {
17116 listener->noMatchingTestCases( spec );
17118 m_reporter->noMatchingTestCases( spec );
17121 void ListeningReporter::reportInvalidArguments(std::string
const&arg){
17122 for (
auto const& listener : m_listeners ) {
17123 listener->reportInvalidArguments( arg );
17125 m_reporter->reportInvalidArguments( arg );
17128 #if defined(CATCH_CONFIG_ENABLE_BENCHMARKING)
17129 void ListeningReporter::benchmarkPreparing( std::string
const& name ) {
17130 for (
auto const& listener : m_listeners) {
17131 listener->benchmarkPreparing(name);
17133 m_reporter->benchmarkPreparing(name);
17135 void ListeningReporter::benchmarkStarting( BenchmarkInfo
const& benchmarkInfo ) {
17136 for (
auto const& listener : m_listeners ) {
17137 listener->benchmarkStarting( benchmarkInfo );
17139 m_reporter->benchmarkStarting( benchmarkInfo );
17141 void ListeningReporter::benchmarkEnded( BenchmarkStats<>
const& benchmarkStats ) {
17142 for (
auto const& listener : m_listeners ) {
17143 listener->benchmarkEnded( benchmarkStats );
17145 m_reporter->benchmarkEnded( benchmarkStats );
17148 void ListeningReporter::benchmarkFailed( std::string
const& error ) {
17149 for (
auto const& listener : m_listeners) {
17150 listener->benchmarkFailed(error);
17152 m_reporter->benchmarkFailed(error);
17156 void ListeningReporter::testRunStarting( TestRunInfo
const& testRunInfo ) {
17157 for (
auto const& listener : m_listeners ) {
17158 listener->testRunStarting( testRunInfo );
17160 m_reporter->testRunStarting( testRunInfo );
17163 void ListeningReporter::testGroupStarting( GroupInfo
const& groupInfo ) {
17164 for (
auto const& listener : m_listeners ) {
17165 listener->testGroupStarting( groupInfo );
17167 m_reporter->testGroupStarting( groupInfo );
17170 void ListeningReporter::testCaseStarting( TestCaseInfo
const& testInfo ) {
17171 for (
auto const& listener : m_listeners ) {
17172 listener->testCaseStarting( testInfo );
17174 m_reporter->testCaseStarting( testInfo );
17177 void ListeningReporter::sectionStarting( SectionInfo
const& sectionInfo ) {
17178 for (
auto const& listener : m_listeners ) {
17179 listener->sectionStarting( sectionInfo );
17181 m_reporter->sectionStarting( sectionInfo );
17184 void ListeningReporter::assertionStarting( AssertionInfo
const& assertionInfo ) {
17185 for (
auto const& listener : m_listeners ) {
17186 listener->assertionStarting( assertionInfo );
17188 m_reporter->assertionStarting( assertionInfo );
17192 bool ListeningReporter::assertionEnded( AssertionStats
const& assertionStats ) {
17193 for(
auto const& listener : m_listeners ) {
17194 static_cast<void>( listener->assertionEnded( assertionStats ) );
17196 return m_reporter->assertionEnded( assertionStats );
17199 void ListeningReporter::sectionEnded( SectionStats
const& sectionStats ) {
17200 for (
auto const& listener : m_listeners ) {
17201 listener->sectionEnded( sectionStats );
17203 m_reporter->sectionEnded( sectionStats );
17206 void ListeningReporter::testCaseEnded( TestCaseStats
const& testCaseStats ) {
17207 for (
auto const& listener : m_listeners ) {
17208 listener->testCaseEnded( testCaseStats );
17210 m_reporter->testCaseEnded( testCaseStats );
17213 void ListeningReporter::testGroupEnded( TestGroupStats
const& testGroupStats ) {
17214 for (
auto const& listener : m_listeners ) {
17215 listener->testGroupEnded( testGroupStats );
17217 m_reporter->testGroupEnded( testGroupStats );
17220 void ListeningReporter::testRunEnded( TestRunStats
const& testRunStats ) {
17221 for (
auto const& listener : m_listeners ) {
17222 listener->testRunEnded( testRunStats );
17224 m_reporter->testRunEnded( testRunStats );
17227 void ListeningReporter::skipTest( TestCaseInfo
const& testInfo ) {
17228 for (
auto const& listener : m_listeners ) {
17229 listener->skipTest( testInfo );
17231 m_reporter->skipTest( testInfo );
17234 bool ListeningReporter::isMulti()
const {
17242 #if defined(_MSC_VER)
17243 #pragma warning(push)
17244 #pragma warning(disable:4061)
17250 XmlReporter::XmlReporter( ReporterConfig
const& _config )
17251 : StreamingReporterBase( _config ),
17252 m_xml(_config.stream())
17254 m_reporterPrefs.shouldRedirectStdOut =
true;
17255 m_reporterPrefs.shouldReportAllAssertions =
true;
17258 XmlReporter::~XmlReporter() =
default;
17260 std::string XmlReporter::getDescription() {
17261 return "Reports test results as an XML document";
17264 std::string XmlReporter::getStylesheetRef()
const {
17265 return std::string();
17268 void XmlReporter::writeSourceInfo( SourceLineInfo
const& sourceInfo ) {
17270 .writeAttribute(
"filename", sourceInfo.file )
17271 .writeAttribute(
"line", sourceInfo.line );
17274 void XmlReporter::noMatchingTestCases( std::string
const& s ) {
17275 StreamingReporterBase::noMatchingTestCases( s );
17278 void XmlReporter::testRunStarting( TestRunInfo
const& testInfo ) {
17279 StreamingReporterBase::testRunStarting( testInfo );
17280 std::string stylesheetRef = getStylesheetRef();
17281 if( !stylesheetRef.empty() )
17282 m_xml.writeStylesheetRef( stylesheetRef );
17283 m_xml.startElement(
"Catch" );
17284 if( !m_config->name().empty() )
17285 m_xml.writeAttribute(
"name", m_config->name() );
17286 if (m_config->testSpec().hasFilters())
17287 m_xml.writeAttribute(
"filters", serializeFilters( m_config->getTestsOrTags() ) );
17288 if( m_config->rngSeed() != 0 )
17289 m_xml.scopedElement(
"Randomness" )
17290 .writeAttribute(
"seed", m_config->rngSeed() );
17293 void XmlReporter::testGroupStarting( GroupInfo
const& groupInfo ) {
17294 StreamingReporterBase::testGroupStarting( groupInfo );
17295 m_xml.startElement(
"Group" )
17296 .writeAttribute(
"name", groupInfo.name );
17299 void XmlReporter::testCaseStarting( TestCaseInfo
const& testInfo ) {
17300 StreamingReporterBase::testCaseStarting(testInfo);
17301 m_xml.startElement(
"TestCase" )
17302 .writeAttribute(
"name",
trim( testInfo.name ) )
17303 .writeAttribute(
"description", testInfo.description )
17304 .writeAttribute(
"tags", testInfo.tagsAsString() );
17306 writeSourceInfo( testInfo.lineInfo );
17309 m_testCaseTimer.start();
17310 m_xml.ensureTagClosed();
17313 void XmlReporter::sectionStarting( SectionInfo
const& sectionInfo ) {
17314 StreamingReporterBase::sectionStarting( sectionInfo );
17315 if( m_sectionDepth++ > 0 ) {
17316 m_xml.startElement(
"Section" )
17317 .writeAttribute(
"name",
trim( sectionInfo.name ) );
17318 writeSourceInfo( sectionInfo.lineInfo );
17319 m_xml.ensureTagClosed();
17323 void XmlReporter::assertionStarting( AssertionInfo
const& ) { }
17325 bool XmlReporter::assertionEnded( AssertionStats
const& assertionStats ) {
17327 AssertionResult
const& result = assertionStats.assertionResult;
17329 bool includeResults = m_config->includeSuccessfulResults() || !result.isOk();
17333 for(
auto const&
msg : assertionStats.infoMessages ) {
17335 m_xml.scopedElement(
"Info" )
17336 .writeText(
msg.message );
17338 m_xml.scopedElement(
"Warning" )
17339 .writeText(
msg.message );
17349 if( result.hasExpression() ) {
17350 m_xml.startElement(
"Expression" )
17351 .writeAttribute(
"success", result.succeeded() )
17352 .writeAttribute(
"type", result.getTestMacroName() );
17354 writeSourceInfo( result.getSourceInfo() );
17356 m_xml.scopedElement(
"Original" )
17357 .writeText( result.getExpression() );
17358 m_xml.scopedElement(
"Expanded" )
17359 .writeText( result.getExpandedExpression() );
17363 switch( result.getResultType() ) {
17365 m_xml.startElement(
"Exception" );
17366 writeSourceInfo( result.getSourceInfo() );
17367 m_xml.writeText( result.getMessage() );
17368 m_xml.endElement();
17371 m_xml.startElement(
"FatalErrorCondition" );
17372 writeSourceInfo( result.getSourceInfo() );
17373 m_xml.writeText( result.getMessage() );
17374 m_xml.endElement();
17377 m_xml.scopedElement(
"Info" )
17378 .writeText( result.getMessage() );
17384 m_xml.startElement(
"Failure" );
17385 writeSourceInfo( result.getSourceInfo() );
17386 m_xml.writeText( result.getMessage() );
17387 m_xml.endElement();
17393 if( result.hasExpression() )
17394 m_xml.endElement();
17399 void XmlReporter::sectionEnded( SectionStats
const& sectionStats ) {
17400 StreamingReporterBase::sectionEnded( sectionStats );
17401 if( --m_sectionDepth > 0 ) {
17402 XmlWriter::ScopedElement e = m_xml.scopedElement(
"OverallResults" );
17403 e.writeAttribute(
"successes", sectionStats.assertions.passed );
17404 e.writeAttribute(
"failures", sectionStats.assertions.failed );
17405 e.writeAttribute(
"expectedFailures", sectionStats.assertions.failedButOk );
17408 e.writeAttribute(
"durationInSeconds", sectionStats.durationInSeconds );
17410 m_xml.endElement();
17414 void XmlReporter::testCaseEnded( TestCaseStats
const& testCaseStats ) {
17415 StreamingReporterBase::testCaseEnded( testCaseStats );
17416 XmlWriter::ScopedElement e = m_xml.scopedElement(
"OverallResult" );
17417 e.writeAttribute(
"success", testCaseStats.totals.assertions.allOk() );
17420 e.writeAttribute(
"durationInSeconds", m_testCaseTimer.getElapsedSeconds() );
17422 if( !testCaseStats.stdOut.empty() )
17423 m_xml.scopedElement(
"StdOut" ).writeText(
trim( testCaseStats.stdOut ), XmlFormatting::Newline );
17424 if( !testCaseStats.stdErr.empty() )
17425 m_xml.scopedElement(
"StdErr" ).writeText(
trim( testCaseStats.stdErr ), XmlFormatting::Newline );
17427 m_xml.endElement();
17430 void XmlReporter::testGroupEnded( TestGroupStats
const& testGroupStats ) {
17431 StreamingReporterBase::testGroupEnded( testGroupStats );
17433 m_xml.scopedElement(
"OverallResults" )
17434 .writeAttribute(
"successes", testGroupStats.totals.assertions.passed )
17435 .writeAttribute(
"failures", testGroupStats.totals.assertions.failed )
17436 .writeAttribute(
"expectedFailures", testGroupStats.totals.assertions.failedButOk );
17437 m_xml.scopedElement(
"OverallResultsCases")
17438 .writeAttribute(
"successes", testGroupStats.totals.testCases.passed )
17439 .writeAttribute(
"failures", testGroupStats.totals.testCases.failed )
17440 .writeAttribute(
"expectedFailures", testGroupStats.totals.testCases.failedButOk );
17441 m_xml.endElement();
17444 void XmlReporter::testRunEnded( TestRunStats
const& testRunStats ) {
17445 StreamingReporterBase::testRunEnded( testRunStats );
17446 m_xml.scopedElement(
"OverallResults" )
17447 .writeAttribute(
"successes", testRunStats.totals.assertions.passed )
17448 .writeAttribute(
"failures", testRunStats.totals.assertions.failed )
17449 .writeAttribute(
"expectedFailures", testRunStats.totals.assertions.failedButOk );
17450 m_xml.scopedElement(
"OverallResultsCases")
17451 .writeAttribute(
"successes", testRunStats.totals.testCases.passed )
17452 .writeAttribute(
"failures", testRunStats.totals.testCases.failed )
17453 .writeAttribute(
"expectedFailures", testRunStats.totals.testCases.failedButOk );
17454 m_xml.endElement();
17457 #if defined(CATCH_CONFIG_ENABLE_BENCHMARKING)
17458 void XmlReporter::benchmarkPreparing(std::string
const& name) {
17459 m_xml.startElement(
"BenchmarkResults")
17460 .writeAttribute(
"name", name);
17463 void XmlReporter::benchmarkStarting(BenchmarkInfo
const &info) {
17464 m_xml.writeAttribute(
"samples",
info.samples)
17465 .writeAttribute(
"resamples",
info.resamples)
17466 .writeAttribute(
"iterations",
info.iterations)
17467 .writeAttribute(
"clockResolution",
info.clockResolution)
17468 .writeAttribute(
"estimatedDuration",
info.estimatedDuration)
17469 .writeComment(
"All values in nano seconds");
17472 void XmlReporter::benchmarkEnded(BenchmarkStats<>
const& benchmarkStats) {
17473 m_xml.startElement(
"mean")
17474 .writeAttribute(
"value", benchmarkStats.mean.point.count())
17475 .writeAttribute(
"lowerBound", benchmarkStats.mean.lower_bound.count())
17476 .writeAttribute(
"upperBound", benchmarkStats.mean.upper_bound.count())
17477 .writeAttribute(
"ci", benchmarkStats.mean.confidence_interval);
17478 m_xml.endElement();
17479 m_xml.startElement(
"standardDeviation")
17480 .writeAttribute(
"value", benchmarkStats.standardDeviation.point.count())
17481 .writeAttribute(
"lowerBound", benchmarkStats.standardDeviation.lower_bound.count())
17482 .writeAttribute(
"upperBound", benchmarkStats.standardDeviation.upper_bound.count())
17483 .writeAttribute(
"ci", benchmarkStats.standardDeviation.confidence_interval);
17484 m_xml.endElement();
17485 m_xml.startElement(
"outliers")
17486 .writeAttribute(
"variance", benchmarkStats.outlierVariance)
17487 .writeAttribute(
"lowMild", benchmarkStats.outliers.low_mild)
17488 .writeAttribute(
"lowSevere", benchmarkStats.outliers.low_severe)
17489 .writeAttribute(
"highMild", benchmarkStats.outliers.high_mild)
17490 .writeAttribute(
"highSevere", benchmarkStats.outliers.high_severe);
17491 m_xml.endElement();
17492 m_xml.endElement();
17495 void XmlReporter::benchmarkFailed(std::string
const &error) {
17496 m_xml.scopedElement(
"failed").
17497 writeAttribute(
"message", error);
17498 m_xml.endElement();
17502 CATCH_REGISTER_REPORTER(
"xml", XmlReporter )
17506 #if defined(_MSC_VER)
17507 #pragma warning(pop)
17512 LeakDetector leakDetector;
17516 #pragma clang diagnostic pop
17522 #ifdef CATCH_CONFIG_MAIN
17527 #ifndef CATCH_INTERNAL_CDECL
17529 #define CATCH_INTERNAL_CDECL __cdecl
17531 #define CATCH_INTERNAL_CDECL
17535 #if defined(CATCH_CONFIG_WCHAR) && defined(CATCH_PLATFORM_WINDOWS) && defined(_UNICODE) && !defined(DO_NOT_USE_WMAIN)
17537 extern "C" int CATCH_INTERNAL_CDECL wmain (
int argc,
wchar_t * argv[],
wchar_t * []) {
17540 int CATCH_INTERNAL_CDECL
main (
int argc,
char * argv[]) {
17543 return Catch::Session().run( argc, argv );
17549 int main (
int argc,
char *
const argv[]) {
17550 #if !CATCH_ARC_ENABLED
17551 NSAutoreleasePool * pool = [[NSAutoreleasePool alloc] init];
17554 Catch::registerTestMethods();
17555 int result = Catch::Session().run( argc, (
char**)argv );
17557 #if !CATCH_ARC_ENABLED
17569 #if !defined(CATCH_CONFIG_IMPL_ONLY)
17571 #ifdef CLARA_CONFIG_MAIN_NOT_DEFINED
17572 # undef CLARA_CONFIG_MAIN
17575 #if !defined(CATCH_CONFIG_DISABLE)
17578 #ifdef CATCH_CONFIG_PREFIX_ALL
17580 #define CATCH_REQUIRE( ... ) INTERNAL_CATCH_TEST( "CATCH_REQUIRE", Catch::ResultDisposition::Normal, __VA_ARGS__ )
17581 #define CATCH_REQUIRE_FALSE( ... ) INTERNAL_CATCH_TEST( "CATCH_REQUIRE_FALSE", Catch::ResultDisposition::Normal | Catch::ResultDisposition::FalseTest, __VA_ARGS__ )
17583 #define CATCH_REQUIRE_THROWS( ... ) INTERNAL_CATCH_THROWS( "CATCH_REQUIRE_THROWS", Catch::ResultDisposition::Normal, __VA_ARGS__ )
17584 #define CATCH_REQUIRE_THROWS_AS( expr, exceptionType ) INTERNAL_CATCH_THROWS_AS( "CATCH_REQUIRE_THROWS_AS", exceptionType, Catch::ResultDisposition::Normal, expr )
17585 #define CATCH_REQUIRE_THROWS_WITH( expr, matcher ) INTERNAL_CATCH_THROWS_STR_MATCHES( "CATCH_REQUIRE_THROWS_WITH", Catch::ResultDisposition::Normal, matcher, expr )
17586 #if !defined(CATCH_CONFIG_DISABLE_MATCHERS)
17587 #define CATCH_REQUIRE_THROWS_MATCHES( expr, exceptionType, matcher ) INTERNAL_CATCH_THROWS_MATCHES( "CATCH_REQUIRE_THROWS_MATCHES", exceptionType, Catch::ResultDisposition::Normal, matcher, expr )
17589 #define CATCH_REQUIRE_NOTHROW( ... ) INTERNAL_CATCH_NO_THROW( "CATCH_REQUIRE_NOTHROW", Catch::ResultDisposition::Normal, __VA_ARGS__ )
17591 #define CATCH_CHECK( ... ) INTERNAL_CATCH_TEST( "CATCH_CHECK", Catch::ResultDisposition::ContinueOnFailure, __VA_ARGS__ )
17592 #define CATCH_CHECK_FALSE( ... ) INTERNAL_CATCH_TEST( "CATCH_CHECK_FALSE", Catch::ResultDisposition::ContinueOnFailure | Catch::ResultDisposition::FalseTest, __VA_ARGS__ )
17593 #define CATCH_CHECKED_IF( ... ) INTERNAL_CATCH_IF( "CATCH_CHECKED_IF", Catch::ResultDisposition::ContinueOnFailure, __VA_ARGS__ )
17594 #define CATCH_CHECKED_ELSE( ... ) INTERNAL_CATCH_ELSE( "CATCH_CHECKED_ELSE", Catch::ResultDisposition::ContinueOnFailure, __VA_ARGS__ )
17595 #define CATCH_CHECK_NOFAIL( ... ) INTERNAL_CATCH_TEST( "CATCH_CHECK_NOFAIL", Catch::ResultDisposition::ContinueOnFailure | Catch::ResultDisposition::SuppressFail, __VA_ARGS__ )
17597 #define CATCH_CHECK_THROWS( ... ) INTERNAL_CATCH_THROWS( "CATCH_CHECK_THROWS", Catch::ResultDisposition::ContinueOnFailure, __VA_ARGS__ )
17598 #define CATCH_CHECK_THROWS_AS( expr, exceptionType ) INTERNAL_CATCH_THROWS_AS( "CATCH_CHECK_THROWS_AS", exceptionType, Catch::ResultDisposition::ContinueOnFailure, expr )
17599 #define CATCH_CHECK_THROWS_WITH( expr, matcher ) INTERNAL_CATCH_THROWS_STR_MATCHES( "CATCH_CHECK_THROWS_WITH", Catch::ResultDisposition::ContinueOnFailure, matcher, expr )
17600 #if !defined(CATCH_CONFIG_DISABLE_MATCHERS)
17601 #define CATCH_CHECK_THROWS_MATCHES( expr, exceptionType, matcher ) INTERNAL_CATCH_THROWS_MATCHES( "CATCH_CHECK_THROWS_MATCHES", exceptionType, Catch::ResultDisposition::ContinueOnFailure, matcher, expr )
17603 #define CATCH_CHECK_NOTHROW( ... ) INTERNAL_CATCH_NO_THROW( "CATCH_CHECK_NOTHROW", Catch::ResultDisposition::ContinueOnFailure, __VA_ARGS__ )
17605 #if !defined(CATCH_CONFIG_DISABLE_MATCHERS)
17606 #define CATCH_CHECK_THAT( arg, matcher ) INTERNAL_CHECK_THAT( "CATCH_CHECK_THAT", matcher, Catch::ResultDisposition::ContinueOnFailure, arg )
17608 #define CATCH_REQUIRE_THAT( arg, matcher ) INTERNAL_CHECK_THAT( "CATCH_REQUIRE_THAT", matcher, Catch::ResultDisposition::Normal, arg )
17611 #define CATCH_INFO( msg ) INTERNAL_CATCH_INFO( "CATCH_INFO", msg )
17612 #define CATCH_UNSCOPED_INFO( msg ) INTERNAL_CATCH_UNSCOPED_INFO( "CATCH_UNSCOPED_INFO", msg )
17613 #define CATCH_WARN( msg ) INTERNAL_CATCH_MSG( "CATCH_WARN", Catch::ResultWas::Warning, Catch::ResultDisposition::ContinueOnFailure, msg )
17614 #define CATCH_CAPTURE( ... ) INTERNAL_CATCH_CAPTURE( INTERNAL_CATCH_UNIQUE_NAME(capturer), "CATCH_CAPTURE",__VA_ARGS__ )
17616 #define CATCH_TEST_CASE( ... ) INTERNAL_CATCH_TESTCASE( __VA_ARGS__ )
17617 #define CATCH_TEST_CASE_METHOD( className, ... ) INTERNAL_CATCH_TEST_CASE_METHOD( className, __VA_ARGS__ )
17618 #define CATCH_METHOD_AS_TEST_CASE( method, ... ) INTERNAL_CATCH_METHOD_AS_TEST_CASE( method, __VA_ARGS__ )
17619 #define CATCH_REGISTER_TEST_CASE( Function, ... ) INTERNAL_CATCH_REGISTER_TESTCASE( Function, __VA_ARGS__ )
17620 #define CATCH_SECTION( ... ) INTERNAL_CATCH_SECTION( __VA_ARGS__ )
17621 #define CATCH_DYNAMIC_SECTION( ... ) INTERNAL_CATCH_DYNAMIC_SECTION( __VA_ARGS__ )
17622 #define CATCH_FAIL( ... ) INTERNAL_CATCH_MSG( "CATCH_FAIL", Catch::ResultWas::ExplicitFailure, Catch::ResultDisposition::Normal, __VA_ARGS__ )
17623 #define CATCH_FAIL_CHECK( ... ) INTERNAL_CATCH_MSG( "CATCH_FAIL_CHECK", Catch::ResultWas::ExplicitFailure, Catch::ResultDisposition::ContinueOnFailure, __VA_ARGS__ )
17624 #define CATCH_SUCCEED( ... ) INTERNAL_CATCH_MSG( "CATCH_SUCCEED", Catch::ResultWas::Ok, Catch::ResultDisposition::ContinueOnFailure, __VA_ARGS__ )
17626 #define CATCH_ANON_TEST_CASE() INTERNAL_CATCH_TESTCASE()
17628 #ifndef CATCH_CONFIG_TRADITIONAL_MSVC_PREPROCESSOR
17629 #define CATCH_TEMPLATE_TEST_CASE( ... ) INTERNAL_CATCH_TEMPLATE_TEST_CASE( __VA_ARGS__ )
17630 #define CATCH_TEMPLATE_TEST_CASE_SIG( ... ) INTERNAL_CATCH_TEMPLATE_TEST_CASE_SIG( __VA_ARGS__ )
17631 #define CATCH_TEMPLATE_TEST_CASE_METHOD( className, ... ) INTERNAL_CATCH_TEMPLATE_TEST_CASE_METHOD( className, __VA_ARGS__ )
17632 #define CATCH_TEMPLATE_TEST_CASE_METHOD_SIG( className, ... ) INTERNAL_CATCH_TEMPLATE_TEST_CASE_METHOD_SIG( className, __VA_ARGS__ )
17633 #define CATCH_TEMPLATE_PRODUCT_TEST_CASE( ... ) INTERNAL_CATCH_TEMPLATE_PRODUCT_TEST_CASE( __VA_ARGS__ )
17634 #define CATCH_TEMPLATE_PRODUCT_TEST_CASE_SIG( ... ) INTERNAL_CATCH_TEMPLATE_PRODUCT_TEST_CASE_SIG( __VA_ARGS__ )
17635 #define CATCH_TEMPLATE_PRODUCT_TEST_CASE_METHOD( className, ... ) INTERNAL_CATCH_TEMPLATE_PRODUCT_TEST_CASE_METHOD( className, __VA_ARGS__ )
17636 #define CATCH_TEMPLATE_PRODUCT_TEST_CASE_METHOD_SIG( className, ... ) INTERNAL_CATCH_TEMPLATE_PRODUCT_TEST_CASE_METHOD_SIG( className, __VA_ARGS__ )
17638 #define CATCH_TEMPLATE_TEST_CASE( ... ) INTERNAL_CATCH_EXPAND_VARGS( INTERNAL_CATCH_TEMPLATE_TEST_CASE( __VA_ARGS__ ) )
17639 #define CATCH_TEMPLATE_TEST_CASE_SIG( ... ) INTERNAL_CATCH_EXPAND_VARGS( INTERNAL_CATCH_TEMPLATE_TEST_CASE_SIG( __VA_ARGS__ ) )
17640 #define CATCH_TEMPLATE_TEST_CASE_METHOD( className, ... ) INTERNAL_CATCH_EXPAND_VARGS( INTERNAL_CATCH_TEMPLATE_TEST_CASE_METHOD( className, __VA_ARGS__ ) )
17641 #define CATCH_TEMPLATE_TEST_CASE_METHOD_SIG( className, ... ) INTERNAL_CATCH_EXPAND_VARGS( INTERNAL_CATCH_TEMPLATE_TEST_CASE_METHOD_SIG( className, __VA_ARGS__ ) )
17642 #define CATCH_TEMPLATE_PRODUCT_TEST_CASE( ... ) INTERNAL_CATCH_EXPAND_VARGS( INTERNAL_CATCH_TEMPLATE_PRODUCT_TEST_CASE( __VA_ARGS__ ) )
17643 #define CATCH_TEMPLATE_PRODUCT_TEST_CASE_SIG( ... ) INTERNAL_CATCH_EXPAND_VARGS( INTERNAL_CATCH_TEMPLATE_PRODUCT_TEST_CASE_SIG( __VA_ARGS__ ) )
17644 #define CATCH_TEMPLATE_PRODUCT_TEST_CASE_METHOD( className, ... ) INTERNAL_CATCH_EXPAND_VARGS( INTERNAL_CATCH_TEMPLATE_PRODUCT_TEST_CASE_METHOD( className, __VA_ARGS__ ) )
17645 #define CATCH_TEMPLATE_PRODUCT_TEST_CASE_METHOD_SIG( className, ... ) INTERNAL_CATCH_EXPAND_VARGS( INTERNAL_CATCH_TEMPLATE_PRODUCT_TEST_CASE_METHOD_SIG( className, __VA_ARGS__ ) )
17648 #if !defined(CATCH_CONFIG_RUNTIME_STATIC_REQUIRE)
17649 #define CATCH_STATIC_REQUIRE( ... ) static_assert( __VA_ARGS__ , #__VA_ARGS__ ); CATCH_SUCCEED( #__VA_ARGS__ )
17650 #define CATCH_STATIC_REQUIRE_FALSE( ... ) static_assert( !(__VA_ARGS__), "!(" #__VA_ARGS__ ")" ); CATCH_SUCCEED( #__VA_ARGS__ )
17652 #define CATCH_STATIC_REQUIRE( ... ) CATCH_REQUIRE( __VA_ARGS__ )
17653 #define CATCH_STATIC_REQUIRE_FALSE( ... ) CATCH_REQUIRE_FALSE( __VA_ARGS__ )
17657 #define CATCH_SCENARIO( ... ) CATCH_TEST_CASE( "Scenario: " __VA_ARGS__ )
17658 #define CATCH_SCENARIO_METHOD( className, ... ) INTERNAL_CATCH_TEST_CASE_METHOD( className, "Scenario: " __VA_ARGS__ )
17659 #define CATCH_GIVEN( desc ) INTERNAL_CATCH_DYNAMIC_SECTION( " Given: " << desc )
17660 #define CATCH_AND_GIVEN( desc ) INTERNAL_CATCH_DYNAMIC_SECTION( "And given: " << desc )
17661 #define CATCH_WHEN( desc ) INTERNAL_CATCH_DYNAMIC_SECTION( " When: " << desc )
17662 #define CATCH_AND_WHEN( desc ) INTERNAL_CATCH_DYNAMIC_SECTION( " And when: " << desc )
17663 #define CATCH_THEN( desc ) INTERNAL_CATCH_DYNAMIC_SECTION( " Then: " << desc )
17664 #define CATCH_AND_THEN( desc ) INTERNAL_CATCH_DYNAMIC_SECTION( " And: " << desc )
17666 #if defined(CATCH_CONFIG_ENABLE_BENCHMARKING)
17667 #define CATCH_BENCHMARK(...) \
17668 INTERNAL_CATCH_BENCHMARK(INTERNAL_CATCH_UNIQUE_NAME(C_A_T_C_H_B_E_N_C_H_), INTERNAL_CATCH_GET_1_ARG(__VA_ARGS__,,), INTERNAL_CATCH_GET_2_ARG(__VA_ARGS__,,))
17669 #define CATCH_BENCHMARK_ADVANCED(name) \
17670 INTERNAL_CATCH_BENCHMARK_ADVANCED(INTERNAL_CATCH_UNIQUE_NAME(C_A_T_C_H_B_E_N_C_H_), name)
17676 #define REQUIRE( ... ) INTERNAL_CATCH_TEST( "REQUIRE", Catch::ResultDisposition::Normal, __VA_ARGS__ )
17677 #define REQUIRE_FALSE( ... ) INTERNAL_CATCH_TEST( "REQUIRE_FALSE", Catch::ResultDisposition::Normal | Catch::ResultDisposition::FalseTest, __VA_ARGS__ )
17679 #define REQUIRE_THROWS( ... ) INTERNAL_CATCH_THROWS( "REQUIRE_THROWS", Catch::ResultDisposition::Normal, __VA_ARGS__ )
17680 #define REQUIRE_THROWS_AS( expr, exceptionType ) INTERNAL_CATCH_THROWS_AS( "REQUIRE_THROWS_AS", exceptionType, Catch::ResultDisposition::Normal, expr )
17681 #define REQUIRE_THROWS_WITH( expr, matcher ) INTERNAL_CATCH_THROWS_STR_MATCHES( "REQUIRE_THROWS_WITH", Catch::ResultDisposition::Normal, matcher, expr )
17682 #if !defined(CATCH_CONFIG_DISABLE_MATCHERS)
17683 #define REQUIRE_THROWS_MATCHES( expr, exceptionType, matcher ) INTERNAL_CATCH_THROWS_MATCHES( "REQUIRE_THROWS_MATCHES", exceptionType, Catch::ResultDisposition::Normal, matcher, expr )
17685 #define REQUIRE_NOTHROW( ... ) INTERNAL_CATCH_NO_THROW( "REQUIRE_NOTHROW", Catch::ResultDisposition::Normal, __VA_ARGS__ )
17687 #define CHECK( ... ) INTERNAL_CATCH_TEST( "CHECK", Catch::ResultDisposition::ContinueOnFailure, __VA_ARGS__ )
17688 #define CHECK_FALSE( ... ) INTERNAL_CATCH_TEST( "CHECK_FALSE", Catch::ResultDisposition::ContinueOnFailure | Catch::ResultDisposition::FalseTest, __VA_ARGS__ )
17689 #define CHECKED_IF( ... ) INTERNAL_CATCH_IF( "CHECKED_IF", Catch::ResultDisposition::ContinueOnFailure, __VA_ARGS__ )
17690 #define CHECKED_ELSE( ... ) INTERNAL_CATCH_ELSE( "CHECKED_ELSE", Catch::ResultDisposition::ContinueOnFailure, __VA_ARGS__ )
17691 #define CHECK_NOFAIL( ... ) INTERNAL_CATCH_TEST( "CHECK_NOFAIL", Catch::ResultDisposition::ContinueOnFailure | Catch::ResultDisposition::SuppressFail, __VA_ARGS__ )
17693 #define CHECK_THROWS( ... ) INTERNAL_CATCH_THROWS( "CHECK_THROWS", Catch::ResultDisposition::ContinueOnFailure, __VA_ARGS__ )
17694 #define CHECK_THROWS_AS( expr, exceptionType ) INTERNAL_CATCH_THROWS_AS( "CHECK_THROWS_AS", exceptionType, Catch::ResultDisposition::ContinueOnFailure, expr )
17695 #define CHECK_THROWS_WITH( expr, matcher ) INTERNAL_CATCH_THROWS_STR_MATCHES( "CHECK_THROWS_WITH", Catch::ResultDisposition::ContinueOnFailure, matcher, expr )
17696 #if !defined(CATCH_CONFIG_DISABLE_MATCHERS)
17697 #define CHECK_THROWS_MATCHES( expr, exceptionType, matcher ) INTERNAL_CATCH_THROWS_MATCHES( "CHECK_THROWS_MATCHES", exceptionType, Catch::ResultDisposition::ContinueOnFailure, matcher, expr )
17699 #define CHECK_NOTHROW( ... ) INTERNAL_CATCH_NO_THROW( "CHECK_NOTHROW", Catch::ResultDisposition::ContinueOnFailure, __VA_ARGS__ )
17701 #if !defined(CATCH_CONFIG_DISABLE_MATCHERS)
17702 #define CHECK_THAT( arg, matcher ) INTERNAL_CHECK_THAT( "CHECK_THAT", matcher, Catch::ResultDisposition::ContinueOnFailure, arg )
17704 #define REQUIRE_THAT( arg, matcher ) INTERNAL_CHECK_THAT( "REQUIRE_THAT", matcher, Catch::ResultDisposition::Normal, arg )
17707 #define INFO( msg ) INTERNAL_CATCH_INFO( "INFO", msg )
17708 #define UNSCOPED_INFO( msg ) INTERNAL_CATCH_UNSCOPED_INFO( "UNSCOPED_INFO", msg )
17709 #define WARN( msg ) INTERNAL_CATCH_MSG( "WARN", Catch::ResultWas::Warning, Catch::ResultDisposition::ContinueOnFailure, msg )
17710 #define CAPTURE( ... ) INTERNAL_CATCH_CAPTURE( INTERNAL_CATCH_UNIQUE_NAME(capturer), "CAPTURE",__VA_ARGS__ )
17712 #define TEST_CASE( ... ) INTERNAL_CATCH_TESTCASE( __VA_ARGS__ )
17713 #define TEST_CASE_METHOD( className, ... ) INTERNAL_CATCH_TEST_CASE_METHOD( className, __VA_ARGS__ )
17714 #define METHOD_AS_TEST_CASE( method, ... ) INTERNAL_CATCH_METHOD_AS_TEST_CASE( method, __VA_ARGS__ )
17715 #define REGISTER_TEST_CASE( Function, ... ) INTERNAL_CATCH_REGISTER_TESTCASE( Function, __VA_ARGS__ )
17716 #define SECTION( ... ) INTERNAL_CATCH_SECTION( __VA_ARGS__ )
17717 #define DYNAMIC_SECTION( ... ) INTERNAL_CATCH_DYNAMIC_SECTION( __VA_ARGS__ )
17718 #define FAIL( ... ) INTERNAL_CATCH_MSG( "FAIL", Catch::ResultWas::ExplicitFailure, Catch::ResultDisposition::Normal, __VA_ARGS__ )
17719 #define FAIL_CHECK( ... ) INTERNAL_CATCH_MSG( "FAIL_CHECK", Catch::ResultWas::ExplicitFailure, Catch::ResultDisposition::ContinueOnFailure, __VA_ARGS__ )
17720 #define SUCCEED( ... ) INTERNAL_CATCH_MSG( "SUCCEED", Catch::ResultWas::Ok, Catch::ResultDisposition::ContinueOnFailure, __VA_ARGS__ )
17721 #define ANON_TEST_CASE() INTERNAL_CATCH_TESTCASE()
17723 #ifndef CATCH_CONFIG_TRADITIONAL_MSVC_PREPROCESSOR
17724 #define TEMPLATE_TEST_CASE( ... ) INTERNAL_CATCH_TEMPLATE_TEST_CASE( __VA_ARGS__ )
17725 #define TEMPLATE_TEST_CASE_SIG( ... ) INTERNAL_CATCH_TEMPLATE_TEST_CASE_SIG( __VA_ARGS__ )
17726 #define TEMPLATE_TEST_CASE_METHOD( className, ... ) INTERNAL_CATCH_TEMPLATE_TEST_CASE_METHOD( className, __VA_ARGS__ )
17727 #define TEMPLATE_TEST_CASE_METHOD_SIG( className, ... ) INTERNAL_CATCH_TEMPLATE_TEST_CASE_METHOD_SIG( className, __VA_ARGS__ )
17728 #define TEMPLATE_PRODUCT_TEST_CASE( ... ) INTERNAL_CATCH_TEMPLATE_PRODUCT_TEST_CASE( __VA_ARGS__ )
17729 #define TEMPLATE_PRODUCT_TEST_CASE_SIG( ... ) INTERNAL_CATCH_TEMPLATE_PRODUCT_TEST_CASE_SIG( __VA_ARGS__ )
17730 #define TEMPLATE_PRODUCT_TEST_CASE_METHOD( className, ... ) INTERNAL_CATCH_TEMPLATE_PRODUCT_TEST_CASE_METHOD( className, __VA_ARGS__ )
17731 #define TEMPLATE_PRODUCT_TEST_CASE_METHOD_SIG( className, ... ) INTERNAL_CATCH_TEMPLATE_PRODUCT_TEST_CASE_METHOD_SIG( className, __VA_ARGS__ )
17732 #define TEMPLATE_LIST_TEST_CASE( ... ) INTERNAL_CATCH_TEMPLATE_LIST_TEST_CASE(__VA_ARGS__)
17733 #define TEMPLATE_LIST_TEST_CASE_METHOD( className, ... ) INTERNAL_CATCH_TEMPLATE_LIST_TEST_CASE_METHOD( className, __VA_ARGS__ )
17735 #define TEMPLATE_TEST_CASE( ... ) INTERNAL_CATCH_EXPAND_VARGS( INTERNAL_CATCH_TEMPLATE_TEST_CASE( __VA_ARGS__ ) )
17736 #define TEMPLATE_TEST_CASE_SIG( ... ) INTERNAL_CATCH_EXPAND_VARGS( INTERNAL_CATCH_TEMPLATE_TEST_CASE_SIG( __VA_ARGS__ ) )
17737 #define TEMPLATE_TEST_CASE_METHOD( className, ... ) INTERNAL_CATCH_EXPAND_VARGS( INTERNAL_CATCH_TEMPLATE_TEST_CASE_METHOD( className, __VA_ARGS__ ) )
17738 #define TEMPLATE_TEST_CASE_METHOD_SIG( className, ... ) INTERNAL_CATCH_EXPAND_VARGS( INTERNAL_CATCH_TEMPLATE_TEST_CASE_METHOD_SIG( className, __VA_ARGS__ ) )
17739 #define TEMPLATE_PRODUCT_TEST_CASE( ... ) INTERNAL_CATCH_EXPAND_VARGS( INTERNAL_CATCH_TEMPLATE_PRODUCT_TEST_CASE( __VA_ARGS__ ) )
17740 #define TEMPLATE_PRODUCT_TEST_CASE_SIG( ... ) INTERNAL_CATCH_EXPAND_VARGS( INTERNAL_CATCH_TEMPLATE_PRODUCT_TEST_CASE_SIG( __VA_ARGS__ ) )
17741 #define TEMPLATE_PRODUCT_TEST_CASE_METHOD( className, ... ) INTERNAL_CATCH_EXPAND_VARGS( INTERNAL_CATCH_TEMPLATE_PRODUCT_TEST_CASE_METHOD( className, __VA_ARGS__ ) )
17742 #define TEMPLATE_PRODUCT_TEST_CASE_METHOD_SIG( className, ... ) INTERNAL_CATCH_EXPAND_VARGS( INTERNAL_CATCH_TEMPLATE_PRODUCT_TEST_CASE_METHOD_SIG( className, __VA_ARGS__ ) )
17743 #define TEMPLATE_LIST_TEST_CASE( ... ) INTERNAL_CATCH_EXPAND_VARGS( INTERNAL_CATCH_TEMPLATE_LIST_TEST_CASE( __VA_ARGS__ ) )
17744 #define TEMPLATE_LIST_TEST_CASE_METHOD( className, ... ) INTERNAL_CATCH_EXPAND_VARGS( INTERNAL_CATCH_TEMPLATE_LIST_TEST_CASE_METHOD( className, __VA_ARGS__ ) )
17747 #if !defined(CATCH_CONFIG_RUNTIME_STATIC_REQUIRE)
17748 #define STATIC_REQUIRE( ... ) static_assert( __VA_ARGS__, #__VA_ARGS__ ); SUCCEED( #__VA_ARGS__ )
17749 #define STATIC_REQUIRE_FALSE( ... ) static_assert( !(__VA_ARGS__), "!(" #__VA_ARGS__ ")" ); SUCCEED( "!(" #__VA_ARGS__ ")" )
17751 #define STATIC_REQUIRE( ... ) REQUIRE( __VA_ARGS__ )
17752 #define STATIC_REQUIRE_FALSE( ... ) REQUIRE_FALSE( __VA_ARGS__ )
17757 #define CATCH_TRANSLATE_EXCEPTION( signature ) INTERNAL_CATCH_TRANSLATE_EXCEPTION( signature )
17760 #define SCENARIO( ... ) TEST_CASE( "Scenario: " __VA_ARGS__ )
17761 #define SCENARIO_METHOD( className, ... ) INTERNAL_CATCH_TEST_CASE_METHOD( className, "Scenario: " __VA_ARGS__ )
17763 #define GIVEN( desc ) INTERNAL_CATCH_DYNAMIC_SECTION( " Given: " << desc )
17764 #define AND_GIVEN( desc ) INTERNAL_CATCH_DYNAMIC_SECTION( "And given: " << desc )
17765 #define WHEN( desc ) INTERNAL_CATCH_DYNAMIC_SECTION( " When: " << desc )
17766 #define AND_WHEN( desc ) INTERNAL_CATCH_DYNAMIC_SECTION( " And when: " << desc )
17767 #define THEN( desc ) INTERNAL_CATCH_DYNAMIC_SECTION( " Then: " << desc )
17768 #define AND_THEN( desc ) INTERNAL_CATCH_DYNAMIC_SECTION( " And: " << desc )
17770 #if defined(CATCH_CONFIG_ENABLE_BENCHMARKING)
17771 #define BENCHMARK(...) \
17772 INTERNAL_CATCH_BENCHMARK(INTERNAL_CATCH_UNIQUE_NAME(C_A_T_C_H_B_E_N_C_H_), INTERNAL_CATCH_GET_1_ARG(__VA_ARGS__,,), INTERNAL_CATCH_GET_2_ARG(__VA_ARGS__,,))
17773 #define BENCHMARK_ADVANCED(name) \
17774 INTERNAL_CATCH_BENCHMARK_ADVANCED(INTERNAL_CATCH_UNIQUE_NAME(C_A_T_C_H_B_E_N_C_H_), name)
17783 #ifdef CATCH_CONFIG_PREFIX_ALL
17785 #define CATCH_REQUIRE( ... ) (void)(0)
17786 #define CATCH_REQUIRE_FALSE( ... ) (void)(0)
17788 #define CATCH_REQUIRE_THROWS( ... ) (void)(0)
17789 #define CATCH_REQUIRE_THROWS_AS( expr, exceptionType ) (void)(0)
17790 #define CATCH_REQUIRE_THROWS_WITH( expr, matcher ) (void)(0)
17791 #if !defined(CATCH_CONFIG_DISABLE_MATCHERS)
17792 #define CATCH_REQUIRE_THROWS_MATCHES( expr, exceptionType, matcher ) (void)(0)
17794 #define CATCH_REQUIRE_NOTHROW( ... ) (void)(0)
17796 #define CATCH_CHECK( ... ) (void)(0)
17797 #define CATCH_CHECK_FALSE( ... ) (void)(0)
17798 #define CATCH_CHECKED_IF( ... ) if (__VA_ARGS__)
17799 #define CATCH_CHECKED_ELSE( ... ) if (!(__VA_ARGS__))
17800 #define CATCH_CHECK_NOFAIL( ... ) (void)(0)
17802 #define CATCH_CHECK_THROWS( ... ) (void)(0)
17803 #define CATCH_CHECK_THROWS_AS( expr, exceptionType ) (void)(0)
17804 #define CATCH_CHECK_THROWS_WITH( expr, matcher ) (void)(0)
17805 #if !defined(CATCH_CONFIG_DISABLE_MATCHERS)
17806 #define CATCH_CHECK_THROWS_MATCHES( expr, exceptionType, matcher ) (void)(0)
17808 #define CATCH_CHECK_NOTHROW( ... ) (void)(0)
17810 #if !defined(CATCH_CONFIG_DISABLE_MATCHERS)
17811 #define CATCH_CHECK_THAT( arg, matcher ) (void)(0)
17813 #define CATCH_REQUIRE_THAT( arg, matcher ) (void)(0)
17816 #define CATCH_INFO( msg ) (void)(0)
17817 #define CATCH_UNSCOPED_INFO( msg ) (void)(0)
17818 #define CATCH_WARN( msg ) (void)(0)
17819 #define CATCH_CAPTURE( msg ) (void)(0)
17821 #define CATCH_TEST_CASE( ... ) INTERNAL_CATCH_TESTCASE_NO_REGISTRATION(INTERNAL_CATCH_UNIQUE_NAME( C_A_T_C_H_T_E_S_T_ ))
17822 #define CATCH_TEST_CASE_METHOD( className, ... ) INTERNAL_CATCH_TESTCASE_NO_REGISTRATION(INTERNAL_CATCH_UNIQUE_NAME( C_A_T_C_H_T_E_S_T_ ))
17823 #define CATCH_METHOD_AS_TEST_CASE( method, ... )
17824 #define CATCH_REGISTER_TEST_CASE( Function, ... ) (void)(0)
17825 #define CATCH_SECTION( ... )
17826 #define CATCH_DYNAMIC_SECTION( ... )
17827 #define CATCH_FAIL( ... ) (void)(0)
17828 #define CATCH_FAIL_CHECK( ... ) (void)(0)
17829 #define CATCH_SUCCEED( ... ) (void)(0)
17831 #define CATCH_ANON_TEST_CASE() INTERNAL_CATCH_TESTCASE_NO_REGISTRATION(INTERNAL_CATCH_UNIQUE_NAME( C_A_T_C_H_T_E_S_T_ ))
17833 #ifndef CATCH_CONFIG_TRADITIONAL_MSVC_PREPROCESSOR
17834 #define CATCH_TEMPLATE_TEST_CASE( ... ) INTERNAL_CATCH_TEMPLATE_TEST_CASE_NO_REGISTRATION(__VA_ARGS__)
17835 #define CATCH_TEMPLATE_TEST_CASE_SIG( ... ) INTERNAL_CATCH_TEMPLATE_TEST_CASE_SIG_NO_REGISTRATION(__VA_ARGS__)
17836 #define CATCH_TEMPLATE_TEST_CASE_METHOD( className, ... ) INTERNAL_CATCH_TEMPLATE_TEST_CASE_METHOD_NO_REGISTRATION(className, __VA_ARGS__)
17837 #define CATCH_TEMPLATE_TEST_CASE_METHOD_SIG( className, ... ) INTERNAL_CATCH_TEMPLATE_TEST_CASE_METHOD_SIG_NO_REGISTRATION(className, __VA_ARGS__ )
17838 #define CATCH_TEMPLATE_PRODUCT_TEST_CASE( ... ) CATCH_TEMPLATE_TEST_CASE( __VA_ARGS__ )
17839 #define CATCH_TEMPLATE_PRODUCT_TEST_CASE_SIG( ... ) CATCH_TEMPLATE_TEST_CASE( __VA_ARGS__ )
17840 #define CATCH_TEMPLATE_PRODUCT_TEST_CASE_METHOD( className, ... ) CATCH_TEMPLATE_TEST_CASE_METHOD( className, __VA_ARGS__ )
17841 #define CATCH_TEMPLATE_PRODUCT_TEST_CASE_METHOD_SIG( className, ... ) CATCH_TEMPLATE_TEST_CASE_METHOD( className, __VA_ARGS__ )
17843 #define CATCH_TEMPLATE_TEST_CASE( ... ) INTERNAL_CATCH_EXPAND_VARGS( INTERNAL_CATCH_TEMPLATE_TEST_CASE_NO_REGISTRATION(__VA_ARGS__) )
17844 #define CATCH_TEMPLATE_TEST_CASE_SIG( ... ) INTERNAL_CATCH_EXPAND_VARGS( INTERNAL_CATCH_TEMPLATE_TEST_CASE_SIG_NO_REGISTRATION(__VA_ARGS__) )
17845 #define CATCH_TEMPLATE_TEST_CASE_METHOD( className, ... ) INTERNAL_CATCH_EXPAND_VARGS( INTERNAL_CATCH_TEMPLATE_TEST_CASE_METHOD_NO_REGISTRATION(className, __VA_ARGS__ ) )
17846 #define CATCH_TEMPLATE_TEST_CASE_METHOD_SIG( className, ... ) INTERNAL_CATCH_EXPAND_VARGS( INTERNAL_CATCH_TEMPLATE_TEST_CASE_METHOD_SIG_NO_REGISTRATION(className, __VA_ARGS__ ) )
17847 #define CATCH_TEMPLATE_PRODUCT_TEST_CASE( ... ) CATCH_TEMPLATE_TEST_CASE( __VA_ARGS__ )
17848 #define CATCH_TEMPLATE_PRODUCT_TEST_CASE_SIG( ... ) CATCH_TEMPLATE_TEST_CASE( __VA_ARGS__ )
17849 #define CATCH_TEMPLATE_PRODUCT_TEST_CASE_METHOD( className, ... ) CATCH_TEMPLATE_TEST_CASE_METHOD( className, __VA_ARGS__ )
17850 #define CATCH_TEMPLATE_PRODUCT_TEST_CASE_METHOD_SIG( className, ... ) CATCH_TEMPLATE_TEST_CASE_METHOD( className, __VA_ARGS__ )
17854 #define CATCH_SCENARIO( ... ) INTERNAL_CATCH_TESTCASE_NO_REGISTRATION(INTERNAL_CATCH_UNIQUE_NAME( C_A_T_C_H_T_E_S_T_ ))
17855 #define CATCH_SCENARIO_METHOD( className, ... ) INTERNAL_CATCH_TESTCASE_METHOD_NO_REGISTRATION(INTERNAL_CATCH_UNIQUE_NAME( C_A_T_C_H_T_E_S_T_ ), className )
17856 #define CATCH_GIVEN( desc )
17857 #define CATCH_AND_GIVEN( desc )
17858 #define CATCH_WHEN( desc )
17859 #define CATCH_AND_WHEN( desc )
17860 #define CATCH_THEN( desc )
17861 #define CATCH_AND_THEN( desc )
17863 #define CATCH_STATIC_REQUIRE( ... ) (void)(0)
17864 #define CATCH_STATIC_REQUIRE_FALSE( ... ) (void)(0)
17869 #define REQUIRE( ... ) (void)(0)
17870 #define REQUIRE_FALSE( ... ) (void)(0)
17872 #define REQUIRE_THROWS( ... ) (void)(0)
17873 #define REQUIRE_THROWS_AS( expr, exceptionType ) (void)(0)
17874 #define REQUIRE_THROWS_WITH( expr, matcher ) (void)(0)
17875 #if !defined(CATCH_CONFIG_DISABLE_MATCHERS)
17876 #define REQUIRE_THROWS_MATCHES( expr, exceptionType, matcher ) (void)(0)
17878 #define REQUIRE_NOTHROW( ... ) (void)(0)
17880 #define CHECK( ... ) (void)(0)
17881 #define CHECK_FALSE( ... ) (void)(0)
17882 #define CHECKED_IF( ... ) if (__VA_ARGS__)
17883 #define CHECKED_ELSE( ... ) if (!(__VA_ARGS__))
17884 #define CHECK_NOFAIL( ... ) (void)(0)
17886 #define CHECK_THROWS( ... ) (void)(0)
17887 #define CHECK_THROWS_AS( expr, exceptionType ) (void)(0)
17888 #define CHECK_THROWS_WITH( expr, matcher ) (void)(0)
17889 #if !defined(CATCH_CONFIG_DISABLE_MATCHERS)
17890 #define CHECK_THROWS_MATCHES( expr, exceptionType, matcher ) (void)(0)
17892 #define CHECK_NOTHROW( ... ) (void)(0)
17894 #if !defined(CATCH_CONFIG_DISABLE_MATCHERS)
17895 #define CHECK_THAT( arg, matcher ) (void)(0)
17897 #define REQUIRE_THAT( arg, matcher ) (void)(0)
17900 #define INFO( msg ) (void)(0)
17901 #define UNSCOPED_INFO( msg ) (void)(0)
17902 #define WARN( msg ) (void)(0)
17903 #define CAPTURE( ... ) (void)(0)
17905 #define TEST_CASE( ... ) INTERNAL_CATCH_TESTCASE_NO_REGISTRATION(INTERNAL_CATCH_UNIQUE_NAME( C_A_T_C_H_T_E_S_T_ ))
17906 #define TEST_CASE_METHOD( className, ... ) INTERNAL_CATCH_TESTCASE_NO_REGISTRATION(INTERNAL_CATCH_UNIQUE_NAME( C_A_T_C_H_T_E_S_T_ ))
17907 #define METHOD_AS_TEST_CASE( method, ... )
17908 #define REGISTER_TEST_CASE( Function, ... ) (void)(0)
17909 #define SECTION( ... )
17910 #define DYNAMIC_SECTION( ... )
17911 #define FAIL( ... ) (void)(0)
17912 #define FAIL_CHECK( ... ) (void)(0)
17913 #define SUCCEED( ... ) (void)(0)
17914 #define ANON_TEST_CASE() INTERNAL_CATCH_TESTCASE_NO_REGISTRATION(INTERNAL_CATCH_UNIQUE_NAME( C_A_T_C_H_T_E_S_T_ ))
17916 #ifndef CATCH_CONFIG_TRADITIONAL_MSVC_PREPROCESSOR
17917 #define TEMPLATE_TEST_CASE( ... ) INTERNAL_CATCH_TEMPLATE_TEST_CASE_NO_REGISTRATION(__VA_ARGS__)
17918 #define TEMPLATE_TEST_CASE_SIG( ... ) INTERNAL_CATCH_TEMPLATE_TEST_CASE_SIG_NO_REGISTRATION(__VA_ARGS__)
17919 #define TEMPLATE_TEST_CASE_METHOD( className, ... ) INTERNAL_CATCH_TEMPLATE_TEST_CASE_METHOD_NO_REGISTRATION(className, __VA_ARGS__)
17920 #define TEMPLATE_TEST_CASE_METHOD_SIG( className, ... ) INTERNAL_CATCH_TEMPLATE_TEST_CASE_METHOD_SIG_NO_REGISTRATION(className, __VA_ARGS__ )
17921 #define TEMPLATE_PRODUCT_TEST_CASE( ... ) TEMPLATE_TEST_CASE( __VA_ARGS__ )
17922 #define TEMPLATE_PRODUCT_TEST_CASE_SIG( ... ) TEMPLATE_TEST_CASE( __VA_ARGS__ )
17923 #define TEMPLATE_PRODUCT_TEST_CASE_METHOD( className, ... ) TEMPLATE_TEST_CASE_METHOD( className, __VA_ARGS__ )
17924 #define TEMPLATE_PRODUCT_TEST_CASE_METHOD_SIG( className, ... ) TEMPLATE_TEST_CASE_METHOD( className, __VA_ARGS__ )
17926 #define TEMPLATE_TEST_CASE( ... ) INTERNAL_CATCH_EXPAND_VARGS( INTERNAL_CATCH_TEMPLATE_TEST_CASE_NO_REGISTRATION(__VA_ARGS__) )
17927 #define TEMPLATE_TEST_CASE_SIG( ... ) INTERNAL_CATCH_EXPAND_VARGS( INTERNAL_CATCH_TEMPLATE_TEST_CASE_SIG_NO_REGISTRATION(__VA_ARGS__) )
17928 #define TEMPLATE_TEST_CASE_METHOD( className, ... ) INTERNAL_CATCH_EXPAND_VARGS( INTERNAL_CATCH_TEMPLATE_TEST_CASE_METHOD_NO_REGISTRATION(className, __VA_ARGS__ ) )
17929 #define TEMPLATE_TEST_CASE_METHOD_SIG( className, ... ) INTERNAL_CATCH_EXPAND_VARGS( INTERNAL_CATCH_TEMPLATE_TEST_CASE_METHOD_SIG_NO_REGISTRATION(className, __VA_ARGS__ ) )
17930 #define TEMPLATE_PRODUCT_TEST_CASE( ... ) TEMPLATE_TEST_CASE( __VA_ARGS__ )
17931 #define TEMPLATE_PRODUCT_TEST_CASE_SIG( ... ) TEMPLATE_TEST_CASE( __VA_ARGS__ )
17932 #define TEMPLATE_PRODUCT_TEST_CASE_METHOD( className, ... ) TEMPLATE_TEST_CASE_METHOD( className, __VA_ARGS__ )
17933 #define TEMPLATE_PRODUCT_TEST_CASE_METHOD_SIG( className, ... ) TEMPLATE_TEST_CASE_METHOD( className, __VA_ARGS__ )
17936 #define STATIC_REQUIRE( ... ) (void)(0)
17937 #define STATIC_REQUIRE_FALSE( ... ) (void)(0)
17941 #define CATCH_TRANSLATE_EXCEPTION( signature ) INTERNAL_CATCH_TRANSLATE_EXCEPTION_NO_REG( INTERNAL_CATCH_UNIQUE_NAME( catch_internal_ExceptionTranslator ), signature )
17944 #define SCENARIO( ... ) INTERNAL_CATCH_TESTCASE_NO_REGISTRATION(INTERNAL_CATCH_UNIQUE_NAME( C_A_T_C_H_T_E_S_T_ ) )
17945 #define SCENARIO_METHOD( className, ... ) INTERNAL_CATCH_TESTCASE_METHOD_NO_REGISTRATION(INTERNAL_CATCH_UNIQUE_NAME( C_A_T_C_H_T_E_S_T_ ), className )
17947 #define GIVEN( desc )
17948 #define AND_GIVEN( desc )
17949 #define WHEN( desc )
17950 #define AND_WHEN( desc )
17951 #define THEN( desc )
17952 #define AND_THEN( desc )
17965 # pragma warning(pop)
17967 # pragma clang diagnostic pop
17969 #elif defined __GNUC__
17970 # pragma GCC diagnostic pop
int main(int argc, char **argv)
#define CATCH_INTERNAL_START_WARNINGS_SUPPRESSION
#define CATCH_CATCH_ANON(type)
#define CATCH_RUNTIME_ERROR(...)
#define CATCH_INTERNAL_SUPPRESS_GLOBALS_WARNINGS
#define CATCH_ENFORCE(condition,...)
#define CATCH_INTERNAL_LINEINFO
std::ostream & operator<<(std::ostream &, Catch_global_namespace_dummy)
#define CATCH_INTERNAL_STOP_WARNINGS_SUPPRESSION
#define CATCH_INTERNAL_ERROR(...)
auto allowThrows() const -> bool
void handleExpr(ExprLhs< T > const &expr)
AssertionHandler(StringRef const ¯oName, SourceLineInfo const &lineInfo, StringRef capturedExpression, ResultDisposition::Flags resultDisposition)
void handleExceptionNotThrownAsExpected()
void handleThrowingCallSkipped()
void handleUnexpectedExceptionNotThrown()
AssertionReaction m_reaction
void handleUnexpectedInflightException()
void handleExceptionThrownAsExpected()
void handleMessage(ResultWas::OfType resultType, StringRef const &message)
AssertionInfo m_assertionInfo
IResultCapture & m_resultCapture
void handleExpr(ITransientExpression const &expr)
auto operator==(T) const -> BinaryExpr< LhsT, RhsT const & > const
auto operator||(T) const -> BinaryExpr< LhsT, RhsT const & > const
auto operator<=(T) const -> BinaryExpr< LhsT, RhsT const & > const
BinaryExpr(bool comparisonResult, LhsT lhs, StringRef op, RhsT rhs)
auto operator>=(T) const -> BinaryExpr< LhsT, RhsT const & > const
auto operator<(T) const -> BinaryExpr< LhsT, RhsT const & > const
auto operator>(T) const -> BinaryExpr< LhsT, RhsT const & > const
auto operator!=(T) const -> BinaryExpr< LhsT, RhsT const & > const
auto operator&&(T) const -> BinaryExpr< LhsT, RhsT const & > const
void streamReconstructedExpression(std::ostream &os) const override
void captureValue(size_t index, std::string const &value)
void captureValues(size_t index, T const &value)
void captureValues(size_t index, T const &value, Ts const &... values)
Capturer(StringRef macroName, SourceLineInfo const &lineInfo, ResultWas::OfType resultType, StringRef names)
std::vector< MessageInfo > m_messages
Approx operator()(T const &value) const
void setEpsilon(double epsilon)
Approx & margin(T const &newMargin)
Approx & scale(T const &newScale)
std::string toString() const
Approx & epsilon(T const &newEpsilon)
bool equalityComparisonImpl(double other) const
void setMargin(double margin)
static auto test(int) -> decltype(std::declval< Stream & >()<< std::declval< U >(), std::true_type())
static auto test(...) -> std::false_type
std::string translate(ExceptionTranslators::const_iterator it, ExceptionTranslators::const_iterator itEnd) const override
ExceptionTranslator(std::string(*translateFunction)(T &))
ExceptionTranslatorRegistrar(std::string(*translateFunction)(T &))
auto operator!=(RhsT const &rhs) -> BinaryExpr< LhsT, RhsT const & > const
auto operator&(RhsT const &rhs) -> BinaryExpr< LhsT, RhsT const & > const
auto operator|(RhsT const &rhs) -> BinaryExpr< LhsT, RhsT const & > const
auto operator>=(RhsT const &rhs) -> BinaryExpr< LhsT, RhsT const & > const
auto operator>(RhsT const &rhs) -> BinaryExpr< LhsT, RhsT const & > const
auto operator^(RhsT const &rhs) -> BinaryExpr< LhsT, RhsT const & > const
auto operator<=(RhsT const &rhs) -> BinaryExpr< LhsT, RhsT const & > const
auto makeUnaryExpr() const -> UnaryExpr< LhsT >
auto operator&&(RhsT const &) -> BinaryExpr< LhsT, RhsT const & > const
auto operator||(RhsT const &) -> BinaryExpr< LhsT, RhsT const & > const
auto operator==(RhsT const &rhs) -> BinaryExpr< LhsT, RhsT const & > const
auto operator<(RhsT const &rhs) -> BinaryExpr< LhsT, RhsT const & > const
GeneratorException(const char *msg)
const char * what() const noexcept override final
ChunkGenerator(size_t size, GeneratorWrapper< T > generator)
GeneratorWrapper< T > m_generator
std::vector< T > const & get() const override
GeneratorWrapper< T > m_generator
FilterGenerator(P &&pred, GeneratorWrapper< T > &&generator)
T const & get() const override
std::vector< T > m_values
FixedValuesGenerator(std::initializer_list< T > values)
T const & get() const override
GeneratorUntypedBase()=default
virtual ~GeneratorUntypedBase()
std::unique_ptr< IGenerator< T > > m_generator
GeneratorWrapper(std::unique_ptr< IGenerator< T >> generator)
Generators(Gs &&... moreGenerators)
std::vector< GeneratorWrapper< T > > m_generators
void populate(GeneratorWrapper< T > &&generator)
T const & get() const override
void populate(U &&valueOrGenerator, Gs &&... moreGenerators)
IteratorGenerator(InputIterator first, InputSentinel last)
T const & get() const override
T const & get() const override
MapGenerator(F2 &&function, GeneratorWrapper< U > &&generator)
GeneratorWrapper< U > m_generator
Float const & get() const override
Catch::SimplePcg32 & m_rng
std::uniform_real_distribution< Float > m_dist
RandomFloatingGenerator(Float a, Float b)
std::uniform_int_distribution< Integer > m_dist
RandomIntegerGenerator(Integer a, Integer b)
Integer const & get() const override
Catch::SimplePcg32 & m_rng
T const & get() const override
RangeGenerator(T const &start, T const &end, T const &step)
RangeGenerator(T const &start, T const &end)
RepeatGenerator(size_t repeats, GeneratorWrapper< T > &&generator)
T const & get() const override
GeneratorWrapper< T > m_generator
std::vector< T > m_returned
T const & get() const override
SingleValueGenerator(T &&value)
GeneratorWrapper< T > m_generator
T const & get() const override
TakeGenerator(size_t target, GeneratorWrapper< T > &&generator)
LazyExpression(bool isNegated)
ITransientExpression const * m_transientExpression
friend struct AssertionStats
friend auto operator<<(std::ostream &os, LazyExpression const &lazyExpr) -> std::ostream &
LazyExpression(LazyExpression const &other)
LazyExpression & operator=(LazyExpression const &)=delete
StringRef m_matcherString
void streamReconstructedExpression(std::ostream &os) const override
MatchExpr(ArgT const &arg, MatcherT const &matcher, StringRef const &matcherString)
std::string describe() const override
bool match(std::exception const &ex) const override
ExceptionMessageMatcher(std::string const &message)
bool match(T const &item) const override
PredicateMatcher(std::function< bool(T const &)> const &elem, std::string const &descr)
std::string m_description
std::function< bool(T const &)> m_predicate
std::string describe() const override
std::string toString() const
virtual ~MatcherUntypedBase()
virtual std::string describe() const =0
std::string m_cachedToString
MatcherUntypedBase(MatcherUntypedBase const &)=default
MatcherUntypedBase()=default
NonCopyable(NonCopyable &&)=delete
NonCopyable(NonCopyable const &)=delete
NonCopyable & operator=(NonCopyable const &)=delete
T const & operator*() const
Option & operator=(Option const &_other)
T valueOr(T const &defaultValue) const
const T * operator->() const
Option(Option const &_other)
auto str() const -> std::string
auto get() -> std::ostream &
ScopedMessage(MessageBuilder const &builder)
ScopedMessage(ScopedMessage &duplicate)=delete
ScopedMessage(ScopedMessage &&old)
Section(SectionInfo const &info)
void seed(result_type seed_)
std::uint32_t result_type
friend bool operator==(SimplePcg32 const &lhs, SimplePcg32 const &rhs)
friend bool operator!=(SimplePcg32 const &lhs, SimplePcg32 const &rhs)
void discard(uint64_t skip)
SimplePcg32(result_type seed_)
constexpr auto empty() const noexcept -> bool
auto c_str() const -> char const *
static constexpr char const *const s_empty
constexpr const_iterator end() const
auto operator[](size_type index) const noexcept -> char
auto substr(size_type start, size_type length) const noexcept -> StringRef
constexpr StringRef() noexcept=default
constexpr auto isNullTerminated() const noexcept -> bool
StringRef(std::string const &stdString) noexcept
auto operator!=(StringRef const &other) const noexcept -> bool
auto operator==(StringRef const &other) const noexcept -> bool
constexpr const_iterator begin() const
auto data() const noexcept -> char const *
const char * const_iterator
constexpr auto size() const noexcept -> size_type
bool operator<(TestCase const &other) const
TestCase withName(std::string const &_newName) const
TestCaseInfo const & getTestCaseInfo() const
bool operator==(TestCase const &other) const
std::shared_ptr< ITestInvoker > test
TestCase(ITestInvoker *testCase, TestCaseInfo &&info)
TestInvokerAsMethod(void(C::*testAsMethod)()) noexcept
void(C::* m_testAsMethod)()
void invoke() const override
auto getElapsedSeconds() const -> double
auto getElapsedNanoseconds() const -> uint64_t
void streamReconstructedExpression(std::ostream &os) const override
@ warning
Warning – something is probably wrong, you should check.
@ info
For information only.
std::string convertUnknownEnumToString(E e)
std::string rawMemoryToString(const T &object)
const std::string unprintableString
std::enable_if< !std::is_enum< T >::value &&!std::is_base_of< std::exception, T >::value, std::string >::type convertUnstreamable(T const &)
std::string rawMemoryToString(const void *object, std::size_t size)
std::string rangeToString(InputIterator first, Sentinel last)
std::string stringify(const T &e)
std::unique_ptr< T > make_unique(Args &&... args)
GeneratorWrapper< std::vector< T > > chunk(size_t size, GeneratorWrapper< T > &&generator)
std::unique_ptr< GeneratorUntypedBase > GeneratorBasePtr
GeneratorWrapper< T > repeat(size_t repeats, GeneratorWrapper< T > &&generator)
auto generate(StringRef generatorName, SourceLineInfo const &lineInfo, L const &generatorExpression) -> decltype(std::declval< decltype(generatorExpression())>().get())
GeneratorWrapper< T > value(T &&value)
GeneratorWrapper< T > values(std::initializer_list< T > values)
std::enable_if< std::is_floating_point< T >::value, GeneratorWrapper< T > >::type random(T a, T b)
GeneratorWrapper< std::tuple< Ts... > > table(std::initializer_list< std::tuple< typename std::decay< Ts >::type... >> tuples)
GeneratorWrapper< T > range(T const &start, T const &end)
GeneratorWrapper< T > take(size_t target, GeneratorWrapper< T > &&generator)
auto makeGenerators(as< T >, U &&val, Gs &&... moreGenerators) -> Generators< T >
auto acquireGeneratorTracker(StringRef generatorName, SourceLineInfo const &lineInfo) -> IGeneratorTracker &
GeneratorWrapper< ResultType > from_range(Container const &cnt)
GeneratorWrapper< T > map(Func &&function, GeneratorWrapper< U > &&generator)
GeneratorWrapper< T > filter(Predicate &&pred, GeneratorWrapper< T > &&generator)
std::string finalizeDescription(const std::string &desc)
Generic::PredicateMatcher< T > Predicate(std::function< bool(T const &)> const &predicate, std::string const &description="")
Exception::ExceptionMessageMatcher Message(std::string const &message)
Floating::WithinRelMatcher WithinRel(float target)
Vector::EqualsMatcher< T, AllocComp, AllocMatch > Equals(std::vector< T, AllocComp > const &comparator)
Floating::WithinAbsMatcher WithinAbs(double target, double margin)
Floating::WithinUlpsMatcher WithinULP(float target, uint64_t maxUlpDiff)
Vector::ContainsMatcher< T, AllocComp, AllocMatch > Contains(std::vector< T, AllocComp > const &comparator)
StdString::RegexMatcher Matches(std::string const ®ex, CaseSensitive::Choice caseSensitivity=CaseSensitive::Yes)
Vector::ContainsElementMatcher< T, Alloc > VectorContains(T const &comparator)
StdString::StartsWithMatcher StartsWith(std::string const &str, CaseSensitive::Choice caseSensitivity=CaseSensitive::Yes)
Vector::UnorderedEqualsMatcher< T, AllocComp, AllocMatch > UnorderedEquals(std::vector< T, AllocComp > const &target)
StdString::EndsWithMatcher EndsWith(std::string const &str, CaseSensitive::Choice caseSensitivity=CaseSensitive::Yes)
Vector::ApproxMatcher< T, AllocComp, AllocMatch > Approx(std::vector< T, AllocComp > const &comparator)
StdString::EqualsMatcher Equals(std::string const &str, CaseSensitive::Choice caseSensitivity=CaseSensitive::Yes)
void toLowerInPlace(std::string &s)
std::string trim(std::string const &str)
Returns a new string without whitespace at the start/end.
std::vector< TestCase > const & getAllTestCasesSorted(IConfig const &config)
auto makeMatchExpr(ArgT const &arg, MatcherT const &matcher, StringRef const &matcherString) -> MatchExpr< ArgT, MatcherT >
typename std::remove_reference< typename std::remove_cv< typename std::result_of< Func(U...)>::type >::type >::type FunctionReturnType
std::vector< StringRef > splitStringRef(StringRef str, char delimiter)
void throw_exception(std::exception const &e)
void throw_runtime_error(std::string const &msg)
void formatReconstructedExpression(std::ostream &os, std::string const &lhs, StringRef op, std::string const &rhs)
bool isOk(ResultWas::OfType resultType)
bool isJustInfo(int flags)
TestCase makeTestCase(ITestInvoker *testCase, std::string const &className, NameAndTags const &nameAndTags, SourceLineInfo const &lineInfo)
T const & operator+(T const &value, StreamEndStop)
ResultDisposition::Flags resultDisposition
auto operator+=(std::string &lhs, StringRef const &sr) -> std::string &
IRegistryHub const & getRegistryHub()
void handleExpression(ITransientExpression const &expr)
bool startsWith(std::string const &s, std::string const &prefix)
std::ostream & operator<<(std::ostream &os, SourceLineInfo const &info)
void throw_logic_error(std::string const &msg)
std::vector< std::unique_ptr< IExceptionTranslator const > > ExceptionTranslators
bool shouldContinueOnFailure(int flags)
auto compareNotEqual(LhsT const &lhs, RhsT &&rhs) -> bool
bool isFalseTest(int flags)
auto getCurrentNanosecondsSinceEpoch() -> uint64_t
bool contains(std::string const &s, std::string const &infix)
bool matchTest(TestCase const &testCase, TestSpec const &testSpec, IConfig const &config)
ResultDisposition::Flags operator|(ResultDisposition::Flags lhs, ResultDisposition::Flags rhs)
auto makeTestInvoker(void(*testAsFunction)()) noexcept -> ITestInvoker *
std::vector< TestCase > filterTests(std::vector< TestCase > const &testCases, TestSpec const &testSpec, IConfig const &config)
bool shouldSuppressFailure(int flags)
Matchers::Impl::MatcherBase< std::string > StringMatcher
std::string toLower(std::string const &s)
auto getEstimatedClockResolution() -> uint64_t
IMutableRegistryHub & getMutableRegistryHub()
bool startsWith(std::string const &s, char prefix)
StringRef capturedExpression
std::shared_ptr< IReporterFactory > IReporterFactoryPtr
IContext & getCurrentContext()
bool endsWith(std::string const &s, std::string const &suffix)
std::string translateActiveException()
std::string rangeToString(std::vector< bool, Allocator > const &v)
void throw_domain_error(std::string const &msg)
std::string(*)() exceptionTranslateFunction
void handleExceptionMatchExpr(AssertionHandler &handler, std::string const &str, StringRef const &matcherString)
std::string rangeToString(Range const &range)
bool isThrowSafe(TestCase const &testCase, IConfig const &config)
auto makeStream(StringRef const &filename) -> IStream const *
IMutableContext & getCurrentMutableContext()
auto compareEqual(LhsT const &lhs, RhsT const &rhs) -> bool
std::shared_ptr< IConfig const > IConfigPtr
bool replaceInPlace(std::string &str, std::string const &replaceThis, std::string const &withThis)
IResultCapture & getResultCapture()
if(ipRecv.find(m_powerElement))
bool operator<=(timespecX const &tsL, timespecX const &tsR)
TimespecX comparison operator <= (see caveats)
bool operator>=(timespecX const &tsL, timespecX const &tsR)
TimespecX comparison operator >= (see caveats)
bool operator==(timespecX const &tsL, timespecX const &tsR)
TimespecX comparison operator == (see caveats)
bool operator<(timespecX const &tsL, timespecX const &tsR)
TimespecX comparison operator < (see caveats)
AutoReg(ITestInvoker *invoker, SourceLineInfo const &lineInfo, StringRef const &classOrMethod, NameAndTags const &nameAndTags) noexcept
Counts & operator+=(Counts const &other)
std::size_t total() const
Counts operator-(Counts const &other) const
auto operator<=(T const &lhs) -> ExprLhs< T const & >
StringRef lookup(int value) const
std::vector< std::pair< int, StringRef > > m_values
virtual T const & get() const =0
virtual ~IGenerator()=default
virtual TestSpec const & testSpec() const =0
virtual RunTests::InWhatOrder runOrder() const =0
virtual double minDuration() const =0
virtual std::vector< std::string > const & getTestsOrTags() const =0
virtual bool includeSuccessfulResults() const =0
virtual bool warnAboutNoTests() const =0
virtual int abortAfter() const =0
virtual unsigned int benchmarkResamples() const =0
virtual bool hasTestFilters() const =0
virtual std::chrono::milliseconds benchmarkWarmupTime() const =0
virtual Verbosity verbosity() const =0
virtual int benchmarkSamples() const =0
virtual bool shouldDebugBreak() const =0
virtual bool warnAboutMissingAssertions() const =0
virtual UseColour::YesOrNo useColour() const =0
virtual std::string name() const =0
virtual bool showInvisibles() const =0
virtual std::ostream & stream() const =0
virtual bool benchmarkNoAnalysis() const =0
virtual bool allowThrows() const =0
virtual ShowDurations::OrNot showDurations() const =0
virtual unsigned int rngSeed() const =0
virtual double benchmarkConfidenceInterval() const =0
virtual std::vector< std::string > const & getSectionsToRun() const =0
virtual IResultCapture * getResultCapture()=0
virtual IConfigPtr const & getConfig() const =0
virtual IRunner * getRunner()=0
virtual ~IExceptionTranslatorRegistry()
virtual std::string translateActiveException() const =0
virtual std::string translate(ExceptionTranslators::const_iterator it, ExceptionTranslators::const_iterator itEnd) const =0
virtual ~IExceptionTranslator()
virtual ~IGeneratorTracker()
virtual auto getGenerator() const -> Generators::GeneratorBasePtr const &=0
virtual void setGenerator(Generators::GeneratorBasePtr &&generator)=0
virtual auto hasGenerator() const -> bool=0
static void createContext()
virtual void setResultCapture(IResultCapture *resultCapture)=0
virtual ~IMutableContext()
virtual void setConfig(IConfigPtr const &config)=0
friend void cleanUpContext()
static IMutableContext * currentContext
virtual void setRunner(IRunner *runner)=0
Detail::EnumInfo const & registerEnum(StringRef enumName, StringRef allEnums, std::initializer_list< E > values)
virtual Detail::EnumInfo const & registerEnum(StringRef enumName, StringRef allEnums, std::vector< int > const &values)=0
virtual ~IMutableEnumValuesRegistry()
virtual void registerTest(TestCase const &testInfo)=0
virtual void registerReporter(std::string const &name, IReporterFactoryPtr const &factory)=0
virtual void registerStartupException() noexcept=0
virtual ~IMutableRegistryHub()
virtual void registerListener(IReporterFactoryPtr const &factory)=0
virtual void registerTagAlias(std::string const &alias, std::string const &tag, SourceLineInfo const &lineInfo)=0
virtual void registerTranslator(const IExceptionTranslator *translator)=0
virtual StartupExceptionRegistry const & getStartupExceptionRegistry() const =0
virtual ITagAliasRegistry const & getTagAliasRegistry() const =0
virtual IExceptionTranslatorRegistry const & getExceptionTranslatorRegistry() const =0
virtual IReporterRegistry const & getReporterRegistry() const =0
virtual ITestCaseRegistry const & getTestCaseRegistry() const =0
virtual void handleMessage(AssertionInfo const &info, ResultWas::OfType resultType, StringRef const &message, AssertionReaction &reaction)=0
virtual ~IResultCapture()
virtual void popScopedMessage(MessageInfo const &message)=0
virtual void handleFatalErrorCondition(StringRef message)=0
virtual void emplaceUnscopedMessage(MessageBuilder const &builder)=0
virtual void sectionEnded(SectionEndInfo const &endInfo)=0
virtual void handleExpr(AssertionInfo const &info, ITransientExpression const &expr, AssertionReaction &reaction)=0
virtual bool sectionStarted(SectionInfo const §ionInfo, Counts &assertions)=0
virtual void handleUnexpectedExceptionNotThrown(AssertionInfo const &info, AssertionReaction &reaction)=0
virtual void handleIncomplete(AssertionInfo const &info)=0
virtual auto acquireGeneratorTracker(StringRef generatorName, SourceLineInfo const &lineInfo) -> IGeneratorTracker &=0
virtual void pushScopedMessage(MessageInfo const &message)=0
virtual bool lastAssertionPassed()=0
virtual void assertionPassed()=0
virtual const AssertionResult * getLastResult() const =0
virtual void handleNonExpr(AssertionInfo const &info, ResultWas::OfType resultType, AssertionReaction &reaction)=0
virtual void exceptionEarlyReported()=0
virtual std::string getCurrentTestName() const =0
virtual void handleUnexpectedInflightException(AssertionInfo const &info, std::string const &message, AssertionReaction &reaction)=0
virtual void sectionEndedEarly(SectionEndInfo const &endInfo)=0
virtual bool aborting() const =0
virtual std::ostream & stream() const =0
virtual std::vector< TestCase > const & getAllTestsSorted(IConfig const &config) const =0
virtual std::vector< TestCase > const & getAllTests() const =0
virtual ~ITestCaseRegistry()
virtual void invoke() const =0
auto getResult() const -> bool
auto isBinaryExpression() const -> bool
bool m_isBinaryExpression
virtual void streamReconstructedExpression(std::ostream &os) const =0
ITransientExpression(bool isBinaryExpression, bool result)
virtual ~ITransientExpression()
std::string describe() const override
WithinAbsMatcher(double target, double margin)
bool match(double const &matchee) const override
WithinRelMatcher(double target, double epsilon)
bool match(double const &matchee) const override
std::string describe() const override
WithinUlpsMatcher(double target, uint64_t ulps, FloatingPointKind baseType)
bool match(double const &matchee) const override
std::string describe() const override
std::vector< MatcherBase< ArgT > const * > m_matchers
std::string describe() const override
bool match(ArgT const &arg) const override
std::vector< MatcherBase< ArgT > const * > m_matchers
std::string describe() const override
bool match(ArgT const &arg) const override
bool match(ArgT const &arg) const override
MatchNotOf(MatcherBase< ArgT > const &underlyingMatcher)
std::string describe() const override
MatcherBase< ArgT > const & m_underlyingMatcher
MatchNotOf< T > operator!() const
MatchAnyOf< T > operator||(MatcherBase const &other) const
MatchAllOf< T > operator&&(MatcherBase const &other) const
virtual bool match(ObjectT const &arg) const =0
std::string adjustString(std::string const &str) const
std::string caseSensitivitySuffix() const
CasedString(std::string const &str, CaseSensitive::Choice caseSensitivity)
CaseSensitive::Choice m_caseSensitivity
bool match(std::string const &source) const override
ContainsMatcher(CasedString const &comparator)
EndsWithMatcher(CasedString const &comparator)
bool match(std::string const &source) const override
bool match(std::string const &source) const override
EqualsMatcher(CasedString const &comparator)
std::string describe() const override
bool match(std::string const &matchee) const override
RegexMatcher(std::string regex, CaseSensitive::Choice caseSensitivity)
CaseSensitive::Choice m_caseSensitivity
StartsWithMatcher(CasedString const &comparator)
bool match(std::string const &source) const override
StringMatcherBase(std::string const &operation, CasedString const &comparator)
std::string describe() const override
ApproxMatcher(std::vector< T, AllocComp > const &comparator)
ApproxMatcher & epsilon(T const &newEpsilon)
std::vector< T, AllocComp > const & m_comparator
ApproxMatcher & margin(T const &newMargin)
ApproxMatcher & scale(T const &newScale)
std::string describe() const override
bool match(std::vector< T, AllocMatch > const &v) const override
ContainsElementMatcher(T const &comparator)
std::string describe() const override
bool match(std::vector< T, Alloc > const &v) const override
bool match(std::vector< T, AllocMatch > const &v) const override
ContainsMatcher(std::vector< T, AllocComp > const &comparator)
std::vector< T, AllocComp > const & m_comparator
std::string describe() const override
std::string describe() const override
bool match(std::vector< T, AllocMatch > const &v) const override
std::vector< T, AllocComp > const & m_comparator
EqualsMatcher(std::vector< T, AllocComp > const &comparator)
std::string describe() const override
UnorderedEqualsMatcher(std::vector< T, AllocComp > const &target)
bool match(std::vector< T, AllocMatch > const &vec) const override
std::vector< T, AllocComp > const & m_target
MessageBuilder(StringRef const ¯oName, SourceLineInfo const &lineInfo, ResultWas::OfType type)
static unsigned int globalCount
bool operator<(MessageInfo const &other) const
bool operator==(MessageInfo const &other) const
MessageInfo(StringRef const &_macroName, SourceLineInfo const &_lineInfo, ResultWas::OfType _type)
ReusableStringStream m_stream
RegistrarForTagAliases(char const *alias, char const *tag, SourceLineInfo const &lineInfo)
SectionInfo(SourceLineInfo const &_lineInfo, std::string const &_name, std::string const &)
SectionInfo(SourceLineInfo const &_lineInfo, std::string const &_name)
bool empty() const noexcept
SourceLineInfo & operator=(SourceLineInfo const &)=default
SourceLineInfo(char const *_file, std::size_t _line) noexcept
SourceLineInfo(SourceLineInfo &&) noexcept=default
SourceLineInfo(SourceLineInfo const &other)=default
bool operator==(SourceLineInfo const &other) const noexcept
bool operator<(SourceLineInfo const &other) const noexcept
std::string operator+() const
static std::string convert(Catch::Detail::Approx const &value)
static std::string convert(R const &range)
static std::string convert(R C::*p)
static std::string convert(U *p)
static std::string convert(T const(&arr)[SZ])
static std::string convert(bool b)
static std::string convert(char c)
static std::string convert(char *str)
static std::string convert(char const *str)
static std::string convert(char const *str)
static std::string convert(double value)
static std::string convert(float value)
static std::string convert(int value)
static std::string convert(long value)
static std::string convert(long long value)
static std::string convert(signed char c)
static std::string convert(signed char const *str)
static std::string convert(std::nullptr_t)
static std::string convert(const std::string &str)
static std::string convert(const std::wstring &wstr)
static std::string convert(unsigned char c)
static std::string convert(unsigned char const *str)
static std::string convert(unsigned int value)
static std::string convert(unsigned long value)
static std::string convert(unsigned long long value)
static std::string convert(wchar_t *str)
static std::string convert(wchar_t const *str)
static std::enable_if<!::Catch::Detail::IsStreamInsertable< Fake >::value, std::string >::type convert(const Fake &value)
static std::enable_if<::Catch::Detail::IsStreamInsertable< Fake >::value, std::string >::type convert(const Fake &value)
friend void setTags(TestCaseInfo &testCaseInfo, std::vector< std::string > tags)
std::vector< std::string > tags
std::string tagsAsString() const
std::vector< std::string > lcaseTags
bool expectedToFail() const
TestCaseInfo(std::string const &_name, std::string const &_className, std::string const &_description, std::vector< std::string > const &_tags, SourceLineInfo const &_lineInfo)
SpecialProperties properties
Totals delta(Totals const &prevTotals) const
Totals & operator+=(Totals const &other)
Totals operator-(Totals const &other) const
static true_given< decltype(std::declval< Fun >)(std::declval< Args >)...))> test(int)
static std::false_type test(...)
pluralise(std::size_t count, std::string const &label)