| 1 | // Copyright Catch2 Authors |
| 2 | // Distributed under the Boost Software License, Version 1.0. |
| 3 | // (See accompanying file LICENSE.txt or copy at |
| 4 | // https://www.boost.org/LICENSE_1_0.txt) |
| 5 | |
| 6 | // SPDX-License-Identifier: BSL-1.0 |
| 7 | |
| 8 | // Catch v3.4.0 |
| 9 | // Generated: 2023-07-13 13:23:07.577770 |
| 10 | // ---------------------------------------------------------- |
| 11 | // This file is an amalgamation of multiple different files. |
| 12 | // You probably shouldn't edit it directly. |
| 13 | // ---------------------------------------------------------- |
| 14 | #ifndef CATCH_AMALGAMATED_HPP_INCLUDED |
| 15 | #define CATCH_AMALGAMATED_HPP_INCLUDED |
| 16 | |
| 17 | |
| 18 | /** \file |
| 19 | * This is a convenience header for Catch2. It includes **all** of Catch2 headers. |
| 20 | * |
| 21 | * Generally the Catch2 users should use specific includes they need, |
| 22 | * but this header can be used instead for ease-of-experimentation, or |
| 23 | * just plain convenience, at the cost of (significantly) increased |
| 24 | * compilation times. |
| 25 | * |
| 26 | * When a new header is added to either the top level folder, or to the |
| 27 | * corresponding internal subfolder, it should be added here. Headers |
| 28 | * added to the various subparts (e.g. matchers, generators, etc...), |
| 29 | * should go their respective catch-all headers. |
| 30 | */ |
| 31 | |
| 32 | #ifndef CATCH_ALL_HPP_INCLUDED |
| 33 | #define CATCH_ALL_HPP_INCLUDED |
| 34 | |
| 35 | |
| 36 | |
| 37 | /** \file |
| 38 | * This is a convenience header for Catch2's benchmarking. It includes |
| 39 | * **all** of Catch2 headers related to benchmarking. |
| 40 | * |
| 41 | * Generally the Catch2 users should use specific includes they need, |
| 42 | * but this header can be used instead for ease-of-experimentation, or |
| 43 | * just plain convenience, at the cost of (significantly) increased |
| 44 | * compilation times. |
| 45 | * |
| 46 | * When a new header is added to either the `benchmark` folder, or to |
| 47 | * the corresponding internal (detail) subfolder, it should be added here. |
| 48 | */ |
| 49 | |
| 50 | #ifndef CATCH_BENCHMARK_ALL_HPP_INCLUDED |
| 51 | #define CATCH_BENCHMARK_ALL_HPP_INCLUDED |
| 52 | |
| 53 | |
| 54 | |
| 55 | // Adapted from donated nonius code. |
| 56 | |
| 57 | #ifndef CATCH_BENCHMARK_HPP_INCLUDED |
| 58 | #define CATCH_BENCHMARK_HPP_INCLUDED |
| 59 | |
| 60 | |
| 61 | |
| 62 | #ifndef CATCH_COMPILER_CAPABILITIES_HPP_INCLUDED |
| 63 | #define CATCH_COMPILER_CAPABILITIES_HPP_INCLUDED |
| 64 | |
| 65 | // Detect a number of compiler features - by compiler |
| 66 | // The following features are defined: |
| 67 | // |
| 68 | // CATCH_CONFIG_WINDOWS_SEH : is Windows SEH supported? |
| 69 | // CATCH_CONFIG_POSIX_SIGNALS : are POSIX signals supported? |
| 70 | // CATCH_CONFIG_DISABLE_EXCEPTIONS : Are exceptions enabled? |
| 71 | // **************** |
| 72 | // Note to maintainers: if new toggles are added please document them |
| 73 | // in configuration.md, too |
| 74 | // **************** |
| 75 | |
| 76 | // In general each macro has a _NO_<feature name> form |
| 77 | // (e.g. CATCH_CONFIG_NO_POSIX_SIGNALS) which disables the feature. |
| 78 | // Many features, at point of detection, define an _INTERNAL_ macro, so they |
| 79 | // can be combined, en-mass, with the _NO_ forms later. |
| 80 | |
| 81 | |
| 82 | |
| 83 | #ifndef CATCH_PLATFORM_HPP_INCLUDED |
| 84 | #define CATCH_PLATFORM_HPP_INCLUDED |
| 85 | |
| 86 | // See e.g.: |
| 87 | // https://opensource.apple.com/source/CarbonHeaders/CarbonHeaders-18.1/TargetConditionals.h.auto.html |
| 88 | #ifdef __APPLE__ |
| 89 | # include <TargetConditionals.h> |
| 90 | # if (defined(TARGET_OS_OSX) && TARGET_OS_OSX == 1) || \ |
| 91 | (defined(TARGET_OS_MAC) && TARGET_OS_MAC == 1) |
| 92 | # define CATCH_PLATFORM_MAC |
| 93 | # elif (defined(TARGET_OS_IPHONE) && TARGET_OS_IPHONE == 1) |
| 94 | # define CATCH_PLATFORM_IPHONE |
| 95 | # endif |
| 96 | |
| 97 | #elif defined(linux) || defined(__linux) || defined(__linux__) |
| 98 | # define CATCH_PLATFORM_LINUX |
| 99 | |
| 100 | #elif defined(WIN32) || defined(__WIN32__) || defined(_WIN32) || defined(_MSC_VER) || defined(__MINGW32__) |
| 101 | # define CATCH_PLATFORM_WINDOWS |
| 102 | |
| 103 | # if defined( WINAPI_FAMILY ) && ( WINAPI_FAMILY == WINAPI_FAMILY_APP ) |
| 104 | # define CATCH_PLATFORM_WINDOWS_UWP |
| 105 | # endif |
| 106 | |
| 107 | #elif defined(__ORBIS__) || defined(__PROSPERO__) |
| 108 | # define CATCH_PLATFORM_PLAYSTATION |
| 109 | |
| 110 | #endif |
| 111 | |
| 112 | #endif // CATCH_PLATFORM_HPP_INCLUDED |
| 113 | |
| 114 | #ifdef __cplusplus |
| 115 | |
| 116 | # if (__cplusplus >= 201402L) || (defined(_MSVC_LANG) && _MSVC_LANG >= 201402L) |
| 117 | # define CATCH_CPP14_OR_GREATER |
| 118 | # endif |
| 119 | |
| 120 | # if (__cplusplus >= 201703L) || (defined(_MSVC_LANG) && _MSVC_LANG >= 201703L) |
| 121 | # define CATCH_CPP17_OR_GREATER |
| 122 | # endif |
| 123 | |
| 124 | #endif |
| 125 | |
| 126 | // Only GCC compiler should be used in this block, so other compilers trying to |
| 127 | // mask themselves as GCC should be ignored. |
| 128 | #if defined(__GNUC__) && !defined(__clang__) && !defined(__ICC) && !defined(__CUDACC__) && !defined(__LCC__) && !defined(__NVCOMPILER) |
| 129 | # define CATCH_INTERNAL_START_WARNINGS_SUPPRESSION _Pragma( "GCC diagnostic push" ) |
| 130 | # define CATCH_INTERNAL_STOP_WARNINGS_SUPPRESSION _Pragma( "GCC diagnostic pop" ) |
| 131 | |
| 132 | // This only works on GCC 9+. so we have to also add a global suppression of Wparentheses |
| 133 | // for older versions of GCC. |
| 134 | # define CATCH_INTERNAL_SUPPRESS_PARENTHESES_WARNINGS \ |
| 135 | _Pragma( "GCC diagnostic ignored \"-Wparentheses\"" ) |
| 136 | |
| 137 | # define CATCH_INTERNAL_SUPPRESS_UNUSED_RESULT \ |
| 138 | _Pragma( "GCC diagnostic ignored \"-Wunused-result\"" ) |
| 139 | |
| 140 | # define CATCH_INTERNAL_SUPPRESS_UNUSED_VARIABLE_WARNINGS \ |
| 141 | _Pragma( "GCC diagnostic ignored \"-Wunused-variable\"" ) |
| 142 | |
| 143 | # define CATCH_INTERNAL_SUPPRESS_USELESS_CAST_WARNINGS \ |
| 144 | _Pragma( "GCC diagnostic ignored \"-Wuseless-cast\"" ) |
| 145 | |
| 146 | # define CATCH_INTERNAL_SUPPRESS_SHADOW_WARNINGS \ |
| 147 | _Pragma( "GCC diagnostic ignored \"-Wshadow\"" ) |
| 148 | |
| 149 | # define CATCH_INTERNAL_IGNORE_BUT_WARN(...) (void)__builtin_constant_p(__VA_ARGS__) |
| 150 | |
| 151 | #endif |
| 152 | |
| 153 | #if defined(__NVCOMPILER) |
| 154 | # define CATCH_INTERNAL_START_WARNINGS_SUPPRESSION _Pragma( "diag push" ) |
| 155 | # define CATCH_INTERNAL_STOP_WARNINGS_SUPPRESSION _Pragma( "diag pop" ) |
| 156 | # define CATCH_INTERNAL_SUPPRESS_UNUSED_VARIABLE_WARNINGS _Pragma( "diag_suppress declared_but_not_referenced" ) |
| 157 | #endif |
| 158 | |
| 159 | #if defined(__CUDACC__) && !defined(__clang__) |
| 160 | # ifdef __NVCC_DIAG_PRAGMA_SUPPORT__ |
| 161 | // New pragmas introduced in CUDA 11.5+ |
| 162 | # define CATCH_INTERNAL_START_WARNINGS_SUPPRESSION _Pragma( "nv_diagnostic push" ) |
| 163 | # define CATCH_INTERNAL_STOP_WARNINGS_SUPPRESSION _Pragma( "nv_diagnostic pop" ) |
| 164 | # define CATCH_INTERNAL_SUPPRESS_UNUSED_VARIABLE_WARNINGS _Pragma( "nv_diag_suppress 177" ) |
| 165 | # else |
| 166 | # define CATCH_INTERNAL_SUPPRESS_UNUSED_VARIABLE_WARNINGS _Pragma( "diag_suppress 177" ) |
| 167 | # endif |
| 168 | #endif |
| 169 | |
| 170 | // clang-cl defines _MSC_VER as well as __clang__, which could cause the |
| 171 | // start/stop internal suppression macros to be double defined. |
| 172 | #if defined(__clang__) && !defined(_MSC_VER) |
| 173 | |
| 174 | # define CATCH_INTERNAL_START_WARNINGS_SUPPRESSION _Pragma( "clang diagnostic push" ) |
| 175 | # define CATCH_INTERNAL_STOP_WARNINGS_SUPPRESSION _Pragma( "clang diagnostic pop" ) |
| 176 | |
| 177 | #endif // __clang__ && !_MSC_VER |
| 178 | |
| 179 | #if defined(__clang__) |
| 180 | |
| 181 | // As of this writing, IBM XL's implementation of __builtin_constant_p has a bug |
| 182 | // which results in calls to destructors being emitted for each temporary, |
| 183 | // without a matching initialization. In practice, this can result in something |
| 184 | // like `std::string::~string` being called on an uninitialized value. |
| 185 | // |
| 186 | // For example, this code will likely segfault under IBM XL: |
| 187 | // ``` |
| 188 | // REQUIRE(std::string("12") + "34" == "1234") |
| 189 | // ``` |
| 190 | // |
| 191 | // Similarly, NVHPC's implementation of `__builtin_constant_p` has a bug which |
| 192 | // results in calls to the immediately evaluated lambda expressions to be |
| 193 | // reported as unevaluated lambdas. |
| 194 | // https://developer.nvidia.com/nvidia_bug/3321845. |
| 195 | // |
| 196 | // Therefore, `CATCH_INTERNAL_IGNORE_BUT_WARN` is not implemented. |
| 197 | # if !defined(__ibmxl__) && !defined(__CUDACC__) && !defined( __NVCOMPILER ) |
| 198 | # define CATCH_INTERNAL_IGNORE_BUT_WARN(...) (void)__builtin_constant_p(__VA_ARGS__) /* NOLINT(cppcoreguidelines-pro-type-vararg, hicpp-vararg) */ |
| 199 | # endif |
| 200 | |
| 201 | |
| 202 | # define CATCH_INTERNAL_SUPPRESS_GLOBALS_WARNINGS \ |
| 203 | _Pragma( "clang diagnostic ignored \"-Wexit-time-destructors\"" ) \ |
| 204 | _Pragma( "clang diagnostic ignored \"-Wglobal-constructors\"") |
| 205 | |
| 206 | # define CATCH_INTERNAL_SUPPRESS_PARENTHESES_WARNINGS \ |
| 207 | _Pragma( "clang diagnostic ignored \"-Wparentheses\"" ) |
| 208 | |
| 209 | # define CATCH_INTERNAL_SUPPRESS_UNUSED_VARIABLE_WARNINGS \ |
| 210 | _Pragma( "clang diagnostic ignored \"-Wunused-variable\"" ) |
| 211 | |
| 212 | # define CATCH_INTERNAL_SUPPRESS_ZERO_VARIADIC_WARNINGS \ |
| 213 | _Pragma( "clang diagnostic ignored \"-Wgnu-zero-variadic-macro-arguments\"" ) |
| 214 | |
| 215 | # define CATCH_INTERNAL_SUPPRESS_UNUSED_TEMPLATE_WARNINGS \ |
| 216 | _Pragma( "clang diagnostic ignored \"-Wunused-template\"" ) |
| 217 | |
| 218 | # define CATCH_INTERNAL_SUPPRESS_COMMA_WARNINGS \ |
| 219 | _Pragma( "clang diagnostic ignored \"-Wcomma\"" ) |
| 220 | |
| 221 | # define CATCH_INTERNAL_SUPPRESS_SHADOW_WARNINGS \ |
| 222 | _Pragma( "clang diagnostic ignored \"-Wshadow\"" ) |
| 223 | |
| 224 | #endif // __clang__ |
| 225 | |
| 226 | |
| 227 | //////////////////////////////////////////////////////////////////////////////// |
| 228 | // We know some environments not to support full POSIX signals |
| 229 | #if defined( CATCH_PLATFORM_WINDOWS ) || \ |
| 230 | defined( CATCH_PLATFORM_PLAYSTATION ) || \ |
| 231 | defined( __CYGWIN__ ) || \ |
| 232 | defined( __QNX__ ) || \ |
| 233 | defined( __EMSCRIPTEN__ ) || \ |
| 234 | defined( __DJGPP__ ) || \ |
| 235 | defined( __OS400__ ) |
| 236 | # define CATCH_INTERNAL_CONFIG_NO_POSIX_SIGNALS |
| 237 | #else |
| 238 | # define CATCH_INTERNAL_CONFIG_POSIX_SIGNALS |
| 239 | #endif |
| 240 | |
| 241 | //////////////////////////////////////////////////////////////////////////////// |
| 242 | // Assume that some platforms do not support getenv. |
| 243 | #if defined(CATCH_PLATFORM_WINDOWS_UWP) || defined(CATCH_PLATFORM_PLAYSTATION) |
| 244 | # define CATCH_INTERNAL_CONFIG_NO_GETENV |
| 245 | #else |
| 246 | # define CATCH_INTERNAL_CONFIG_GETENV |
| 247 | #endif |
| 248 | |
| 249 | //////////////////////////////////////////////////////////////////////////////// |
| 250 | // Android somehow still does not support std::to_string |
| 251 | #if defined(__ANDROID__) |
| 252 | # define CATCH_INTERNAL_CONFIG_NO_CPP11_TO_STRING |
| 253 | #endif |
| 254 | |
| 255 | //////////////////////////////////////////////////////////////////////////////// |
| 256 | // Not all Windows environments support SEH properly |
| 257 | #if defined(__MINGW32__) |
| 258 | # define CATCH_INTERNAL_CONFIG_NO_WINDOWS_SEH |
| 259 | #endif |
| 260 | |
| 261 | //////////////////////////////////////////////////////////////////////////////// |
| 262 | // PS4 |
| 263 | #if defined(__ORBIS__) |
| 264 | # define CATCH_INTERNAL_CONFIG_NO_NEW_CAPTURE |
| 265 | #endif |
| 266 | |
| 267 | //////////////////////////////////////////////////////////////////////////////// |
| 268 | // Cygwin |
| 269 | #ifdef __CYGWIN__ |
| 270 | |
| 271 | // Required for some versions of Cygwin to declare gettimeofday |
| 272 | // see: http://stackoverflow.com/questions/36901803/gettimeofday-not-declared-in-this-scope-cygwin |
| 273 | # define _BSD_SOURCE |
| 274 | // some versions of cygwin (most) do not support std::to_string. Use the libstd check. |
| 275 | // https://gcc.gnu.org/onlinedocs/gcc-4.8.2/libstdc++/api/a01053_source.html line 2812-2813 |
| 276 | # if !((__cplusplus >= 201103L) && defined(_GLIBCXX_USE_C99) \ |
| 277 | && !defined(_GLIBCXX_HAVE_BROKEN_VSWPRINTF)) |
| 278 | |
| 279 | # define CATCH_INTERNAL_CONFIG_NO_CPP11_TO_STRING |
| 280 | |
| 281 | # endif |
| 282 | #endif // __CYGWIN__ |
| 283 | |
| 284 | //////////////////////////////////////////////////////////////////////////////// |
| 285 | // Visual C++ |
| 286 | #if defined(_MSC_VER) |
| 287 | |
| 288 | // We want to defer to nvcc-specific warning suppression if we are compiled |
| 289 | // with nvcc masquerading for MSVC. |
| 290 | # if !defined( __CUDACC__ ) |
| 291 | # define CATCH_INTERNAL_START_WARNINGS_SUPPRESSION \ |
| 292 | __pragma( warning( push ) ) |
| 293 | # define CATCH_INTERNAL_STOP_WARNINGS_SUPPRESSION \ |
| 294 | __pragma( warning( pop ) ) |
| 295 | # endif |
| 296 | |
| 297 | // Universal Windows platform does not support SEH |
| 298 | // Or console colours (or console at all...) |
| 299 | # if defined(CATCH_PLATFORM_WINDOWS_UWP) |
| 300 | # define CATCH_INTERNAL_CONFIG_NO_COLOUR_WIN32 |
| 301 | # else |
| 302 | # define CATCH_INTERNAL_CONFIG_WINDOWS_SEH |
| 303 | # endif |
| 304 | |
| 305 | // MSVC traditional preprocessor needs some workaround for __VA_ARGS__ |
| 306 | // _MSVC_TRADITIONAL == 0 means new conformant preprocessor |
| 307 | // _MSVC_TRADITIONAL == 1 means old traditional non-conformant preprocessor |
| 308 | # if !defined(__clang__) // Handle Clang masquerading for msvc |
| 309 | # if !defined(_MSVC_TRADITIONAL) || (defined(_MSVC_TRADITIONAL) && _MSVC_TRADITIONAL) |
| 310 | # define CATCH_INTERNAL_CONFIG_TRADITIONAL_MSVC_PREPROCESSOR |
| 311 | # endif // MSVC_TRADITIONAL |
| 312 | # endif // __clang__ |
| 313 | |
| 314 | #endif // _MSC_VER |
| 315 | |
| 316 | #if defined(_REENTRANT) || defined(_MSC_VER) |
| 317 | // Enable async processing, as -pthread is specified or no additional linking is required |
| 318 | # define CATCH_INTERNAL_CONFIG_USE_ASYNC |
| 319 | #endif // _MSC_VER |
| 320 | |
| 321 | //////////////////////////////////////////////////////////////////////////////// |
| 322 | // Check if we are compiled with -fno-exceptions or equivalent |
| 323 | #if defined(__EXCEPTIONS) || defined(__cpp_exceptions) || defined(_CPPUNWIND) |
| 324 | # define CATCH_INTERNAL_CONFIG_EXCEPTIONS_ENABLED |
| 325 | #endif |
| 326 | |
| 327 | |
| 328 | //////////////////////////////////////////////////////////////////////////////// |
| 329 | // Embarcadero C++Build |
| 330 | #if defined(__BORLANDC__) |
| 331 | #define CATCH_INTERNAL_CONFIG_POLYFILL_ISNAN |
| 332 | #endif |
| 333 | |
| 334 | //////////////////////////////////////////////////////////////////////////////// |
| 335 | |
| 336 | // RTX is a special version of Windows that is real time. |
| 337 | // This means that it is detected as Windows, but does not provide |
| 338 | // the same set of capabilities as real Windows does. |
| 339 | #if defined(UNDER_RTSS) || defined(RTX64_BUILD) |
| 340 | #define CATCH_INTERNAL_CONFIG_NO_WINDOWS_SEH |
| 341 | #define CATCH_INTERNAL_CONFIG_NO_ASYNC |
| 342 | #define CATCH_INTERNAL_CONFIG_NO_COLOUR_WIN32 |
| 343 | #endif |
| 344 | |
| 345 | #if !defined(_GLIBCXX_USE_C99_MATH_TR1) |
| 346 | #define CATCH_INTERNAL_CONFIG_GLOBAL_NEXTAFTER |
| 347 | #endif |
| 348 | |
| 349 | // Various stdlib support checks that require __has_include |
| 350 | #if defined(__has_include) |
| 351 | // Check if string_view is available and usable |
| 352 | #if __has_include(<string_view>) && defined(CATCH_CPP17_OR_GREATER) |
| 353 | # define CATCH_INTERNAL_CONFIG_CPP17_STRING_VIEW |
| 354 | #endif |
| 355 | |
| 356 | // Check if optional is available and usable |
| 357 | # if __has_include(<optional>) && defined(CATCH_CPP17_OR_GREATER) |
| 358 | # define CATCH_INTERNAL_CONFIG_CPP17_OPTIONAL |
| 359 | # endif // __has_include(<optional>) && defined(CATCH_CPP17_OR_GREATER) |
| 360 | |
| 361 | // Check if byte is available and usable |
| 362 | # if __has_include(<cstddef>) && defined(CATCH_CPP17_OR_GREATER) |
| 363 | # include <cstddef> |
| 364 | # if defined(__cpp_lib_byte) && (__cpp_lib_byte > 0) |
| 365 | # define CATCH_INTERNAL_CONFIG_CPP17_BYTE |
| 366 | # endif |
| 367 | # endif // __has_include(<cstddef>) && defined(CATCH_CPP17_OR_GREATER) |
| 368 | |
| 369 | // Check if variant is available and usable |
| 370 | # if __has_include(<variant>) && defined(CATCH_CPP17_OR_GREATER) |
| 371 | # if defined(__clang__) && (__clang_major__ < 8) |
| 372 | // work around clang bug with libstdc++ https://bugs.llvm.org/show_bug.cgi?id=31852 |
| 373 | // fix should be in clang 8, workaround in libstdc++ 8.2 |
| 374 | # include <ciso646> |
| 375 | # if defined(__GLIBCXX__) && defined(_GLIBCXX_RELEASE) && (_GLIBCXX_RELEASE < 9) |
| 376 | # define CATCH_CONFIG_NO_CPP17_VARIANT |
| 377 | # else |
| 378 | # define CATCH_INTERNAL_CONFIG_CPP17_VARIANT |
| 379 | # endif // defined(__GLIBCXX__) && defined(_GLIBCXX_RELEASE) && (_GLIBCXX_RELEASE < 9) |
| 380 | # else |
| 381 | # define CATCH_INTERNAL_CONFIG_CPP17_VARIANT |
| 382 | # endif // defined(__clang__) && (__clang_major__ < 8) |
| 383 | # endif // __has_include(<variant>) && defined(CATCH_CPP17_OR_GREATER) |
| 384 | #endif // defined(__has_include) |
| 385 | |
| 386 | |
| 387 | #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) |
| 388 | # define CATCH_CONFIG_WINDOWS_SEH |
| 389 | #endif |
| 390 | // This is set by default, because we assume that unix compilers are posix-signal-compatible by default. |
| 391 | #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) |
| 392 | # define CATCH_CONFIG_POSIX_SIGNALS |
| 393 | #endif |
| 394 | |
| 395 | #if defined(CATCH_INTERNAL_CONFIG_GETENV) && !defined(CATCH_INTERNAL_CONFIG_NO_GETENV) && !defined(CATCH_CONFIG_NO_GETENV) && !defined(CATCH_CONFIG_GETENV) |
| 396 | # define CATCH_CONFIG_GETENV |
| 397 | #endif |
| 398 | |
| 399 | #if !defined(CATCH_INTERNAL_CONFIG_NO_CPP11_TO_STRING) && !defined(CATCH_CONFIG_NO_CPP11_TO_STRING) && !defined(CATCH_CONFIG_CPP11_TO_STRING) |
| 400 | # define CATCH_CONFIG_CPP11_TO_STRING |
| 401 | #endif |
| 402 | |
| 403 | #if defined(CATCH_INTERNAL_CONFIG_CPP17_OPTIONAL) && !defined(CATCH_CONFIG_NO_CPP17_OPTIONAL) && !defined(CATCH_CONFIG_CPP17_OPTIONAL) |
| 404 | # define CATCH_CONFIG_CPP17_OPTIONAL |
| 405 | #endif |
| 406 | |
| 407 | #if defined(CATCH_INTERNAL_CONFIG_CPP17_STRING_VIEW) && !defined(CATCH_CONFIG_NO_CPP17_STRING_VIEW) && !defined(CATCH_CONFIG_CPP17_STRING_VIEW) |
| 408 | # define CATCH_CONFIG_CPP17_STRING_VIEW |
| 409 | #endif |
| 410 | |
| 411 | #if defined(CATCH_INTERNAL_CONFIG_CPP17_VARIANT) && !defined(CATCH_CONFIG_NO_CPP17_VARIANT) && !defined(CATCH_CONFIG_CPP17_VARIANT) |
| 412 | # define CATCH_CONFIG_CPP17_VARIANT |
| 413 | #endif |
| 414 | |
| 415 | #if defined(CATCH_INTERNAL_CONFIG_CPP17_BYTE) && !defined(CATCH_CONFIG_NO_CPP17_BYTE) && !defined(CATCH_CONFIG_CPP17_BYTE) |
| 416 | # define CATCH_CONFIG_CPP17_BYTE |
| 417 | #endif |
| 418 | |
| 419 | |
| 420 | #if defined(CATCH_CONFIG_EXPERIMENTAL_REDIRECT) |
| 421 | # define CATCH_INTERNAL_CONFIG_NEW_CAPTURE |
| 422 | #endif |
| 423 | |
| 424 | #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) |
| 425 | # define CATCH_CONFIG_NEW_CAPTURE |
| 426 | #endif |
| 427 | |
| 428 | #if !defined( CATCH_INTERNAL_CONFIG_EXCEPTIONS_ENABLED ) && \ |
| 429 | !defined( CATCH_CONFIG_DISABLE_EXCEPTIONS ) && \ |
| 430 | !defined( CATCH_CONFIG_NO_DISABLE_EXCEPTIONS ) |
| 431 | # define CATCH_CONFIG_DISABLE_EXCEPTIONS |
| 432 | #endif |
| 433 | |
| 434 | #if defined(CATCH_INTERNAL_CONFIG_POLYFILL_ISNAN) && !defined(CATCH_CONFIG_NO_POLYFILL_ISNAN) && !defined(CATCH_CONFIG_POLYFILL_ISNAN) |
| 435 | # define CATCH_CONFIG_POLYFILL_ISNAN |
| 436 | #endif |
| 437 | |
| 438 | #if defined(CATCH_INTERNAL_CONFIG_USE_ASYNC) && !defined(CATCH_INTERNAL_CONFIG_NO_ASYNC) && !defined(CATCH_CONFIG_NO_USE_ASYNC) && !defined(CATCH_CONFIG_USE_ASYNC) |
| 439 | # define CATCH_CONFIG_USE_ASYNC |
| 440 | #endif |
| 441 | |
| 442 | #if defined(CATCH_INTERNAL_CONFIG_GLOBAL_NEXTAFTER) && !defined(CATCH_CONFIG_NO_GLOBAL_NEXTAFTER) && !defined(CATCH_CONFIG_GLOBAL_NEXTAFTER) |
| 443 | # define CATCH_CONFIG_GLOBAL_NEXTAFTER |
| 444 | #endif |
| 445 | |
| 446 | |
| 447 | // Even if we do not think the compiler has that warning, we still have |
| 448 | // to provide a macro that can be used by the code. |
| 449 | #if !defined(CATCH_INTERNAL_START_WARNINGS_SUPPRESSION) |
| 450 | # define CATCH_INTERNAL_START_WARNINGS_SUPPRESSION |
| 451 | #endif |
| 452 | #if !defined(CATCH_INTERNAL_STOP_WARNINGS_SUPPRESSION) |
| 453 | # define CATCH_INTERNAL_STOP_WARNINGS_SUPPRESSION |
| 454 | #endif |
| 455 | #if !defined(CATCH_INTERNAL_SUPPRESS_PARENTHESES_WARNINGS) |
| 456 | # define CATCH_INTERNAL_SUPPRESS_PARENTHESES_WARNINGS |
| 457 | #endif |
| 458 | #if !defined(CATCH_INTERNAL_SUPPRESS_GLOBALS_WARNINGS) |
| 459 | # define CATCH_INTERNAL_SUPPRESS_GLOBALS_WARNINGS |
| 460 | #endif |
| 461 | #if !defined(CATCH_INTERNAL_SUPPRESS_UNUSED_RESULT) |
| 462 | # define CATCH_INTERNAL_SUPPRESS_UNUSED_RESULT |
| 463 | #endif |
| 464 | #if !defined(CATCH_INTERNAL_SUPPRESS_UNUSED_VARIABLE_WARNINGS) |
| 465 | # define CATCH_INTERNAL_SUPPRESS_UNUSED_VARIABLE_WARNINGS |
| 466 | #endif |
| 467 | #if !defined(CATCH_INTERNAL_SUPPRESS_USELESS_CAST_WARNINGS) |
| 468 | # define CATCH_INTERNAL_SUPPRESS_USELESS_CAST_WARNINGS |
| 469 | #endif |
| 470 | #if !defined(CATCH_INTERNAL_SUPPRESS_ZERO_VARIADIC_WARNINGS) |
| 471 | # define CATCH_INTERNAL_SUPPRESS_ZERO_VARIADIC_WARNINGS |
| 472 | #endif |
| 473 | #if !defined( CATCH_INTERNAL_SUPPRESS_UNUSED_TEMPLATE_WARNINGS ) |
| 474 | # define CATCH_INTERNAL_SUPPRESS_UNUSED_TEMPLATE_WARNINGS |
| 475 | #endif |
| 476 | #if !defined( CATCH_INTERNAL_SUPPRESS_COMMA_WARNINGS ) |
| 477 | # define CATCH_INTERNAL_SUPPRESS_COMMA_WARNINGS |
| 478 | #endif |
| 479 | #if !defined( CATCH_INTERNAL_SUPPRESS_SHADOW_WARNINGS ) |
| 480 | # define CATCH_INTERNAL_SUPPRESS_SHADOW_WARNINGS |
| 481 | #endif |
| 482 | |
| 483 | |
| 484 | // The goal of this macro is to avoid evaluation of the arguments, but |
| 485 | // still have the compiler warn on problems inside... |
| 486 | #if !defined(CATCH_INTERNAL_IGNORE_BUT_WARN) |
| 487 | # define CATCH_INTERNAL_IGNORE_BUT_WARN(...) |
| 488 | #endif |
| 489 | |
| 490 | #if defined(__APPLE__) && defined(__apple_build_version__) && (__clang_major__ < 10) |
| 491 | # undef CATCH_INTERNAL_SUPPRESS_UNUSED_TEMPLATE_WARNINGS |
| 492 | #elif defined(__clang__) && (__clang_major__ < 5) |
| 493 | # undef CATCH_INTERNAL_SUPPRESS_UNUSED_TEMPLATE_WARNINGS |
| 494 | #endif |
| 495 | |
| 496 | |
| 497 | #if defined(CATCH_CONFIG_DISABLE_EXCEPTIONS) |
| 498 | #define CATCH_TRY if ((true)) |
| 499 | #define CATCH_CATCH_ALL if ((false)) |
| 500 | #define CATCH_CATCH_ANON(type) if ((false)) |
| 501 | #else |
| 502 | #define CATCH_TRY try |
| 503 | #define CATCH_CATCH_ALL catch (...) |
| 504 | #define CATCH_CATCH_ANON(type) catch (type) |
| 505 | #endif |
| 506 | |
| 507 | #if defined(CATCH_INTERNAL_CONFIG_TRADITIONAL_MSVC_PREPROCESSOR) && !defined(CATCH_CONFIG_NO_TRADITIONAL_MSVC_PREPROCESSOR) && !defined(CATCH_CONFIG_TRADITIONAL_MSVC_PREPROCESSOR) |
| 508 | #define CATCH_CONFIG_TRADITIONAL_MSVC_PREPROCESSOR |
| 509 | #endif |
| 510 | |
| 511 | #if defined( CATCH_PLATFORM_WINDOWS ) && \ |
| 512 | !defined( CATCH_CONFIG_COLOUR_WIN32 ) && \ |
| 513 | !defined( CATCH_CONFIG_NO_COLOUR_WIN32 ) && \ |
| 514 | !defined( CATCH_INTERNAL_CONFIG_NO_COLOUR_WIN32 ) |
| 515 | # define CATCH_CONFIG_COLOUR_WIN32 |
| 516 | #endif |
| 517 | |
| 518 | #if defined( CATCH_CONFIG_SHARED_LIBRARY ) && defined( _MSC_VER ) && \ |
| 519 | !defined( CATCH_CONFIG_STATIC ) |
| 520 | # ifdef Catch2_EXPORTS |
| 521 | # define CATCH_EXPORT //__declspec( dllexport ) // not needed |
| 522 | # else |
| 523 | # define CATCH_EXPORT __declspec( dllimport ) |
| 524 | # endif |
| 525 | #else |
| 526 | # define CATCH_EXPORT |
| 527 | #endif |
| 528 | |
| 529 | #endif // CATCH_COMPILER_CAPABILITIES_HPP_INCLUDED |
| 530 | |
| 531 | |
| 532 | #ifndef CATCH_CONTEXT_HPP_INCLUDED |
| 533 | #define CATCH_CONTEXT_HPP_INCLUDED |
| 534 | |
| 535 | |
| 536 | namespace Catch { |
| 537 | |
| 538 | class IResultCapture; |
| 539 | class IConfig; |
| 540 | |
| 541 | class Context { |
| 542 | IConfig const* m_config = nullptr; |
| 543 | IResultCapture* m_resultCapture = nullptr; |
| 544 | |
| 545 | CATCH_EXPORT static Context* currentContext; |
| 546 | friend Context& getCurrentMutableContext(); |
| 547 | friend Context const& getCurrentContext(); |
| 548 | static void createContext(); |
| 549 | friend void cleanUpContext(); |
| 550 | |
| 551 | public: |
| 552 | IResultCapture* getResultCapture() const { return m_resultCapture; } |
| 553 | IConfig const* getConfig() const { return m_config; } |
| 554 | void setResultCapture( IResultCapture* resultCapture ); |
| 555 | void setConfig( IConfig const* config ); |
| 556 | }; |
| 557 | |
| 558 | Context& getCurrentMutableContext(); |
| 559 | |
| 560 | inline Context const& getCurrentContext() { |
| 561 | // We duplicate the logic from `getCurrentMutableContext` here, |
| 562 | // to avoid paying the call overhead in debug mode. |
| 563 | if ( !Context::currentContext ) { Context::createContext(); } |
| 564 | // NOLINTNEXTLINE(clang-analyzer-core.uninitialized.UndefReturn) |
| 565 | return *Context::currentContext; |
| 566 | } |
| 567 | |
| 568 | void cleanUpContext(); |
| 569 | |
| 570 | class SimplePcg32; |
| 571 | SimplePcg32& sharedRng(); |
| 572 | } |
| 573 | |
| 574 | #endif // CATCH_CONTEXT_HPP_INCLUDED |
| 575 | |
| 576 | |
| 577 | #ifndef CATCH_MOVE_AND_FORWARD_HPP_INCLUDED |
| 578 | #define CATCH_MOVE_AND_FORWARD_HPP_INCLUDED |
| 579 | |
| 580 | #include <type_traits> |
| 581 | |
| 582 | //! Replacement for std::move with better compile time performance |
| 583 | #define CATCH_MOVE(...) static_cast<std::remove_reference_t<decltype(__VA_ARGS__)>&&>(__VA_ARGS__) |
| 584 | |
| 585 | //! Replacement for std::forward with better compile time performance |
| 586 | #define CATCH_FORWARD(...) static_cast<decltype(__VA_ARGS__)&&>(__VA_ARGS__) |
| 587 | |
| 588 | #endif // CATCH_MOVE_AND_FORWARD_HPP_INCLUDED |
| 589 | |
| 590 | |
| 591 | #ifndef CATCH_TEST_FAILURE_EXCEPTION_HPP_INCLUDED |
| 592 | #define CATCH_TEST_FAILURE_EXCEPTION_HPP_INCLUDED |
| 593 | |
| 594 | namespace Catch { |
| 595 | |
| 596 | //! Used to signal that an assertion macro failed |
| 597 | struct TestFailureException{}; |
| 598 | //! Used to signal that the remainder of a test should be skipped |
| 599 | struct TestSkipException {}; |
| 600 | |
| 601 | /** |
| 602 | * Outlines throwing of `TestFailureException` into a single TU |
| 603 | * |
| 604 | * Also handles `CATCH_CONFIG_DISABLE_EXCEPTIONS` for callers. |
| 605 | */ |
| 606 | [[noreturn]] void throw_test_failure_exception(); |
| 607 | |
| 608 | /** |
| 609 | * Outlines throwing of `TestSkipException` into a single TU |
| 610 | * |
| 611 | * Also handles `CATCH_CONFIG_DISABLE_EXCEPTIONS` for callers. |
| 612 | */ |
| 613 | [[noreturn]] void throw_test_skip_exception(); |
| 614 | |
| 615 | } // namespace Catch |
| 616 | |
| 617 | #endif // CATCH_TEST_FAILURE_EXCEPTION_HPP_INCLUDED |
| 618 | |
| 619 | |
| 620 | #ifndef CATCH_UNIQUE_NAME_HPP_INCLUDED |
| 621 | #define CATCH_UNIQUE_NAME_HPP_INCLUDED |
| 622 | |
| 623 | |
| 624 | |
| 625 | |
| 626 | /** \file |
| 627 | * Wrapper for the CONFIG configuration option |
| 628 | * |
| 629 | * When generating internal unique names, there are two options. Either |
| 630 | * we mix in the current line number, or mix in an incrementing number. |
| 631 | * We prefer the latter, using `__COUNTER__`, but users might want to |
| 632 | * use the former. |
| 633 | */ |
| 634 | |
| 635 | #ifndef CATCH_CONFIG_COUNTER_HPP_INCLUDED |
| 636 | #define CATCH_CONFIG_COUNTER_HPP_INCLUDED |
| 637 | |
| 638 | |
| 639 | #if ( !defined(__JETBRAINS_IDE__) || __JETBRAINS_IDE__ >= 20170300L ) |
| 640 | #define CATCH_INTERNAL_CONFIG_COUNTER |
| 641 | #endif |
| 642 | |
| 643 | #if defined( CATCH_INTERNAL_CONFIG_COUNTER ) && \ |
| 644 | !defined( CATCH_CONFIG_NO_COUNTER ) && \ |
| 645 | !defined( CATCH_CONFIG_COUNTER ) |
| 646 | # define CATCH_CONFIG_COUNTER |
| 647 | #endif |
| 648 | |
| 649 | |
| 650 | #endif // CATCH_CONFIG_COUNTER_HPP_INCLUDED |
| 651 | #define INTERNAL_CATCH_UNIQUE_NAME_LINE2( name, line ) name##line |
| 652 | #define INTERNAL_CATCH_UNIQUE_NAME_LINE( name, line ) INTERNAL_CATCH_UNIQUE_NAME_LINE2( name, line ) |
| 653 | #ifdef CATCH_CONFIG_COUNTER |
| 654 | # define INTERNAL_CATCH_UNIQUE_NAME( name ) INTERNAL_CATCH_UNIQUE_NAME_LINE( name, __COUNTER__ ) |
| 655 | #else |
| 656 | # define INTERNAL_CATCH_UNIQUE_NAME( name ) INTERNAL_CATCH_UNIQUE_NAME_LINE( name, __LINE__ ) |
| 657 | #endif |
| 658 | |
| 659 | #endif // CATCH_UNIQUE_NAME_HPP_INCLUDED |
| 660 | |
| 661 | |
| 662 | #ifndef CATCH_INTERFACES_CAPTURE_HPP_INCLUDED |
| 663 | #define CATCH_INTERFACES_CAPTURE_HPP_INCLUDED |
| 664 | |
| 665 | #include <string> |
| 666 | #include <chrono> |
| 667 | |
| 668 | |
| 669 | |
| 670 | #ifndef CATCH_STRINGREF_HPP_INCLUDED |
| 671 | #define CATCH_STRINGREF_HPP_INCLUDED |
| 672 | |
| 673 | #include <cstddef> |
| 674 | #include <string> |
| 675 | #include <iosfwd> |
| 676 | #include <cassert> |
| 677 | |
| 678 | #include <cstring> |
| 679 | |
| 680 | namespace Catch { |
| 681 | |
| 682 | /// A non-owning string class (similar to the forthcoming std::string_view) |
| 683 | /// Note that, because a StringRef may be a substring of another string, |
| 684 | /// it may not be null terminated. |
| 685 | class StringRef { |
| 686 | public: |
| 687 | using size_type = std::size_t; |
| 688 | using const_iterator = const char*; |
| 689 | |
| 690 | private: |
| 691 | static constexpr char const* const s_empty = ""; |
| 692 | |
| 693 | char const* m_start = s_empty; |
| 694 | size_type m_size = 0; |
| 695 | |
| 696 | public: // construction |
| 697 | constexpr StringRef() noexcept = default; |
| 698 | |
| 699 | StringRef( char const* rawChars ) noexcept; |
| 700 | |
| 701 | constexpr StringRef( char const* rawChars, size_type size ) noexcept |
| 702 | : m_start( rawChars ), |
| 703 | m_size( size ) |
| 704 | {} |
| 705 | |
| 706 | StringRef( std::string const& stdString ) noexcept |
| 707 | : m_start( stdString.c_str() ), |
| 708 | m_size( stdString.size() ) |
| 709 | {} |
| 710 | |
| 711 | explicit operator std::string() const { |
| 712 | return std::string(m_start, m_size); |
| 713 | } |
| 714 | |
| 715 | public: // operators |
| 716 | auto operator == ( StringRef other ) const noexcept -> bool { |
| 717 | return m_size == other.m_size |
| 718 | && (std::memcmp( m_start, other.m_start, m_size ) == 0); |
| 719 | } |
| 720 | auto operator != (StringRef other) const noexcept -> bool { |
| 721 | return !(*this == other); |
| 722 | } |
| 723 | |
| 724 | constexpr auto operator[] ( size_type index ) const noexcept -> char { |
| 725 | assert(index < m_size); |
| 726 | return m_start[index]; |
| 727 | } |
| 728 | |
| 729 | bool operator<(StringRef rhs) const noexcept; |
| 730 | |
| 731 | public: // named queries |
| 732 | constexpr auto empty() const noexcept -> bool { |
| 733 | return m_size == 0; |
| 734 | } |
| 735 | constexpr auto size() const noexcept -> size_type { |
| 736 | return m_size; |
| 737 | } |
| 738 | |
| 739 | // Returns a substring of [start, start + length). |
| 740 | // If start + length > size(), then the substring is [start, start + size()). |
| 741 | // If start > size(), then the substring is empty. |
| 742 | constexpr StringRef substr(size_type start, size_type length) const noexcept { |
| 743 | if (start < m_size) { |
| 744 | const auto shortened_size = m_size - start; |
| 745 | return StringRef(m_start + start, (shortened_size < length) ? shortened_size : length); |
| 746 | } else { |
| 747 | return StringRef(); |
| 748 | } |
| 749 | } |
| 750 | |
| 751 | // Returns the current start pointer. May not be null-terminated. |
| 752 | constexpr char const* data() const noexcept { |
| 753 | return m_start; |
| 754 | } |
| 755 | |
| 756 | constexpr const_iterator begin() const { return m_start; } |
| 757 | constexpr const_iterator end() const { return m_start + m_size; } |
| 758 | |
| 759 | |
| 760 | friend std::string& operator += (std::string& lhs, StringRef sr); |
| 761 | friend std::ostream& operator << (std::ostream& os, StringRef sr); |
| 762 | friend std::string operator+(StringRef lhs, StringRef rhs); |
| 763 | |
| 764 | /** |
| 765 | * Provides a three-way comparison with rhs |
| 766 | * |
| 767 | * Returns negative number if lhs < rhs, 0 if lhs == rhs, and a positive |
| 768 | * number if lhs > rhs |
| 769 | */ |
| 770 | int compare( StringRef rhs ) const; |
| 771 | }; |
| 772 | |
| 773 | |
| 774 | constexpr auto operator ""_sr( char const* rawChars, std::size_t size ) noexcept -> StringRef { |
| 775 | return StringRef( rawChars, size ); |
| 776 | } |
| 777 | } // namespace Catch |
| 778 | |
| 779 | constexpr auto operator ""_catch_sr( char const* rawChars, std::size_t size ) noexcept -> Catch::StringRef { |
| 780 | return Catch::StringRef( rawChars, size ); |
| 781 | } |
| 782 | |
| 783 | #endif // CATCH_STRINGREF_HPP_INCLUDED |
| 784 | |
| 785 | |
| 786 | #ifndef CATCH_RESULT_TYPE_HPP_INCLUDED |
| 787 | #define CATCH_RESULT_TYPE_HPP_INCLUDED |
| 788 | |
| 789 | namespace Catch { |
| 790 | |
| 791 | // ResultWas::OfType enum |
| 792 | struct ResultWas { enum OfType { |
| 793 | Unknown = -1, |
| 794 | Ok = 0, |
| 795 | Info = 1, |
| 796 | Warning = 2, |
| 797 | // TODO: Should explicit skip be considered "not OK" (cf. isOk)? I.e., should it have the failure bit? |
| 798 | ExplicitSkip = 4, |
| 799 | |
| 800 | FailureBit = 0x10, |
| 801 | |
| 802 | ExpressionFailed = FailureBit | 1, |
| 803 | ExplicitFailure = FailureBit | 2, |
| 804 | |
| 805 | Exception = 0x100 | FailureBit, |
| 806 | |
| 807 | ThrewException = Exception | 1, |
| 808 | DidntThrowException = Exception | 2, |
| 809 | |
| 810 | FatalErrorCondition = 0x200 | FailureBit |
| 811 | |
| 812 | }; }; |
| 813 | |
| 814 | bool isOk( ResultWas::OfType resultType ); |
| 815 | bool isJustInfo( int flags ); |
| 816 | |
| 817 | |
| 818 | // ResultDisposition::Flags enum |
| 819 | struct ResultDisposition { enum Flags { |
| 820 | Normal = 0x01, |
| 821 | |
| 822 | ContinueOnFailure = 0x02, // Failures fail test, but execution continues |
| 823 | FalseTest = 0x04, // Prefix expression with ! |
| 824 | SuppressFail = 0x08 // Failures are reported but do not fail the test |
| 825 | }; }; |
| 826 | |
| 827 | ResultDisposition::Flags operator | ( ResultDisposition::Flags lhs, ResultDisposition::Flags rhs ); |
| 828 | |
| 829 | bool shouldContinueOnFailure( int flags ); |
| 830 | inline bool isFalseTest( int flags ) { return ( flags & ResultDisposition::FalseTest ) != 0; } |
| 831 | bool shouldSuppressFailure( int flags ); |
| 832 | |
| 833 | } // end namespace Catch |
| 834 | |
| 835 | #endif // CATCH_RESULT_TYPE_HPP_INCLUDED |
| 836 | |
| 837 | |
| 838 | #ifndef CATCH_UNIQUE_PTR_HPP_INCLUDED |
| 839 | #define CATCH_UNIQUE_PTR_HPP_INCLUDED |
| 840 | |
| 841 | #include <cassert> |
| 842 | #include <type_traits> |
| 843 | |
| 844 | |
| 845 | namespace Catch { |
| 846 | namespace Detail { |
| 847 | /** |
| 848 | * A reimplementation of `std::unique_ptr` for improved compilation performance |
| 849 | * |
| 850 | * Does not support arrays nor custom deleters. |
| 851 | */ |
| 852 | template <typename T> |
| 853 | class unique_ptr { |
| 854 | T* m_ptr; |
| 855 | public: |
| 856 | constexpr unique_ptr(std::nullptr_t = nullptr): |
| 857 | m_ptr{} |
| 858 | {} |
| 859 | explicit constexpr unique_ptr(T* ptr): |
| 860 | m_ptr(ptr) |
| 861 | {} |
| 862 | |
| 863 | template <typename U, typename = std::enable_if_t<std::is_base_of<T, U>::value>> |
| 864 | unique_ptr(unique_ptr<U>&& from): |
| 865 | m_ptr(from.release()) |
| 866 | {} |
| 867 | |
| 868 | template <typename U, typename = std::enable_if_t<std::is_base_of<T, U>::value>> |
| 869 | unique_ptr& operator=(unique_ptr<U>&& from) { |
| 870 | reset(from.release()); |
| 871 | |
| 872 | return *this; |
| 873 | } |
| 874 | |
| 875 | unique_ptr(unique_ptr const&) = delete; |
| 876 | unique_ptr& operator=(unique_ptr const&) = delete; |
| 877 | |
| 878 | unique_ptr(unique_ptr&& rhs) noexcept: |
| 879 | m_ptr(rhs.m_ptr) { |
| 880 | rhs.m_ptr = nullptr; |
| 881 | } |
| 882 | unique_ptr& operator=(unique_ptr&& rhs) noexcept { |
| 883 | reset(rhs.release()); |
| 884 | |
| 885 | return *this; |
| 886 | } |
| 887 | |
| 888 | ~unique_ptr() { |
| 889 | delete m_ptr; |
| 890 | } |
| 891 | |
| 892 | T& operator*() { |
| 893 | assert(m_ptr); |
| 894 | return *m_ptr; |
| 895 | } |
| 896 | T const& operator*() const { |
| 897 | assert(m_ptr); |
| 898 | return *m_ptr; |
| 899 | } |
| 900 | T* operator->() noexcept { |
| 901 | assert(m_ptr); |
| 902 | return m_ptr; |
| 903 | } |
| 904 | T const* operator->() const noexcept { |
| 905 | assert(m_ptr); |
| 906 | return m_ptr; |
| 907 | } |
| 908 | |
| 909 | T* get() { return m_ptr; } |
| 910 | T const* get() const { return m_ptr; } |
| 911 | |
| 912 | void reset(T* ptr = nullptr) { |
| 913 | delete m_ptr; |
| 914 | m_ptr = ptr; |
| 915 | } |
| 916 | |
| 917 | T* release() { |
| 918 | auto temp = m_ptr; |
| 919 | m_ptr = nullptr; |
| 920 | return temp; |
| 921 | } |
| 922 | |
| 923 | explicit operator bool() const { |
| 924 | return m_ptr; |
| 925 | } |
| 926 | |
| 927 | friend void swap(unique_ptr& lhs, unique_ptr& rhs) { |
| 928 | auto temp = lhs.m_ptr; |
| 929 | lhs.m_ptr = rhs.m_ptr; |
| 930 | rhs.m_ptr = temp; |
| 931 | } |
| 932 | }; |
| 933 | |
| 934 | //! Specialization to cause compile-time error for arrays |
| 935 | template <typename T> |
| 936 | class unique_ptr<T[]>; |
| 937 | |
| 938 | template <typename T, typename... Args> |
| 939 | unique_ptr<T> make_unique(Args&&... args) { |
| 940 | return unique_ptr<T>(new T(CATCH_FORWARD(args)...)); |
| 941 | } |
| 942 | |
| 943 | |
| 944 | } // end namespace Detail |
| 945 | } // end namespace Catch |
| 946 | |
| 947 | #endif // CATCH_UNIQUE_PTR_HPP_INCLUDED |
| 948 | |
| 949 | |
| 950 | #ifndef CATCH_BENCHMARK_STATS_FWD_HPP_INCLUDED |
| 951 | #define CATCH_BENCHMARK_STATS_FWD_HPP_INCLUDED |
| 952 | |
| 953 | #include <chrono> |
| 954 | |
| 955 | namespace Catch { |
| 956 | |
| 957 | // We cannot forward declare the type with default template argument |
| 958 | // multiple times, so it is split out into a separate header so that |
| 959 | // we can prevent multiple declarations in dependees |
| 960 | template <typename Duration = std::chrono::duration<double, std::nano>> |
| 961 | struct BenchmarkStats; |
| 962 | |
| 963 | } // end namespace Catch |
| 964 | |
| 965 | #endif // CATCH_BENCHMARK_STATS_FWD_HPP_INCLUDED |
| 966 | |
| 967 | namespace Catch { |
| 968 | |
| 969 | class AssertionResult; |
| 970 | struct AssertionInfo; |
| 971 | struct SectionInfo; |
| 972 | struct SectionEndInfo; |
| 973 | struct MessageInfo; |
| 974 | struct MessageBuilder; |
| 975 | struct Counts; |
| 976 | struct AssertionReaction; |
| 977 | struct SourceLineInfo; |
| 978 | |
| 979 | class ITransientExpression; |
| 980 | class IGeneratorTracker; |
| 981 | |
| 982 | struct BenchmarkInfo; |
| 983 | |
| 984 | namespace Generators { |
| 985 | class GeneratorUntypedBase; |
| 986 | using GeneratorBasePtr = Catch::Detail::unique_ptr<GeneratorUntypedBase>; |
| 987 | } |
| 988 | |
| 989 | |
| 990 | class IResultCapture { |
| 991 | public: |
| 992 | virtual ~IResultCapture(); |
| 993 | |
| 994 | virtual void notifyAssertionStarted( AssertionInfo const& info ) = 0; |
| 995 | virtual bool sectionStarted( StringRef sectionName, |
| 996 | SourceLineInfo const& sectionLineInfo, |
| 997 | Counts& assertions ) = 0; |
| 998 | virtual void sectionEnded( SectionEndInfo&& endInfo ) = 0; |
| 999 | virtual void sectionEndedEarly( SectionEndInfo&& endInfo ) = 0; |
| 1000 | |
| 1001 | virtual IGeneratorTracker* |
| 1002 | acquireGeneratorTracker( StringRef generatorName, |
| 1003 | SourceLineInfo const& lineInfo ) = 0; |
| 1004 | virtual IGeneratorTracker* |
| 1005 | createGeneratorTracker( StringRef generatorName, |
| 1006 | SourceLineInfo lineInfo, |
| 1007 | Generators::GeneratorBasePtr&& generator ) = 0; |
| 1008 | |
| 1009 | virtual void benchmarkPreparing( StringRef name ) = 0; |
| 1010 | virtual void benchmarkStarting( BenchmarkInfo const& info ) = 0; |
| 1011 | virtual void benchmarkEnded( BenchmarkStats<> const& stats ) = 0; |
| 1012 | virtual void benchmarkFailed( StringRef error ) = 0; |
| 1013 | |
| 1014 | virtual void pushScopedMessage( MessageInfo const& message ) = 0; |
| 1015 | virtual void popScopedMessage( MessageInfo const& message ) = 0; |
| 1016 | |
| 1017 | virtual void emplaceUnscopedMessage( MessageBuilder&& builder ) = 0; |
| 1018 | |
| 1019 | virtual void handleFatalErrorCondition( StringRef message ) = 0; |
| 1020 | |
| 1021 | virtual void handleExpr |
| 1022 | ( AssertionInfo const& info, |
| 1023 | ITransientExpression const& expr, |
| 1024 | AssertionReaction& reaction ) = 0; |
| 1025 | virtual void handleMessage |
| 1026 | ( AssertionInfo const& info, |
| 1027 | ResultWas::OfType resultType, |
| 1028 | StringRef message, |
| 1029 | AssertionReaction& reaction ) = 0; |
| 1030 | virtual void handleUnexpectedExceptionNotThrown |
| 1031 | ( AssertionInfo const& info, |
| 1032 | AssertionReaction& reaction ) = 0; |
| 1033 | virtual void handleUnexpectedInflightException |
| 1034 | ( AssertionInfo const& info, |
| 1035 | std::string&& message, |
| 1036 | AssertionReaction& reaction ) = 0; |
| 1037 | virtual void handleIncomplete |
| 1038 | ( AssertionInfo const& info ) = 0; |
| 1039 | virtual void handleNonExpr |
| 1040 | ( AssertionInfo const &info, |
| 1041 | ResultWas::OfType resultType, |
| 1042 | AssertionReaction &reaction ) = 0; |
| 1043 | |
| 1044 | |
| 1045 | |
| 1046 | virtual bool lastAssertionPassed() = 0; |
| 1047 | virtual void assertionPassed() = 0; |
| 1048 | |
| 1049 | // Deprecated, do not use: |
| 1050 | virtual std::string getCurrentTestName() const = 0; |
| 1051 | virtual const AssertionResult* getLastResult() const = 0; |
| 1052 | virtual void exceptionEarlyReported() = 0; |
| 1053 | }; |
| 1054 | |
| 1055 | IResultCapture& getResultCapture(); |
| 1056 | } |
| 1057 | |
| 1058 | #endif // CATCH_INTERFACES_CAPTURE_HPP_INCLUDED |
| 1059 | |
| 1060 | |
| 1061 | #ifndef CATCH_INTERFACES_CONFIG_HPP_INCLUDED |
| 1062 | #define CATCH_INTERFACES_CONFIG_HPP_INCLUDED |
| 1063 | |
| 1064 | |
| 1065 | |
| 1066 | #ifndef CATCH_NONCOPYABLE_HPP_INCLUDED |
| 1067 | #define CATCH_NONCOPYABLE_HPP_INCLUDED |
| 1068 | |
| 1069 | namespace Catch { |
| 1070 | namespace Detail { |
| 1071 | |
| 1072 | //! Deriving classes become noncopyable and nonmovable |
| 1073 | class NonCopyable { |
| 1074 | NonCopyable( NonCopyable const& ) = delete; |
| 1075 | NonCopyable( NonCopyable&& ) = delete; |
| 1076 | NonCopyable& operator=( NonCopyable const& ) = delete; |
| 1077 | NonCopyable& operator=( NonCopyable&& ) = delete; |
| 1078 | |
| 1079 | protected: |
| 1080 | NonCopyable() noexcept = default; |
| 1081 | }; |
| 1082 | |
| 1083 | } // namespace Detail |
| 1084 | } // namespace Catch |
| 1085 | |
| 1086 | #endif // CATCH_NONCOPYABLE_HPP_INCLUDED |
| 1087 | |
| 1088 | #include <chrono> |
| 1089 | #include <iosfwd> |
| 1090 | #include <string> |
| 1091 | #include <vector> |
| 1092 | |
| 1093 | namespace Catch { |
| 1094 | |
| 1095 | enum class Verbosity { |
| 1096 | Quiet = 0, |
| 1097 | Normal, |
| 1098 | High |
| 1099 | }; |
| 1100 | |
| 1101 | struct WarnAbout { enum What { |
| 1102 | Nothing = 0x00, |
| 1103 | //! A test case or leaf section did not run any assertions |
| 1104 | NoAssertions = 0x01, |
| 1105 | //! A command line test spec matched no test cases |
| 1106 | UnmatchedTestSpec = 0x02, |
| 1107 | }; }; |
| 1108 | |
| 1109 | enum class ShowDurations { |
| 1110 | DefaultForReporter, |
| 1111 | Always, |
| 1112 | Never |
| 1113 | }; |
| 1114 | enum class TestRunOrder { |
| 1115 | Declared, |
| 1116 | LexicographicallySorted, |
| 1117 | Randomized |
| 1118 | }; |
| 1119 | enum class ColourMode : std::uint8_t { |
| 1120 | //! Let Catch2 pick implementation based on platform detection |
| 1121 | PlatformDefault, |
| 1122 | //! Use ANSI colour code escapes |
| 1123 | ANSI, |
| 1124 | //! Use Win32 console colour API |
| 1125 | Win32, |
| 1126 | //! Don't use any colour |
| 1127 | None |
| 1128 | }; |
| 1129 | struct WaitForKeypress { enum When { |
| 1130 | Never, |
| 1131 | BeforeStart = 1, |
| 1132 | BeforeExit = 2, |
| 1133 | BeforeStartAndExit = BeforeStart | BeforeExit |
| 1134 | }; }; |
| 1135 | |
| 1136 | class TestSpec; |
| 1137 | class IStream; |
| 1138 | |
| 1139 | class IConfig : public Detail::NonCopyable { |
| 1140 | public: |
| 1141 | virtual ~IConfig(); |
| 1142 | |
| 1143 | virtual bool allowThrows() const = 0; |
| 1144 | virtual StringRef name() const = 0; |
| 1145 | virtual bool includeSuccessfulResults() const = 0; |
| 1146 | virtual bool shouldDebugBreak() const = 0; |
| 1147 | virtual bool warnAboutMissingAssertions() const = 0; |
| 1148 | virtual bool warnAboutUnmatchedTestSpecs() const = 0; |
| 1149 | virtual bool zeroTestsCountAsSuccess() const = 0; |
| 1150 | virtual int abortAfter() const = 0; |
| 1151 | virtual bool showInvisibles() const = 0; |
| 1152 | virtual ShowDurations showDurations() const = 0; |
| 1153 | virtual double minDuration() const = 0; |
| 1154 | virtual TestSpec const& testSpec() const = 0; |
| 1155 | virtual bool hasTestFilters() const = 0; |
| 1156 | virtual std::vector<std::string> const& getTestsOrTags() const = 0; |
| 1157 | virtual TestRunOrder runOrder() const = 0; |
| 1158 | virtual uint32_t rngSeed() const = 0; |
| 1159 | virtual unsigned int shardCount() const = 0; |
| 1160 | virtual unsigned int shardIndex() const = 0; |
| 1161 | virtual ColourMode defaultColourMode() const = 0; |
| 1162 | virtual std::vector<std::string> const& getSectionsToRun() const = 0; |
| 1163 | virtual Verbosity verbosity() const = 0; |
| 1164 | |
| 1165 | virtual bool skipBenchmarks() const = 0; |
| 1166 | virtual bool benchmarkNoAnalysis() const = 0; |
| 1167 | virtual unsigned int benchmarkSamples() const = 0; |
| 1168 | virtual double benchmarkConfidenceInterval() const = 0; |
| 1169 | virtual unsigned int benchmarkResamples() const = 0; |
| 1170 | virtual std::chrono::milliseconds benchmarkWarmupTime() const = 0; |
| 1171 | }; |
| 1172 | } |
| 1173 | |
| 1174 | #endif // CATCH_INTERFACES_CONFIG_HPP_INCLUDED |
| 1175 | |
| 1176 | |
| 1177 | #ifndef CATCH_INTERFACES_REGISTRY_HUB_HPP_INCLUDED |
| 1178 | #define CATCH_INTERFACES_REGISTRY_HUB_HPP_INCLUDED |
| 1179 | |
| 1180 | |
| 1181 | #include <string> |
| 1182 | |
| 1183 | namespace Catch { |
| 1184 | |
| 1185 | class TestCaseHandle; |
| 1186 | struct TestCaseInfo; |
| 1187 | class ITestCaseRegistry; |
| 1188 | class IExceptionTranslatorRegistry; |
| 1189 | class IExceptionTranslator; |
| 1190 | class ReporterRegistry; |
| 1191 | class IReporterFactory; |
| 1192 | class ITagAliasRegistry; |
| 1193 | class ITestInvoker; |
| 1194 | class IMutableEnumValuesRegistry; |
| 1195 | struct SourceLineInfo; |
| 1196 | |
| 1197 | class StartupExceptionRegistry; |
| 1198 | class EventListenerFactory; |
| 1199 | |
| 1200 | using IReporterFactoryPtr = Detail::unique_ptr<IReporterFactory>; |
| 1201 | |
| 1202 | class IRegistryHub { |
| 1203 | public: |
| 1204 | virtual ~IRegistryHub(); // = default |
| 1205 | |
| 1206 | virtual ReporterRegistry const& getReporterRegistry() const = 0; |
| 1207 | virtual ITestCaseRegistry const& getTestCaseRegistry() const = 0; |
| 1208 | virtual ITagAliasRegistry const& getTagAliasRegistry() const = 0; |
| 1209 | virtual IExceptionTranslatorRegistry const& getExceptionTranslatorRegistry() const = 0; |
| 1210 | |
| 1211 | |
| 1212 | virtual StartupExceptionRegistry const& getStartupExceptionRegistry() const = 0; |
| 1213 | }; |
| 1214 | |
| 1215 | class IMutableRegistryHub { |
| 1216 | public: |
| 1217 | virtual ~IMutableRegistryHub(); // = default |
| 1218 | virtual void registerReporter( std::string const& name, IReporterFactoryPtr factory ) = 0; |
| 1219 | virtual void registerListener( Detail::unique_ptr<EventListenerFactory> factory ) = 0; |
| 1220 | virtual void registerTest(Detail::unique_ptr<TestCaseInfo>&& testInfo, Detail::unique_ptr<ITestInvoker>&& invoker) = 0; |
| 1221 | virtual void registerTranslator( Detail::unique_ptr<IExceptionTranslator>&& translator ) = 0; |
| 1222 | virtual void registerTagAlias( std::string const& alias, std::string const& tag, SourceLineInfo const& lineInfo ) = 0; |
| 1223 | virtual void registerStartupException() noexcept = 0; |
| 1224 | virtual IMutableEnumValuesRegistry& getMutableEnumValuesRegistry() = 0; |
| 1225 | }; |
| 1226 | |
| 1227 | IRegistryHub const& getRegistryHub(); |
| 1228 | IMutableRegistryHub& getMutableRegistryHub(); |
| 1229 | void cleanUp(); |
| 1230 | std::string translateActiveException(); |
| 1231 | |
| 1232 | } |
| 1233 | |
| 1234 | #endif // CATCH_INTERFACES_REGISTRY_HUB_HPP_INCLUDED |
| 1235 | |
| 1236 | |
| 1237 | #ifndef CATCH_BENCHMARK_STATS_HPP_INCLUDED |
| 1238 | #define CATCH_BENCHMARK_STATS_HPP_INCLUDED |
| 1239 | |
| 1240 | |
| 1241 | |
| 1242 | // Adapted from donated nonius code. |
| 1243 | |
| 1244 | #ifndef CATCH_ESTIMATE_HPP_INCLUDED |
| 1245 | #define CATCH_ESTIMATE_HPP_INCLUDED |
| 1246 | |
| 1247 | namespace Catch { |
| 1248 | namespace Benchmark { |
| 1249 | template <typename Duration> |
| 1250 | struct Estimate { |
| 1251 | Duration point; |
| 1252 | Duration lower_bound; |
| 1253 | Duration upper_bound; |
| 1254 | double confidence_interval; |
| 1255 | |
| 1256 | template <typename Duration2> |
| 1257 | operator Estimate<Duration2>() const { |
| 1258 | return { point, lower_bound, upper_bound, confidence_interval }; |
| 1259 | } |
| 1260 | }; |
| 1261 | } // namespace Benchmark |
| 1262 | } // namespace Catch |
| 1263 | |
| 1264 | #endif // CATCH_ESTIMATE_HPP_INCLUDED |
| 1265 | |
| 1266 | |
| 1267 | // Adapted from donated nonius code. |
| 1268 | |
| 1269 | #ifndef CATCH_OUTLIER_CLASSIFICATION_HPP_INCLUDED |
| 1270 | #define CATCH_OUTLIER_CLASSIFICATION_HPP_INCLUDED |
| 1271 | |
| 1272 | namespace Catch { |
| 1273 | namespace Benchmark { |
| 1274 | struct OutlierClassification { |
| 1275 | int samples_seen = 0; |
| 1276 | int low_severe = 0; // more than 3 times IQR below Q1 |
| 1277 | int low_mild = 0; // 1.5 to 3 times IQR below Q1 |
| 1278 | int high_mild = 0; // 1.5 to 3 times IQR above Q3 |
| 1279 | int high_severe = 0; // more than 3 times IQR above Q3 |
| 1280 | |
| 1281 | int total() const { |
| 1282 | return low_severe + low_mild + high_mild + high_severe; |
| 1283 | } |
| 1284 | }; |
| 1285 | } // namespace Benchmark |
| 1286 | } // namespace Catch |
| 1287 | |
| 1288 | #endif // CATCH_OUTLIERS_CLASSIFICATION_HPP_INCLUDED |
| 1289 | // The fwd decl & default specialization needs to be seen by VS2017 before |
| 1290 | // BenchmarkStats itself, or VS2017 will report compilation error. |
| 1291 | |
| 1292 | #include <string> |
| 1293 | #include <vector> |
| 1294 | |
| 1295 | namespace Catch { |
| 1296 | |
| 1297 | struct BenchmarkInfo { |
| 1298 | std::string name; |
| 1299 | double estimatedDuration; |
| 1300 | int iterations; |
| 1301 | unsigned int samples; |
| 1302 | unsigned int resamples; |
| 1303 | double clockResolution; |
| 1304 | double clockCost; |
| 1305 | }; |
| 1306 | |
| 1307 | template <class Duration> |
| 1308 | struct BenchmarkStats { |
| 1309 | BenchmarkInfo info; |
| 1310 | |
| 1311 | std::vector<Duration> samples; |
| 1312 | Benchmark::Estimate<Duration> mean; |
| 1313 | Benchmark::Estimate<Duration> standardDeviation; |
| 1314 | Benchmark::OutlierClassification outliers; |
| 1315 | double outlierVariance; |
| 1316 | |
| 1317 | template <typename Duration2> |
| 1318 | operator BenchmarkStats<Duration2>() const { |
| 1319 | std::vector<Duration2> samples2; |
| 1320 | samples2.reserve(samples.size()); |
| 1321 | for (auto const& sample : samples) { |
| 1322 | samples2.push_back(Duration2(sample)); |
| 1323 | } |
| 1324 | return { |
| 1325 | info, |
| 1326 | CATCH_MOVE(samples2), |
| 1327 | mean, |
| 1328 | standardDeviation, |
| 1329 | outliers, |
| 1330 | outlierVariance, |
| 1331 | }; |
| 1332 | } |
| 1333 | }; |
| 1334 | |
| 1335 | |
| 1336 | } // end namespace Catch |
| 1337 | |
| 1338 | #endif // CATCH_BENCHMARK_STATS_HPP_INCLUDED |
| 1339 | |
| 1340 | |
| 1341 | // Adapted from donated nonius code. |
| 1342 | |
| 1343 | #ifndef CATCH_CLOCK_HPP_INCLUDED |
| 1344 | #define CATCH_CLOCK_HPP_INCLUDED |
| 1345 | |
| 1346 | #include <chrono> |
| 1347 | #include <ratio> |
| 1348 | |
| 1349 | namespace Catch { |
| 1350 | namespace Benchmark { |
| 1351 | template <typename Clock> |
| 1352 | using ClockDuration = typename Clock::duration; |
| 1353 | template <typename Clock> |
| 1354 | using FloatDuration = std::chrono::duration<double, typename Clock::period>; |
| 1355 | |
| 1356 | template <typename Clock> |
| 1357 | using TimePoint = typename Clock::time_point; |
| 1358 | |
| 1359 | using default_clock = std::chrono::steady_clock; |
| 1360 | |
| 1361 | template <typename Clock> |
| 1362 | struct now { |
| 1363 | TimePoint<Clock> operator()() const { |
| 1364 | return Clock::now(); |
| 1365 | } |
| 1366 | }; |
| 1367 | |
| 1368 | using fp_seconds = std::chrono::duration<double, std::ratio<1>>; |
| 1369 | } // namespace Benchmark |
| 1370 | } // namespace Catch |
| 1371 | |
| 1372 | #endif // CATCH_CLOCK_HPP_INCLUDED |
| 1373 | |
| 1374 | |
| 1375 | // Adapted from donated nonius code. |
| 1376 | |
| 1377 | #ifndef CATCH_ENVIRONMENT_HPP_INCLUDED |
| 1378 | #define CATCH_ENVIRONMENT_HPP_INCLUDED |
| 1379 | |
| 1380 | |
| 1381 | namespace Catch { |
| 1382 | namespace Benchmark { |
| 1383 | template <typename Duration> |
| 1384 | struct EnvironmentEstimate { |
| 1385 | Duration mean; |
| 1386 | OutlierClassification outliers; |
| 1387 | |
| 1388 | template <typename Duration2> |
| 1389 | operator EnvironmentEstimate<Duration2>() const { |
| 1390 | return { mean, outliers }; |
| 1391 | } |
| 1392 | }; |
| 1393 | template <typename Clock> |
| 1394 | struct Environment { |
| 1395 | using clock_type = Clock; |
| 1396 | EnvironmentEstimate<FloatDuration<Clock>> clock_resolution; |
| 1397 | EnvironmentEstimate<FloatDuration<Clock>> clock_cost; |
| 1398 | }; |
| 1399 | } // namespace Benchmark |
| 1400 | } // namespace Catch |
| 1401 | |
| 1402 | #endif // CATCH_ENVIRONMENT_HPP_INCLUDED |
| 1403 | |
| 1404 | |
| 1405 | // Adapted from donated nonius code. |
| 1406 | |
| 1407 | #ifndef CATCH_EXECUTION_PLAN_HPP_INCLUDED |
| 1408 | #define CATCH_EXECUTION_PLAN_HPP_INCLUDED |
| 1409 | |
| 1410 | |
| 1411 | |
| 1412 | // Adapted from donated nonius code. |
| 1413 | |
| 1414 | #ifndef CATCH_BENCHMARK_FUNCTION_HPP_INCLUDED |
| 1415 | #define CATCH_BENCHMARK_FUNCTION_HPP_INCLUDED |
| 1416 | |
| 1417 | |
| 1418 | |
| 1419 | // Adapted from donated nonius code. |
| 1420 | |
| 1421 | #ifndef CATCH_CHRONOMETER_HPP_INCLUDED |
| 1422 | #define CATCH_CHRONOMETER_HPP_INCLUDED |
| 1423 | |
| 1424 | |
| 1425 | |
| 1426 | // Adapted from donated nonius code. |
| 1427 | |
| 1428 | #ifndef CATCH_OPTIMIZER_HPP_INCLUDED |
| 1429 | #define CATCH_OPTIMIZER_HPP_INCLUDED |
| 1430 | |
| 1431 | #if defined(_MSC_VER) || defined(__IAR_SYSTEMS_ICC__) |
| 1432 | # include <atomic> // atomic_thread_fence |
| 1433 | #endif |
| 1434 | |
| 1435 | |
| 1436 | #include <type_traits> |
| 1437 | |
| 1438 | namespace Catch { |
| 1439 | namespace Benchmark { |
| 1440 | #if defined(__GNUC__) || defined(__clang__) |
| 1441 | template <typename T> |
| 1442 | inline void keep_memory(T* p) { |
| 1443 | asm volatile("" : : "g"(p) : "memory"); |
| 1444 | } |
| 1445 | inline void keep_memory() { |
| 1446 | asm volatile("" : : : "memory"); |
| 1447 | } |
| 1448 | |
| 1449 | namespace Detail { |
| 1450 | inline void optimizer_barrier() { keep_memory(); } |
| 1451 | } // namespace Detail |
| 1452 | #elif defined(_MSC_VER) || defined(__IAR_SYSTEMS_ICC__) |
| 1453 | |
| 1454 | #if defined(_MSVC_VER) |
| 1455 | #pragma optimize("", off) |
| 1456 | #elif defined(__IAR_SYSTEMS_ICC__) |
| 1457 | // For IAR the pragma only affects the following function |
| 1458 | #pragma optimize=disable |
| 1459 | #endif |
| 1460 | template <typename T> |
| 1461 | inline void keep_memory(T* p) { |
| 1462 | // thanks @milleniumbug |
| 1463 | *reinterpret_cast<char volatile*>(p) = *reinterpret_cast<char const volatile*>(p); |
| 1464 | } |
| 1465 | // TODO equivalent keep_memory() |
| 1466 | #if defined(_MSVC_VER) |
| 1467 | #pragma optimize("", on) |
| 1468 | #endif |
| 1469 | |
| 1470 | namespace Detail { |
| 1471 | inline void optimizer_barrier() { |
| 1472 | std::atomic_thread_fence(std::memory_order_seq_cst); |
| 1473 | } |
| 1474 | } // namespace Detail |
| 1475 | |
| 1476 | #endif |
| 1477 | |
| 1478 | template <typename T> |
| 1479 | inline void deoptimize_value(T&& x) { |
| 1480 | keep_memory(&x); |
| 1481 | } |
| 1482 | |
| 1483 | template <typename Fn, typename... Args> |
| 1484 | inline auto invoke_deoptimized(Fn&& fn, Args&&... args) -> std::enable_if_t<!std::is_same<void, decltype(fn(args...))>::value> { |
| 1485 | deoptimize_value(CATCH_FORWARD(fn) (CATCH_FORWARD(args)...)); |
| 1486 | } |
| 1487 | |
| 1488 | template <typename Fn, typename... Args> |
| 1489 | inline auto invoke_deoptimized(Fn&& fn, Args&&... args) -> std::enable_if_t<std::is_same<void, decltype(fn(args...))>::value> { |
| 1490 | CATCH_FORWARD(fn) (CATCH_FORWARD(args)...); |
| 1491 | } |
| 1492 | } // namespace Benchmark |
| 1493 | } // namespace Catch |
| 1494 | |
| 1495 | #endif // CATCH_OPTIMIZER_HPP_INCLUDED |
| 1496 | |
| 1497 | |
| 1498 | #ifndef CATCH_META_HPP_INCLUDED |
| 1499 | #define CATCH_META_HPP_INCLUDED |
| 1500 | |
| 1501 | #include <type_traits> |
| 1502 | |
| 1503 | namespace Catch { |
| 1504 | template <typename> |
| 1505 | struct true_given : std::true_type {}; |
| 1506 | |
| 1507 | struct is_callable_tester { |
| 1508 | template <typename Fun, typename... Args> |
| 1509 | static true_given<decltype(std::declval<Fun>()(std::declval<Args>()...))> test(int); |
| 1510 | template <typename...> |
| 1511 | static std::false_type test(...); |
| 1512 | }; |
| 1513 | |
| 1514 | template <typename T> |
| 1515 | struct is_callable; |
| 1516 | |
| 1517 | template <typename Fun, typename... Args> |
| 1518 | struct is_callable<Fun(Args...)> : decltype(is_callable_tester::test<Fun, Args...>(0)) {}; |
| 1519 | |
| 1520 | |
| 1521 | #if defined(__cpp_lib_is_invocable) && __cpp_lib_is_invocable >= 201703 |
| 1522 | // std::result_of is deprecated in C++17 and removed in C++20. Hence, it is |
| 1523 | // replaced with std::invoke_result here. |
| 1524 | template <typename Func, typename... U> |
| 1525 | using FunctionReturnType = std::remove_reference_t<std::remove_cv_t<std::invoke_result_t<Func, U...>>>; |
| 1526 | #else |
| 1527 | template <typename Func, typename... U> |
| 1528 | using FunctionReturnType = std::remove_reference_t<std::remove_cv_t<std::result_of_t<Func(U...)>>>; |
| 1529 | #endif |
| 1530 | |
| 1531 | } // namespace Catch |
| 1532 | |
| 1533 | namespace mpl_{ |
| 1534 | struct na; |
| 1535 | } |
| 1536 | |
| 1537 | #endif // CATCH_META_HPP_INCLUDED |
| 1538 | |
| 1539 | namespace Catch { |
| 1540 | namespace Benchmark { |
| 1541 | namespace Detail { |
| 1542 | struct ChronometerConcept { |
| 1543 | virtual void start() = 0; |
| 1544 | virtual void finish() = 0; |
| 1545 | virtual ~ChronometerConcept(); // = default; |
| 1546 | |
| 1547 | ChronometerConcept() = default; |
| 1548 | ChronometerConcept(ChronometerConcept const&) = default; |
| 1549 | ChronometerConcept& operator=(ChronometerConcept const&) = default; |
| 1550 | }; |
| 1551 | template <typename Clock> |
| 1552 | struct ChronometerModel final : public ChronometerConcept { |
| 1553 | void start() override { started = Clock::now(); } |
| 1554 | void finish() override { finished = Clock::now(); } |
| 1555 | |
| 1556 | ClockDuration<Clock> elapsed() const { return finished - started; } |
| 1557 | |
| 1558 | TimePoint<Clock> started; |
| 1559 | TimePoint<Clock> finished; |
| 1560 | }; |
| 1561 | } // namespace Detail |
| 1562 | |
| 1563 | struct Chronometer { |
| 1564 | public: |
| 1565 | template <typename Fun> |
| 1566 | void measure(Fun&& fun) { measure(CATCH_FORWARD(fun), is_callable<Fun(int)>()); } |
| 1567 | |
| 1568 | int runs() const { return repeats; } |
| 1569 | |
| 1570 | Chronometer(Detail::ChronometerConcept& meter, int repeats_) |
| 1571 | : impl(&meter) |
| 1572 | , repeats(repeats_) {} |
| 1573 | |
| 1574 | private: |
| 1575 | template <typename Fun> |
| 1576 | void measure(Fun&& fun, std::false_type) { |
| 1577 | measure([&fun](int) { return fun(); }, std::true_type()); |
| 1578 | } |
| 1579 | |
| 1580 | template <typename Fun> |
| 1581 | void measure(Fun&& fun, std::true_type) { |
| 1582 | Detail::optimizer_barrier(); |
| 1583 | impl->start(); |
| 1584 | for (int i = 0; i < repeats; ++i) invoke_deoptimized(fun, i); |
| 1585 | impl->finish(); |
| 1586 | Detail::optimizer_barrier(); |
| 1587 | } |
| 1588 | |
| 1589 | Detail::ChronometerConcept* impl; |
| 1590 | int repeats; |
| 1591 | }; |
| 1592 | } // namespace Benchmark |
| 1593 | } // namespace Catch |
| 1594 | |
| 1595 | #endif // CATCH_CHRONOMETER_HPP_INCLUDED |
| 1596 | |
| 1597 | #include <type_traits> |
| 1598 | |
| 1599 | namespace Catch { |
| 1600 | namespace Benchmark { |
| 1601 | namespace Detail { |
| 1602 | template <typename T, typename U> |
| 1603 | struct is_related |
| 1604 | : std::is_same<std::decay_t<T>, std::decay_t<U>> {}; |
| 1605 | |
| 1606 | /// We need to reinvent std::function because every piece of code that might add overhead |
| 1607 | /// in a measurement context needs to have consistent performance characteristics so that we |
| 1608 | /// can account for it in the measurement. |
| 1609 | /// Implementations of std::function with optimizations that aren't always applicable, like |
| 1610 | /// small buffer optimizations, are not uncommon. |
| 1611 | /// This is effectively an implementation of std::function without any such optimizations; |
| 1612 | /// it may be slow, but it is consistently slow. |
| 1613 | struct BenchmarkFunction { |
| 1614 | private: |
| 1615 | struct callable { |
| 1616 | virtual void call(Chronometer meter) const = 0; |
| 1617 | virtual Catch::Detail::unique_ptr<callable> clone() const = 0; |
| 1618 | virtual ~callable(); // = default; |
| 1619 | |
| 1620 | callable() = default; |
| 1621 | callable(callable const&) = default; |
| 1622 | callable& operator=(callable const&) = default; |
| 1623 | }; |
| 1624 | template <typename Fun> |
| 1625 | struct model : public callable { |
| 1626 | model(Fun&& fun_) : fun(CATCH_MOVE(fun_)) {} |
| 1627 | model(Fun const& fun_) : fun(fun_) {} |
| 1628 | |
| 1629 | Catch::Detail::unique_ptr<callable> clone() const override { |
| 1630 | return Catch::Detail::make_unique<model<Fun>>( *this ); |
| 1631 | } |
| 1632 | |
| 1633 | void call(Chronometer meter) const override { |
| 1634 | call(meter, is_callable<Fun(Chronometer)>()); |
| 1635 | } |
| 1636 | void call(Chronometer meter, std::true_type) const { |
| 1637 | fun(meter); |
| 1638 | } |
| 1639 | void call(Chronometer meter, std::false_type) const { |
| 1640 | meter.measure(fun); |
| 1641 | } |
| 1642 | |
| 1643 | Fun fun; |
| 1644 | }; |
| 1645 | |
| 1646 | struct do_nothing { void operator()() const {} }; |
| 1647 | |
| 1648 | template <typename T> |
| 1649 | BenchmarkFunction(model<T>* c) : f(c) {} |
| 1650 | |
| 1651 | public: |
| 1652 | BenchmarkFunction() |
| 1653 | : f(new model<do_nothing>{ {} }) {} |
| 1654 | |
| 1655 | template <typename Fun, |
| 1656 | std::enable_if_t<!is_related<Fun, BenchmarkFunction>::value, int> = 0> |
| 1657 | BenchmarkFunction(Fun&& fun) |
| 1658 | : f(new model<std::decay_t<Fun>>(CATCH_FORWARD(fun))) {} |
| 1659 | |
| 1660 | BenchmarkFunction( BenchmarkFunction&& that ) noexcept: |
| 1661 | f( CATCH_MOVE( that.f ) ) {} |
| 1662 | |
| 1663 | BenchmarkFunction(BenchmarkFunction const& that) |
| 1664 | : f(that.f->clone()) {} |
| 1665 | |
| 1666 | BenchmarkFunction& |
| 1667 | operator=( BenchmarkFunction&& that ) noexcept { |
| 1668 | f = CATCH_MOVE( that.f ); |
| 1669 | return *this; |
| 1670 | } |
| 1671 | |
| 1672 | BenchmarkFunction& operator=(BenchmarkFunction const& that) { |
| 1673 | f = that.f->clone(); |
| 1674 | return *this; |
| 1675 | } |
| 1676 | |
| 1677 | void operator()(Chronometer meter) const { f->call(meter); } |
| 1678 | |
| 1679 | private: |
| 1680 | Catch::Detail::unique_ptr<callable> f; |
| 1681 | }; |
| 1682 | } // namespace Detail |
| 1683 | } // namespace Benchmark |
| 1684 | } // namespace Catch |
| 1685 | |
| 1686 | #endif // CATCH_BENCHMARK_FUNCTION_HPP_INCLUDED |
| 1687 | |
| 1688 | |
| 1689 | // Adapted from donated nonius code. |
| 1690 | |
| 1691 | #ifndef CATCH_REPEAT_HPP_INCLUDED |
| 1692 | #define CATCH_REPEAT_HPP_INCLUDED |
| 1693 | |
| 1694 | #include <type_traits> |
| 1695 | |
| 1696 | namespace Catch { |
| 1697 | namespace Benchmark { |
| 1698 | namespace Detail { |
| 1699 | template <typename Fun> |
| 1700 | struct repeater { |
| 1701 | void operator()(int k) const { |
| 1702 | for (int i = 0; i < k; ++i) { |
| 1703 | fun(); |
| 1704 | } |
| 1705 | } |
| 1706 | Fun fun; |
| 1707 | }; |
| 1708 | template <typename Fun> |
| 1709 | repeater<std::decay_t<Fun>> repeat(Fun&& fun) { |
| 1710 | return { CATCH_FORWARD(fun) }; |
| 1711 | } |
| 1712 | } // namespace Detail |
| 1713 | } // namespace Benchmark |
| 1714 | } // namespace Catch |
| 1715 | |
| 1716 | #endif // CATCH_REPEAT_HPP_INCLUDED |
| 1717 | |
| 1718 | |
| 1719 | // Adapted from donated nonius code. |
| 1720 | |
| 1721 | #ifndef CATCH_RUN_FOR_AT_LEAST_HPP_INCLUDED |
| 1722 | #define CATCH_RUN_FOR_AT_LEAST_HPP_INCLUDED |
| 1723 | |
| 1724 | |
| 1725 | |
| 1726 | // Adapted from donated nonius code. |
| 1727 | |
| 1728 | #ifndef CATCH_MEASURE_HPP_INCLUDED |
| 1729 | #define CATCH_MEASURE_HPP_INCLUDED |
| 1730 | |
| 1731 | |
| 1732 | |
| 1733 | // Adapted from donated nonius code. |
| 1734 | |
| 1735 | #ifndef CATCH_COMPLETE_INVOKE_HPP_INCLUDED |
| 1736 | #define CATCH_COMPLETE_INVOKE_HPP_INCLUDED |
| 1737 | |
| 1738 | |
| 1739 | namespace Catch { |
| 1740 | namespace Benchmark { |
| 1741 | namespace Detail { |
| 1742 | template <typename T> |
| 1743 | struct CompleteType { using type = T; }; |
| 1744 | template <> |
| 1745 | struct CompleteType<void> { struct type {}; }; |
| 1746 | |
| 1747 | template <typename T> |
| 1748 | using CompleteType_t = typename CompleteType<T>::type; |
| 1749 | |
| 1750 | template <typename Result> |
| 1751 | struct CompleteInvoker { |
| 1752 | template <typename Fun, typename... Args> |
| 1753 | static Result invoke(Fun&& fun, Args&&... args) { |
| 1754 | return CATCH_FORWARD(fun)(CATCH_FORWARD(args)...); |
| 1755 | } |
| 1756 | }; |
| 1757 | template <> |
| 1758 | struct CompleteInvoker<void> { |
| 1759 | template <typename Fun, typename... Args> |
| 1760 | static CompleteType_t<void> invoke(Fun&& fun, Args&&... args) { |
| 1761 | CATCH_FORWARD(fun)(CATCH_FORWARD(args)...); |
| 1762 | return {}; |
| 1763 | } |
| 1764 | }; |
| 1765 | |
| 1766 | // invoke and not return void :( |
| 1767 | template <typename Fun, typename... Args> |
| 1768 | CompleteType_t<FunctionReturnType<Fun, Args...>> complete_invoke(Fun&& fun, Args&&... args) { |
| 1769 | return CompleteInvoker<FunctionReturnType<Fun, Args...>>::invoke(CATCH_FORWARD(fun), CATCH_FORWARD(args)...); |
| 1770 | } |
| 1771 | |
| 1772 | } // namespace Detail |
| 1773 | |
| 1774 | template <typename Fun> |
| 1775 | Detail::CompleteType_t<FunctionReturnType<Fun>> user_code(Fun&& fun) { |
| 1776 | return Detail::complete_invoke(CATCH_FORWARD(fun)); |
| 1777 | } |
| 1778 | } // namespace Benchmark |
| 1779 | } // namespace Catch |
| 1780 | |
| 1781 | #endif // CATCH_COMPLETE_INVOKE_HPP_INCLUDED |
| 1782 | |
| 1783 | |
| 1784 | // Adapted from donated nonius code. |
| 1785 | |
| 1786 | #ifndef CATCH_TIMING_HPP_INCLUDED |
| 1787 | #define CATCH_TIMING_HPP_INCLUDED |
| 1788 | |
| 1789 | |
| 1790 | #include <type_traits> |
| 1791 | |
| 1792 | namespace Catch { |
| 1793 | namespace Benchmark { |
| 1794 | template <typename Duration, typename Result> |
| 1795 | struct Timing { |
| 1796 | Duration elapsed; |
| 1797 | Result result; |
| 1798 | int iterations; |
| 1799 | }; |
| 1800 | template <typename Clock, typename Func, typename... Args> |
| 1801 | using TimingOf = Timing<ClockDuration<Clock>, Detail::CompleteType_t<FunctionReturnType<Func, Args...>>>; |
| 1802 | } // namespace Benchmark |
| 1803 | } // namespace Catch |
| 1804 | |
| 1805 | #endif // CATCH_TIMING_HPP_INCLUDED |
| 1806 | |
| 1807 | namespace Catch { |
| 1808 | namespace Benchmark { |
| 1809 | namespace Detail { |
| 1810 | template <typename Clock, typename Fun, typename... Args> |
| 1811 | TimingOf<Clock, Fun, Args...> measure(Fun&& fun, Args&&... args) { |
| 1812 | auto start = Clock::now(); |
| 1813 | auto&& r = Detail::complete_invoke(fun, CATCH_FORWARD(args)...); |
| 1814 | auto end = Clock::now(); |
| 1815 | auto delta = end - start; |
| 1816 | return { delta, CATCH_FORWARD(r), 1 }; |
| 1817 | } |
| 1818 | } // namespace Detail |
| 1819 | } // namespace Benchmark |
| 1820 | } // namespace Catch |
| 1821 | |
| 1822 | #endif // CATCH_MEASURE_HPP_INCLUDED |
| 1823 | |
| 1824 | #include <type_traits> |
| 1825 | |
| 1826 | namespace Catch { |
| 1827 | namespace Benchmark { |
| 1828 | namespace Detail { |
| 1829 | template <typename Clock, typename Fun> |
| 1830 | TimingOf<Clock, Fun, int> measure_one(Fun&& fun, int iters, std::false_type) { |
| 1831 | return Detail::measure<Clock>(fun, iters); |
| 1832 | } |
| 1833 | template <typename Clock, typename Fun> |
| 1834 | TimingOf<Clock, Fun, Chronometer> measure_one(Fun&& fun, int iters, std::true_type) { |
| 1835 | Detail::ChronometerModel<Clock> meter; |
| 1836 | auto&& result = Detail::complete_invoke(fun, Chronometer(meter, iters)); |
| 1837 | |
| 1838 | return { meter.elapsed(), CATCH_MOVE(result), iters }; |
| 1839 | } |
| 1840 | |
| 1841 | template <typename Clock, typename Fun> |
| 1842 | using run_for_at_least_argument_t = std::conditional_t<is_callable<Fun(Chronometer)>::value, Chronometer, int>; |
| 1843 | |
| 1844 | |
| 1845 | [[noreturn]] |
| 1846 | void throw_optimized_away_error(); |
| 1847 | |
| 1848 | template <typename Clock, typename Fun> |
| 1849 | TimingOf<Clock, Fun, run_for_at_least_argument_t<Clock, Fun>> |
| 1850 | run_for_at_least(ClockDuration<Clock> how_long, |
| 1851 | const int initial_iterations, |
| 1852 | Fun&& fun) { |
| 1853 | auto iters = initial_iterations; |
| 1854 | while (iters < (1 << 30)) { |
| 1855 | auto&& Timing = measure_one<Clock>(fun, iters, is_callable<Fun(Chronometer)>()); |
| 1856 | |
| 1857 | if (Timing.elapsed >= how_long) { |
| 1858 | return { Timing.elapsed, CATCH_MOVE(Timing.result), iters }; |
| 1859 | } |
| 1860 | iters *= 2; |
| 1861 | } |
| 1862 | throw_optimized_away_error(); |
| 1863 | } |
| 1864 | } // namespace Detail |
| 1865 | } // namespace Benchmark |
| 1866 | } // namespace Catch |
| 1867 | |
| 1868 | #endif // CATCH_RUN_FOR_AT_LEAST_HPP_INCLUDED |
| 1869 | |
| 1870 | #include <vector> |
| 1871 | |
| 1872 | namespace Catch { |
| 1873 | namespace Benchmark { |
| 1874 | template <typename Duration> |
| 1875 | struct ExecutionPlan { |
| 1876 | int iterations_per_sample; |
| 1877 | Duration estimated_duration; |
| 1878 | Detail::BenchmarkFunction benchmark; |
| 1879 | Duration warmup_time; |
| 1880 | int warmup_iterations; |
| 1881 | |
| 1882 | template <typename Duration2> |
| 1883 | operator ExecutionPlan<Duration2>() const { |
| 1884 | return { iterations_per_sample, estimated_duration, benchmark, warmup_time, warmup_iterations }; |
| 1885 | } |
| 1886 | |
| 1887 | template <typename Clock> |
| 1888 | std::vector<FloatDuration<Clock>> run(const IConfig &cfg, Environment<FloatDuration<Clock>> env) const { |
| 1889 | // warmup a bit |
| 1890 | Detail::run_for_at_least<Clock>(std::chrono::duration_cast<ClockDuration<Clock>>(warmup_time), warmup_iterations, Detail::repeat(now<Clock>{})); |
| 1891 | |
| 1892 | std::vector<FloatDuration<Clock>> times; |
| 1893 | const auto num_samples = cfg.benchmarkSamples(); |
| 1894 | times.reserve( num_samples ); |
| 1895 | for ( size_t i = 0; i < num_samples; ++i ) { |
| 1896 | Detail::ChronometerModel<Clock> model; |
| 1897 | this->benchmark( Chronometer( model, iterations_per_sample ) ); |
| 1898 | auto sample_time = model.elapsed() - env.clock_cost.mean; |
| 1899 | if ( sample_time < FloatDuration<Clock>::zero() ) { |
| 1900 | sample_time = FloatDuration<Clock>::zero(); |
| 1901 | } |
| 1902 | times.push_back(sample_time / iterations_per_sample); |
| 1903 | } |
| 1904 | return times; |
| 1905 | } |
| 1906 | }; |
| 1907 | } // namespace Benchmark |
| 1908 | } // namespace Catch |
| 1909 | |
| 1910 | #endif // CATCH_EXECUTION_PLAN_HPP_INCLUDED |
| 1911 | |
| 1912 | |
| 1913 | // Adapted from donated nonius code. |
| 1914 | |
| 1915 | #ifndef CATCH_ESTIMATE_CLOCK_HPP_INCLUDED |
| 1916 | #define CATCH_ESTIMATE_CLOCK_HPP_INCLUDED |
| 1917 | |
| 1918 | |
| 1919 | |
| 1920 | // Adapted from donated nonius code. |
| 1921 | |
| 1922 | #ifndef CATCH_STATS_HPP_INCLUDED |
| 1923 | #define CATCH_STATS_HPP_INCLUDED |
| 1924 | |
| 1925 | |
| 1926 | #include <algorithm> |
| 1927 | #include <vector> |
| 1928 | #include <cmath> |
| 1929 | |
| 1930 | namespace Catch { |
| 1931 | namespace Benchmark { |
| 1932 | namespace Detail { |
| 1933 | using sample = std::vector<double>; |
| 1934 | |
| 1935 | // Used when we know we want == comparison of two doubles |
| 1936 | // to centralize warning suppression |
| 1937 | bool directCompare( double lhs, double rhs ); |
| 1938 | |
| 1939 | double weighted_average_quantile(int k, int q, std::vector<double>::iterator first, std::vector<double>::iterator last); |
| 1940 | |
| 1941 | OutlierClassification |
| 1942 | classify_outliers( std::vector<double>::const_iterator first, |
| 1943 | std::vector<double>::const_iterator last ); |
| 1944 | |
| 1945 | double mean( std::vector<double>::const_iterator first, |
| 1946 | std::vector<double>::const_iterator last ); |
| 1947 | |
| 1948 | template <typename Estimator> |
| 1949 | sample jackknife(Estimator&& estimator, |
| 1950 | std::vector<double>::iterator first, |
| 1951 | std::vector<double>::iterator last) { |
| 1952 | auto n = static_cast<size_t>(last - first); |
| 1953 | auto second = first; |
| 1954 | ++second; |
| 1955 | sample results; |
| 1956 | results.reserve(n); |
| 1957 | |
| 1958 | for (auto it = first; it != last; ++it) { |
| 1959 | std::iter_swap(it, first); |
| 1960 | results.push_back(estimator(second, last)); |
| 1961 | } |
| 1962 | |
| 1963 | return results; |
| 1964 | } |
| 1965 | |
| 1966 | inline double normal_cdf(double x) { |
| 1967 | return std::erfc(-x / std::sqrt(2.0)) / 2.0; |
| 1968 | } |
| 1969 | |
| 1970 | double erfc_inv(double x); |
| 1971 | |
| 1972 | double normal_quantile(double p); |
| 1973 | |
| 1974 | template <typename Estimator> |
| 1975 | Estimate<double> bootstrap( double confidence_level, |
| 1976 | std::vector<double>::iterator first, |
| 1977 | std::vector<double>::iterator last, |
| 1978 | sample const& resample, |
| 1979 | Estimator&& estimator ) { |
| 1980 | auto n_samples = last - first; |
| 1981 | |
| 1982 | double point = estimator(first, last); |
| 1983 | // Degenerate case with a single sample |
| 1984 | if (n_samples == 1) return { point, point, point, confidence_level }; |
| 1985 | |
| 1986 | sample jack = jackknife(estimator, first, last); |
| 1987 | double jack_mean = mean(jack.begin(), jack.end()); |
| 1988 | double sum_squares = 0, sum_cubes = 0; |
| 1989 | for (double x : jack) { |
| 1990 | auto difference = jack_mean - x; |
| 1991 | auto square = difference * difference; |
| 1992 | auto cube = square * difference; |
| 1993 | sum_squares += square; sum_cubes += cube; |
| 1994 | } |
| 1995 | |
| 1996 | double accel = sum_cubes / (6 * std::pow(sum_squares, 1.5)); |
| 1997 | long n = static_cast<long>(resample.size()); |
| 1998 | double prob_n = std::count_if(resample.begin(), resample.end(), [point](double x) { return x < point; }) / static_cast<double>(n); |
| 1999 | // degenerate case with uniform samples |
| 2000 | if ( directCompare( prob_n, 0. ) ) { |
| 2001 | return { point, point, point, confidence_level }; |
| 2002 | } |
| 2003 | |
| 2004 | double bias = normal_quantile(prob_n); |
| 2005 | double z1 = normal_quantile((1. - confidence_level) / 2.); |
| 2006 | |
| 2007 | auto cumn = [n]( double x ) -> long { |
| 2008 | return std::lround( normal_cdf( x ) * static_cast<double>(n) ); |
| 2009 | }; |
| 2010 | auto a = [bias, accel](double b) { return bias + b / (1. - accel * b); }; |
| 2011 | double b1 = bias + z1; |
| 2012 | double b2 = bias - z1; |
| 2013 | double a1 = a(b1); |
| 2014 | double a2 = a(b2); |
| 2015 | auto lo = static_cast<size_t>((std::max)(cumn(a1), 0l)); |
| 2016 | auto hi = static_cast<size_t>((std::min)(cumn(a2), n - 1)); |
| 2017 | |
| 2018 | return { point, resample[lo], resample[hi], confidence_level }; |
| 2019 | } |
| 2020 | |
| 2021 | struct bootstrap_analysis { |
| 2022 | Estimate<double> mean; |
| 2023 | Estimate<double> standard_deviation; |
| 2024 | double outlier_variance; |
| 2025 | }; |
| 2026 | |
| 2027 | bootstrap_analysis analyse_samples(double confidence_level, |
| 2028 | unsigned int n_resamples, |
| 2029 | std::vector<double>::iterator first, |
| 2030 | std::vector<double>::iterator last); |
| 2031 | } // namespace Detail |
| 2032 | } // namespace Benchmark |
| 2033 | } // namespace Catch |
| 2034 | |
| 2035 | #endif // CATCH_STATS_HPP_INCLUDED |
| 2036 | |
| 2037 | #include <algorithm> |
| 2038 | #include <vector> |
| 2039 | #include <cmath> |
| 2040 | |
| 2041 | namespace Catch { |
| 2042 | namespace Benchmark { |
| 2043 | namespace Detail { |
| 2044 | template <typename Clock> |
| 2045 | std::vector<double> resolution(int k) { |
| 2046 | std::vector<TimePoint<Clock>> times; |
| 2047 | times.reserve(static_cast<size_t>(k + 1)); |
| 2048 | for ( int i = 0; i < k + 1; ++i ) { |
| 2049 | times.push_back( Clock::now() ); |
| 2050 | } |
| 2051 | |
| 2052 | std::vector<double> deltas; |
| 2053 | deltas.reserve(static_cast<size_t>(k)); |
| 2054 | for ( size_t idx = 1; idx < times.size(); ++idx ) { |
| 2055 | deltas.push_back( static_cast<double>( |
| 2056 | ( times[idx] - times[idx - 1] ).count() ) ); |
| 2057 | } |
| 2058 | |
| 2059 | return deltas; |
| 2060 | } |
| 2061 | |
| 2062 | constexpr auto warmup_iterations = 10000; |
| 2063 | constexpr auto warmup_time = std::chrono::milliseconds(100); |
| 2064 | constexpr auto minimum_ticks = 1000; |
| 2065 | constexpr auto warmup_seed = 10000; |
| 2066 | constexpr auto clock_resolution_estimation_time = std::chrono::milliseconds(500); |
| 2067 | constexpr auto clock_cost_estimation_time_limit = std::chrono::seconds(1); |
| 2068 | constexpr auto clock_cost_estimation_tick_limit = 100000; |
| 2069 | constexpr auto clock_cost_estimation_time = std::chrono::milliseconds(10); |
| 2070 | constexpr auto clock_cost_estimation_iterations = 10000; |
| 2071 | |
| 2072 | template <typename Clock> |
| 2073 | int warmup() { |
| 2074 | return run_for_at_least<Clock>(std::chrono::duration_cast<ClockDuration<Clock>>(warmup_time), warmup_seed, &resolution<Clock>) |
| 2075 | .iterations; |
| 2076 | } |
| 2077 | template <typename Clock> |
| 2078 | EnvironmentEstimate<FloatDuration<Clock>> estimate_clock_resolution(int iterations) { |
| 2079 | auto r = run_for_at_least<Clock>(std::chrono::duration_cast<ClockDuration<Clock>>(clock_resolution_estimation_time), iterations, &resolution<Clock>) |
| 2080 | .result; |
| 2081 | return { |
| 2082 | FloatDuration<Clock>(mean(r.begin(), r.end())), |
| 2083 | classify_outliers(r.begin(), r.end()), |
| 2084 | }; |
| 2085 | } |
| 2086 | template <typename Clock> |
| 2087 | EnvironmentEstimate<FloatDuration<Clock>> estimate_clock_cost(FloatDuration<Clock> resolution) { |
| 2088 | auto time_limit = (std::min)( |
| 2089 | resolution * clock_cost_estimation_tick_limit, |
| 2090 | FloatDuration<Clock>(clock_cost_estimation_time_limit)); |
| 2091 | auto time_clock = [](int k) { |
| 2092 | return Detail::measure<Clock>([k] { |
| 2093 | for (int i = 0; i < k; ++i) { |
| 2094 | volatile auto ignored = Clock::now(); |
| 2095 | (void)ignored; |
| 2096 | } |
| 2097 | }).elapsed; |
| 2098 | }; |
| 2099 | time_clock(1); |
| 2100 | int iters = clock_cost_estimation_iterations; |
| 2101 | auto&& r = run_for_at_least<Clock>(std::chrono::duration_cast<ClockDuration<Clock>>(clock_cost_estimation_time), iters, time_clock); |
| 2102 | std::vector<double> times; |
| 2103 | int nsamples = static_cast<int>(std::ceil(time_limit / r.elapsed)); |
| 2104 | times.reserve(static_cast<size_t>(nsamples)); |
| 2105 | for ( int s = 0; s < nsamples; ++s ) { |
| 2106 | times.push_back( static_cast<double>( |
| 2107 | ( time_clock( r.iterations ) / r.iterations ) |
| 2108 | .count() ) ); |
| 2109 | } |
| 2110 | return { |
| 2111 | FloatDuration<Clock>(mean(times.begin(), times.end())), |
| 2112 | classify_outliers(times.begin(), times.end()), |
| 2113 | }; |
| 2114 | } |
| 2115 | |
| 2116 | template <typename Clock> |
| 2117 | Environment<FloatDuration<Clock>> measure_environment() { |
| 2118 | #if defined(__clang__) |
| 2119 | # pragma clang diagnostic push |
| 2120 | # pragma clang diagnostic ignored "-Wexit-time-destructors" |
| 2121 | #endif |
| 2122 | static Catch::Detail::unique_ptr<Environment<FloatDuration<Clock>>> env; |
| 2123 | #if defined(__clang__) |
| 2124 | # pragma clang diagnostic pop |
| 2125 | #endif |
| 2126 | if (env) { |
| 2127 | return *env; |
| 2128 | } |
| 2129 | |
| 2130 | auto iters = Detail::warmup<Clock>(); |
| 2131 | auto resolution = Detail::estimate_clock_resolution<Clock>(iters); |
| 2132 | auto cost = Detail::estimate_clock_cost<Clock>(resolution.mean); |
| 2133 | |
| 2134 | env = Catch::Detail::make_unique<Environment<FloatDuration<Clock>>>( Environment<FloatDuration<Clock>>{resolution, cost} ); |
| 2135 | return *env; |
| 2136 | } |
| 2137 | } // namespace Detail |
| 2138 | } // namespace Benchmark |
| 2139 | } // namespace Catch |
| 2140 | |
| 2141 | #endif // CATCH_ESTIMATE_CLOCK_HPP_INCLUDED |
| 2142 | |
| 2143 | |
| 2144 | // Adapted from donated nonius code. |
| 2145 | |
| 2146 | #ifndef CATCH_ANALYSE_HPP_INCLUDED |
| 2147 | #define CATCH_ANALYSE_HPP_INCLUDED |
| 2148 | |
| 2149 | |
| 2150 | |
| 2151 | // Adapted from donated nonius code. |
| 2152 | |
| 2153 | #ifndef CATCH_SAMPLE_ANALYSIS_HPP_INCLUDED |
| 2154 | #define CATCH_SAMPLE_ANALYSIS_HPP_INCLUDED |
| 2155 | |
| 2156 | |
| 2157 | #include <vector> |
| 2158 | |
| 2159 | namespace Catch { |
| 2160 | namespace Benchmark { |
| 2161 | template <typename Duration> |
| 2162 | struct SampleAnalysis { |
| 2163 | std::vector<Duration> samples; |
| 2164 | Estimate<Duration> mean; |
| 2165 | Estimate<Duration> standard_deviation; |
| 2166 | OutlierClassification outliers; |
| 2167 | double outlier_variance; |
| 2168 | |
| 2169 | template <typename Duration2> |
| 2170 | operator SampleAnalysis<Duration2>() const { |
| 2171 | std::vector<Duration2> samples2; |
| 2172 | samples2.reserve(samples.size()); |
| 2173 | for (auto const& d : samples) { |
| 2174 | samples2.push_back(Duration2(d)); |
| 2175 | } |
| 2176 | return { |
| 2177 | CATCH_MOVE(samples2), |
| 2178 | mean, |
| 2179 | standard_deviation, |
| 2180 | outliers, |
| 2181 | outlier_variance, |
| 2182 | }; |
| 2183 | } |
| 2184 | }; |
| 2185 | } // namespace Benchmark |
| 2186 | } // namespace Catch |
| 2187 | |
| 2188 | #endif // CATCH_SAMPLE_ANALYSIS_HPP_INCLUDED |
| 2189 | |
| 2190 | #include <vector> |
| 2191 | |
| 2192 | namespace Catch { |
| 2193 | namespace Benchmark { |
| 2194 | namespace Detail { |
| 2195 | template <typename Duration, typename Iterator> |
| 2196 | SampleAnalysis<Duration> analyse(const IConfig &cfg, Environment<Duration>, Iterator first, Iterator last) { |
| 2197 | if (!cfg.benchmarkNoAnalysis()) { |
| 2198 | std::vector<double> samples; |
| 2199 | samples.reserve(static_cast<size_t>(last - first)); |
| 2200 | for (auto current = first; current != last; ++current) { |
| 2201 | samples.push_back( current->count() ); |
| 2202 | } |
| 2203 | |
| 2204 | auto analysis = Catch::Benchmark::Detail::analyse_samples(cfg.benchmarkConfidenceInterval(), cfg.benchmarkResamples(), samples.begin(), samples.end()); |
| 2205 | auto outliers = Catch::Benchmark::Detail::classify_outliers(samples.begin(), samples.end()); |
| 2206 | |
| 2207 | auto wrap_estimate = [](Estimate<double> e) { |
| 2208 | return Estimate<Duration> { |
| 2209 | Duration(e.point), |
| 2210 | Duration(e.lower_bound), |
| 2211 | Duration(e.upper_bound), |
| 2212 | e.confidence_interval, |
| 2213 | }; |
| 2214 | }; |
| 2215 | std::vector<Duration> samples2; |
| 2216 | samples2.reserve(samples.size()); |
| 2217 | for (auto s : samples) { |
| 2218 | samples2.push_back( Duration( s ) ); |
| 2219 | } |
| 2220 | |
| 2221 | return { |
| 2222 | CATCH_MOVE(samples2), |
| 2223 | wrap_estimate(analysis.mean), |
| 2224 | wrap_estimate(analysis.standard_deviation), |
| 2225 | outliers, |
| 2226 | analysis.outlier_variance, |
| 2227 | }; |
| 2228 | } else { |
| 2229 | std::vector<Duration> samples; |
| 2230 | samples.reserve(static_cast<size_t>(last - first)); |
| 2231 | |
| 2232 | Duration mean = Duration(0); |
| 2233 | int i = 0; |
| 2234 | for (auto it = first; it < last; ++it, ++i) { |
| 2235 | samples.push_back(Duration(*it)); |
| 2236 | mean += Duration(*it); |
| 2237 | } |
| 2238 | mean /= i; |
| 2239 | |
| 2240 | return { |
| 2241 | CATCH_MOVE(samples), |
| 2242 | Estimate<Duration>{mean, mean, mean, 0.0}, |
| 2243 | Estimate<Duration>{Duration(0), Duration(0), Duration(0), 0.0}, |
| 2244 | OutlierClassification{}, |
| 2245 | 0.0 |
| 2246 | }; |
| 2247 | } |
| 2248 | } |
| 2249 | } // namespace Detail |
| 2250 | } // namespace Benchmark |
| 2251 | } // namespace Catch |
| 2252 | |
| 2253 | #endif // CATCH_ANALYSE_HPP_INCLUDED |
| 2254 | |
| 2255 | #include <algorithm> |
| 2256 | #include <chrono> |
| 2257 | #include <exception> |
| 2258 | #include <functional> |
| 2259 | #include <string> |
| 2260 | #include <vector> |
| 2261 | #include <cmath> |
| 2262 | |
| 2263 | namespace Catch { |
| 2264 | namespace Benchmark { |
| 2265 | struct Benchmark { |
| 2266 | Benchmark(std::string&& benchmarkName) |
| 2267 | : name(CATCH_MOVE(benchmarkName)) {} |
| 2268 | |
| 2269 | template <class FUN> |
| 2270 | Benchmark(std::string&& benchmarkName , FUN &&func) |
| 2271 | : fun(CATCH_MOVE(func)), name(CATCH_MOVE(benchmarkName)) {} |
| 2272 | |
| 2273 | template <typename Clock> |
| 2274 | ExecutionPlan<FloatDuration<Clock>> prepare(const IConfig &cfg, Environment<FloatDuration<Clock>> env) const { |
| 2275 | auto min_time = env.clock_resolution.mean * Detail::minimum_ticks; |
| 2276 | auto run_time = std::max(min_time, std::chrono::duration_cast<decltype(min_time)>(cfg.benchmarkWarmupTime())); |
| 2277 | auto&& test = Detail::run_for_at_least<Clock>(std::chrono::duration_cast<ClockDuration<Clock>>(run_time), 1, fun); |
| 2278 | int new_iters = static_cast<int>(std::ceil(min_time * test.iterations / test.elapsed)); |
| 2279 | return { new_iters, test.elapsed / test.iterations * new_iters * cfg.benchmarkSamples(), fun, std::chrono::duration_cast<FloatDuration<Clock>>(cfg.benchmarkWarmupTime()), Detail::warmup_iterations }; |
| 2280 | } |
| 2281 | |
| 2282 | template <typename Clock = default_clock> |
| 2283 | void run() { |
| 2284 | auto const* cfg = getCurrentContext().getConfig(); |
| 2285 | |
| 2286 | auto env = Detail::measure_environment<Clock>(); |
| 2287 | |
| 2288 | getResultCapture().benchmarkPreparing(name); |
| 2289 | CATCH_TRY{ |
| 2290 | auto plan = user_code([&] { |
| 2291 | return prepare<Clock>(*cfg, env); |
| 2292 | }); |
| 2293 | |
| 2294 | BenchmarkInfo info { |
| 2295 | CATCH_MOVE(name), |
| 2296 | plan.estimated_duration.count(), |
| 2297 | plan.iterations_per_sample, |
| 2298 | cfg->benchmarkSamples(), |
| 2299 | cfg->benchmarkResamples(), |
| 2300 | env.clock_resolution.mean.count(), |
| 2301 | env.clock_cost.mean.count() |
| 2302 | }; |
| 2303 | |
| 2304 | getResultCapture().benchmarkStarting(info); |
| 2305 | |
| 2306 | auto samples = user_code([&] { |
| 2307 | return plan.template run<Clock>(*cfg, env); |
| 2308 | }); |
| 2309 | |
| 2310 | auto analysis = Detail::analyse(*cfg, env, samples.begin(), samples.end()); |
| 2311 | BenchmarkStats<FloatDuration<Clock>> stats{ CATCH_MOVE(info), CATCH_MOVE(analysis.samples), analysis.mean, analysis.standard_deviation, analysis.outliers, analysis.outlier_variance }; |
| 2312 | getResultCapture().benchmarkEnded(stats); |
| 2313 | } CATCH_CATCH_ANON (TestFailureException const&) { |
| 2314 | getResultCapture().benchmarkFailed("Benchmark failed due to failed assertion"_sr); |
| 2315 | } CATCH_CATCH_ALL{ |
| 2316 | getResultCapture().benchmarkFailed(translateActiveException()); |
| 2317 | // We let the exception go further up so that the |
| 2318 | // test case is marked as failed. |
| 2319 | std::rethrow_exception(std::current_exception()); |
| 2320 | } |
| 2321 | } |
| 2322 | |
| 2323 | // sets lambda to be used in fun *and* executes benchmark! |
| 2324 | template <typename Fun, std::enable_if_t<!Detail::is_related<Fun, Benchmark>::value, int> = 0> |
| 2325 | Benchmark & operator=(Fun func) { |
| 2326 | auto const* cfg = getCurrentContext().getConfig(); |
| 2327 | if (!cfg->skipBenchmarks()) { |
| 2328 | fun = Detail::BenchmarkFunction(func); |
| 2329 | run(); |
| 2330 | } |
| 2331 | return *this; |
| 2332 | } |
| 2333 | |
| 2334 | explicit operator bool() { |
| 2335 | return true; |
| 2336 | } |
| 2337 | |
| 2338 | private: |
| 2339 | Detail::BenchmarkFunction fun; |
| 2340 | std::string name; |
| 2341 | }; |
| 2342 | } |
| 2343 | } // namespace Catch |
| 2344 | |
| 2345 | #define INTERNAL_CATCH_GET_1_ARG(arg1, arg2, ...) arg1 |
| 2346 | #define INTERNAL_CATCH_GET_2_ARG(arg1, arg2, ...) arg2 |
| 2347 | |
| 2348 | #define INTERNAL_CATCH_BENCHMARK(BenchmarkName, name, benchmarkIndex)\ |
| 2349 | if( Catch::Benchmark::Benchmark BenchmarkName{name} ) \ |
| 2350 | BenchmarkName = [&](int benchmarkIndex) |
| 2351 | |
| 2352 | #define INTERNAL_CATCH_BENCHMARK_ADVANCED(BenchmarkName, name)\ |
| 2353 | if( Catch::Benchmark::Benchmark BenchmarkName{name} ) \ |
| 2354 | BenchmarkName = [&] |
| 2355 | |
| 2356 | #if defined(CATCH_CONFIG_PREFIX_ALL) |
| 2357 | |
| 2358 | #define CATCH_BENCHMARK(...) \ |
| 2359 | INTERNAL_CATCH_BENCHMARK(INTERNAL_CATCH_UNIQUE_NAME(CATCH2_INTERNAL_BENCHMARK_), INTERNAL_CATCH_GET_1_ARG(__VA_ARGS__,,), INTERNAL_CATCH_GET_2_ARG(__VA_ARGS__,,)) |
| 2360 | #define CATCH_BENCHMARK_ADVANCED(name) \ |
| 2361 | INTERNAL_CATCH_BENCHMARK_ADVANCED(INTERNAL_CATCH_UNIQUE_NAME(CATCH2_INTERNAL_BENCHMARK_), name) |
| 2362 | |
| 2363 | #else |
| 2364 | |
| 2365 | #define BENCHMARK(...) \ |
| 2366 | INTERNAL_CATCH_BENCHMARK(INTERNAL_CATCH_UNIQUE_NAME(CATCH2_INTERNAL_BENCHMARK_), INTERNAL_CATCH_GET_1_ARG(__VA_ARGS__,,), INTERNAL_CATCH_GET_2_ARG(__VA_ARGS__,,)) |
| 2367 | #define BENCHMARK_ADVANCED(name) \ |
| 2368 | INTERNAL_CATCH_BENCHMARK_ADVANCED(INTERNAL_CATCH_UNIQUE_NAME(CATCH2_INTERNAL_BENCHMARK_), name) |
| 2369 | |
| 2370 | #endif |
| 2371 | |
| 2372 | #endif // CATCH_BENCHMARK_HPP_INCLUDED |
| 2373 | |
| 2374 | |
| 2375 | // Adapted from donated nonius code. |
| 2376 | |
| 2377 | #ifndef CATCH_CONSTRUCTOR_HPP_INCLUDED |
| 2378 | #define CATCH_CONSTRUCTOR_HPP_INCLUDED |
| 2379 | |
| 2380 | |
| 2381 | #include <type_traits> |
| 2382 | |
| 2383 | namespace Catch { |
| 2384 | namespace Benchmark { |
| 2385 | namespace Detail { |
| 2386 | template <typename T, bool Destruct> |
| 2387 | struct ObjectStorage |
| 2388 | { |
| 2389 | ObjectStorage() = default; |
| 2390 | |
| 2391 | ObjectStorage(const ObjectStorage& other) |
| 2392 | { |
| 2393 | new(&data) T(other.stored_object()); |
| 2394 | } |
| 2395 | |
| 2396 | ObjectStorage(ObjectStorage&& other) |
| 2397 | { |
| 2398 | new(data) T(CATCH_MOVE(other.stored_object())); |
| 2399 | } |
| 2400 | |
| 2401 | ~ObjectStorage() { destruct_on_exit<T>(); } |
| 2402 | |
| 2403 | template <typename... Args> |
| 2404 | void construct(Args&&... args) |
| 2405 | { |
| 2406 | new (data) T(CATCH_FORWARD(args)...); |
| 2407 | } |
| 2408 | |
| 2409 | template <bool AllowManualDestruction = !Destruct> |
| 2410 | std::enable_if_t<AllowManualDestruction> destruct() |
| 2411 | { |
| 2412 | stored_object().~T(); |
| 2413 | } |
| 2414 | |
| 2415 | private: |
| 2416 | // If this is a constructor benchmark, destruct the underlying object |
| 2417 | template <typename U> |
| 2418 | void destruct_on_exit(std::enable_if_t<Destruct, U>* = nullptr) { destruct<true>(); } |
| 2419 | // Otherwise, don't |
| 2420 | template <typename U> |
| 2421 | void destruct_on_exit(std::enable_if_t<!Destruct, U>* = nullptr) { } |
| 2422 | |
| 2423 | #if defined( __GNUC__ ) && __GNUC__ <= 6 |
| 2424 | # pragma GCC diagnostic push |
| 2425 | # pragma GCC diagnostic ignored "-Wstrict-aliasing" |
| 2426 | #endif |
| 2427 | T& stored_object() { return *reinterpret_cast<T*>( data ); } |
| 2428 | |
| 2429 | T const& stored_object() const { |
| 2430 | return *reinterpret_cast<T const*>( data ); |
| 2431 | } |
| 2432 | #if defined( __GNUC__ ) && __GNUC__ <= 6 |
| 2433 | # pragma GCC diagnostic pop |
| 2434 | #endif |
| 2435 | |
| 2436 | alignas( T ) unsigned char data[sizeof( T )]{}; |
| 2437 | }; |
| 2438 | } // namespace Detail |
| 2439 | |
| 2440 | template <typename T> |
| 2441 | using storage_for = Detail::ObjectStorage<T, true>; |
| 2442 | |
| 2443 | template <typename T> |
| 2444 | using destructable_object = Detail::ObjectStorage<T, false>; |
| 2445 | } // namespace Benchmark |
| 2446 | } // namespace Catch |
| 2447 | |
| 2448 | #endif // CATCH_CONSTRUCTOR_HPP_INCLUDED |
| 2449 | |
| 2450 | #endif // CATCH_BENCHMARK_ALL_HPP_INCLUDED |
| 2451 | |
| 2452 | |
| 2453 | #ifndef CATCH_APPROX_HPP_INCLUDED |
| 2454 | #define CATCH_APPROX_HPP_INCLUDED |
| 2455 | |
| 2456 | |
| 2457 | |
| 2458 | #ifndef CATCH_TOSTRING_HPP_INCLUDED |
| 2459 | #define CATCH_TOSTRING_HPP_INCLUDED |
| 2460 | |
| 2461 | |
| 2462 | #include <vector> |
| 2463 | #include <cstddef> |
| 2464 | #include <type_traits> |
| 2465 | #include <string> |
| 2466 | |
| 2467 | |
| 2468 | |
| 2469 | |
| 2470 | /** \file |
| 2471 | * Wrapper for the WCHAR configuration option |
| 2472 | * |
| 2473 | * We want to support platforms that do not provide `wchar_t`, so we |
| 2474 | * sometimes have to disable providing wchar_t overloads through Catch2, |
| 2475 | * e.g. the StringMaker specialization for `std::wstring`. |
| 2476 | */ |
| 2477 | |
| 2478 | #ifndef CATCH_CONFIG_WCHAR_HPP_INCLUDED |
| 2479 | #define CATCH_CONFIG_WCHAR_HPP_INCLUDED |
| 2480 | |
| 2481 | |
| 2482 | // We assume that WCHAR should be enabled by default, and only disabled |
| 2483 | // for a shortlist (so far only DJGPP) of compilers. |
| 2484 | |
| 2485 | #if defined(__DJGPP__) |
| 2486 | # define CATCH_INTERNAL_CONFIG_NO_WCHAR |
| 2487 | #endif // __DJGPP__ |
| 2488 | |
| 2489 | #if !defined( CATCH_INTERNAL_CONFIG_NO_WCHAR ) && \ |
| 2490 | !defined( CATCH_CONFIG_NO_WCHAR ) && \ |
| 2491 | !defined( CATCH_CONFIG_WCHAR ) |
| 2492 | # define CATCH_CONFIG_WCHAR |
| 2493 | #endif |
| 2494 | |
| 2495 | #endif // CATCH_CONFIG_WCHAR_HPP_INCLUDED |
| 2496 | |
| 2497 | |
| 2498 | #ifndef CATCH_REUSABLE_STRING_STREAM_HPP_INCLUDED |
| 2499 | #define CATCH_REUSABLE_STRING_STREAM_HPP_INCLUDED |
| 2500 | |
| 2501 | |
| 2502 | #include <iosfwd> |
| 2503 | #include <cstddef> |
| 2504 | #include <ostream> |
| 2505 | #include <string> |
| 2506 | |
| 2507 | namespace Catch { |
| 2508 | |
| 2509 | class ReusableStringStream : Detail::NonCopyable { |
| 2510 | std::size_t m_index; |
| 2511 | std::ostream* m_oss; |
| 2512 | public: |
| 2513 | ReusableStringStream(); |
| 2514 | ~ReusableStringStream(); |
| 2515 | |
| 2516 | //! Returns the serialized state |
| 2517 | std::string str() const; |
| 2518 | //! Sets internal state to `str` |
| 2519 | void str(std::string const& str); |
| 2520 | |
| 2521 | #if defined(__GNUC__) && !defined(__clang__) |
| 2522 | #pragma GCC diagnostic push |
| 2523 | // Old versions of GCC do not understand -Wnonnull-compare |
| 2524 | #pragma GCC diagnostic ignored "-Wpragmas" |
| 2525 | // Streaming a function pointer triggers Waddress and Wnonnull-compare |
| 2526 | // on GCC, because it implicitly converts it to bool and then decides |
| 2527 | // that the check it uses (a? true : false) is tautological and cannot |
| 2528 | // be null... |
| 2529 | #pragma GCC diagnostic ignored "-Waddress" |
| 2530 | #pragma GCC diagnostic ignored "-Wnonnull-compare" |
| 2531 | #endif |
| 2532 | |
| 2533 | template<typename T> |
| 2534 | auto operator << ( T const& value ) -> ReusableStringStream& { |
| 2535 | *m_oss << value; |
| 2536 | return *this; |
| 2537 | } |
| 2538 | |
| 2539 | #if defined(__GNUC__) && !defined(__clang__) |
| 2540 | #pragma GCC diagnostic pop |
| 2541 | #endif |
| 2542 | auto get() -> std::ostream& { return *m_oss; } |
| 2543 | }; |
| 2544 | } |
| 2545 | |
| 2546 | #endif // CATCH_REUSABLE_STRING_STREAM_HPP_INCLUDED |
| 2547 | |
| 2548 | |
| 2549 | #ifndef CATCH_VOID_TYPE_HPP_INCLUDED |
| 2550 | #define CATCH_VOID_TYPE_HPP_INCLUDED |
| 2551 | |
| 2552 | |
| 2553 | namespace Catch { |
| 2554 | namespace Detail { |
| 2555 | |
| 2556 | template <typename...> |
| 2557 | struct make_void { using type = void; }; |
| 2558 | |
| 2559 | template <typename... Ts> |
| 2560 | using void_t = typename make_void<Ts...>::type; |
| 2561 | |
| 2562 | } // namespace Detail |
| 2563 | } // namespace Catch |
| 2564 | |
| 2565 | |
| 2566 | #endif // CATCH_VOID_TYPE_HPP_INCLUDED |
| 2567 | |
| 2568 | |
| 2569 | #ifndef CATCH_INTERFACES_ENUM_VALUES_REGISTRY_HPP_INCLUDED |
| 2570 | #define CATCH_INTERFACES_ENUM_VALUES_REGISTRY_HPP_INCLUDED |
| 2571 | |
| 2572 | |
| 2573 | #include <vector> |
| 2574 | |
| 2575 | namespace Catch { |
| 2576 | |
| 2577 | namespace Detail { |
| 2578 | struct EnumInfo { |
| 2579 | StringRef m_name; |
| 2580 | std::vector<std::pair<int, StringRef>> m_values; |
| 2581 | |
| 2582 | ~EnumInfo(); |
| 2583 | |
| 2584 | StringRef lookup( int value ) const; |
| 2585 | }; |
| 2586 | } // namespace Detail |
| 2587 | |
| 2588 | class IMutableEnumValuesRegistry { |
| 2589 | public: |
| 2590 | virtual ~IMutableEnumValuesRegistry(); // = default; |
| 2591 | |
| 2592 | virtual Detail::EnumInfo const& registerEnum( StringRef enumName, StringRef allEnums, std::vector<int> const& values ) = 0; |
| 2593 | |
| 2594 | template<typename E> |
| 2595 | Detail::EnumInfo const& registerEnum( StringRef enumName, StringRef allEnums, std::initializer_list<E> values ) { |
| 2596 | static_assert(sizeof(int) >= sizeof(E), "Cannot serialize enum to int"); |
| 2597 | std::vector<int> intValues; |
| 2598 | intValues.reserve( values.size() ); |
| 2599 | for( auto enumValue : values ) |
| 2600 | intValues.push_back( static_cast<int>( enumValue ) ); |
| 2601 | return registerEnum( enumName, allEnums, intValues ); |
| 2602 | } |
| 2603 | }; |
| 2604 | |
| 2605 | } // Catch |
| 2606 | |
| 2607 | #endif // CATCH_INTERFACES_ENUM_VALUES_REGISTRY_HPP_INCLUDED |
| 2608 | |
| 2609 | #ifdef CATCH_CONFIG_CPP17_STRING_VIEW |
| 2610 | #include <string_view> |
| 2611 | #endif |
| 2612 | |
| 2613 | #ifdef _MSC_VER |
| 2614 | #pragma warning(push) |
| 2615 | #pragma warning(disable:4180) // We attempt to stream a function (address) by const&, which MSVC complains about but is harmless |
| 2616 | #endif |
| 2617 | |
| 2618 | // We need a dummy global operator<< so we can bring it into Catch namespace later |
| 2619 | struct Catch_global_namespace_dummy{}; |
| 2620 | std::ostream& operator<<(std::ostream&, Catch_global_namespace_dummy); |
| 2621 | |
| 2622 | namespace Catch { |
| 2623 | // Bring in global namespace operator<< for ADL lookup in |
| 2624 | // `IsStreamInsertable` below. |
| 2625 | using ::operator<<; |
| 2626 | |
| 2627 | namespace Detail { |
| 2628 | |
| 2629 | inline std::size_t catch_strnlen(const char *str, std::size_t n) { |
| 2630 | auto ret = std::char_traits<char>::find(str, n, '\0'); |
| 2631 | if (ret != nullptr) { |
| 2632 | return static_cast<std::size_t>(ret - str); |
| 2633 | } |
| 2634 | return n; |
| 2635 | } |
| 2636 | |
| 2637 | constexpr StringRef unprintableString = "{?}"_sr; |
| 2638 | |
| 2639 | //! Encases `string in quotes, and optionally escapes invisibles |
| 2640 | std::string convertIntoString( StringRef string, bool escapeInvisibles ); |
| 2641 | |
| 2642 | //! Encases `string` in quotes, and escapes invisibles if user requested |
| 2643 | //! it via CLI |
| 2644 | std::string convertIntoString( StringRef string ); |
| 2645 | |
| 2646 | std::string rawMemoryToString( const void *object, std::size_t size ); |
| 2647 | |
| 2648 | template<typename T> |
| 2649 | std::string rawMemoryToString( const T& object ) { |
| 2650 | return rawMemoryToString( &object, sizeof(object) ); |
| 2651 | } |
| 2652 | |
| 2653 | template<typename T> |
| 2654 | class IsStreamInsertable { |
| 2655 | template<typename Stream, typename U> |
| 2656 | static auto test(int) |
| 2657 | -> decltype(std::declval<Stream&>() << std::declval<U>(), std::true_type()); |
| 2658 | |
| 2659 | template<typename, typename> |
| 2660 | static auto test(...)->std::false_type; |
| 2661 | |
| 2662 | public: |
| 2663 | static const bool value = decltype(test<std::ostream, const T&>(0))::value; |
| 2664 | }; |
| 2665 | |
| 2666 | template<typename E> |
| 2667 | std::string convertUnknownEnumToString( E e ); |
| 2668 | |
| 2669 | template<typename T> |
| 2670 | std::enable_if_t< |
| 2671 | !std::is_enum<T>::value && !std::is_base_of<std::exception, T>::value, |
| 2672 | std::string> convertUnstreamable( T const& ) { |
| 2673 | return std::string(Detail::unprintableString); |
| 2674 | } |
| 2675 | template<typename T> |
| 2676 | std::enable_if_t< |
| 2677 | !std::is_enum<T>::value && std::is_base_of<std::exception, T>::value, |
| 2678 | std::string> convertUnstreamable(T const& ex) { |
| 2679 | return ex.what(); |
| 2680 | } |
| 2681 | |
| 2682 | |
| 2683 | template<typename T> |
| 2684 | std::enable_if_t< |
| 2685 | std::is_enum<T>::value, |
| 2686 | std::string> convertUnstreamable( T const& value ) { |
| 2687 | return convertUnknownEnumToString( value ); |
| 2688 | } |
| 2689 | |
| 2690 | #if defined(_MANAGED) |
| 2691 | //! Convert a CLR string to a utf8 std::string |
| 2692 | template<typename T> |
| 2693 | std::string clrReferenceToString( T^ ref ) { |
| 2694 | if (ref == nullptr) |
| 2695 | return std::string("null"); |
| 2696 | auto bytes = System::Text::Encoding::UTF8->GetBytes(ref->ToString()); |
| 2697 | cli::pin_ptr<System::Byte> p = &bytes[0]; |
| 2698 | return std::string(reinterpret_cast<char const *>(p), bytes->Length); |
| 2699 | } |
| 2700 | #endif |
| 2701 | |
| 2702 | } // namespace Detail |
| 2703 | |
| 2704 | |
| 2705 | template <typename T, typename = void> |
| 2706 | struct StringMaker { |
| 2707 | template <typename Fake = T> |
| 2708 | static |
| 2709 | std::enable_if_t<::Catch::Detail::IsStreamInsertable<Fake>::value, std::string> |
| 2710 | convert(const Fake& value) { |
| 2711 | ReusableStringStream rss; |
| 2712 | // NB: call using the function-like syntax to avoid ambiguity with |
| 2713 | // user-defined templated operator<< under clang. |
| 2714 | rss.operator<<(value); |
| 2715 | return rss.str(); |
| 2716 | } |
| 2717 | |
| 2718 | template <typename Fake = T> |
| 2719 | static |
| 2720 | std::enable_if_t<!::Catch::Detail::IsStreamInsertable<Fake>::value, std::string> |
| 2721 | convert( const Fake& value ) { |
| 2722 | #if !defined(CATCH_CONFIG_FALLBACK_STRINGIFIER) |
| 2723 | return Detail::convertUnstreamable(value); |
| 2724 | #else |
| 2725 | return CATCH_CONFIG_FALLBACK_STRINGIFIER(value); |
| 2726 | #endif |
| 2727 | } |
| 2728 | }; |
| 2729 | |
| 2730 | namespace Detail { |
| 2731 | |
| 2732 | // This function dispatches all stringification requests inside of Catch. |
| 2733 | // Should be preferably called fully qualified, like ::Catch::Detail::stringify |
| 2734 | template <typename T> |
| 2735 | std::string stringify(const T& e) { |
| 2736 | return ::Catch::StringMaker<std::remove_cv_t<std::remove_reference_t<T>>>::convert(e); |
| 2737 | } |
| 2738 | |
| 2739 | template<typename E> |
| 2740 | std::string convertUnknownEnumToString( E e ) { |
| 2741 | return ::Catch::Detail::stringify(static_cast<std::underlying_type_t<E>>(e)); |
| 2742 | } |
| 2743 | |
| 2744 | #if defined(_MANAGED) |
| 2745 | template <typename T> |
| 2746 | std::string stringify( T^ e ) { |
| 2747 | return ::Catch::StringMaker<T^>::convert(e); |
| 2748 | } |
| 2749 | #endif |
| 2750 | |
| 2751 | } // namespace Detail |
| 2752 | |
| 2753 | // Some predefined specializations |
| 2754 | |
| 2755 | template<> |
| 2756 | struct StringMaker<std::string> { |
| 2757 | static std::string convert(const std::string& str); |
| 2758 | }; |
| 2759 | |
| 2760 | #ifdef CATCH_CONFIG_CPP17_STRING_VIEW |
| 2761 | template<> |
| 2762 | struct StringMaker<std::string_view> { |
| 2763 | static std::string convert(std::string_view str); |
| 2764 | }; |
| 2765 | #endif |
| 2766 | |
| 2767 | template<> |
| 2768 | struct StringMaker<char const *> { |
| 2769 | static std::string convert(char const * str); |
| 2770 | }; |
| 2771 | template<> |
| 2772 | struct StringMaker<char *> { |
| 2773 | static std::string convert(char * str); |
| 2774 | }; |
| 2775 | |
| 2776 | #if defined(CATCH_CONFIG_WCHAR) |
| 2777 | template<> |
| 2778 | struct StringMaker<std::wstring> { |
| 2779 | static std::string convert(const std::wstring& wstr); |
| 2780 | }; |
| 2781 | |
| 2782 | # ifdef CATCH_CONFIG_CPP17_STRING_VIEW |
| 2783 | template<> |
| 2784 | struct StringMaker<std::wstring_view> { |
| 2785 | static std::string convert(std::wstring_view str); |
| 2786 | }; |
| 2787 | # endif |
| 2788 | |
| 2789 | template<> |
| 2790 | struct StringMaker<wchar_t const *> { |
| 2791 | static std::string convert(wchar_t const * str); |
| 2792 | }; |
| 2793 | template<> |
| 2794 | struct StringMaker<wchar_t *> { |
| 2795 | static std::string convert(wchar_t * str); |
| 2796 | }; |
| 2797 | #endif // CATCH_CONFIG_WCHAR |
| 2798 | |
| 2799 | template<size_t SZ> |
| 2800 | struct StringMaker<char[SZ]> { |
| 2801 | static std::string convert(char const* str) { |
| 2802 | return Detail::convertIntoString( |
| 2803 | StringRef( str, Detail::catch_strnlen( str, SZ ) ) ); |
| 2804 | } |
| 2805 | }; |
| 2806 | template<size_t SZ> |
| 2807 | struct StringMaker<signed char[SZ]> { |
| 2808 | static std::string convert(signed char const* str) { |
| 2809 | auto reinterpreted = reinterpret_cast<char const*>(str); |
| 2810 | return Detail::convertIntoString( |
| 2811 | StringRef(reinterpreted, Detail::catch_strnlen(reinterpreted, SZ))); |
| 2812 | } |
| 2813 | }; |
| 2814 | template<size_t SZ> |
| 2815 | struct StringMaker<unsigned char[SZ]> { |
| 2816 | static std::string convert(unsigned char const* str) { |
| 2817 | auto reinterpreted = reinterpret_cast<char const*>(str); |
| 2818 | return Detail::convertIntoString( |
| 2819 | StringRef(reinterpreted, Detail::catch_strnlen(reinterpreted, SZ))); |
| 2820 | } |
| 2821 | }; |
| 2822 | |
| 2823 | #if defined(CATCH_CONFIG_CPP17_BYTE) |
| 2824 | template<> |
| 2825 | struct StringMaker<std::byte> { |
| 2826 | static std::string convert(std::byte value); |
| 2827 | }; |
| 2828 | #endif // defined(CATCH_CONFIG_CPP17_BYTE) |
| 2829 | template<> |
| 2830 | struct StringMaker<int> { |
| 2831 | static std::string convert(int value); |
| 2832 | }; |
| 2833 | template<> |
| 2834 | struct StringMaker<long> { |
| 2835 | static std::string convert(long value); |
| 2836 | }; |
| 2837 | template<> |
| 2838 | struct StringMaker<long long> { |
| 2839 | static std::string convert(long long value); |
| 2840 | }; |
| 2841 | template<> |
| 2842 | struct StringMaker<unsigned int> { |
| 2843 | static std::string convert(unsigned int value); |
| 2844 | }; |
| 2845 | template<> |
| 2846 | struct StringMaker<unsigned long> { |
| 2847 | static std::string convert(unsigned long value); |
| 2848 | }; |
| 2849 | template<> |
| 2850 | struct StringMaker<unsigned long long> { |
| 2851 | static std::string convert(unsigned long long value); |
| 2852 | }; |
| 2853 | |
| 2854 | template<> |
| 2855 | struct StringMaker<bool> { |
| 2856 | static std::string convert(bool b) { |
| 2857 | using namespace std::string_literals; |
| 2858 | return b ? "true"s : "false"s; |
| 2859 | } |
| 2860 | }; |
| 2861 | |
| 2862 | template<> |
| 2863 | struct StringMaker<char> { |
| 2864 | static std::string convert(char c); |
| 2865 | }; |
| 2866 | template<> |
| 2867 | struct StringMaker<signed char> { |
| 2868 | static std::string convert(signed char c); |
| 2869 | }; |
| 2870 | template<> |
| 2871 | struct StringMaker<unsigned char> { |
| 2872 | static std::string convert(unsigned char c); |
| 2873 | }; |
| 2874 | |
| 2875 | template<> |
| 2876 | struct StringMaker<std::nullptr_t> { |
| 2877 | static std::string convert(std::nullptr_t) { |
| 2878 | using namespace std::string_literals; |
| 2879 | return "nullptr"s; |
| 2880 | } |
| 2881 | }; |
| 2882 | |
| 2883 | template<> |
| 2884 | struct StringMaker<float> { |
| 2885 | static std::string convert(float value); |
| 2886 | CATCH_EXPORT static int precision; |
| 2887 | }; |
| 2888 | |
| 2889 | template<> |
| 2890 | struct StringMaker<double> { |
| 2891 | static std::string convert(double value); |
| 2892 | CATCH_EXPORT static int precision; |
| 2893 | }; |
| 2894 | |
| 2895 | template <typename T> |
| 2896 | struct StringMaker<T*> { |
| 2897 | template <typename U> |
| 2898 | static std::string convert(U* p) { |
| 2899 | if (p) { |
| 2900 | return ::Catch::Detail::rawMemoryToString(p); |
| 2901 | } else { |
| 2902 | return "nullptr"; |
| 2903 | } |
| 2904 | } |
| 2905 | }; |
| 2906 | |
| 2907 | template <typename R, typename C> |
| 2908 | struct StringMaker<R C::*> { |
| 2909 | static std::string convert(R C::* p) { |
| 2910 | if (p) { |
| 2911 | return ::Catch::Detail::rawMemoryToString(p); |
| 2912 | } else { |
| 2913 | return "nullptr"; |
| 2914 | } |
| 2915 | } |
| 2916 | }; |
| 2917 | |
| 2918 | #if defined(_MANAGED) |
| 2919 | template <typename T> |
| 2920 | struct StringMaker<T^> { |
| 2921 | static std::string convert( T^ ref ) { |
| 2922 | return ::Catch::Detail::clrReferenceToString(ref); |
| 2923 | } |
| 2924 | }; |
| 2925 | #endif |
| 2926 | |
| 2927 | namespace Detail { |
| 2928 | template<typename InputIterator, typename Sentinel = InputIterator> |
| 2929 | std::string rangeToString(InputIterator first, Sentinel last) { |
| 2930 | ReusableStringStream rss; |
| 2931 | rss << "{ "; |
| 2932 | if (first != last) { |
| 2933 | rss << ::Catch::Detail::stringify(*first); |
| 2934 | for (++first; first != last; ++first) |
| 2935 | rss << ", " << ::Catch::Detail::stringify(*first); |
| 2936 | } |
| 2937 | rss << " }"; |
| 2938 | return rss.str(); |
| 2939 | } |
| 2940 | } |
| 2941 | |
| 2942 | } // namespace Catch |
| 2943 | |
| 2944 | ////////////////////////////////////////////////////// |
| 2945 | // Separate std-lib types stringification, so it can be selectively enabled |
| 2946 | // This means that we do not bring in their headers |
| 2947 | |
| 2948 | #if defined(CATCH_CONFIG_ENABLE_ALL_STRINGMAKERS) |
| 2949 | # define CATCH_CONFIG_ENABLE_PAIR_STRINGMAKER |
| 2950 | # define CATCH_CONFIG_ENABLE_TUPLE_STRINGMAKER |
| 2951 | # define CATCH_CONFIG_ENABLE_VARIANT_STRINGMAKER |
| 2952 | # define CATCH_CONFIG_ENABLE_OPTIONAL_STRINGMAKER |
| 2953 | #endif |
| 2954 | |
| 2955 | // Separate std::pair specialization |
| 2956 | #if defined(CATCH_CONFIG_ENABLE_PAIR_STRINGMAKER) |
| 2957 | #include <utility> |
| 2958 | namespace Catch { |
| 2959 | template<typename T1, typename T2> |
| 2960 | struct StringMaker<std::pair<T1, T2> > { |
| 2961 | static std::string convert(const std::pair<T1, T2>& pair) { |
| 2962 | ReusableStringStream rss; |
| 2963 | rss << "{ " |
| 2964 | << ::Catch::Detail::stringify(pair.first) |
| 2965 | << ", " |
| 2966 | << ::Catch::Detail::stringify(pair.second) |
| 2967 | << " }"; |
| 2968 | return rss.str(); |
| 2969 | } |
| 2970 | }; |
| 2971 | } |
| 2972 | #endif // CATCH_CONFIG_ENABLE_PAIR_STRINGMAKER |
| 2973 | |
| 2974 | #if defined(CATCH_CONFIG_ENABLE_OPTIONAL_STRINGMAKER) && defined(CATCH_CONFIG_CPP17_OPTIONAL) |
| 2975 | #include <optional> |
| 2976 | namespace Catch { |
| 2977 | template<typename T> |
| 2978 | struct StringMaker<std::optional<T> > { |
| 2979 | static std::string convert(const std::optional<T>& optional) { |
| 2980 | if (optional.has_value()) { |
| 2981 | return ::Catch::Detail::stringify(*optional); |
| 2982 | } else { |
| 2983 | return "{ }"; |
| 2984 | } |
| 2985 | } |
| 2986 | }; |
| 2987 | } |
| 2988 | #endif // CATCH_CONFIG_ENABLE_OPTIONAL_STRINGMAKER |
| 2989 | |
| 2990 | // Separate std::tuple specialization |
| 2991 | #if defined(CATCH_CONFIG_ENABLE_TUPLE_STRINGMAKER) |
| 2992 | #include <tuple> |
| 2993 | namespace Catch { |
| 2994 | namespace Detail { |
| 2995 | template< |
| 2996 | typename Tuple, |
| 2997 | std::size_t N = 0, |
| 2998 | bool = (N < std::tuple_size<Tuple>::value) |
| 2999 | > |
| 3000 | struct TupleElementPrinter { |
| 3001 | static void print(const Tuple& tuple, std::ostream& os) { |
| 3002 | os << (N ? ", " : " ") |
| 3003 | << ::Catch::Detail::stringify(std::get<N>(tuple)); |
| 3004 | TupleElementPrinter<Tuple, N + 1>::print(tuple, os); |
| 3005 | } |
| 3006 | }; |
| 3007 | |
| 3008 | template< |
| 3009 | typename Tuple, |
| 3010 | std::size_t N |
| 3011 | > |
| 3012 | struct TupleElementPrinter<Tuple, N, false> { |
| 3013 | static void print(const Tuple&, std::ostream&) {} |
| 3014 | }; |
| 3015 | |
| 3016 | } |
| 3017 | |
| 3018 | |
| 3019 | template<typename ...Types> |
| 3020 | struct StringMaker<std::tuple<Types...>> { |
| 3021 | static std::string convert(const std::tuple<Types...>& tuple) { |
| 3022 | ReusableStringStream rss; |
| 3023 | rss << '{'; |
| 3024 | Detail::TupleElementPrinter<std::tuple<Types...>>::print(tuple, rss.get()); |
| 3025 | rss << " }"; |
| 3026 | return rss.str(); |
| 3027 | } |
| 3028 | }; |
| 3029 | } |
| 3030 | #endif // CATCH_CONFIG_ENABLE_TUPLE_STRINGMAKER |
| 3031 | |
| 3032 | #if defined(CATCH_CONFIG_ENABLE_VARIANT_STRINGMAKER) && defined(CATCH_CONFIG_CPP17_VARIANT) |
| 3033 | #include <variant> |
| 3034 | namespace Catch { |
| 3035 | template<> |
| 3036 | struct StringMaker<std::monostate> { |
| 3037 | static std::string convert(const std::monostate&) { |
| 3038 | return "{ }"; |
| 3039 | } |
| 3040 | }; |
| 3041 | |
| 3042 | template<typename... Elements> |
| 3043 | struct StringMaker<std::variant<Elements...>> { |
| 3044 | static std::string convert(const std::variant<Elements...>& variant) { |
| 3045 | if (variant.valueless_by_exception()) { |
| 3046 | return "{valueless variant}"; |
| 3047 | } else { |
| 3048 | return std::visit( |
| 3049 | [](const auto& value) { |
| 3050 | return ::Catch::Detail::stringify(value); |
| 3051 | }, |
| 3052 | variant |
| 3053 | ); |
| 3054 | } |
| 3055 | } |
| 3056 | }; |
| 3057 | } |
| 3058 | #endif // CATCH_CONFIG_ENABLE_VARIANT_STRINGMAKER |
| 3059 | |
| 3060 | namespace Catch { |
| 3061 | // Import begin/ end from std here |
| 3062 | using std::begin; |
| 3063 | using std::end; |
| 3064 | |
| 3065 | namespace Detail { |
| 3066 | template <typename T, typename = void> |
| 3067 | struct is_range_impl : std::false_type {}; |
| 3068 | |
| 3069 | template <typename T> |
| 3070 | struct is_range_impl<T, void_t<decltype(begin(std::declval<T>()))>> : std::true_type {}; |
| 3071 | } // namespace Detail |
| 3072 | |
| 3073 | template <typename T> |
| 3074 | struct is_range : Detail::is_range_impl<T> {}; |
| 3075 | |
| 3076 | #if defined(_MANAGED) // Managed types are never ranges |
| 3077 | template <typename T> |
| 3078 | struct is_range<T^> { |
| 3079 | static const bool value = false; |
| 3080 | }; |
| 3081 | #endif |
| 3082 | |
| 3083 | template<typename Range> |
| 3084 | std::string rangeToString( Range const& range ) { |
| 3085 | return ::Catch::Detail::rangeToString( begin( range ), end( range ) ); |
| 3086 | } |
| 3087 | |
| 3088 | // Handle vector<bool> specially |
| 3089 | template<typename Allocator> |
| 3090 | std::string rangeToString( std::vector<bool, Allocator> const& v ) { |
| 3091 | ReusableStringStream rss; |
| 3092 | rss << "{ "; |
| 3093 | bool first = true; |
| 3094 | for( bool b : v ) { |
| 3095 | if( first ) |
| 3096 | first = false; |
| 3097 | else |
| 3098 | rss << ", "; |
| 3099 | rss << ::Catch::Detail::stringify( b ); |
| 3100 | } |
| 3101 | rss << " }"; |
| 3102 | return rss.str(); |
| 3103 | } |
| 3104 | |
| 3105 | template<typename R> |
| 3106 | struct StringMaker<R, std::enable_if_t<is_range<R>::value && !::Catch::Detail::IsStreamInsertable<R>::value>> { |
| 3107 | static std::string convert( R const& range ) { |
| 3108 | return rangeToString( range ); |
| 3109 | } |
| 3110 | }; |
| 3111 | |
| 3112 | template <typename T, size_t SZ> |
| 3113 | struct StringMaker<T[SZ]> { |
| 3114 | static std::string convert(T const(&arr)[SZ]) { |
| 3115 | return rangeToString(arr); |
| 3116 | } |
| 3117 | }; |
| 3118 | |
| 3119 | |
| 3120 | } // namespace Catch |
| 3121 | |
| 3122 | // Separate std::chrono::duration specialization |
| 3123 | #include <ctime> |
| 3124 | #include <ratio> |
| 3125 | #include <chrono> |
| 3126 | |
| 3127 | |
| 3128 | namespace Catch { |
| 3129 | |
| 3130 | template <class Ratio> |
| 3131 | struct ratio_string { |
| 3132 | static std::string symbol() { |
| 3133 | Catch::ReusableStringStream rss; |
| 3134 | rss << '[' << Ratio::num << '/' |
| 3135 | << Ratio::den << ']'; |
| 3136 | return rss.str(); |
| 3137 | } |
| 3138 | }; |
| 3139 | |
| 3140 | template <> |
| 3141 | struct ratio_string<std::atto> { |
| 3142 | static char symbol() { return 'a'; } |
| 3143 | }; |
| 3144 | template <> |
| 3145 | struct ratio_string<std::femto> { |
| 3146 | static char symbol() { return 'f'; } |
| 3147 | }; |
| 3148 | template <> |
| 3149 | struct ratio_string<std::pico> { |
| 3150 | static char symbol() { return 'p'; } |
| 3151 | }; |
| 3152 | template <> |
| 3153 | struct ratio_string<std::nano> { |
| 3154 | static char symbol() { return 'n'; } |
| 3155 | }; |
| 3156 | template <> |
| 3157 | struct ratio_string<std::micro> { |
| 3158 | static char symbol() { return 'u'; } |
| 3159 | }; |
| 3160 | template <> |
| 3161 | struct ratio_string<std::milli> { |
| 3162 | static char symbol() { return 'm'; } |
| 3163 | }; |
| 3164 | |
| 3165 | //////////// |
| 3166 | // std::chrono::duration specializations |
| 3167 | template<typename Value, typename Ratio> |
| 3168 | struct StringMaker<std::chrono::duration<Value, Ratio>> { |
| 3169 | static std::string convert(std::chrono::duration<Value, Ratio> const& duration) { |
| 3170 | ReusableStringStream rss; |
| 3171 | rss << duration.count() << ' ' << ratio_string<Ratio>::symbol() << 's'; |
| 3172 | return rss.str(); |
| 3173 | } |
| 3174 | }; |
| 3175 | template<typename Value> |
| 3176 | struct StringMaker<std::chrono::duration<Value, std::ratio<1>>> { |
| 3177 | static std::string convert(std::chrono::duration<Value, std::ratio<1>> const& duration) { |
| 3178 | ReusableStringStream rss; |
| 3179 | rss << duration.count() << " s"; |
| 3180 | return rss.str(); |
| 3181 | } |
| 3182 | }; |
| 3183 | template<typename Value> |
| 3184 | struct StringMaker<std::chrono::duration<Value, std::ratio<60>>> { |
| 3185 | static std::string convert(std::chrono::duration<Value, std::ratio<60>> const& duration) { |
| 3186 | ReusableStringStream rss; |
| 3187 | rss << duration.count() << " m"; |
| 3188 | return rss.str(); |
| 3189 | } |
| 3190 | }; |
| 3191 | template<typename Value> |
| 3192 | struct StringMaker<std::chrono::duration<Value, std::ratio<3600>>> { |
| 3193 | static std::string convert(std::chrono::duration<Value, std::ratio<3600>> const& duration) { |
| 3194 | ReusableStringStream rss; |
| 3195 | rss << duration.count() << " h"; |
| 3196 | return rss.str(); |
| 3197 | } |
| 3198 | }; |
| 3199 | |
| 3200 | //////////// |
| 3201 | // std::chrono::time_point specialization |
| 3202 | // Generic time_point cannot be specialized, only std::chrono::time_point<system_clock> |
| 3203 | template<typename Clock, typename Duration> |
| 3204 | struct StringMaker<std::chrono::time_point<Clock, Duration>> { |
| 3205 | static std::string convert(std::chrono::time_point<Clock, Duration> const& time_point) { |
| 3206 | return ::Catch::Detail::stringify(time_point.time_since_epoch()) + " since epoch"; |
| 3207 | } |
| 3208 | }; |
| 3209 | // std::chrono::time_point<system_clock> specialization |
| 3210 | template<typename Duration> |
| 3211 | struct StringMaker<std::chrono::time_point<std::chrono::system_clock, Duration>> { |
| 3212 | static std::string convert(std::chrono::time_point<std::chrono::system_clock, Duration> const& time_point) { |
| 3213 | auto converted = std::chrono::system_clock::to_time_t(time_point); |
| 3214 | |
| 3215 | #ifdef _MSC_VER |
| 3216 | std::tm timeInfo = {}; |
| 3217 | gmtime_s(&timeInfo, &converted); |
| 3218 | #else |
| 3219 | std::tm* timeInfo = std::gmtime(&converted); |
| 3220 | #endif |
| 3221 | |
| 3222 | auto const timeStampSize = sizeof("2017-01-16T17:06:45Z"); |
| 3223 | char timeStamp[timeStampSize]; |
| 3224 | const char * const fmt = "%Y-%m-%dT%H:%M:%SZ"; |
| 3225 | |
| 3226 | #ifdef _MSC_VER |
| 3227 | std::strftime(timeStamp, timeStampSize, fmt, &timeInfo); |
| 3228 | #else |
| 3229 | std::strftime(timeStamp, timeStampSize, fmt, timeInfo); |
| 3230 | #endif |
| 3231 | return std::string(timeStamp, timeStampSize - 1); |
| 3232 | } |
| 3233 | }; |
| 3234 | } |
| 3235 | |
| 3236 | |
| 3237 | #define INTERNAL_CATCH_REGISTER_ENUM( enumName, ... ) \ |
| 3238 | namespace Catch { \ |
| 3239 | template<> struct StringMaker<enumName> { \ |
| 3240 | static std::string convert( enumName value ) { \ |
| 3241 | static const auto& enumInfo = ::Catch::getMutableRegistryHub().getMutableEnumValuesRegistry().registerEnum( #enumName, #__VA_ARGS__, { __VA_ARGS__ } ); \ |
| 3242 | return static_cast<std::string>(enumInfo.lookup( static_cast<int>( value ) )); \ |
| 3243 | } \ |
| 3244 | }; \ |
| 3245 | } |
| 3246 | |
| 3247 | #define CATCH_REGISTER_ENUM( enumName, ... ) INTERNAL_CATCH_REGISTER_ENUM( enumName, __VA_ARGS__ ) |
| 3248 | |
| 3249 | #ifdef _MSC_VER |
| 3250 | #pragma warning(pop) |
| 3251 | #endif |
| 3252 | |
| 3253 | #endif // CATCH_TOSTRING_HPP_INCLUDED |
| 3254 | |
| 3255 | #include <type_traits> |
| 3256 | |
| 3257 | namespace Catch { |
| 3258 | |
| 3259 | class Approx { |
| 3260 | private: |
| 3261 | bool equalityComparisonImpl(double other) const; |
| 3262 | // Sets and validates the new margin (margin >= 0) |
| 3263 | void setMargin(double margin); |
| 3264 | // Sets and validates the new epsilon (0 < epsilon < 1) |
| 3265 | void setEpsilon(double epsilon); |
| 3266 | |
| 3267 | public: |
| 3268 | explicit Approx ( double value ); |
| 3269 | |
| 3270 | static Approx custom(); |
| 3271 | |
| 3272 | Approx operator-() const; |
| 3273 | |
| 3274 | template <typename T, typename = std::enable_if_t<std::is_constructible<double, T>::value>> |
| 3275 | Approx operator()( T const& value ) const { |
| 3276 | Approx approx( static_cast<double>(value) ); |
| 3277 | approx.m_epsilon = m_epsilon; |
| 3278 | approx.m_margin = m_margin; |
| 3279 | approx.m_scale = m_scale; |
| 3280 | return approx; |
| 3281 | } |
| 3282 | |
| 3283 | template <typename T, typename = std::enable_if_t<std::is_constructible<double, T>::value>> |
| 3284 | explicit Approx( T const& value ): Approx(static_cast<double>(value)) |
| 3285 | {} |
| 3286 | |
| 3287 | |
| 3288 | template <typename T, typename = std::enable_if_t<std::is_constructible<double, T>::value>> |
| 3289 | friend bool operator == ( const T& lhs, Approx const& rhs ) { |
| 3290 | auto lhs_v = static_cast<double>(lhs); |
| 3291 | return rhs.equalityComparisonImpl(lhs_v); |
| 3292 | } |
| 3293 | |
| 3294 | template <typename T, typename = std::enable_if_t<std::is_constructible<double, T>::value>> |
| 3295 | friend bool operator == ( Approx const& lhs, const T& rhs ) { |
| 3296 | return operator==( rhs, lhs ); |
| 3297 | } |
| 3298 | |
| 3299 | template <typename T, typename = std::enable_if_t<std::is_constructible<double, T>::value>> |
| 3300 | friend bool operator != ( T const& lhs, Approx const& rhs ) { |
| 3301 | return !operator==( lhs, rhs ); |
| 3302 | } |
| 3303 | |
| 3304 | template <typename T, typename = std::enable_if_t<std::is_constructible<double, T>::value>> |
| 3305 | friend bool operator != ( Approx const& lhs, T const& rhs ) { |
| 3306 | return !operator==( rhs, lhs ); |
| 3307 | } |
| 3308 | |
| 3309 | template <typename T, typename = std::enable_if_t<std::is_constructible<double, T>::value>> |
| 3310 | friend bool operator <= ( T const& lhs, Approx const& rhs ) { |
| 3311 | return static_cast<double>(lhs) < rhs.m_value || lhs == rhs; |
| 3312 | } |
| 3313 | |
| 3314 | template <typename T, typename = std::enable_if_t<std::is_constructible<double, T>::value>> |
| 3315 | friend bool operator <= ( Approx const& lhs, T const& rhs ) { |
| 3316 | return lhs.m_value < static_cast<double>(rhs) || lhs == rhs; |
| 3317 | } |
| 3318 | |
| 3319 | template <typename T, typename = std::enable_if_t<std::is_constructible<double, T>::value>> |
| 3320 | friend bool operator >= ( T const& lhs, Approx const& rhs ) { |
| 3321 | return static_cast<double>(lhs) > rhs.m_value || lhs == rhs; |
| 3322 | } |
| 3323 | |
| 3324 | template <typename T, typename = std::enable_if_t<std::is_constructible<double, T>::value>> |
| 3325 | friend bool operator >= ( Approx const& lhs, T const& rhs ) { |
| 3326 | return lhs.m_value > static_cast<double>(rhs) || lhs == rhs; |
| 3327 | } |
| 3328 | |
| 3329 | template <typename T, typename = std::enable_if_t<std::is_constructible<double, T>::value>> |
| 3330 | Approx& epsilon( T const& newEpsilon ) { |
| 3331 | const auto epsilonAsDouble = static_cast<double>(newEpsilon); |
| 3332 | setEpsilon(epsilonAsDouble); |
| 3333 | return *this; |
| 3334 | } |
| 3335 | |
| 3336 | template <typename T, typename = std::enable_if_t<std::is_constructible<double, T>::value>> |
| 3337 | Approx& margin( T const& newMargin ) { |
| 3338 | const auto marginAsDouble = static_cast<double>(newMargin); |
| 3339 | setMargin(marginAsDouble); |
| 3340 | return *this; |
| 3341 | } |
| 3342 | |
| 3343 | template <typename T, typename = std::enable_if_t<std::is_constructible<double, T>::value>> |
| 3344 | Approx& scale( T const& newScale ) { |
| 3345 | m_scale = static_cast<double>(newScale); |
| 3346 | return *this; |
| 3347 | } |
| 3348 | |
| 3349 | std::string toString() const; |
| 3350 | |
| 3351 | private: |
| 3352 | double m_epsilon; |
| 3353 | double m_margin; |
| 3354 | double m_scale; |
| 3355 | double m_value; |
| 3356 | }; |
| 3357 | |
| 3358 | namespace literals { |
| 3359 | Approx operator ""_a(long double val); |
| 3360 | Approx operator ""_a(unsigned long long val); |
| 3361 | } // end namespace literals |
| 3362 | |
| 3363 | template<> |
| 3364 | struct StringMaker<Catch::Approx> { |
| 3365 | static std::string convert(Catch::Approx const& value); |
| 3366 | }; |
| 3367 | |
| 3368 | } // end namespace Catch |
| 3369 | |
| 3370 | #endif // CATCH_APPROX_HPP_INCLUDED |
| 3371 | |
| 3372 | |
| 3373 | #ifndef CATCH_ASSERTION_INFO_HPP_INCLUDED |
| 3374 | #define CATCH_ASSERTION_INFO_HPP_INCLUDED |
| 3375 | |
| 3376 | |
| 3377 | |
| 3378 | #ifndef CATCH_SOURCE_LINE_INFO_HPP_INCLUDED |
| 3379 | #define CATCH_SOURCE_LINE_INFO_HPP_INCLUDED |
| 3380 | |
| 3381 | #include <cstddef> |
| 3382 | #include <iosfwd> |
| 3383 | |
| 3384 | namespace Catch { |
| 3385 | |
| 3386 | struct SourceLineInfo { |
| 3387 | |
| 3388 | SourceLineInfo() = delete; |
| 3389 | constexpr SourceLineInfo( char const* _file, std::size_t _line ) noexcept: |
| 3390 | file( _file ), |
| 3391 | line( _line ) |
| 3392 | {} |
| 3393 | |
| 3394 | bool operator == ( SourceLineInfo const& other ) const noexcept; |
| 3395 | bool operator < ( SourceLineInfo const& other ) const noexcept; |
| 3396 | |
| 3397 | char const* file; |
| 3398 | std::size_t line; |
| 3399 | |
| 3400 | friend std::ostream& operator << (std::ostream& os, SourceLineInfo const& info); |
| 3401 | }; |
| 3402 | } |
| 3403 | |
| 3404 | #define CATCH_INTERNAL_LINEINFO \ |
| 3405 | ::Catch::SourceLineInfo( __FILE__, static_cast<std::size_t>( __LINE__ ) ) |
| 3406 | |
| 3407 | #endif // CATCH_SOURCE_LINE_INFO_HPP_INCLUDED |
| 3408 | |
| 3409 | namespace Catch { |
| 3410 | |
| 3411 | struct AssertionInfo { |
| 3412 | // AssertionInfo() = delete; |
| 3413 | |
| 3414 | StringRef macroName; |
| 3415 | SourceLineInfo lineInfo; |
| 3416 | StringRef capturedExpression; |
| 3417 | ResultDisposition::Flags resultDisposition; |
| 3418 | }; |
| 3419 | |
| 3420 | } // end namespace Catch |
| 3421 | |
| 3422 | #endif // CATCH_ASSERTION_INFO_HPP_INCLUDED |
| 3423 | |
| 3424 | |
| 3425 | #ifndef CATCH_ASSERTION_RESULT_HPP_INCLUDED |
| 3426 | #define CATCH_ASSERTION_RESULT_HPP_INCLUDED |
| 3427 | |
| 3428 | |
| 3429 | |
| 3430 | #ifndef CATCH_LAZY_EXPR_HPP_INCLUDED |
| 3431 | #define CATCH_LAZY_EXPR_HPP_INCLUDED |
| 3432 | |
| 3433 | #include <iosfwd> |
| 3434 | |
| 3435 | namespace Catch { |
| 3436 | |
| 3437 | class ITransientExpression; |
| 3438 | |
| 3439 | class LazyExpression { |
| 3440 | friend class AssertionHandler; |
| 3441 | friend struct AssertionStats; |
| 3442 | friend class RunContext; |
| 3443 | |
| 3444 | ITransientExpression const* m_transientExpression = nullptr; |
| 3445 | bool m_isNegated; |
| 3446 | public: |
| 3447 | LazyExpression( bool isNegated ): |
| 3448 | m_isNegated(isNegated) |
| 3449 | {} |
| 3450 | LazyExpression(LazyExpression const& other) = default; |
| 3451 | LazyExpression& operator = ( LazyExpression const& ) = delete; |
| 3452 | |
| 3453 | explicit operator bool() const { |
| 3454 | return m_transientExpression != nullptr; |
| 3455 | } |
| 3456 | |
| 3457 | friend auto operator << ( std::ostream& os, LazyExpression const& lazyExpr ) -> std::ostream&; |
| 3458 | }; |
| 3459 | |
| 3460 | } // namespace Catch |
| 3461 | |
| 3462 | #endif // CATCH_LAZY_EXPR_HPP_INCLUDED |
| 3463 | |
| 3464 | #include <string> |
| 3465 | |
| 3466 | namespace Catch { |
| 3467 | |
| 3468 | struct AssertionResultData |
| 3469 | { |
| 3470 | AssertionResultData() = delete; |
| 3471 | |
| 3472 | AssertionResultData( ResultWas::OfType _resultType, LazyExpression const& _lazyExpression ); |
| 3473 | |
| 3474 | std::string message; |
| 3475 | mutable std::string reconstructedExpression; |
| 3476 | LazyExpression lazyExpression; |
| 3477 | ResultWas::OfType resultType; |
| 3478 | |
| 3479 | std::string reconstructExpression() const; |
| 3480 | }; |
| 3481 | |
| 3482 | class AssertionResult { |
| 3483 | public: |
| 3484 | AssertionResult() = delete; |
| 3485 | AssertionResult( AssertionInfo const& info, AssertionResultData&& data ); |
| 3486 | |
| 3487 | bool isOk() const; |
| 3488 | bool succeeded() const; |
| 3489 | ResultWas::OfType getResultType() const; |
| 3490 | bool hasExpression() const; |
| 3491 | bool hasMessage() const; |
| 3492 | std::string getExpression() const; |
| 3493 | std::string getExpressionInMacro() const; |
| 3494 | bool hasExpandedExpression() const; |
| 3495 | std::string getExpandedExpression() const; |
| 3496 | StringRef getMessage() const; |
| 3497 | SourceLineInfo getSourceInfo() const; |
| 3498 | StringRef getTestMacroName() const; |
| 3499 | |
| 3500 | //protected: |
| 3501 | AssertionInfo m_info; |
| 3502 | AssertionResultData m_resultData; |
| 3503 | }; |
| 3504 | |
| 3505 | } // end namespace Catch |
| 3506 | |
| 3507 | #endif // CATCH_ASSERTION_RESULT_HPP_INCLUDED |
| 3508 | |
| 3509 | |
| 3510 | #ifndef CATCH_CONFIG_HPP_INCLUDED |
| 3511 | #define CATCH_CONFIG_HPP_INCLUDED |
| 3512 | |
| 3513 | |
| 3514 | |
| 3515 | #ifndef CATCH_TEST_SPEC_HPP_INCLUDED |
| 3516 | #define CATCH_TEST_SPEC_HPP_INCLUDED |
| 3517 | |
| 3518 | #ifdef __clang__ |
| 3519 | #pragma clang diagnostic push |
| 3520 | #pragma clang diagnostic ignored "-Wpadded" |
| 3521 | #endif |
| 3522 | |
| 3523 | |
| 3524 | |
| 3525 | #ifndef CATCH_WILDCARD_PATTERN_HPP_INCLUDED |
| 3526 | #define CATCH_WILDCARD_PATTERN_HPP_INCLUDED |
| 3527 | |
| 3528 | |
| 3529 | |
| 3530 | #ifndef CATCH_CASE_SENSITIVE_HPP_INCLUDED |
| 3531 | #define CATCH_CASE_SENSITIVE_HPP_INCLUDED |
| 3532 | |
| 3533 | namespace Catch { |
| 3534 | |
| 3535 | enum class CaseSensitive { Yes, No }; |
| 3536 | |
| 3537 | } // namespace Catch |
| 3538 | |
| 3539 | #endif // CATCH_CASE_SENSITIVE_HPP_INCLUDED |
| 3540 | |
| 3541 | #include <string> |
| 3542 | |
| 3543 | namespace Catch |
| 3544 | { |
| 3545 | class WildcardPattern { |
| 3546 | enum WildcardPosition { |
| 3547 | NoWildcard = 0, |
| 3548 | WildcardAtStart = 1, |
| 3549 | WildcardAtEnd = 2, |
| 3550 | WildcardAtBothEnds = WildcardAtStart | WildcardAtEnd |
| 3551 | }; |
| 3552 | |
| 3553 | public: |
| 3554 | |
| 3555 | WildcardPattern( std::string const& pattern, CaseSensitive caseSensitivity ); |
| 3556 | bool matches( std::string const& str ) const; |
| 3557 | |
| 3558 | private: |
| 3559 | std::string normaliseString( std::string const& str ) const; |
| 3560 | CaseSensitive m_caseSensitivity; |
| 3561 | WildcardPosition m_wildcard = NoWildcard; |
| 3562 | std::string m_pattern; |
| 3563 | }; |
| 3564 | } |
| 3565 | |
| 3566 | #endif // CATCH_WILDCARD_PATTERN_HPP_INCLUDED |
| 3567 | |
| 3568 | #include <iosfwd> |
| 3569 | #include <string> |
| 3570 | #include <vector> |
| 3571 | |
| 3572 | namespace Catch { |
| 3573 | |
| 3574 | class IConfig; |
| 3575 | struct TestCaseInfo; |
| 3576 | class TestCaseHandle; |
| 3577 | |
| 3578 | class TestSpec { |
| 3579 | |
| 3580 | class Pattern { |
| 3581 | public: |
| 3582 | explicit Pattern( std::string const& name ); |
| 3583 | virtual ~Pattern(); |
| 3584 | virtual bool matches( TestCaseInfo const& testCase ) const = 0; |
| 3585 | std::string const& name() const; |
| 3586 | private: |
| 3587 | virtual void serializeTo( std::ostream& out ) const = 0; |
| 3588 | // Writes string that would be reparsed into the pattern |
| 3589 | friend std::ostream& operator<<(std::ostream& out, |
| 3590 | Pattern const& pattern) { |
| 3591 | pattern.serializeTo( out ); |
| 3592 | return out; |
| 3593 | } |
| 3594 | |
| 3595 | std::string const m_name; |
| 3596 | }; |
| 3597 | |
| 3598 | class NamePattern : public Pattern { |
| 3599 | public: |
| 3600 | explicit NamePattern( std::string const& name, std::string const& filterString ); |
| 3601 | bool matches( TestCaseInfo const& testCase ) const override; |
| 3602 | private: |
| 3603 | void serializeTo( std::ostream& out ) const override; |
| 3604 | |
| 3605 | WildcardPattern m_wildcardPattern; |
| 3606 | }; |
| 3607 | |
| 3608 | class TagPattern : public Pattern { |
| 3609 | public: |
| 3610 | explicit TagPattern( std::string const& tag, std::string const& filterString ); |
| 3611 | bool matches( TestCaseInfo const& testCase ) const override; |
| 3612 | private: |
| 3613 | void serializeTo( std::ostream& out ) const override; |
| 3614 | |
| 3615 | std::string m_tag; |
| 3616 | }; |
| 3617 | |
| 3618 | struct Filter { |
| 3619 | std::vector<Detail::unique_ptr<Pattern>> m_required; |
| 3620 | std::vector<Detail::unique_ptr<Pattern>> m_forbidden; |
| 3621 | |
| 3622 | //! Serializes this filter into a string that would be parsed into |
| 3623 | //! an equivalent filter |
| 3624 | void serializeTo( std::ostream& out ) const; |
| 3625 | friend std::ostream& operator<<(std::ostream& out, Filter const& f) { |
| 3626 | f.serializeTo( out ); |
| 3627 | return out; |
| 3628 | } |
| 3629 | |
| 3630 | bool matches( TestCaseInfo const& testCase ) const; |
| 3631 | }; |
| 3632 | |
| 3633 | static std::string extractFilterName( Filter const& filter ); |
| 3634 | |
| 3635 | public: |
| 3636 | struct FilterMatch { |
| 3637 | std::string name; |
| 3638 | std::vector<TestCaseHandle const*> tests; |
| 3639 | }; |
| 3640 | using Matches = std::vector<FilterMatch>; |
| 3641 | using vectorStrings = std::vector<std::string>; |
| 3642 | |
| 3643 | bool hasFilters() const; |
| 3644 | bool matches( TestCaseInfo const& testCase ) const; |
| 3645 | Matches matchesByFilter( std::vector<TestCaseHandle> const& testCases, IConfig const& config ) const; |
| 3646 | const vectorStrings & getInvalidSpecs() const; |
| 3647 | |
| 3648 | private: |
| 3649 | std::vector<Filter> m_filters; |
| 3650 | std::vector<std::string> m_invalidSpecs; |
| 3651 | |
| 3652 | friend class TestSpecParser; |
| 3653 | //! Serializes this test spec into a string that would be parsed into |
| 3654 | //! equivalent test spec |
| 3655 | void serializeTo( std::ostream& out ) const; |
| 3656 | friend std::ostream& operator<<(std::ostream& out, |
| 3657 | TestSpec const& spec) { |
| 3658 | spec.serializeTo( out ); |
| 3659 | return out; |
| 3660 | } |
| 3661 | }; |
| 3662 | } |
| 3663 | |
| 3664 | #ifdef __clang__ |
| 3665 | #pragma clang diagnostic pop |
| 3666 | #endif |
| 3667 | |
| 3668 | #endif // CATCH_TEST_SPEC_HPP_INCLUDED |
| 3669 | |
| 3670 | |
| 3671 | #ifndef CATCH_OPTIONAL_HPP_INCLUDED |
| 3672 | #define CATCH_OPTIONAL_HPP_INCLUDED |
| 3673 | |
| 3674 | |
| 3675 | #include <cassert> |
| 3676 | |
| 3677 | namespace Catch { |
| 3678 | |
| 3679 | // An optional type |
| 3680 | template<typename T> |
| 3681 | class Optional { |
| 3682 | public: |
| 3683 | Optional(): nullableValue( nullptr ) {} |
| 3684 | ~Optional() { reset(); } |
| 3685 | |
| 3686 | Optional( T const& _value ): |
| 3687 | nullableValue( new ( storage ) T( _value ) ) {} |
| 3688 | Optional( T&& _value ): |
| 3689 | nullableValue( new ( storage ) T( CATCH_MOVE( _value ) ) ) {} |
| 3690 | |
| 3691 | Optional& operator=( T const& _value ) { |
| 3692 | reset(); |
| 3693 | nullableValue = new ( storage ) T( _value ); |
| 3694 | return *this; |
| 3695 | } |
| 3696 | Optional& operator=( T&& _value ) { |
| 3697 | reset(); |
| 3698 | nullableValue = new ( storage ) T( CATCH_MOVE( _value ) ); |
| 3699 | return *this; |
| 3700 | } |
| 3701 | |
| 3702 | Optional( Optional const& _other ): |
| 3703 | nullableValue( _other ? new ( storage ) T( *_other ) : nullptr ) {} |
| 3704 | Optional( Optional&& _other ): |
| 3705 | nullableValue( _other ? new ( storage ) T( CATCH_MOVE( *_other ) ) |
| 3706 | : nullptr ) {} |
| 3707 | |
| 3708 | Optional& operator=( Optional const& _other ) { |
| 3709 | if ( &_other != this ) { |
| 3710 | reset(); |
| 3711 | if ( _other ) { nullableValue = new ( storage ) T( *_other ); } |
| 3712 | } |
| 3713 | return *this; |
| 3714 | } |
| 3715 | Optional& operator=( Optional&& _other ) { |
| 3716 | if ( &_other != this ) { |
| 3717 | reset(); |
| 3718 | if ( _other ) { |
| 3719 | nullableValue = new ( storage ) T( CATCH_MOVE( *_other ) ); |
| 3720 | } |
| 3721 | } |
| 3722 | return *this; |
| 3723 | } |
| 3724 | |
| 3725 | void reset() { |
| 3726 | if ( nullableValue ) { nullableValue->~T(); } |
| 3727 | nullableValue = nullptr; |
| 3728 | } |
| 3729 | |
| 3730 | T& operator*() { |
| 3731 | assert(nullableValue); |
| 3732 | return *nullableValue; |
| 3733 | } |
| 3734 | T const& operator*() const { |
| 3735 | assert(nullableValue); |
| 3736 | return *nullableValue; |
| 3737 | } |
| 3738 | T* operator->() { |
| 3739 | assert(nullableValue); |
| 3740 | return nullableValue; |
| 3741 | } |
| 3742 | const T* operator->() const { |
| 3743 | assert(nullableValue); |
| 3744 | return nullableValue; |
| 3745 | } |
| 3746 | |
| 3747 | T valueOr( T const& defaultValue ) const { |
| 3748 | return nullableValue ? *nullableValue : defaultValue; |
| 3749 | } |
| 3750 | |
| 3751 | bool some() const { return nullableValue != nullptr; } |
| 3752 | bool none() const { return nullableValue == nullptr; } |
| 3753 | |
| 3754 | bool operator !() const { return nullableValue == nullptr; } |
| 3755 | explicit operator bool() const { |
| 3756 | return some(); |
| 3757 | } |
| 3758 | |
| 3759 | friend bool operator==(Optional const& a, Optional const& b) { |
| 3760 | if (a.none() && b.none()) { |
| 3761 | return true; |
| 3762 | } else if (a.some() && b.some()) { |
| 3763 | return *a == *b; |
| 3764 | } else { |
| 3765 | return false; |
| 3766 | } |
| 3767 | } |
| 3768 | friend bool operator!=(Optional const& a, Optional const& b) { |
| 3769 | return !( a == b ); |
| 3770 | } |
| 3771 | |
| 3772 | private: |
| 3773 | T* nullableValue; |
| 3774 | alignas(alignof(T)) char storage[sizeof(T)]; |
| 3775 | }; |
| 3776 | |
| 3777 | } // end namespace Catch |
| 3778 | |
| 3779 | #endif // CATCH_OPTIONAL_HPP_INCLUDED |
| 3780 | |
| 3781 | |
| 3782 | #ifndef CATCH_RANDOM_SEED_GENERATION_HPP_INCLUDED |
| 3783 | #define CATCH_RANDOM_SEED_GENERATION_HPP_INCLUDED |
| 3784 | |
| 3785 | #include <cstdint> |
| 3786 | |
| 3787 | namespace Catch { |
| 3788 | |
| 3789 | enum class GenerateFrom { |
| 3790 | Time, |
| 3791 | RandomDevice, |
| 3792 | //! Currently equivalent to RandomDevice, but can change at any point |
| 3793 | Default |
| 3794 | }; |
| 3795 | |
| 3796 | std::uint32_t generateRandomSeed(GenerateFrom from); |
| 3797 | |
| 3798 | } // end namespace Catch |
| 3799 | |
| 3800 | #endif // CATCH_RANDOM_SEED_GENERATION_HPP_INCLUDED |
| 3801 | |
| 3802 | |
| 3803 | #ifndef CATCH_REPORTER_SPEC_PARSER_HPP_INCLUDED |
| 3804 | #define CATCH_REPORTER_SPEC_PARSER_HPP_INCLUDED |
| 3805 | |
| 3806 | |
| 3807 | |
| 3808 | #ifndef CATCH_CONSOLE_COLOUR_HPP_INCLUDED |
| 3809 | #define CATCH_CONSOLE_COLOUR_HPP_INCLUDED |
| 3810 | |
| 3811 | |
| 3812 | #include <iosfwd> |
| 3813 | #include <cstdint> |
| 3814 | |
| 3815 | namespace Catch { |
| 3816 | |
| 3817 | enum class ColourMode : std::uint8_t; |
| 3818 | class IStream; |
| 3819 | |
| 3820 | struct Colour { |
| 3821 | enum Code { |
| 3822 | None = 0, |
| 3823 | |
| 3824 | White, |
| 3825 | Red, |
| 3826 | Green, |
| 3827 | Blue, |
| 3828 | Cyan, |
| 3829 | Yellow, |
| 3830 | Grey, |
| 3831 | |
| 3832 | Bright = 0x10, |
| 3833 | |
| 3834 | BrightRed = Bright | Red, |
| 3835 | BrightGreen = Bright | Green, |
| 3836 | LightGrey = Bright | Grey, |
| 3837 | BrightWhite = Bright | White, |
| 3838 | BrightYellow = Bright | Yellow, |
| 3839 | |
| 3840 | // By intention |
| 3841 | FileName = LightGrey, |
| 3842 | Warning = BrightYellow, |
| 3843 | ResultError = BrightRed, |
| 3844 | ResultSuccess = BrightGreen, |
| 3845 | ResultExpectedFailure = Warning, |
| 3846 | |
| 3847 | Error = BrightRed, |
| 3848 | Success = Green, |
| 3849 | Skip = LightGrey, |
| 3850 | |
| 3851 | OriginalExpression = Cyan, |
| 3852 | ReconstructedExpression = BrightYellow, |
| 3853 | |
| 3854 | SecondaryText = LightGrey, |
| 3855 | Headers = White |
| 3856 | }; |
| 3857 | }; |
| 3858 | |
| 3859 | class ColourImpl { |
| 3860 | protected: |
| 3861 | //! The associated stream of this ColourImpl instance |
| 3862 | IStream* m_stream; |
| 3863 | public: |
| 3864 | ColourImpl( IStream* stream ): m_stream( stream ) {} |
| 3865 | |
| 3866 | //! RAII wrapper around writing specific colour of text using specific |
| 3867 | //! colour impl into a stream. |
| 3868 | class ColourGuard { |
| 3869 | ColourImpl const* m_colourImpl; |
| 3870 | Colour::Code m_code; |
| 3871 | bool m_engaged = false; |
| 3872 | |
| 3873 | public: |
| 3874 | //! Does **not** engage the guard/start the colour |
| 3875 | ColourGuard( Colour::Code code, |
| 3876 | ColourImpl const* colour ); |
| 3877 | |
| 3878 | ColourGuard( ColourGuard const& rhs ) = delete; |
| 3879 | ColourGuard& operator=( ColourGuard const& rhs ) = delete; |
| 3880 | |
| 3881 | ColourGuard( ColourGuard&& rhs ) noexcept; |
| 3882 | ColourGuard& operator=( ColourGuard&& rhs ) noexcept; |
| 3883 | |
| 3884 | //! Removes colour _if_ the guard was engaged |
| 3885 | ~ColourGuard(); |
| 3886 | |
| 3887 | /** |
| 3888 | * Explicitly engages colour for given stream. |
| 3889 | * |
| 3890 | * The API based on operator<< should be preferred. |
| 3891 | */ |
| 3892 | ColourGuard& engage( std::ostream& stream ) &; |
| 3893 | /** |
| 3894 | * Explicitly engages colour for given stream. |
| 3895 | * |
| 3896 | * The API based on operator<< should be preferred. |
| 3897 | */ |
| 3898 | ColourGuard&& engage( std::ostream& stream ) &&; |
| 3899 | |
| 3900 | private: |
| 3901 | //! Engages the guard and starts using colour |
| 3902 | friend std::ostream& operator<<( std::ostream& lhs, |
| 3903 | ColourGuard& guard ) { |
| 3904 | guard.engageImpl( lhs ); |
| 3905 | return lhs; |
| 3906 | } |
| 3907 | //! Engages the guard and starts using colour |
| 3908 | friend std::ostream& operator<<( std::ostream& lhs, |
| 3909 | ColourGuard&& guard) { |
| 3910 | guard.engageImpl( lhs ); |
| 3911 | return lhs; |
| 3912 | } |
| 3913 | |
| 3914 | void engageImpl( std::ostream& stream ); |
| 3915 | |
| 3916 | }; |
| 3917 | |
| 3918 | virtual ~ColourImpl(); // = default |
| 3919 | /** |
| 3920 | * Creates a guard object for given colour and this colour impl |
| 3921 | * |
| 3922 | * **Important:** |
| 3923 | * the guard starts disengaged, and has to be engaged explicitly. |
| 3924 | */ |
| 3925 | ColourGuard guardColour( Colour::Code colourCode ); |
| 3926 | |
| 3927 | private: |
| 3928 | virtual void use( Colour::Code colourCode ) const = 0; |
| 3929 | }; |
| 3930 | |
| 3931 | //! Provides ColourImpl based on global config and target compilation platform |
| 3932 | Detail::unique_ptr<ColourImpl> makeColourImpl( ColourMode colourSelection, |
| 3933 | IStream* stream ); |
| 3934 | |
| 3935 | //! Checks if specific colour impl has been compiled into the binary |
| 3936 | bool isColourImplAvailable( ColourMode colourSelection ); |
| 3937 | |
| 3938 | } // end namespace Catch |
| 3939 | |
| 3940 | #endif // CATCH_CONSOLE_COLOUR_HPP_INCLUDED |
| 3941 | |
| 3942 | #include <map> |
| 3943 | #include <string> |
| 3944 | #include <vector> |
| 3945 | |
| 3946 | namespace Catch { |
| 3947 | |
| 3948 | enum class ColourMode : std::uint8_t; |
| 3949 | |
| 3950 | namespace Detail { |
| 3951 | //! Splits the reporter spec into reporter name and kv-pair options |
| 3952 | std::vector<std::string> splitReporterSpec( StringRef reporterSpec ); |
| 3953 | |
| 3954 | Optional<ColourMode> stringToColourMode( StringRef colourMode ); |
| 3955 | } |
| 3956 | |
| 3957 | /** |
| 3958 | * Structured reporter spec that a reporter can be created from |
| 3959 | * |
| 3960 | * Parsing has been validated, but semantics have not. This means e.g. |
| 3961 | * that the colour mode is known to Catch2, but it might not be |
| 3962 | * compiled into the binary, and the output filename might not be |
| 3963 | * openable. |
| 3964 | */ |
| 3965 | class ReporterSpec { |
| 3966 | std::string m_name; |
| 3967 | Optional<std::string> m_outputFileName; |
| 3968 | Optional<ColourMode> m_colourMode; |
| 3969 | std::map<std::string, std::string> m_customOptions; |
| 3970 | |
| 3971 | friend bool operator==( ReporterSpec const& lhs, |
| 3972 | ReporterSpec const& rhs ); |
| 3973 | friend bool operator!=( ReporterSpec const& lhs, |
| 3974 | ReporterSpec const& rhs ) { |
| 3975 | return !( lhs == rhs ); |
| 3976 | } |
| 3977 | |
| 3978 | public: |
| 3979 | ReporterSpec( |
| 3980 | std::string name, |
| 3981 | Optional<std::string> outputFileName, |
| 3982 | Optional<ColourMode> colourMode, |
| 3983 | std::map<std::string, std::string> customOptions ); |
| 3984 | |
| 3985 | std::string const& name() const { return m_name; } |
| 3986 | |
| 3987 | Optional<std::string> const& outputFile() const { |
| 3988 | return m_outputFileName; |
| 3989 | } |
| 3990 | |
| 3991 | Optional<ColourMode> const& colourMode() const { return m_colourMode; } |
| 3992 | |
| 3993 | std::map<std::string, std::string> const& customOptions() const { |
| 3994 | return m_customOptions; |
| 3995 | } |
| 3996 | }; |
| 3997 | |
| 3998 | /** |
| 3999 | * Parses provided reporter spec string into |
| 4000 | * |
| 4001 | * Returns empty optional on errors, e.g. |
| 4002 | * * field that is not first and not a key+value pair |
| 4003 | * * duplicated keys in kv pair |
| 4004 | * * unknown catch reporter option |
| 4005 | * * empty key/value in an custom kv pair |
| 4006 | * * ... |
| 4007 | */ |
| 4008 | Optional<ReporterSpec> parseReporterSpec( StringRef reporterSpec ); |
| 4009 | |
| 4010 | } |
| 4011 | |
| 4012 | #endif // CATCH_REPORTER_SPEC_PARSER_HPP_INCLUDED |
| 4013 | |
| 4014 | #include <chrono> |
| 4015 | #include <map> |
| 4016 | #include <string> |
| 4017 | #include <vector> |
| 4018 | |
| 4019 | namespace Catch { |
| 4020 | |
| 4021 | class IStream; |
| 4022 | |
| 4023 | /** |
| 4024 | * `ReporterSpec` but with the defaults filled in. |
| 4025 | * |
| 4026 | * Like `ReporterSpec`, the semantics are unchecked. |
| 4027 | */ |
| 4028 | struct ProcessedReporterSpec { |
| 4029 | std::string name; |
| 4030 | std::string outputFilename; |
| 4031 | ColourMode colourMode; |
| 4032 | std::map<std::string, std::string> customOptions; |
| 4033 | friend bool operator==( ProcessedReporterSpec const& lhs, |
| 4034 | ProcessedReporterSpec const& rhs ); |
| 4035 | friend bool operator!=( ProcessedReporterSpec const& lhs, |
| 4036 | ProcessedReporterSpec const& rhs ) { |
| 4037 | return !( lhs == rhs ); |
| 4038 | } |
| 4039 | }; |
| 4040 | |
| 4041 | struct ConfigData { |
| 4042 | |
| 4043 | bool listTests = false; |
| 4044 | bool listTags = false; |
| 4045 | bool listReporters = false; |
| 4046 | bool listListeners = false; |
| 4047 | |
| 4048 | bool showSuccessfulTests = false; |
| 4049 | bool shouldDebugBreak = false; |
| 4050 | bool noThrow = false; |
| 4051 | bool showHelp = false; |
| 4052 | bool showInvisibles = false; |
| 4053 | bool filenamesAsTags = false; |
| 4054 | bool libIdentify = false; |
| 4055 | bool allowZeroTests = false; |
| 4056 | |
| 4057 | int abortAfter = -1; |
| 4058 | uint32_t rngSeed = generateRandomSeed(GenerateFrom::Default); |
| 4059 | |
| 4060 | unsigned int shardCount = 1; |
| 4061 | unsigned int shardIndex = 0; |
| 4062 | |
| 4063 | bool skipBenchmarks = false; |
| 4064 | bool benchmarkNoAnalysis = false; |
| 4065 | unsigned int benchmarkSamples = 100; |
| 4066 | double benchmarkConfidenceInterval = 0.95; |
| 4067 | unsigned int benchmarkResamples = 100000; |
| 4068 | std::chrono::milliseconds::rep benchmarkWarmupTime = 100; |
| 4069 | |
| 4070 | Verbosity verbosity = Verbosity::Normal; |
| 4071 | WarnAbout::What warnings = WarnAbout::Nothing; |
| 4072 | ShowDurations showDurations = ShowDurations::DefaultForReporter; |
| 4073 | double minDuration = -1; |
| 4074 | TestRunOrder runOrder = TestRunOrder::Declared; |
| 4075 | ColourMode defaultColourMode = ColourMode::PlatformDefault; |
| 4076 | WaitForKeypress::When waitForKeypress = WaitForKeypress::Never; |
| 4077 | |
| 4078 | std::string defaultOutputFilename; |
| 4079 | std::string name; |
| 4080 | std::string processName; |
| 4081 | std::vector<ReporterSpec> reporterSpecifications; |
| 4082 | |
| 4083 | std::vector<std::string> testsOrTags; |
| 4084 | std::vector<std::string> sectionsToRun; |
| 4085 | }; |
| 4086 | |
| 4087 | |
| 4088 | class Config : public IConfig { |
| 4089 | public: |
| 4090 | |
| 4091 | Config() = default; |
| 4092 | Config( ConfigData const& data ); |
| 4093 | ~Config() override; // = default in the cpp file |
| 4094 | |
| 4095 | bool listTests() const; |
| 4096 | bool listTags() const; |
| 4097 | bool listReporters() const; |
| 4098 | bool listListeners() const; |
| 4099 | |
| 4100 | std::vector<ReporterSpec> const& getReporterSpecs() const; |
| 4101 | std::vector<ProcessedReporterSpec> const& |
| 4102 | getProcessedReporterSpecs() const; |
| 4103 | |
| 4104 | std::vector<std::string> const& getTestsOrTags() const override; |
| 4105 | std::vector<std::string> const& getSectionsToRun() const override; |
| 4106 | |
| 4107 | TestSpec const& testSpec() const override; |
| 4108 | bool hasTestFilters() const override; |
| 4109 | |
| 4110 | bool showHelp() const; |
| 4111 | |
| 4112 | // IConfig interface |
| 4113 | bool allowThrows() const override; |
| 4114 | StringRef name() const override; |
| 4115 | bool includeSuccessfulResults() const override; |
| 4116 | bool warnAboutMissingAssertions() const override; |
| 4117 | bool warnAboutUnmatchedTestSpecs() const override; |
| 4118 | bool zeroTestsCountAsSuccess() const override; |
| 4119 | ShowDurations showDurations() const override; |
| 4120 | double minDuration() const override; |
| 4121 | TestRunOrder runOrder() const override; |
| 4122 | uint32_t rngSeed() const override; |
| 4123 | unsigned int shardCount() const override; |
| 4124 | unsigned int shardIndex() const override; |
| 4125 | ColourMode defaultColourMode() const override; |
| 4126 | bool shouldDebugBreak() const override; |
| 4127 | int abortAfter() const override; |
| 4128 | bool showInvisibles() const override; |
| 4129 | Verbosity verbosity() const override; |
| 4130 | bool skipBenchmarks() const override; |
| 4131 | bool benchmarkNoAnalysis() const override; |
| 4132 | unsigned int benchmarkSamples() const override; |
| 4133 | double benchmarkConfidenceInterval() const override; |
| 4134 | unsigned int benchmarkResamples() const override; |
| 4135 | std::chrono::milliseconds benchmarkWarmupTime() const override; |
| 4136 | |
| 4137 | private: |
| 4138 | // Reads Bazel env vars and applies them to the config |
| 4139 | void readBazelEnvVars(); |
| 4140 | |
| 4141 | ConfigData m_data; |
| 4142 | std::vector<ProcessedReporterSpec> m_processedReporterSpecs; |
| 4143 | TestSpec m_testSpec; |
| 4144 | bool m_hasTestFilters = false; |
| 4145 | }; |
| 4146 | } // end namespace Catch |
| 4147 | |
| 4148 | #endif // CATCH_CONFIG_HPP_INCLUDED |
| 4149 | |
| 4150 | |
| 4151 | #ifndef CATCH_GET_RANDOM_SEED_HPP_INCLUDED |
| 4152 | #define CATCH_GET_RANDOM_SEED_HPP_INCLUDED |
| 4153 | |
| 4154 | #include <cstdint> |
| 4155 | |
| 4156 | namespace Catch { |
| 4157 | //! Returns Catch2's current RNG seed. |
| 4158 | std::uint32_t getSeed(); |
| 4159 | } |
| 4160 | |
| 4161 | #endif // CATCH_GET_RANDOM_SEED_HPP_INCLUDED |
| 4162 | |
| 4163 | |
| 4164 | #ifndef CATCH_MESSAGE_HPP_INCLUDED |
| 4165 | #define CATCH_MESSAGE_HPP_INCLUDED |
| 4166 | |
| 4167 | |
| 4168 | |
| 4169 | #ifndef CATCH_STREAM_END_STOP_HPP_INCLUDED |
| 4170 | #define CATCH_STREAM_END_STOP_HPP_INCLUDED |
| 4171 | |
| 4172 | |
| 4173 | namespace Catch { |
| 4174 | |
| 4175 | // Use this in variadic streaming macros to allow |
| 4176 | // << +StreamEndStop |
| 4177 | // as well as |
| 4178 | // << stuff +StreamEndStop |
| 4179 | struct StreamEndStop { |
| 4180 | constexpr StringRef operator+() const { return StringRef(); } |
| 4181 | |
| 4182 | template <typename T> |
| 4183 | constexpr friend T const& operator+( T const& value, StreamEndStop ) { |
| 4184 | return value; |
| 4185 | } |
| 4186 | }; |
| 4187 | |
| 4188 | } // namespace Catch |
| 4189 | |
| 4190 | #endif // CATCH_STREAM_END_STOP_HPP_INCLUDED |
| 4191 | |
| 4192 | |
| 4193 | #ifndef CATCH_MESSAGE_INFO_HPP_INCLUDED |
| 4194 | #define CATCH_MESSAGE_INFO_HPP_INCLUDED |
| 4195 | |
| 4196 | |
| 4197 | #include <string> |
| 4198 | |
| 4199 | namespace Catch { |
| 4200 | |
| 4201 | struct MessageInfo { |
| 4202 | MessageInfo( StringRef _macroName, |
| 4203 | SourceLineInfo const& _lineInfo, |
| 4204 | ResultWas::OfType _type ); |
| 4205 | |
| 4206 | StringRef macroName; |
| 4207 | std::string message; |
| 4208 | SourceLineInfo lineInfo; |
| 4209 | ResultWas::OfType type; |
| 4210 | unsigned int sequence; |
| 4211 | |
| 4212 | bool operator == (MessageInfo const& other) const { |
| 4213 | return sequence == other.sequence; |
| 4214 | } |
| 4215 | bool operator < (MessageInfo const& other) const { |
| 4216 | return sequence < other.sequence; |
| 4217 | } |
| 4218 | private: |
| 4219 | static unsigned int globalCount; |
| 4220 | }; |
| 4221 | |
| 4222 | } // end namespace Catch |
| 4223 | |
| 4224 | #endif // CATCH_MESSAGE_INFO_HPP_INCLUDED |
| 4225 | |
| 4226 | #include <string> |
| 4227 | #include <vector> |
| 4228 | |
| 4229 | namespace Catch { |
| 4230 | |
| 4231 | struct SourceLineInfo; |
| 4232 | class IResultCapture; |
| 4233 | |
| 4234 | struct MessageStream { |
| 4235 | |
| 4236 | template<typename T> |
| 4237 | MessageStream& operator << ( T const& value ) { |
| 4238 | m_stream << value; |
| 4239 | return *this; |
| 4240 | } |
| 4241 | |
| 4242 | ReusableStringStream m_stream; |
| 4243 | }; |
| 4244 | |
| 4245 | struct MessageBuilder : MessageStream { |
| 4246 | MessageBuilder( StringRef macroName, |
| 4247 | SourceLineInfo const& lineInfo, |
| 4248 | ResultWas::OfType type ): |
| 4249 | m_info(macroName, lineInfo, type) {} |
| 4250 | |
| 4251 | template<typename T> |
| 4252 | MessageBuilder&& operator << ( T const& value ) && { |
| 4253 | m_stream << value; |
| 4254 | return CATCH_MOVE(*this); |
| 4255 | } |
| 4256 | |
| 4257 | MessageInfo m_info; |
| 4258 | }; |
| 4259 | |
| 4260 | class ScopedMessage { |
| 4261 | public: |
| 4262 | explicit ScopedMessage( MessageBuilder&& builder ); |
| 4263 | ScopedMessage( ScopedMessage& duplicate ) = delete; |
| 4264 | ScopedMessage( ScopedMessage&& old ) noexcept; |
| 4265 | ~ScopedMessage(); |
| 4266 | |
| 4267 | MessageInfo m_info; |
| 4268 | bool m_moved = false; |
| 4269 | }; |
| 4270 | |
| 4271 | class Capturer { |
| 4272 | std::vector<MessageInfo> m_messages; |
| 4273 | IResultCapture& m_resultCapture; |
| 4274 | size_t m_captured = 0; |
| 4275 | public: |
| 4276 | Capturer( StringRef macroName, SourceLineInfo const& lineInfo, ResultWas::OfType resultType, StringRef names ); |
| 4277 | |
| 4278 | Capturer(Capturer const&) = delete; |
| 4279 | Capturer& operator=(Capturer const&) = delete; |
| 4280 | |
| 4281 | ~Capturer(); |
| 4282 | |
| 4283 | void captureValue( size_t index, std::string const& value ); |
| 4284 | |
| 4285 | template<typename T> |
| 4286 | void captureValues( size_t index, T const& value ) { |
| 4287 | captureValue( index, Catch::Detail::stringify( value ) ); |
| 4288 | } |
| 4289 | |
| 4290 | template<typename T, typename... Ts> |
| 4291 | void captureValues( size_t index, T const& value, Ts const&... values ) { |
| 4292 | captureValue( index, Catch::Detail::stringify(value) ); |
| 4293 | captureValues( index+1, values... ); |
| 4294 | } |
| 4295 | }; |
| 4296 | |
| 4297 | } // end namespace Catch |
| 4298 | |
| 4299 | /////////////////////////////////////////////////////////////////////////////// |
| 4300 | #define INTERNAL_CATCH_MSG( macroName, messageType, resultDisposition, ... ) \ |
| 4301 | do { \ |
| 4302 | Catch::AssertionHandler catchAssertionHandler( macroName##_catch_sr, CATCH_INTERNAL_LINEINFO, Catch::StringRef(), resultDisposition ); \ |
| 4303 | catchAssertionHandler.handleMessage( messageType, ( Catch::MessageStream() << __VA_ARGS__ + ::Catch::StreamEndStop() ).m_stream.str() ); \ |
| 4304 | INTERNAL_CATCH_REACT( catchAssertionHandler ) \ |
| 4305 | } while( false ) |
| 4306 | |
| 4307 | /////////////////////////////////////////////////////////////////////////////// |
| 4308 | #define INTERNAL_CATCH_CAPTURE( varName, macroName, ... ) \ |
| 4309 | Catch::Capturer varName( macroName##_catch_sr, \ |
| 4310 | CATCH_INTERNAL_LINEINFO, \ |
| 4311 | Catch::ResultWas::Info, \ |
| 4312 | #__VA_ARGS__##_catch_sr ); \ |
| 4313 | varName.captureValues( 0, __VA_ARGS__ ) |
| 4314 | |
| 4315 | /////////////////////////////////////////////////////////////////////////////// |
| 4316 | #define INTERNAL_CATCH_INFO( macroName, log ) \ |
| 4317 | const Catch::ScopedMessage INTERNAL_CATCH_UNIQUE_NAME( scopedMessage )( Catch::MessageBuilder( macroName##_catch_sr, CATCH_INTERNAL_LINEINFO, Catch::ResultWas::Info ) << log ) |
| 4318 | |
| 4319 | /////////////////////////////////////////////////////////////////////////////// |
| 4320 | #define INTERNAL_CATCH_UNSCOPED_INFO( macroName, log ) \ |
| 4321 | Catch::getResultCapture().emplaceUnscopedMessage( Catch::MessageBuilder( macroName##_catch_sr, CATCH_INTERNAL_LINEINFO, Catch::ResultWas::Info ) << log ) |
| 4322 | |
| 4323 | |
| 4324 | #if defined(CATCH_CONFIG_PREFIX_ALL) && !defined(CATCH_CONFIG_DISABLE) |
| 4325 | |
| 4326 | #define CATCH_INFO( msg ) INTERNAL_CATCH_INFO( "CATCH_INFO", msg ) |
| 4327 | #define CATCH_UNSCOPED_INFO( msg ) INTERNAL_CATCH_UNSCOPED_INFO( "CATCH_UNSCOPED_INFO", msg ) |
| 4328 | #define CATCH_WARN( msg ) INTERNAL_CATCH_MSG( "CATCH_WARN", Catch::ResultWas::Warning, Catch::ResultDisposition::ContinueOnFailure, msg ) |
| 4329 | #define CATCH_CAPTURE( ... ) INTERNAL_CATCH_CAPTURE( INTERNAL_CATCH_UNIQUE_NAME(capturer), "CATCH_CAPTURE", __VA_ARGS__ ) |
| 4330 | |
| 4331 | #elif defined(CATCH_CONFIG_PREFIX_ALL) && defined(CATCH_CONFIG_DISABLE) |
| 4332 | |
| 4333 | #define CATCH_INFO( msg ) (void)(0) |
| 4334 | #define CATCH_UNSCOPED_INFO( msg ) (void)(0) |
| 4335 | #define CATCH_WARN( msg ) (void)(0) |
| 4336 | #define CATCH_CAPTURE( ... ) (void)(0) |
| 4337 | |
| 4338 | #elif !defined(CATCH_CONFIG_PREFIX_ALL) && !defined(CATCH_CONFIG_DISABLE) |
| 4339 | |
| 4340 | #define INFO( msg ) INTERNAL_CATCH_INFO( "INFO", msg ) |
| 4341 | #define UNSCOPED_INFO( msg ) INTERNAL_CATCH_UNSCOPED_INFO( "UNSCOPED_INFO", msg ) |
| 4342 | #define WARN( msg ) INTERNAL_CATCH_MSG( "WARN", Catch::ResultWas::Warning, Catch::ResultDisposition::ContinueOnFailure, msg ) |
| 4343 | #define CAPTURE( ... ) INTERNAL_CATCH_CAPTURE( INTERNAL_CATCH_UNIQUE_NAME(capturer), "CAPTURE", __VA_ARGS__ ) |
| 4344 | |
| 4345 | #elif !defined(CATCH_CONFIG_PREFIX_ALL) && defined(CATCH_CONFIG_DISABLE) |
| 4346 | |
| 4347 | #define INFO( msg ) (void)(0) |
| 4348 | #define UNSCOPED_INFO( msg ) (void)(0) |
| 4349 | #define WARN( msg ) (void)(0) |
| 4350 | #define CAPTURE( ... ) (void)(0) |
| 4351 | |
| 4352 | #endif // end of user facing macro declarations |
| 4353 | |
| 4354 | |
| 4355 | |
| 4356 | |
| 4357 | #endif // CATCH_MESSAGE_HPP_INCLUDED |
| 4358 | |
| 4359 | |
| 4360 | #ifndef CATCH_SECTION_INFO_HPP_INCLUDED |
| 4361 | #define CATCH_SECTION_INFO_HPP_INCLUDED |
| 4362 | |
| 4363 | |
| 4364 | |
| 4365 | #ifndef CATCH_TOTALS_HPP_INCLUDED |
| 4366 | #define CATCH_TOTALS_HPP_INCLUDED |
| 4367 | |
| 4368 | #include <cstdint> |
| 4369 | |
| 4370 | namespace Catch { |
| 4371 | |
| 4372 | struct Counts { |
| 4373 | Counts operator - ( Counts const& other ) const; |
| 4374 | Counts& operator += ( Counts const& other ); |
| 4375 | |
| 4376 | std::uint64_t total() const; |
| 4377 | bool allPassed() const; |
| 4378 | bool allOk() const; |
| 4379 | |
| 4380 | std::uint64_t passed = 0; |
| 4381 | std::uint64_t failed = 0; |
| 4382 | std::uint64_t failedButOk = 0; |
| 4383 | std::uint64_t skipped = 0; |
| 4384 | }; |
| 4385 | |
| 4386 | struct Totals { |
| 4387 | |
| 4388 | Totals operator - ( Totals const& other ) const; |
| 4389 | Totals& operator += ( Totals const& other ); |
| 4390 | |
| 4391 | Totals delta( Totals const& prevTotals ) const; |
| 4392 | |
| 4393 | Counts assertions; |
| 4394 | Counts testCases; |
| 4395 | }; |
| 4396 | } |
| 4397 | |
| 4398 | #endif // CATCH_TOTALS_HPP_INCLUDED |
| 4399 | |
| 4400 | #include <string> |
| 4401 | |
| 4402 | namespace Catch { |
| 4403 | |
| 4404 | struct SectionInfo { |
| 4405 | // The last argument is ignored, so that people can write |
| 4406 | // SECTION("ShortName", "Proper description that is long") and |
| 4407 | // still use the `-c` flag comfortably. |
| 4408 | SectionInfo( SourceLineInfo const& _lineInfo, std::string _name, |
| 4409 | const char* const = nullptr ): |
| 4410 | name(CATCH_MOVE(_name)), |
| 4411 | lineInfo(_lineInfo) |
| 4412 | {} |
| 4413 | |
| 4414 | std::string name; |
| 4415 | SourceLineInfo lineInfo; |
| 4416 | }; |
| 4417 | |
| 4418 | struct SectionEndInfo { |
| 4419 | SectionInfo sectionInfo; |
| 4420 | Counts prevAssertions; |
| 4421 | double durationInSeconds; |
| 4422 | }; |
| 4423 | |
| 4424 | } // end namespace Catch |
| 4425 | |
| 4426 | #endif // CATCH_SECTION_INFO_HPP_INCLUDED |
| 4427 | |
| 4428 | |
| 4429 | #ifndef CATCH_SESSION_HPP_INCLUDED |
| 4430 | #define CATCH_SESSION_HPP_INCLUDED |
| 4431 | |
| 4432 | |
| 4433 | |
| 4434 | #ifndef CATCH_COMMANDLINE_HPP_INCLUDED |
| 4435 | #define CATCH_COMMANDLINE_HPP_INCLUDED |
| 4436 | |
| 4437 | |
| 4438 | |
| 4439 | #ifndef CATCH_CLARA_HPP_INCLUDED |
| 4440 | #define CATCH_CLARA_HPP_INCLUDED |
| 4441 | |
| 4442 | #if defined( __clang__ ) |
| 4443 | # pragma clang diagnostic push |
| 4444 | # pragma clang diagnostic ignored "-Wweak-vtables" |
| 4445 | # pragma clang diagnostic ignored "-Wshadow" |
| 4446 | # pragma clang diagnostic ignored "-Wdeprecated" |
| 4447 | #endif |
| 4448 | |
| 4449 | #if defined( __GNUC__ ) |
| 4450 | # pragma GCC diagnostic push |
| 4451 | # pragma GCC diagnostic ignored "-Wsign-conversion" |
| 4452 | #endif |
| 4453 | |
| 4454 | #ifndef CLARA_CONFIG_OPTIONAL_TYPE |
| 4455 | # ifdef __has_include |
| 4456 | # if __has_include( <optional>) && __cplusplus >= 201703L |
| 4457 | # include <optional> |
| 4458 | # define CLARA_CONFIG_OPTIONAL_TYPE std::optional |
| 4459 | # endif |
| 4460 | # endif |
| 4461 | #endif |
| 4462 | |
| 4463 | |
| 4464 | #include <cassert> |
| 4465 | #include <memory> |
| 4466 | #include <ostream> |
| 4467 | #include <sstream> |
| 4468 | #include <string> |
| 4469 | #include <type_traits> |
| 4470 | #include <vector> |
| 4471 | |
| 4472 | namespace Catch { |
| 4473 | namespace Clara { |
| 4474 | |
| 4475 | class Args; |
| 4476 | class Parser; |
| 4477 | |
| 4478 | // enum of result types from a parse |
| 4479 | enum class ParseResultType { |
| 4480 | Matched, |
| 4481 | NoMatch, |
| 4482 | ShortCircuitAll, |
| 4483 | ShortCircuitSame |
| 4484 | }; |
| 4485 | |
| 4486 | struct accept_many_t {}; |
| 4487 | constexpr accept_many_t accept_many {}; |
| 4488 | |
| 4489 | namespace Detail { |
| 4490 | struct fake_arg { |
| 4491 | template <typename T> |
| 4492 | operator T(); |
| 4493 | }; |
| 4494 | |
| 4495 | template <typename F, typename = void> |
| 4496 | struct is_unary_function : std::false_type {}; |
| 4497 | |
| 4498 | template <typename F> |
| 4499 | struct is_unary_function< |
| 4500 | F, |
| 4501 | Catch::Detail::void_t<decltype( |
| 4502 | std::declval<F>()( fake_arg() ) ) |
| 4503 | > |
| 4504 | > : std::true_type {}; |
| 4505 | |
| 4506 | // Traits for extracting arg and return type of lambdas (for single |
| 4507 | // argument lambdas) |
| 4508 | template <typename L> |
| 4509 | struct UnaryLambdaTraits |
| 4510 | : UnaryLambdaTraits<decltype( &L::operator() )> {}; |
| 4511 | |
| 4512 | template <typename ClassT, typename ReturnT, typename... Args> |
| 4513 | struct UnaryLambdaTraits<ReturnT ( ClassT::* )( Args... ) const> { |
| 4514 | static const bool isValid = false; |
| 4515 | }; |
| 4516 | |
| 4517 | template <typename ClassT, typename ReturnT, typename ArgT> |
| 4518 | struct UnaryLambdaTraits<ReturnT ( ClassT::* )( ArgT ) const> { |
| 4519 | static const bool isValid = true; |
| 4520 | using ArgType = std::remove_const_t<std::remove_reference_t<ArgT>>; |
| 4521 | using ReturnType = ReturnT; |
| 4522 | }; |
| 4523 | |
| 4524 | class TokenStream; |
| 4525 | |
| 4526 | // Wraps a token coming from a token stream. These may not directly |
| 4527 | // correspond to strings as a single string may encode an option + |
| 4528 | // its argument if the : or = form is used |
| 4529 | enum class TokenType { Option, Argument }; |
| 4530 | struct Token { |
| 4531 | TokenType type; |
| 4532 | std::string token; |
| 4533 | }; |
| 4534 | |
| 4535 | // Abstracts iterators into args as a stream of tokens, with option |
| 4536 | // arguments uniformly handled |
| 4537 | class TokenStream { |
| 4538 | using Iterator = std::vector<std::string>::const_iterator; |
| 4539 | Iterator it; |
| 4540 | Iterator itEnd; |
| 4541 | std::vector<Token> m_tokenBuffer; |
| 4542 | |
| 4543 | void loadBuffer(); |
| 4544 | |
| 4545 | public: |
| 4546 | explicit TokenStream( Args const& args ); |
| 4547 | TokenStream( Iterator it, Iterator itEnd ); |
| 4548 | |
| 4549 | explicit operator bool() const { |
| 4550 | return !m_tokenBuffer.empty() || it != itEnd; |
| 4551 | } |
| 4552 | |
| 4553 | size_t count() const { |
| 4554 | return m_tokenBuffer.size() + ( itEnd - it ); |
| 4555 | } |
| 4556 | |
| 4557 | Token operator*() const { |
| 4558 | assert( !m_tokenBuffer.empty() ); |
| 4559 | return m_tokenBuffer.front(); |
| 4560 | } |
| 4561 | |
| 4562 | Token const* operator->() const { |
| 4563 | assert( !m_tokenBuffer.empty() ); |
| 4564 | return &m_tokenBuffer.front(); |
| 4565 | } |
| 4566 | |
| 4567 | TokenStream& operator++(); |
| 4568 | }; |
| 4569 | |
| 4570 | //! Denotes type of a parsing result |
| 4571 | enum class ResultType { |
| 4572 | Ok, ///< No errors |
| 4573 | LogicError, ///< Error in user-specified arguments for |
| 4574 | ///< construction |
| 4575 | RuntimeError ///< Error in parsing inputs |
| 4576 | }; |
| 4577 | |
| 4578 | class ResultBase { |
| 4579 | protected: |
| 4580 | ResultBase( ResultType type ): m_type( type ) {} |
| 4581 | virtual ~ResultBase(); // = default; |
| 4582 | |
| 4583 | |
| 4584 | ResultBase(ResultBase const&) = default; |
| 4585 | ResultBase& operator=(ResultBase const&) = default; |
| 4586 | ResultBase(ResultBase&&) = default; |
| 4587 | ResultBase& operator=(ResultBase&&) = default; |
| 4588 | |
| 4589 | virtual void enforceOk() const = 0; |
| 4590 | |
| 4591 | ResultType m_type; |
| 4592 | }; |
| 4593 | |
| 4594 | template <typename T> class ResultValueBase : public ResultBase { |
| 4595 | public: |
| 4596 | auto value() const -> T const& { |
| 4597 | enforceOk(); |
| 4598 | return m_value; |
| 4599 | } |
| 4600 | |
| 4601 | protected: |
| 4602 | ResultValueBase( ResultType type ): ResultBase( type ) {} |
| 4603 | |
| 4604 | ResultValueBase( ResultValueBase const& other ): |
| 4605 | ResultBase( other ) { |
| 4606 | if ( m_type == ResultType::Ok ) |
| 4607 | new ( &m_value ) T( other.m_value ); |
| 4608 | } |
| 4609 | |
| 4610 | ResultValueBase( ResultType, T const& value ): ResultBase( ResultType::Ok ) { |
| 4611 | new ( &m_value ) T( value ); |
| 4612 | } |
| 4613 | |
| 4614 | auto operator=( ResultValueBase const& other ) |
| 4615 | -> ResultValueBase& { |
| 4616 | if ( m_type == ResultType::Ok ) |
| 4617 | m_value.~T(); |
| 4618 | ResultBase::operator=( other ); |
| 4619 | if ( m_type == ResultType::Ok ) |
| 4620 | new ( &m_value ) T( other.m_value ); |
| 4621 | return *this; |
| 4622 | } |
| 4623 | |
| 4624 | ~ResultValueBase() override { |
| 4625 | if ( m_type == ResultType::Ok ) |
| 4626 | m_value.~T(); |
| 4627 | } |
| 4628 | |
| 4629 | union { |
| 4630 | T m_value; |
| 4631 | }; |
| 4632 | }; |
| 4633 | |
| 4634 | template <> class ResultValueBase<void> : public ResultBase { |
| 4635 | protected: |
| 4636 | using ResultBase::ResultBase; |
| 4637 | }; |
| 4638 | |
| 4639 | template <typename T = void> |
| 4640 | class BasicResult : public ResultValueBase<T> { |
| 4641 | public: |
| 4642 | template <typename U> |
| 4643 | explicit BasicResult( BasicResult<U> const& other ): |
| 4644 | ResultValueBase<T>( other.type() ), |
| 4645 | m_errorMessage( other.errorMessage() ) { |
| 4646 | assert( type() != ResultType::Ok ); |
| 4647 | } |
| 4648 | |
| 4649 | template <typename U> |
| 4650 | static auto ok( U const& value ) -> BasicResult { |
| 4651 | return { ResultType::Ok, value }; |
| 4652 | } |
| 4653 | static auto ok() -> BasicResult { return { ResultType::Ok }; } |
| 4654 | static auto logicError( std::string&& message ) |
| 4655 | -> BasicResult { |
| 4656 | return { ResultType::LogicError, CATCH_MOVE(message) }; |
| 4657 | } |
| 4658 | static auto runtimeError( std::string&& message ) |
| 4659 | -> BasicResult { |
| 4660 | return { ResultType::RuntimeError, CATCH_MOVE(message) }; |
| 4661 | } |
| 4662 | |
| 4663 | explicit operator bool() const { |
| 4664 | return m_type == ResultType::Ok; |
| 4665 | } |
| 4666 | auto type() const -> ResultType { return m_type; } |
| 4667 | auto errorMessage() const -> std::string const& { |
| 4668 | return m_errorMessage; |
| 4669 | } |
| 4670 | |
| 4671 | protected: |
| 4672 | void enforceOk() const override { |
| 4673 | |
| 4674 | // Errors shouldn't reach this point, but if they do |
| 4675 | // the actual error message will be in m_errorMessage |
| 4676 | assert( m_type != ResultType::LogicError ); |
| 4677 | assert( m_type != ResultType::RuntimeError ); |
| 4678 | if ( m_type != ResultType::Ok ) |
| 4679 | std::abort(); |
| 4680 | } |
| 4681 | |
| 4682 | std::string |
| 4683 | m_errorMessage; // Only populated if resultType is an error |
| 4684 | |
| 4685 | BasicResult( ResultType type, |
| 4686 | std::string&& message ): |
| 4687 | ResultValueBase<T>( type ), m_errorMessage( CATCH_MOVE(message) ) { |
| 4688 | assert( m_type != ResultType::Ok ); |
| 4689 | } |
| 4690 | |
| 4691 | using ResultValueBase<T>::ResultValueBase; |
| 4692 | using ResultBase::m_type; |
| 4693 | }; |
| 4694 | |
| 4695 | class ParseState { |
| 4696 | public: |
| 4697 | ParseState( ParseResultType type, |
| 4698 | TokenStream const& remainingTokens ); |
| 4699 | |
| 4700 | ParseResultType type() const { return m_type; } |
| 4701 | TokenStream const& remainingTokens() const { |
| 4702 | return m_remainingTokens; |
| 4703 | } |
| 4704 | |
| 4705 | private: |
| 4706 | ParseResultType m_type; |
| 4707 | TokenStream m_remainingTokens; |
| 4708 | }; |
| 4709 | |
| 4710 | using Result = BasicResult<void>; |
| 4711 | using ParserResult = BasicResult<ParseResultType>; |
| 4712 | using InternalParseResult = BasicResult<ParseState>; |
| 4713 | |
| 4714 | struct HelpColumns { |
| 4715 | std::string left; |
| 4716 | std::string right; |
| 4717 | }; |
| 4718 | |
| 4719 | template <typename T> |
| 4720 | ParserResult convertInto( std::string const& source, T& target ) { |
| 4721 | std::stringstream ss( source ); |
| 4722 | ss >> target; |
| 4723 | if ( ss.fail() ) { |
| 4724 | return ParserResult::runtimeError( |
| 4725 | "Unable to convert '" + source + |
| 4726 | "' to destination type" ); |
| 4727 | } else { |
| 4728 | return ParserResult::ok( ParseResultType::Matched ); |
| 4729 | } |
| 4730 | } |
| 4731 | ParserResult convertInto( std::string const& source, |
| 4732 | std::string& target ); |
| 4733 | ParserResult convertInto( std::string const& source, bool& target ); |
| 4734 | |
| 4735 | #ifdef CLARA_CONFIG_OPTIONAL_TYPE |
| 4736 | template <typename T> |
| 4737 | auto convertInto( std::string const& source, |
| 4738 | CLARA_CONFIG_OPTIONAL_TYPE<T>& target ) |
| 4739 | -> ParserResult { |
| 4740 | T temp; |
| 4741 | auto result = convertInto( source, temp ); |
| 4742 | if ( result ) |
| 4743 | target = CATCH_MOVE( temp ); |
| 4744 | return result; |
| 4745 | } |
| 4746 | #endif // CLARA_CONFIG_OPTIONAL_TYPE |
| 4747 | |
| 4748 | struct BoundRef : Catch::Detail::NonCopyable { |
| 4749 | virtual ~BoundRef() = default; |
| 4750 | virtual bool isContainer() const; |
| 4751 | virtual bool isFlag() const; |
| 4752 | }; |
| 4753 | struct BoundValueRefBase : BoundRef { |
| 4754 | virtual auto setValue( std::string const& arg ) |
| 4755 | -> ParserResult = 0; |
| 4756 | }; |
| 4757 | struct BoundFlagRefBase : BoundRef { |
| 4758 | virtual auto setFlag( bool flag ) -> ParserResult = 0; |
| 4759 | bool isFlag() const override; |
| 4760 | }; |
| 4761 | |
| 4762 | template <typename T> struct BoundValueRef : BoundValueRefBase { |
| 4763 | T& m_ref; |
| 4764 | |
| 4765 | explicit BoundValueRef( T& ref ): m_ref( ref ) {} |
| 4766 | |
| 4767 | ParserResult setValue( std::string const& arg ) override { |
| 4768 | return convertInto( arg, m_ref ); |
| 4769 | } |
| 4770 | }; |
| 4771 | |
| 4772 | template <typename T> |
| 4773 | struct BoundValueRef<std::vector<T>> : BoundValueRefBase { |
| 4774 | std::vector<T>& m_ref; |
| 4775 | |
| 4776 | explicit BoundValueRef( std::vector<T>& ref ): m_ref( ref ) {} |
| 4777 | |
| 4778 | auto isContainer() const -> bool override { return true; } |
| 4779 | |
| 4780 | auto setValue( std::string const& arg ) |
| 4781 | -> ParserResult override { |
| 4782 | T temp; |
| 4783 | auto result = convertInto( arg, temp ); |
| 4784 | if ( result ) |
| 4785 | m_ref.push_back( temp ); |
| 4786 | return result; |
| 4787 | } |
| 4788 | }; |
| 4789 | |
| 4790 | struct BoundFlagRef : BoundFlagRefBase { |
| 4791 | bool& m_ref; |
| 4792 | |
| 4793 | explicit BoundFlagRef( bool& ref ): m_ref( ref ) {} |
| 4794 | |
| 4795 | ParserResult setFlag( bool flag ) override; |
| 4796 | }; |
| 4797 | |
| 4798 | template <typename ReturnType> struct LambdaInvoker { |
| 4799 | static_assert( |
| 4800 | std::is_same<ReturnType, ParserResult>::value, |
| 4801 | "Lambda must return void or clara::ParserResult" ); |
| 4802 | |
| 4803 | template <typename L, typename ArgType> |
| 4804 | static auto invoke( L const& lambda, ArgType const& arg ) |
| 4805 | -> ParserResult { |
| 4806 | return lambda( arg ); |
| 4807 | } |
| 4808 | }; |
| 4809 | |
| 4810 | template <> struct LambdaInvoker<void> { |
| 4811 | template <typename L, typename ArgType> |
| 4812 | static auto invoke( L const& lambda, ArgType const& arg ) |
| 4813 | -> ParserResult { |
| 4814 | lambda( arg ); |
| 4815 | return ParserResult::ok( ParseResultType::Matched ); |
| 4816 | } |
| 4817 | }; |
| 4818 | |
| 4819 | template <typename ArgType, typename L> |
| 4820 | auto invokeLambda( L const& lambda, std::string const& arg ) |
| 4821 | -> ParserResult { |
| 4822 | ArgType temp{}; |
| 4823 | auto result = convertInto( arg, temp ); |
| 4824 | return !result ? result |
| 4825 | : LambdaInvoker<typename UnaryLambdaTraits< |
| 4826 | L>::ReturnType>::invoke( lambda, temp ); |
| 4827 | } |
| 4828 | |
| 4829 | template <typename L> struct BoundLambda : BoundValueRefBase { |
| 4830 | L m_lambda; |
| 4831 | |
| 4832 | static_assert( |
| 4833 | UnaryLambdaTraits<L>::isValid, |
| 4834 | "Supplied lambda must take exactly one argument" ); |
| 4835 | explicit BoundLambda( L const& lambda ): m_lambda( lambda ) {} |
| 4836 | |
| 4837 | auto setValue( std::string const& arg ) |
| 4838 | -> ParserResult override { |
| 4839 | return invokeLambda<typename UnaryLambdaTraits<L>::ArgType>( |
| 4840 | m_lambda, arg ); |
| 4841 | } |
| 4842 | }; |
| 4843 | |
| 4844 | template <typename L> struct BoundManyLambda : BoundLambda<L> { |
| 4845 | explicit BoundManyLambda( L const& lambda ): BoundLambda<L>( lambda ) {} |
| 4846 | bool isContainer() const override { return true; } |
| 4847 | }; |
| 4848 | |
| 4849 | template <typename L> struct BoundFlagLambda : BoundFlagRefBase { |
| 4850 | L m_lambda; |
| 4851 | |
| 4852 | static_assert( |
| 4853 | UnaryLambdaTraits<L>::isValid, |
| 4854 | "Supplied lambda must take exactly one argument" ); |
| 4855 | static_assert( |
| 4856 | std::is_same<typename UnaryLambdaTraits<L>::ArgType, |
| 4857 | bool>::value, |
| 4858 | "flags must be boolean" ); |
| 4859 | |
| 4860 | explicit BoundFlagLambda( L const& lambda ): |
| 4861 | m_lambda( lambda ) {} |
| 4862 | |
| 4863 | auto setFlag( bool flag ) -> ParserResult override { |
| 4864 | return LambdaInvoker<typename UnaryLambdaTraits< |
| 4865 | L>::ReturnType>::invoke( m_lambda, flag ); |
| 4866 | } |
| 4867 | }; |
| 4868 | |
| 4869 | enum class Optionality { Optional, Required }; |
| 4870 | |
| 4871 | class ParserBase { |
| 4872 | public: |
| 4873 | virtual ~ParserBase() = default; |
| 4874 | virtual auto validate() const -> Result { return Result::ok(); } |
| 4875 | virtual auto parse( std::string const& exeName, |
| 4876 | TokenStream const& tokens ) const |
| 4877 | -> InternalParseResult = 0; |
| 4878 | virtual size_t cardinality() const; |
| 4879 | |
| 4880 | InternalParseResult parse( Args const& args ) const; |
| 4881 | }; |
| 4882 | |
| 4883 | template <typename DerivedT> |
| 4884 | class ComposableParserImpl : public ParserBase { |
| 4885 | public: |
| 4886 | template <typename T> |
| 4887 | auto operator|( T const& other ) const -> Parser; |
| 4888 | }; |
| 4889 | |
| 4890 | // Common code and state for Args and Opts |
| 4891 | template <typename DerivedT> |
| 4892 | class ParserRefImpl : public ComposableParserImpl<DerivedT> { |
| 4893 | protected: |
| 4894 | Optionality m_optionality = Optionality::Optional; |
| 4895 | std::shared_ptr<BoundRef> m_ref; |
| 4896 | std::string m_hint; |
| 4897 | std::string m_description; |
| 4898 | |
| 4899 | explicit ParserRefImpl( std::shared_ptr<BoundRef> const& ref ): |
| 4900 | m_ref( ref ) {} |
| 4901 | |
| 4902 | public: |
| 4903 | template <typename LambdaT> |
| 4904 | ParserRefImpl( accept_many_t, |
| 4905 | LambdaT const& ref, |
| 4906 | std::string const& hint ): |
| 4907 | m_ref( std::make_shared<BoundManyLambda<LambdaT>>( ref ) ), |
| 4908 | m_hint( hint ) {} |
| 4909 | |
| 4910 | template <typename T, |
| 4911 | typename = typename std::enable_if_t< |
| 4912 | !Detail::is_unary_function<T>::value>> |
| 4913 | ParserRefImpl( T& ref, std::string const& hint ): |
| 4914 | m_ref( std::make_shared<BoundValueRef<T>>( ref ) ), |
| 4915 | m_hint( hint ) {} |
| 4916 | |
| 4917 | template <typename LambdaT, |
| 4918 | typename = typename std::enable_if_t< |
| 4919 | Detail::is_unary_function<LambdaT>::value>> |
| 4920 | ParserRefImpl( LambdaT const& ref, std::string const& hint ): |
| 4921 | m_ref( std::make_shared<BoundLambda<LambdaT>>( ref ) ), |
| 4922 | m_hint( hint ) {} |
| 4923 | |
| 4924 | auto operator()( std::string const& description ) -> DerivedT& { |
| 4925 | m_description = description; |
| 4926 | return static_cast<DerivedT&>( *this ); |
| 4927 | } |
| 4928 | |
| 4929 | auto optional() -> DerivedT& { |
| 4930 | m_optionality = Optionality::Optional; |
| 4931 | return static_cast<DerivedT&>( *this ); |
| 4932 | } |
| 4933 | |
| 4934 | auto required() -> DerivedT& { |
| 4935 | m_optionality = Optionality::Required; |
| 4936 | return static_cast<DerivedT&>( *this ); |
| 4937 | } |
| 4938 | |
| 4939 | auto isOptional() const -> bool { |
| 4940 | return m_optionality == Optionality::Optional; |
| 4941 | } |
| 4942 | |
| 4943 | auto cardinality() const -> size_t override { |
| 4944 | if ( m_ref->isContainer() ) |
| 4945 | return 0; |
| 4946 | else |
| 4947 | return 1; |
| 4948 | } |
| 4949 | |
| 4950 | std::string const& hint() const { return m_hint; } |
| 4951 | }; |
| 4952 | |
| 4953 | } // namespace detail |
| 4954 | |
| 4955 | |
| 4956 | // A parser for arguments |
| 4957 | class Arg : public Detail::ParserRefImpl<Arg> { |
| 4958 | public: |
| 4959 | using ParserRefImpl::ParserRefImpl; |
| 4960 | using ParserBase::parse; |
| 4961 | |
| 4962 | Detail::InternalParseResult |
| 4963 | parse(std::string const&, |
| 4964 | Detail::TokenStream const& tokens) const override; |
| 4965 | }; |
| 4966 | |
| 4967 | // A parser for options |
| 4968 | class Opt : public Detail::ParserRefImpl<Opt> { |
| 4969 | protected: |
| 4970 | std::vector<std::string> m_optNames; |
| 4971 | |
| 4972 | public: |
| 4973 | template <typename LambdaT> |
| 4974 | explicit Opt(LambdaT const& ref) : |
| 4975 | ParserRefImpl( |
| 4976 | std::make_shared<Detail::BoundFlagLambda<LambdaT>>(ref)) {} |
| 4977 | |
| 4978 | explicit Opt(bool& ref); |
| 4979 | |
| 4980 | template <typename LambdaT, |
| 4981 | typename = typename std::enable_if_t< |
| 4982 | Detail::is_unary_function<LambdaT>::value>> |
| 4983 | Opt( LambdaT const& ref, std::string const& hint ): |
| 4984 | ParserRefImpl( ref, hint ) {} |
| 4985 | |
| 4986 | template <typename LambdaT> |
| 4987 | Opt( accept_many_t, LambdaT const& ref, std::string const& hint ): |
| 4988 | ParserRefImpl( accept_many, ref, hint ) {} |
| 4989 | |
| 4990 | template <typename T, |
| 4991 | typename = typename std::enable_if_t< |
| 4992 | !Detail::is_unary_function<T>::value>> |
| 4993 | Opt( T& ref, std::string const& hint ): |
| 4994 | ParserRefImpl( ref, hint ) {} |
| 4995 | |
| 4996 | auto operator[](std::string const& optName) -> Opt& { |
| 4997 | m_optNames.push_back(optName); |
| 4998 | return *this; |
| 4999 | } |
| 5000 | |
| 5001 | std::vector<Detail::HelpColumns> getHelpColumns() const; |
| 5002 | |
| 5003 | bool isMatch(std::string const& optToken) const; |
| 5004 | |
| 5005 | using ParserBase::parse; |
| 5006 | |
| 5007 | Detail::InternalParseResult |
| 5008 | parse(std::string const&, |
| 5009 | Detail::TokenStream const& tokens) const override; |
| 5010 | |
| 5011 | Detail::Result validate() const override; |
| 5012 | }; |
| 5013 | |
| 5014 | // Specifies the name of the executable |
| 5015 | class ExeName : public Detail::ComposableParserImpl<ExeName> { |
| 5016 | std::shared_ptr<std::string> m_name; |
| 5017 | std::shared_ptr<Detail::BoundValueRefBase> m_ref; |
| 5018 | |
| 5019 | public: |
| 5020 | ExeName(); |
| 5021 | explicit ExeName(std::string& ref); |
| 5022 | |
| 5023 | template <typename LambdaT> |
| 5024 | explicit ExeName(LambdaT const& lambda) : ExeName() { |
| 5025 | m_ref = std::make_shared<Detail::BoundLambda<LambdaT>>(lambda); |
| 5026 | } |
| 5027 | |
| 5028 | // The exe name is not parsed out of the normal tokens, but is |
| 5029 | // handled specially |
| 5030 | Detail::InternalParseResult |
| 5031 | parse(std::string const&, |
| 5032 | Detail::TokenStream const& tokens) const override; |
| 5033 | |
| 5034 | std::string const& name() const { return *m_name; } |
| 5035 | Detail::ParserResult set(std::string const& newName); |
| 5036 | }; |
| 5037 | |
| 5038 | |
| 5039 | // A Combined parser |
| 5040 | class Parser : Detail::ParserBase { |
| 5041 | mutable ExeName m_exeName; |
| 5042 | std::vector<Opt> m_options; |
| 5043 | std::vector<Arg> m_args; |
| 5044 | |
| 5045 | public: |
| 5046 | |
| 5047 | auto operator|=(ExeName const& exeName) -> Parser& { |
| 5048 | m_exeName = exeName; |
| 5049 | return *this; |
| 5050 | } |
| 5051 | |
| 5052 | auto operator|=(Arg const& arg) -> Parser& { |
| 5053 | m_args.push_back(arg); |
| 5054 | return *this; |
| 5055 | } |
| 5056 | |
| 5057 | auto operator|=(Opt const& opt) -> Parser& { |
| 5058 | m_options.push_back(opt); |
| 5059 | return *this; |
| 5060 | } |
| 5061 | |
| 5062 | Parser& operator|=(Parser const& other); |
| 5063 | |
| 5064 | template <typename T> |
| 5065 | auto operator|(T const& other) const -> Parser { |
| 5066 | return Parser(*this) |= other; |
| 5067 | } |
| 5068 | |
| 5069 | std::vector<Detail::HelpColumns> getHelpColumns() const; |
| 5070 | |
| 5071 | void writeToStream(std::ostream& os) const; |
| 5072 | |
| 5073 | friend auto operator<<(std::ostream& os, Parser const& parser) |
| 5074 | -> std::ostream& { |
| 5075 | parser.writeToStream(os); |
| 5076 | return os; |
| 5077 | } |
| 5078 | |
| 5079 | Detail::Result validate() const override; |
| 5080 | |
| 5081 | using ParserBase::parse; |
| 5082 | Detail::InternalParseResult |
| 5083 | parse(std::string const& exeName, |
| 5084 | Detail::TokenStream const& tokens) const override; |
| 5085 | }; |
| 5086 | |
| 5087 | // Transport for raw args (copied from main args, or supplied via |
| 5088 | // init list for testing) |
| 5089 | class Args { |
| 5090 | friend Detail::TokenStream; |
| 5091 | std::string m_exeName; |
| 5092 | std::vector<std::string> m_args; |
| 5093 | |
| 5094 | public: |
| 5095 | Args(int argc, char const* const* argv); |
| 5096 | Args(std::initializer_list<std::string> args); |
| 5097 | |
| 5098 | std::string const& exeName() const { return m_exeName; } |
| 5099 | }; |
| 5100 | |
| 5101 | |
| 5102 | // Convenience wrapper for option parser that specifies the help option |
| 5103 | struct Help : Opt { |
| 5104 | Help(bool& showHelpFlag); |
| 5105 | }; |
| 5106 | |
| 5107 | // Result type for parser operation |
| 5108 | using Detail::ParserResult; |
| 5109 | |
| 5110 | namespace Detail { |
| 5111 | template <typename DerivedT> |
| 5112 | template <typename T> |
| 5113 | Parser |
| 5114 | ComposableParserImpl<DerivedT>::operator|(T const& other) const { |
| 5115 | return Parser() | static_cast<DerivedT const&>(*this) | other; |
| 5116 | } |
| 5117 | } |
| 5118 | |
| 5119 | } // namespace Clara |
| 5120 | } // namespace Catch |
| 5121 | |
| 5122 | #if defined( __clang__ ) |
| 5123 | # pragma clang diagnostic pop |
| 5124 | #endif |
| 5125 | |
| 5126 | #if defined( __GNUC__ ) |
| 5127 | # pragma GCC diagnostic pop |
| 5128 | #endif |
| 5129 | |
| 5130 | #endif // CATCH_CLARA_HPP_INCLUDED |
| 5131 | |
| 5132 | namespace Catch { |
| 5133 | |
| 5134 | struct ConfigData; |
| 5135 | |
| 5136 | Clara::Parser makeCommandLineParser( ConfigData& config ); |
| 5137 | |
| 5138 | } // end namespace Catch |
| 5139 | |
| 5140 | #endif // CATCH_COMMANDLINE_HPP_INCLUDED |
| 5141 | |
| 5142 | namespace Catch { |
| 5143 | |
| 5144 | class Session : Detail::NonCopyable { |
| 5145 | public: |
| 5146 | |
| 5147 | Session(); |
| 5148 | ~Session(); |
| 5149 | |
| 5150 | void showHelp() const; |
| 5151 | void libIdentify(); |
| 5152 | |
| 5153 | int applyCommandLine( int argc, char const * const * argv ); |
| 5154 | #if defined(CATCH_CONFIG_WCHAR) && defined(_WIN32) && defined(UNICODE) |
| 5155 | int applyCommandLine( int argc, wchar_t const * const * argv ); |
| 5156 | #endif |
| 5157 | |
| 5158 | void useConfigData( ConfigData const& configData ); |
| 5159 | |
| 5160 | template<typename CharT> |
| 5161 | int run(int argc, CharT const * const argv[]) { |
| 5162 | if (m_startupExceptions) |
| 5163 | return 1; |
| 5164 | int returnCode = applyCommandLine(argc, argv); |
| 5165 | if (returnCode == 0) |
| 5166 | returnCode = run(); |
| 5167 | return returnCode; |
| 5168 | } |
| 5169 | |
| 5170 | int run(); |
| 5171 | |
| 5172 | Clara::Parser const& cli() const; |
| 5173 | void cli( Clara::Parser const& newParser ); |
| 5174 | ConfigData& configData(); |
| 5175 | Config& config(); |
| 5176 | private: |
| 5177 | int runInternal(); |
| 5178 | |
| 5179 | Clara::Parser m_cli; |
| 5180 | ConfigData m_configData; |
| 5181 | Detail::unique_ptr<Config> m_config; |
| 5182 | bool m_startupExceptions = false; |
| 5183 | }; |
| 5184 | |
| 5185 | } // end namespace Catch |
| 5186 | |
| 5187 | #endif // CATCH_SESSION_HPP_INCLUDED |
| 5188 | |
| 5189 | |
| 5190 | #ifndef CATCH_TAG_ALIAS_HPP_INCLUDED |
| 5191 | #define CATCH_TAG_ALIAS_HPP_INCLUDED |
| 5192 | |
| 5193 | |
| 5194 | #include <string> |
| 5195 | |
| 5196 | namespace Catch { |
| 5197 | |
| 5198 | struct TagAlias { |
| 5199 | TagAlias(std::string const& _tag, SourceLineInfo _lineInfo): |
| 5200 | tag(_tag), |
| 5201 | lineInfo(_lineInfo) |
| 5202 | {} |
| 5203 | |
| 5204 | std::string tag; |
| 5205 | SourceLineInfo lineInfo; |
| 5206 | }; |
| 5207 | |
| 5208 | } // end namespace Catch |
| 5209 | |
| 5210 | #endif // CATCH_TAG_ALIAS_HPP_INCLUDED |
| 5211 | |
| 5212 | |
| 5213 | #ifndef CATCH_TAG_ALIAS_AUTOREGISTRAR_HPP_INCLUDED |
| 5214 | #define CATCH_TAG_ALIAS_AUTOREGISTRAR_HPP_INCLUDED |
| 5215 | |
| 5216 | |
| 5217 | namespace Catch { |
| 5218 | |
| 5219 | struct RegistrarForTagAliases { |
| 5220 | RegistrarForTagAliases( char const* alias, char const* tag, SourceLineInfo const& lineInfo ); |
| 5221 | }; |
| 5222 | |
| 5223 | } // end namespace Catch |
| 5224 | |
| 5225 | #define CATCH_REGISTER_TAG_ALIAS( alias, spec ) \ |
| 5226 | CATCH_INTERNAL_START_WARNINGS_SUPPRESSION \ |
| 5227 | CATCH_INTERNAL_SUPPRESS_GLOBALS_WARNINGS \ |
| 5228 | namespace{ Catch::RegistrarForTagAliases INTERNAL_CATCH_UNIQUE_NAME( AutoRegisterTagAlias )( alias, spec, CATCH_INTERNAL_LINEINFO ); } \ |
| 5229 | CATCH_INTERNAL_STOP_WARNINGS_SUPPRESSION |
| 5230 | |
| 5231 | #endif // CATCH_TAG_ALIAS_AUTOREGISTRAR_HPP_INCLUDED |
| 5232 | |
| 5233 | |
| 5234 | #ifndef CATCH_TEMPLATE_TEST_MACROS_HPP_INCLUDED |
| 5235 | #define CATCH_TEMPLATE_TEST_MACROS_HPP_INCLUDED |
| 5236 | |
| 5237 | // We need this suppression to leak, because it took until GCC 10 |
| 5238 | // for the front end to handle local suppression via _Pragma properly |
| 5239 | // inside templates (so `TEMPLATE_TEST_CASE` and co). |
| 5240 | // **THIS IS DIFFERENT FOR STANDARD TESTS, WHERE GCC 9 IS SUFFICIENT** |
| 5241 | #if defined(__GNUC__) && !defined(__clang__) && !defined(__ICC) && __GNUC__ < 10 |
| 5242 | #pragma GCC diagnostic ignored "-Wparentheses" |
| 5243 | #endif |
| 5244 | |
| 5245 | |
| 5246 | |
| 5247 | |
| 5248 | #ifndef CATCH_TEST_MACROS_HPP_INCLUDED |
| 5249 | #define CATCH_TEST_MACROS_HPP_INCLUDED |
| 5250 | |
| 5251 | |
| 5252 | |
| 5253 | #ifndef CATCH_TEST_MACRO_IMPL_HPP_INCLUDED |
| 5254 | #define CATCH_TEST_MACRO_IMPL_HPP_INCLUDED |
| 5255 | |
| 5256 | |
| 5257 | |
| 5258 | #ifndef CATCH_ASSERTION_HANDLER_HPP_INCLUDED |
| 5259 | #define CATCH_ASSERTION_HANDLER_HPP_INCLUDED |
| 5260 | |
| 5261 | |
| 5262 | |
| 5263 | #ifndef CATCH_DECOMPOSER_HPP_INCLUDED |
| 5264 | #define CATCH_DECOMPOSER_HPP_INCLUDED |
| 5265 | |
| 5266 | |
| 5267 | |
| 5268 | #ifndef CATCH_COMPARE_TRAITS_HPP_INCLUDED |
| 5269 | #define CATCH_COMPARE_TRAITS_HPP_INCLUDED |
| 5270 | |
| 5271 | |
| 5272 | #include <type_traits> |
| 5273 | |
| 5274 | namespace Catch { |
| 5275 | namespace Detail { |
| 5276 | |
| 5277 | #if defined( __GNUC__ ) && !defined( __clang__ ) |
| 5278 | # pragma GCC diagnostic push |
| 5279 | // GCC likes to complain about comparing bool with 0, in the decltype() |
| 5280 | // that defines the comparable traits below. |
| 5281 | # pragma GCC diagnostic ignored "-Wbool-compare" |
| 5282 | // "ordered comparison of pointer with integer zero" same as above, |
| 5283 | // but it does not have a separate warning flag to suppress |
| 5284 | # pragma GCC diagnostic ignored "-Wextra" |
| 5285 | // Did you know that comparing floats with `0` directly |
| 5286 | // is super-duper dangerous in unevaluated context? |
| 5287 | # pragma GCC diagnostic ignored "-Wfloat-equal" |
| 5288 | #endif |
| 5289 | |
| 5290 | #if defined( __clang__ ) |
| 5291 | # pragma clang diagnostic push |
| 5292 | // Did you know that comparing floats with `0` directly |
| 5293 | // is super-duper dangerous in unevaluated context? |
| 5294 | # pragma clang diagnostic ignored "-Wfloat-equal" |
| 5295 | #endif |
| 5296 | |
| 5297 | #define CATCH_DEFINE_COMPARABLE_TRAIT( id, op ) \ |
| 5298 | template <typename, typename, typename = void> \ |
| 5299 | struct is_##id##_comparable : std::false_type {}; \ |
| 5300 | template <typename T, typename U> \ |
| 5301 | struct is_##id##_comparable< \ |
| 5302 | T, \ |
| 5303 | U, \ |
| 5304 | void_t<decltype( std::declval<T>() op std::declval<U>() )>> \ |
| 5305 | : std::true_type {}; \ |
| 5306 | template <typename, typename = void> \ |
| 5307 | struct is_##id##_0_comparable : std::false_type {}; \ |
| 5308 | template <typename T> \ |
| 5309 | struct is_##id##_0_comparable<T, \ |
| 5310 | void_t<decltype( std::declval<T>() op 0 )>> \ |
| 5311 | : std::true_type {}; |
| 5312 | |
| 5313 | // We need all 6 pre-spaceship comparison ops: <, <=, >, >=, ==, != |
| 5314 | CATCH_DEFINE_COMPARABLE_TRAIT( lt, < ) |
| 5315 | CATCH_DEFINE_COMPARABLE_TRAIT( le, <= ) |
| 5316 | CATCH_DEFINE_COMPARABLE_TRAIT( gt, > ) |
| 5317 | CATCH_DEFINE_COMPARABLE_TRAIT( ge, >= ) |
| 5318 | CATCH_DEFINE_COMPARABLE_TRAIT( eq, == ) |
| 5319 | CATCH_DEFINE_COMPARABLE_TRAIT( ne, != ) |
| 5320 | |
| 5321 | #undef CATCH_DEFINE_COMPARABLE_TRAIT |
| 5322 | |
| 5323 | #if defined( __GNUC__ ) && !defined( __clang__ ) |
| 5324 | # pragma GCC diagnostic pop |
| 5325 | #endif |
| 5326 | #if defined( __clang__ ) |
| 5327 | # pragma clang diagnostic pop |
| 5328 | #endif |
| 5329 | |
| 5330 | |
| 5331 | } // namespace Detail |
| 5332 | } // namespace Catch |
| 5333 | |
| 5334 | #endif // CATCH_COMPARE_TRAITS_HPP_INCLUDED |
| 5335 | |
| 5336 | |
| 5337 | #ifndef CATCH_LOGICAL_TRAITS_HPP_INCLUDED |
| 5338 | #define CATCH_LOGICAL_TRAITS_HPP_INCLUDED |
| 5339 | |
| 5340 | #include <type_traits> |
| 5341 | |
| 5342 | namespace Catch { |
| 5343 | namespace Detail { |
| 5344 | |
| 5345 | #if defined( __cpp_lib_logical_traits ) && __cpp_lib_logical_traits >= 201510 |
| 5346 | |
| 5347 | using std::conjunction; |
| 5348 | using std::disjunction; |
| 5349 | using std::negation; |
| 5350 | |
| 5351 | #else |
| 5352 | |
| 5353 | template <class...> struct conjunction : std::true_type {}; |
| 5354 | template <class B1> struct conjunction<B1> : B1 {}; |
| 5355 | template <class B1, class... Bn> |
| 5356 | struct conjunction<B1, Bn...> |
| 5357 | : std::conditional_t<bool( B1::value ), conjunction<Bn...>, B1> {}; |
| 5358 | |
| 5359 | template <class...> struct disjunction : std::false_type {}; |
| 5360 | template <class B1> struct disjunction<B1> : B1 {}; |
| 5361 | template <class B1, class... Bn> |
| 5362 | struct disjunction<B1, Bn...> |
| 5363 | : std::conditional_t<bool( B1::value ), B1, disjunction<Bn...>> {}; |
| 5364 | |
| 5365 | template <class B> |
| 5366 | struct negation : std::integral_constant<bool, !bool(B::value)> {}; |
| 5367 | |
| 5368 | #endif |
| 5369 | |
| 5370 | } // namespace Detail |
| 5371 | } // namespace Catch |
| 5372 | |
| 5373 | #endif // CATCH_LOGICAL_TRAITS_HPP_INCLUDED |
| 5374 | |
| 5375 | #include <type_traits> |
| 5376 | #include <iosfwd> |
| 5377 | |
| 5378 | #ifdef _MSC_VER |
| 5379 | #pragma warning(push) |
| 5380 | #pragma warning(disable:4389) // '==' : signed/unsigned mismatch |
| 5381 | #pragma warning(disable:4018) // more "signed/unsigned mismatch" |
| 5382 | #pragma warning(disable:4312) // Converting int to T* using reinterpret_cast (issue on x64 platform) |
| 5383 | #pragma warning(disable:4180) // qualifier applied to function type has no meaning |
| 5384 | #pragma warning(disable:4800) // Forcing result to true or false |
| 5385 | #endif |
| 5386 | |
| 5387 | #ifdef __clang__ |
| 5388 | # pragma clang diagnostic push |
| 5389 | # pragma clang diagnostic ignored "-Wsign-compare" |
| 5390 | #elif defined __GNUC__ |
| 5391 | # pragma GCC diagnostic push |
| 5392 | # pragma GCC diagnostic ignored "-Wsign-compare" |
| 5393 | #endif |
| 5394 | |
| 5395 | namespace Catch { |
| 5396 | |
| 5397 | template <typename T> |
| 5398 | struct always_false : std::false_type {}; |
| 5399 | |
| 5400 | class ITransientExpression { |
| 5401 | bool m_isBinaryExpression; |
| 5402 | bool m_result; |
| 5403 | |
| 5404 | public: |
| 5405 | auto isBinaryExpression() const -> bool { return m_isBinaryExpression; } |
| 5406 | auto getResult() const -> bool { return m_result; } |
| 5407 | virtual void streamReconstructedExpression( std::ostream &os ) const = 0; |
| 5408 | |
| 5409 | ITransientExpression( bool isBinaryExpression, bool result ) |
| 5410 | : m_isBinaryExpression( isBinaryExpression ), |
| 5411 | m_result( result ) |
| 5412 | {} |
| 5413 | |
| 5414 | ITransientExpression() = default; |
| 5415 | ITransientExpression(ITransientExpression const&) = default; |
| 5416 | ITransientExpression& operator=(ITransientExpression const&) = default; |
| 5417 | |
| 5418 | // We don't actually need a virtual destructor, but many static analysers |
| 5419 | // complain if it's not here :-( |
| 5420 | virtual ~ITransientExpression(); // = default; |
| 5421 | |
| 5422 | friend std::ostream& operator<<(std::ostream& out, ITransientExpression const& expr) { |
| 5423 | expr.streamReconstructedExpression(out); |
| 5424 | return out; |
| 5425 | } |
| 5426 | }; |
| 5427 | |
| 5428 | void formatReconstructedExpression( std::ostream &os, std::string const& lhs, StringRef op, std::string const& rhs ); |
| 5429 | |
| 5430 | template<typename LhsT, typename RhsT> |
| 5431 | class BinaryExpr : public ITransientExpression { |
| 5432 | LhsT m_lhs; |
| 5433 | StringRef m_op; |
| 5434 | RhsT m_rhs; |
| 5435 | |
| 5436 | void streamReconstructedExpression( std::ostream &os ) const override { |
| 5437 | formatReconstructedExpression |
| 5438 | ( os, Catch::Detail::stringify( m_lhs ), m_op, Catch::Detail::stringify( m_rhs ) ); |
| 5439 | } |
| 5440 | |
| 5441 | public: |
| 5442 | BinaryExpr( bool comparisonResult, LhsT lhs, StringRef op, RhsT rhs ) |
| 5443 | : ITransientExpression{ true, comparisonResult }, |
| 5444 | m_lhs( lhs ), |
| 5445 | m_op( op ), |
| 5446 | m_rhs( rhs ) |
| 5447 | {} |
| 5448 | |
| 5449 | template<typename T> |
| 5450 | auto operator && ( T ) const -> BinaryExpr<LhsT, RhsT const&> const { |
| 5451 | static_assert(always_false<T>::value, |
| 5452 | "chained comparisons are not supported inside assertions, " |
| 5453 | "wrap the expression inside parentheses, or decompose it"); |
| 5454 | } |
| 5455 | |
| 5456 | template<typename T> |
| 5457 | auto operator || ( T ) const -> BinaryExpr<LhsT, RhsT const&> const { |
| 5458 | static_assert(always_false<T>::value, |
| 5459 | "chained comparisons are not supported inside assertions, " |
| 5460 | "wrap the expression inside parentheses, or decompose it"); |
| 5461 | } |
| 5462 | |
| 5463 | template<typename T> |
| 5464 | auto operator == ( T ) const -> BinaryExpr<LhsT, RhsT const&> const { |
| 5465 | static_assert(always_false<T>::value, |
| 5466 | "chained comparisons are not supported inside assertions, " |
| 5467 | "wrap the expression inside parentheses, or decompose it"); |
| 5468 | } |
| 5469 | |
| 5470 | template<typename T> |
| 5471 | auto operator != ( T ) const -> BinaryExpr<LhsT, RhsT const&> const { |
| 5472 | static_assert(always_false<T>::value, |
| 5473 | "chained comparisons are not supported inside assertions, " |
| 5474 | "wrap the expression inside parentheses, or decompose it"); |
| 5475 | } |
| 5476 | |
| 5477 | template<typename T> |
| 5478 | auto operator > ( T ) const -> BinaryExpr<LhsT, RhsT const&> const { |
| 5479 | static_assert(always_false<T>::value, |
| 5480 | "chained comparisons are not supported inside assertions, " |
| 5481 | "wrap the expression inside parentheses, or decompose it"); |
| 5482 | } |
| 5483 | |
| 5484 | template<typename T> |
| 5485 | auto operator < ( T ) const -> BinaryExpr<LhsT, RhsT const&> const { |
| 5486 | static_assert(always_false<T>::value, |
| 5487 | "chained comparisons are not supported inside assertions, " |
| 5488 | "wrap the expression inside parentheses, or decompose it"); |
| 5489 | } |
| 5490 | |
| 5491 | template<typename T> |
| 5492 | auto operator >= ( T ) const -> BinaryExpr<LhsT, RhsT const&> const { |
| 5493 | static_assert(always_false<T>::value, |
| 5494 | "chained comparisons are not supported inside assertions, " |
| 5495 | "wrap the expression inside parentheses, or decompose it"); |
| 5496 | } |
| 5497 | |
| 5498 | template<typename T> |
| 5499 | auto operator <= ( T ) const -> BinaryExpr<LhsT, RhsT const&> const { |
| 5500 | static_assert(always_false<T>::value, |
| 5501 | "chained comparisons are not supported inside assertions, " |
| 5502 | "wrap the expression inside parentheses, or decompose it"); |
| 5503 | } |
| 5504 | }; |
| 5505 | |
| 5506 | template<typename LhsT> |
| 5507 | class UnaryExpr : public ITransientExpression { |
| 5508 | LhsT m_lhs; |
| 5509 | |
| 5510 | void streamReconstructedExpression( std::ostream &os ) const override { |
| 5511 | os << Catch::Detail::stringify( m_lhs ); |
| 5512 | } |
| 5513 | |
| 5514 | public: |
| 5515 | explicit UnaryExpr( LhsT lhs ) |
| 5516 | : ITransientExpression{ false, static_cast<bool>(lhs) }, |
| 5517 | m_lhs( lhs ) |
| 5518 | {} |
| 5519 | }; |
| 5520 | |
| 5521 | |
| 5522 | template<typename LhsT> |
| 5523 | class ExprLhs { |
| 5524 | LhsT m_lhs; |
| 5525 | public: |
| 5526 | explicit ExprLhs( LhsT lhs ) : m_lhs( lhs ) {} |
| 5527 | |
| 5528 | #define CATCH_INTERNAL_DEFINE_EXPRESSION_EQUALITY_OPERATOR( id, op ) \ |
| 5529 | template <typename RhsT> \ |
| 5530 | friend auto operator op( ExprLhs&& lhs, RhsT&& rhs ) \ |
| 5531 | ->std::enable_if_t< \ |
| 5532 | Detail::conjunction<Detail::is_##id##_comparable<LhsT, RhsT>, \ |
| 5533 | Detail::negation<std::is_arithmetic< \ |
| 5534 | std::remove_reference_t<RhsT>>>>::value, \ |
| 5535 | BinaryExpr<LhsT, RhsT const&>> { \ |
| 5536 | return { \ |
| 5537 | static_cast<bool>( lhs.m_lhs op rhs ), lhs.m_lhs, #op##_sr, rhs }; \ |
| 5538 | } \ |
| 5539 | template <typename RhsT> \ |
| 5540 | friend auto operator op( ExprLhs&& lhs, RhsT rhs ) \ |
| 5541 | ->std::enable_if_t< \ |
| 5542 | Detail::conjunction<Detail::is_##id##_comparable<LhsT, RhsT>, \ |
| 5543 | std::is_arithmetic<RhsT>>::value, \ |
| 5544 | BinaryExpr<LhsT, RhsT>> { \ |
| 5545 | return { \ |
| 5546 | static_cast<bool>( lhs.m_lhs op rhs ), lhs.m_lhs, #op##_sr, rhs }; \ |
| 5547 | } \ |
| 5548 | template <typename RhsT> \ |
| 5549 | friend auto operator op( ExprLhs&& lhs, RhsT rhs ) \ |
| 5550 | ->std::enable_if_t< \ |
| 5551 | Detail::conjunction< \ |
| 5552 | Detail::negation<Detail::is_##id##_comparable<LhsT, RhsT>>, \ |
| 5553 | Detail::is_eq_0_comparable<LhsT>, \ |
| 5554 | /* We allow long because we want `ptr op NULL` to be accepted */ \ |
| 5555 | Detail::disjunction<std::is_same<RhsT, int>, \ |
| 5556 | std::is_same<RhsT, long>>>::value, \ |
| 5557 | BinaryExpr<LhsT, RhsT>> { \ |
| 5558 | if ( rhs != 0 ) { throw_test_failure_exception(); } \ |
| 5559 | return { \ |
| 5560 | static_cast<bool>( lhs.m_lhs op 0 ), lhs.m_lhs, #op##_sr, rhs }; \ |
| 5561 | } \ |
| 5562 | template <typename RhsT> \ |
| 5563 | friend auto operator op( ExprLhs&& lhs, RhsT rhs ) \ |
| 5564 | ->std::enable_if_t< \ |
| 5565 | Detail::conjunction< \ |
| 5566 | Detail::negation<Detail::is_##id##_comparable<LhsT, RhsT>>, \ |
| 5567 | Detail::is_eq_0_comparable<RhsT>, \ |
| 5568 | /* We allow long because we want `ptr op NULL` to be accepted */ \ |
| 5569 | Detail::disjunction<std::is_same<LhsT, int>, \ |
| 5570 | std::is_same<LhsT, long>>>::value, \ |
| 5571 | BinaryExpr<LhsT, RhsT>> { \ |
| 5572 | if ( lhs.m_lhs != 0 ) { throw_test_failure_exception(); } \ |
| 5573 | return { static_cast<bool>( 0 op rhs ), lhs.m_lhs, #op##_sr, rhs }; \ |
| 5574 | } |
| 5575 | |
| 5576 | CATCH_INTERNAL_DEFINE_EXPRESSION_EQUALITY_OPERATOR( eq, == ) |
| 5577 | CATCH_INTERNAL_DEFINE_EXPRESSION_EQUALITY_OPERATOR( ne, != ) |
| 5578 | |
| 5579 | #undef CATCH_INTERNAL_DEFINE_EXPRESSION_EQUALITY_OPERATOR |
| 5580 | |
| 5581 | #define CATCH_INTERNAL_DEFINE_EXPRESSION_COMPARISON_OPERATOR( id, op ) \ |
| 5582 | template <typename RhsT> \ |
| 5583 | friend auto operator op( ExprLhs&& lhs, RhsT&& rhs ) \ |
| 5584 | ->std::enable_if_t< \ |
| 5585 | Detail::conjunction<Detail::is_##id##_comparable<LhsT, RhsT>, \ |
| 5586 | Detail::negation<std::is_arithmetic< \ |
| 5587 | std::remove_reference_t<RhsT>>>>::value, \ |
| 5588 | BinaryExpr<LhsT, RhsT const&>> { \ |
| 5589 | return { \ |
| 5590 | static_cast<bool>( lhs.m_lhs op rhs ), lhs.m_lhs, #op##_sr, rhs }; \ |
| 5591 | } \ |
| 5592 | template <typename RhsT> \ |
| 5593 | friend auto operator op( ExprLhs&& lhs, RhsT rhs ) \ |
| 5594 | ->std::enable_if_t< \ |
| 5595 | Detail::conjunction<Detail::is_##id##_comparable<LhsT, RhsT>, \ |
| 5596 | std::is_arithmetic<RhsT>>::value, \ |
| 5597 | BinaryExpr<LhsT, RhsT>> { \ |
| 5598 | return { \ |
| 5599 | static_cast<bool>( lhs.m_lhs op rhs ), lhs.m_lhs, #op##_sr, rhs }; \ |
| 5600 | } \ |
| 5601 | template <typename RhsT> \ |
| 5602 | friend auto operator op( ExprLhs&& lhs, RhsT rhs ) \ |
| 5603 | ->std::enable_if_t< \ |
| 5604 | Detail::conjunction< \ |
| 5605 | Detail::negation<Detail::is_##id##_comparable<LhsT, RhsT>>, \ |
| 5606 | Detail::is_##id##_0_comparable<LhsT>, \ |
| 5607 | std::is_same<RhsT, int>>::value, \ |
| 5608 | BinaryExpr<LhsT, RhsT>> { \ |
| 5609 | if ( rhs != 0 ) { throw_test_failure_exception(); } \ |
| 5610 | return { \ |
| 5611 | static_cast<bool>( lhs.m_lhs op 0 ), lhs.m_lhs, #op##_sr, rhs }; \ |
| 5612 | } \ |
| 5613 | template <typename RhsT> \ |
| 5614 | friend auto operator op( ExprLhs&& lhs, RhsT rhs ) \ |
| 5615 | ->std::enable_if_t< \ |
| 5616 | Detail::conjunction< \ |
| 5617 | Detail::negation<Detail::is_##id##_comparable<LhsT, RhsT>>, \ |
| 5618 | Detail::is_##id##_0_comparable<RhsT>, \ |
| 5619 | std::is_same<LhsT, int>>::value, \ |
| 5620 | BinaryExpr<LhsT, RhsT>> { \ |
| 5621 | if ( lhs.m_lhs != 0 ) { throw_test_failure_exception(); } \ |
| 5622 | return { static_cast<bool>( 0 op rhs ), lhs.m_lhs, #op##_sr, rhs }; \ |
| 5623 | } |
| 5624 | |
| 5625 | CATCH_INTERNAL_DEFINE_EXPRESSION_COMPARISON_OPERATOR( lt, < ) |
| 5626 | CATCH_INTERNAL_DEFINE_EXPRESSION_COMPARISON_OPERATOR( le, <= ) |
| 5627 | CATCH_INTERNAL_DEFINE_EXPRESSION_COMPARISON_OPERATOR( gt, > ) |
| 5628 | CATCH_INTERNAL_DEFINE_EXPRESSION_COMPARISON_OPERATOR( ge, >= ) |
| 5629 | |
| 5630 | #undef CATCH_INTERNAL_DEFINE_EXPRESSION_COMPARISON_OPERATOR |
| 5631 | |
| 5632 | |
| 5633 | #define CATCH_INTERNAL_DEFINE_EXPRESSION_OPERATOR( op ) \ |
| 5634 | template <typename RhsT> \ |
| 5635 | friend auto operator op( ExprLhs&& lhs, RhsT&& rhs ) \ |
| 5636 | ->std::enable_if_t< \ |
| 5637 | !std::is_arithmetic<std::remove_reference_t<RhsT>>::value, \ |
| 5638 | BinaryExpr<LhsT, RhsT const&>> { \ |
| 5639 | return { \ |
| 5640 | static_cast<bool>( lhs.m_lhs op rhs ), lhs.m_lhs, #op##_sr, rhs }; \ |
| 5641 | } \ |
| 5642 | template <typename RhsT> \ |
| 5643 | friend auto operator op( ExprLhs&& lhs, RhsT rhs ) \ |
| 5644 | ->std::enable_if_t<std::is_arithmetic<RhsT>::value, \ |
| 5645 | BinaryExpr<LhsT, RhsT>> { \ |
| 5646 | return { \ |
| 5647 | static_cast<bool>( lhs.m_lhs op rhs ), lhs.m_lhs, #op##_sr, rhs }; \ |
| 5648 | } |
| 5649 | |
| 5650 | CATCH_INTERNAL_DEFINE_EXPRESSION_OPERATOR(|) |
| 5651 | CATCH_INTERNAL_DEFINE_EXPRESSION_OPERATOR(&) |
| 5652 | CATCH_INTERNAL_DEFINE_EXPRESSION_OPERATOR(^) |
| 5653 | |
| 5654 | #undef CATCH_INTERNAL_DEFINE_EXPRESSION_OPERATOR |
| 5655 | |
| 5656 | template<typename RhsT> |
| 5657 | friend auto operator && ( ExprLhs &&, RhsT && ) -> BinaryExpr<LhsT, RhsT const&> { |
| 5658 | static_assert(always_false<RhsT>::value, |
| 5659 | "operator&& is not supported inside assertions, " |
| 5660 | "wrap the expression inside parentheses, or decompose it"); |
| 5661 | } |
| 5662 | |
| 5663 | template<typename RhsT> |
| 5664 | friend auto operator || ( ExprLhs &&, RhsT && ) -> BinaryExpr<LhsT, RhsT const&> { |
| 5665 | static_assert(always_false<RhsT>::value, |
| 5666 | "operator|| is not supported inside assertions, " |
| 5667 | "wrap the expression inside parentheses, or decompose it"); |
| 5668 | } |
| 5669 | |
| 5670 | auto makeUnaryExpr() const -> UnaryExpr<LhsT> { |
| 5671 | return UnaryExpr<LhsT>{ m_lhs }; |
| 5672 | } |
| 5673 | }; |
| 5674 | |
| 5675 | struct Decomposer { |
| 5676 | template<typename T, std::enable_if_t<!std::is_arithmetic<std::remove_reference_t<T>>::value, int> = 0> |
| 5677 | friend auto operator <= ( Decomposer &&, T && lhs ) -> ExprLhs<T const&> { |
| 5678 | return ExprLhs<const T&>{ lhs }; |
| 5679 | } |
| 5680 | |
| 5681 | template<typename T, std::enable_if_t<std::is_arithmetic<T>::value, int> = 0> |
| 5682 | friend auto operator <= ( Decomposer &&, T value ) -> ExprLhs<T> { |
| 5683 | return ExprLhs<T>{ value }; |
| 5684 | } |
| 5685 | }; |
| 5686 | |
| 5687 | } // end namespace Catch |
| 5688 | |
| 5689 | #ifdef _MSC_VER |
| 5690 | #pragma warning(pop) |
| 5691 | #endif |
| 5692 | #ifdef __clang__ |
| 5693 | # pragma clang diagnostic pop |
| 5694 | #elif defined __GNUC__ |
| 5695 | # pragma GCC diagnostic pop |
| 5696 | #endif |
| 5697 | |
| 5698 | #endif // CATCH_DECOMPOSER_HPP_INCLUDED |
| 5699 | |
| 5700 | #include <string> |
| 5701 | |
| 5702 | namespace Catch { |
| 5703 | |
| 5704 | struct AssertionReaction { |
| 5705 | bool shouldDebugBreak = false; |
| 5706 | bool shouldThrow = false; |
| 5707 | bool shouldSkip = false; |
| 5708 | }; |
| 5709 | |
| 5710 | class AssertionHandler { |
| 5711 | AssertionInfo m_assertionInfo; |
| 5712 | AssertionReaction m_reaction; |
| 5713 | bool m_completed = false; |
| 5714 | IResultCapture& m_resultCapture; |
| 5715 | |
| 5716 | public: |
| 5717 | AssertionHandler |
| 5718 | ( StringRef macroName, |
| 5719 | SourceLineInfo const& lineInfo, |
| 5720 | StringRef capturedExpression, |
| 5721 | ResultDisposition::Flags resultDisposition ); |
| 5722 | ~AssertionHandler() { |
| 5723 | if ( !m_completed ) { |
| 5724 | m_resultCapture.handleIncomplete( m_assertionInfo ); |
| 5725 | } |
| 5726 | } |
| 5727 | |
| 5728 | |
| 5729 | template<typename T> |
| 5730 | void handleExpr( ExprLhs<T> const& expr ) { |
| 5731 | handleExpr( expr.makeUnaryExpr() ); |
| 5732 | } |
| 5733 | void handleExpr( ITransientExpression const& expr ); |
| 5734 | |
| 5735 | void handleMessage(ResultWas::OfType resultType, StringRef message); |
| 5736 | |
| 5737 | void handleExceptionThrownAsExpected(); |
| 5738 | void handleUnexpectedExceptionNotThrown(); |
| 5739 | void handleExceptionNotThrownAsExpected(); |
| 5740 | void handleThrowingCallSkipped(); |
| 5741 | void handleUnexpectedInflightException(); |
| 5742 | |
| 5743 | void complete(); |
| 5744 | |
| 5745 | // query |
| 5746 | auto allowThrows() const -> bool; |
| 5747 | }; |
| 5748 | |
| 5749 | void handleExceptionMatchExpr( AssertionHandler& handler, std::string const& str ); |
| 5750 | |
| 5751 | } // namespace Catch |
| 5752 | |
| 5753 | #endif // CATCH_ASSERTION_HANDLER_HPP_INCLUDED |
| 5754 | |
| 5755 | |
| 5756 | #ifndef CATCH_PREPROCESSOR_INTERNAL_STRINGIFY_HPP_INCLUDED |
| 5757 | #define CATCH_PREPROCESSOR_INTERNAL_STRINGIFY_HPP_INCLUDED |
| 5758 | |
| 5759 | |
| 5760 | #if !defined(CATCH_CONFIG_DISABLE_STRINGIFICATION) |
| 5761 | #define CATCH_INTERNAL_STRINGIFY(...) #__VA_ARGS__##_catch_sr |
| 5762 | #else |
| 5763 | #define CATCH_INTERNAL_STRINGIFY(...) "Disabled by CATCH_CONFIG_DISABLE_STRINGIFICATION"_catch_sr |
| 5764 | #endif |
| 5765 | |
| 5766 | #endif // CATCH_PREPROCESSOR_INTERNAL_STRINGIFY_HPP_INCLUDED |
| 5767 | |
| 5768 | // We need this suppression to leak, because it took until GCC 10 |
| 5769 | // for the front end to handle local suppression via _Pragma properly |
| 5770 | #if defined(__GNUC__) && !defined(__clang__) && !defined(__ICC) && __GNUC__ <= 9 |
| 5771 | #pragma GCC diagnostic ignored "-Wparentheses" |
| 5772 | #endif |
| 5773 | |
| 5774 | #if !defined(CATCH_CONFIG_DISABLE) |
| 5775 | |
| 5776 | #if defined(CATCH_CONFIG_FAST_COMPILE) || defined(CATCH_CONFIG_DISABLE_EXCEPTIONS) |
| 5777 | |
| 5778 | /////////////////////////////////////////////////////////////////////////////// |
| 5779 | // Another way to speed-up compilation is to omit local try-catch for REQUIRE* |
| 5780 | // macros. |
| 5781 | #define INTERNAL_CATCH_TRY |
| 5782 | #define INTERNAL_CATCH_CATCH( capturer ) |
| 5783 | |
| 5784 | #else // CATCH_CONFIG_FAST_COMPILE |
| 5785 | |
| 5786 | #define INTERNAL_CATCH_TRY try |
| 5787 | #define INTERNAL_CATCH_CATCH( handler ) catch(...) { handler.handleUnexpectedInflightException(); } |
| 5788 | |
| 5789 | #endif |
| 5790 | |
| 5791 | #define INTERNAL_CATCH_REACT( handler ) handler.complete(); |
| 5792 | |
| 5793 | /////////////////////////////////////////////////////////////////////////////// |
| 5794 | #define INTERNAL_CATCH_TEST( macroName, resultDisposition, ... ) \ |
| 5795 | do { /* NOLINT(bugprone-infinite-loop) */ \ |
| 5796 | /* The expression should not be evaluated, but warnings should hopefully be checked */ \ |
| 5797 | CATCH_INTERNAL_IGNORE_BUT_WARN(__VA_ARGS__); \ |
| 5798 | Catch::AssertionHandler catchAssertionHandler( macroName##_catch_sr, CATCH_INTERNAL_LINEINFO, CATCH_INTERNAL_STRINGIFY(__VA_ARGS__), resultDisposition ); \ |
| 5799 | INTERNAL_CATCH_TRY { \ |
| 5800 | CATCH_INTERNAL_START_WARNINGS_SUPPRESSION \ |
| 5801 | CATCH_INTERNAL_SUPPRESS_PARENTHESES_WARNINGS \ |
| 5802 | catchAssertionHandler.handleExpr( Catch::Decomposer() <= __VA_ARGS__ ); \ |
| 5803 | CATCH_INTERNAL_STOP_WARNINGS_SUPPRESSION \ |
| 5804 | } INTERNAL_CATCH_CATCH( catchAssertionHandler ) \ |
| 5805 | INTERNAL_CATCH_REACT( catchAssertionHandler ) \ |
| 5806 | } while( (void)0, (false) && static_cast<const bool&>( !!(__VA_ARGS__) ) ) // the expression here is never evaluated at runtime but it forces the compiler to give it a look |
| 5807 | // The double negation silences MSVC's C4800 warning, the static_cast forces short-circuit evaluation if the type has overloaded &&. |
| 5808 | |
| 5809 | /////////////////////////////////////////////////////////////////////////////// |
| 5810 | #define INTERNAL_CATCH_IF( macroName, resultDisposition, ... ) \ |
| 5811 | INTERNAL_CATCH_TEST( macroName, resultDisposition, __VA_ARGS__ ); \ |
| 5812 | if( Catch::getResultCapture().lastAssertionPassed() ) |
| 5813 | |
| 5814 | /////////////////////////////////////////////////////////////////////////////// |
| 5815 | #define INTERNAL_CATCH_ELSE( macroName, resultDisposition, ... ) \ |
| 5816 | INTERNAL_CATCH_TEST( macroName, resultDisposition, __VA_ARGS__ ); \ |
| 5817 | if( !Catch::getResultCapture().lastAssertionPassed() ) |
| 5818 | |
| 5819 | /////////////////////////////////////////////////////////////////////////////// |
| 5820 | #define INTERNAL_CATCH_NO_THROW( macroName, resultDisposition, ... ) \ |
| 5821 | do { \ |
| 5822 | Catch::AssertionHandler catchAssertionHandler( macroName##_catch_sr, CATCH_INTERNAL_LINEINFO, CATCH_INTERNAL_STRINGIFY(__VA_ARGS__), resultDisposition ); \ |
| 5823 | try { \ |
| 5824 | CATCH_INTERNAL_START_WARNINGS_SUPPRESSION \ |
| 5825 | CATCH_INTERNAL_SUPPRESS_USELESS_CAST_WARNINGS \ |
| 5826 | static_cast<void>(__VA_ARGS__); \ |
| 5827 | CATCH_INTERNAL_STOP_WARNINGS_SUPPRESSION \ |
| 5828 | catchAssertionHandler.handleExceptionNotThrownAsExpected(); \ |
| 5829 | } \ |
| 5830 | catch( ... ) { \ |
| 5831 | catchAssertionHandler.handleUnexpectedInflightException(); \ |
| 5832 | } \ |
| 5833 | INTERNAL_CATCH_REACT( catchAssertionHandler ) \ |
| 5834 | } while( false ) |
| 5835 | |
| 5836 | /////////////////////////////////////////////////////////////////////////////// |
| 5837 | #define INTERNAL_CATCH_THROWS( macroName, resultDisposition, ... ) \ |
| 5838 | do { \ |
| 5839 | Catch::AssertionHandler catchAssertionHandler( macroName##_catch_sr, CATCH_INTERNAL_LINEINFO, CATCH_INTERNAL_STRINGIFY(__VA_ARGS__), resultDisposition); \ |
| 5840 | if( catchAssertionHandler.allowThrows() ) \ |
| 5841 | try { \ |
| 5842 | CATCH_INTERNAL_START_WARNINGS_SUPPRESSION \ |
| 5843 | CATCH_INTERNAL_SUPPRESS_UNUSED_RESULT \ |
| 5844 | CATCH_INTERNAL_SUPPRESS_USELESS_CAST_WARNINGS \ |
| 5845 | static_cast<void>(__VA_ARGS__); \ |
| 5846 | CATCH_INTERNAL_STOP_WARNINGS_SUPPRESSION \ |
| 5847 | catchAssertionHandler.handleUnexpectedExceptionNotThrown(); \ |
| 5848 | } \ |
| 5849 | catch( ... ) { \ |
| 5850 | catchAssertionHandler.handleExceptionThrownAsExpected(); \ |
| 5851 | } \ |
| 5852 | else \ |
| 5853 | catchAssertionHandler.handleThrowingCallSkipped(); \ |
| 5854 | INTERNAL_CATCH_REACT( catchAssertionHandler ) \ |
| 5855 | } while( false ) |
| 5856 | |
| 5857 | /////////////////////////////////////////////////////////////////////////////// |
| 5858 | #define INTERNAL_CATCH_THROWS_AS( macroName, exceptionType, resultDisposition, expr ) \ |
| 5859 | do { \ |
| 5860 | Catch::AssertionHandler catchAssertionHandler( macroName##_catch_sr, CATCH_INTERNAL_LINEINFO, CATCH_INTERNAL_STRINGIFY(expr) ", " CATCH_INTERNAL_STRINGIFY(exceptionType), resultDisposition ); \ |
| 5861 | if( catchAssertionHandler.allowThrows() ) \ |
| 5862 | try { \ |
| 5863 | CATCH_INTERNAL_START_WARNINGS_SUPPRESSION \ |
| 5864 | CATCH_INTERNAL_SUPPRESS_UNUSED_RESULT \ |
| 5865 | CATCH_INTERNAL_SUPPRESS_USELESS_CAST_WARNINGS \ |
| 5866 | static_cast<void>(expr); \ |
| 5867 | CATCH_INTERNAL_STOP_WARNINGS_SUPPRESSION \ |
| 5868 | catchAssertionHandler.handleUnexpectedExceptionNotThrown(); \ |
| 5869 | } \ |
| 5870 | catch( exceptionType const& ) { \ |
| 5871 | catchAssertionHandler.handleExceptionThrownAsExpected(); \ |
| 5872 | } \ |
| 5873 | catch( ... ) { \ |
| 5874 | catchAssertionHandler.handleUnexpectedInflightException(); \ |
| 5875 | } \ |
| 5876 | else \ |
| 5877 | catchAssertionHandler.handleThrowingCallSkipped(); \ |
| 5878 | INTERNAL_CATCH_REACT( catchAssertionHandler ) \ |
| 5879 | } while( false ) |
| 5880 | |
| 5881 | |
| 5882 | |
| 5883 | /////////////////////////////////////////////////////////////////////////////// |
| 5884 | // Although this is matcher-based, it can be used with just a string |
| 5885 | #define INTERNAL_CATCH_THROWS_STR_MATCHES( macroName, resultDisposition, matcher, ... ) \ |
| 5886 | do { \ |
| 5887 | Catch::AssertionHandler catchAssertionHandler( macroName##_catch_sr, CATCH_INTERNAL_LINEINFO, CATCH_INTERNAL_STRINGIFY(__VA_ARGS__) ", " CATCH_INTERNAL_STRINGIFY(matcher), resultDisposition ); \ |
| 5888 | if( catchAssertionHandler.allowThrows() ) \ |
| 5889 | try { \ |
| 5890 | CATCH_INTERNAL_START_WARNINGS_SUPPRESSION \ |
| 5891 | CATCH_INTERNAL_SUPPRESS_UNUSED_RESULT \ |
| 5892 | CATCH_INTERNAL_SUPPRESS_USELESS_CAST_WARNINGS \ |
| 5893 | static_cast<void>(__VA_ARGS__); \ |
| 5894 | CATCH_INTERNAL_STOP_WARNINGS_SUPPRESSION \ |
| 5895 | catchAssertionHandler.handleUnexpectedExceptionNotThrown(); \ |
| 5896 | } \ |
| 5897 | catch( ... ) { \ |
| 5898 | Catch::handleExceptionMatchExpr( catchAssertionHandler, matcher ); \ |
| 5899 | } \ |
| 5900 | else \ |
| 5901 | catchAssertionHandler.handleThrowingCallSkipped(); \ |
| 5902 | INTERNAL_CATCH_REACT( catchAssertionHandler ) \ |
| 5903 | } while( false ) |
| 5904 | |
| 5905 | #endif // CATCH_CONFIG_DISABLE |
| 5906 | |
| 5907 | #endif // CATCH_TEST_MACRO_IMPL_HPP_INCLUDED |
| 5908 | |
| 5909 | |
| 5910 | #ifndef CATCH_SECTION_HPP_INCLUDED |
| 5911 | #define CATCH_SECTION_HPP_INCLUDED |
| 5912 | |
| 5913 | |
| 5914 | |
| 5915 | |
| 5916 | /** \file |
| 5917 | * Wrapper for the STATIC_ANALYSIS_SUPPORT configuration option |
| 5918 | * |
| 5919 | * Some of Catch2's macros can be defined differently to work better with |
| 5920 | * static analysis tools, like clang-tidy or coverity. |
| 5921 | * Currently the main use case is to show that `SECTION`s are executed |
| 5922 | * exclusively, and not all in one run of a `TEST_CASE`. |
| 5923 | */ |
| 5924 | |
| 5925 | #ifndef CATCH_CONFIG_STATIC_ANALYSIS_SUPPORT_HPP_INCLUDED |
| 5926 | #define CATCH_CONFIG_STATIC_ANALYSIS_SUPPORT_HPP_INCLUDED |
| 5927 | |
| 5928 | |
| 5929 | #if defined(__clang_analyzer__) || defined(__COVERITY__) |
| 5930 | #define CATCH_INTERNAL_CONFIG_STATIC_ANALYSIS_SUPPORT |
| 5931 | #endif |
| 5932 | |
| 5933 | #if defined( CATCH_INTERNAL_CONFIG_STATIC_ANALYSIS_SUPPORT ) && \ |
| 5934 | !defined( CATCH_CONFIG_NO_EXPERIMENTAL_STATIC_ANALYSIS_SUPPORT ) && \ |
| 5935 | !defined( CATCH_CONFIG_EXPERIMENTAL_STATIC_ANALYSIS_SUPPORT ) |
| 5936 | # define CATCH_CONFIG_EXPERIMENTAL_STATIC_ANALYSIS_SUPPORT |
| 5937 | #endif |
| 5938 | |
| 5939 | |
| 5940 | #endif // CATCH_CONFIG_STATIC_ANALYSIS_SUPPORT_HPP_INCLUDED |
| 5941 | |
| 5942 | |
| 5943 | #ifndef CATCH_TIMER_HPP_INCLUDED |
| 5944 | #define CATCH_TIMER_HPP_INCLUDED |
| 5945 | |
| 5946 | #include <cstdint> |
| 5947 | |
| 5948 | namespace Catch { |
| 5949 | |
| 5950 | class Timer { |
| 5951 | uint64_t m_nanoseconds = 0; |
| 5952 | public: |
| 5953 | void start(); |
| 5954 | auto getElapsedNanoseconds() const -> uint64_t; |
| 5955 | auto getElapsedMicroseconds() const -> uint64_t; |
| 5956 | auto getElapsedMilliseconds() const -> unsigned int; |
| 5957 | auto getElapsedSeconds() const -> double; |
| 5958 | }; |
| 5959 | |
| 5960 | } // namespace Catch |
| 5961 | |
| 5962 | #endif // CATCH_TIMER_HPP_INCLUDED |
| 5963 | |
| 5964 | namespace Catch { |
| 5965 | |
| 5966 | class Section : Detail::NonCopyable { |
| 5967 | public: |
| 5968 | Section( SectionInfo&& info ); |
| 5969 | Section( SourceLineInfo const& _lineInfo, |
| 5970 | StringRef _name, |
| 5971 | const char* const = nullptr ); |
| 5972 | ~Section(); |
| 5973 | |
| 5974 | // This indicates whether the section should be executed or not |
| 5975 | explicit operator bool() const; |
| 5976 | |
| 5977 | private: |
| 5978 | SectionInfo m_info; |
| 5979 | |
| 5980 | Counts m_assertions; |
| 5981 | bool m_sectionIncluded; |
| 5982 | Timer m_timer; |
| 5983 | }; |
| 5984 | |
| 5985 | } // end namespace Catch |
| 5986 | |
| 5987 | #if !defined(CATCH_CONFIG_EXPERIMENTAL_STATIC_ANALYSIS_SUPPORT) |
| 5988 | # define INTERNAL_CATCH_SECTION( ... ) \ |
| 5989 | CATCH_INTERNAL_START_WARNINGS_SUPPRESSION \ |
| 5990 | CATCH_INTERNAL_SUPPRESS_UNUSED_VARIABLE_WARNINGS \ |
| 5991 | if ( Catch::Section const& INTERNAL_CATCH_UNIQUE_NAME( \ |
| 5992 | catch_internal_Section ) = \ |
| 5993 | Catch::Section( CATCH_INTERNAL_LINEINFO, __VA_ARGS__ ) ) \ |
| 5994 | CATCH_INTERNAL_STOP_WARNINGS_SUPPRESSION |
| 5995 | |
| 5996 | # define INTERNAL_CATCH_DYNAMIC_SECTION( ... ) \ |
| 5997 | CATCH_INTERNAL_START_WARNINGS_SUPPRESSION \ |
| 5998 | CATCH_INTERNAL_SUPPRESS_UNUSED_VARIABLE_WARNINGS \ |
| 5999 | if ( Catch::Section const& INTERNAL_CATCH_UNIQUE_NAME( \ |
| 6000 | catch_internal_Section ) = \ |
| 6001 | Catch::SectionInfo( \ |
| 6002 | CATCH_INTERNAL_LINEINFO, \ |
| 6003 | ( Catch::ReusableStringStream() << __VA_ARGS__ ) \ |
| 6004 | .str() ) ) \ |
| 6005 | CATCH_INTERNAL_STOP_WARNINGS_SUPPRESSION |
| 6006 | |
| 6007 | #else |
| 6008 | |
| 6009 | // These section definitions imply that at most one section at one level |
| 6010 | // will be intered (because only one section's __LINE__ can be equal to |
| 6011 | // the dummy `catchInternalSectionHint` variable from `TEST_CASE`). |
| 6012 | |
| 6013 | namespace Catch { |
| 6014 | namespace Detail { |
| 6015 | // Intentionally without linkage, as it should only be used as a dummy |
| 6016 | // symbol for static analysis. |
| 6017 | int GetNewSectionHint(); |
| 6018 | } // namespace Detail |
| 6019 | } // namespace Catch |
| 6020 | |
| 6021 | |
| 6022 | # define INTERNAL_CATCH_SECTION( ... ) \ |
| 6023 | CATCH_INTERNAL_START_WARNINGS_SUPPRESSION \ |
| 6024 | CATCH_INTERNAL_SUPPRESS_UNUSED_VARIABLE_WARNINGS \ |
| 6025 | CATCH_INTERNAL_SUPPRESS_SHADOW_WARNINGS \ |
| 6026 | if ( [[maybe_unused]] int catchInternalPreviousSectionHint = \ |
| 6027 | catchInternalSectionHint, \ |
| 6028 | catchInternalSectionHint = Catch::Detail::GetNewSectionHint(); \ |
| 6029 | catchInternalPreviousSectionHint == __LINE__ ) \ |
| 6030 | CATCH_INTERNAL_STOP_WARNINGS_SUPPRESSION |
| 6031 | |
| 6032 | # define INTERNAL_CATCH_DYNAMIC_SECTION( ... ) \ |
| 6033 | CATCH_INTERNAL_START_WARNINGS_SUPPRESSION \ |
| 6034 | CATCH_INTERNAL_SUPPRESS_UNUSED_VARIABLE_WARNINGS \ |
| 6035 | CATCH_INTERNAL_SUPPRESS_SHADOW_WARNINGS \ |
| 6036 | if ( [[maybe_unused]] int catchInternalPreviousSectionHint = \ |
| 6037 | catchInternalSectionHint, \ |
| 6038 | catchInternalSectionHint = Catch::Detail::GetNewSectionHint(); \ |
| 6039 | catchInternalPreviousSectionHint == __LINE__ ) \ |
| 6040 | CATCH_INTERNAL_STOP_WARNINGS_SUPPRESSION |
| 6041 | |
| 6042 | #endif |
| 6043 | |
| 6044 | |
| 6045 | #endif // CATCH_SECTION_HPP_INCLUDED |
| 6046 | |
| 6047 | |
| 6048 | #ifndef CATCH_TEST_REGISTRY_HPP_INCLUDED |
| 6049 | #define CATCH_TEST_REGISTRY_HPP_INCLUDED |
| 6050 | |
| 6051 | |
| 6052 | |
| 6053 | #ifndef CATCH_INTERFACES_TEST_INVOKER_HPP_INCLUDED |
| 6054 | #define CATCH_INTERFACES_TEST_INVOKER_HPP_INCLUDED |
| 6055 | |
| 6056 | namespace Catch { |
| 6057 | |
| 6058 | class ITestInvoker { |
| 6059 | public: |
| 6060 | virtual void invoke() const = 0; |
| 6061 | virtual ~ITestInvoker(); // = default |
| 6062 | }; |
| 6063 | |
| 6064 | } // namespace Catch |
| 6065 | |
| 6066 | #endif // CATCH_INTERFACES_TEST_INVOKER_HPP_INCLUDED |
| 6067 | |
| 6068 | |
| 6069 | #ifndef CATCH_PREPROCESSOR_REMOVE_PARENS_HPP_INCLUDED |
| 6070 | #define CATCH_PREPROCESSOR_REMOVE_PARENS_HPP_INCLUDED |
| 6071 | |
| 6072 | #define INTERNAL_CATCH_EXPAND1( param ) INTERNAL_CATCH_EXPAND2( param ) |
| 6073 | #define INTERNAL_CATCH_EXPAND2( ... ) INTERNAL_CATCH_NO##__VA_ARGS__ |
| 6074 | #define INTERNAL_CATCH_DEF( ... ) INTERNAL_CATCH_DEF __VA_ARGS__ |
| 6075 | #define INTERNAL_CATCH_NOINTERNAL_CATCH_DEF |
| 6076 | |
| 6077 | #define INTERNAL_CATCH_REMOVE_PARENS( ... ) \ |
| 6078 | INTERNAL_CATCH_EXPAND1( INTERNAL_CATCH_DEF __VA_ARGS__ ) |
| 6079 | |
| 6080 | #endif // CATCH_PREPROCESSOR_REMOVE_PARENS_HPP_INCLUDED |
| 6081 | |
| 6082 | // GCC 5 and older do not properly handle disabling unused-variable warning |
| 6083 | // with a _Pragma. This means that we have to leak the suppression to the |
| 6084 | // user code as well :-( |
| 6085 | #if defined(__GNUC__) && !defined(__clang__) && __GNUC__ <= 5 |
| 6086 | #pragma GCC diagnostic ignored "-Wunused-variable" |
| 6087 | #endif |
| 6088 | |
| 6089 | |
| 6090 | |
| 6091 | namespace Catch { |
| 6092 | |
| 6093 | template<typename C> |
| 6094 | class TestInvokerAsMethod : public ITestInvoker { |
| 6095 | void (C::*m_testAsMethod)(); |
| 6096 | public: |
| 6097 | TestInvokerAsMethod( void (C::*testAsMethod)() ) noexcept : m_testAsMethod( testAsMethod ) {} |
| 6098 | |
| 6099 | void invoke() const override { |
| 6100 | C obj; |
| 6101 | (obj.*m_testAsMethod)(); |
| 6102 | } |
| 6103 | }; |
| 6104 | |
| 6105 | Detail::unique_ptr<ITestInvoker> makeTestInvoker( void(*testAsFunction)() ); |
| 6106 | |
| 6107 | template<typename C> |
| 6108 | Detail::unique_ptr<ITestInvoker> makeTestInvoker( void (C::*testAsMethod)() ) { |
| 6109 | return Detail::make_unique<TestInvokerAsMethod<C>>( testAsMethod ); |
| 6110 | } |
| 6111 | |
| 6112 | struct NameAndTags { |
| 6113 | constexpr NameAndTags( StringRef name_ = StringRef(), |
| 6114 | StringRef tags_ = StringRef() ) noexcept: |
| 6115 | name( name_ ), tags( tags_ ) {} |
| 6116 | StringRef name; |
| 6117 | StringRef tags; |
| 6118 | }; |
| 6119 | |
| 6120 | struct AutoReg : Detail::NonCopyable { |
| 6121 | AutoReg( Detail::unique_ptr<ITestInvoker> invoker, SourceLineInfo const& lineInfo, StringRef classOrMethod, NameAndTags const& nameAndTags ) noexcept; |
| 6122 | }; |
| 6123 | |
| 6124 | } // end namespace Catch |
| 6125 | |
| 6126 | #if defined(CATCH_CONFIG_DISABLE) |
| 6127 | #define INTERNAL_CATCH_TESTCASE_NO_REGISTRATION( TestName, ... ) \ |
| 6128 | static inline void TestName() |
| 6129 | #define INTERNAL_CATCH_TESTCASE_METHOD_NO_REGISTRATION( TestName, ClassName, ... ) \ |
| 6130 | namespace{ \ |
| 6131 | struct TestName : INTERNAL_CATCH_REMOVE_PARENS(ClassName) { \ |
| 6132 | void test(); \ |
| 6133 | }; \ |
| 6134 | } \ |
| 6135 | void TestName::test() |
| 6136 | #endif |
| 6137 | |
| 6138 | |
| 6139 | #if !defined(CATCH_CONFIG_EXPERIMENTAL_STATIC_ANALYSIS_SUPPORT) |
| 6140 | |
| 6141 | /////////////////////////////////////////////////////////////////////////////// |
| 6142 | #define INTERNAL_CATCH_TESTCASE2( TestName, ... ) \ |
| 6143 | static void TestName(); \ |
| 6144 | CATCH_INTERNAL_START_WARNINGS_SUPPRESSION \ |
| 6145 | CATCH_INTERNAL_SUPPRESS_GLOBALS_WARNINGS \ |
| 6146 | CATCH_INTERNAL_SUPPRESS_UNUSED_VARIABLE_WARNINGS \ |
| 6147 | namespace{ const Catch::AutoReg INTERNAL_CATCH_UNIQUE_NAME( autoRegistrar )( Catch::makeTestInvoker( &TestName ), CATCH_INTERNAL_LINEINFO, Catch::StringRef(), Catch::NameAndTags{ __VA_ARGS__ } ); } /* NOLINT */ \ |
| 6148 | CATCH_INTERNAL_STOP_WARNINGS_SUPPRESSION \ |
| 6149 | static void TestName() |
| 6150 | #define INTERNAL_CATCH_TESTCASE( ... ) \ |
| 6151 | INTERNAL_CATCH_TESTCASE2( INTERNAL_CATCH_UNIQUE_NAME( CATCH2_INTERNAL_TEST_ ), __VA_ARGS__ ) |
| 6152 | |
| 6153 | #else // ^^ !CATCH_CONFIG_EXPERIMENTAL_STATIC_ANALYSIS_SUPPORT | vv CATCH_CONFIG_EXPERIMENTAL_STATIC_ANALYSIS_SUPPORT |
| 6154 | |
| 6155 | |
| 6156 | // Dummy registrator for the dumy test case macros |
| 6157 | namespace Catch { |
| 6158 | namespace Detail { |
| 6159 | struct DummyUse { |
| 6160 | DummyUse( void ( * )( int ) ); |
| 6161 | }; |
| 6162 | } // namespace Detail |
| 6163 | } // namespace Catch |
| 6164 | |
| 6165 | // Note that both the presence of the argument and its exact name are |
| 6166 | // necessary for the section support. |
| 6167 | |
| 6168 | // We provide a shadowed variable so that a `SECTION` inside non-`TEST_CASE` |
| 6169 | // tests can compile. The redefined `TEST_CASE` shadows this with param. |
| 6170 | static int catchInternalSectionHint = 0; |
| 6171 | |
| 6172 | # define INTERNAL_CATCH_TESTCASE2( fname ) \ |
| 6173 | static void fname( int ); \ |
| 6174 | CATCH_INTERNAL_START_WARNINGS_SUPPRESSION \ |
| 6175 | CATCH_INTERNAL_SUPPRESS_GLOBALS_WARNINGS \ |
| 6176 | CATCH_INTERNAL_SUPPRESS_UNUSED_VARIABLE_WARNINGS \ |
| 6177 | static const Catch::Detail::DummyUse INTERNAL_CATCH_UNIQUE_NAME( \ |
| 6178 | dummyUser )( &fname ); \ |
| 6179 | CATCH_INTERNAL_SUPPRESS_SHADOW_WARNINGS \ |
| 6180 | static void fname( [[maybe_unused]] int catchInternalSectionHint ) \ |
| 6181 | CATCH_INTERNAL_STOP_WARNINGS_SUPPRESSION |
| 6182 | # define INTERNAL_CATCH_TESTCASE( ... ) \ |
| 6183 | INTERNAL_CATCH_TESTCASE2( INTERNAL_CATCH_UNIQUE_NAME( dummyFunction ) ) |
| 6184 | |
| 6185 | |
| 6186 | #endif // CATCH_CONFIG_EXPERIMENTAL_STATIC_ANALYSIS_SUPPORT |
| 6187 | |
| 6188 | /////////////////////////////////////////////////////////////////////////////// |
| 6189 | #define INTERNAL_CATCH_TEST_CASE_METHOD2( TestName, ClassName, ... )\ |
| 6190 | CATCH_INTERNAL_START_WARNINGS_SUPPRESSION \ |
| 6191 | CATCH_INTERNAL_SUPPRESS_GLOBALS_WARNINGS \ |
| 6192 | CATCH_INTERNAL_SUPPRESS_UNUSED_VARIABLE_WARNINGS \ |
| 6193 | namespace{ \ |
| 6194 | struct TestName : INTERNAL_CATCH_REMOVE_PARENS(ClassName) { \ |
| 6195 | void test(); \ |
| 6196 | }; \ |
| 6197 | const Catch::AutoReg INTERNAL_CATCH_UNIQUE_NAME( autoRegistrar )( \ |
| 6198 | Catch::makeTestInvoker( &TestName::test ), \ |
| 6199 | CATCH_INTERNAL_LINEINFO, \ |
| 6200 | #ClassName##_catch_sr, \ |
| 6201 | Catch::NameAndTags{ __VA_ARGS__ } ); /* NOLINT */ \ |
| 6202 | } \ |
| 6203 | CATCH_INTERNAL_STOP_WARNINGS_SUPPRESSION \ |
| 6204 | void TestName::test() |
| 6205 | #define INTERNAL_CATCH_TEST_CASE_METHOD( ClassName, ... ) \ |
| 6206 | INTERNAL_CATCH_TEST_CASE_METHOD2( INTERNAL_CATCH_UNIQUE_NAME( CATCH2_INTERNAL_TEST_ ), ClassName, __VA_ARGS__ ) |
| 6207 | |
| 6208 | |
| 6209 | /////////////////////////////////////////////////////////////////////////////// |
| 6210 | #define INTERNAL_CATCH_METHOD_AS_TEST_CASE( QualifiedMethod, ... ) \ |
| 6211 | CATCH_INTERNAL_START_WARNINGS_SUPPRESSION \ |
| 6212 | CATCH_INTERNAL_SUPPRESS_GLOBALS_WARNINGS \ |
| 6213 | CATCH_INTERNAL_SUPPRESS_UNUSED_VARIABLE_WARNINGS \ |
| 6214 | namespace { \ |
| 6215 | const Catch::AutoReg INTERNAL_CATCH_UNIQUE_NAME( autoRegistrar )( \ |
| 6216 | Catch::makeTestInvoker( &QualifiedMethod ), \ |
| 6217 | CATCH_INTERNAL_LINEINFO, \ |
| 6218 | "&" #QualifiedMethod##_catch_sr, \ |
| 6219 | Catch::NameAndTags{ __VA_ARGS__ } ); \ |
| 6220 | } /* NOLINT */ \ |
| 6221 | CATCH_INTERNAL_STOP_WARNINGS_SUPPRESSION |
| 6222 | |
| 6223 | |
| 6224 | /////////////////////////////////////////////////////////////////////////////// |
| 6225 | #define INTERNAL_CATCH_REGISTER_TESTCASE( Function, ... ) \ |
| 6226 | do { \ |
| 6227 | CATCH_INTERNAL_START_WARNINGS_SUPPRESSION \ |
| 6228 | CATCH_INTERNAL_SUPPRESS_GLOBALS_WARNINGS \ |
| 6229 | CATCH_INTERNAL_SUPPRESS_UNUSED_VARIABLE_WARNINGS \ |
| 6230 | Catch::AutoReg INTERNAL_CATCH_UNIQUE_NAME( autoRegistrar )( Catch::makeTestInvoker( Function ), CATCH_INTERNAL_LINEINFO, Catch::StringRef(), Catch::NameAndTags{ __VA_ARGS__ } ); /* NOLINT */ \ |
| 6231 | CATCH_INTERNAL_STOP_WARNINGS_SUPPRESSION \ |
| 6232 | } while(false) |
| 6233 | |
| 6234 | |
| 6235 | #endif // CATCH_TEST_REGISTRY_HPP_INCLUDED |
| 6236 | |
| 6237 | |
| 6238 | // All of our user-facing macros support configuration toggle, that |
| 6239 | // forces them to be defined prefixed with CATCH_. We also like to |
| 6240 | // support another toggle that can minimize (disable) their implementation. |
| 6241 | // Given this, we have 4 different configuration options below |
| 6242 | |
| 6243 | #if defined(CATCH_CONFIG_PREFIX_ALL) && !defined(CATCH_CONFIG_DISABLE) |
| 6244 | |
| 6245 | #define CATCH_REQUIRE( ... ) INTERNAL_CATCH_TEST( "CATCH_REQUIRE", Catch::ResultDisposition::Normal, __VA_ARGS__ ) |
| 6246 | #define CATCH_REQUIRE_FALSE( ... ) INTERNAL_CATCH_TEST( "CATCH_REQUIRE_FALSE", Catch::ResultDisposition::Normal | Catch::ResultDisposition::FalseTest, __VA_ARGS__ ) |
| 6247 | |
| 6248 | #define CATCH_REQUIRE_THROWS( ... ) INTERNAL_CATCH_THROWS( "CATCH_REQUIRE_THROWS", Catch::ResultDisposition::Normal, __VA_ARGS__ ) |
| 6249 | #define CATCH_REQUIRE_THROWS_AS( expr, exceptionType ) INTERNAL_CATCH_THROWS_AS( "CATCH_REQUIRE_THROWS_AS", exceptionType, Catch::ResultDisposition::Normal, expr ) |
| 6250 | #define CATCH_REQUIRE_NOTHROW( ... ) INTERNAL_CATCH_NO_THROW( "CATCH_REQUIRE_NOTHROW", Catch::ResultDisposition::Normal, __VA_ARGS__ ) |
| 6251 | |
| 6252 | #define CATCH_CHECK( ... ) INTERNAL_CATCH_TEST( "CATCH_CHECK", Catch::ResultDisposition::ContinueOnFailure, __VA_ARGS__ ) |
| 6253 | #define CATCH_CHECK_FALSE( ... ) INTERNAL_CATCH_TEST( "CATCH_CHECK_FALSE", Catch::ResultDisposition::ContinueOnFailure | Catch::ResultDisposition::FalseTest, __VA_ARGS__ ) |
| 6254 | #define CATCH_CHECKED_IF( ... ) INTERNAL_CATCH_IF( "CATCH_CHECKED_IF", Catch::ResultDisposition::ContinueOnFailure | Catch::ResultDisposition::SuppressFail, __VA_ARGS__ ) |
| 6255 | #define CATCH_CHECKED_ELSE( ... ) INTERNAL_CATCH_ELSE( "CATCH_CHECKED_ELSE", Catch::ResultDisposition::ContinueOnFailure | Catch::ResultDisposition::SuppressFail, __VA_ARGS__ ) |
| 6256 | #define CATCH_CHECK_NOFAIL( ... ) INTERNAL_CATCH_TEST( "CATCH_CHECK_NOFAIL", Catch::ResultDisposition::ContinueOnFailure | Catch::ResultDisposition::SuppressFail, __VA_ARGS__ ) |
| 6257 | |
| 6258 | #define CATCH_CHECK_THROWS( ... ) INTERNAL_CATCH_THROWS( "CATCH_CHECK_THROWS", Catch::ResultDisposition::ContinueOnFailure, __VA_ARGS__ ) |
| 6259 | #define CATCH_CHECK_THROWS_AS( expr, exceptionType ) INTERNAL_CATCH_THROWS_AS( "CATCH_CHECK_THROWS_AS", exceptionType, Catch::ResultDisposition::ContinueOnFailure, expr ) |
| 6260 | #define CATCH_CHECK_NOTHROW( ... ) INTERNAL_CATCH_NO_THROW( "CATCH_CHECK_NOTHROW", Catch::ResultDisposition::ContinueOnFailure, __VA_ARGS__ ) |
| 6261 | |
| 6262 | #define CATCH_TEST_CASE( ... ) INTERNAL_CATCH_TESTCASE( __VA_ARGS__ ) |
| 6263 | #define CATCH_TEST_CASE_METHOD( className, ... ) INTERNAL_CATCH_TEST_CASE_METHOD( className, __VA_ARGS__ ) |
| 6264 | #define CATCH_METHOD_AS_TEST_CASE( method, ... ) INTERNAL_CATCH_METHOD_AS_TEST_CASE( method, __VA_ARGS__ ) |
| 6265 | #define CATCH_REGISTER_TEST_CASE( Function, ... ) INTERNAL_CATCH_REGISTER_TESTCASE( Function, __VA_ARGS__ ) |
| 6266 | #define CATCH_SECTION( ... ) INTERNAL_CATCH_SECTION( __VA_ARGS__ ) |
| 6267 | #define CATCH_DYNAMIC_SECTION( ... ) INTERNAL_CATCH_DYNAMIC_SECTION( __VA_ARGS__ ) |
| 6268 | #define CATCH_FAIL( ... ) INTERNAL_CATCH_MSG( "CATCH_FAIL", Catch::ResultWas::ExplicitFailure, Catch::ResultDisposition::Normal, __VA_ARGS__ ) |
| 6269 | #define CATCH_FAIL_CHECK( ... ) INTERNAL_CATCH_MSG( "CATCH_FAIL_CHECK", Catch::ResultWas::ExplicitFailure, Catch::ResultDisposition::ContinueOnFailure, __VA_ARGS__ ) |
| 6270 | #define CATCH_SUCCEED( ... ) INTERNAL_CATCH_MSG( "CATCH_SUCCEED", Catch::ResultWas::Ok, Catch::ResultDisposition::ContinueOnFailure, __VA_ARGS__ ) |
| 6271 | #define CATCH_SKIP( ... ) INTERNAL_CATCH_MSG( "SKIP", Catch::ResultWas::ExplicitSkip, Catch::ResultDisposition::Normal, __VA_ARGS__ ) |
| 6272 | |
| 6273 | |
| 6274 | #if !defined(CATCH_CONFIG_RUNTIME_STATIC_REQUIRE) |
| 6275 | #define CATCH_STATIC_REQUIRE( ... ) static_assert( __VA_ARGS__ , #__VA_ARGS__ ); CATCH_SUCCEED( #__VA_ARGS__ ) |
| 6276 | #define CATCH_STATIC_REQUIRE_FALSE( ... ) static_assert( !(__VA_ARGS__), "!(" #__VA_ARGS__ ")" ); CATCH_SUCCEED( #__VA_ARGS__ ) |
| 6277 | #define CATCH_STATIC_CHECK( ... ) static_assert( __VA_ARGS__ , #__VA_ARGS__ ); CATCH_SUCCEED( #__VA_ARGS__ ) |
| 6278 | #define CATCH_STATIC_CHECK_FALSE( ... ) static_assert( !(__VA_ARGS__), "!(" #__VA_ARGS__ ")" ); CATCH_SUCCEED( #__VA_ARGS__ ) |
| 6279 | #else |
| 6280 | #define CATCH_STATIC_REQUIRE( ... ) CATCH_REQUIRE( __VA_ARGS__ ) |
| 6281 | #define CATCH_STATIC_REQUIRE_FALSE( ... ) CATCH_REQUIRE_FALSE( __VA_ARGS__ ) |
| 6282 | #define CATCH_STATIC_CHECK( ... ) CATCH_CHECK( __VA_ARGS__ ) |
| 6283 | #define CATCH_STATIC_CHECK_FALSE( ... ) CATCH_CHECK_FALSE( __VA_ARGS__ ) |
| 6284 | #endif |
| 6285 | |
| 6286 | |
| 6287 | // "BDD-style" convenience wrappers |
| 6288 | #define CATCH_SCENARIO( ... ) CATCH_TEST_CASE( "Scenario: " __VA_ARGS__ ) |
| 6289 | #define CATCH_SCENARIO_METHOD( className, ... ) INTERNAL_CATCH_TEST_CASE_METHOD( className, "Scenario: " __VA_ARGS__ ) |
| 6290 | #define CATCH_GIVEN( desc ) INTERNAL_CATCH_DYNAMIC_SECTION( " Given: " << desc ) |
| 6291 | #define CATCH_AND_GIVEN( desc ) INTERNAL_CATCH_DYNAMIC_SECTION( "And given: " << desc ) |
| 6292 | #define CATCH_WHEN( desc ) INTERNAL_CATCH_DYNAMIC_SECTION( " When: " << desc ) |
| 6293 | #define CATCH_AND_WHEN( desc ) INTERNAL_CATCH_DYNAMIC_SECTION( " And when: " << desc ) |
| 6294 | #define CATCH_THEN( desc ) INTERNAL_CATCH_DYNAMIC_SECTION( " Then: " << desc ) |
| 6295 | #define CATCH_AND_THEN( desc ) INTERNAL_CATCH_DYNAMIC_SECTION( " And: " << desc ) |
| 6296 | |
| 6297 | #elif defined(CATCH_CONFIG_PREFIX_ALL) && defined(CATCH_CONFIG_DISABLE) // ^^ prefixed, implemented | vv prefixed, disabled |
| 6298 | |
| 6299 | #define CATCH_REQUIRE( ... ) (void)(0) |
| 6300 | #define CATCH_REQUIRE_FALSE( ... ) (void)(0) |
| 6301 | |
| 6302 | #define CATCH_REQUIRE_THROWS( ... ) (void)(0) |
| 6303 | #define CATCH_REQUIRE_THROWS_AS( expr, exceptionType ) (void)(0) |
| 6304 | #define CATCH_REQUIRE_NOTHROW( ... ) (void)(0) |
| 6305 | |
| 6306 | #define CATCH_CHECK( ... ) (void)(0) |
| 6307 | #define CATCH_CHECK_FALSE( ... ) (void)(0) |
| 6308 | #define CATCH_CHECKED_IF( ... ) if (__VA_ARGS__) |
| 6309 | #define CATCH_CHECKED_ELSE( ... ) if (!(__VA_ARGS__)) |
| 6310 | #define CATCH_CHECK_NOFAIL( ... ) (void)(0) |
| 6311 | |
| 6312 | #define CATCH_CHECK_THROWS( ... ) (void)(0) |
| 6313 | #define CATCH_CHECK_THROWS_AS( expr, exceptionType ) (void)(0) |
| 6314 | #define CATCH_CHECK_NOTHROW( ... ) (void)(0) |
| 6315 | |
| 6316 | #define CATCH_TEST_CASE( ... ) INTERNAL_CATCH_TESTCASE_NO_REGISTRATION(INTERNAL_CATCH_UNIQUE_NAME( CATCH2_INTERNAL_TEST_ )) |
| 6317 | #define CATCH_TEST_CASE_METHOD( className, ... ) INTERNAL_CATCH_TESTCASE_NO_REGISTRATION(INTERNAL_CATCH_UNIQUE_NAME( CATCH2_INTERNAL_TEST_ )) |
| 6318 | #define CATCH_METHOD_AS_TEST_CASE( method, ... ) |
| 6319 | #define CATCH_REGISTER_TEST_CASE( Function, ... ) (void)(0) |
| 6320 | #define CATCH_SECTION( ... ) |
| 6321 | #define CATCH_DYNAMIC_SECTION( ... ) |
| 6322 | #define CATCH_FAIL( ... ) (void)(0) |
| 6323 | #define CATCH_FAIL_CHECK( ... ) (void)(0) |
| 6324 | #define CATCH_SUCCEED( ... ) (void)(0) |
| 6325 | #define CATCH_SKIP( ... ) (void)(0) |
| 6326 | |
| 6327 | #define CATCH_STATIC_REQUIRE( ... ) (void)(0) |
| 6328 | #define CATCH_STATIC_REQUIRE_FALSE( ... ) (void)(0) |
| 6329 | #define CATCH_STATIC_CHECK( ... ) (void)(0) |
| 6330 | #define CATCH_STATIC_CHECK_FALSE( ... ) (void)(0) |
| 6331 | |
| 6332 | // "BDD-style" convenience wrappers |
| 6333 | #define CATCH_SCENARIO( ... ) INTERNAL_CATCH_TESTCASE_NO_REGISTRATION(INTERNAL_CATCH_UNIQUE_NAME( CATCH2_INTERNAL_TEST_ )) |
| 6334 | #define CATCH_SCENARIO_METHOD( className, ... ) INTERNAL_CATCH_TESTCASE_METHOD_NO_REGISTRATION(INTERNAL_CATCH_UNIQUE_NAME( CATCH2_INTERNAL_TEST_ ), className ) |
| 6335 | #define CATCH_GIVEN( desc ) |
| 6336 | #define CATCH_AND_GIVEN( desc ) |
| 6337 | #define CATCH_WHEN( desc ) |
| 6338 | #define CATCH_AND_WHEN( desc ) |
| 6339 | #define CATCH_THEN( desc ) |
| 6340 | #define CATCH_AND_THEN( desc ) |
| 6341 | |
| 6342 | #elif !defined(CATCH_CONFIG_PREFIX_ALL) && !defined(CATCH_CONFIG_DISABLE) // ^^ prefixed, disabled | vv unprefixed, implemented |
| 6343 | |
| 6344 | #define REQUIRE( ... ) INTERNAL_CATCH_TEST( "REQUIRE", Catch::ResultDisposition::Normal, __VA_ARGS__ ) |
| 6345 | #define REQUIRE_FALSE( ... ) INTERNAL_CATCH_TEST( "REQUIRE_FALSE", Catch::ResultDisposition::Normal | Catch::ResultDisposition::FalseTest, __VA_ARGS__ ) |
| 6346 | |
| 6347 | #define REQUIRE_THROWS( ... ) INTERNAL_CATCH_THROWS( "REQUIRE_THROWS", Catch::ResultDisposition::Normal, __VA_ARGS__ ) |
| 6348 | #define REQUIRE_THROWS_AS( expr, exceptionType ) INTERNAL_CATCH_THROWS_AS( "REQUIRE_THROWS_AS", exceptionType, Catch::ResultDisposition::Normal, expr ) |
| 6349 | #define REQUIRE_NOTHROW( ... ) INTERNAL_CATCH_NO_THROW( "REQUIRE_NOTHROW", Catch::ResultDisposition::Normal, __VA_ARGS__ ) |
| 6350 | |
| 6351 | #define CHECK( ... ) INTERNAL_CATCH_TEST( "CHECK", Catch::ResultDisposition::ContinueOnFailure, __VA_ARGS__ ) |
| 6352 | #define CHECK_FALSE( ... ) INTERNAL_CATCH_TEST( "CHECK_FALSE", Catch::ResultDisposition::ContinueOnFailure | Catch::ResultDisposition::FalseTest, __VA_ARGS__ ) |
| 6353 | #define CHECKED_IF( ... ) INTERNAL_CATCH_IF( "CHECKED_IF", Catch::ResultDisposition::ContinueOnFailure | Catch::ResultDisposition::SuppressFail, __VA_ARGS__ ) |
| 6354 | #define CHECKED_ELSE( ... ) INTERNAL_CATCH_ELSE( "CHECKED_ELSE", Catch::ResultDisposition::ContinueOnFailure | Catch::ResultDisposition::SuppressFail, __VA_ARGS__ ) |
| 6355 | #define CHECK_NOFAIL( ... ) INTERNAL_CATCH_TEST( "CHECK_NOFAIL", Catch::ResultDisposition::ContinueOnFailure | Catch::ResultDisposition::SuppressFail, __VA_ARGS__ ) |
| 6356 | |
| 6357 | #define CHECK_THROWS( ... ) INTERNAL_CATCH_THROWS( "CHECK_THROWS", Catch::ResultDisposition::ContinueOnFailure, __VA_ARGS__ ) |
| 6358 | #define CHECK_THROWS_AS( expr, exceptionType ) INTERNAL_CATCH_THROWS_AS( "CHECK_THROWS_AS", exceptionType, Catch::ResultDisposition::ContinueOnFailure, expr ) |
| 6359 | #define CHECK_NOTHROW( ... ) INTERNAL_CATCH_NO_THROW( "CHECK_NOTHROW", Catch::ResultDisposition::ContinueOnFailure, __VA_ARGS__ ) |
| 6360 | |
| 6361 | #define TEST_CASE( ... ) INTERNAL_CATCH_TESTCASE( __VA_ARGS__ ) |
| 6362 | #define TEST_CASE_METHOD( className, ... ) INTERNAL_CATCH_TEST_CASE_METHOD( className, __VA_ARGS__ ) |
| 6363 | #define METHOD_AS_TEST_CASE( method, ... ) INTERNAL_CATCH_METHOD_AS_TEST_CASE( method, __VA_ARGS__ ) |
| 6364 | #define REGISTER_TEST_CASE( Function, ... ) INTERNAL_CATCH_REGISTER_TESTCASE( Function, __VA_ARGS__ ) |
| 6365 | #define SECTION( ... ) INTERNAL_CATCH_SECTION( __VA_ARGS__ ) |
| 6366 | #define DYNAMIC_SECTION( ... ) INTERNAL_CATCH_DYNAMIC_SECTION( __VA_ARGS__ ) |
| 6367 | #define FAIL( ... ) INTERNAL_CATCH_MSG( "FAIL", Catch::ResultWas::ExplicitFailure, Catch::ResultDisposition::Normal, __VA_ARGS__ ) |
| 6368 | #define FAIL_CHECK( ... ) INTERNAL_CATCH_MSG( "FAIL_CHECK", Catch::ResultWas::ExplicitFailure, Catch::ResultDisposition::ContinueOnFailure, __VA_ARGS__ ) |
| 6369 | #define SUCCEED( ... ) INTERNAL_CATCH_MSG( "SUCCEED", Catch::ResultWas::Ok, Catch::ResultDisposition::ContinueOnFailure, __VA_ARGS__ ) |
| 6370 | #define SKIP( ... ) INTERNAL_CATCH_MSG( "SKIP", Catch::ResultWas::ExplicitSkip, Catch::ResultDisposition::Normal, __VA_ARGS__ ) |
| 6371 | |
| 6372 | |
| 6373 | #if !defined(CATCH_CONFIG_RUNTIME_STATIC_REQUIRE) |
| 6374 | #define STATIC_REQUIRE( ... ) static_assert( __VA_ARGS__, #__VA_ARGS__ ); SUCCEED( #__VA_ARGS__ ) |
| 6375 | #define STATIC_REQUIRE_FALSE( ... ) static_assert( !(__VA_ARGS__), "!(" #__VA_ARGS__ ")" ); SUCCEED( "!(" #__VA_ARGS__ ")" ) |
| 6376 | #define STATIC_CHECK( ... ) static_assert( __VA_ARGS__, #__VA_ARGS__ ); SUCCEED( #__VA_ARGS__ ) |
| 6377 | #define STATIC_CHECK_FALSE( ... ) static_assert( !(__VA_ARGS__), "!(" #__VA_ARGS__ ")" ); SUCCEED( "!(" #__VA_ARGS__ ")" ) |
| 6378 | #else |
| 6379 | #define STATIC_REQUIRE( ... ) REQUIRE( __VA_ARGS__ ) |
| 6380 | #define STATIC_REQUIRE_FALSE( ... ) REQUIRE_FALSE( __VA_ARGS__ ) |
| 6381 | #define STATIC_CHECK( ... ) CHECK( __VA_ARGS__ ) |
| 6382 | #define STATIC_CHECK_FALSE( ... ) CHECK_FALSE( __VA_ARGS__ ) |
| 6383 | #endif |
| 6384 | |
| 6385 | // "BDD-style" convenience wrappers |
| 6386 | #define SCENARIO( ... ) TEST_CASE( "Scenario: " __VA_ARGS__ ) |
| 6387 | #define SCENARIO_METHOD( className, ... ) INTERNAL_CATCH_TEST_CASE_METHOD( className, "Scenario: " __VA_ARGS__ ) |
| 6388 | #define GIVEN( desc ) INTERNAL_CATCH_DYNAMIC_SECTION( " Given: " << desc ) |
| 6389 | #define AND_GIVEN( desc ) INTERNAL_CATCH_DYNAMIC_SECTION( "And given: " << desc ) |
| 6390 | #define WHEN( desc ) INTERNAL_CATCH_DYNAMIC_SECTION( " When: " << desc ) |
| 6391 | #define AND_WHEN( desc ) INTERNAL_CATCH_DYNAMIC_SECTION( " And when: " << desc ) |
| 6392 | #define THEN( desc ) INTERNAL_CATCH_DYNAMIC_SECTION( " Then: " << desc ) |
| 6393 | #define AND_THEN( desc ) INTERNAL_CATCH_DYNAMIC_SECTION( " And: " << desc ) |
| 6394 | |
| 6395 | #elif !defined(CATCH_CONFIG_PREFIX_ALL) && defined(CATCH_CONFIG_DISABLE) // ^^ unprefixed, implemented | vv unprefixed, disabled |
| 6396 | |
| 6397 | #define REQUIRE( ... ) (void)(0) |
| 6398 | #define REQUIRE_FALSE( ... ) (void)(0) |
| 6399 | |
| 6400 | #define REQUIRE_THROWS( ... ) (void)(0) |
| 6401 | #define REQUIRE_THROWS_AS( expr, exceptionType ) (void)(0) |
| 6402 | #define REQUIRE_NOTHROW( ... ) (void)(0) |
| 6403 | |
| 6404 | #define CHECK( ... ) (void)(0) |
| 6405 | #define CHECK_FALSE( ... ) (void)(0) |
| 6406 | #define CHECKED_IF( ... ) if (__VA_ARGS__) |
| 6407 | #define CHECKED_ELSE( ... ) if (!(__VA_ARGS__)) |
| 6408 | #define CHECK_NOFAIL( ... ) (void)(0) |
| 6409 | |
| 6410 | #define CHECK_THROWS( ... ) (void)(0) |
| 6411 | #define CHECK_THROWS_AS( expr, exceptionType ) (void)(0) |
| 6412 | #define CHECK_NOTHROW( ... ) (void)(0) |
| 6413 | |
| 6414 | #define TEST_CASE( ... ) INTERNAL_CATCH_TESTCASE_NO_REGISTRATION(INTERNAL_CATCH_UNIQUE_NAME( CATCH2_INTERNAL_TEST_ ), __VA_ARGS__) |
| 6415 | #define TEST_CASE_METHOD( className, ... ) INTERNAL_CATCH_TESTCASE_NO_REGISTRATION(INTERNAL_CATCH_UNIQUE_NAME( CATCH2_INTERNAL_TEST_ )) |
| 6416 | #define METHOD_AS_TEST_CASE( method, ... ) |
| 6417 | #define REGISTER_TEST_CASE( Function, ... ) (void)(0) |
| 6418 | #define SECTION( ... ) |
| 6419 | #define DYNAMIC_SECTION( ... ) |
| 6420 | #define FAIL( ... ) (void)(0) |
| 6421 | #define FAIL_CHECK( ... ) (void)(0) |
| 6422 | #define SUCCEED( ... ) (void)(0) |
| 6423 | #define SKIP( ... ) (void)(0) |
| 6424 | |
| 6425 | #define STATIC_REQUIRE( ... ) (void)(0) |
| 6426 | #define STATIC_REQUIRE_FALSE( ... ) (void)(0) |
| 6427 | #define STATIC_CHECK( ... ) (void)(0) |
| 6428 | #define STATIC_CHECK_FALSE( ... ) (void)(0) |
| 6429 | |
| 6430 | // "BDD-style" convenience wrappers |
| 6431 | #define SCENARIO( ... ) INTERNAL_CATCH_TESTCASE_NO_REGISTRATION(INTERNAL_CATCH_UNIQUE_NAME( CATCH2_INTERNAL_TEST_ ) ) |
| 6432 | #define SCENARIO_METHOD( className, ... ) INTERNAL_CATCH_TESTCASE_METHOD_NO_REGISTRATION(INTERNAL_CATCH_UNIQUE_NAME( CATCH2_INTERNAL_TEST_ ), className ) |
| 6433 | |
| 6434 | #define GIVEN( desc ) |
| 6435 | #define AND_GIVEN( desc ) |
| 6436 | #define WHEN( desc ) |
| 6437 | #define AND_WHEN( desc ) |
| 6438 | #define THEN( desc ) |
| 6439 | #define AND_THEN( desc ) |
| 6440 | |
| 6441 | #endif // ^^ unprefixed, disabled |
| 6442 | |
| 6443 | // end of user facing macros |
| 6444 | |
| 6445 | #endif // CATCH_TEST_MACROS_HPP_INCLUDED |
| 6446 | |
| 6447 | |
| 6448 | #ifndef CATCH_TEMPLATE_TEST_REGISTRY_HPP_INCLUDED |
| 6449 | #define CATCH_TEMPLATE_TEST_REGISTRY_HPP_INCLUDED |
| 6450 | |
| 6451 | |
| 6452 | |
| 6453 | #ifndef CATCH_PREPROCESSOR_HPP_INCLUDED |
| 6454 | #define CATCH_PREPROCESSOR_HPP_INCLUDED |
| 6455 | |
| 6456 | |
| 6457 | #if defined(__GNUC__) |
| 6458 | // We need to silence "empty __VA_ARGS__ warning", and using just _Pragma does not work |
| 6459 | #pragma GCC system_header |
| 6460 | #endif |
| 6461 | |
| 6462 | |
| 6463 | #define CATCH_RECURSION_LEVEL0(...) __VA_ARGS__ |
| 6464 | #define CATCH_RECURSION_LEVEL1(...) CATCH_RECURSION_LEVEL0(CATCH_RECURSION_LEVEL0(CATCH_RECURSION_LEVEL0(__VA_ARGS__))) |
| 6465 | #define CATCH_RECURSION_LEVEL2(...) CATCH_RECURSION_LEVEL1(CATCH_RECURSION_LEVEL1(CATCH_RECURSION_LEVEL1(__VA_ARGS__))) |
| 6466 | #define CATCH_RECURSION_LEVEL3(...) CATCH_RECURSION_LEVEL2(CATCH_RECURSION_LEVEL2(CATCH_RECURSION_LEVEL2(__VA_ARGS__))) |
| 6467 | #define CATCH_RECURSION_LEVEL4(...) CATCH_RECURSION_LEVEL3(CATCH_RECURSION_LEVEL3(CATCH_RECURSION_LEVEL3(__VA_ARGS__))) |
| 6468 | #define CATCH_RECURSION_LEVEL5(...) CATCH_RECURSION_LEVEL4(CATCH_RECURSION_LEVEL4(CATCH_RECURSION_LEVEL4(__VA_ARGS__))) |
| 6469 | |
| 6470 | #ifdef CATCH_CONFIG_TRADITIONAL_MSVC_PREPROCESSOR |
| 6471 | #define INTERNAL_CATCH_EXPAND_VARGS(...) __VA_ARGS__ |
| 6472 | // MSVC needs more evaluations |
| 6473 | #define CATCH_RECURSION_LEVEL6(...) CATCH_RECURSION_LEVEL5(CATCH_RECURSION_LEVEL5(CATCH_RECURSION_LEVEL5(__VA_ARGS__))) |
| 6474 | #define CATCH_RECURSE(...) CATCH_RECURSION_LEVEL6(CATCH_RECURSION_LEVEL6(__VA_ARGS__)) |
| 6475 | #else |
| 6476 | #define CATCH_RECURSE(...) CATCH_RECURSION_LEVEL5(__VA_ARGS__) |
| 6477 | #endif |
| 6478 | |
| 6479 | #define CATCH_REC_END(...) |
| 6480 | #define CATCH_REC_OUT |
| 6481 | |
| 6482 | #define CATCH_EMPTY() |
| 6483 | #define CATCH_DEFER(id) id CATCH_EMPTY() |
| 6484 | |
| 6485 | #define CATCH_REC_GET_END2() 0, CATCH_REC_END |
| 6486 | #define CATCH_REC_GET_END1(...) CATCH_REC_GET_END2 |
| 6487 | #define CATCH_REC_GET_END(...) CATCH_REC_GET_END1 |
| 6488 | #define CATCH_REC_NEXT0(test, next, ...) next CATCH_REC_OUT |
| 6489 | #define CATCH_REC_NEXT1(test, next) CATCH_DEFER ( CATCH_REC_NEXT0 ) ( test, next, 0) |
| 6490 | #define CATCH_REC_NEXT(test, next) CATCH_REC_NEXT1(CATCH_REC_GET_END test, next) |
| 6491 | |
| 6492 | #define CATCH_REC_LIST0(f, x, peek, ...) , f(x) CATCH_DEFER ( CATCH_REC_NEXT(peek, CATCH_REC_LIST1) ) ( f, peek, __VA_ARGS__ ) |
| 6493 | #define CATCH_REC_LIST1(f, x, peek, ...) , f(x) CATCH_DEFER ( CATCH_REC_NEXT(peek, CATCH_REC_LIST0) ) ( f, peek, __VA_ARGS__ ) |
| 6494 | #define CATCH_REC_LIST2(f, x, peek, ...) f(x) CATCH_DEFER ( CATCH_REC_NEXT(peek, CATCH_REC_LIST1) ) ( f, peek, __VA_ARGS__ ) |
| 6495 | |
| 6496 | #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__ ) |
| 6497 | #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__ ) |
| 6498 | #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__ ) |
| 6499 | |
| 6500 | // Applies the function macro `f` to each of the remaining parameters, inserts commas between the results, |
| 6501 | // and passes userdata as the first parameter to each invocation, |
| 6502 | // e.g. CATCH_REC_LIST_UD(f, x, a, b, c) evaluates to f(x, a), f(x, b), f(x, c) |
| 6503 | #define CATCH_REC_LIST_UD(f, userdata, ...) CATCH_RECURSE(CATCH_REC_LIST2_UD(f, userdata, __VA_ARGS__, ()()(), ()()(), ()()(), 0)) |
| 6504 | |
| 6505 | #define CATCH_REC_LIST(f, ...) CATCH_RECURSE(CATCH_REC_LIST2(f, __VA_ARGS__, ()()(), ()()(), ()()(), 0)) |
| 6506 | |
| 6507 | #define INTERNAL_CATCH_STRINGIZE(...) INTERNAL_CATCH_STRINGIZE2(__VA_ARGS__) |
| 6508 | #ifndef CATCH_CONFIG_TRADITIONAL_MSVC_PREPROCESSOR |
| 6509 | #define INTERNAL_CATCH_STRINGIZE2(...) #__VA_ARGS__ |
| 6510 | #define INTERNAL_CATCH_STRINGIZE_WITHOUT_PARENS(param) INTERNAL_CATCH_STRINGIZE(INTERNAL_CATCH_REMOVE_PARENS(param)) |
| 6511 | #else |
| 6512 | // MSVC is adding extra space and needs another indirection to expand INTERNAL_CATCH_NOINTERNAL_CATCH_DEF |
| 6513 | #define INTERNAL_CATCH_STRINGIZE2(...) INTERNAL_CATCH_STRINGIZE3(__VA_ARGS__) |
| 6514 | #define INTERNAL_CATCH_STRINGIZE3(...) #__VA_ARGS__ |
| 6515 | #define INTERNAL_CATCH_STRINGIZE_WITHOUT_PARENS(param) (INTERNAL_CATCH_STRINGIZE(INTERNAL_CATCH_REMOVE_PARENS(param)) + 1) |
| 6516 | #endif |
| 6517 | |
| 6518 | #define INTERNAL_CATCH_MAKE_NAMESPACE2(...) ns_##__VA_ARGS__ |
| 6519 | #define INTERNAL_CATCH_MAKE_NAMESPACE(name) INTERNAL_CATCH_MAKE_NAMESPACE2(name) |
| 6520 | |
| 6521 | #ifndef CATCH_CONFIG_TRADITIONAL_MSVC_PREPROCESSOR |
| 6522 | #define INTERNAL_CATCH_MAKE_TYPE_LIST2(...) decltype(get_wrapper<INTERNAL_CATCH_REMOVE_PARENS_GEN(__VA_ARGS__)>()) |
| 6523 | #define INTERNAL_CATCH_MAKE_TYPE_LIST(...) INTERNAL_CATCH_MAKE_TYPE_LIST2(INTERNAL_CATCH_REMOVE_PARENS(__VA_ARGS__)) |
| 6524 | #else |
| 6525 | #define INTERNAL_CATCH_MAKE_TYPE_LIST2(...) INTERNAL_CATCH_EXPAND_VARGS(decltype(get_wrapper<INTERNAL_CATCH_REMOVE_PARENS_GEN(__VA_ARGS__)>())) |
| 6526 | #define INTERNAL_CATCH_MAKE_TYPE_LIST(...) INTERNAL_CATCH_EXPAND_VARGS(INTERNAL_CATCH_MAKE_TYPE_LIST2(INTERNAL_CATCH_REMOVE_PARENS(__VA_ARGS__))) |
| 6527 | #endif |
| 6528 | |
| 6529 | #define INTERNAL_CATCH_MAKE_TYPE_LISTS_FROM_TYPES(...)\ |
| 6530 | CATCH_REC_LIST(INTERNAL_CATCH_MAKE_TYPE_LIST,__VA_ARGS__) |
| 6531 | |
| 6532 | #define INTERNAL_CATCH_REMOVE_PARENS_1_ARG(_0) INTERNAL_CATCH_REMOVE_PARENS(_0) |
| 6533 | #define INTERNAL_CATCH_REMOVE_PARENS_2_ARG(_0, _1) INTERNAL_CATCH_REMOVE_PARENS(_0), INTERNAL_CATCH_REMOVE_PARENS_1_ARG(_1) |
| 6534 | #define INTERNAL_CATCH_REMOVE_PARENS_3_ARG(_0, _1, _2) INTERNAL_CATCH_REMOVE_PARENS(_0), INTERNAL_CATCH_REMOVE_PARENS_2_ARG(_1, _2) |
| 6535 | #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) |
| 6536 | #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) |
| 6537 | #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) |
| 6538 | #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) |
| 6539 | #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) |
| 6540 | #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) |
| 6541 | #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) |
| 6542 | #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) |
| 6543 | |
| 6544 | #define INTERNAL_CATCH_VA_NARGS_IMPL(_0, _1, _2, _3, _4, _5, _6, _7, _8, _9, _10, N, ...) N |
| 6545 | |
| 6546 | #define INTERNAL_CATCH_TYPE_GEN\ |
| 6547 | template<typename...> struct TypeList {};\ |
| 6548 | template<typename...Ts>\ |
| 6549 | constexpr auto get_wrapper() noexcept -> TypeList<Ts...> { return {}; }\ |
| 6550 | template<template<typename...> class...> struct TemplateTypeList{};\ |
| 6551 | template<template<typename...> class...Cs>\ |
| 6552 | constexpr auto get_wrapper() noexcept -> TemplateTypeList<Cs...> { return {}; }\ |
| 6553 | template<typename...>\ |
| 6554 | struct append;\ |
| 6555 | template<typename...>\ |
| 6556 | struct rewrap;\ |
| 6557 | template<template<typename...> class, typename...>\ |
| 6558 | struct create;\ |
| 6559 | template<template<typename...> class, typename>\ |
| 6560 | struct convert;\ |
| 6561 | \ |
| 6562 | template<typename T> \ |
| 6563 | struct append<T> { using type = T; };\ |
| 6564 | template< template<typename...> class L1, typename...E1, template<typename...> class L2, typename...E2, typename...Rest>\ |
| 6565 | struct append<L1<E1...>, L2<E2...>, Rest...> { using type = typename append<L1<E1...,E2...>, Rest...>::type; };\ |
| 6566 | template< template<typename...> class L1, typename...E1, typename...Rest>\ |
| 6567 | struct append<L1<E1...>, TypeList<mpl_::na>, Rest...> { using type = L1<E1...>; };\ |
| 6568 | \ |
| 6569 | template< template<typename...> class Container, template<typename...> class List, typename...elems>\ |
| 6570 | struct rewrap<TemplateTypeList<Container>, List<elems...>> { using type = TypeList<Container<elems...>>; };\ |
| 6571 | template< template<typename...> class Container, template<typename...> class List, class...Elems, typename...Elements>\ |
| 6572 | struct rewrap<TemplateTypeList<Container>, List<Elems...>, Elements...> { using type = typename append<TypeList<Container<Elems...>>, typename rewrap<TemplateTypeList<Container>, Elements...>::type>::type; };\ |
| 6573 | \ |
| 6574 | template<template <typename...> class Final, template< typename...> class...Containers, typename...Types>\ |
| 6575 | struct create<Final, TemplateTypeList<Containers...>, TypeList<Types...>> { using type = typename append<Final<>, typename rewrap<TemplateTypeList<Containers>, Types...>::type...>::type; };\ |
| 6576 | template<template <typename...> class Final, template <typename...> class List, typename...Ts>\ |
| 6577 | struct convert<Final, List<Ts...>> { using type = typename append<Final<>,TypeList<Ts>...>::type; }; |
| 6578 | |
| 6579 | #define INTERNAL_CATCH_NTTP_1(signature, ...)\ |
| 6580 | template<INTERNAL_CATCH_REMOVE_PARENS(signature)> struct Nttp{};\ |
| 6581 | template<INTERNAL_CATCH_REMOVE_PARENS(signature)>\ |
| 6582 | constexpr auto get_wrapper() noexcept -> Nttp<__VA_ARGS__> { return {}; } \ |
| 6583 | template<template<INTERNAL_CATCH_REMOVE_PARENS(signature)> class...> struct NttpTemplateTypeList{};\ |
| 6584 | template<template<INTERNAL_CATCH_REMOVE_PARENS(signature)> class...Cs>\ |
| 6585 | constexpr auto get_wrapper() noexcept -> NttpTemplateTypeList<Cs...> { return {}; } \ |
| 6586 | \ |
| 6587 | template< template<INTERNAL_CATCH_REMOVE_PARENS(signature)> class Container, template<INTERNAL_CATCH_REMOVE_PARENS(signature)> class List, INTERNAL_CATCH_REMOVE_PARENS(signature)>\ |
| 6588 | struct rewrap<NttpTemplateTypeList<Container>, List<__VA_ARGS__>> { using type = TypeList<Container<__VA_ARGS__>>; };\ |
| 6589 | template< template<INTERNAL_CATCH_REMOVE_PARENS(signature)> class Container, template<INTERNAL_CATCH_REMOVE_PARENS(signature)> class List, INTERNAL_CATCH_REMOVE_PARENS(signature), typename...Elements>\ |
| 6590 | struct rewrap<NttpTemplateTypeList<Container>, List<__VA_ARGS__>, Elements...> { using type = typename append<TypeList<Container<__VA_ARGS__>>, typename rewrap<NttpTemplateTypeList<Container>, Elements...>::type>::type; };\ |
| 6591 | template<template <typename...> class Final, template<INTERNAL_CATCH_REMOVE_PARENS(signature)> class...Containers, typename...Types>\ |
| 6592 | struct create<Final, NttpTemplateTypeList<Containers...>, TypeList<Types...>> { using type = typename append<Final<>, typename rewrap<NttpTemplateTypeList<Containers>, Types...>::type...>::type; }; |
| 6593 | |
| 6594 | #define INTERNAL_CATCH_DECLARE_SIG_TEST0(TestName) |
| 6595 | #define INTERNAL_CATCH_DECLARE_SIG_TEST1(TestName, signature)\ |
| 6596 | template<INTERNAL_CATCH_REMOVE_PARENS(signature)>\ |
| 6597 | static void TestName() |
| 6598 | #define INTERNAL_CATCH_DECLARE_SIG_TEST_X(TestName, signature, ...)\ |
| 6599 | template<INTERNAL_CATCH_REMOVE_PARENS(signature)>\ |
| 6600 | static void TestName() |
| 6601 | |
| 6602 | #define INTERNAL_CATCH_DEFINE_SIG_TEST0(TestName) |
| 6603 | #define INTERNAL_CATCH_DEFINE_SIG_TEST1(TestName, signature)\ |
| 6604 | template<INTERNAL_CATCH_REMOVE_PARENS(signature)>\ |
| 6605 | static void TestName() |
| 6606 | #define INTERNAL_CATCH_DEFINE_SIG_TEST_X(TestName, signature,...)\ |
| 6607 | template<INTERNAL_CATCH_REMOVE_PARENS(signature)>\ |
| 6608 | static void TestName() |
| 6609 | |
| 6610 | #define INTERNAL_CATCH_NTTP_REGISTER0(TestFunc, signature)\ |
| 6611 | template<typename Type>\ |
| 6612 | void reg_test(TypeList<Type>, Catch::NameAndTags nameAndTags)\ |
| 6613 | {\ |
| 6614 | Catch::AutoReg( Catch::makeTestInvoker(&TestFunc<Type>), CATCH_INTERNAL_LINEINFO, Catch::StringRef(), nameAndTags);\ |
| 6615 | } |
| 6616 | |
| 6617 | #define INTERNAL_CATCH_NTTP_REGISTER(TestFunc, signature, ...)\ |
| 6618 | template<INTERNAL_CATCH_REMOVE_PARENS(signature)>\ |
| 6619 | void reg_test(Nttp<__VA_ARGS__>, Catch::NameAndTags nameAndTags)\ |
| 6620 | {\ |
| 6621 | Catch::AutoReg( Catch::makeTestInvoker(&TestFunc<__VA_ARGS__>), CATCH_INTERNAL_LINEINFO, Catch::StringRef(), nameAndTags);\ |
| 6622 | } |
| 6623 | |
| 6624 | #define INTERNAL_CATCH_NTTP_REGISTER_METHOD0(TestName, signature, ...)\ |
| 6625 | template<typename Type>\ |
| 6626 | void reg_test(TypeList<Type>, Catch::StringRef className, Catch::NameAndTags nameAndTags)\ |
| 6627 | {\ |
| 6628 | Catch::AutoReg( Catch::makeTestInvoker(&TestName<Type>::test), CATCH_INTERNAL_LINEINFO, className, nameAndTags);\ |
| 6629 | } |
| 6630 | |
| 6631 | #define INTERNAL_CATCH_NTTP_REGISTER_METHOD(TestName, signature, ...)\ |
| 6632 | template<INTERNAL_CATCH_REMOVE_PARENS(signature)>\ |
| 6633 | void reg_test(Nttp<__VA_ARGS__>, Catch::StringRef className, Catch::NameAndTags nameAndTags)\ |
| 6634 | {\ |
| 6635 | Catch::AutoReg( Catch::makeTestInvoker(&TestName<__VA_ARGS__>::test), CATCH_INTERNAL_LINEINFO, className, nameAndTags);\ |
| 6636 | } |
| 6637 | |
| 6638 | #define INTERNAL_CATCH_DECLARE_SIG_TEST_METHOD0(TestName, ClassName) |
| 6639 | #define INTERNAL_CATCH_DECLARE_SIG_TEST_METHOD1(TestName, ClassName, signature)\ |
| 6640 | template<typename TestType> \ |
| 6641 | struct TestName : INTERNAL_CATCH_REMOVE_PARENS(ClassName)<TestType> { \ |
| 6642 | void test();\ |
| 6643 | } |
| 6644 | |
| 6645 | #define INTERNAL_CATCH_DECLARE_SIG_TEST_METHOD_X(TestName, ClassName, signature, ...)\ |
| 6646 | template<INTERNAL_CATCH_REMOVE_PARENS(signature)> \ |
| 6647 | struct TestName : INTERNAL_CATCH_REMOVE_PARENS(ClassName)<__VA_ARGS__> { \ |
| 6648 | void test();\ |
| 6649 | } |
| 6650 | |
| 6651 | #define INTERNAL_CATCH_DEFINE_SIG_TEST_METHOD0(TestName) |
| 6652 | #define INTERNAL_CATCH_DEFINE_SIG_TEST_METHOD1(TestName, signature)\ |
| 6653 | template<typename TestType> \ |
| 6654 | void INTERNAL_CATCH_MAKE_NAMESPACE(TestName)::TestName<TestType>::test() |
| 6655 | #define INTERNAL_CATCH_DEFINE_SIG_TEST_METHOD_X(TestName, signature, ...)\ |
| 6656 | template<INTERNAL_CATCH_REMOVE_PARENS(signature)> \ |
| 6657 | void INTERNAL_CATCH_MAKE_NAMESPACE(TestName)::TestName<__VA_ARGS__>::test() |
| 6658 | |
| 6659 | #ifndef CATCH_CONFIG_TRADITIONAL_MSVC_PREPROCESSOR |
| 6660 | #define INTERNAL_CATCH_NTTP_0 |
| 6661 | #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) |
| 6662 | #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__) |
| 6663 | #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__) |
| 6664 | #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__) |
| 6665 | #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__) |
| 6666 | #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__) |
| 6667 | #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__) |
| 6668 | #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__) |
| 6669 | #else |
| 6670 | #define INTERNAL_CATCH_NTTP_0(signature) |
| 6671 | #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__)) |
| 6672 | #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__)) |
| 6673 | #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__)) |
| 6674 | #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__)) |
| 6675 | #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__)) |
| 6676 | #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__)) |
| 6677 | #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__)) |
| 6678 | #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__)) |
| 6679 | #endif |
| 6680 | |
| 6681 | #endif // CATCH_PREPROCESSOR_HPP_INCLUDED |
| 6682 | |
| 6683 | |
| 6684 | // GCC 5 and older do not properly handle disabling unused-variable warning |
| 6685 | // with a _Pragma. This means that we have to leak the suppression to the |
| 6686 | // user code as well :-( |
| 6687 | #if defined(__GNUC__) && !defined(__clang__) && __GNUC__ <= 5 |
| 6688 | #pragma GCC diagnostic ignored "-Wunused-variable" |
| 6689 | #endif |
| 6690 | |
| 6691 | #if defined(CATCH_CONFIG_DISABLE) |
| 6692 | #define INTERNAL_CATCH_TEMPLATE_TEST_CASE_NO_REGISTRATION_2( TestName, TestFunc, Name, Tags, Signature, ... ) \ |
| 6693 | INTERNAL_CATCH_DEFINE_SIG_TEST(TestFunc, INTERNAL_CATCH_REMOVE_PARENS(Signature)) |
| 6694 | #define INTERNAL_CATCH_TEMPLATE_TEST_CASE_METHOD_NO_REGISTRATION_2( TestNameClass, TestName, ClassName, Name, Tags, Signature, ... ) \ |
| 6695 | namespace{ \ |
| 6696 | namespace INTERNAL_CATCH_MAKE_NAMESPACE(TestName) { \ |
| 6697 | INTERNAL_CATCH_DECLARE_SIG_TEST_METHOD(TestName, ClassName, INTERNAL_CATCH_REMOVE_PARENS(Signature));\ |
| 6698 | } \ |
| 6699 | } \ |
| 6700 | INTERNAL_CATCH_DEFINE_SIG_TEST_METHOD(TestName, INTERNAL_CATCH_REMOVE_PARENS(Signature)) |
| 6701 | |
| 6702 | #ifndef CATCH_CONFIG_TRADITIONAL_MSVC_PREPROCESSOR |
| 6703 | #define INTERNAL_CATCH_TEMPLATE_TEST_CASE_NO_REGISTRATION(Name, Tags, ...) \ |
| 6704 | INTERNAL_CATCH_TEMPLATE_TEST_CASE_NO_REGISTRATION_2( INTERNAL_CATCH_UNIQUE_NAME( CATCH2_INTERNAL_TEMPLATE_TEST_ ), INTERNAL_CATCH_UNIQUE_NAME( CATCH2_INTERNAL_TEMPLATE_TEST_ ), Name, Tags, typename TestType, __VA_ARGS__ ) |
| 6705 | #else |
| 6706 | #define INTERNAL_CATCH_TEMPLATE_TEST_CASE_NO_REGISTRATION(Name, Tags, ...) \ |
| 6707 | INTERNAL_CATCH_EXPAND_VARGS( INTERNAL_CATCH_TEMPLATE_TEST_CASE_NO_REGISTRATION_2( INTERNAL_CATCH_UNIQUE_NAME( CATCH2_INTERNAL_TEMPLATE_TEST_ ), INTERNAL_CATCH_UNIQUE_NAME( CATCH2_INTERNAL_TEMPLATE_TEST_ ), Name, Tags, typename TestType, __VA_ARGS__ ) ) |
| 6708 | #endif |
| 6709 | |
| 6710 | #ifndef CATCH_CONFIG_TRADITIONAL_MSVC_PREPROCESSOR |
| 6711 | #define INTERNAL_CATCH_TEMPLATE_TEST_CASE_SIG_NO_REGISTRATION(Name, Tags, Signature, ...) \ |
| 6712 | INTERNAL_CATCH_TEMPLATE_TEST_CASE_NO_REGISTRATION_2( INTERNAL_CATCH_UNIQUE_NAME( CATCH2_INTERNAL_TEMPLATE_TEST_ ), INTERNAL_CATCH_UNIQUE_NAME( CATCH2_INTERNAL_TEMPLATE_TEST_ ), Name, Tags, Signature, __VA_ARGS__ ) |
| 6713 | #else |
| 6714 | #define INTERNAL_CATCH_TEMPLATE_TEST_CASE_SIG_NO_REGISTRATION(Name, Tags, Signature, ...) \ |
| 6715 | INTERNAL_CATCH_EXPAND_VARGS( INTERNAL_CATCH_TEMPLATE_TEST_CASE_NO_REGISTRATION_2( INTERNAL_CATCH_UNIQUE_NAME( CATCH2_INTERNAL_TEMPLATE_TEST_ ), INTERNAL_CATCH_UNIQUE_NAME( CATCH2_INTERNAL_TEMPLATE_TEST_ ), Name, Tags, Signature, __VA_ARGS__ ) ) |
| 6716 | #endif |
| 6717 | |
| 6718 | #ifndef CATCH_CONFIG_TRADITIONAL_MSVC_PREPROCESSOR |
| 6719 | #define INTERNAL_CATCH_TEMPLATE_TEST_CASE_METHOD_NO_REGISTRATION( ClassName, Name, Tags,... ) \ |
| 6720 | INTERNAL_CATCH_TEMPLATE_TEST_CASE_METHOD_NO_REGISTRATION_2( INTERNAL_CATCH_UNIQUE_NAME( CATCH2_INTERNAL_TEMPLATE_TEST_CLASS_ ), INTERNAL_CATCH_UNIQUE_NAME( CATCH2_INTERNAL_TEMPLATE_TEST_ ) , ClassName, Name, Tags, typename T, __VA_ARGS__ ) |
| 6721 | #else |
| 6722 | #define INTERNAL_CATCH_TEMPLATE_TEST_CASE_METHOD_NO_REGISTRATION( ClassName, Name, Tags,... ) \ |
| 6723 | INTERNAL_CATCH_EXPAND_VARGS( INTERNAL_CATCH_TEMPLATE_TEST_CASE_METHOD_NO_REGISTRATION_2( INTERNAL_CATCH_UNIQUE_NAME( CATCH2_INTERNAL_TEMPLATE_TEST_CLASS_ ), INTERNAL_CATCH_UNIQUE_NAME( CATCH2_INTERNAL_TEMPLATE_TEST_ ) , ClassName, Name, Tags, typename T, __VA_ARGS__ ) ) |
| 6724 | #endif |
| 6725 | |
| 6726 | #ifndef CATCH_CONFIG_TRADITIONAL_MSVC_PREPROCESSOR |
| 6727 | #define INTERNAL_CATCH_TEMPLATE_TEST_CASE_METHOD_SIG_NO_REGISTRATION( ClassName, Name, Tags, Signature, ... ) \ |
| 6728 | INTERNAL_CATCH_TEMPLATE_TEST_CASE_METHOD_NO_REGISTRATION_2( INTERNAL_CATCH_UNIQUE_NAME( CATCH2_INTERNAL_TEMPLATE_TEST_CLASS_ ), INTERNAL_CATCH_UNIQUE_NAME( CATCH2_INTERNAL_TEMPLATE_TEST_ ) , ClassName, Name, Tags, Signature, __VA_ARGS__ ) |
| 6729 | #else |
| 6730 | #define INTERNAL_CATCH_TEMPLATE_TEST_CASE_METHOD_SIG_NO_REGISTRATION( ClassName, Name, Tags, Signature, ... ) \ |
| 6731 | INTERNAL_CATCH_EXPAND_VARGS( INTERNAL_CATCH_TEMPLATE_TEST_CASE_METHOD_NO_REGISTRATION_2( INTERNAL_CATCH_UNIQUE_NAME( CATCH2_INTERNAL_TEMPLATE_TEST_CLASS_ ), INTERNAL_CATCH_UNIQUE_NAME( CATCH2_INTERNAL_TEMPLATE_TEST_ ) , ClassName, Name, Tags, Signature, __VA_ARGS__ ) ) |
| 6732 | #endif |
| 6733 | #endif |
| 6734 | |
| 6735 | |
| 6736 | /////////////////////////////////////////////////////////////////////////////// |
| 6737 | #define INTERNAL_CATCH_TEMPLATE_TEST_CASE_2(TestName, TestFunc, Name, Tags, Signature, ... )\ |
| 6738 | CATCH_INTERNAL_START_WARNINGS_SUPPRESSION \ |
| 6739 | CATCH_INTERNAL_SUPPRESS_GLOBALS_WARNINGS \ |
| 6740 | CATCH_INTERNAL_SUPPRESS_ZERO_VARIADIC_WARNINGS \ |
| 6741 | CATCH_INTERNAL_SUPPRESS_UNUSED_TEMPLATE_WARNINGS \ |
| 6742 | CATCH_INTERNAL_SUPPRESS_UNUSED_VARIABLE_WARNINGS \ |
| 6743 | CATCH_INTERNAL_SUPPRESS_COMMA_WARNINGS \ |
| 6744 | INTERNAL_CATCH_DECLARE_SIG_TEST(TestFunc, INTERNAL_CATCH_REMOVE_PARENS(Signature));\ |
| 6745 | namespace {\ |
| 6746 | namespace INTERNAL_CATCH_MAKE_NAMESPACE(TestName){\ |
| 6747 | INTERNAL_CATCH_TYPE_GEN\ |
| 6748 | INTERNAL_CATCH_NTTP_GEN(INTERNAL_CATCH_REMOVE_PARENS(Signature))\ |
| 6749 | INTERNAL_CATCH_NTTP_REG_GEN(TestFunc,INTERNAL_CATCH_REMOVE_PARENS(Signature))\ |
| 6750 | template<typename...Types> \ |
| 6751 | struct TestName{\ |
| 6752 | TestName(){\ |
| 6753 | size_t index = 0; \ |
| 6754 | constexpr char const* tmpl_types[] = {CATCH_REC_LIST(INTERNAL_CATCH_STRINGIZE_WITHOUT_PARENS, __VA_ARGS__)}; /* NOLINT(cppcoreguidelines-avoid-c-arrays,modernize-avoid-c-arrays,hicpp-avoid-c-arrays) */\ |
| 6755 | using expander = size_t[]; /* NOLINT(cppcoreguidelines-avoid-c-arrays,modernize-avoid-c-arrays,hicpp-avoid-c-arrays) */\ |
| 6756 | (void)expander{(reg_test(Types{}, Catch::NameAndTags{ Name " - " + std::string(tmpl_types[index]), Tags } ), index++)... };/* NOLINT */ \ |
| 6757 | }\ |
| 6758 | };\ |
| 6759 | static const int INTERNAL_CATCH_UNIQUE_NAME( globalRegistrar ) = [](){\ |
| 6760 | TestName<INTERNAL_CATCH_MAKE_TYPE_LISTS_FROM_TYPES(__VA_ARGS__)>();\ |
| 6761 | return 0;\ |
| 6762 | }();\ |
| 6763 | }\ |
| 6764 | }\ |
| 6765 | CATCH_INTERNAL_STOP_WARNINGS_SUPPRESSION \ |
| 6766 | INTERNAL_CATCH_DEFINE_SIG_TEST(TestFunc,INTERNAL_CATCH_REMOVE_PARENS(Signature)) |
| 6767 | |
| 6768 | #ifndef CATCH_CONFIG_TRADITIONAL_MSVC_PREPROCESSOR |
| 6769 | #define INTERNAL_CATCH_TEMPLATE_TEST_CASE(Name, Tags, ...) \ |
| 6770 | INTERNAL_CATCH_TEMPLATE_TEST_CASE_2( INTERNAL_CATCH_UNIQUE_NAME( CATCH2_INTERNAL_TEMPLATE_TEST_ ), INTERNAL_CATCH_UNIQUE_NAME( CATCH2_INTERNAL_TEMPLATE_TEST_ ), Name, Tags, typename TestType, __VA_ARGS__ ) |
| 6771 | #else |
| 6772 | #define INTERNAL_CATCH_TEMPLATE_TEST_CASE(Name, Tags, ...) \ |
| 6773 | INTERNAL_CATCH_EXPAND_VARGS( INTERNAL_CATCH_TEMPLATE_TEST_CASE_2( INTERNAL_CATCH_UNIQUE_NAME( CATCH2_INTERNAL_TEMPLATE_TEST_ ), INTERNAL_CATCH_UNIQUE_NAME( CATCH2_INTERNAL_TEMPLATE_TEST_ ), Name, Tags, typename TestType, __VA_ARGS__ ) ) |
| 6774 | #endif |
| 6775 | |
| 6776 | #ifndef CATCH_CONFIG_TRADITIONAL_MSVC_PREPROCESSOR |
| 6777 | #define INTERNAL_CATCH_TEMPLATE_TEST_CASE_SIG(Name, Tags, Signature, ...) \ |
| 6778 | INTERNAL_CATCH_TEMPLATE_TEST_CASE_2( INTERNAL_CATCH_UNIQUE_NAME( CATCH2_INTERNAL_TEMPLATE_TEST_ ), INTERNAL_CATCH_UNIQUE_NAME( CATCH2_INTERNAL_TEMPLATE_TEST_ ), Name, Tags, Signature, __VA_ARGS__ ) |
| 6779 | #else |
| 6780 | #define INTERNAL_CATCH_TEMPLATE_TEST_CASE_SIG(Name, Tags, Signature, ...) \ |
| 6781 | INTERNAL_CATCH_EXPAND_VARGS( INTERNAL_CATCH_TEMPLATE_TEST_CASE_2( INTERNAL_CATCH_UNIQUE_NAME( CATCH2_INTERNAL_TEMPLATE_TEST_ ), INTERNAL_CATCH_UNIQUE_NAME( CATCH2_INTERNAL_TEMPLATE_TEST_ ), Name, Tags, Signature, __VA_ARGS__ ) ) |
| 6782 | #endif |
| 6783 | |
| 6784 | #define INTERNAL_CATCH_TEMPLATE_PRODUCT_TEST_CASE2(TestName, TestFuncName, Name, Tags, Signature, TmplTypes, TypesList) \ |
| 6785 | CATCH_INTERNAL_START_WARNINGS_SUPPRESSION \ |
| 6786 | CATCH_INTERNAL_SUPPRESS_GLOBALS_WARNINGS \ |
| 6787 | CATCH_INTERNAL_SUPPRESS_ZERO_VARIADIC_WARNINGS \ |
| 6788 | CATCH_INTERNAL_SUPPRESS_UNUSED_TEMPLATE_WARNINGS \ |
| 6789 | CATCH_INTERNAL_SUPPRESS_UNUSED_VARIABLE_WARNINGS \ |
| 6790 | CATCH_INTERNAL_SUPPRESS_COMMA_WARNINGS \ |
| 6791 | template<typename TestType> static void TestFuncName(); \ |
| 6792 | namespace {\ |
| 6793 | namespace INTERNAL_CATCH_MAKE_NAMESPACE(TestName) { \ |
| 6794 | INTERNAL_CATCH_TYPE_GEN \ |
| 6795 | INTERNAL_CATCH_NTTP_GEN(INTERNAL_CATCH_REMOVE_PARENS(Signature)) \ |
| 6796 | template<typename... Types> \ |
| 6797 | struct TestName { \ |
| 6798 | void reg_tests() { \ |
| 6799 | size_t index = 0; \ |
| 6800 | using expander = size_t[]; \ |
| 6801 | constexpr char const* tmpl_types[] = {CATCH_REC_LIST(INTERNAL_CATCH_STRINGIZE_WITHOUT_PARENS, INTERNAL_CATCH_REMOVE_PARENS(TmplTypes))};\ |
| 6802 | constexpr char const* types_list[] = {CATCH_REC_LIST(INTERNAL_CATCH_STRINGIZE_WITHOUT_PARENS, INTERNAL_CATCH_REMOVE_PARENS(TypesList))};\ |
| 6803 | constexpr auto num_types = sizeof(types_list) / sizeof(types_list[0]);\ |
| 6804 | (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++)... };/* NOLINT */\ |
| 6805 | } \ |
| 6806 | }; \ |
| 6807 | static int INTERNAL_CATCH_UNIQUE_NAME( globalRegistrar ) = [](){ \ |
| 6808 | 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; \ |
| 6809 | TestInit t; \ |
| 6810 | t.reg_tests(); \ |
| 6811 | return 0; \ |
| 6812 | }(); \ |
| 6813 | } \ |
| 6814 | } \ |
| 6815 | CATCH_INTERNAL_STOP_WARNINGS_SUPPRESSION \ |
| 6816 | template<typename TestType> \ |
| 6817 | static void TestFuncName() |
| 6818 | |
| 6819 | #ifndef CATCH_CONFIG_TRADITIONAL_MSVC_PREPROCESSOR |
| 6820 | #define INTERNAL_CATCH_TEMPLATE_PRODUCT_TEST_CASE(Name, Tags, ...)\ |
| 6821 | INTERNAL_CATCH_TEMPLATE_PRODUCT_TEST_CASE2(INTERNAL_CATCH_UNIQUE_NAME( CATCH2_INTERNAL_TEMPLATE_TEST_ ), INTERNAL_CATCH_UNIQUE_NAME( CATCH2_INTERNAL_TEMPLATE_TEST_ ), Name, Tags, typename T,__VA_ARGS__) |
| 6822 | #else |
| 6823 | #define INTERNAL_CATCH_TEMPLATE_PRODUCT_TEST_CASE(Name, Tags, ...)\ |
| 6824 | INTERNAL_CATCH_EXPAND_VARGS( INTERNAL_CATCH_TEMPLATE_PRODUCT_TEST_CASE2( INTERNAL_CATCH_UNIQUE_NAME( CATCH2_INTERNAL_TEMPLATE_TEST_ ), INTERNAL_CATCH_UNIQUE_NAME( CATCH2_INTERNAL_TEMPLATE_TEST_ ), Name, Tags, typename T, __VA_ARGS__ ) ) |
| 6825 | #endif |
| 6826 | |
| 6827 | #ifndef CATCH_CONFIG_TRADITIONAL_MSVC_PREPROCESSOR |
| 6828 | #define INTERNAL_CATCH_TEMPLATE_PRODUCT_TEST_CASE_SIG(Name, Tags, Signature, ...)\ |
| 6829 | INTERNAL_CATCH_TEMPLATE_PRODUCT_TEST_CASE2(INTERNAL_CATCH_UNIQUE_NAME( CATCH2_INTERNAL_TEMPLATE_TEST_ ), INTERNAL_CATCH_UNIQUE_NAME( CATCH2_INTERNAL_TEMPLATE_TEST_ ), Name, Tags, Signature, __VA_ARGS__) |
| 6830 | #else |
| 6831 | #define INTERNAL_CATCH_TEMPLATE_PRODUCT_TEST_CASE_SIG(Name, Tags, Signature, ...)\ |
| 6832 | INTERNAL_CATCH_EXPAND_VARGS( INTERNAL_CATCH_TEMPLATE_PRODUCT_TEST_CASE2( INTERNAL_CATCH_UNIQUE_NAME( CATCH2_INTERNAL_TEMPLATE_TEST_ ), INTERNAL_CATCH_UNIQUE_NAME( CATCH2_INTERNAL_TEMPLATE_TEST_ ), Name, Tags, Signature, __VA_ARGS__ ) ) |
| 6833 | #endif |
| 6834 | |
| 6835 | #define INTERNAL_CATCH_TEMPLATE_LIST_TEST_CASE_2(TestName, TestFunc, Name, Tags, TmplList)\ |
| 6836 | CATCH_INTERNAL_START_WARNINGS_SUPPRESSION \ |
| 6837 | CATCH_INTERNAL_SUPPRESS_GLOBALS_WARNINGS \ |
| 6838 | CATCH_INTERNAL_SUPPRESS_UNUSED_TEMPLATE_WARNINGS \ |
| 6839 | CATCH_INTERNAL_SUPPRESS_UNUSED_VARIABLE_WARNINGS \ |
| 6840 | CATCH_INTERNAL_SUPPRESS_COMMA_WARNINGS \ |
| 6841 | template<typename TestType> static void TestFunc(); \ |
| 6842 | namespace {\ |
| 6843 | namespace INTERNAL_CATCH_MAKE_NAMESPACE(TestName){\ |
| 6844 | INTERNAL_CATCH_TYPE_GEN\ |
| 6845 | template<typename... Types> \ |
| 6846 | struct TestName { \ |
| 6847 | void reg_tests() { \ |
| 6848 | size_t index = 0; \ |
| 6849 | using expander = size_t[]; \ |
| 6850 | (void)expander{(Catch::AutoReg( Catch::makeTestInvoker( &TestFunc<Types> ), CATCH_INTERNAL_LINEINFO, Catch::StringRef(), Catch::NameAndTags{ Name " - " INTERNAL_CATCH_STRINGIZE(TmplList) " - " + std::to_string(index), Tags } ), index++)... };/* NOLINT */\ |
| 6851 | } \ |
| 6852 | };\ |
| 6853 | static int INTERNAL_CATCH_UNIQUE_NAME( globalRegistrar ) = [](){ \ |
| 6854 | using TestInit = typename convert<TestName, TmplList>::type; \ |
| 6855 | TestInit t; \ |
| 6856 | t.reg_tests(); \ |
| 6857 | return 0; \ |
| 6858 | }(); \ |
| 6859 | }}\ |
| 6860 | CATCH_INTERNAL_STOP_WARNINGS_SUPPRESSION \ |
| 6861 | template<typename TestType> \ |
| 6862 | static void TestFunc() |
| 6863 | |
| 6864 | #define INTERNAL_CATCH_TEMPLATE_LIST_TEST_CASE(Name, Tags, TmplList) \ |
| 6865 | INTERNAL_CATCH_TEMPLATE_LIST_TEST_CASE_2( INTERNAL_CATCH_UNIQUE_NAME( CATCH2_INTERNAL_TEMPLATE_TEST_ ), INTERNAL_CATCH_UNIQUE_NAME( CATCH2_INTERNAL_TEMPLATE_TEST_ ), Name, Tags, TmplList ) |
| 6866 | |
| 6867 | |
| 6868 | #define INTERNAL_CATCH_TEMPLATE_TEST_CASE_METHOD_2( TestNameClass, TestName, ClassName, Name, Tags, Signature, ... ) \ |
| 6869 | CATCH_INTERNAL_START_WARNINGS_SUPPRESSION \ |
| 6870 | CATCH_INTERNAL_SUPPRESS_GLOBALS_WARNINGS \ |
| 6871 | CATCH_INTERNAL_SUPPRESS_ZERO_VARIADIC_WARNINGS \ |
| 6872 | CATCH_INTERNAL_SUPPRESS_UNUSED_TEMPLATE_WARNINGS \ |
| 6873 | CATCH_INTERNAL_SUPPRESS_UNUSED_VARIABLE_WARNINGS \ |
| 6874 | namespace {\ |
| 6875 | namespace INTERNAL_CATCH_MAKE_NAMESPACE(TestName){ \ |
| 6876 | INTERNAL_CATCH_TYPE_GEN\ |
| 6877 | INTERNAL_CATCH_NTTP_GEN(INTERNAL_CATCH_REMOVE_PARENS(Signature))\ |
| 6878 | INTERNAL_CATCH_DECLARE_SIG_TEST_METHOD(TestName, ClassName, INTERNAL_CATCH_REMOVE_PARENS(Signature));\ |
| 6879 | INTERNAL_CATCH_NTTP_REG_METHOD_GEN(TestName, INTERNAL_CATCH_REMOVE_PARENS(Signature))\ |
| 6880 | template<typename...Types> \ |
| 6881 | struct TestNameClass{\ |
| 6882 | TestNameClass(){\ |
| 6883 | size_t index = 0; \ |
| 6884 | constexpr char const* tmpl_types[] = {CATCH_REC_LIST(INTERNAL_CATCH_STRINGIZE_WITHOUT_PARENS, __VA_ARGS__)};\ |
| 6885 | using expander = size_t[];\ |
| 6886 | (void)expander{(reg_test(Types{}, #ClassName, Catch::NameAndTags{ Name " - " + std::string(tmpl_types[index]), Tags } ), index++)... };/* NOLINT */ \ |
| 6887 | }\ |
| 6888 | };\ |
| 6889 | static int INTERNAL_CATCH_UNIQUE_NAME( globalRegistrar ) = [](){\ |
| 6890 | TestNameClass<INTERNAL_CATCH_MAKE_TYPE_LISTS_FROM_TYPES(__VA_ARGS__)>();\ |
| 6891 | return 0;\ |
| 6892 | }();\ |
| 6893 | }\ |
| 6894 | }\ |
| 6895 | CATCH_INTERNAL_STOP_WARNINGS_SUPPRESSION \ |
| 6896 | INTERNAL_CATCH_DEFINE_SIG_TEST_METHOD(TestName, INTERNAL_CATCH_REMOVE_PARENS(Signature)) |
| 6897 | |
| 6898 | #ifndef CATCH_CONFIG_TRADITIONAL_MSVC_PREPROCESSOR |
| 6899 | #define INTERNAL_CATCH_TEMPLATE_TEST_CASE_METHOD( ClassName, Name, Tags,... ) \ |
| 6900 | INTERNAL_CATCH_TEMPLATE_TEST_CASE_METHOD_2( INTERNAL_CATCH_UNIQUE_NAME( CATCH2_INTERNAL_TEMPLATE_TEST_CLASS_ ), INTERNAL_CATCH_UNIQUE_NAME( CATCH2_INTERNAL_TEMPLATE_TEST_ ) , ClassName, Name, Tags, typename T, __VA_ARGS__ ) |
| 6901 | #else |
| 6902 | #define INTERNAL_CATCH_TEMPLATE_TEST_CASE_METHOD( ClassName, Name, Tags,... ) \ |
| 6903 | INTERNAL_CATCH_EXPAND_VARGS( INTERNAL_CATCH_TEMPLATE_TEST_CASE_METHOD_2( INTERNAL_CATCH_UNIQUE_NAME( CATCH2_INTERNAL_TEMPLATE_TEST_CLASS_ ), INTERNAL_CATCH_UNIQUE_NAME( CATCH2_INTERNAL_TEMPLATE_TEST_ ) , ClassName, Name, Tags, typename T, __VA_ARGS__ ) ) |
| 6904 | #endif |
| 6905 | |
| 6906 | #ifndef CATCH_CONFIG_TRADITIONAL_MSVC_PREPROCESSOR |
| 6907 | #define INTERNAL_CATCH_TEMPLATE_TEST_CASE_METHOD_SIG( ClassName, Name, Tags, Signature, ... ) \ |
| 6908 | INTERNAL_CATCH_TEMPLATE_TEST_CASE_METHOD_2( INTERNAL_CATCH_UNIQUE_NAME( CATCH2_INTERNAL_TEMPLATE_TEST_CLASS_ ), INTERNAL_CATCH_UNIQUE_NAME( CATCH2_INTERNAL_TEMPLATE_TEST_ ) , ClassName, Name, Tags, Signature, __VA_ARGS__ ) |
| 6909 | #else |
| 6910 | #define INTERNAL_CATCH_TEMPLATE_TEST_CASE_METHOD_SIG( ClassName, Name, Tags, Signature, ... ) \ |
| 6911 | INTERNAL_CATCH_EXPAND_VARGS( INTERNAL_CATCH_TEMPLATE_TEST_CASE_METHOD_2( INTERNAL_CATCH_UNIQUE_NAME( CATCH2_INTERNAL_TEMPLATE_TEST_CLASS_ ), INTERNAL_CATCH_UNIQUE_NAME( CATCH2_INTERNAL_TEMPLATE_TEST_ ) , ClassName, Name, Tags, Signature, __VA_ARGS__ ) ) |
| 6912 | #endif |
| 6913 | |
| 6914 | #define INTERNAL_CATCH_TEMPLATE_PRODUCT_TEST_CASE_METHOD_2(TestNameClass, TestName, ClassName, Name, Tags, Signature, TmplTypes, TypesList)\ |
| 6915 | CATCH_INTERNAL_START_WARNINGS_SUPPRESSION \ |
| 6916 | CATCH_INTERNAL_SUPPRESS_GLOBALS_WARNINGS \ |
| 6917 | CATCH_INTERNAL_SUPPRESS_ZERO_VARIADIC_WARNINGS \ |
| 6918 | CATCH_INTERNAL_SUPPRESS_UNUSED_TEMPLATE_WARNINGS \ |
| 6919 | CATCH_INTERNAL_SUPPRESS_UNUSED_VARIABLE_WARNINGS \ |
| 6920 | template<typename TestType> \ |
| 6921 | struct TestName : INTERNAL_CATCH_REMOVE_PARENS(ClassName <TestType>) { \ |
| 6922 | void test();\ |
| 6923 | };\ |
| 6924 | namespace {\ |
| 6925 | namespace INTERNAL_CATCH_MAKE_NAMESPACE(TestNameClass) {\ |
| 6926 | INTERNAL_CATCH_TYPE_GEN \ |
| 6927 | INTERNAL_CATCH_NTTP_GEN(INTERNAL_CATCH_REMOVE_PARENS(Signature))\ |
| 6928 | template<typename...Types>\ |
| 6929 | struct TestNameClass{\ |
| 6930 | void reg_tests(){\ |
| 6931 | std::size_t index = 0;\ |
| 6932 | using expander = std::size_t[];\ |
| 6933 | constexpr char const* tmpl_types[] = {CATCH_REC_LIST(INTERNAL_CATCH_STRINGIZE_WITHOUT_PARENS, INTERNAL_CATCH_REMOVE_PARENS(TmplTypes))};\ |
| 6934 | constexpr char const* types_list[] = {CATCH_REC_LIST(INTERNAL_CATCH_STRINGIZE_WITHOUT_PARENS, INTERNAL_CATCH_REMOVE_PARENS(TypesList))};\ |
| 6935 | constexpr auto num_types = sizeof(types_list) / sizeof(types_list[0]);\ |
| 6936 | (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++)... };/* NOLINT */ \ |
| 6937 | }\ |
| 6938 | };\ |
| 6939 | static int INTERNAL_CATCH_UNIQUE_NAME( globalRegistrar ) = [](){\ |
| 6940 | 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;\ |
| 6941 | TestInit t;\ |
| 6942 | t.reg_tests();\ |
| 6943 | return 0;\ |
| 6944 | }(); \ |
| 6945 | }\ |
| 6946 | }\ |
| 6947 | CATCH_INTERNAL_STOP_WARNINGS_SUPPRESSION \ |
| 6948 | template<typename TestType> \ |
| 6949 | void TestName<TestType>::test() |
| 6950 | |
| 6951 | #ifndef CATCH_CONFIG_TRADITIONAL_MSVC_PREPROCESSOR |
| 6952 | #define INTERNAL_CATCH_TEMPLATE_PRODUCT_TEST_CASE_METHOD( ClassName, Name, Tags, ... )\ |
| 6953 | INTERNAL_CATCH_TEMPLATE_PRODUCT_TEST_CASE_METHOD_2( INTERNAL_CATCH_UNIQUE_NAME( CATCH2_INTERNAL_TEMPLATE_TEST_ ), INTERNAL_CATCH_UNIQUE_NAME( CATCH2_INTERNAL_TEMPLATE_TEST_ ), ClassName, Name, Tags, typename T, __VA_ARGS__ ) |
| 6954 | #else |
| 6955 | #define INTERNAL_CATCH_TEMPLATE_PRODUCT_TEST_CASE_METHOD( ClassName, Name, Tags, ... )\ |
| 6956 | INTERNAL_CATCH_EXPAND_VARGS( INTERNAL_CATCH_TEMPLATE_PRODUCT_TEST_CASE_METHOD_2( INTERNAL_CATCH_UNIQUE_NAME( CATCH2_INTERNAL_TEMPLATE_TEST_ ), INTERNAL_CATCH_UNIQUE_NAME( CATCH2_INTERNAL_TEMPLATE_TEST_ ), ClassName, Name, Tags, typename T,__VA_ARGS__ ) ) |
| 6957 | #endif |
| 6958 | |
| 6959 | #ifndef CATCH_CONFIG_TRADITIONAL_MSVC_PREPROCESSOR |
| 6960 | #define INTERNAL_CATCH_TEMPLATE_PRODUCT_TEST_CASE_METHOD_SIG( ClassName, Name, Tags, Signature, ... )\ |
| 6961 | INTERNAL_CATCH_TEMPLATE_PRODUCT_TEST_CASE_METHOD_2( INTERNAL_CATCH_UNIQUE_NAME( CATCH2_INTERNAL_TEMPLATE_TEST_ ), INTERNAL_CATCH_UNIQUE_NAME( CATCH2_INTERNAL_TEMPLATE_TEST_ ), ClassName, Name, Tags, Signature, __VA_ARGS__ ) |
| 6962 | #else |
| 6963 | #define INTERNAL_CATCH_TEMPLATE_PRODUCT_TEST_CASE_METHOD_SIG( ClassName, Name, Tags, Signature, ... )\ |
| 6964 | INTERNAL_CATCH_EXPAND_VARGS( INTERNAL_CATCH_TEMPLATE_PRODUCT_TEST_CASE_METHOD_2( INTERNAL_CATCH_UNIQUE_NAME( CATCH2_INTERNAL_TEMPLATE_TEST_ ), INTERNAL_CATCH_UNIQUE_NAME( CATCH2_INTERNAL_TEMPLATE_TEST_ ), ClassName, Name, Tags, Signature,__VA_ARGS__ ) ) |
| 6965 | #endif |
| 6966 | |
| 6967 | #define INTERNAL_CATCH_TEMPLATE_LIST_TEST_CASE_METHOD_2( TestNameClass, TestName, ClassName, Name, Tags, TmplList) \ |
| 6968 | CATCH_INTERNAL_START_WARNINGS_SUPPRESSION \ |
| 6969 | CATCH_INTERNAL_SUPPRESS_GLOBALS_WARNINGS \ |
| 6970 | CATCH_INTERNAL_SUPPRESS_UNUSED_TEMPLATE_WARNINGS \ |
| 6971 | CATCH_INTERNAL_SUPPRESS_UNUSED_VARIABLE_WARNINGS \ |
| 6972 | CATCH_INTERNAL_SUPPRESS_COMMA_WARNINGS \ |
| 6973 | template<typename TestType> \ |
| 6974 | struct TestName : INTERNAL_CATCH_REMOVE_PARENS(ClassName <TestType>) { \ |
| 6975 | void test();\ |
| 6976 | };\ |
| 6977 | namespace {\ |
| 6978 | namespace INTERNAL_CATCH_MAKE_NAMESPACE(TestName){ \ |
| 6979 | INTERNAL_CATCH_TYPE_GEN\ |
| 6980 | template<typename...Types>\ |
| 6981 | struct TestNameClass{\ |
| 6982 | void reg_tests(){\ |
| 6983 | size_t index = 0;\ |
| 6984 | using expander = size_t[];\ |
| 6985 | (void)expander{(Catch::AutoReg( Catch::makeTestInvoker( &TestName<Types>::test ), CATCH_INTERNAL_LINEINFO, #ClassName##_catch_sr, Catch::NameAndTags{ Name " - " INTERNAL_CATCH_STRINGIZE(TmplList) " - " + std::to_string(index), Tags } ), index++)... };/* NOLINT */ \ |
| 6986 | }\ |
| 6987 | };\ |
| 6988 | static int INTERNAL_CATCH_UNIQUE_NAME( globalRegistrar ) = [](){\ |
| 6989 | using TestInit = typename convert<TestNameClass, TmplList>::type;\ |
| 6990 | TestInit t;\ |
| 6991 | t.reg_tests();\ |
| 6992 | return 0;\ |
| 6993 | }(); \ |
| 6994 | }}\ |
| 6995 | CATCH_INTERNAL_STOP_WARNINGS_SUPPRESSION \ |
| 6996 | template<typename TestType> \ |
| 6997 | void TestName<TestType>::test() |
| 6998 | |
| 6999 | #define INTERNAL_CATCH_TEMPLATE_LIST_TEST_CASE_METHOD(ClassName, Name, Tags, TmplList) \ |
| 7000 | INTERNAL_CATCH_TEMPLATE_LIST_TEST_CASE_METHOD_2( INTERNAL_CATCH_UNIQUE_NAME( CATCH2_INTERNAL_TEMPLATE_TEST_ ), INTERNAL_CATCH_UNIQUE_NAME( CATCH2_INTERNAL_TEMPLATE_TEST_ ), ClassName, Name, Tags, TmplList ) |
| 7001 | |
| 7002 | |
| 7003 | #endif // CATCH_TEMPLATE_TEST_REGISTRY_HPP_INCLUDED |
| 7004 | |
| 7005 | |
| 7006 | #if defined(CATCH_CONFIG_PREFIX_ALL) && !defined(CATCH_CONFIG_DISABLE) |
| 7007 | |
| 7008 | #ifndef CATCH_CONFIG_TRADITIONAL_MSVC_PREPROCESSOR |
| 7009 | #define CATCH_TEMPLATE_TEST_CASE( ... ) INTERNAL_CATCH_TEMPLATE_TEST_CASE( __VA_ARGS__ ) |
| 7010 | #define CATCH_TEMPLATE_TEST_CASE_SIG( ... ) INTERNAL_CATCH_TEMPLATE_TEST_CASE_SIG( __VA_ARGS__ ) |
| 7011 | #define CATCH_TEMPLATE_TEST_CASE_METHOD( className, ... ) INTERNAL_CATCH_TEMPLATE_TEST_CASE_METHOD( className, __VA_ARGS__ ) |
| 7012 | #define CATCH_TEMPLATE_TEST_CASE_METHOD_SIG( className, ... ) INTERNAL_CATCH_TEMPLATE_TEST_CASE_METHOD_SIG( className, __VA_ARGS__ ) |
| 7013 | #define CATCH_TEMPLATE_PRODUCT_TEST_CASE( ... ) INTERNAL_CATCH_TEMPLATE_PRODUCT_TEST_CASE( __VA_ARGS__ ) |
| 7014 | #define CATCH_TEMPLATE_PRODUCT_TEST_CASE_SIG( ... ) INTERNAL_CATCH_TEMPLATE_PRODUCT_TEST_CASE_SIG( __VA_ARGS__ ) |
| 7015 | #define CATCH_TEMPLATE_PRODUCT_TEST_CASE_METHOD( className, ... ) INTERNAL_CATCH_TEMPLATE_PRODUCT_TEST_CASE_METHOD( className, __VA_ARGS__ ) |
| 7016 | #define CATCH_TEMPLATE_PRODUCT_TEST_CASE_METHOD_SIG( className, ... ) INTERNAL_CATCH_TEMPLATE_PRODUCT_TEST_CASE_METHOD_SIG( className, __VA_ARGS__ ) |
| 7017 | #define CATCH_TEMPLATE_LIST_TEST_CASE( ... ) INTERNAL_CATCH_TEMPLATE_LIST_TEST_CASE(__VA_ARGS__) |
| 7018 | #define CATCH_TEMPLATE_LIST_TEST_CASE_METHOD( className, ... ) INTERNAL_CATCH_TEMPLATE_LIST_TEST_CASE_METHOD( className, __VA_ARGS__ ) |
| 7019 | #else |
| 7020 | #define CATCH_TEMPLATE_TEST_CASE( ... ) INTERNAL_CATCH_EXPAND_VARGS( INTERNAL_CATCH_TEMPLATE_TEST_CASE( __VA_ARGS__ ) ) |
| 7021 | #define CATCH_TEMPLATE_TEST_CASE_SIG( ... ) INTERNAL_CATCH_EXPAND_VARGS( INTERNAL_CATCH_TEMPLATE_TEST_CASE_SIG( __VA_ARGS__ ) ) |
| 7022 | #define CATCH_TEMPLATE_TEST_CASE_METHOD( className, ... ) INTERNAL_CATCH_EXPAND_VARGS( INTERNAL_CATCH_TEMPLATE_TEST_CASE_METHOD( className, __VA_ARGS__ ) ) |
| 7023 | #define CATCH_TEMPLATE_TEST_CASE_METHOD_SIG( className, ... ) INTERNAL_CATCH_EXPAND_VARGS( INTERNAL_CATCH_TEMPLATE_TEST_CASE_METHOD_SIG( className, __VA_ARGS__ ) ) |
| 7024 | #define CATCH_TEMPLATE_PRODUCT_TEST_CASE( ... ) INTERNAL_CATCH_EXPAND_VARGS( INTERNAL_CATCH_TEMPLATE_PRODUCT_TEST_CASE( __VA_ARGS__ ) ) |
| 7025 | #define CATCH_TEMPLATE_PRODUCT_TEST_CASE_SIG( ... ) INTERNAL_CATCH_EXPAND_VARGS( INTERNAL_CATCH_TEMPLATE_PRODUCT_TEST_CASE_SIG( __VA_ARGS__ ) ) |
| 7026 | #define CATCH_TEMPLATE_PRODUCT_TEST_CASE_METHOD( className, ... ) INTERNAL_CATCH_EXPAND_VARGS( INTERNAL_CATCH_TEMPLATE_PRODUCT_TEST_CASE_METHOD( className, __VA_ARGS__ ) ) |
| 7027 | #define CATCH_TEMPLATE_PRODUCT_TEST_CASE_METHOD_SIG( className, ... ) INTERNAL_CATCH_EXPAND_VARGS( INTERNAL_CATCH_TEMPLATE_PRODUCT_TEST_CASE_METHOD_SIG( className, __VA_ARGS__ ) ) |
| 7028 | #define CATCH_TEMPLATE_LIST_TEST_CASE( ... ) INTERNAL_CATCH_EXPAND_VARGS( INTERNAL_CATCH_TEMPLATE_LIST_TEST_CASE( __VA_ARGS__ ) ) |
| 7029 | #define CATCH_TEMPLATE_LIST_TEST_CASE_METHOD( className, ... ) INTERNAL_CATCH_EXPAND_VARGS( INTERNAL_CATCH_TEMPLATE_LIST_TEST_CASE_METHOD( className, __VA_ARGS__ ) ) |
| 7030 | #endif |
| 7031 | |
| 7032 | #elif defined(CATCH_CONFIG_PREFIX_ALL) && defined(CATCH_CONFIG_DISABLE) |
| 7033 | |
| 7034 | #ifndef CATCH_CONFIG_TRADITIONAL_MSVC_PREPROCESSOR |
| 7035 | #define CATCH_TEMPLATE_TEST_CASE( ... ) INTERNAL_CATCH_TEMPLATE_TEST_CASE_NO_REGISTRATION(__VA_ARGS__) |
| 7036 | #define CATCH_TEMPLATE_TEST_CASE_SIG( ... ) INTERNAL_CATCH_TEMPLATE_TEST_CASE_SIG_NO_REGISTRATION(__VA_ARGS__) |
| 7037 | #define CATCH_TEMPLATE_TEST_CASE_METHOD( className, ... ) INTERNAL_CATCH_TEMPLATE_TEST_CASE_METHOD_NO_REGISTRATION(className, __VA_ARGS__) |
| 7038 | #define CATCH_TEMPLATE_TEST_CASE_METHOD_SIG( className, ... ) INTERNAL_CATCH_TEMPLATE_TEST_CASE_METHOD_SIG_NO_REGISTRATION(className, __VA_ARGS__ ) |
| 7039 | #else |
| 7040 | #define CATCH_TEMPLATE_TEST_CASE( ... ) INTERNAL_CATCH_EXPAND_VARGS( INTERNAL_CATCH_TEMPLATE_TEST_CASE_NO_REGISTRATION(__VA_ARGS__) ) |
| 7041 | #define CATCH_TEMPLATE_TEST_CASE_SIG( ... ) INTERNAL_CATCH_EXPAND_VARGS( INTERNAL_CATCH_TEMPLATE_TEST_CASE_SIG_NO_REGISTRATION(__VA_ARGS__) ) |
| 7042 | #define CATCH_TEMPLATE_TEST_CASE_METHOD( className, ... ) INTERNAL_CATCH_EXPAND_VARGS( INTERNAL_CATCH_TEMPLATE_TEST_CASE_METHOD_NO_REGISTRATION(className, __VA_ARGS__ ) ) |
| 7043 | #define CATCH_TEMPLATE_TEST_CASE_METHOD_SIG( className, ... ) INTERNAL_CATCH_EXPAND_VARGS( INTERNAL_CATCH_TEMPLATE_TEST_CASE_METHOD_SIG_NO_REGISTRATION(className, __VA_ARGS__ ) ) |
| 7044 | #endif |
| 7045 | |
| 7046 | // When disabled, these can be shared between proper preprocessor and MSVC preprocessor |
| 7047 | #define CATCH_TEMPLATE_PRODUCT_TEST_CASE( ... ) CATCH_TEMPLATE_TEST_CASE( __VA_ARGS__ ) |
| 7048 | #define CATCH_TEMPLATE_PRODUCT_TEST_CASE_SIG( ... ) CATCH_TEMPLATE_TEST_CASE( __VA_ARGS__ ) |
| 7049 | #define CATCH_TEMPLATE_PRODUCT_TEST_CASE_METHOD( className, ... ) CATCH_TEMPLATE_TEST_CASE_METHOD( className, __VA_ARGS__ ) |
| 7050 | #define CATCH_TEMPLATE_PRODUCT_TEST_CASE_METHOD_SIG( className, ... ) CATCH_TEMPLATE_TEST_CASE_METHOD( className, __VA_ARGS__ ) |
| 7051 | #define CATCH_TEMPLATE_LIST_TEST_CASE( ... ) CATCH_TEMPLATE_TEST_CASE(__VA_ARGS__) |
| 7052 | #define CATCH_TEMPLATE_LIST_TEST_CASE_METHOD( className, ... ) CATCH_TEMPLATE_TEST_CASE_METHOD( className, __VA_ARGS__ ) |
| 7053 | |
| 7054 | #elif !defined(CATCH_CONFIG_PREFIX_ALL) && !defined(CATCH_CONFIG_DISABLE) |
| 7055 | |
| 7056 | #ifndef CATCH_CONFIG_TRADITIONAL_MSVC_PREPROCESSOR |
| 7057 | #define TEMPLATE_TEST_CASE( ... ) INTERNAL_CATCH_TEMPLATE_TEST_CASE( __VA_ARGS__ ) |
| 7058 | #define TEMPLATE_TEST_CASE_SIG( ... ) INTERNAL_CATCH_TEMPLATE_TEST_CASE_SIG( __VA_ARGS__ ) |
| 7059 | #define TEMPLATE_TEST_CASE_METHOD( className, ... ) INTERNAL_CATCH_TEMPLATE_TEST_CASE_METHOD( className, __VA_ARGS__ ) |
| 7060 | #define TEMPLATE_TEST_CASE_METHOD_SIG( className, ... ) INTERNAL_CATCH_TEMPLATE_TEST_CASE_METHOD_SIG( className, __VA_ARGS__ ) |
| 7061 | #define TEMPLATE_PRODUCT_TEST_CASE( ... ) INTERNAL_CATCH_TEMPLATE_PRODUCT_TEST_CASE( __VA_ARGS__ ) |
| 7062 | #define TEMPLATE_PRODUCT_TEST_CASE_SIG( ... ) INTERNAL_CATCH_TEMPLATE_PRODUCT_TEST_CASE_SIG( __VA_ARGS__ ) |
| 7063 | #define TEMPLATE_PRODUCT_TEST_CASE_METHOD( className, ... ) INTERNAL_CATCH_TEMPLATE_PRODUCT_TEST_CASE_METHOD( className, __VA_ARGS__ ) |
| 7064 | #define TEMPLATE_PRODUCT_TEST_CASE_METHOD_SIG( className, ... ) INTERNAL_CATCH_TEMPLATE_PRODUCT_TEST_CASE_METHOD_SIG( className, __VA_ARGS__ ) |
| 7065 | #define TEMPLATE_LIST_TEST_CASE( ... ) INTERNAL_CATCH_TEMPLATE_LIST_TEST_CASE(__VA_ARGS__) |
| 7066 | #define TEMPLATE_LIST_TEST_CASE_METHOD( className, ... ) INTERNAL_CATCH_TEMPLATE_LIST_TEST_CASE_METHOD( className, __VA_ARGS__ ) |
| 7067 | #else |
| 7068 | #define TEMPLATE_TEST_CASE( ... ) INTERNAL_CATCH_EXPAND_VARGS( INTERNAL_CATCH_TEMPLATE_TEST_CASE( __VA_ARGS__ ) ) |
| 7069 | #define TEMPLATE_TEST_CASE_SIG( ... ) INTERNAL_CATCH_EXPAND_VARGS( INTERNAL_CATCH_TEMPLATE_TEST_CASE_SIG( __VA_ARGS__ ) ) |
| 7070 | #define TEMPLATE_TEST_CASE_METHOD( className, ... ) INTERNAL_CATCH_EXPAND_VARGS( INTERNAL_CATCH_TEMPLATE_TEST_CASE_METHOD( className, __VA_ARGS__ ) ) |
| 7071 | #define TEMPLATE_TEST_CASE_METHOD_SIG( className, ... ) INTERNAL_CATCH_EXPAND_VARGS( INTERNAL_CATCH_TEMPLATE_TEST_CASE_METHOD_SIG( className, __VA_ARGS__ ) ) |
| 7072 | #define TEMPLATE_PRODUCT_TEST_CASE( ... ) INTERNAL_CATCH_EXPAND_VARGS( INTERNAL_CATCH_TEMPLATE_PRODUCT_TEST_CASE( __VA_ARGS__ ) ) |
| 7073 | #define TEMPLATE_PRODUCT_TEST_CASE_SIG( ... ) INTERNAL_CATCH_EXPAND_VARGS( INTERNAL_CATCH_TEMPLATE_PRODUCT_TEST_CASE_SIG( __VA_ARGS__ ) ) |
| 7074 | #define TEMPLATE_PRODUCT_TEST_CASE_METHOD( className, ... ) INTERNAL_CATCH_EXPAND_VARGS( INTERNAL_CATCH_TEMPLATE_PRODUCT_TEST_CASE_METHOD( className, __VA_ARGS__ ) ) |
| 7075 | #define TEMPLATE_PRODUCT_TEST_CASE_METHOD_SIG( className, ... ) INTERNAL_CATCH_EXPAND_VARGS( INTERNAL_CATCH_TEMPLATE_PRODUCT_TEST_CASE_METHOD_SIG( className, __VA_ARGS__ ) ) |
| 7076 | #define TEMPLATE_LIST_TEST_CASE( ... ) INTERNAL_CATCH_EXPAND_VARGS( INTERNAL_CATCH_TEMPLATE_LIST_TEST_CASE( __VA_ARGS__ ) ) |
| 7077 | #define TEMPLATE_LIST_TEST_CASE_METHOD( className, ... ) INTERNAL_CATCH_EXPAND_VARGS( INTERNAL_CATCH_TEMPLATE_LIST_TEST_CASE_METHOD( className, __VA_ARGS__ ) ) |
| 7078 | #endif |
| 7079 | |
| 7080 | #elif !defined(CATCH_CONFIG_PREFIX_ALL) && defined(CATCH_CONFIG_DISABLE) |
| 7081 | |
| 7082 | #ifndef CATCH_CONFIG_TRADITIONAL_MSVC_PREPROCESSOR |
| 7083 | #define TEMPLATE_TEST_CASE( ... ) INTERNAL_CATCH_TEMPLATE_TEST_CASE_NO_REGISTRATION(__VA_ARGS__) |
| 7084 | #define TEMPLATE_TEST_CASE_SIG( ... ) INTERNAL_CATCH_TEMPLATE_TEST_CASE_SIG_NO_REGISTRATION(__VA_ARGS__) |
| 7085 | #define TEMPLATE_TEST_CASE_METHOD( className, ... ) INTERNAL_CATCH_TEMPLATE_TEST_CASE_METHOD_NO_REGISTRATION(className, __VA_ARGS__) |
| 7086 | #define TEMPLATE_TEST_CASE_METHOD_SIG( className, ... ) INTERNAL_CATCH_TEMPLATE_TEST_CASE_METHOD_SIG_NO_REGISTRATION(className, __VA_ARGS__ ) |
| 7087 | #else |
| 7088 | #define TEMPLATE_TEST_CASE( ... ) INTERNAL_CATCH_EXPAND_VARGS( INTERNAL_CATCH_TEMPLATE_TEST_CASE_NO_REGISTRATION(__VA_ARGS__) ) |
| 7089 | #define TEMPLATE_TEST_CASE_SIG( ... ) INTERNAL_CATCH_EXPAND_VARGS( INTERNAL_CATCH_TEMPLATE_TEST_CASE_SIG_NO_REGISTRATION(__VA_ARGS__) ) |
| 7090 | #define TEMPLATE_TEST_CASE_METHOD( className, ... ) INTERNAL_CATCH_EXPAND_VARGS( INTERNAL_CATCH_TEMPLATE_TEST_CASE_METHOD_NO_REGISTRATION(className, __VA_ARGS__ ) ) |
| 7091 | #define TEMPLATE_TEST_CASE_METHOD_SIG( className, ... ) INTERNAL_CATCH_EXPAND_VARGS( INTERNAL_CATCH_TEMPLATE_TEST_CASE_METHOD_SIG_NO_REGISTRATION(className, __VA_ARGS__ ) ) |
| 7092 | #endif |
| 7093 | |
| 7094 | // When disabled, these can be shared between proper preprocessor and MSVC preprocessor |
| 7095 | #define TEMPLATE_PRODUCT_TEST_CASE( ... ) TEMPLATE_TEST_CASE( __VA_ARGS__ ) |
| 7096 | #define TEMPLATE_PRODUCT_TEST_CASE_SIG( ... ) TEMPLATE_TEST_CASE( __VA_ARGS__ ) |
| 7097 | #define TEMPLATE_PRODUCT_TEST_CASE_METHOD( className, ... ) TEMPLATE_TEST_CASE_METHOD( className, __VA_ARGS__ ) |
| 7098 | #define TEMPLATE_PRODUCT_TEST_CASE_METHOD_SIG( className, ... ) TEMPLATE_TEST_CASE_METHOD( className, __VA_ARGS__ ) |
| 7099 | #define TEMPLATE_LIST_TEST_CASE( ... ) TEMPLATE_TEST_CASE(__VA_ARGS__) |
| 7100 | #define TEMPLATE_LIST_TEST_CASE_METHOD( className, ... ) TEMPLATE_TEST_CASE_METHOD( className, __VA_ARGS__ ) |
| 7101 | |
| 7102 | #endif // end of user facing macro declarations |
| 7103 | |
| 7104 | |
| 7105 | #endif // CATCH_TEMPLATE_TEST_MACROS_HPP_INCLUDED |
| 7106 | |
| 7107 | |
| 7108 | #ifndef CATCH_TEST_CASE_INFO_HPP_INCLUDED |
| 7109 | #define CATCH_TEST_CASE_INFO_HPP_INCLUDED |
| 7110 | |
| 7111 | |
| 7112 | |
| 7113 | #include <cstdint> |
| 7114 | #include <string> |
| 7115 | #include <vector> |
| 7116 | |
| 7117 | #ifdef __clang__ |
| 7118 | #pragma clang diagnostic push |
| 7119 | #pragma clang diagnostic ignored "-Wpadded" |
| 7120 | #endif |
| 7121 | |
| 7122 | namespace Catch { |
| 7123 | |
| 7124 | /** |
| 7125 | * A **view** of a tag string that provides case insensitive comparisons |
| 7126 | * |
| 7127 | * Note that in Catch2 internals, the square brackets around tags are |
| 7128 | * not a part of tag's representation, so e.g. "[cool-tag]" is represented |
| 7129 | * as "cool-tag" internally. |
| 7130 | */ |
| 7131 | struct Tag { |
| 7132 | constexpr Tag(StringRef original_): |
| 7133 | original(original_) |
| 7134 | {} |
| 7135 | StringRef original; |
| 7136 | |
| 7137 | friend bool operator< ( Tag const& lhs, Tag const& rhs ); |
| 7138 | friend bool operator==( Tag const& lhs, Tag const& rhs ); |
| 7139 | }; |
| 7140 | |
| 7141 | class ITestInvoker; |
| 7142 | |
| 7143 | enum class TestCaseProperties : uint8_t { |
| 7144 | None = 0, |
| 7145 | IsHidden = 1 << 1, |
| 7146 | ShouldFail = 1 << 2, |
| 7147 | MayFail = 1 << 3, |
| 7148 | Throws = 1 << 4, |
| 7149 | NonPortable = 1 << 5, |
| 7150 | Benchmark = 1 << 6 |
| 7151 | }; |
| 7152 | |
| 7153 | /** |
| 7154 | * Various metadata about the test case. |
| 7155 | * |
| 7156 | * A test case is uniquely identified by its (class)name and tags |
| 7157 | * combination, with source location being ignored, and other properties |
| 7158 | * being determined from tags. |
| 7159 | * |
| 7160 | * Tags are kept sorted. |
| 7161 | */ |
| 7162 | struct TestCaseInfo : Detail::NonCopyable { |
| 7163 | |
| 7164 | TestCaseInfo(StringRef _className, |
| 7165 | NameAndTags const& _tags, |
| 7166 | SourceLineInfo const& _lineInfo); |
| 7167 | |
| 7168 | bool isHidden() const; |
| 7169 | bool throws() const; |
| 7170 | bool okToFail() const; |
| 7171 | bool expectedToFail() const; |
| 7172 | |
| 7173 | // Adds the tag(s) with test's filename (for the -# flag) |
| 7174 | void addFilenameTag(); |
| 7175 | |
| 7176 | //! Orders by name, classname and tags |
| 7177 | friend bool operator<( TestCaseInfo const& lhs, |
| 7178 | TestCaseInfo const& rhs ); |
| 7179 | |
| 7180 | |
| 7181 | std::string tagsAsString() const; |
| 7182 | |
| 7183 | std::string name; |
| 7184 | StringRef className; |
| 7185 | private: |
| 7186 | std::string backingTags; |
| 7187 | // Internally we copy tags to the backing storage and then add |
| 7188 | // refs to this storage to the tags vector. |
| 7189 | void internalAppendTag(StringRef tagString); |
| 7190 | public: |
| 7191 | std::vector<Tag> tags; |
| 7192 | SourceLineInfo lineInfo; |
| 7193 | TestCaseProperties properties = TestCaseProperties::None; |
| 7194 | }; |
| 7195 | |
| 7196 | /** |
| 7197 | * Wrapper over the test case information and the test case invoker |
| 7198 | * |
| 7199 | * Does not own either, and is specifically made to be cheap |
| 7200 | * to copy around. |
| 7201 | */ |
| 7202 | class TestCaseHandle { |
| 7203 | TestCaseInfo* m_info; |
| 7204 | ITestInvoker* m_invoker; |
| 7205 | public: |
| 7206 | TestCaseHandle(TestCaseInfo* info, ITestInvoker* invoker) : |
| 7207 | m_info(info), m_invoker(invoker) {} |
| 7208 | |
| 7209 | void invoke() const { |
| 7210 | m_invoker->invoke(); |
| 7211 | } |
| 7212 | |
| 7213 | TestCaseInfo const& getTestCaseInfo() const; |
| 7214 | }; |
| 7215 | |
| 7216 | Detail::unique_ptr<TestCaseInfo> |
| 7217 | makeTestCaseInfo( StringRef className, |
| 7218 | NameAndTags const& nameAndTags, |
| 7219 | SourceLineInfo const& lineInfo ); |
| 7220 | } |
| 7221 | |
| 7222 | #ifdef __clang__ |
| 7223 | #pragma clang diagnostic pop |
| 7224 | #endif |
| 7225 | |
| 7226 | #endif // CATCH_TEST_CASE_INFO_HPP_INCLUDED |
| 7227 | |
| 7228 | |
| 7229 | #ifndef CATCH_TRANSLATE_EXCEPTION_HPP_INCLUDED |
| 7230 | #define CATCH_TRANSLATE_EXCEPTION_HPP_INCLUDED |
| 7231 | |
| 7232 | |
| 7233 | |
| 7234 | #ifndef CATCH_INTERFACES_EXCEPTION_HPP_INCLUDED |
| 7235 | #define CATCH_INTERFACES_EXCEPTION_HPP_INCLUDED |
| 7236 | |
| 7237 | |
| 7238 | #include <string> |
| 7239 | #include <vector> |
| 7240 | |
| 7241 | namespace Catch { |
| 7242 | using exceptionTranslateFunction = std::string(*)(); |
| 7243 | |
| 7244 | class IExceptionTranslator; |
| 7245 | using ExceptionTranslators = std::vector<Detail::unique_ptr<IExceptionTranslator const>>; |
| 7246 | |
| 7247 | class IExceptionTranslator { |
| 7248 | public: |
| 7249 | virtual ~IExceptionTranslator(); // = default |
| 7250 | virtual std::string translate( ExceptionTranslators::const_iterator it, ExceptionTranslators::const_iterator itEnd ) const = 0; |
| 7251 | }; |
| 7252 | |
| 7253 | class IExceptionTranslatorRegistry { |
| 7254 | public: |
| 7255 | virtual ~IExceptionTranslatorRegistry(); // = default |
| 7256 | virtual std::string translateActiveException() const = 0; |
| 7257 | }; |
| 7258 | |
| 7259 | } // namespace Catch |
| 7260 | |
| 7261 | #endif // CATCH_INTERFACES_EXCEPTION_HPP_INCLUDED |
| 7262 | |
| 7263 | #include <exception> |
| 7264 | |
| 7265 | namespace Catch { |
| 7266 | namespace Detail { |
| 7267 | void registerTranslatorImpl( |
| 7268 | Detail::unique_ptr<IExceptionTranslator>&& translator ); |
| 7269 | } |
| 7270 | |
| 7271 | class ExceptionTranslatorRegistrar { |
| 7272 | template<typename T> |
| 7273 | class ExceptionTranslator : public IExceptionTranslator { |
| 7274 | public: |
| 7275 | |
| 7276 | ExceptionTranslator( std::string(*translateFunction)( T const& ) ) |
| 7277 | : m_translateFunction( translateFunction ) |
| 7278 | {} |
| 7279 | |
| 7280 | std::string translate( ExceptionTranslators::const_iterator it, ExceptionTranslators::const_iterator itEnd ) const override { |
| 7281 | #if !defined(CATCH_CONFIG_DISABLE_EXCEPTIONS) |
| 7282 | try { |
| 7283 | if( it == itEnd ) |
| 7284 | std::rethrow_exception(std::current_exception()); |
| 7285 | else |
| 7286 | return (*it)->translate( it+1, itEnd ); |
| 7287 | } |
| 7288 | catch( T const& ex ) { |
| 7289 | return m_translateFunction( ex ); |
| 7290 | } |
| 7291 | #else |
| 7292 | return "You should never get here!"; |
| 7293 | #endif |
| 7294 | } |
| 7295 | |
| 7296 | protected: |
| 7297 | std::string(*m_translateFunction)( T const& ); |
| 7298 | }; |
| 7299 | |
| 7300 | public: |
| 7301 | template<typename T> |
| 7302 | ExceptionTranslatorRegistrar( std::string(*translateFunction)( T const& ) ) { |
| 7303 | Detail::registerTranslatorImpl( |
| 7304 | Detail::make_unique<ExceptionTranslator<T>>( |
| 7305 | translateFunction ) ); |
| 7306 | } |
| 7307 | }; |
| 7308 | |
| 7309 | } // namespace Catch |
| 7310 | |
| 7311 | /////////////////////////////////////////////////////////////////////////////// |
| 7312 | #define INTERNAL_CATCH_TRANSLATE_EXCEPTION2( translatorName, signature ) \ |
| 7313 | static std::string translatorName( signature ); \ |
| 7314 | CATCH_INTERNAL_START_WARNINGS_SUPPRESSION \ |
| 7315 | CATCH_INTERNAL_SUPPRESS_GLOBALS_WARNINGS \ |
| 7316 | namespace{ Catch::ExceptionTranslatorRegistrar INTERNAL_CATCH_UNIQUE_NAME( catch_internal_ExceptionRegistrar )( &translatorName ); } \ |
| 7317 | CATCH_INTERNAL_STOP_WARNINGS_SUPPRESSION \ |
| 7318 | static std::string translatorName( signature ) |
| 7319 | |
| 7320 | #define INTERNAL_CATCH_TRANSLATE_EXCEPTION( signature ) INTERNAL_CATCH_TRANSLATE_EXCEPTION2( INTERNAL_CATCH_UNIQUE_NAME( catch_internal_ExceptionTranslator ), signature ) |
| 7321 | |
| 7322 | #if defined(CATCH_CONFIG_DISABLE) |
| 7323 | #define INTERNAL_CATCH_TRANSLATE_EXCEPTION_NO_REG( translatorName, signature) \ |
| 7324 | static std::string translatorName( signature ) |
| 7325 | #endif |
| 7326 | |
| 7327 | |
| 7328 | // This macro is always prefixed |
| 7329 | #if !defined(CATCH_CONFIG_DISABLE) |
| 7330 | #define CATCH_TRANSLATE_EXCEPTION( signature ) INTERNAL_CATCH_TRANSLATE_EXCEPTION( signature ) |
| 7331 | #else |
| 7332 | #define CATCH_TRANSLATE_EXCEPTION( signature ) INTERNAL_CATCH_TRANSLATE_EXCEPTION_NO_REG( INTERNAL_CATCH_UNIQUE_NAME( catch_internal_ExceptionTranslator ), signature ) |
| 7333 | #endif |
| 7334 | |
| 7335 | |
| 7336 | #endif // CATCH_TRANSLATE_EXCEPTION_HPP_INCLUDED |
| 7337 | |
| 7338 | |
| 7339 | #ifndef CATCH_VERSION_HPP_INCLUDED |
| 7340 | #define CATCH_VERSION_HPP_INCLUDED |
| 7341 | |
| 7342 | #include <iosfwd> |
| 7343 | |
| 7344 | namespace Catch { |
| 7345 | |
| 7346 | // Versioning information |
| 7347 | struct Version { |
| 7348 | Version( Version const& ) = delete; |
| 7349 | Version& operator=( Version const& ) = delete; |
| 7350 | Version( unsigned int _majorVersion, |
| 7351 | unsigned int _minorVersion, |
| 7352 | unsigned int _patchNumber, |
| 7353 | char const * const _branchName, |
| 7354 | unsigned int _buildNumber ); |
| 7355 | |
| 7356 | unsigned int const majorVersion; |
| 7357 | unsigned int const minorVersion; |
| 7358 | unsigned int const patchNumber; |
| 7359 | |
| 7360 | // buildNumber is only used if branchName is not null |
| 7361 | char const * const branchName; |
| 7362 | unsigned int const buildNumber; |
| 7363 | |
| 7364 | friend std::ostream& operator << ( std::ostream& os, Version const& version ); |
| 7365 | }; |
| 7366 | |
| 7367 | Version const& libraryVersion(); |
| 7368 | } |
| 7369 | |
| 7370 | #endif // CATCH_VERSION_HPP_INCLUDED |
| 7371 | |
| 7372 | |
| 7373 | #ifndef CATCH_VERSION_MACROS_HPP_INCLUDED |
| 7374 | #define CATCH_VERSION_MACROS_HPP_INCLUDED |
| 7375 | |
| 7376 | #define CATCH_VERSION_MAJOR 3 |
| 7377 | #define CATCH_VERSION_MINOR 4 |
| 7378 | #define CATCH_VERSION_PATCH 0 |
| 7379 | |
| 7380 | #endif // CATCH_VERSION_MACROS_HPP_INCLUDED |
| 7381 | |
| 7382 | |
| 7383 | /** \file |
| 7384 | * This is a convenience header for Catch2's Generator support. It includes |
| 7385 | * **all** of Catch2 headers related to generators. |
| 7386 | * |
| 7387 | * Generally the Catch2 users should use specific includes they need, |
| 7388 | * but this header can be used instead for ease-of-experimentation, or |
| 7389 | * just plain convenience, at the cost of (significantly) increased |
| 7390 | * compilation times. |
| 7391 | * |
| 7392 | * When a new header is added to either the `generators` folder, |
| 7393 | * or to the corresponding internal subfolder, it should be added here. |
| 7394 | */ |
| 7395 | |
| 7396 | #ifndef CATCH_GENERATORS_ALL_HPP_INCLUDED |
| 7397 | #define CATCH_GENERATORS_ALL_HPP_INCLUDED |
| 7398 | |
| 7399 | |
| 7400 | |
| 7401 | #ifndef CATCH_GENERATOR_EXCEPTION_HPP_INCLUDED |
| 7402 | #define CATCH_GENERATOR_EXCEPTION_HPP_INCLUDED |
| 7403 | |
| 7404 | #include <exception> |
| 7405 | |
| 7406 | namespace Catch { |
| 7407 | |
| 7408 | // Exception type to be thrown when a Generator runs into an error, |
| 7409 | // e.g. it cannot initialize the first return value based on |
| 7410 | // runtime information |
| 7411 | class GeneratorException : public std::exception { |
| 7412 | const char* const m_msg = ""; |
| 7413 | |
| 7414 | public: |
| 7415 | GeneratorException(const char* msg): |
| 7416 | m_msg(msg) |
| 7417 | {} |
| 7418 | |
| 7419 | const char* what() const noexcept override final; |
| 7420 | }; |
| 7421 | |
| 7422 | } // end namespace Catch |
| 7423 | |
| 7424 | #endif // CATCH_GENERATOR_EXCEPTION_HPP_INCLUDED |
| 7425 | |
| 7426 | |
| 7427 | #ifndef CATCH_GENERATORS_HPP_INCLUDED |
| 7428 | #define CATCH_GENERATORS_HPP_INCLUDED |
| 7429 | |
| 7430 | |
| 7431 | |
| 7432 | #ifndef CATCH_INTERFACES_GENERATORTRACKER_HPP_INCLUDED |
| 7433 | #define CATCH_INTERFACES_GENERATORTRACKER_HPP_INCLUDED |
| 7434 | |
| 7435 | |
| 7436 | #include <string> |
| 7437 | |
| 7438 | namespace Catch { |
| 7439 | |
| 7440 | namespace Generators { |
| 7441 | class GeneratorUntypedBase { |
| 7442 | // Caches result from `toStringImpl`, assume that when it is an |
| 7443 | // empty string, the cache is invalidated. |
| 7444 | mutable std::string m_stringReprCache; |
| 7445 | |
| 7446 | // Counts based on `next` returning true |
| 7447 | std::size_t m_currentElementIndex = 0; |
| 7448 | |
| 7449 | /** |
| 7450 | * Attempts to move the generator to the next element |
| 7451 | * |
| 7452 | * Returns true iff the move succeeded (and a valid element |
| 7453 | * can be retrieved). |
| 7454 | */ |
| 7455 | virtual bool next() = 0; |
| 7456 | |
| 7457 | //! Customization point for `currentElementAsString` |
| 7458 | virtual std::string stringifyImpl() const = 0; |
| 7459 | |
| 7460 | public: |
| 7461 | GeneratorUntypedBase() = default; |
| 7462 | // Generation of copy ops is deprecated (and Clang will complain) |
| 7463 | // if there is a user destructor defined |
| 7464 | GeneratorUntypedBase(GeneratorUntypedBase const&) = default; |
| 7465 | GeneratorUntypedBase& operator=(GeneratorUntypedBase const&) = default; |
| 7466 | |
| 7467 | virtual ~GeneratorUntypedBase(); // = default; |
| 7468 | |
| 7469 | /** |
| 7470 | * Attempts to move the generator to the next element |
| 7471 | * |
| 7472 | * Serves as a non-virtual interface to `next`, so that the |
| 7473 | * top level interface can provide sanity checking and shared |
| 7474 | * features. |
| 7475 | * |
| 7476 | * As with `next`, returns true iff the move succeeded and |
| 7477 | * the generator has new valid element to provide. |
| 7478 | */ |
| 7479 | bool countedNext(); |
| 7480 | |
| 7481 | std::size_t currentElementIndex() const { return m_currentElementIndex; } |
| 7482 | |
| 7483 | /** |
| 7484 | * Returns generator's current element as user-friendly string. |
| 7485 | * |
| 7486 | * By default returns string equivalent to calling |
| 7487 | * `Catch::Detail::stringify` on the current element, but generators |
| 7488 | * can customize their implementation as needed. |
| 7489 | * |
| 7490 | * Not thread-safe due to internal caching. |
| 7491 | * |
| 7492 | * The returned ref is valid only until the generator instance |
| 7493 | * is destructed, or it moves onto the next element, whichever |
| 7494 | * comes first. |
| 7495 | */ |
| 7496 | StringRef currentElementAsString() const; |
| 7497 | }; |
| 7498 | using GeneratorBasePtr = Catch::Detail::unique_ptr<GeneratorUntypedBase>; |
| 7499 | |
| 7500 | } // namespace Generators |
| 7501 | |
| 7502 | class IGeneratorTracker { |
| 7503 | public: |
| 7504 | virtual ~IGeneratorTracker(); // = default; |
| 7505 | virtual auto hasGenerator() const -> bool = 0; |
| 7506 | virtual auto getGenerator() const -> Generators::GeneratorBasePtr const& = 0; |
| 7507 | virtual void setGenerator( Generators::GeneratorBasePtr&& generator ) = 0; |
| 7508 | }; |
| 7509 | |
| 7510 | } // namespace Catch |
| 7511 | |
| 7512 | #endif // CATCH_INTERFACES_GENERATORTRACKER_HPP_INCLUDED |
| 7513 | |
| 7514 | #include <vector> |
| 7515 | #include <tuple> |
| 7516 | |
| 7517 | namespace Catch { |
| 7518 | |
| 7519 | namespace Generators { |
| 7520 | |
| 7521 | namespace Detail { |
| 7522 | |
| 7523 | //! Throws GeneratorException with the provided message |
| 7524 | [[noreturn]] |
| 7525 | void throw_generator_exception(char const * msg); |
| 7526 | |
| 7527 | } // end namespace detail |
| 7528 | |
| 7529 | template<typename T> |
| 7530 | class IGenerator : public GeneratorUntypedBase { |
| 7531 | std::string stringifyImpl() const override { |
| 7532 | return ::Catch::Detail::stringify( get() ); |
| 7533 | } |
| 7534 | |
| 7535 | public: |
| 7536 | ~IGenerator() override = default; |
| 7537 | IGenerator() = default; |
| 7538 | IGenerator(IGenerator const&) = default; |
| 7539 | IGenerator& operator=(IGenerator const&) = default; |
| 7540 | |
| 7541 | |
| 7542 | // Returns the current element of the generator |
| 7543 | // |
| 7544 | // \Precondition The generator is either freshly constructed, |
| 7545 | // or the last call to `next()` returned true |
| 7546 | virtual T const& get() const = 0; |
| 7547 | using type = T; |
| 7548 | }; |
| 7549 | |
| 7550 | template <typename T> |
| 7551 | using GeneratorPtr = Catch::Detail::unique_ptr<IGenerator<T>>; |
| 7552 | |
| 7553 | template <typename T> |
| 7554 | class GeneratorWrapper final { |
| 7555 | GeneratorPtr<T> m_generator; |
| 7556 | public: |
| 7557 | //! Takes ownership of the passed pointer. |
| 7558 | GeneratorWrapper(IGenerator<T>* generator): |
| 7559 | m_generator(generator) {} |
| 7560 | GeneratorWrapper(GeneratorPtr<T> generator): |
| 7561 | m_generator(CATCH_MOVE(generator)) {} |
| 7562 | |
| 7563 | T const& get() const { |
| 7564 | return m_generator->get(); |
| 7565 | } |
| 7566 | bool next() { |
| 7567 | return m_generator->countedNext(); |
| 7568 | } |
| 7569 | }; |
| 7570 | |
| 7571 | |
| 7572 | template<typename T> |
| 7573 | class SingleValueGenerator final : public IGenerator<T> { |
| 7574 | T m_value; |
| 7575 | public: |
| 7576 | SingleValueGenerator(T const& value) : |
| 7577 | m_value(value) |
| 7578 | {} |
| 7579 | SingleValueGenerator(T&& value): |
| 7580 | m_value(CATCH_MOVE(value)) |
| 7581 | {} |
| 7582 | |
| 7583 | T const& get() const override { |
| 7584 | return m_value; |
| 7585 | } |
| 7586 | bool next() override { |
| 7587 | return false; |
| 7588 | } |
| 7589 | }; |
| 7590 | |
| 7591 | template<typename T> |
| 7592 | class FixedValuesGenerator final : public IGenerator<T> { |
| 7593 | static_assert(!std::is_same<T, bool>::value, |
| 7594 | "FixedValuesGenerator does not support bools because of std::vector<bool>" |
| 7595 | "specialization, use SingleValue Generator instead."); |
| 7596 | std::vector<T> m_values; |
| 7597 | size_t m_idx = 0; |
| 7598 | public: |
| 7599 | FixedValuesGenerator( std::initializer_list<T> values ) : m_values( values ) {} |
| 7600 | |
| 7601 | T const& get() const override { |
| 7602 | return m_values[m_idx]; |
| 7603 | } |
| 7604 | bool next() override { |
| 7605 | ++m_idx; |
| 7606 | return m_idx < m_values.size(); |
| 7607 | } |
| 7608 | }; |
| 7609 | |
| 7610 | template <typename T, typename DecayedT = std::decay_t<T>> |
| 7611 | GeneratorWrapper<DecayedT> value( T&& value ) { |
| 7612 | return GeneratorWrapper<DecayedT>( |
| 7613 | Catch::Detail::make_unique<SingleValueGenerator<DecayedT>>( |
| 7614 | CATCH_FORWARD( value ) ) ); |
| 7615 | } |
| 7616 | template <typename T> |
| 7617 | GeneratorWrapper<T> values(std::initializer_list<T> values) { |
| 7618 | return GeneratorWrapper<T>(Catch::Detail::make_unique<FixedValuesGenerator<T>>(values)); |
| 7619 | } |
| 7620 | |
| 7621 | template<typename T> |
| 7622 | class Generators : public IGenerator<T> { |
| 7623 | std::vector<GeneratorWrapper<T>> m_generators; |
| 7624 | size_t m_current = 0; |
| 7625 | |
| 7626 | void add_generator( GeneratorWrapper<T>&& generator ) { |
| 7627 | m_generators.emplace_back( CATCH_MOVE( generator ) ); |
| 7628 | } |
| 7629 | void add_generator( T const& val ) { |
| 7630 | m_generators.emplace_back( value( val ) ); |
| 7631 | } |
| 7632 | void add_generator( T&& val ) { |
| 7633 | m_generators.emplace_back( value( CATCH_MOVE( val ) ) ); |
| 7634 | } |
| 7635 | template <typename U> |
| 7636 | std::enable_if_t<!std::is_same<std::decay_t<U>, T>::value> |
| 7637 | add_generator( U&& val ) { |
| 7638 | add_generator( T( CATCH_FORWARD( val ) ) ); |
| 7639 | } |
| 7640 | |
| 7641 | template <typename U> void add_generators( U&& valueOrGenerator ) { |
| 7642 | add_generator( CATCH_FORWARD( valueOrGenerator ) ); |
| 7643 | } |
| 7644 | |
| 7645 | template <typename U, typename... Gs> |
| 7646 | void add_generators( U&& valueOrGenerator, Gs&&... moreGenerators ) { |
| 7647 | add_generator( CATCH_FORWARD( valueOrGenerator ) ); |
| 7648 | add_generators( CATCH_FORWARD( moreGenerators )... ); |
| 7649 | } |
| 7650 | |
| 7651 | public: |
| 7652 | template <typename... Gs> |
| 7653 | Generators(Gs &&... moreGenerators) { |
| 7654 | m_generators.reserve(sizeof...(Gs)); |
| 7655 | add_generators(CATCH_FORWARD(moreGenerators)...); |
| 7656 | } |
| 7657 | |
| 7658 | T const& get() const override { |
| 7659 | return m_generators[m_current].get(); |
| 7660 | } |
| 7661 | |
| 7662 | bool next() override { |
| 7663 | if (m_current >= m_generators.size()) { |
| 7664 | return false; |
| 7665 | } |
| 7666 | const bool current_status = m_generators[m_current].next(); |
| 7667 | if (!current_status) { |
| 7668 | ++m_current; |
| 7669 | } |
| 7670 | return m_current < m_generators.size(); |
| 7671 | } |
| 7672 | }; |
| 7673 | |
| 7674 | |
| 7675 | template <typename... Ts> |
| 7676 | GeneratorWrapper<std::tuple<std::decay_t<Ts>...>> |
| 7677 | table( std::initializer_list<std::tuple<std::decay_t<Ts>...>> tuples ) { |
| 7678 | return values<std::tuple<Ts...>>( tuples ); |
| 7679 | } |
| 7680 | |
| 7681 | // Tag type to signal that a generator sequence should convert arguments to a specific type |
| 7682 | template <typename T> |
| 7683 | struct as {}; |
| 7684 | |
| 7685 | template<typename T, typename... Gs> |
| 7686 | auto makeGenerators( GeneratorWrapper<T>&& generator, Gs &&... moreGenerators ) -> Generators<T> { |
| 7687 | return Generators<T>(CATCH_MOVE(generator), CATCH_FORWARD(moreGenerators)...); |
| 7688 | } |
| 7689 | template<typename T> |
| 7690 | auto makeGenerators( GeneratorWrapper<T>&& generator ) -> Generators<T> { |
| 7691 | return Generators<T>(CATCH_MOVE(generator)); |
| 7692 | } |
| 7693 | template<typename T, typename... Gs> |
| 7694 | auto makeGenerators( T&& val, Gs &&... moreGenerators ) -> Generators<std::decay_t<T>> { |
| 7695 | return makeGenerators( value( CATCH_FORWARD( val ) ), CATCH_FORWARD( moreGenerators )... ); |
| 7696 | } |
| 7697 | template<typename T, typename U, typename... Gs> |
| 7698 | auto makeGenerators( as<T>, U&& val, Gs &&... moreGenerators ) -> Generators<T> { |
| 7699 | return makeGenerators( value( T( CATCH_FORWARD( val ) ) ), CATCH_FORWARD( moreGenerators )... ); |
| 7700 | } |
| 7701 | |
| 7702 | IGeneratorTracker* acquireGeneratorTracker( StringRef generatorName, |
| 7703 | SourceLineInfo const& lineInfo ); |
| 7704 | IGeneratorTracker* createGeneratorTracker( StringRef generatorName, |
| 7705 | SourceLineInfo lineInfo, |
| 7706 | GeneratorBasePtr&& generator ); |
| 7707 | |
| 7708 | template<typename L> |
| 7709 | auto generate( StringRef generatorName, SourceLineInfo const& lineInfo, L const& generatorExpression ) -> typename decltype(generatorExpression())::type { |
| 7710 | using UnderlyingType = typename decltype(generatorExpression())::type; |
| 7711 | |
| 7712 | IGeneratorTracker* tracker = acquireGeneratorTracker( generatorName, lineInfo ); |
| 7713 | // Creation of tracker is delayed after generator creation, so |
| 7714 | // that constructing generator can fail without breaking everything. |
| 7715 | if (!tracker) { |
| 7716 | tracker = createGeneratorTracker( |
| 7717 | generatorName, |
| 7718 | lineInfo, |
| 7719 | Catch::Detail::make_unique<Generators<UnderlyingType>>( |
| 7720 | generatorExpression() ) ); |
| 7721 | } |
| 7722 | |
| 7723 | auto const& generator = static_cast<IGenerator<UnderlyingType> const&>( *tracker->getGenerator() ); |
| 7724 | return generator.get(); |
| 7725 | } |
| 7726 | |
| 7727 | } // namespace Generators |
| 7728 | } // namespace Catch |
| 7729 | |
| 7730 | #define CATCH_INTERNAL_GENERATOR_STRINGIZE_IMPL( ... ) #__VA_ARGS__##_catch_sr |
| 7731 | #define CATCH_INTERNAL_GENERATOR_STRINGIZE(...) CATCH_INTERNAL_GENERATOR_STRINGIZE_IMPL(__VA_ARGS__) |
| 7732 | |
| 7733 | #define GENERATE( ... ) \ |
| 7734 | Catch::Generators::generate( CATCH_INTERNAL_GENERATOR_STRINGIZE(INTERNAL_CATCH_UNIQUE_NAME(generator)), \ |
| 7735 | CATCH_INTERNAL_LINEINFO, \ |
| 7736 | [ ]{ using namespace Catch::Generators; return makeGenerators( __VA_ARGS__ ); } ) //NOLINT(google-build-using-namespace) |
| 7737 | #define GENERATE_COPY( ... ) \ |
| 7738 | Catch::Generators::generate( CATCH_INTERNAL_GENERATOR_STRINGIZE(INTERNAL_CATCH_UNIQUE_NAME(generator)), \ |
| 7739 | CATCH_INTERNAL_LINEINFO, \ |
| 7740 | [=]{ using namespace Catch::Generators; return makeGenerators( __VA_ARGS__ ); } ) //NOLINT(google-build-using-namespace) |
| 7741 | #define GENERATE_REF( ... ) \ |
| 7742 | Catch::Generators::generate( CATCH_INTERNAL_GENERATOR_STRINGIZE(INTERNAL_CATCH_UNIQUE_NAME(generator)), \ |
| 7743 | CATCH_INTERNAL_LINEINFO, \ |
| 7744 | [&]{ using namespace Catch::Generators; return makeGenerators( __VA_ARGS__ ); } ) //NOLINT(google-build-using-namespace) |
| 7745 | |
| 7746 | #endif // CATCH_GENERATORS_HPP_INCLUDED |
| 7747 | |
| 7748 | |
| 7749 | #ifndef CATCH_GENERATORS_ADAPTERS_HPP_INCLUDED |
| 7750 | #define CATCH_GENERATORS_ADAPTERS_HPP_INCLUDED |
| 7751 | |
| 7752 | |
| 7753 | #include <cassert> |
| 7754 | |
| 7755 | namespace Catch { |
| 7756 | namespace Generators { |
| 7757 | |
| 7758 | template <typename T> |
| 7759 | class TakeGenerator final : public IGenerator<T> { |
| 7760 | GeneratorWrapper<T> m_generator; |
| 7761 | size_t m_returned = 0; |
| 7762 | size_t m_target; |
| 7763 | public: |
| 7764 | TakeGenerator(size_t target, GeneratorWrapper<T>&& generator): |
| 7765 | m_generator(CATCH_MOVE(generator)), |
| 7766 | m_target(target) |
| 7767 | { |
| 7768 | assert(target != 0 && "Empty generators are not allowed"); |
| 7769 | } |
| 7770 | T const& get() const override { |
| 7771 | return m_generator.get(); |
| 7772 | } |
| 7773 | bool next() override { |
| 7774 | ++m_returned; |
| 7775 | if (m_returned >= m_target) { |
| 7776 | return false; |
| 7777 | } |
| 7778 | |
| 7779 | const auto success = m_generator.next(); |
| 7780 | // If the underlying generator does not contain enough values |
| 7781 | // then we cut short as well |
| 7782 | if (!success) { |
| 7783 | m_returned = m_target; |
| 7784 | } |
| 7785 | return success; |
| 7786 | } |
| 7787 | }; |
| 7788 | |
| 7789 | template <typename T> |
| 7790 | GeneratorWrapper<T> take(size_t target, GeneratorWrapper<T>&& generator) { |
| 7791 | return GeneratorWrapper<T>(Catch::Detail::make_unique<TakeGenerator<T>>(target, CATCH_MOVE(generator))); |
| 7792 | } |
| 7793 | |
| 7794 | |
| 7795 | template <typename T, typename Predicate> |
| 7796 | class FilterGenerator final : public IGenerator<T> { |
| 7797 | GeneratorWrapper<T> m_generator; |
| 7798 | Predicate m_predicate; |
| 7799 | public: |
| 7800 | template <typename P = Predicate> |
| 7801 | FilterGenerator(P&& pred, GeneratorWrapper<T>&& generator): |
| 7802 | m_generator(CATCH_MOVE(generator)), |
| 7803 | m_predicate(CATCH_FORWARD(pred)) |
| 7804 | { |
| 7805 | if (!m_predicate(m_generator.get())) { |
| 7806 | // It might happen that there are no values that pass the |
| 7807 | // filter. In that case we throw an exception. |
| 7808 | auto has_initial_value = next(); |
| 7809 | if (!has_initial_value) { |
| 7810 | Detail::throw_generator_exception("No valid value found in filtered generator"); |
| 7811 | } |
| 7812 | } |
| 7813 | } |
| 7814 | |
| 7815 | T const& get() const override { |
| 7816 | return m_generator.get(); |
| 7817 | } |
| 7818 | |
| 7819 | bool next() override { |
| 7820 | bool success = m_generator.next(); |
| 7821 | if (!success) { |
| 7822 | return false; |
| 7823 | } |
| 7824 | while (!m_predicate(m_generator.get()) && (success = m_generator.next()) == true); |
| 7825 | return success; |
| 7826 | } |
| 7827 | }; |
| 7828 | |
| 7829 | |
| 7830 | template <typename T, typename Predicate> |
| 7831 | GeneratorWrapper<T> filter(Predicate&& pred, GeneratorWrapper<T>&& generator) { |
| 7832 | return GeneratorWrapper<T>(Catch::Detail::make_unique<FilterGenerator<T, Predicate>>(CATCH_FORWARD(pred), CATCH_MOVE(generator))); |
| 7833 | } |
| 7834 | |
| 7835 | template <typename T> |
| 7836 | class RepeatGenerator final : public IGenerator<T> { |
| 7837 | static_assert(!std::is_same<T, bool>::value, |
| 7838 | "RepeatGenerator currently does not support bools" |
| 7839 | "because of std::vector<bool> specialization"); |
| 7840 | GeneratorWrapper<T> m_generator; |
| 7841 | mutable std::vector<T> m_returned; |
| 7842 | size_t m_target_repeats; |
| 7843 | size_t m_current_repeat = 0; |
| 7844 | size_t m_repeat_index = 0; |
| 7845 | public: |
| 7846 | RepeatGenerator(size_t repeats, GeneratorWrapper<T>&& generator): |
| 7847 | m_generator(CATCH_MOVE(generator)), |
| 7848 | m_target_repeats(repeats) |
| 7849 | { |
| 7850 | assert(m_target_repeats > 0 && "Repeat generator must repeat at least once"); |
| 7851 | } |
| 7852 | |
| 7853 | T const& get() const override { |
| 7854 | if (m_current_repeat == 0) { |
| 7855 | m_returned.push_back(m_generator.get()); |
| 7856 | return m_returned.back(); |
| 7857 | } |
| 7858 | return m_returned[m_repeat_index]; |
| 7859 | } |
| 7860 | |
| 7861 | bool next() override { |
| 7862 | // There are 2 basic cases: |
| 7863 | // 1) We are still reading the generator |
| 7864 | // 2) We are reading our own cache |
| 7865 | |
| 7866 | // In the first case, we need to poke the underlying generator. |
| 7867 | // If it happily moves, we are left in that state, otherwise it is time to start reading from our cache |
| 7868 | if (m_current_repeat == 0) { |
| 7869 | const auto success = m_generator.next(); |
| 7870 | if (!success) { |
| 7871 | ++m_current_repeat; |
| 7872 | } |
| 7873 | return m_current_repeat < m_target_repeats; |
| 7874 | } |
| 7875 | |
| 7876 | // In the second case, we need to move indices forward and check that we haven't run up against the end |
| 7877 | ++m_repeat_index; |
| 7878 | if (m_repeat_index == m_returned.size()) { |
| 7879 | m_repeat_index = 0; |
| 7880 | ++m_current_repeat; |
| 7881 | } |
| 7882 | return m_current_repeat < m_target_repeats; |
| 7883 | } |
| 7884 | }; |
| 7885 | |
| 7886 | template <typename T> |
| 7887 | GeneratorWrapper<T> repeat(size_t repeats, GeneratorWrapper<T>&& generator) { |
| 7888 | return GeneratorWrapper<T>(Catch::Detail::make_unique<RepeatGenerator<T>>(repeats, CATCH_MOVE(generator))); |
| 7889 | } |
| 7890 | |
| 7891 | template <typename T, typename U, typename Func> |
| 7892 | class MapGenerator final : public IGenerator<T> { |
| 7893 | // TBD: provide static assert for mapping function, for friendly error message |
| 7894 | GeneratorWrapper<U> m_generator; |
| 7895 | Func m_function; |
| 7896 | // To avoid returning dangling reference, we have to save the values |
| 7897 | T m_cache; |
| 7898 | public: |
| 7899 | template <typename F2 = Func> |
| 7900 | MapGenerator(F2&& function, GeneratorWrapper<U>&& generator) : |
| 7901 | m_generator(CATCH_MOVE(generator)), |
| 7902 | m_function(CATCH_FORWARD(function)), |
| 7903 | m_cache(m_function(m_generator.get())) |
| 7904 | {} |
| 7905 | |
| 7906 | T const& get() const override { |
| 7907 | return m_cache; |
| 7908 | } |
| 7909 | bool next() override { |
| 7910 | const auto success = m_generator.next(); |
| 7911 | if (success) { |
| 7912 | m_cache = m_function(m_generator.get()); |
| 7913 | } |
| 7914 | return success; |
| 7915 | } |
| 7916 | }; |
| 7917 | |
| 7918 | template <typename Func, typename U, typename T = FunctionReturnType<Func, U>> |
| 7919 | GeneratorWrapper<T> map(Func&& function, GeneratorWrapper<U>&& generator) { |
| 7920 | return GeneratorWrapper<T>( |
| 7921 | Catch::Detail::make_unique<MapGenerator<T, U, Func>>(CATCH_FORWARD(function), CATCH_MOVE(generator)) |
| 7922 | ); |
| 7923 | } |
| 7924 | |
| 7925 | template <typename T, typename U, typename Func> |
| 7926 | GeneratorWrapper<T> map(Func&& function, GeneratorWrapper<U>&& generator) { |
| 7927 | return GeneratorWrapper<T>( |
| 7928 | Catch::Detail::make_unique<MapGenerator<T, U, Func>>(CATCH_FORWARD(function), CATCH_MOVE(generator)) |
| 7929 | ); |
| 7930 | } |
| 7931 | |
| 7932 | template <typename T> |
| 7933 | class ChunkGenerator final : public IGenerator<std::vector<T>> { |
| 7934 | std::vector<T> m_chunk; |
| 7935 | size_t m_chunk_size; |
| 7936 | GeneratorWrapper<T> m_generator; |
| 7937 | bool m_used_up = false; |
| 7938 | public: |
| 7939 | ChunkGenerator(size_t size, GeneratorWrapper<T> generator) : |
| 7940 | m_chunk_size(size), m_generator(CATCH_MOVE(generator)) |
| 7941 | { |
| 7942 | m_chunk.reserve(m_chunk_size); |
| 7943 | if (m_chunk_size != 0) { |
| 7944 | m_chunk.push_back(m_generator.get()); |
| 7945 | for (size_t i = 1; i < m_chunk_size; ++i) { |
| 7946 | if (!m_generator.next()) { |
| 7947 | Detail::throw_generator_exception("Not enough values to initialize the first chunk"); |
| 7948 | } |
| 7949 | m_chunk.push_back(m_generator.get()); |
| 7950 | } |
| 7951 | } |
| 7952 | } |
| 7953 | std::vector<T> const& get() const override { |
| 7954 | return m_chunk; |
| 7955 | } |
| 7956 | bool next() override { |
| 7957 | m_chunk.clear(); |
| 7958 | for (size_t idx = 0; idx < m_chunk_size; ++idx) { |
| 7959 | if (!m_generator.next()) { |
| 7960 | return false; |
| 7961 | } |
| 7962 | m_chunk.push_back(m_generator.get()); |
| 7963 | } |
| 7964 | return true; |
| 7965 | } |
| 7966 | }; |
| 7967 | |
| 7968 | template <typename T> |
| 7969 | GeneratorWrapper<std::vector<T>> chunk(size_t size, GeneratorWrapper<T>&& generator) { |
| 7970 | return GeneratorWrapper<std::vector<T>>( |
| 7971 | Catch::Detail::make_unique<ChunkGenerator<T>>(size, CATCH_MOVE(generator)) |
| 7972 | ); |
| 7973 | } |
| 7974 | |
| 7975 | } // namespace Generators |
| 7976 | } // namespace Catch |
| 7977 | |
| 7978 | |
| 7979 | #endif // CATCH_GENERATORS_ADAPTERS_HPP_INCLUDED |
| 7980 | |
| 7981 | |
| 7982 | #ifndef CATCH_GENERATORS_RANDOM_HPP_INCLUDED |
| 7983 | #define CATCH_GENERATORS_RANDOM_HPP_INCLUDED |
| 7984 | |
| 7985 | |
| 7986 | |
| 7987 | #ifndef CATCH_RANDOM_NUMBER_GENERATOR_HPP_INCLUDED |
| 7988 | #define CATCH_RANDOM_NUMBER_GENERATOR_HPP_INCLUDED |
| 7989 | |
| 7990 | #include <cstdint> |
| 7991 | |
| 7992 | namespace Catch { |
| 7993 | |
| 7994 | // This is a simple implementation of C++11 Uniform Random Number |
| 7995 | // Generator. It does not provide all operators, because Catch2 |
| 7996 | // does not use it, but it should behave as expected inside stdlib's |
| 7997 | // distributions. |
| 7998 | // The implementation is based on the PCG family (http://pcg-random.org) |
| 7999 | class SimplePcg32 { |
| 8000 | using state_type = std::uint64_t; |
| 8001 | public: |
| 8002 | using result_type = std::uint32_t; |
| 8003 | static constexpr result_type (min)() { |
| 8004 | return 0; |
| 8005 | } |
| 8006 | static constexpr result_type (max)() { |
| 8007 | return static_cast<result_type>(-1); |
| 8008 | } |
| 8009 | |
| 8010 | // Provide some default initial state for the default constructor |
| 8011 | SimplePcg32():SimplePcg32(0xed743cc4U) {} |
| 8012 | |
| 8013 | explicit SimplePcg32(result_type seed_); |
| 8014 | |
| 8015 | void seed(result_type seed_); |
| 8016 | void discard(uint64_t skip); |
| 8017 | |
| 8018 | result_type operator()(); |
| 8019 | |
| 8020 | private: |
| 8021 | friend bool operator==(SimplePcg32 const& lhs, SimplePcg32 const& rhs); |
| 8022 | friend bool operator!=(SimplePcg32 const& lhs, SimplePcg32 const& rhs); |
| 8023 | |
| 8024 | // In theory we also need operator<< and operator>> |
| 8025 | // In practice we do not use them, so we will skip them for now |
| 8026 | |
| 8027 | |
| 8028 | std::uint64_t m_state; |
| 8029 | // This part of the state determines which "stream" of the numbers |
| 8030 | // is chosen -- we take it as a constant for Catch2, so we only |
| 8031 | // need to deal with seeding the main state. |
| 8032 | // Picked by reading 8 bytes from `/dev/random` :-) |
| 8033 | static const std::uint64_t s_inc = (0x13ed0cc53f939476ULL << 1ULL) | 1ULL; |
| 8034 | }; |
| 8035 | |
| 8036 | } // end namespace Catch |
| 8037 | |
| 8038 | #endif // CATCH_RANDOM_NUMBER_GENERATOR_HPP_INCLUDED |
| 8039 | |
| 8040 | #include <random> |
| 8041 | |
| 8042 | namespace Catch { |
| 8043 | namespace Generators { |
| 8044 | namespace Detail { |
| 8045 | // Returns a suitable seed for a random floating generator based off |
| 8046 | // the primary internal rng. It does so by taking current value from |
| 8047 | // the rng and returning it as the seed. |
| 8048 | std::uint32_t getSeed(); |
| 8049 | } |
| 8050 | |
| 8051 | template <typename Float> |
| 8052 | class RandomFloatingGenerator final : public IGenerator<Float> { |
| 8053 | Catch::SimplePcg32 m_rng; |
| 8054 | std::uniform_real_distribution<Float> m_dist; |
| 8055 | Float m_current_number; |
| 8056 | public: |
| 8057 | RandomFloatingGenerator( Float a, Float b, std::uint32_t seed ): |
| 8058 | m_rng(seed), |
| 8059 | m_dist(a, b) { |
| 8060 | static_cast<void>(next()); |
| 8061 | } |
| 8062 | |
| 8063 | Float const& get() const override { |
| 8064 | return m_current_number; |
| 8065 | } |
| 8066 | bool next() override { |
| 8067 | m_current_number = m_dist(m_rng); |
| 8068 | return true; |
| 8069 | } |
| 8070 | }; |
| 8071 | |
| 8072 | template <typename Integer> |
| 8073 | class RandomIntegerGenerator final : public IGenerator<Integer> { |
| 8074 | Catch::SimplePcg32 m_rng; |
| 8075 | std::uniform_int_distribution<Integer> m_dist; |
| 8076 | Integer m_current_number; |
| 8077 | public: |
| 8078 | RandomIntegerGenerator( Integer a, Integer b, std::uint32_t seed ): |
| 8079 | m_rng(seed), |
| 8080 | m_dist(a, b) { |
| 8081 | static_cast<void>(next()); |
| 8082 | } |
| 8083 | |
| 8084 | Integer const& get() const override { |
| 8085 | return m_current_number; |
| 8086 | } |
| 8087 | bool next() override { |
| 8088 | m_current_number = m_dist(m_rng); |
| 8089 | return true; |
| 8090 | } |
| 8091 | }; |
| 8092 | |
| 8093 | template <typename T> |
| 8094 | std::enable_if_t<std::is_integral<T>::value, GeneratorWrapper<T>> |
| 8095 | random(T a, T b) { |
| 8096 | static_assert( |
| 8097 | !std::is_same<T, char>::value && |
| 8098 | !std::is_same<T, int8_t>::value && |
| 8099 | !std::is_same<T, uint8_t>::value && |
| 8100 | !std::is_same<T, signed char>::value && |
| 8101 | !std::is_same<T, unsigned char>::value && |
| 8102 | !std::is_same<T, bool>::value, |
| 8103 | "The requested type is not supported by the underlying random distributions from std" ); |
| 8104 | return GeneratorWrapper<T>( |
| 8105 | Catch::Detail::make_unique<RandomIntegerGenerator<T>>(a, b, Detail::getSeed()) |
| 8106 | ); |
| 8107 | } |
| 8108 | |
| 8109 | template <typename T> |
| 8110 | std::enable_if_t<std::is_floating_point<T>::value, |
| 8111 | GeneratorWrapper<T>> |
| 8112 | random(T a, T b) { |
| 8113 | return GeneratorWrapper<T>( |
| 8114 | Catch::Detail::make_unique<RandomFloatingGenerator<T>>(a, b, Detail::getSeed()) |
| 8115 | ); |
| 8116 | } |
| 8117 | |
| 8118 | |
| 8119 | } // namespace Generators |
| 8120 | } // namespace Catch |
| 8121 | |
| 8122 | |
| 8123 | #endif // CATCH_GENERATORS_RANDOM_HPP_INCLUDED |
| 8124 | |
| 8125 | |
| 8126 | #ifndef CATCH_GENERATORS_RANGE_HPP_INCLUDED |
| 8127 | #define CATCH_GENERATORS_RANGE_HPP_INCLUDED |
| 8128 | |
| 8129 | |
| 8130 | #include <iterator> |
| 8131 | #include <type_traits> |
| 8132 | |
| 8133 | namespace Catch { |
| 8134 | namespace Generators { |
| 8135 | |
| 8136 | |
| 8137 | template <typename T> |
| 8138 | class RangeGenerator final : public IGenerator<T> { |
| 8139 | T m_current; |
| 8140 | T m_end; |
| 8141 | T m_step; |
| 8142 | bool m_positive; |
| 8143 | |
| 8144 | public: |
| 8145 | RangeGenerator(T const& start, T const& end, T const& step): |
| 8146 | m_current(start), |
| 8147 | m_end(end), |
| 8148 | m_step(step), |
| 8149 | m_positive(m_step > T(0)) |
| 8150 | { |
| 8151 | assert(m_current != m_end && "Range start and end cannot be equal"); |
| 8152 | assert(m_step != T(0) && "Step size cannot be zero"); |
| 8153 | assert(((m_positive && m_current <= m_end) || (!m_positive && m_current >= m_end)) && "Step moves away from end"); |
| 8154 | } |
| 8155 | |
| 8156 | RangeGenerator(T const& start, T const& end): |
| 8157 | RangeGenerator(start, end, (start < end) ? T(1) : T(-1)) |
| 8158 | {} |
| 8159 | |
| 8160 | T const& get() const override { |
| 8161 | return m_current; |
| 8162 | } |
| 8163 | |
| 8164 | bool next() override { |
| 8165 | m_current += m_step; |
| 8166 | return (m_positive) ? (m_current < m_end) : (m_current > m_end); |
| 8167 | } |
| 8168 | }; |
| 8169 | |
| 8170 | template <typename T> |
| 8171 | GeneratorWrapper<T> range(T const& start, T const& end, T const& step) { |
| 8172 | static_assert(std::is_arithmetic<T>::value && !std::is_same<T, bool>::value, "Type must be numeric"); |
| 8173 | return GeneratorWrapper<T>(Catch::Detail::make_unique<RangeGenerator<T>>(start, end, step)); |
| 8174 | } |
| 8175 | |
| 8176 | template <typename T> |
| 8177 | GeneratorWrapper<T> range(T const& start, T const& end) { |
| 8178 | static_assert(std::is_integral<T>::value && !std::is_same<T, bool>::value, "Type must be an integer"); |
| 8179 | return GeneratorWrapper<T>(Catch::Detail::make_unique<RangeGenerator<T>>(start, end)); |
| 8180 | } |
| 8181 | |
| 8182 | |
| 8183 | template <typename T> |
| 8184 | class IteratorGenerator final : public IGenerator<T> { |
| 8185 | static_assert(!std::is_same<T, bool>::value, |
| 8186 | "IteratorGenerator currently does not support bools" |
| 8187 | "because of std::vector<bool> specialization"); |
| 8188 | |
| 8189 | std::vector<T> m_elems; |
| 8190 | size_t m_current = 0; |
| 8191 | public: |
| 8192 | template <typename InputIterator, typename InputSentinel> |
| 8193 | IteratorGenerator(InputIterator first, InputSentinel last):m_elems(first, last) { |
| 8194 | if (m_elems.empty()) { |
| 8195 | Detail::throw_generator_exception("IteratorGenerator received no valid values"); |
| 8196 | } |
| 8197 | } |
| 8198 | |
| 8199 | T const& get() const override { |
| 8200 | return m_elems[m_current]; |
| 8201 | } |
| 8202 | |
| 8203 | bool next() override { |
| 8204 | ++m_current; |
| 8205 | return m_current != m_elems.size(); |
| 8206 | } |
| 8207 | }; |
| 8208 | |
| 8209 | template <typename InputIterator, |
| 8210 | typename InputSentinel, |
| 8211 | typename ResultType = typename std::iterator_traits<InputIterator>::value_type> |
| 8212 | GeneratorWrapper<ResultType> from_range(InputIterator from, InputSentinel to) { |
| 8213 | return GeneratorWrapper<ResultType>(Catch::Detail::make_unique<IteratorGenerator<ResultType>>(from, to)); |
| 8214 | } |
| 8215 | |
| 8216 | template <typename Container, |
| 8217 | typename ResultType = typename Container::value_type> |
| 8218 | GeneratorWrapper<ResultType> from_range(Container const& cnt) { |
| 8219 | return GeneratorWrapper<ResultType>(Catch::Detail::make_unique<IteratorGenerator<ResultType>>(cnt.begin(), cnt.end())); |
| 8220 | } |
| 8221 | |
| 8222 | |
| 8223 | } // namespace Generators |
| 8224 | } // namespace Catch |
| 8225 | |
| 8226 | |
| 8227 | #endif // CATCH_GENERATORS_RANGE_HPP_INCLUDED |
| 8228 | |
| 8229 | #endif // CATCH_GENERATORS_ALL_HPP_INCLUDED |
| 8230 | |
| 8231 | |
| 8232 | /** \file |
| 8233 | * This is a convenience header for Catch2's interfaces. It includes |
| 8234 | * **all** of Catch2 headers related to interfaces. |
| 8235 | * |
| 8236 | * Generally the Catch2 users should use specific includes they need, |
| 8237 | * but this header can be used instead for ease-of-experimentation, or |
| 8238 | * just plain convenience, at the cost of somewhat increased compilation |
| 8239 | * times. |
| 8240 | * |
| 8241 | * When a new header is added to either the `interfaces` folder, or to |
| 8242 | * the corresponding internal subfolder, it should be added here. |
| 8243 | */ |
| 8244 | |
| 8245 | |
| 8246 | #ifndef CATCH_INTERFACES_ALL_HPP_INCLUDED |
| 8247 | #define CATCH_INTERFACES_ALL_HPP_INCLUDED |
| 8248 | |
| 8249 | |
| 8250 | |
| 8251 | #ifndef CATCH_INTERFACES_REPORTER_HPP_INCLUDED |
| 8252 | #define CATCH_INTERFACES_REPORTER_HPP_INCLUDED |
| 8253 | |
| 8254 | |
| 8255 | |
| 8256 | #ifndef CATCH_TEST_RUN_INFO_HPP_INCLUDED |
| 8257 | #define CATCH_TEST_RUN_INFO_HPP_INCLUDED |
| 8258 | |
| 8259 | |
| 8260 | namespace Catch { |
| 8261 | |
| 8262 | struct TestRunInfo { |
| 8263 | constexpr TestRunInfo(StringRef _name) : name(_name) {} |
| 8264 | StringRef name; |
| 8265 | }; |
| 8266 | |
| 8267 | } // end namespace Catch |
| 8268 | |
| 8269 | #endif // CATCH_TEST_RUN_INFO_HPP_INCLUDED |
| 8270 | |
| 8271 | #include <map> |
| 8272 | #include <string> |
| 8273 | #include <vector> |
| 8274 | #include <iosfwd> |
| 8275 | |
| 8276 | namespace Catch { |
| 8277 | |
| 8278 | struct ReporterDescription; |
| 8279 | struct ListenerDescription; |
| 8280 | struct TagInfo; |
| 8281 | struct TestCaseInfo; |
| 8282 | class TestCaseHandle; |
| 8283 | class IConfig; |
| 8284 | class IStream; |
| 8285 | enum class ColourMode : std::uint8_t; |
| 8286 | |
| 8287 | struct ReporterConfig { |
| 8288 | ReporterConfig( IConfig const* _fullConfig, |
| 8289 | Detail::unique_ptr<IStream> _stream, |
| 8290 | ColourMode colourMode, |
| 8291 | std::map<std::string, std::string> customOptions ); |
| 8292 | |
| 8293 | ReporterConfig( ReporterConfig&& ) = default; |
| 8294 | ReporterConfig& operator=( ReporterConfig&& ) = default; |
| 8295 | ~ReporterConfig(); // = default |
| 8296 | |
| 8297 | Detail::unique_ptr<IStream> takeStream() &&; |
| 8298 | IConfig const* fullConfig() const; |
| 8299 | ColourMode colourMode() const; |
| 8300 | std::map<std::string, std::string> const& customOptions() const; |
| 8301 | |
| 8302 | private: |
| 8303 | Detail::unique_ptr<IStream> m_stream; |
| 8304 | IConfig const* m_fullConfig; |
| 8305 | ColourMode m_colourMode; |
| 8306 | std::map<std::string, std::string> m_customOptions; |
| 8307 | }; |
| 8308 | |
| 8309 | struct AssertionStats { |
| 8310 | AssertionStats( AssertionResult const& _assertionResult, |
| 8311 | std::vector<MessageInfo> const& _infoMessages, |
| 8312 | Totals const& _totals ); |
| 8313 | |
| 8314 | AssertionStats( AssertionStats const& ) = default; |
| 8315 | AssertionStats( AssertionStats && ) = default; |
| 8316 | AssertionStats& operator = ( AssertionStats const& ) = delete; |
| 8317 | AssertionStats& operator = ( AssertionStats && ) = delete; |
| 8318 | |
| 8319 | AssertionResult assertionResult; |
| 8320 | std::vector<MessageInfo> infoMessages; |
| 8321 | Totals totals; |
| 8322 | }; |
| 8323 | |
| 8324 | struct SectionStats { |
| 8325 | SectionStats( SectionInfo&& _sectionInfo, |
| 8326 | Counts const& _assertions, |
| 8327 | double _durationInSeconds, |
| 8328 | bool _missingAssertions ); |
| 8329 | |
| 8330 | SectionInfo sectionInfo; |
| 8331 | Counts assertions; |
| 8332 | double durationInSeconds; |
| 8333 | bool missingAssertions; |
| 8334 | }; |
| 8335 | |
| 8336 | struct TestCaseStats { |
| 8337 | TestCaseStats( TestCaseInfo const& _testInfo, |
| 8338 | Totals const& _totals, |
| 8339 | std::string&& _stdOut, |
| 8340 | std::string&& _stdErr, |
| 8341 | bool _aborting ); |
| 8342 | |
| 8343 | TestCaseInfo const * testInfo; |
| 8344 | Totals totals; |
| 8345 | std::string stdOut; |
| 8346 | std::string stdErr; |
| 8347 | bool aborting; |
| 8348 | }; |
| 8349 | |
| 8350 | struct TestRunStats { |
| 8351 | TestRunStats( TestRunInfo const& _runInfo, |
| 8352 | Totals const& _totals, |
| 8353 | bool _aborting ); |
| 8354 | |
| 8355 | TestRunInfo runInfo; |
| 8356 | Totals totals; |
| 8357 | bool aborting; |
| 8358 | }; |
| 8359 | |
| 8360 | //! By setting up its preferences, a reporter can modify Catch2's behaviour |
| 8361 | //! in some regards, e.g. it can request Catch2 to capture writes to |
| 8362 | //! stdout/stderr during test execution, and pass them to the reporter. |
| 8363 | struct ReporterPreferences { |
| 8364 | //! Catch2 should redirect writes to stdout and pass them to the |
| 8365 | //! reporter |
| 8366 | bool shouldRedirectStdOut = false; |
| 8367 | //! Catch2 should call `Reporter::assertionEnded` even for passing |
| 8368 | //! assertions |
| 8369 | bool shouldReportAllAssertions = false; |
| 8370 | }; |
| 8371 | |
| 8372 | /** |
| 8373 | * The common base for all reporters and event listeners |
| 8374 | * |
| 8375 | * Implementing classes must also implement: |
| 8376 | * |
| 8377 | * //! User-friendly description of the reporter/listener type |
| 8378 | * static std::string getDescription() |
| 8379 | * |
| 8380 | * Generally shouldn't be derived from by users of Catch2 directly, |
| 8381 | * instead they should derive from one of the utility bases that |
| 8382 | * derive from this class. |
| 8383 | */ |
| 8384 | class IEventListener { |
| 8385 | protected: |
| 8386 | //! Derived classes can set up their preferences here |
| 8387 | ReporterPreferences m_preferences; |
| 8388 | //! The test run's config as filled in from CLI and defaults |
| 8389 | IConfig const* m_config; |
| 8390 | |
| 8391 | public: |
| 8392 | IEventListener( IConfig const* config ): m_config( config ) {} |
| 8393 | |
| 8394 | virtual ~IEventListener(); // = default; |
| 8395 | |
| 8396 | // Implementing class must also provide the following static methods: |
| 8397 | // static std::string getDescription(); |
| 8398 | |
| 8399 | ReporterPreferences const& getPreferences() const { |
| 8400 | return m_preferences; |
| 8401 | } |
| 8402 | |
| 8403 | //! Called when no test cases match provided test spec |
| 8404 | virtual void noMatchingTestCases( StringRef unmatchedSpec ) = 0; |
| 8405 | //! Called for all invalid test specs from the cli |
| 8406 | virtual void reportInvalidTestSpec( StringRef invalidArgument ) = 0; |
| 8407 | |
| 8408 | /** |
| 8409 | * Called once in a testing run before tests are started |
| 8410 | * |
| 8411 | * Not called if tests won't be run (e.g. only listing will happen) |
| 8412 | */ |
| 8413 | virtual void testRunStarting( TestRunInfo const& testRunInfo ) = 0; |
| 8414 | |
| 8415 | //! Called _once_ for each TEST_CASE, no matter how many times it is entered |
| 8416 | virtual void testCaseStarting( TestCaseInfo const& testInfo ) = 0; |
| 8417 | //! Called _every time_ a TEST_CASE is entered, including repeats (due to sections) |
| 8418 | virtual void testCasePartialStarting( TestCaseInfo const& testInfo, uint64_t partNumber ) = 0; |
| 8419 | //! Called when a `SECTION` is being entered. Not called for skipped sections |
| 8420 | virtual void sectionStarting( SectionInfo const& sectionInfo ) = 0; |
| 8421 | |
| 8422 | //! Called when user-code is being probed before the actual benchmark runs |
| 8423 | virtual void benchmarkPreparing( StringRef benchmarkName ) = 0; |
| 8424 | //! Called after probe but before the user-code is being benchmarked |
| 8425 | virtual void benchmarkStarting( BenchmarkInfo const& benchmarkInfo ) = 0; |
| 8426 | //! Called with the benchmark results if benchmark successfully finishes |
| 8427 | virtual void benchmarkEnded( BenchmarkStats<> const& benchmarkStats ) = 0; |
| 8428 | //! Called if running the benchmarks fails for any reason |
| 8429 | virtual void benchmarkFailed( StringRef benchmarkName ) = 0; |
| 8430 | |
| 8431 | //! Called before assertion success/failure is evaluated |
| 8432 | virtual void assertionStarting( AssertionInfo const& assertionInfo ) = 0; |
| 8433 | |
| 8434 | //! Called after assertion was fully evaluated |
| 8435 | virtual void assertionEnded( AssertionStats const& assertionStats ) = 0; |
| 8436 | |
| 8437 | //! Called after a `SECTION` has finished running |
| 8438 | virtual void sectionEnded( SectionStats const& sectionStats ) = 0; |
| 8439 | //! Called _every time_ a TEST_CASE is entered, including repeats (due to sections) |
| 8440 | virtual void testCasePartialEnded(TestCaseStats const& testCaseStats, uint64_t partNumber ) = 0; |
| 8441 | //! Called _once_ for each TEST_CASE, no matter how many times it is entered |
| 8442 | virtual void testCaseEnded( TestCaseStats const& testCaseStats ) = 0; |
| 8443 | /** |
| 8444 | * Called once after all tests in a testing run are finished |
| 8445 | * |
| 8446 | * Not called if tests weren't run (e.g. only listings happened) |
| 8447 | */ |
| 8448 | virtual void testRunEnded( TestRunStats const& testRunStats ) = 0; |
| 8449 | |
| 8450 | /** |
| 8451 | * Called with test cases that are skipped due to the test run aborting. |
| 8452 | * NOT called for test cases that are explicitly skipped using the `SKIP` macro. |
| 8453 | * |
| 8454 | * Deprecated - will be removed in the next major release. |
| 8455 | */ |
| 8456 | virtual void skipTest( TestCaseInfo const& testInfo ) = 0; |
| 8457 | |
| 8458 | //! Called if a fatal error (signal/structured exception) occurred |
| 8459 | virtual void fatalErrorEncountered( StringRef error ) = 0; |
| 8460 | |
| 8461 | //! Writes out information about provided reporters using reporter-specific format |
| 8462 | virtual void listReporters(std::vector<ReporterDescription> const& descriptions) = 0; |
| 8463 | //! Writes out the provided listeners descriptions using reporter-specific format |
| 8464 | virtual void listListeners(std::vector<ListenerDescription> const& descriptions) = 0; |
| 8465 | //! Writes out information about provided tests using reporter-specific format |
| 8466 | virtual void listTests(std::vector<TestCaseHandle> const& tests) = 0; |
| 8467 | //! Writes out information about the provided tags using reporter-specific format |
| 8468 | virtual void listTags(std::vector<TagInfo> const& tags) = 0; |
| 8469 | }; |
| 8470 | using IEventListenerPtr = Detail::unique_ptr<IEventListener>; |
| 8471 | |
| 8472 | } // end namespace Catch |
| 8473 | |
| 8474 | #endif // CATCH_INTERFACES_REPORTER_HPP_INCLUDED |
| 8475 | |
| 8476 | |
| 8477 | #ifndef CATCH_INTERFACES_REPORTER_FACTORY_HPP_INCLUDED |
| 8478 | #define CATCH_INTERFACES_REPORTER_FACTORY_HPP_INCLUDED |
| 8479 | |
| 8480 | |
| 8481 | #include <string> |
| 8482 | |
| 8483 | namespace Catch { |
| 8484 | |
| 8485 | struct ReporterConfig; |
| 8486 | class IConfig; |
| 8487 | class IEventListener; |
| 8488 | using IEventListenerPtr = Detail::unique_ptr<IEventListener>; |
| 8489 | |
| 8490 | |
| 8491 | class IReporterFactory { |
| 8492 | public: |
| 8493 | virtual ~IReporterFactory(); // = default |
| 8494 | |
| 8495 | virtual IEventListenerPtr |
| 8496 | create( ReporterConfig&& config ) const = 0; |
| 8497 | virtual std::string getDescription() const = 0; |
| 8498 | }; |
| 8499 | using IReporterFactoryPtr = Detail::unique_ptr<IReporterFactory>; |
| 8500 | |
| 8501 | class EventListenerFactory { |
| 8502 | public: |
| 8503 | virtual ~EventListenerFactory(); // = default |
| 8504 | virtual IEventListenerPtr create( IConfig const* config ) const = 0; |
| 8505 | //! Return a meaningful name for the listener, e.g. its type name |
| 8506 | virtual StringRef getName() const = 0; |
| 8507 | //! Return listener's description if available |
| 8508 | virtual std::string getDescription() const = 0; |
| 8509 | }; |
| 8510 | } // namespace Catch |
| 8511 | |
| 8512 | #endif // CATCH_INTERFACES_REPORTER_FACTORY_HPP_INCLUDED |
| 8513 | |
| 8514 | |
| 8515 | #ifndef CATCH_INTERFACES_TAG_ALIAS_REGISTRY_HPP_INCLUDED |
| 8516 | #define CATCH_INTERFACES_TAG_ALIAS_REGISTRY_HPP_INCLUDED |
| 8517 | |
| 8518 | #include <string> |
| 8519 | |
| 8520 | namespace Catch { |
| 8521 | |
| 8522 | struct TagAlias; |
| 8523 | |
| 8524 | class ITagAliasRegistry { |
| 8525 | public: |
| 8526 | virtual ~ITagAliasRegistry(); // = default |
| 8527 | // Nullptr if not present |
| 8528 | virtual TagAlias const* find( std::string const& alias ) const = 0; |
| 8529 | virtual std::string expandAliases( std::string const& unexpandedTestSpec ) const = 0; |
| 8530 | |
| 8531 | static ITagAliasRegistry const& get(); |
| 8532 | }; |
| 8533 | |
| 8534 | } // end namespace Catch |
| 8535 | |
| 8536 | #endif // CATCH_INTERFACES_TAG_ALIAS_REGISTRY_HPP_INCLUDED |
| 8537 | |
| 8538 | |
| 8539 | #ifndef CATCH_INTERFACES_TESTCASE_HPP_INCLUDED |
| 8540 | #define CATCH_INTERFACES_TESTCASE_HPP_INCLUDED |
| 8541 | |
| 8542 | #include <vector> |
| 8543 | |
| 8544 | namespace Catch { |
| 8545 | |
| 8546 | struct TestCaseInfo; |
| 8547 | class TestCaseHandle; |
| 8548 | class IConfig; |
| 8549 | |
| 8550 | class ITestCaseRegistry { |
| 8551 | public: |
| 8552 | virtual ~ITestCaseRegistry(); // = default |
| 8553 | // TODO: this exists only for adding filenames to test cases -- let's expose this in a saner way later |
| 8554 | virtual std::vector<TestCaseInfo* > const& getAllInfos() const = 0; |
| 8555 | virtual std::vector<TestCaseHandle> const& getAllTests() const = 0; |
| 8556 | virtual std::vector<TestCaseHandle> const& getAllTestsSorted( IConfig const& config ) const = 0; |
| 8557 | }; |
| 8558 | |
| 8559 | } |
| 8560 | |
| 8561 | #endif // CATCH_INTERFACES_TESTCASE_HPP_INCLUDED |
| 8562 | |
| 8563 | #endif // CATCH_INTERFACES_ALL_HPP_INCLUDED |
| 8564 | |
| 8565 | |
| 8566 | #ifndef CATCH_CASE_INSENSITIVE_COMPARISONS_HPP_INCLUDED |
| 8567 | #define CATCH_CASE_INSENSITIVE_COMPARISONS_HPP_INCLUDED |
| 8568 | |
| 8569 | |
| 8570 | namespace Catch { |
| 8571 | namespace Detail { |
| 8572 | //! Provides case-insensitive `op<` semantics when called |
| 8573 | struct CaseInsensitiveLess { |
| 8574 | bool operator()( StringRef lhs, |
| 8575 | StringRef rhs ) const; |
| 8576 | }; |
| 8577 | |
| 8578 | //! Provides case-insensitive `op==` semantics when called |
| 8579 | struct CaseInsensitiveEqualTo { |
| 8580 | bool operator()( StringRef lhs, |
| 8581 | StringRef rhs ) const; |
| 8582 | }; |
| 8583 | |
| 8584 | } // namespace Detail |
| 8585 | } // namespace Catch |
| 8586 | |
| 8587 | #endif // CATCH_CASE_INSENSITIVE_COMPARISONS_HPP_INCLUDED |
| 8588 | |
| 8589 | |
| 8590 | |
| 8591 | /** \file |
| 8592 | * Wrapper for ANDROID_LOGWRITE configuration option |
| 8593 | * |
| 8594 | * We want to default to enabling it when compiled for android, but |
| 8595 | * users of the library should also be able to disable it if they want |
| 8596 | * to. |
| 8597 | */ |
| 8598 | |
| 8599 | #ifndef CATCH_CONFIG_ANDROID_LOGWRITE_HPP_INCLUDED |
| 8600 | #define CATCH_CONFIG_ANDROID_LOGWRITE_HPP_INCLUDED |
| 8601 | |
| 8602 | |
| 8603 | #if defined(__ANDROID__) |
| 8604 | # define CATCH_INTERNAL_CONFIG_ANDROID_LOGWRITE |
| 8605 | #endif |
| 8606 | |
| 8607 | |
| 8608 | #if defined( CATCH_INTERNAL_CONFIG_ANDROID_LOGWRITE ) && \ |
| 8609 | !defined( CATCH_CONFIG_NO_ANDROID_LOGWRITE ) && \ |
| 8610 | !defined( CATCH_CONFIG_ANDROID_LOGWRITE ) |
| 8611 | # define CATCH_CONFIG_ANDROID_LOGWRITE |
| 8612 | #endif |
| 8613 | |
| 8614 | #endif // CATCH_CONFIG_ANDROID_LOGWRITE_HPP_INCLUDED |
| 8615 | |
| 8616 | |
| 8617 | |
| 8618 | /** \file |
| 8619 | * Wrapper for UNCAUGHT_EXCEPTIONS configuration option |
| 8620 | * |
| 8621 | * For some functionality, Catch2 requires to know whether there is |
| 8622 | * an active exception. Because `std::uncaught_exception` is deprecated |
| 8623 | * in C++17, we want to use `std::uncaught_exceptions` if possible. |
| 8624 | */ |
| 8625 | |
| 8626 | #ifndef CATCH_CONFIG_UNCAUGHT_EXCEPTIONS_HPP_INCLUDED |
| 8627 | #define CATCH_CONFIG_UNCAUGHT_EXCEPTIONS_HPP_INCLUDED |
| 8628 | |
| 8629 | |
| 8630 | #if defined(_MSC_VER) |
| 8631 | # if _MSC_VER >= 1900 // Visual Studio 2015 or newer |
| 8632 | # define CATCH_INTERNAL_CONFIG_CPP17_UNCAUGHT_EXCEPTIONS |
| 8633 | # endif |
| 8634 | #endif |
| 8635 | |
| 8636 | |
| 8637 | #include <exception> |
| 8638 | |
| 8639 | #if defined(__cpp_lib_uncaught_exceptions) \ |
| 8640 | && !defined(CATCH_INTERNAL_CONFIG_CPP17_UNCAUGHT_EXCEPTIONS) |
| 8641 | |
| 8642 | # define CATCH_INTERNAL_CONFIG_CPP17_UNCAUGHT_EXCEPTIONS |
| 8643 | #endif // __cpp_lib_uncaught_exceptions |
| 8644 | |
| 8645 | |
| 8646 | #if defined(CATCH_INTERNAL_CONFIG_CPP17_UNCAUGHT_EXCEPTIONS) \ |
| 8647 | && !defined(CATCH_CONFIG_NO_CPP17_UNCAUGHT_EXCEPTIONS) \ |
| 8648 | && !defined(CATCH_CONFIG_CPP17_UNCAUGHT_EXCEPTIONS) |
| 8649 | |
| 8650 | # define CATCH_CONFIG_CPP17_UNCAUGHT_EXCEPTIONS |
| 8651 | #endif |
| 8652 | |
| 8653 | |
| 8654 | #endif // CATCH_CONFIG_UNCAUGHT_EXCEPTIONS_HPP_INCLUDED |
| 8655 | |
| 8656 | |
| 8657 | #ifndef CATCH_CONSOLE_WIDTH_HPP_INCLUDED |
| 8658 | #define CATCH_CONSOLE_WIDTH_HPP_INCLUDED |
| 8659 | |
| 8660 | // This include must be kept so that user's configured value for CONSOLE_WIDTH |
| 8661 | // is used before we attempt to provide a default value |
| 8662 | |
| 8663 | #ifndef CATCH_CONFIG_CONSOLE_WIDTH |
| 8664 | #define CATCH_CONFIG_CONSOLE_WIDTH 80 |
| 8665 | #endif |
| 8666 | |
| 8667 | #endif // CATCH_CONSOLE_WIDTH_HPP_INCLUDED |
| 8668 | |
| 8669 | |
| 8670 | #ifndef CATCH_CONTAINER_NONMEMBERS_HPP_INCLUDED |
| 8671 | #define CATCH_CONTAINER_NONMEMBERS_HPP_INCLUDED |
| 8672 | |
| 8673 | |
| 8674 | #include <cstddef> |
| 8675 | #include <initializer_list> |
| 8676 | |
| 8677 | // We want a simple polyfill over `std::empty`, `std::size` and so on |
| 8678 | // for C++14 or C++ libraries with incomplete support. |
| 8679 | // We also have to handle that MSVC std lib will happily provide these |
| 8680 | // under older standards. |
| 8681 | #if defined(CATCH_CPP17_OR_GREATER) || defined(_MSC_VER) |
| 8682 | |
| 8683 | // We are already using this header either way, so there shouldn't |
| 8684 | // be much additional overhead in including it to get the feature |
| 8685 | // test macros |
| 8686 | #include <string> |
| 8687 | |
| 8688 | # if !defined(__cpp_lib_nonmember_container_access) |
| 8689 | # define CATCH_CONFIG_POLYFILL_NONMEMBER_CONTAINER_ACCESS |
| 8690 | # endif |
| 8691 | |
| 8692 | #else |
| 8693 | #define CATCH_CONFIG_POLYFILL_NONMEMBER_CONTAINER_ACCESS |
| 8694 | #endif |
| 8695 | |
| 8696 | |
| 8697 | |
| 8698 | namespace Catch { |
| 8699 | namespace Detail { |
| 8700 | |
| 8701 | #if defined(CATCH_CONFIG_POLYFILL_NONMEMBER_CONTAINER_ACCESS) |
| 8702 | template <typename Container> |
| 8703 | constexpr auto empty(Container const& cont) -> decltype(cont.empty()) { |
| 8704 | return cont.empty(); |
| 8705 | } |
| 8706 | template <typename T, std::size_t N> |
| 8707 | constexpr bool empty(const T (&)[N]) noexcept { |
| 8708 | // GCC < 7 does not support the const T(&)[] parameter syntax |
| 8709 | // so we have to ignore the length explicitly |
| 8710 | (void)N; |
| 8711 | return false; |
| 8712 | } |
| 8713 | template <typename T> |
| 8714 | constexpr bool empty(std::initializer_list<T> list) noexcept { |
| 8715 | return list.size() > 0; |
| 8716 | } |
| 8717 | |
| 8718 | |
| 8719 | template <typename Container> |
| 8720 | constexpr auto size(Container const& cont) -> decltype(cont.size()) { |
| 8721 | return cont.size(); |
| 8722 | } |
| 8723 | template <typename T, std::size_t N> |
| 8724 | constexpr std::size_t size(const T(&)[N]) noexcept { |
| 8725 | return N; |
| 8726 | } |
| 8727 | #endif // CATCH_CONFIG_POLYFILL_NONMEMBER_CONTAINER_ACCESS |
| 8728 | |
| 8729 | } // end namespace Detail |
| 8730 | } // end namespace Catch |
| 8731 | |
| 8732 | |
| 8733 | |
| 8734 | #endif // CATCH_CONTAINER_NONMEMBERS_HPP_INCLUDED |
| 8735 | |
| 8736 | |
| 8737 | #ifndef CATCH_DEBUG_CONSOLE_HPP_INCLUDED |
| 8738 | #define CATCH_DEBUG_CONSOLE_HPP_INCLUDED |
| 8739 | |
| 8740 | #include <string> |
| 8741 | |
| 8742 | namespace Catch { |
| 8743 | void writeToDebugConsole( std::string const& text ); |
| 8744 | } |
| 8745 | |
| 8746 | #endif // CATCH_DEBUG_CONSOLE_HPP_INCLUDED |
| 8747 | |
| 8748 | |
| 8749 | #ifndef CATCH_DEBUGGER_HPP_INCLUDED |
| 8750 | #define CATCH_DEBUGGER_HPP_INCLUDED |
| 8751 | |
| 8752 | |
| 8753 | namespace Catch { |
| 8754 | bool isDebuggerActive(); |
| 8755 | } |
| 8756 | |
| 8757 | #ifdef CATCH_PLATFORM_MAC |
| 8758 | |
| 8759 | #if defined(__i386__) || defined(__x86_64__) |
| 8760 | #define CATCH_TRAP() __asm__("int $3\n" : : ) /* NOLINT */ |
| 8761 | #elif defined(__aarch64__) |
| 8762 | #define CATCH_TRAP() __asm__(".inst 0xd43e0000") |
| 8763 | #elif defined(__POWERPC__) |
| 8764 | #define CATCH_TRAP() __asm__("li r0, 20\nsc\nnop\nli r0, 37\nli r4, 2\nsc\nnop\n" \ |
| 8765 | : : : "memory","r0","r3","r4" ) /* NOLINT */ |
| 8766 | #endif |
| 8767 | |
| 8768 | #elif defined(CATCH_PLATFORM_IPHONE) |
| 8769 | |
| 8770 | // use inline assembler |
| 8771 | #if defined(__i386__) || defined(__x86_64__) |
| 8772 | #define CATCH_TRAP() __asm__("int $3") |
| 8773 | #elif defined(__aarch64__) |
| 8774 | #define CATCH_TRAP() __asm__(".inst 0xd4200000") |
| 8775 | #elif defined(__arm__) && !defined(__thumb__) |
| 8776 | #define CATCH_TRAP() __asm__(".inst 0xe7f001f0") |
| 8777 | #elif defined(__arm__) && defined(__thumb__) |
| 8778 | #define CATCH_TRAP() __asm__(".inst 0xde01") |
| 8779 | #endif |
| 8780 | |
| 8781 | #elif defined(CATCH_PLATFORM_LINUX) |
| 8782 | // If we can use inline assembler, do it because this allows us to break |
| 8783 | // directly at the location of the failing check instead of breaking inside |
| 8784 | // raise() called from it, i.e. one stack frame below. |
| 8785 | #if defined(__GNUC__) && (defined(__i386) || defined(__x86_64)) |
| 8786 | #define CATCH_TRAP() asm volatile ("int $3") /* NOLINT */ |
| 8787 | #else // Fall back to the generic way. |
| 8788 | #include <signal.h> |
| 8789 | |
| 8790 | #define CATCH_TRAP() raise(SIGTRAP) |
| 8791 | #endif |
| 8792 | #elif defined(_MSC_VER) |
| 8793 | #define CATCH_TRAP() __debugbreak() |
| 8794 | #elif defined(__MINGW32__) |
| 8795 | extern "C" __declspec(dllimport) void __stdcall DebugBreak(); |
| 8796 | #define CATCH_TRAP() DebugBreak() |
| 8797 | #endif |
| 8798 | |
| 8799 | #ifndef CATCH_BREAK_INTO_DEBUGGER |
| 8800 | #ifdef CATCH_TRAP |
| 8801 | #define CATCH_BREAK_INTO_DEBUGGER() []{ if( Catch::isDebuggerActive() ) { CATCH_TRAP(); } }() |
| 8802 | #else |
| 8803 | #define CATCH_BREAK_INTO_DEBUGGER() []{}() |
| 8804 | #endif |
| 8805 | #endif |
| 8806 | |
| 8807 | #endif // CATCH_DEBUGGER_HPP_INCLUDED |
| 8808 | |
| 8809 | |
| 8810 | #ifndef CATCH_ENFORCE_HPP_INCLUDED |
| 8811 | #define CATCH_ENFORCE_HPP_INCLUDED |
| 8812 | |
| 8813 | |
| 8814 | #include <exception> |
| 8815 | |
| 8816 | namespace Catch { |
| 8817 | #if !defined(CATCH_CONFIG_DISABLE_EXCEPTIONS) |
| 8818 | template <typename Ex> |
| 8819 | [[noreturn]] |
| 8820 | void throw_exception(Ex const& e) { |
| 8821 | throw e; |
| 8822 | } |
| 8823 | #else // ^^ Exceptions are enabled // Exceptions are disabled vv |
| 8824 | [[noreturn]] |
| 8825 | void throw_exception(std::exception const& e); |
| 8826 | #endif |
| 8827 | |
| 8828 | [[noreturn]] |
| 8829 | void throw_logic_error(std::string const& msg); |
| 8830 | [[noreturn]] |
| 8831 | void throw_domain_error(std::string const& msg); |
| 8832 | [[noreturn]] |
| 8833 | void throw_runtime_error(std::string const& msg); |
| 8834 | |
| 8835 | } // namespace Catch; |
| 8836 | |
| 8837 | #define CATCH_MAKE_MSG(...) \ |
| 8838 | (Catch::ReusableStringStream() << __VA_ARGS__).str() |
| 8839 | |
| 8840 | #define CATCH_INTERNAL_ERROR(...) \ |
| 8841 | Catch::throw_logic_error(CATCH_MAKE_MSG( CATCH_INTERNAL_LINEINFO << ": Internal Catch2 error: " << __VA_ARGS__)) |
| 8842 | |
| 8843 | #define CATCH_ERROR(...) \ |
| 8844 | Catch::throw_domain_error(CATCH_MAKE_MSG( __VA_ARGS__ )) |
| 8845 | |
| 8846 | #define CATCH_RUNTIME_ERROR(...) \ |
| 8847 | Catch::throw_runtime_error(CATCH_MAKE_MSG( __VA_ARGS__ )) |
| 8848 | |
| 8849 | #define CATCH_ENFORCE( condition, ... ) \ |
| 8850 | do{ if( !(condition) ) CATCH_ERROR( __VA_ARGS__ ); } while(false) |
| 8851 | |
| 8852 | |
| 8853 | #endif // CATCH_ENFORCE_HPP_INCLUDED |
| 8854 | |
| 8855 | |
| 8856 | #ifndef CATCH_ENUM_VALUES_REGISTRY_HPP_INCLUDED |
| 8857 | #define CATCH_ENUM_VALUES_REGISTRY_HPP_INCLUDED |
| 8858 | |
| 8859 | |
| 8860 | #include <vector> |
| 8861 | |
| 8862 | namespace Catch { |
| 8863 | |
| 8864 | namespace Detail { |
| 8865 | |
| 8866 | Catch::Detail::unique_ptr<EnumInfo> makeEnumInfo( StringRef enumName, StringRef allValueNames, std::vector<int> const& values ); |
| 8867 | |
| 8868 | class EnumValuesRegistry : public IMutableEnumValuesRegistry { |
| 8869 | |
| 8870 | std::vector<Catch::Detail::unique_ptr<EnumInfo>> m_enumInfos; |
| 8871 | |
| 8872 | EnumInfo const& registerEnum( StringRef enumName, StringRef allEnums, std::vector<int> const& values) override; |
| 8873 | }; |
| 8874 | |
| 8875 | std::vector<StringRef> parseEnums( StringRef enums ); |
| 8876 | |
| 8877 | } // Detail |
| 8878 | |
| 8879 | } // Catch |
| 8880 | |
| 8881 | #endif // CATCH_ENUM_VALUES_REGISTRY_HPP_INCLUDED |
| 8882 | |
| 8883 | |
| 8884 | #ifndef CATCH_ERRNO_GUARD_HPP_INCLUDED |
| 8885 | #define CATCH_ERRNO_GUARD_HPP_INCLUDED |
| 8886 | |
| 8887 | namespace Catch { |
| 8888 | |
| 8889 | //! Simple RAII class that stores the value of `errno` |
| 8890 | //! at construction and restores it at destruction. |
| 8891 | class ErrnoGuard { |
| 8892 | public: |
| 8893 | // Keep these outlined to avoid dragging in macros from <cerrno> |
| 8894 | |
| 8895 | ErrnoGuard(); |
| 8896 | ~ErrnoGuard(); |
| 8897 | private: |
| 8898 | int m_oldErrno; |
| 8899 | }; |
| 8900 | |
| 8901 | } |
| 8902 | |
| 8903 | #endif // CATCH_ERRNO_GUARD_HPP_INCLUDED |
| 8904 | |
| 8905 | |
| 8906 | #ifndef CATCH_EXCEPTION_TRANSLATOR_REGISTRY_HPP_INCLUDED |
| 8907 | #define CATCH_EXCEPTION_TRANSLATOR_REGISTRY_HPP_INCLUDED |
| 8908 | |
| 8909 | |
| 8910 | #include <vector> |
| 8911 | #include <string> |
| 8912 | |
| 8913 | namespace Catch { |
| 8914 | |
| 8915 | class ExceptionTranslatorRegistry : public IExceptionTranslatorRegistry { |
| 8916 | public: |
| 8917 | ~ExceptionTranslatorRegistry() override; |
| 8918 | void registerTranslator( Detail::unique_ptr<IExceptionTranslator>&& translator ); |
| 8919 | std::string translateActiveException() const override; |
| 8920 | |
| 8921 | private: |
| 8922 | ExceptionTranslators m_translators; |
| 8923 | }; |
| 8924 | } |
| 8925 | |
| 8926 | #endif // CATCH_EXCEPTION_TRANSLATOR_REGISTRY_HPP_INCLUDED |
| 8927 | |
| 8928 | |
| 8929 | #ifndef CATCH_FATAL_CONDITION_HANDLER_HPP_INCLUDED |
| 8930 | #define CATCH_FATAL_CONDITION_HANDLER_HPP_INCLUDED |
| 8931 | |
| 8932 | |
| 8933 | #include <cassert> |
| 8934 | |
| 8935 | namespace Catch { |
| 8936 | |
| 8937 | /** |
| 8938 | * Wrapper for platform-specific fatal error (signals/SEH) handlers |
| 8939 | * |
| 8940 | * Tries to be cooperative with other handlers, and not step over |
| 8941 | * other handlers. This means that unknown structured exceptions |
| 8942 | * are passed on, previous signal handlers are called, and so on. |
| 8943 | * |
| 8944 | * Can only be instantiated once, and assumes that once a signal |
| 8945 | * is caught, the binary will end up terminating. Thus, there |
| 8946 | */ |
| 8947 | class FatalConditionHandler { |
| 8948 | bool m_started = false; |
| 8949 | |
| 8950 | // Install/disengage implementation for specific platform. |
| 8951 | // Should be if-defed to work on current platform, can assume |
| 8952 | // engage-disengage 1:1 pairing. |
| 8953 | void engage_platform(); |
| 8954 | void disengage_platform() noexcept; |
| 8955 | public: |
| 8956 | // Should also have platform-specific implementations as needed |
| 8957 | FatalConditionHandler(); |
| 8958 | ~FatalConditionHandler(); |
| 8959 | |
| 8960 | void engage() { |
| 8961 | assert(!m_started && "Handler cannot be installed twice."); |
| 8962 | m_started = true; |
| 8963 | engage_platform(); |
| 8964 | } |
| 8965 | |
| 8966 | void disengage() noexcept { |
| 8967 | assert(m_started && "Handler cannot be uninstalled without being installed first"); |
| 8968 | m_started = false; |
| 8969 | disengage_platform(); |
| 8970 | } |
| 8971 | }; |
| 8972 | |
| 8973 | //! Simple RAII guard for (dis)engaging the FatalConditionHandler |
| 8974 | class FatalConditionHandlerGuard { |
| 8975 | FatalConditionHandler* m_handler; |
| 8976 | public: |
| 8977 | FatalConditionHandlerGuard(FatalConditionHandler* handler): |
| 8978 | m_handler(handler) { |
| 8979 | m_handler->engage(); |
| 8980 | } |
| 8981 | ~FatalConditionHandlerGuard() { |
| 8982 | m_handler->disengage(); |
| 8983 | } |
| 8984 | }; |
| 8985 | |
| 8986 | } // end namespace Catch |
| 8987 | |
| 8988 | #endif // CATCH_FATAL_CONDITION_HANDLER_HPP_INCLUDED |
| 8989 | |
| 8990 | |
| 8991 | #ifndef CATCH_FLOATING_POINT_HELPERS_HPP_INCLUDED |
| 8992 | #define CATCH_FLOATING_POINT_HELPERS_HPP_INCLUDED |
| 8993 | |
| 8994 | |
| 8995 | |
| 8996 | #ifndef CATCH_POLYFILLS_HPP_INCLUDED |
| 8997 | #define CATCH_POLYFILLS_HPP_INCLUDED |
| 8998 | |
| 8999 | namespace Catch { |
| 9000 | bool isnan(float f); |
| 9001 | bool isnan(double d); |
| 9002 | } |
| 9003 | |
| 9004 | #endif // CATCH_POLYFILLS_HPP_INCLUDED |
| 9005 | |
| 9006 | #include <cassert> |
| 9007 | #include <cmath> |
| 9008 | #include <cstdint> |
| 9009 | #include <utility> |
| 9010 | #include <limits> |
| 9011 | |
| 9012 | namespace Catch { |
| 9013 | namespace Detail { |
| 9014 | |
| 9015 | uint32_t convertToBits(float f); |
| 9016 | uint64_t convertToBits(double d); |
| 9017 | |
| 9018 | } // end namespace Detail |
| 9019 | |
| 9020 | |
| 9021 | |
| 9022 | #if defined( __GNUC__ ) || defined( __clang__ ) |
| 9023 | # pragma GCC diagnostic push |
| 9024 | // We do a bunch of direct compensations of floating point numbers, |
| 9025 | // because we know what we are doing and actually do want the direct |
| 9026 | // comparison behaviour. |
| 9027 | # pragma GCC diagnostic ignored "-Wfloat-equal" |
| 9028 | #endif |
| 9029 | |
| 9030 | /** |
| 9031 | * Calculates the ULP distance between two floating point numbers |
| 9032 | * |
| 9033 | * The ULP distance of two floating point numbers is the count of |
| 9034 | * valid floating point numbers representable between them. |
| 9035 | * |
| 9036 | * There are some exceptions between how this function counts the |
| 9037 | * distance, and the interpretation of the standard as implemented. |
| 9038 | * by e.g. `nextafter`. For this function it always holds that: |
| 9039 | * * `(x == y) => ulpDistance(x, y) == 0` (so `ulpDistance(-0, 0) == 0`) |
| 9040 | * * `ulpDistance(maxFinite, INF) == 1` |
| 9041 | * * `ulpDistance(x, -x) == 2 * ulpDistance(x, 0)` |
| 9042 | * |
| 9043 | * \pre `!isnan( lhs )` |
| 9044 | * \pre `!isnan( rhs )` |
| 9045 | * \pre floating point numbers are represented in IEEE-754 format |
| 9046 | */ |
| 9047 | template <typename FP> |
| 9048 | uint64_t ulpDistance( FP lhs, FP rhs ) { |
| 9049 | assert( std::numeric_limits<FP>::is_iec559 && |
| 9050 | "ulpDistance assumes IEEE-754 format for floating point types" ); |
| 9051 | assert( !Catch::isnan( lhs ) && |
| 9052 | "Distance between NaN and number is not meaningful" ); |
| 9053 | assert( !Catch::isnan( rhs ) && |
| 9054 | "Distance between NaN and number is not meaningful" ); |
| 9055 | |
| 9056 | // We want X == Y to imply 0 ULP distance even if X and Y aren't |
| 9057 | // bit-equal (-0 and 0), or X - Y != 0 (same sign infinities). |
| 9058 | if ( lhs == rhs ) { return 0; } |
| 9059 | |
| 9060 | // We need a properly typed positive zero for type inference. |
| 9061 | static constexpr FP positive_zero{}; |
| 9062 | |
| 9063 | // We want to ensure that +/- 0 is always represented as positive zero |
| 9064 | if ( lhs == positive_zero ) { lhs = positive_zero; } |
| 9065 | if ( rhs == positive_zero ) { rhs = positive_zero; } |
| 9066 | |
| 9067 | // If arguments have different signs, we can handle them by summing |
| 9068 | // how far are they from 0 each. |
| 9069 | if ( std::signbit( lhs ) != std::signbit( rhs ) ) { |
| 9070 | return ulpDistance( std::abs( lhs ), positive_zero ) + |
| 9071 | ulpDistance( std::abs( rhs ), positive_zero ); |
| 9072 | } |
| 9073 | |
| 9074 | // When both lhs and rhs are of the same sign, we can just |
| 9075 | // read the numbers bitwise as integers, and then subtract them |
| 9076 | // (assuming IEEE). |
| 9077 | uint64_t lc = Detail::convertToBits( lhs ); |
| 9078 | uint64_t rc = Detail::convertToBits( rhs ); |
| 9079 | |
| 9080 | // The ulp distance between two numbers is symmetric, so to avoid |
| 9081 | // dealing with overflows we want the bigger converted number on the lhs |
| 9082 | if ( lc < rc ) { |
| 9083 | std::swap( lc, rc ); |
| 9084 | } |
| 9085 | |
| 9086 | return lc - rc; |
| 9087 | } |
| 9088 | |
| 9089 | #if defined( __GNUC__ ) || defined( __clang__ ) |
| 9090 | # pragma GCC diagnostic pop |
| 9091 | #endif |
| 9092 | |
| 9093 | |
| 9094 | } // end namespace Catch |
| 9095 | |
| 9096 | #endif // CATCH_FLOATING_POINT_HELPERS_HPP_INCLUDED |
| 9097 | |
| 9098 | |
| 9099 | #ifndef CATCH_GETENV_HPP_INCLUDED |
| 9100 | #define CATCH_GETENV_HPP_INCLUDED |
| 9101 | |
| 9102 | namespace Catch { |
| 9103 | namespace Detail { |
| 9104 | |
| 9105 | //! Wrapper over `std::getenv` that compiles on UWP (and always returns nullptr there) |
| 9106 | char const* getEnv(char const* varName); |
| 9107 | |
| 9108 | } |
| 9109 | } |
| 9110 | |
| 9111 | #endif // CATCH_GETENV_HPP_INCLUDED |
| 9112 | |
| 9113 | |
| 9114 | #ifndef CATCH_IS_PERMUTATION_HPP_INCLUDED |
| 9115 | #define CATCH_IS_PERMUTATION_HPP_INCLUDED |
| 9116 | |
| 9117 | #include <algorithm> |
| 9118 | #include <iterator> |
| 9119 | |
| 9120 | namespace Catch { |
| 9121 | namespace Detail { |
| 9122 | |
| 9123 | template <typename ForwardIter, |
| 9124 | typename Sentinel, |
| 9125 | typename T, |
| 9126 | typename Comparator> |
| 9127 | ForwardIter find_sentinel( ForwardIter start, |
| 9128 | Sentinel sentinel, |
| 9129 | T const& value, |
| 9130 | Comparator cmp ) { |
| 9131 | while ( start != sentinel ) { |
| 9132 | if ( cmp( *start, value ) ) { break; } |
| 9133 | ++start; |
| 9134 | } |
| 9135 | return start; |
| 9136 | } |
| 9137 | |
| 9138 | template <typename ForwardIter, |
| 9139 | typename Sentinel, |
| 9140 | typename T, |
| 9141 | typename Comparator> |
| 9142 | std::ptrdiff_t count_sentinel( ForwardIter start, |
| 9143 | Sentinel sentinel, |
| 9144 | T const& value, |
| 9145 | Comparator cmp ) { |
| 9146 | std::ptrdiff_t count = 0; |
| 9147 | while ( start != sentinel ) { |
| 9148 | if ( cmp( *start, value ) ) { ++count; } |
| 9149 | ++start; |
| 9150 | } |
| 9151 | return count; |
| 9152 | } |
| 9153 | |
| 9154 | template <typename ForwardIter, typename Sentinel> |
| 9155 | std::enable_if_t<!std::is_same<ForwardIter, Sentinel>::value, |
| 9156 | std::ptrdiff_t> |
| 9157 | sentinel_distance( ForwardIter iter, const Sentinel sentinel ) { |
| 9158 | std::ptrdiff_t dist = 0; |
| 9159 | while ( iter != sentinel ) { |
| 9160 | ++iter; |
| 9161 | ++dist; |
| 9162 | } |
| 9163 | return dist; |
| 9164 | } |
| 9165 | |
| 9166 | template <typename ForwardIter> |
| 9167 | std::ptrdiff_t sentinel_distance( ForwardIter first, |
| 9168 | ForwardIter last ) { |
| 9169 | return std::distance( first, last ); |
| 9170 | } |
| 9171 | |
| 9172 | template <typename ForwardIter1, |
| 9173 | typename Sentinel1, |
| 9174 | typename ForwardIter2, |
| 9175 | typename Sentinel2, |
| 9176 | typename Comparator> |
| 9177 | bool check_element_counts( ForwardIter1 first_1, |
| 9178 | const Sentinel1 end_1, |
| 9179 | ForwardIter2 first_2, |
| 9180 | const Sentinel2 end_2, |
| 9181 | Comparator cmp ) { |
| 9182 | auto cursor = first_1; |
| 9183 | while ( cursor != end_1 ) { |
| 9184 | if ( find_sentinel( first_1, cursor, *cursor, cmp ) == |
| 9185 | cursor ) { |
| 9186 | // we haven't checked this element yet |
| 9187 | const auto count_in_range_2 = |
| 9188 | count_sentinel( first_2, end_2, *cursor, cmp ); |
| 9189 | // Not a single instance in 2nd range, so it cannot be a |
| 9190 | // permutation of 1st range |
| 9191 | if ( count_in_range_2 == 0 ) { return false; } |
| 9192 | |
| 9193 | const auto count_in_range_1 = |
| 9194 | count_sentinel( cursor, end_1, *cursor, cmp ); |
| 9195 | if ( count_in_range_1 != count_in_range_2 ) { |
| 9196 | return false; |
| 9197 | } |
| 9198 | } |
| 9199 | |
| 9200 | ++cursor; |
| 9201 | } |
| 9202 | |
| 9203 | return true; |
| 9204 | } |
| 9205 | |
| 9206 | template <typename ForwardIter1, |
| 9207 | typename Sentinel1, |
| 9208 | typename ForwardIter2, |
| 9209 | typename Sentinel2, |
| 9210 | typename Comparator> |
| 9211 | bool is_permutation( ForwardIter1 first_1, |
| 9212 | const Sentinel1 end_1, |
| 9213 | ForwardIter2 first_2, |
| 9214 | const Sentinel2 end_2, |
| 9215 | Comparator cmp ) { |
| 9216 | // TODO: no optimization for stronger iterators, because we would also have to constrain on sentinel vs not sentinel types |
| 9217 | // TODO: Comparator has to be "both sides", e.g. a == b => b == a |
| 9218 | // This skips shared prefix of the two ranges |
| 9219 | while (first_1 != end_1 && first_2 != end_2 && cmp(*first_1, *first_2)) { |
| 9220 | ++first_1; |
| 9221 | ++first_2; |
| 9222 | } |
| 9223 | |
| 9224 | // We need to handle case where at least one of the ranges has no more elements |
| 9225 | if (first_1 == end_1 || first_2 == end_2) { |
| 9226 | return first_1 == end_1 && first_2 == end_2; |
| 9227 | } |
| 9228 | |
| 9229 | // pair counting is n**2, so we pay linear walk to compare the sizes first |
| 9230 | auto dist_1 = sentinel_distance( first_1, end_1 ); |
| 9231 | auto dist_2 = sentinel_distance( first_2, end_2 ); |
| 9232 | |
| 9233 | if (dist_1 != dist_2) { return false; } |
| 9234 | |
| 9235 | // Since we do not try to handle stronger iterators pair (e.g. |
| 9236 | // bidir) optimally, the only thing left to do is to check counts in |
| 9237 | // the remaining ranges. |
| 9238 | return check_element_counts( first_1, end_1, first_2, end_2, cmp ); |
| 9239 | } |
| 9240 | |
| 9241 | } // namespace Detail |
| 9242 | } // namespace Catch |
| 9243 | |
| 9244 | #endif // CATCH_IS_PERMUTATION_HPP_INCLUDED |
| 9245 | |
| 9246 | |
| 9247 | #ifndef CATCH_ISTREAM_HPP_INCLUDED |
| 9248 | #define CATCH_ISTREAM_HPP_INCLUDED |
| 9249 | |
| 9250 | |
| 9251 | #include <iosfwd> |
| 9252 | #include <cstddef> |
| 9253 | #include <ostream> |
| 9254 | #include <string> |
| 9255 | |
| 9256 | namespace Catch { |
| 9257 | |
| 9258 | class IStream { |
| 9259 | public: |
| 9260 | virtual ~IStream(); // = default |
| 9261 | virtual std::ostream& stream() = 0; |
| 9262 | /** |
| 9263 | * Best guess on whether the instance is writing to a console (e.g. via stdout/stderr) |
| 9264 | * |
| 9265 | * This is useful for e.g. Win32 colour support, because the Win32 |
| 9266 | * API manipulates console directly, unlike POSIX escape codes, |
| 9267 | * that can be written anywhere. |
| 9268 | * |
| 9269 | * Due to variety of ways to change where the stdout/stderr is |
| 9270 | * _actually_ being written, users should always assume that |
| 9271 | * the answer might be wrong. |
| 9272 | */ |
| 9273 | virtual bool isConsole() const { return false; } |
| 9274 | }; |
| 9275 | |
| 9276 | /** |
| 9277 | * Creates a stream wrapper that writes to specific file. |
| 9278 | * |
| 9279 | * Also recognizes 4 special filenames |
| 9280 | * * `-` for stdout |
| 9281 | * * `%stdout` for stdout |
| 9282 | * * `%stderr` for stderr |
| 9283 | * * `%debug` for platform specific debugging output |
| 9284 | * |
| 9285 | * \throws if passed an unrecognized %-prefixed stream |
| 9286 | */ |
| 9287 | auto makeStream( std::string const& filename ) -> Detail::unique_ptr<IStream>; |
| 9288 | |
| 9289 | } |
| 9290 | |
| 9291 | #endif // CATCH_STREAM_HPP_INCLUDED |
| 9292 | |
| 9293 | |
| 9294 | #ifndef CATCH_LEAK_DETECTOR_HPP_INCLUDED |
| 9295 | #define CATCH_LEAK_DETECTOR_HPP_INCLUDED |
| 9296 | |
| 9297 | namespace Catch { |
| 9298 | |
| 9299 | struct LeakDetector { |
| 9300 | LeakDetector(); |
| 9301 | ~LeakDetector(); |
| 9302 | }; |
| 9303 | |
| 9304 | } |
| 9305 | #endif // CATCH_LEAK_DETECTOR_HPP_INCLUDED |
| 9306 | |
| 9307 | |
| 9308 | #ifndef CATCH_LIST_HPP_INCLUDED |
| 9309 | #define CATCH_LIST_HPP_INCLUDED |
| 9310 | |
| 9311 | |
| 9312 | #include <set> |
| 9313 | #include <string> |
| 9314 | |
| 9315 | |
| 9316 | namespace Catch { |
| 9317 | |
| 9318 | class IEventListener; |
| 9319 | class Config; |
| 9320 | |
| 9321 | |
| 9322 | struct ReporterDescription { |
| 9323 | std::string name, description; |
| 9324 | }; |
| 9325 | struct ListenerDescription { |
| 9326 | StringRef name; |
| 9327 | std::string description; |
| 9328 | }; |
| 9329 | |
| 9330 | struct TagInfo { |
| 9331 | void add(StringRef spelling); |
| 9332 | std::string all() const; |
| 9333 | |
| 9334 | std::set<StringRef> spellings; |
| 9335 | std::size_t count = 0; |
| 9336 | }; |
| 9337 | |
| 9338 | bool list( IEventListener& reporter, Config const& config ); |
| 9339 | |
| 9340 | } // end namespace Catch |
| 9341 | |
| 9342 | #endif // CATCH_LIST_HPP_INCLUDED |
| 9343 | |
| 9344 | |
| 9345 | #ifndef CATCH_OUTPUT_REDIRECT_HPP_INCLUDED |
| 9346 | #define CATCH_OUTPUT_REDIRECT_HPP_INCLUDED |
| 9347 | |
| 9348 | |
| 9349 | #include <cstdio> |
| 9350 | #include <iosfwd> |
| 9351 | #include <string> |
| 9352 | |
| 9353 | namespace Catch { |
| 9354 | |
| 9355 | class RedirectedStream { |
| 9356 | std::ostream& m_originalStream; |
| 9357 | std::ostream& m_redirectionStream; |
| 9358 | std::streambuf* m_prevBuf; |
| 9359 | |
| 9360 | public: |
| 9361 | RedirectedStream( std::ostream& originalStream, std::ostream& redirectionStream ); |
| 9362 | ~RedirectedStream(); |
| 9363 | }; |
| 9364 | |
| 9365 | class RedirectedStdOut { |
| 9366 | ReusableStringStream m_rss; |
| 9367 | RedirectedStream m_cout; |
| 9368 | public: |
| 9369 | RedirectedStdOut(); |
| 9370 | auto str() const -> std::string; |
| 9371 | }; |
| 9372 | |
| 9373 | // StdErr has two constituent streams in C++, std::cerr and std::clog |
| 9374 | // This means that we need to redirect 2 streams into 1 to keep proper |
| 9375 | // order of writes |
| 9376 | class RedirectedStdErr { |
| 9377 | ReusableStringStream m_rss; |
| 9378 | RedirectedStream m_cerr; |
| 9379 | RedirectedStream m_clog; |
| 9380 | public: |
| 9381 | RedirectedStdErr(); |
| 9382 | auto str() const -> std::string; |
| 9383 | }; |
| 9384 | |
| 9385 | class RedirectedStreams { |
| 9386 | public: |
| 9387 | RedirectedStreams(RedirectedStreams const&) = delete; |
| 9388 | RedirectedStreams& operator=(RedirectedStreams const&) = delete; |
| 9389 | RedirectedStreams(RedirectedStreams&&) = delete; |
| 9390 | RedirectedStreams& operator=(RedirectedStreams&&) = delete; |
| 9391 | |
| 9392 | RedirectedStreams(std::string& redirectedCout, std::string& redirectedCerr); |
| 9393 | ~RedirectedStreams(); |
| 9394 | private: |
| 9395 | std::string& m_redirectedCout; |
| 9396 | std::string& m_redirectedCerr; |
| 9397 | RedirectedStdOut m_redirectedStdOut; |
| 9398 | RedirectedStdErr m_redirectedStdErr; |
| 9399 | }; |
| 9400 | |
| 9401 | #if defined(CATCH_CONFIG_NEW_CAPTURE) |
| 9402 | |
| 9403 | // Windows's implementation of std::tmpfile is terrible (it tries |
| 9404 | // to create a file inside system folder, thus requiring elevated |
| 9405 | // privileges for the binary), so we have to use tmpnam(_s) and |
| 9406 | // create the file ourselves there. |
| 9407 | class TempFile { |
| 9408 | public: |
| 9409 | TempFile(TempFile const&) = delete; |
| 9410 | TempFile& operator=(TempFile const&) = delete; |
| 9411 | TempFile(TempFile&&) = delete; |
| 9412 | TempFile& operator=(TempFile&&) = delete; |
| 9413 | |
| 9414 | TempFile(); |
| 9415 | ~TempFile(); |
| 9416 | |
| 9417 | std::FILE* getFile(); |
| 9418 | std::string getContents(); |
| 9419 | |
| 9420 | private: |
| 9421 | std::FILE* m_file = nullptr; |
| 9422 | #if defined(_MSC_VER) |
| 9423 | char m_buffer[L_tmpnam] = { 0 }; |
| 9424 | #endif |
| 9425 | }; |
| 9426 | |
| 9427 | |
| 9428 | class OutputRedirect { |
| 9429 | public: |
| 9430 | OutputRedirect(OutputRedirect const&) = delete; |
| 9431 | OutputRedirect& operator=(OutputRedirect const&) = delete; |
| 9432 | OutputRedirect(OutputRedirect&&) = delete; |
| 9433 | OutputRedirect& operator=(OutputRedirect&&) = delete; |
| 9434 | |
| 9435 | |
| 9436 | OutputRedirect(std::string& stdout_dest, std::string& stderr_dest); |
| 9437 | ~OutputRedirect(); |
| 9438 | |
| 9439 | private: |
| 9440 | int m_originalStdout = -1; |
| 9441 | int m_originalStderr = -1; |
| 9442 | TempFile m_stdoutFile; |
| 9443 | TempFile m_stderrFile; |
| 9444 | std::string& m_stdoutDest; |
| 9445 | std::string& m_stderrDest; |
| 9446 | }; |
| 9447 | |
| 9448 | #endif |
| 9449 | |
| 9450 | } // end namespace Catch |
| 9451 | |
| 9452 | #endif // CATCH_OUTPUT_REDIRECT_HPP_INCLUDED |
| 9453 | |
| 9454 | |
| 9455 | #ifndef CATCH_PARSE_NUMBERS_HPP_INCLUDED |
| 9456 | #define CATCH_PARSE_NUMBERS_HPP_INCLUDED |
| 9457 | |
| 9458 | |
| 9459 | #include <string> |
| 9460 | |
| 9461 | namespace Catch { |
| 9462 | |
| 9463 | /** |
| 9464 | * Parses unsigned int from the input, using provided base |
| 9465 | * |
| 9466 | * Effectively a wrapper around std::stoul but with better error checking |
| 9467 | * e.g. "-1" is rejected, instead of being parsed as UINT_MAX. |
| 9468 | */ |
| 9469 | Optional<unsigned int> parseUInt(std::string const& input, int base = 10); |
| 9470 | } |
| 9471 | |
| 9472 | #endif // CATCH_PARSE_NUMBERS_HPP_INCLUDED |
| 9473 | |
| 9474 | |
| 9475 | #ifndef CATCH_REPORTER_REGISTRY_HPP_INCLUDED |
| 9476 | #define CATCH_REPORTER_REGISTRY_HPP_INCLUDED |
| 9477 | |
| 9478 | |
| 9479 | #include <map> |
| 9480 | #include <string> |
| 9481 | #include <vector> |
| 9482 | |
| 9483 | namespace Catch { |
| 9484 | |
| 9485 | class IEventListener; |
| 9486 | using IEventListenerPtr = Detail::unique_ptr<IEventListener>; |
| 9487 | class IReporterFactory; |
| 9488 | using IReporterFactoryPtr = Detail::unique_ptr<IReporterFactory>; |
| 9489 | struct ReporterConfig; |
| 9490 | class EventListenerFactory; |
| 9491 | |
| 9492 | class ReporterRegistry { |
| 9493 | struct ReporterRegistryImpl; |
| 9494 | Detail::unique_ptr<ReporterRegistryImpl> m_impl; |
| 9495 | |
| 9496 | public: |
| 9497 | ReporterRegistry(); |
| 9498 | ~ReporterRegistry(); // = default; |
| 9499 | |
| 9500 | IEventListenerPtr create( std::string const& name, |
| 9501 | ReporterConfig&& config ) const; |
| 9502 | |
| 9503 | void registerReporter( std::string const& name, |
| 9504 | IReporterFactoryPtr factory ); |
| 9505 | |
| 9506 | void |
| 9507 | registerListener( Detail::unique_ptr<EventListenerFactory> factory ); |
| 9508 | |
| 9509 | std::map<std::string, |
| 9510 | IReporterFactoryPtr, |
| 9511 | Detail::CaseInsensitiveLess> const& |
| 9512 | getFactories() const; |
| 9513 | |
| 9514 | std::vector<Detail::unique_ptr<EventListenerFactory>> const& |
| 9515 | getListeners() const; |
| 9516 | }; |
| 9517 | |
| 9518 | } // end namespace Catch |
| 9519 | |
| 9520 | #endif // CATCH_REPORTER_REGISTRY_HPP_INCLUDED |
| 9521 | |
| 9522 | |
| 9523 | #ifndef CATCH_RUN_CONTEXT_HPP_INCLUDED |
| 9524 | #define CATCH_RUN_CONTEXT_HPP_INCLUDED |
| 9525 | |
| 9526 | |
| 9527 | |
| 9528 | #ifndef CATCH_TEST_CASE_TRACKER_HPP_INCLUDED |
| 9529 | #define CATCH_TEST_CASE_TRACKER_HPP_INCLUDED |
| 9530 | |
| 9531 | |
| 9532 | #include <string> |
| 9533 | #include <vector> |
| 9534 | |
| 9535 | namespace Catch { |
| 9536 | namespace TestCaseTracking { |
| 9537 | |
| 9538 | struct NameAndLocation { |
| 9539 | std::string name; |
| 9540 | SourceLineInfo location; |
| 9541 | |
| 9542 | NameAndLocation( std::string&& _name, SourceLineInfo const& _location ); |
| 9543 | friend bool operator==(NameAndLocation const& lhs, NameAndLocation const& rhs) { |
| 9544 | // This is a very cheap check that should have a very high hit rate. |
| 9545 | // If we get to SourceLineInfo::operator==, we will redo it, but the |
| 9546 | // cost of repeating is trivial at that point (we will be paying |
| 9547 | // multiple strcmp/memcmps at that point). |
| 9548 | if ( lhs.location.line != rhs.location.line ) { return false; } |
| 9549 | return lhs.name == rhs.name && lhs.location == rhs.location; |
| 9550 | } |
| 9551 | friend bool operator!=(NameAndLocation const& lhs, |
| 9552 | NameAndLocation const& rhs) { |
| 9553 | return !( lhs == rhs ); |
| 9554 | } |
| 9555 | }; |
| 9556 | |
| 9557 | /** |
| 9558 | * This is a variant of `NameAndLocation` that does not own the name string |
| 9559 | * |
| 9560 | * This avoids extra allocations when trying to locate a tracker by its |
| 9561 | * name and location, as long as we make sure that trackers only keep |
| 9562 | * around the owning variant. |
| 9563 | */ |
| 9564 | struct NameAndLocationRef { |
| 9565 | StringRef name; |
| 9566 | SourceLineInfo location; |
| 9567 | |
| 9568 | constexpr NameAndLocationRef( StringRef name_, |
| 9569 | SourceLineInfo location_ ): |
| 9570 | name( name_ ), location( location_ ) {} |
| 9571 | |
| 9572 | friend bool operator==( NameAndLocation const& lhs, |
| 9573 | NameAndLocationRef const& rhs ) { |
| 9574 | // This is a very cheap check that should have a very high hit rate. |
| 9575 | // If we get to SourceLineInfo::operator==, we will redo it, but the |
| 9576 | // cost of repeating is trivial at that point (we will be paying |
| 9577 | // multiple strcmp/memcmps at that point). |
| 9578 | if ( lhs.location.line != rhs.location.line ) { return false; } |
| 9579 | return StringRef( lhs.name ) == rhs.name && |
| 9580 | lhs.location == rhs.location; |
| 9581 | } |
| 9582 | friend bool operator==( NameAndLocationRef const& lhs, |
| 9583 | NameAndLocation const& rhs ) { |
| 9584 | return rhs == lhs; |
| 9585 | } |
| 9586 | }; |
| 9587 | |
| 9588 | class ITracker; |
| 9589 | |
| 9590 | using ITrackerPtr = Catch::Detail::unique_ptr<ITracker>; |
| 9591 | |
| 9592 | class ITracker { |
| 9593 | NameAndLocation m_nameAndLocation; |
| 9594 | |
| 9595 | using Children = std::vector<ITrackerPtr>; |
| 9596 | |
| 9597 | protected: |
| 9598 | enum CycleState { |
| 9599 | NotStarted, |
| 9600 | Executing, |
| 9601 | ExecutingChildren, |
| 9602 | NeedsAnotherRun, |
| 9603 | CompletedSuccessfully, |
| 9604 | Failed |
| 9605 | }; |
| 9606 | |
| 9607 | ITracker* m_parent = nullptr; |
| 9608 | Children m_children; |
| 9609 | CycleState m_runState = NotStarted; |
| 9610 | |
| 9611 | public: |
| 9612 | ITracker( NameAndLocation&& nameAndLoc, ITracker* parent ): |
| 9613 | m_nameAndLocation( CATCH_MOVE(nameAndLoc) ), |
| 9614 | m_parent( parent ) |
| 9615 | {} |
| 9616 | |
| 9617 | |
| 9618 | // static queries |
| 9619 | NameAndLocation const& nameAndLocation() const { |
| 9620 | return m_nameAndLocation; |
| 9621 | } |
| 9622 | ITracker* parent() const { |
| 9623 | return m_parent; |
| 9624 | } |
| 9625 | |
| 9626 | virtual ~ITracker(); // = default |
| 9627 | |
| 9628 | |
| 9629 | // dynamic queries |
| 9630 | |
| 9631 | //! Returns true if tracker run to completion (successfully or not) |
| 9632 | virtual bool isComplete() const = 0; |
| 9633 | //! Returns true if tracker run to completion successfully |
| 9634 | bool isSuccessfullyCompleted() const { |
| 9635 | return m_runState == CompletedSuccessfully; |
| 9636 | } |
| 9637 | //! Returns true if tracker has started but hasn't been completed |
| 9638 | bool isOpen() const; |
| 9639 | //! Returns true iff tracker has started |
| 9640 | bool hasStarted() const; |
| 9641 | |
| 9642 | // actions |
| 9643 | virtual void close() = 0; // Successfully complete |
| 9644 | virtual void fail() = 0; |
| 9645 | void markAsNeedingAnotherRun(); |
| 9646 | |
| 9647 | //! Register a nested ITracker |
| 9648 | void addChild( ITrackerPtr&& child ); |
| 9649 | /** |
| 9650 | * Returns ptr to specific child if register with this tracker. |
| 9651 | * |
| 9652 | * Returns nullptr if not found. |
| 9653 | */ |
| 9654 | ITracker* findChild( NameAndLocationRef const& nameAndLocation ); |
| 9655 | //! Have any children been added? |
| 9656 | bool hasChildren() const { |
| 9657 | return !m_children.empty(); |
| 9658 | } |
| 9659 | |
| 9660 | |
| 9661 | //! Marks tracker as executing a child, doing se recursively up the tree |
| 9662 | void openChild(); |
| 9663 | |
| 9664 | /** |
| 9665 | * Returns true if the instance is a section tracker |
| 9666 | * |
| 9667 | * Subclasses should override to true if they are, replaces RTTI |
| 9668 | * for internal debug checks. |
| 9669 | */ |
| 9670 | virtual bool isSectionTracker() const; |
| 9671 | /** |
| 9672 | * Returns true if the instance is a generator tracker |
| 9673 | * |
| 9674 | * Subclasses should override to true if they are, replaces RTTI |
| 9675 | * for internal debug checks. |
| 9676 | */ |
| 9677 | virtual bool isGeneratorTracker() const; |
| 9678 | }; |
| 9679 | |
| 9680 | class TrackerContext { |
| 9681 | |
| 9682 | enum RunState { |
| 9683 | NotStarted, |
| 9684 | Executing, |
| 9685 | CompletedCycle |
| 9686 | }; |
| 9687 | |
| 9688 | ITrackerPtr m_rootTracker; |
| 9689 | ITracker* m_currentTracker = nullptr; |
| 9690 | RunState m_runState = NotStarted; |
| 9691 | |
| 9692 | public: |
| 9693 | |
| 9694 | ITracker& startRun(); |
| 9695 | |
| 9696 | void startCycle() { |
| 9697 | m_currentTracker = m_rootTracker.get(); |
| 9698 | m_runState = Executing; |
| 9699 | } |
| 9700 | void completeCycle(); |
| 9701 | |
| 9702 | bool completedCycle() const; |
| 9703 | ITracker& currentTracker() { return *m_currentTracker; } |
| 9704 | void setCurrentTracker( ITracker* tracker ); |
| 9705 | }; |
| 9706 | |
| 9707 | class TrackerBase : public ITracker { |
| 9708 | protected: |
| 9709 | |
| 9710 | TrackerContext& m_ctx; |
| 9711 | |
| 9712 | public: |
| 9713 | TrackerBase( NameAndLocation&& nameAndLocation, TrackerContext& ctx, ITracker* parent ); |
| 9714 | |
| 9715 | bool isComplete() const override; |
| 9716 | |
| 9717 | void open(); |
| 9718 | |
| 9719 | void close() override; |
| 9720 | void fail() override; |
| 9721 | |
| 9722 | private: |
| 9723 | void moveToParent(); |
| 9724 | void moveToThis(); |
| 9725 | }; |
| 9726 | |
| 9727 | class SectionTracker : public TrackerBase { |
| 9728 | std::vector<StringRef> m_filters; |
| 9729 | // Note that lifetime-wise we piggy back off the name stored in the `ITracker` parent`. |
| 9730 | // Currently it allocates owns the name, so this is safe. If it is later refactored |
| 9731 | // to not own the name, the name still has to outlive the `ITracker` parent, so |
| 9732 | // this should still be safe. |
| 9733 | StringRef m_trimmed_name; |
| 9734 | public: |
| 9735 | SectionTracker( NameAndLocation&& nameAndLocation, TrackerContext& ctx, ITracker* parent ); |
| 9736 | |
| 9737 | bool isSectionTracker() const override; |
| 9738 | |
| 9739 | bool isComplete() const override; |
| 9740 | |
| 9741 | static SectionTracker& acquire( TrackerContext& ctx, NameAndLocationRef const& nameAndLocation ); |
| 9742 | |
| 9743 | void tryOpen(); |
| 9744 | |
| 9745 | void addInitialFilters( std::vector<std::string> const& filters ); |
| 9746 | void addNextFilters( std::vector<StringRef> const& filters ); |
| 9747 | //! Returns filters active in this tracker |
| 9748 | std::vector<StringRef> const& getFilters() const { return m_filters; } |
| 9749 | //! Returns whitespace-trimmed name of the tracked section |
| 9750 | StringRef trimmedName() const; |
| 9751 | }; |
| 9752 | |
| 9753 | } // namespace TestCaseTracking |
| 9754 | |
| 9755 | using TestCaseTracking::ITracker; |
| 9756 | using TestCaseTracking::TrackerContext; |
| 9757 | using TestCaseTracking::SectionTracker; |
| 9758 | |
| 9759 | } // namespace Catch |
| 9760 | |
| 9761 | #endif // CATCH_TEST_CASE_TRACKER_HPP_INCLUDED |
| 9762 | |
| 9763 | #include <string> |
| 9764 | |
| 9765 | namespace Catch { |
| 9766 | |
| 9767 | class IGeneratorTracker; |
| 9768 | class IConfig; |
| 9769 | class IEventListener; |
| 9770 | using IEventListenerPtr = Detail::unique_ptr<IEventListener>; |
| 9771 | |
| 9772 | /////////////////////////////////////////////////////////////////////////// |
| 9773 | |
| 9774 | class RunContext final : public IResultCapture { |
| 9775 | |
| 9776 | public: |
| 9777 | RunContext( RunContext const& ) = delete; |
| 9778 | RunContext& operator =( RunContext const& ) = delete; |
| 9779 | |
| 9780 | explicit RunContext( IConfig const* _config, IEventListenerPtr&& reporter ); |
| 9781 | |
| 9782 | ~RunContext() override; |
| 9783 | |
| 9784 | Totals runTest(TestCaseHandle const& testCase); |
| 9785 | |
| 9786 | public: // IResultCapture |
| 9787 | |
| 9788 | // Assertion handlers |
| 9789 | void handleExpr |
| 9790 | ( AssertionInfo const& info, |
| 9791 | ITransientExpression const& expr, |
| 9792 | AssertionReaction& reaction ) override; |
| 9793 | void handleMessage |
| 9794 | ( AssertionInfo const& info, |
| 9795 | ResultWas::OfType resultType, |
| 9796 | StringRef message, |
| 9797 | AssertionReaction& reaction ) override; |
| 9798 | void handleUnexpectedExceptionNotThrown |
| 9799 | ( AssertionInfo const& info, |
| 9800 | AssertionReaction& reaction ) override; |
| 9801 | void handleUnexpectedInflightException |
| 9802 | ( AssertionInfo const& info, |
| 9803 | std::string&& message, |
| 9804 | AssertionReaction& reaction ) override; |
| 9805 | void handleIncomplete |
| 9806 | ( AssertionInfo const& info ) override; |
| 9807 | void handleNonExpr |
| 9808 | ( AssertionInfo const &info, |
| 9809 | ResultWas::OfType resultType, |
| 9810 | AssertionReaction &reaction ) override; |
| 9811 | |
| 9812 | void notifyAssertionStarted( AssertionInfo const& info ) override; |
| 9813 | bool sectionStarted( StringRef sectionName, |
| 9814 | SourceLineInfo const& sectionLineInfo, |
| 9815 | Counts& assertions ) override; |
| 9816 | |
| 9817 | void sectionEnded( SectionEndInfo&& endInfo ) override; |
| 9818 | void sectionEndedEarly( SectionEndInfo&& endInfo ) override; |
| 9819 | |
| 9820 | IGeneratorTracker* |
| 9821 | acquireGeneratorTracker( StringRef generatorName, |
| 9822 | SourceLineInfo const& lineInfo ) override; |
| 9823 | IGeneratorTracker* createGeneratorTracker( |
| 9824 | StringRef generatorName, |
| 9825 | SourceLineInfo lineInfo, |
| 9826 | Generators::GeneratorBasePtr&& generator ) override; |
| 9827 | |
| 9828 | |
| 9829 | void benchmarkPreparing( StringRef name ) override; |
| 9830 | void benchmarkStarting( BenchmarkInfo const& info ) override; |
| 9831 | void benchmarkEnded( BenchmarkStats<> const& stats ) override; |
| 9832 | void benchmarkFailed( StringRef error ) override; |
| 9833 | |
| 9834 | void pushScopedMessage( MessageInfo const& message ) override; |
| 9835 | void popScopedMessage( MessageInfo const& message ) override; |
| 9836 | |
| 9837 | void emplaceUnscopedMessage( MessageBuilder&& builder ) override; |
| 9838 | |
| 9839 | std::string getCurrentTestName() const override; |
| 9840 | |
| 9841 | const AssertionResult* getLastResult() const override; |
| 9842 | |
| 9843 | void exceptionEarlyReported() override; |
| 9844 | |
| 9845 | void handleFatalErrorCondition( StringRef message ) override; |
| 9846 | |
| 9847 | bool lastAssertionPassed() override; |
| 9848 | |
| 9849 | void assertionPassed() override; |
| 9850 | |
| 9851 | public: |
| 9852 | // !TBD We need to do this another way! |
| 9853 | bool aborting() const; |
| 9854 | |
| 9855 | private: |
| 9856 | |
| 9857 | void runCurrentTest( std::string& redirectedCout, std::string& redirectedCerr ); |
| 9858 | void invokeActiveTestCase(); |
| 9859 | |
| 9860 | void resetAssertionInfo(); |
| 9861 | bool testForMissingAssertions( Counts& assertions ); |
| 9862 | |
| 9863 | void assertionEnded( AssertionResult&& result ); |
| 9864 | void reportExpr |
| 9865 | ( AssertionInfo const &info, |
| 9866 | ResultWas::OfType resultType, |
| 9867 | ITransientExpression const *expr, |
| 9868 | bool negated ); |
| 9869 | |
| 9870 | void populateReaction( AssertionReaction& reaction ); |
| 9871 | |
| 9872 | private: |
| 9873 | |
| 9874 | void handleUnfinishedSections(); |
| 9875 | |
| 9876 | TestRunInfo m_runInfo; |
| 9877 | TestCaseHandle const* m_activeTestCase = nullptr; |
| 9878 | ITracker* m_testCaseTracker = nullptr; |
| 9879 | Optional<AssertionResult> m_lastResult; |
| 9880 | |
| 9881 | IConfig const* m_config; |
| 9882 | Totals m_totals; |
| 9883 | IEventListenerPtr m_reporter; |
| 9884 | std::vector<MessageInfo> m_messages; |
| 9885 | std::vector<ScopedMessage> m_messageScopes; /* Keeps owners of so-called unscoped messages. */ |
| 9886 | AssertionInfo m_lastAssertionInfo; |
| 9887 | std::vector<SectionEndInfo> m_unfinishedSections; |
| 9888 | std::vector<ITracker*> m_activeSections; |
| 9889 | TrackerContext m_trackerContext; |
| 9890 | FatalConditionHandler m_fatalConditionhandler; |
| 9891 | bool m_lastAssertionPassed = false; |
| 9892 | bool m_shouldReportUnexpected = true; |
| 9893 | bool m_includeSuccessfulResults; |
| 9894 | }; |
| 9895 | |
| 9896 | void seedRng(IConfig const& config); |
| 9897 | unsigned int rngSeed(); |
| 9898 | } // end namespace Catch |
| 9899 | |
| 9900 | #endif // CATCH_RUN_CONTEXT_HPP_INCLUDED |
| 9901 | |
| 9902 | |
| 9903 | #ifndef CATCH_SHARDING_HPP_INCLUDED |
| 9904 | #define CATCH_SHARDING_HPP_INCLUDED |
| 9905 | |
| 9906 | |
| 9907 | #include <cmath> |
| 9908 | #include <algorithm> |
| 9909 | |
| 9910 | namespace Catch { |
| 9911 | |
| 9912 | template<typename Container> |
| 9913 | Container createShard(Container const& container, std::size_t const shardCount, std::size_t const shardIndex) { |
| 9914 | assert(shardCount > shardIndex); |
| 9915 | |
| 9916 | if (shardCount == 1) { |
| 9917 | return container; |
| 9918 | } |
| 9919 | |
| 9920 | const std::size_t totalTestCount = container.size(); |
| 9921 | |
| 9922 | const std::size_t shardSize = totalTestCount / shardCount; |
| 9923 | const std::size_t leftoverTests = totalTestCount % shardCount; |
| 9924 | |
| 9925 | const std::size_t startIndex = shardIndex * shardSize + (std::min)(shardIndex, leftoverTests); |
| 9926 | const std::size_t endIndex = (shardIndex + 1) * shardSize + (std::min)(shardIndex + 1, leftoverTests); |
| 9927 | |
| 9928 | auto startIterator = std::next(container.begin(), static_cast<std::ptrdiff_t>(startIndex)); |
| 9929 | auto endIterator = std::next(container.begin(), static_cast<std::ptrdiff_t>(endIndex)); |
| 9930 | |
| 9931 | return Container(startIterator, endIterator); |
| 9932 | } |
| 9933 | |
| 9934 | } |
| 9935 | |
| 9936 | #endif // CATCH_SHARDING_HPP_INCLUDED |
| 9937 | |
| 9938 | |
| 9939 | #ifndef CATCH_SINGLETONS_HPP_INCLUDED |
| 9940 | #define CATCH_SINGLETONS_HPP_INCLUDED |
| 9941 | |
| 9942 | namespace Catch { |
| 9943 | |
| 9944 | struct ISingleton { |
| 9945 | virtual ~ISingleton(); // = default |
| 9946 | }; |
| 9947 | |
| 9948 | |
| 9949 | void addSingleton( ISingleton* singleton ); |
| 9950 | void cleanupSingletons(); |
| 9951 | |
| 9952 | |
| 9953 | template<typename SingletonImplT, typename InterfaceT = SingletonImplT, typename MutableInterfaceT = InterfaceT> |
| 9954 | class Singleton : SingletonImplT, public ISingleton { |
| 9955 | |
| 9956 | static auto getInternal() -> Singleton* { |
| 9957 | static Singleton* s_instance = nullptr; |
| 9958 | if( !s_instance ) { |
| 9959 | s_instance = new Singleton; |
| 9960 | addSingleton( s_instance ); |
| 9961 | } |
| 9962 | return s_instance; |
| 9963 | } |
| 9964 | |
| 9965 | public: |
| 9966 | static auto get() -> InterfaceT const& { |
| 9967 | return *getInternal(); |
| 9968 | } |
| 9969 | static auto getMutable() -> MutableInterfaceT& { |
| 9970 | return *getInternal(); |
| 9971 | } |
| 9972 | }; |
| 9973 | |
| 9974 | } // namespace Catch |
| 9975 | |
| 9976 | #endif // CATCH_SINGLETONS_HPP_INCLUDED |
| 9977 | |
| 9978 | |
| 9979 | #ifndef CATCH_STARTUP_EXCEPTION_REGISTRY_HPP_INCLUDED |
| 9980 | #define CATCH_STARTUP_EXCEPTION_REGISTRY_HPP_INCLUDED |
| 9981 | |
| 9982 | |
| 9983 | #include <vector> |
| 9984 | #include <exception> |
| 9985 | |
| 9986 | namespace Catch { |
| 9987 | |
| 9988 | class StartupExceptionRegistry { |
| 9989 | #if !defined(CATCH_CONFIG_DISABLE_EXCEPTIONS) |
| 9990 | public: |
| 9991 | void add(std::exception_ptr const& exception) noexcept; |
| 9992 | std::vector<std::exception_ptr> const& getExceptions() const noexcept; |
| 9993 | private: |
| 9994 | std::vector<std::exception_ptr> m_exceptions; |
| 9995 | #endif |
| 9996 | }; |
| 9997 | |
| 9998 | } // end namespace Catch |
| 9999 | |
| 10000 | #endif // CATCH_STARTUP_EXCEPTION_REGISTRY_HPP_INCLUDED |
| 10001 | |
| 10002 | |
| 10003 | |
| 10004 | #ifndef CATCH_STDSTREAMS_HPP_INCLUDED |
| 10005 | #define CATCH_STDSTREAMS_HPP_INCLUDED |
| 10006 | |
| 10007 | #include <iosfwd> |
| 10008 | |
| 10009 | namespace Catch { |
| 10010 | |
| 10011 | std::ostream& cout(); |
| 10012 | std::ostream& cerr(); |
| 10013 | std::ostream& clog(); |
| 10014 | |
| 10015 | } // namespace Catch |
| 10016 | |
| 10017 | #endif |
| 10018 | |
| 10019 | |
| 10020 | #ifndef CATCH_STRING_MANIP_HPP_INCLUDED |
| 10021 | #define CATCH_STRING_MANIP_HPP_INCLUDED |
| 10022 | |
| 10023 | |
| 10024 | #include <cstdint> |
| 10025 | #include <string> |
| 10026 | #include <iosfwd> |
| 10027 | #include <vector> |
| 10028 | |
| 10029 | namespace Catch { |
| 10030 | |
| 10031 | bool startsWith( std::string const& s, std::string const& prefix ); |
| 10032 | bool startsWith( StringRef s, char prefix ); |
| 10033 | bool endsWith( std::string const& s, std::string const& suffix ); |
| 10034 | bool endsWith( std::string const& s, char suffix ); |
| 10035 | bool contains( std::string const& s, std::string const& infix ); |
| 10036 | void toLowerInPlace( std::string& s ); |
| 10037 | std::string toLower( std::string const& s ); |
| 10038 | char toLower( char c ); |
| 10039 | //! Returns a new string without whitespace at the start/end |
| 10040 | std::string trim( std::string const& str ); |
| 10041 | //! Returns a substring of the original ref without whitespace. Beware lifetimes! |
| 10042 | StringRef trim(StringRef ref); |
| 10043 | |
| 10044 | // !!! Be aware, returns refs into original string - make sure original string outlives them |
| 10045 | std::vector<StringRef> splitStringRef( StringRef str, char delimiter ); |
| 10046 | bool replaceInPlace( std::string& str, std::string const& replaceThis, std::string const& withThis ); |
| 10047 | |
| 10048 | /** |
| 10049 | * Helper for streaming a "count [maybe-plural-of-label]" human-friendly string |
| 10050 | * |
| 10051 | * Usage example: |
| 10052 | * ```cpp |
| 10053 | * std::cout << "Found " << pluralise(count, "error") << '\n'; |
| 10054 | * ``` |
| 10055 | * |
| 10056 | * **Important:** The provided string must outlive the instance |
| 10057 | */ |
| 10058 | class pluralise { |
| 10059 | std::uint64_t m_count; |
| 10060 | StringRef m_label; |
| 10061 | |
| 10062 | public: |
| 10063 | constexpr pluralise(std::uint64_t count, StringRef label): |
| 10064 | m_count(count), |
| 10065 | m_label(label) |
| 10066 | {} |
| 10067 | |
| 10068 | friend std::ostream& operator << ( std::ostream& os, pluralise const& pluraliser ); |
| 10069 | }; |
| 10070 | } |
| 10071 | |
| 10072 | #endif // CATCH_STRING_MANIP_HPP_INCLUDED |
| 10073 | |
| 10074 | |
| 10075 | #ifndef CATCH_TAG_ALIAS_REGISTRY_HPP_INCLUDED |
| 10076 | #define CATCH_TAG_ALIAS_REGISTRY_HPP_INCLUDED |
| 10077 | |
| 10078 | |
| 10079 | #include <map> |
| 10080 | #include <string> |
| 10081 | |
| 10082 | namespace Catch { |
| 10083 | struct SourceLineInfo; |
| 10084 | |
| 10085 | class TagAliasRegistry : public ITagAliasRegistry { |
| 10086 | public: |
| 10087 | ~TagAliasRegistry() override; |
| 10088 | TagAlias const* find( std::string const& alias ) const override; |
| 10089 | std::string expandAliases( std::string const& unexpandedTestSpec ) const override; |
| 10090 | void add( std::string const& alias, std::string const& tag, SourceLineInfo const& lineInfo ); |
| 10091 | |
| 10092 | private: |
| 10093 | std::map<std::string, TagAlias> m_registry; |
| 10094 | }; |
| 10095 | |
| 10096 | } // end namespace Catch |
| 10097 | |
| 10098 | #endif // CATCH_TAG_ALIAS_REGISTRY_HPP_INCLUDED |
| 10099 | |
| 10100 | |
| 10101 | #ifndef CATCH_TEST_CASE_INFO_HASHER_HPP_INCLUDED |
| 10102 | #define CATCH_TEST_CASE_INFO_HASHER_HPP_INCLUDED |
| 10103 | |
| 10104 | #include <cstdint> |
| 10105 | |
| 10106 | namespace Catch { |
| 10107 | |
| 10108 | struct TestCaseInfo; |
| 10109 | |
| 10110 | class TestCaseInfoHasher { |
| 10111 | public: |
| 10112 | using hash_t = std::uint64_t; |
| 10113 | TestCaseInfoHasher( hash_t seed ); |
| 10114 | uint32_t operator()( TestCaseInfo const& t ) const; |
| 10115 | |
| 10116 | private: |
| 10117 | hash_t m_seed; |
| 10118 | }; |
| 10119 | |
| 10120 | } // namespace Catch |
| 10121 | |
| 10122 | #endif /* CATCH_TEST_CASE_INFO_HASHER_HPP_INCLUDED */ |
| 10123 | |
| 10124 | |
| 10125 | #ifndef CATCH_TEST_CASE_REGISTRY_IMPL_HPP_INCLUDED |
| 10126 | #define CATCH_TEST_CASE_REGISTRY_IMPL_HPP_INCLUDED |
| 10127 | |
| 10128 | |
| 10129 | #include <vector> |
| 10130 | |
| 10131 | namespace Catch { |
| 10132 | |
| 10133 | class IConfig; |
| 10134 | class ITestInvoker; |
| 10135 | class TestCaseHandle; |
| 10136 | class TestSpec; |
| 10137 | |
| 10138 | std::vector<TestCaseHandle> sortTests( IConfig const& config, std::vector<TestCaseHandle> const& unsortedTestCases ); |
| 10139 | |
| 10140 | bool isThrowSafe( TestCaseHandle const& testCase, IConfig const& config ); |
| 10141 | |
| 10142 | std::vector<TestCaseHandle> filterTests( std::vector<TestCaseHandle> const& testCases, TestSpec const& testSpec, IConfig const& config ); |
| 10143 | std::vector<TestCaseHandle> const& getAllTestCasesSorted( IConfig const& config ); |
| 10144 | |
| 10145 | class TestRegistry : public ITestCaseRegistry { |
| 10146 | public: |
| 10147 | ~TestRegistry() override = default; |
| 10148 | |
| 10149 | void registerTest( Detail::unique_ptr<TestCaseInfo> testInfo, Detail::unique_ptr<ITestInvoker> testInvoker ); |
| 10150 | |
| 10151 | std::vector<TestCaseInfo*> const& getAllInfos() const override; |
| 10152 | std::vector<TestCaseHandle> const& getAllTests() const override; |
| 10153 | std::vector<TestCaseHandle> const& getAllTestsSorted( IConfig const& config ) const override; |
| 10154 | |
| 10155 | private: |
| 10156 | std::vector<Detail::unique_ptr<TestCaseInfo>> m_owned_test_infos; |
| 10157 | // Keeps a materialized vector for `getAllInfos`. |
| 10158 | // We should get rid of that eventually (see interface note) |
| 10159 | std::vector<TestCaseInfo*> m_viewed_test_infos; |
| 10160 | |
| 10161 | std::vector<Detail::unique_ptr<ITestInvoker>> m_invokers; |
| 10162 | std::vector<TestCaseHandle> m_handles; |
| 10163 | mutable TestRunOrder m_currentSortOrder = TestRunOrder::Declared; |
| 10164 | mutable std::vector<TestCaseHandle> m_sortedFunctions; |
| 10165 | }; |
| 10166 | |
| 10167 | /////////////////////////////////////////////////////////////////////////// |
| 10168 | |
| 10169 | |
| 10170 | } // end namespace Catch |
| 10171 | |
| 10172 | |
| 10173 | #endif // CATCH_TEST_CASE_REGISTRY_IMPL_HPP_INCLUDED |
| 10174 | |
| 10175 | |
| 10176 | #ifndef CATCH_TEST_SPEC_PARSER_HPP_INCLUDED |
| 10177 | #define CATCH_TEST_SPEC_PARSER_HPP_INCLUDED |
| 10178 | |
| 10179 | #ifdef __clang__ |
| 10180 | #pragma clang diagnostic push |
| 10181 | #pragma clang diagnostic ignored "-Wpadded" |
| 10182 | #endif |
| 10183 | |
| 10184 | |
| 10185 | #include <vector> |
| 10186 | #include <string> |
| 10187 | |
| 10188 | namespace Catch { |
| 10189 | |
| 10190 | class ITagAliasRegistry; |
| 10191 | |
| 10192 | class TestSpecParser { |
| 10193 | enum Mode{ None, Name, QuotedName, Tag, EscapedName }; |
| 10194 | Mode m_mode = None; |
| 10195 | Mode lastMode = None; |
| 10196 | bool m_exclusion = false; |
| 10197 | std::size_t m_pos = 0; |
| 10198 | std::size_t m_realPatternPos = 0; |
| 10199 | std::string m_arg; |
| 10200 | std::string m_substring; |
| 10201 | std::string m_patternName; |
| 10202 | std::vector<std::size_t> m_escapeChars; |
| 10203 | TestSpec::Filter m_currentFilter; |
| 10204 | TestSpec m_testSpec; |
| 10205 | ITagAliasRegistry const* m_tagAliases = nullptr; |
| 10206 | |
| 10207 | public: |
| 10208 | TestSpecParser( ITagAliasRegistry const& tagAliases ); |
| 10209 | |
| 10210 | TestSpecParser& parse( std::string const& arg ); |
| 10211 | TestSpec testSpec(); |
| 10212 | |
| 10213 | private: |
| 10214 | bool visitChar( char c ); |
| 10215 | void startNewMode( Mode mode ); |
| 10216 | bool processNoneChar( char c ); |
| 10217 | void processNameChar( char c ); |
| 10218 | bool processOtherChar( char c ); |
| 10219 | void endMode(); |
| 10220 | void escape(); |
| 10221 | bool isControlChar( char c ) const; |
| 10222 | void saveLastMode(); |
| 10223 | void revertBackToLastMode(); |
| 10224 | void addFilter(); |
| 10225 | bool separate(); |
| 10226 | |
| 10227 | // Handles common preprocessing of the pattern for name/tag patterns |
| 10228 | std::string preprocessPattern(); |
| 10229 | // Adds the current pattern as a test name |
| 10230 | void addNamePattern(); |
| 10231 | // Adds the current pattern as a tag |
| 10232 | void addTagPattern(); |
| 10233 | |
| 10234 | inline void addCharToPattern(char c) { |
| 10235 | m_substring += c; |
| 10236 | m_patternName += c; |
| 10237 | m_realPatternPos++; |
| 10238 | } |
| 10239 | |
| 10240 | }; |
| 10241 | |
| 10242 | } // namespace Catch |
| 10243 | |
| 10244 | #ifdef __clang__ |
| 10245 | #pragma clang diagnostic pop |
| 10246 | #endif |
| 10247 | |
| 10248 | #endif // CATCH_TEST_SPEC_PARSER_HPP_INCLUDED |
| 10249 | |
| 10250 | |
| 10251 | #ifndef CATCH_TEXTFLOW_HPP_INCLUDED |
| 10252 | #define CATCH_TEXTFLOW_HPP_INCLUDED |
| 10253 | |
| 10254 | #include <cassert> |
| 10255 | #include <string> |
| 10256 | #include <vector> |
| 10257 | |
| 10258 | namespace Catch { |
| 10259 | namespace TextFlow { |
| 10260 | |
| 10261 | class Columns; |
| 10262 | |
| 10263 | /** |
| 10264 | * Represents a column of text with specific width and indentation |
| 10265 | * |
| 10266 | * When written out to a stream, it will perform linebreaking |
| 10267 | * of the provided text so that the written lines fit within |
| 10268 | * target width. |
| 10269 | */ |
| 10270 | class Column { |
| 10271 | // String to be written out |
| 10272 | std::string m_string; |
| 10273 | // Width of the column for linebreaking |
| 10274 | size_t m_width = CATCH_CONFIG_CONSOLE_WIDTH - 1; |
| 10275 | // Indentation of other lines (including first if initial indent is unset) |
| 10276 | size_t m_indent = 0; |
| 10277 | // Indentation of the first line |
| 10278 | size_t m_initialIndent = std::string::npos; |
| 10279 | |
| 10280 | public: |
| 10281 | /** |
| 10282 | * Iterates "lines" in `Column` and return sthem |
| 10283 | */ |
| 10284 | class const_iterator { |
| 10285 | friend Column; |
| 10286 | struct EndTag {}; |
| 10287 | |
| 10288 | Column const& m_column; |
| 10289 | // Where does the current line start? |
| 10290 | size_t m_lineStart = 0; |
| 10291 | // How long should the current line be? |
| 10292 | size_t m_lineLength = 0; |
| 10293 | // How far have we checked the string to iterate? |
| 10294 | size_t m_parsedTo = 0; |
| 10295 | // Should a '-' be appended to the line? |
| 10296 | bool m_addHyphen = false; |
| 10297 | |
| 10298 | const_iterator( Column const& column, EndTag ): |
| 10299 | m_column( column ), m_lineStart( m_column.m_string.size() ) {} |
| 10300 | |
| 10301 | // Calculates the length of the current line |
| 10302 | void calcLength(); |
| 10303 | |
| 10304 | // Returns current indentation width |
| 10305 | size_t indentSize() const; |
| 10306 | |
| 10307 | // Creates an indented and (optionally) suffixed string from |
| 10308 | // current iterator position, indentation and length. |
| 10309 | std::string addIndentAndSuffix( size_t position, |
| 10310 | size_t length ) const; |
| 10311 | |
| 10312 | public: |
| 10313 | using difference_type = std::ptrdiff_t; |
| 10314 | using value_type = std::string; |
| 10315 | using pointer = value_type*; |
| 10316 | using reference = value_type&; |
| 10317 | using iterator_category = std::forward_iterator_tag; |
| 10318 | |
| 10319 | explicit const_iterator( Column const& column ); |
| 10320 | |
| 10321 | std::string operator*() const; |
| 10322 | |
| 10323 | const_iterator& operator++(); |
| 10324 | const_iterator operator++( int ); |
| 10325 | |
| 10326 | bool operator==( const_iterator const& other ) const { |
| 10327 | return m_lineStart == other.m_lineStart && &m_column == &other.m_column; |
| 10328 | } |
| 10329 | bool operator!=( const_iterator const& other ) const { |
| 10330 | return !operator==( other ); |
| 10331 | } |
| 10332 | }; |
| 10333 | using iterator = const_iterator; |
| 10334 | |
| 10335 | explicit Column( std::string const& text ): m_string( text ) {} |
| 10336 | |
| 10337 | Column& width( size_t newWidth ) { |
| 10338 | assert( newWidth > 0 ); |
| 10339 | m_width = newWidth; |
| 10340 | return *this; |
| 10341 | } |
| 10342 | Column& indent( size_t newIndent ) { |
| 10343 | m_indent = newIndent; |
| 10344 | return *this; |
| 10345 | } |
| 10346 | Column& initialIndent( size_t newIndent ) { |
| 10347 | m_initialIndent = newIndent; |
| 10348 | return *this; |
| 10349 | } |
| 10350 | |
| 10351 | size_t width() const { return m_width; } |
| 10352 | const_iterator begin() const { return const_iterator( *this ); } |
| 10353 | const_iterator end() const { return { *this, const_iterator::EndTag{} }; } |
| 10354 | |
| 10355 | friend std::ostream& operator<<( std::ostream& os, |
| 10356 | Column const& col ); |
| 10357 | |
| 10358 | Columns operator+( Column const& other ); |
| 10359 | }; |
| 10360 | |
| 10361 | //! Creates a column that serves as an empty space of specific width |
| 10362 | Column Spacer( size_t spaceWidth ); |
| 10363 | |
| 10364 | class Columns { |
| 10365 | std::vector<Column> m_columns; |
| 10366 | |
| 10367 | public: |
| 10368 | class iterator { |
| 10369 | friend Columns; |
| 10370 | struct EndTag {}; |
| 10371 | |
| 10372 | std::vector<Column> const& m_columns; |
| 10373 | std::vector<Column::const_iterator> m_iterators; |
| 10374 | size_t m_activeIterators; |
| 10375 | |
| 10376 | iterator( Columns const& columns, EndTag ); |
| 10377 | |
| 10378 | public: |
| 10379 | using difference_type = std::ptrdiff_t; |
| 10380 | using value_type = std::string; |
| 10381 | using pointer = value_type*; |
| 10382 | using reference = value_type&; |
| 10383 | using iterator_category = std::forward_iterator_tag; |
| 10384 | |
| 10385 | explicit iterator( Columns const& columns ); |
| 10386 | |
| 10387 | auto operator==( iterator const& other ) const -> bool { |
| 10388 | return m_iterators == other.m_iterators; |
| 10389 | } |
| 10390 | auto operator!=( iterator const& other ) const -> bool { |
| 10391 | return m_iterators != other.m_iterators; |
| 10392 | } |
| 10393 | std::string operator*() const; |
| 10394 | iterator& operator++(); |
| 10395 | iterator operator++( int ); |
| 10396 | }; |
| 10397 | using const_iterator = iterator; |
| 10398 | |
| 10399 | iterator begin() const { return iterator( *this ); } |
| 10400 | iterator end() const { return { *this, iterator::EndTag() }; } |
| 10401 | |
| 10402 | Columns& operator+=( Column const& col ); |
| 10403 | Columns operator+( Column const& col ); |
| 10404 | |
| 10405 | friend std::ostream& operator<<( std::ostream& os, |
| 10406 | Columns const& cols ); |
| 10407 | }; |
| 10408 | |
| 10409 | } // namespace TextFlow |
| 10410 | } // namespace Catch |
| 10411 | #endif // CATCH_TEXTFLOW_HPP_INCLUDED |
| 10412 | |
| 10413 | |
| 10414 | #ifndef CATCH_TO_STRING_HPP_INCLUDED |
| 10415 | #define CATCH_TO_STRING_HPP_INCLUDED |
| 10416 | |
| 10417 | #include <string> |
| 10418 | |
| 10419 | |
| 10420 | namespace Catch { |
| 10421 | template <typename T> |
| 10422 | std::string to_string(T const& t) { |
| 10423 | #if defined(CATCH_CONFIG_CPP11_TO_STRING) |
| 10424 | return std::to_string(t); |
| 10425 | #else |
| 10426 | ReusableStringStream rss; |
| 10427 | rss << t; |
| 10428 | return rss.str(); |
| 10429 | #endif |
| 10430 | } |
| 10431 | } // end namespace Catch |
| 10432 | |
| 10433 | #endif // CATCH_TO_STRING_HPP_INCLUDED |
| 10434 | |
| 10435 | |
| 10436 | #ifndef CATCH_UNCAUGHT_EXCEPTIONS_HPP_INCLUDED |
| 10437 | #define CATCH_UNCAUGHT_EXCEPTIONS_HPP_INCLUDED |
| 10438 | |
| 10439 | namespace Catch { |
| 10440 | bool uncaught_exceptions(); |
| 10441 | } // end namespace Catch |
| 10442 | |
| 10443 | #endif // CATCH_UNCAUGHT_EXCEPTIONS_HPP_INCLUDED |
| 10444 | |
| 10445 | |
| 10446 | #ifndef CATCH_XMLWRITER_HPP_INCLUDED |
| 10447 | #define CATCH_XMLWRITER_HPP_INCLUDED |
| 10448 | |
| 10449 | |
| 10450 | #include <iosfwd> |
| 10451 | #include <vector> |
| 10452 | |
| 10453 | namespace Catch { |
| 10454 | enum class XmlFormatting { |
| 10455 | None = 0x00, |
| 10456 | Indent = 0x01, |
| 10457 | Newline = 0x02, |
| 10458 | }; |
| 10459 | |
| 10460 | XmlFormatting operator | (XmlFormatting lhs, XmlFormatting rhs); |
| 10461 | XmlFormatting operator & (XmlFormatting lhs, XmlFormatting rhs); |
| 10462 | |
| 10463 | /** |
| 10464 | * Helper for XML-encoding text (escaping angle brackets, quotes, etc) |
| 10465 | * |
| 10466 | * Note: doesn't take ownership of passed strings, and thus the |
| 10467 | * encoded string must outlive the encoding instance. |
| 10468 | */ |
| 10469 | class XmlEncode { |
| 10470 | public: |
| 10471 | enum ForWhat { ForTextNodes, ForAttributes }; |
| 10472 | |
| 10473 | XmlEncode( StringRef str, ForWhat forWhat = ForTextNodes ); |
| 10474 | |
| 10475 | void encodeTo( std::ostream& os ) const; |
| 10476 | |
| 10477 | friend std::ostream& operator << ( std::ostream& os, XmlEncode const& xmlEncode ); |
| 10478 | |
| 10479 | private: |
| 10480 | StringRef m_str; |
| 10481 | ForWhat m_forWhat; |
| 10482 | }; |
| 10483 | |
| 10484 | class XmlWriter { |
| 10485 | public: |
| 10486 | |
| 10487 | class ScopedElement { |
| 10488 | public: |
| 10489 | ScopedElement( XmlWriter* writer, XmlFormatting fmt ); |
| 10490 | |
| 10491 | ScopedElement( ScopedElement&& other ) noexcept; |
| 10492 | ScopedElement& operator=( ScopedElement&& other ) noexcept; |
| 10493 | |
| 10494 | ~ScopedElement(); |
| 10495 | |
| 10496 | ScopedElement& |
| 10497 | writeText( StringRef text, |
| 10498 | XmlFormatting fmt = XmlFormatting::Newline | |
| 10499 | XmlFormatting::Indent ); |
| 10500 | |
| 10501 | ScopedElement& writeAttribute( StringRef name, |
| 10502 | StringRef attribute ); |
| 10503 | template <typename T, |
| 10504 | // Without this SFINAE, this overload is a better match |
| 10505 | // for `std::string`, `char const*`, `char const[N]` args. |
| 10506 | // While it would still work, it would cause code bloat |
| 10507 | // and multiple iteration over the strings |
| 10508 | typename = typename std::enable_if_t< |
| 10509 | !std::is_convertible<T, StringRef>::value>> |
| 10510 | ScopedElement& writeAttribute( StringRef name, |
| 10511 | T const& attribute ) { |
| 10512 | m_writer->writeAttribute( name, attribute ); |
| 10513 | return *this; |
| 10514 | } |
| 10515 | |
| 10516 | private: |
| 10517 | XmlWriter* m_writer = nullptr; |
| 10518 | XmlFormatting m_fmt; |
| 10519 | }; |
| 10520 | |
| 10521 | XmlWriter( std::ostream& os ); |
| 10522 | ~XmlWriter(); |
| 10523 | |
| 10524 | XmlWriter( XmlWriter const& ) = delete; |
| 10525 | XmlWriter& operator=( XmlWriter const& ) = delete; |
| 10526 | |
| 10527 | XmlWriter& startElement( std::string const& name, XmlFormatting fmt = XmlFormatting::Newline | XmlFormatting::Indent); |
| 10528 | |
| 10529 | ScopedElement scopedElement( std::string const& name, XmlFormatting fmt = XmlFormatting::Newline | XmlFormatting::Indent); |
| 10530 | |
| 10531 | XmlWriter& endElement(XmlFormatting fmt = XmlFormatting::Newline | XmlFormatting::Indent); |
| 10532 | |
| 10533 | //! The attribute content is XML-encoded |
| 10534 | XmlWriter& writeAttribute( StringRef name, StringRef attribute ); |
| 10535 | |
| 10536 | //! Writes the attribute as "true/false" |
| 10537 | XmlWriter& writeAttribute( StringRef name, bool attribute ); |
| 10538 | |
| 10539 | //! The attribute content is XML-encoded |
| 10540 | XmlWriter& writeAttribute( StringRef name, char const* attribute ); |
| 10541 | |
| 10542 | //! The attribute value must provide op<<(ostream&, T). The resulting |
| 10543 | //! serialization is XML-encoded |
| 10544 | template <typename T, |
| 10545 | // Without this SFINAE, this overload is a better match |
| 10546 | // for `std::string`, `char const*`, `char const[N]` args. |
| 10547 | // While it would still work, it would cause code bloat |
| 10548 | // and multiple iteration over the strings |
| 10549 | typename = typename std::enable_if_t< |
| 10550 | !std::is_convertible<T, StringRef>::value>> |
| 10551 | XmlWriter& writeAttribute( StringRef name, T const& attribute ) { |
| 10552 | ReusableStringStream rss; |
| 10553 | rss << attribute; |
| 10554 | return writeAttribute( name, rss.str() ); |
| 10555 | } |
| 10556 | |
| 10557 | //! Writes escaped `text` in a element |
| 10558 | XmlWriter& writeText( StringRef text, |
| 10559 | XmlFormatting fmt = XmlFormatting::Newline | |
| 10560 | XmlFormatting::Indent ); |
| 10561 | |
| 10562 | //! Writes XML comment as "<!-- text -->" |
| 10563 | XmlWriter& writeComment( StringRef text, |
| 10564 | XmlFormatting fmt = XmlFormatting::Newline | |
| 10565 | XmlFormatting::Indent ); |
| 10566 | |
| 10567 | void writeStylesheetRef( StringRef url ); |
| 10568 | |
| 10569 | void ensureTagClosed(); |
| 10570 | |
| 10571 | private: |
| 10572 | |
| 10573 | void applyFormatting(XmlFormatting fmt); |
| 10574 | |
| 10575 | void writeDeclaration(); |
| 10576 | |
| 10577 | void newlineIfNecessary(); |
| 10578 | |
| 10579 | bool m_tagIsOpen = false; |
| 10580 | bool m_needsNewline = false; |
| 10581 | std::vector<std::string> m_tags; |
| 10582 | std::string m_indent; |
| 10583 | std::ostream& m_os; |
| 10584 | }; |
| 10585 | |
| 10586 | } |
| 10587 | |
| 10588 | #endif // CATCH_XMLWRITER_HPP_INCLUDED |
| 10589 | |
| 10590 | |
| 10591 | /** \file |
| 10592 | * This is a convenience header for Catch2's Matcher support. It includes |
| 10593 | * **all** of Catch2 headers related to matchers. |
| 10594 | * |
| 10595 | * Generally the Catch2 users should use specific includes they need, |
| 10596 | * but this header can be used instead for ease-of-experimentation, or |
| 10597 | * just plain convenience, at the cost of increased compilation times. |
| 10598 | * |
| 10599 | * When a new header is added to either the `matchers` folder, or to |
| 10600 | * the corresponding internal subfolder, it should be added here. |
| 10601 | */ |
| 10602 | |
| 10603 | #ifndef CATCH_MATCHERS_ALL_HPP_INCLUDED |
| 10604 | #define CATCH_MATCHERS_ALL_HPP_INCLUDED |
| 10605 | |
| 10606 | |
| 10607 | |
| 10608 | #ifndef CATCH_MATCHERS_HPP_INCLUDED |
| 10609 | #define CATCH_MATCHERS_HPP_INCLUDED |
| 10610 | |
| 10611 | |
| 10612 | |
| 10613 | #ifndef CATCH_MATCHERS_IMPL_HPP_INCLUDED |
| 10614 | #define CATCH_MATCHERS_IMPL_HPP_INCLUDED |
| 10615 | |
| 10616 | |
| 10617 | #include <string> |
| 10618 | |
| 10619 | namespace Catch { |
| 10620 | |
| 10621 | template<typename ArgT, typename MatcherT> |
| 10622 | class MatchExpr : public ITransientExpression { |
| 10623 | ArgT && m_arg; |
| 10624 | MatcherT const& m_matcher; |
| 10625 | public: |
| 10626 | MatchExpr( ArgT && arg, MatcherT const& matcher ) |
| 10627 | : ITransientExpression{ true, matcher.match( arg ) }, // not forwarding arg here on purpose |
| 10628 | m_arg( CATCH_FORWARD(arg) ), |
| 10629 | m_matcher( matcher ) |
| 10630 | {} |
| 10631 | |
| 10632 | void streamReconstructedExpression( std::ostream& os ) const override { |
| 10633 | os << Catch::Detail::stringify( m_arg ) |
| 10634 | << ' ' |
| 10635 | << m_matcher.toString(); |
| 10636 | } |
| 10637 | }; |
| 10638 | |
| 10639 | namespace Matchers { |
| 10640 | template <typename ArgT> |
| 10641 | class MatcherBase; |
| 10642 | } |
| 10643 | |
| 10644 | using StringMatcher = Matchers::MatcherBase<std::string>; |
| 10645 | |
| 10646 | void handleExceptionMatchExpr( AssertionHandler& handler, StringMatcher const& matcher ); |
| 10647 | |
| 10648 | template<typename ArgT, typename MatcherT> |
| 10649 | auto makeMatchExpr( ArgT && arg, MatcherT const& matcher ) -> MatchExpr<ArgT, MatcherT> { |
| 10650 | return MatchExpr<ArgT, MatcherT>( CATCH_FORWARD(arg), matcher ); |
| 10651 | } |
| 10652 | |
| 10653 | } // namespace Catch |
| 10654 | |
| 10655 | |
| 10656 | /////////////////////////////////////////////////////////////////////////////// |
| 10657 | #define INTERNAL_CHECK_THAT( macroName, matcher, resultDisposition, arg ) \ |
| 10658 | do { \ |
| 10659 | Catch::AssertionHandler catchAssertionHandler( macroName##_catch_sr, CATCH_INTERNAL_LINEINFO, CATCH_INTERNAL_STRINGIFY(arg) ", " CATCH_INTERNAL_STRINGIFY(matcher), resultDisposition ); \ |
| 10660 | INTERNAL_CATCH_TRY { \ |
| 10661 | catchAssertionHandler.handleExpr( Catch::makeMatchExpr( arg, matcher ) ); \ |
| 10662 | } INTERNAL_CATCH_CATCH( catchAssertionHandler ) \ |
| 10663 | INTERNAL_CATCH_REACT( catchAssertionHandler ) \ |
| 10664 | } while( false ) |
| 10665 | |
| 10666 | |
| 10667 | /////////////////////////////////////////////////////////////////////////////// |
| 10668 | #define INTERNAL_CATCH_THROWS_MATCHES( macroName, exceptionType, resultDisposition, matcher, ... ) \ |
| 10669 | do { \ |
| 10670 | Catch::AssertionHandler catchAssertionHandler( macroName##_catch_sr, CATCH_INTERNAL_LINEINFO, CATCH_INTERNAL_STRINGIFY(__VA_ARGS__) ", " CATCH_INTERNAL_STRINGIFY(exceptionType) ", " CATCH_INTERNAL_STRINGIFY(matcher), resultDisposition ); \ |
| 10671 | if( catchAssertionHandler.allowThrows() ) \ |
| 10672 | try { \ |
| 10673 | static_cast<void>(__VA_ARGS__ ); \ |
| 10674 | catchAssertionHandler.handleUnexpectedExceptionNotThrown(); \ |
| 10675 | } \ |
| 10676 | catch( exceptionType const& ex ) { \ |
| 10677 | catchAssertionHandler.handleExpr( Catch::makeMatchExpr( ex, matcher ) ); \ |
| 10678 | } \ |
| 10679 | catch( ... ) { \ |
| 10680 | catchAssertionHandler.handleUnexpectedInflightException(); \ |
| 10681 | } \ |
| 10682 | else \ |
| 10683 | catchAssertionHandler.handleThrowingCallSkipped(); \ |
| 10684 | INTERNAL_CATCH_REACT( catchAssertionHandler ) \ |
| 10685 | } while( false ) |
| 10686 | |
| 10687 | |
| 10688 | #endif // CATCH_MATCHERS_IMPL_HPP_INCLUDED |
| 10689 | |
| 10690 | #include <string> |
| 10691 | #include <vector> |
| 10692 | |
| 10693 | namespace Catch { |
| 10694 | namespace Matchers { |
| 10695 | |
| 10696 | class MatcherUntypedBase { |
| 10697 | public: |
| 10698 | MatcherUntypedBase() = default; |
| 10699 | |
| 10700 | MatcherUntypedBase(MatcherUntypedBase const&) = default; |
| 10701 | MatcherUntypedBase(MatcherUntypedBase&&) = default; |
| 10702 | |
| 10703 | MatcherUntypedBase& operator = (MatcherUntypedBase const&) = delete; |
| 10704 | MatcherUntypedBase& operator = (MatcherUntypedBase&&) = delete; |
| 10705 | |
| 10706 | std::string toString() const; |
| 10707 | |
| 10708 | protected: |
| 10709 | virtual ~MatcherUntypedBase(); // = default; |
| 10710 | virtual std::string describe() const = 0; |
| 10711 | mutable std::string m_cachedToString; |
| 10712 | }; |
| 10713 | |
| 10714 | |
| 10715 | template<typename T> |
| 10716 | class MatcherBase : public MatcherUntypedBase { |
| 10717 | public: |
| 10718 | virtual bool match( T const& arg ) const = 0; |
| 10719 | }; |
| 10720 | |
| 10721 | namespace Detail { |
| 10722 | |
| 10723 | template<typename ArgT> |
| 10724 | class MatchAllOf final : public MatcherBase<ArgT> { |
| 10725 | std::vector<MatcherBase<ArgT> const*> m_matchers; |
| 10726 | |
| 10727 | public: |
| 10728 | MatchAllOf() = default; |
| 10729 | MatchAllOf(MatchAllOf const&) = delete; |
| 10730 | MatchAllOf& operator=(MatchAllOf const&) = delete; |
| 10731 | MatchAllOf(MatchAllOf&&) = default; |
| 10732 | MatchAllOf& operator=(MatchAllOf&&) = default; |
| 10733 | |
| 10734 | |
| 10735 | bool match( ArgT const& arg ) const override { |
| 10736 | for( auto matcher : m_matchers ) { |
| 10737 | if (!matcher->match(arg)) |
| 10738 | return false; |
| 10739 | } |
| 10740 | return true; |
| 10741 | } |
| 10742 | std::string describe() const override { |
| 10743 | std::string description; |
| 10744 | description.reserve( 4 + m_matchers.size()*32 ); |
| 10745 | description += "( "; |
| 10746 | bool first = true; |
| 10747 | for( auto matcher : m_matchers ) { |
| 10748 | if( first ) |
| 10749 | first = false; |
| 10750 | else |
| 10751 | description += " and "; |
| 10752 | description += matcher->toString(); |
| 10753 | } |
| 10754 | description += " )"; |
| 10755 | return description; |
| 10756 | } |
| 10757 | |
| 10758 | friend MatchAllOf operator&& (MatchAllOf&& lhs, MatcherBase<ArgT> const& rhs) { |
| 10759 | lhs.m_matchers.push_back(&rhs); |
| 10760 | return CATCH_MOVE(lhs); |
| 10761 | } |
| 10762 | friend MatchAllOf operator&& (MatcherBase<ArgT> const& lhs, MatchAllOf&& rhs) { |
| 10763 | rhs.m_matchers.insert(rhs.m_matchers.begin(), &lhs); |
| 10764 | return CATCH_MOVE(rhs); |
| 10765 | } |
| 10766 | }; |
| 10767 | |
| 10768 | //! lvalue overload is intentionally deleted, users should |
| 10769 | //! not be trying to compose stored composition matchers |
| 10770 | template<typename ArgT> |
| 10771 | MatchAllOf<ArgT> operator&& (MatchAllOf<ArgT> const& lhs, MatcherBase<ArgT> const& rhs) = delete; |
| 10772 | //! lvalue overload is intentionally deleted, users should |
| 10773 | //! not be trying to compose stored composition matchers |
| 10774 | template<typename ArgT> |
| 10775 | MatchAllOf<ArgT> operator&& (MatcherBase<ArgT> const& lhs, MatchAllOf<ArgT> const& rhs) = delete; |
| 10776 | |
| 10777 | template<typename ArgT> |
| 10778 | class MatchAnyOf final : public MatcherBase<ArgT> { |
| 10779 | std::vector<MatcherBase<ArgT> const*> m_matchers; |
| 10780 | public: |
| 10781 | MatchAnyOf() = default; |
| 10782 | MatchAnyOf(MatchAnyOf const&) = delete; |
| 10783 | MatchAnyOf& operator=(MatchAnyOf const&) = delete; |
| 10784 | MatchAnyOf(MatchAnyOf&&) = default; |
| 10785 | MatchAnyOf& operator=(MatchAnyOf&&) = default; |
| 10786 | |
| 10787 | bool match( ArgT const& arg ) const override { |
| 10788 | for( auto matcher : m_matchers ) { |
| 10789 | if (matcher->match(arg)) |
| 10790 | return true; |
| 10791 | } |
| 10792 | return false; |
| 10793 | } |
| 10794 | std::string describe() const override { |
| 10795 | std::string description; |
| 10796 | description.reserve( 4 + m_matchers.size()*32 ); |
| 10797 | description += "( "; |
| 10798 | bool first = true; |
| 10799 | for( auto matcher : m_matchers ) { |
| 10800 | if( first ) |
| 10801 | first = false; |
| 10802 | else |
| 10803 | description += " or "; |
| 10804 | description += matcher->toString(); |
| 10805 | } |
| 10806 | description += " )"; |
| 10807 | return description; |
| 10808 | } |
| 10809 | |
| 10810 | friend MatchAnyOf operator|| (MatchAnyOf&& lhs, MatcherBase<ArgT> const& rhs) { |
| 10811 | lhs.m_matchers.push_back(&rhs); |
| 10812 | return CATCH_MOVE(lhs); |
| 10813 | } |
| 10814 | friend MatchAnyOf operator|| (MatcherBase<ArgT> const& lhs, MatchAnyOf&& rhs) { |
| 10815 | rhs.m_matchers.insert(rhs.m_matchers.begin(), &lhs); |
| 10816 | return CATCH_MOVE(rhs); |
| 10817 | } |
| 10818 | }; |
| 10819 | |
| 10820 | //! lvalue overload is intentionally deleted, users should |
| 10821 | //! not be trying to compose stored composition matchers |
| 10822 | template<typename ArgT> |
| 10823 | MatchAnyOf<ArgT> operator|| (MatchAnyOf<ArgT> const& lhs, MatcherBase<ArgT> const& rhs) = delete; |
| 10824 | //! lvalue overload is intentionally deleted, users should |
| 10825 | //! not be trying to compose stored composition matchers |
| 10826 | template<typename ArgT> |
| 10827 | MatchAnyOf<ArgT> operator|| (MatcherBase<ArgT> const& lhs, MatchAnyOf<ArgT> const& rhs) = delete; |
| 10828 | |
| 10829 | template<typename ArgT> |
| 10830 | class MatchNotOf final : public MatcherBase<ArgT> { |
| 10831 | MatcherBase<ArgT> const& m_underlyingMatcher; |
| 10832 | |
| 10833 | public: |
| 10834 | explicit MatchNotOf( MatcherBase<ArgT> const& underlyingMatcher ): |
| 10835 | m_underlyingMatcher( underlyingMatcher ) |
| 10836 | {} |
| 10837 | |
| 10838 | bool match( ArgT const& arg ) const override { |
| 10839 | return !m_underlyingMatcher.match( arg ); |
| 10840 | } |
| 10841 | |
| 10842 | std::string describe() const override { |
| 10843 | return "not " + m_underlyingMatcher.toString(); |
| 10844 | } |
| 10845 | }; |
| 10846 | |
| 10847 | } // namespace Detail |
| 10848 | |
| 10849 | template <typename T> |
| 10850 | Detail::MatchAllOf<T> operator&& (MatcherBase<T> const& lhs, MatcherBase<T> const& rhs) { |
| 10851 | return Detail::MatchAllOf<T>{} && lhs && rhs; |
| 10852 | } |
| 10853 | template <typename T> |
| 10854 | Detail::MatchAnyOf<T> operator|| (MatcherBase<T> const& lhs, MatcherBase<T> const& rhs) { |
| 10855 | return Detail::MatchAnyOf<T>{} || lhs || rhs; |
| 10856 | } |
| 10857 | |
| 10858 | template <typename T> |
| 10859 | Detail::MatchNotOf<T> operator! (MatcherBase<T> const& matcher) { |
| 10860 | return Detail::MatchNotOf<T>{ matcher }; |
| 10861 | } |
| 10862 | |
| 10863 | |
| 10864 | } // namespace Matchers |
| 10865 | } // namespace Catch |
| 10866 | |
| 10867 | |
| 10868 | #if defined(CATCH_CONFIG_PREFIX_ALL) && !defined(CATCH_CONFIG_DISABLE) |
| 10869 | #define CATCH_REQUIRE_THROWS_WITH( expr, matcher ) INTERNAL_CATCH_THROWS_STR_MATCHES( "CATCH_REQUIRE_THROWS_WITH", Catch::ResultDisposition::Normal, matcher, expr ) |
| 10870 | #define CATCH_REQUIRE_THROWS_MATCHES( expr, exceptionType, matcher ) INTERNAL_CATCH_THROWS_MATCHES( "CATCH_REQUIRE_THROWS_MATCHES", exceptionType, Catch::ResultDisposition::Normal, matcher, expr ) |
| 10871 | |
| 10872 | #define CATCH_CHECK_THROWS_WITH( expr, matcher ) INTERNAL_CATCH_THROWS_STR_MATCHES( "CATCH_CHECK_THROWS_WITH", Catch::ResultDisposition::ContinueOnFailure, matcher, expr ) |
| 10873 | #define CATCH_CHECK_THROWS_MATCHES( expr, exceptionType, matcher ) INTERNAL_CATCH_THROWS_MATCHES( "CATCH_CHECK_THROWS_MATCHES", exceptionType, Catch::ResultDisposition::ContinueOnFailure, matcher, expr ) |
| 10874 | |
| 10875 | #define CATCH_CHECK_THAT( arg, matcher ) INTERNAL_CHECK_THAT( "CATCH_CHECK_THAT", matcher, Catch::ResultDisposition::ContinueOnFailure, arg ) |
| 10876 | #define CATCH_REQUIRE_THAT( arg, matcher ) INTERNAL_CHECK_THAT( "CATCH_REQUIRE_THAT", matcher, Catch::ResultDisposition::Normal, arg ) |
| 10877 | |
| 10878 | #elif defined(CATCH_CONFIG_PREFIX_ALL) && defined(CATCH_CONFIG_DISABLE) |
| 10879 | |
| 10880 | #define CATCH_REQUIRE_THROWS_WITH( expr, matcher ) (void)(0) |
| 10881 | #define CATCH_REQUIRE_THROWS_MATCHES( expr, exceptionType, matcher ) (void)(0) |
| 10882 | |
| 10883 | #define CATCH_CHECK_THROWS_WITH( expr, matcher ) (void)(0) |
| 10884 | #define CATCH_CHECK_THROWS_MATCHES( expr, exceptionType, matcher ) (void)(0) |
| 10885 | |
| 10886 | #define CATCH_CHECK_THAT( arg, matcher ) (void)(0) |
| 10887 | #define CATCH_REQUIRE_THAT( arg, matcher ) (void)(0) |
| 10888 | |
| 10889 | #elif !defined(CATCH_CONFIG_PREFIX_ALL) && !defined(CATCH_CONFIG_DISABLE) |
| 10890 | |
| 10891 | #define REQUIRE_THROWS_WITH( expr, matcher ) INTERNAL_CATCH_THROWS_STR_MATCHES( "REQUIRE_THROWS_WITH", Catch::ResultDisposition::Normal, matcher, expr ) |
| 10892 | #define REQUIRE_THROWS_MATCHES( expr, exceptionType, matcher ) INTERNAL_CATCH_THROWS_MATCHES( "REQUIRE_THROWS_MATCHES", exceptionType, Catch::ResultDisposition::Normal, matcher, expr ) |
| 10893 | |
| 10894 | #define CHECK_THROWS_WITH( expr, matcher ) INTERNAL_CATCH_THROWS_STR_MATCHES( "CHECK_THROWS_WITH", Catch::ResultDisposition::ContinueOnFailure, matcher, expr ) |
| 10895 | #define CHECK_THROWS_MATCHES( expr, exceptionType, matcher ) INTERNAL_CATCH_THROWS_MATCHES( "CHECK_THROWS_MATCHES", exceptionType, Catch::ResultDisposition::ContinueOnFailure, matcher, expr ) |
| 10896 | |
| 10897 | #define CHECK_THAT( arg, matcher ) INTERNAL_CHECK_THAT( "CHECK_THAT", matcher, Catch::ResultDisposition::ContinueOnFailure, arg ) |
| 10898 | #define REQUIRE_THAT( arg, matcher ) INTERNAL_CHECK_THAT( "REQUIRE_THAT", matcher, Catch::ResultDisposition::Normal, arg ) |
| 10899 | |
| 10900 | #elif !defined(CATCH_CONFIG_PREFIX_ALL) && defined(CATCH_CONFIG_DISABLE) |
| 10901 | |
| 10902 | #define REQUIRE_THROWS_WITH( expr, matcher ) (void)(0) |
| 10903 | #define REQUIRE_THROWS_MATCHES( expr, exceptionType, matcher ) (void)(0) |
| 10904 | |
| 10905 | #define CHECK_THROWS_WITH( expr, matcher ) (void)(0) |
| 10906 | #define CHECK_THROWS_MATCHES( expr, exceptionType, matcher ) (void)(0) |
| 10907 | |
| 10908 | #define CHECK_THAT( arg, matcher ) (void)(0) |
| 10909 | #define REQUIRE_THAT( arg, matcher ) (void)(0) |
| 10910 | |
| 10911 | #endif // end of user facing macro declarations |
| 10912 | |
| 10913 | #endif // CATCH_MATCHERS_HPP_INCLUDED |
| 10914 | |
| 10915 | |
| 10916 | #ifndef CATCH_MATCHERS_CONTAINER_PROPERTIES_HPP_INCLUDED |
| 10917 | #define CATCH_MATCHERS_CONTAINER_PROPERTIES_HPP_INCLUDED |
| 10918 | |
| 10919 | |
| 10920 | |
| 10921 | #ifndef CATCH_MATCHERS_TEMPLATED_HPP_INCLUDED |
| 10922 | #define CATCH_MATCHERS_TEMPLATED_HPP_INCLUDED |
| 10923 | |
| 10924 | |
| 10925 | #include <array> |
| 10926 | #include <algorithm> |
| 10927 | #include <string> |
| 10928 | #include <type_traits> |
| 10929 | |
| 10930 | namespace Catch { |
| 10931 | namespace Matchers { |
| 10932 | class MatcherGenericBase : public MatcherUntypedBase { |
| 10933 | public: |
| 10934 | MatcherGenericBase() = default; |
| 10935 | ~MatcherGenericBase() override; // = default; |
| 10936 | |
| 10937 | MatcherGenericBase(MatcherGenericBase const&) = default; |
| 10938 | MatcherGenericBase(MatcherGenericBase&&) = default; |
| 10939 | |
| 10940 | MatcherGenericBase& operator=(MatcherGenericBase const&) = delete; |
| 10941 | MatcherGenericBase& operator=(MatcherGenericBase&&) = delete; |
| 10942 | }; |
| 10943 | |
| 10944 | |
| 10945 | namespace Detail { |
| 10946 | template<std::size_t N, std::size_t M> |
| 10947 | std::array<void const*, N + M> array_cat(std::array<void const*, N> && lhs, std::array<void const*, M> && rhs) { |
| 10948 | std::array<void const*, N + M> arr{}; |
| 10949 | std::copy_n(lhs.begin(), N, arr.begin()); |
| 10950 | std::copy_n(rhs.begin(), M, arr.begin() + N); |
| 10951 | return arr; |
| 10952 | } |
| 10953 | |
| 10954 | template<std::size_t N> |
| 10955 | std::array<void const*, N+1> array_cat(std::array<void const*, N> && lhs, void const* rhs) { |
| 10956 | std::array<void const*, N+1> arr{}; |
| 10957 | std::copy_n(lhs.begin(), N, arr.begin()); |
| 10958 | arr[N] = rhs; |
| 10959 | return arr; |
| 10960 | } |
| 10961 | |
| 10962 | template<std::size_t N> |
| 10963 | std::array<void const*, N+1> array_cat(void const* lhs, std::array<void const*, N> && rhs) { |
| 10964 | std::array<void const*, N + 1> arr{ {lhs} }; |
| 10965 | std::copy_n(rhs.begin(), N, arr.begin() + 1); |
| 10966 | return arr; |
| 10967 | } |
| 10968 | |
| 10969 | template<typename T> |
| 10970 | using is_generic_matcher = std::is_base_of< |
| 10971 | Catch::Matchers::MatcherGenericBase, |
| 10972 | std::remove_cv_t<std::remove_reference_t<T>> |
| 10973 | >; |
| 10974 | |
| 10975 | template<typename... Ts> |
| 10976 | using are_generic_matchers = Catch::Detail::conjunction<is_generic_matcher<Ts>...>; |
| 10977 | |
| 10978 | template<typename T> |
| 10979 | using is_matcher = std::is_base_of< |
| 10980 | Catch::Matchers::MatcherUntypedBase, |
| 10981 | std::remove_cv_t<std::remove_reference_t<T>> |
| 10982 | >; |
| 10983 | |
| 10984 | |
| 10985 | template<std::size_t N, typename Arg> |
| 10986 | bool match_all_of(Arg&&, std::array<void const*, N> const&, std::index_sequence<>) { |
| 10987 | return true; |
| 10988 | } |
| 10989 | |
| 10990 | template<typename T, typename... MatcherTs, std::size_t N, typename Arg, std::size_t Idx, std::size_t... Indices> |
| 10991 | bool match_all_of(Arg&& arg, std::array<void const*, N> const& matchers, std::index_sequence<Idx, Indices...>) { |
| 10992 | return static_cast<T const*>(matchers[Idx])->match(arg) && match_all_of<MatcherTs...>(arg, matchers, std::index_sequence<Indices...>{}); |
| 10993 | } |
| 10994 | |
| 10995 | |
| 10996 | template<std::size_t N, typename Arg> |
| 10997 | bool match_any_of(Arg&&, std::array<void const*, N> const&, std::index_sequence<>) { |
| 10998 | return false; |
| 10999 | } |
| 11000 | |
| 11001 | template<typename T, typename... MatcherTs, std::size_t N, typename Arg, std::size_t Idx, std::size_t... Indices> |
| 11002 | bool match_any_of(Arg&& arg, std::array<void const*, N> const& matchers, std::index_sequence<Idx, Indices...>) { |
| 11003 | return static_cast<T const*>(matchers[Idx])->match(arg) || match_any_of<MatcherTs...>(arg, matchers, std::index_sequence<Indices...>{}); |
| 11004 | } |
| 11005 | |
| 11006 | std::string describe_multi_matcher(StringRef combine, std::string const* descriptions_begin, std::string const* descriptions_end); |
| 11007 | |
| 11008 | template<typename... MatcherTs, std::size_t... Idx> |
| 11009 | std::string describe_multi_matcher(StringRef combine, std::array<void const*, sizeof...(MatcherTs)> const& matchers, std::index_sequence<Idx...>) { |
| 11010 | std::array<std::string, sizeof...(MatcherTs)> descriptions {{ |
| 11011 | static_cast<MatcherTs const*>(matchers[Idx])->toString()... |
| 11012 | }}; |
| 11013 | |
| 11014 | return describe_multi_matcher(combine, descriptions.data(), descriptions.data() + descriptions.size()); |
| 11015 | } |
| 11016 | |
| 11017 | |
| 11018 | template<typename... MatcherTs> |
| 11019 | class MatchAllOfGeneric final : public MatcherGenericBase { |
| 11020 | public: |
| 11021 | MatchAllOfGeneric(MatchAllOfGeneric const&) = delete; |
| 11022 | MatchAllOfGeneric& operator=(MatchAllOfGeneric const&) = delete; |
| 11023 | MatchAllOfGeneric(MatchAllOfGeneric&&) = default; |
| 11024 | MatchAllOfGeneric& operator=(MatchAllOfGeneric&&) = default; |
| 11025 | |
| 11026 | MatchAllOfGeneric(MatcherTs const&... matchers) : m_matchers{ {std::addressof(matchers)...} } {} |
| 11027 | explicit MatchAllOfGeneric(std::array<void const*, sizeof...(MatcherTs)> matchers) : m_matchers{matchers} {} |
| 11028 | |
| 11029 | template<typename Arg> |
| 11030 | bool match(Arg&& arg) const { |
| 11031 | return match_all_of<MatcherTs...>(arg, m_matchers, std::index_sequence_for<MatcherTs...>{}); |
| 11032 | } |
| 11033 | |
| 11034 | std::string describe() const override { |
| 11035 | return describe_multi_matcher<MatcherTs...>(" and "_sr, m_matchers, std::index_sequence_for<MatcherTs...>{}); |
| 11036 | } |
| 11037 | |
| 11038 | // Has to be public to enable the concatenating operators |
| 11039 | // below, because they are not friend of the RHS, only LHS, |
| 11040 | // and thus cannot access private fields of RHS |
| 11041 | std::array<void const*, sizeof...( MatcherTs )> m_matchers; |
| 11042 | |
| 11043 | |
| 11044 | //! Avoids type nesting for `GenericAllOf && GenericAllOf` case |
| 11045 | template<typename... MatchersRHS> |
| 11046 | friend |
| 11047 | MatchAllOfGeneric<MatcherTs..., MatchersRHS...> operator && ( |
| 11048 | MatchAllOfGeneric<MatcherTs...>&& lhs, |
| 11049 | MatchAllOfGeneric<MatchersRHS...>&& rhs) { |
| 11050 | return MatchAllOfGeneric<MatcherTs..., MatchersRHS...>{array_cat(CATCH_MOVE(lhs.m_matchers), CATCH_MOVE(rhs.m_matchers))}; |
| 11051 | } |
| 11052 | |
| 11053 | //! Avoids type nesting for `GenericAllOf && some matcher` case |
| 11054 | template<typename MatcherRHS> |
| 11055 | friend std::enable_if_t<is_matcher<MatcherRHS>::value, |
| 11056 | MatchAllOfGeneric<MatcherTs..., MatcherRHS>> operator && ( |
| 11057 | MatchAllOfGeneric<MatcherTs...>&& lhs, |
| 11058 | MatcherRHS const& rhs) { |
| 11059 | return MatchAllOfGeneric<MatcherTs..., MatcherRHS>{array_cat(CATCH_MOVE(lhs.m_matchers), static_cast<void const*>(&rhs))}; |
| 11060 | } |
| 11061 | |
| 11062 | //! Avoids type nesting for `some matcher && GenericAllOf` case |
| 11063 | template<typename MatcherLHS> |
| 11064 | friend std::enable_if_t<is_matcher<MatcherLHS>::value, |
| 11065 | MatchAllOfGeneric<MatcherLHS, MatcherTs...>> operator && ( |
| 11066 | MatcherLHS const& lhs, |
| 11067 | MatchAllOfGeneric<MatcherTs...>&& rhs) { |
| 11068 | return MatchAllOfGeneric<MatcherLHS, MatcherTs...>{array_cat(static_cast<void const*>(std::addressof(lhs)), CATCH_MOVE(rhs.m_matchers))}; |
| 11069 | } |
| 11070 | }; |
| 11071 | |
| 11072 | |
| 11073 | template<typename... MatcherTs> |
| 11074 | class MatchAnyOfGeneric final : public MatcherGenericBase { |
| 11075 | public: |
| 11076 | MatchAnyOfGeneric(MatchAnyOfGeneric const&) = delete; |
| 11077 | MatchAnyOfGeneric& operator=(MatchAnyOfGeneric const&) = delete; |
| 11078 | MatchAnyOfGeneric(MatchAnyOfGeneric&&) = default; |
| 11079 | MatchAnyOfGeneric& operator=(MatchAnyOfGeneric&&) = default; |
| 11080 | |
| 11081 | MatchAnyOfGeneric(MatcherTs const&... matchers) : m_matchers{ {std::addressof(matchers)...} } {} |
| 11082 | explicit MatchAnyOfGeneric(std::array<void const*, sizeof...(MatcherTs)> matchers) : m_matchers{matchers} {} |
| 11083 | |
| 11084 | template<typename Arg> |
| 11085 | bool match(Arg&& arg) const { |
| 11086 | return match_any_of<MatcherTs...>(arg, m_matchers, std::index_sequence_for<MatcherTs...>{}); |
| 11087 | } |
| 11088 | |
| 11089 | std::string describe() const override { |
| 11090 | return describe_multi_matcher<MatcherTs...>(" or "_sr, m_matchers, std::index_sequence_for<MatcherTs...>{}); |
| 11091 | } |
| 11092 | |
| 11093 | |
| 11094 | // Has to be public to enable the concatenating operators |
| 11095 | // below, because they are not friend of the RHS, only LHS, |
| 11096 | // and thus cannot access private fields of RHS |
| 11097 | std::array<void const*, sizeof...( MatcherTs )> m_matchers; |
| 11098 | |
| 11099 | //! Avoids type nesting for `GenericAnyOf || GenericAnyOf` case |
| 11100 | template<typename... MatchersRHS> |
| 11101 | friend MatchAnyOfGeneric<MatcherTs..., MatchersRHS...> operator || ( |
| 11102 | MatchAnyOfGeneric<MatcherTs...>&& lhs, |
| 11103 | MatchAnyOfGeneric<MatchersRHS...>&& rhs) { |
| 11104 | return MatchAnyOfGeneric<MatcherTs..., MatchersRHS...>{array_cat(CATCH_MOVE(lhs.m_matchers), CATCH_MOVE(rhs.m_matchers))}; |
| 11105 | } |
| 11106 | |
| 11107 | //! Avoids type nesting for `GenericAnyOf || some matcher` case |
| 11108 | template<typename MatcherRHS> |
| 11109 | friend std::enable_if_t<is_matcher<MatcherRHS>::value, |
| 11110 | MatchAnyOfGeneric<MatcherTs..., MatcherRHS>> operator || ( |
| 11111 | MatchAnyOfGeneric<MatcherTs...>&& lhs, |
| 11112 | MatcherRHS const& rhs) { |
| 11113 | return MatchAnyOfGeneric<MatcherTs..., MatcherRHS>{array_cat(CATCH_MOVE(lhs.m_matchers), static_cast<void const*>(std::addressof(rhs)))}; |
| 11114 | } |
| 11115 | |
| 11116 | //! Avoids type nesting for `some matcher || GenericAnyOf` case |
| 11117 | template<typename MatcherLHS> |
| 11118 | friend std::enable_if_t<is_matcher<MatcherLHS>::value, |
| 11119 | MatchAnyOfGeneric<MatcherLHS, MatcherTs...>> operator || ( |
| 11120 | MatcherLHS const& lhs, |
| 11121 | MatchAnyOfGeneric<MatcherTs...>&& rhs) { |
| 11122 | return MatchAnyOfGeneric<MatcherLHS, MatcherTs...>{array_cat(static_cast<void const*>(std::addressof(lhs)), CATCH_MOVE(rhs.m_matchers))}; |
| 11123 | } |
| 11124 | }; |
| 11125 | |
| 11126 | |
| 11127 | template<typename MatcherT> |
| 11128 | class MatchNotOfGeneric final : public MatcherGenericBase { |
| 11129 | MatcherT const& m_matcher; |
| 11130 | |
| 11131 | public: |
| 11132 | MatchNotOfGeneric(MatchNotOfGeneric const&) = delete; |
| 11133 | MatchNotOfGeneric& operator=(MatchNotOfGeneric const&) = delete; |
| 11134 | MatchNotOfGeneric(MatchNotOfGeneric&&) = default; |
| 11135 | MatchNotOfGeneric& operator=(MatchNotOfGeneric&&) = default; |
| 11136 | |
| 11137 | explicit MatchNotOfGeneric(MatcherT const& matcher) : m_matcher{matcher} {} |
| 11138 | |
| 11139 | template<typename Arg> |
| 11140 | bool match(Arg&& arg) const { |
| 11141 | return !m_matcher.match(arg); |
| 11142 | } |
| 11143 | |
| 11144 | std::string describe() const override { |
| 11145 | return "not " + m_matcher.toString(); |
| 11146 | } |
| 11147 | |
| 11148 | //! Negating negation can just unwrap and return underlying matcher |
| 11149 | friend MatcherT const& operator ! (MatchNotOfGeneric<MatcherT> const& matcher) { |
| 11150 | return matcher.m_matcher; |
| 11151 | } |
| 11152 | }; |
| 11153 | } // namespace Detail |
| 11154 | |
| 11155 | |
| 11156 | // compose only generic matchers |
| 11157 | template<typename MatcherLHS, typename MatcherRHS> |
| 11158 | std::enable_if_t<Detail::are_generic_matchers<MatcherLHS, MatcherRHS>::value, Detail::MatchAllOfGeneric<MatcherLHS, MatcherRHS>> |
| 11159 | operator && (MatcherLHS const& lhs, MatcherRHS const& rhs) { |
| 11160 | return { lhs, rhs }; |
| 11161 | } |
| 11162 | |
| 11163 | template<typename MatcherLHS, typename MatcherRHS> |
| 11164 | std::enable_if_t<Detail::are_generic_matchers<MatcherLHS, MatcherRHS>::value, Detail::MatchAnyOfGeneric<MatcherLHS, MatcherRHS>> |
| 11165 | operator || (MatcherLHS const& lhs, MatcherRHS const& rhs) { |
| 11166 | return { lhs, rhs }; |
| 11167 | } |
| 11168 | |
| 11169 | //! Wrap provided generic matcher in generic negator |
| 11170 | template<typename MatcherT> |
| 11171 | std::enable_if_t<Detail::is_generic_matcher<MatcherT>::value, Detail::MatchNotOfGeneric<MatcherT>> |
| 11172 | operator ! (MatcherT const& matcher) { |
| 11173 | return Detail::MatchNotOfGeneric<MatcherT>{matcher}; |
| 11174 | } |
| 11175 | |
| 11176 | |
| 11177 | // compose mixed generic and non-generic matchers |
| 11178 | template<typename MatcherLHS, typename ArgRHS> |
| 11179 | std::enable_if_t<Detail::is_generic_matcher<MatcherLHS>::value, Detail::MatchAllOfGeneric<MatcherLHS, MatcherBase<ArgRHS>>> |
| 11180 | operator && (MatcherLHS const& lhs, MatcherBase<ArgRHS> const& rhs) { |
| 11181 | return { lhs, rhs }; |
| 11182 | } |
| 11183 | |
| 11184 | template<typename ArgLHS, typename MatcherRHS> |
| 11185 | std::enable_if_t<Detail::is_generic_matcher<MatcherRHS>::value, Detail::MatchAllOfGeneric<MatcherBase<ArgLHS>, MatcherRHS>> |
| 11186 | operator && (MatcherBase<ArgLHS> const& lhs, MatcherRHS const& rhs) { |
| 11187 | return { lhs, rhs }; |
| 11188 | } |
| 11189 | |
| 11190 | template<typename MatcherLHS, typename ArgRHS> |
| 11191 | std::enable_if_t<Detail::is_generic_matcher<MatcherLHS>::value, Detail::MatchAnyOfGeneric<MatcherLHS, MatcherBase<ArgRHS>>> |
| 11192 | operator || (MatcherLHS const& lhs, MatcherBase<ArgRHS> const& rhs) { |
| 11193 | return { lhs, rhs }; |
| 11194 | } |
| 11195 | |
| 11196 | template<typename ArgLHS, typename MatcherRHS> |
| 11197 | std::enable_if_t<Detail::is_generic_matcher<MatcherRHS>::value, Detail::MatchAnyOfGeneric<MatcherBase<ArgLHS>, MatcherRHS>> |
| 11198 | operator || (MatcherBase<ArgLHS> const& lhs, MatcherRHS const& rhs) { |
| 11199 | return { lhs, rhs }; |
| 11200 | } |
| 11201 | |
| 11202 | } // namespace Matchers |
| 11203 | } // namespace Catch |
| 11204 | |
| 11205 | #endif // CATCH_MATCHERS_TEMPLATED_HPP_INCLUDED |
| 11206 | |
| 11207 | namespace Catch { |
| 11208 | namespace Matchers { |
| 11209 | |
| 11210 | class IsEmptyMatcher final : public MatcherGenericBase { |
| 11211 | public: |
| 11212 | template <typename RangeLike> |
| 11213 | bool match(RangeLike&& rng) const { |
| 11214 | #if defined(CATCH_CONFIG_POLYFILL_NONMEMBER_CONTAINER_ACCESS) |
| 11215 | using Catch::Detail::empty; |
| 11216 | #else |
| 11217 | using std::empty; |
| 11218 | #endif |
| 11219 | return empty(rng); |
| 11220 | } |
| 11221 | |
| 11222 | std::string describe() const override; |
| 11223 | }; |
| 11224 | |
| 11225 | class HasSizeMatcher final : public MatcherGenericBase { |
| 11226 | std::size_t m_target_size; |
| 11227 | public: |
| 11228 | explicit HasSizeMatcher(std::size_t target_size): |
| 11229 | m_target_size(target_size) |
| 11230 | {} |
| 11231 | |
| 11232 | template <typename RangeLike> |
| 11233 | bool match(RangeLike&& rng) const { |
| 11234 | #if defined(CATCH_CONFIG_POLYFILL_NONMEMBER_CONTAINER_ACCESS) |
| 11235 | using Catch::Detail::size; |
| 11236 | #else |
| 11237 | using std::size; |
| 11238 | #endif |
| 11239 | return size(rng) == m_target_size; |
| 11240 | } |
| 11241 | |
| 11242 | std::string describe() const override; |
| 11243 | }; |
| 11244 | |
| 11245 | template <typename Matcher> |
| 11246 | class SizeMatchesMatcher final : public MatcherGenericBase { |
| 11247 | Matcher m_matcher; |
| 11248 | public: |
| 11249 | explicit SizeMatchesMatcher(Matcher m): |
| 11250 | m_matcher(CATCH_MOVE(m)) |
| 11251 | {} |
| 11252 | |
| 11253 | template <typename RangeLike> |
| 11254 | bool match(RangeLike&& rng) const { |
| 11255 | #if defined(CATCH_CONFIG_POLYFILL_NONMEMBER_CONTAINER_ACCESS) |
| 11256 | using Catch::Detail::size; |
| 11257 | #else |
| 11258 | using std::size; |
| 11259 | #endif |
| 11260 | return m_matcher.match(size(rng)); |
| 11261 | } |
| 11262 | |
| 11263 | std::string describe() const override { |
| 11264 | return "size matches " + m_matcher.describe(); |
| 11265 | } |
| 11266 | }; |
| 11267 | |
| 11268 | |
| 11269 | //! Creates a matcher that accepts empty ranges/containers |
| 11270 | IsEmptyMatcher IsEmpty(); |
| 11271 | //! Creates a matcher that accepts ranges/containers with specific size |
| 11272 | HasSizeMatcher SizeIs(std::size_t sz); |
| 11273 | template <typename Matcher> |
| 11274 | std::enable_if_t<Detail::is_matcher<Matcher>::value, |
| 11275 | SizeMatchesMatcher<Matcher>> SizeIs(Matcher&& m) { |
| 11276 | return SizeMatchesMatcher<Matcher>{CATCH_FORWARD(m)}; |
| 11277 | } |
| 11278 | |
| 11279 | } // end namespace Matchers |
| 11280 | } // end namespace Catch |
| 11281 | |
| 11282 | #endif // CATCH_MATCHERS_CONTAINER_PROPERTIES_HPP_INCLUDED |
| 11283 | |
| 11284 | |
| 11285 | #ifndef CATCH_MATCHERS_CONTAINS_HPP_INCLUDED |
| 11286 | #define CATCH_MATCHERS_CONTAINS_HPP_INCLUDED |
| 11287 | |
| 11288 | |
| 11289 | #include <algorithm> |
| 11290 | #include <functional> |
| 11291 | |
| 11292 | namespace Catch { |
| 11293 | namespace Matchers { |
| 11294 | //! Matcher for checking that an element in range is equal to specific element |
| 11295 | template <typename T, typename Equality> |
| 11296 | class ContainsElementMatcher final : public MatcherGenericBase { |
| 11297 | T m_desired; |
| 11298 | Equality m_eq; |
| 11299 | public: |
| 11300 | template <typename T2, typename Equality2> |
| 11301 | ContainsElementMatcher(T2&& target, Equality2&& predicate): |
| 11302 | m_desired(CATCH_FORWARD(target)), |
| 11303 | m_eq(CATCH_FORWARD(predicate)) |
| 11304 | {} |
| 11305 | |
| 11306 | std::string describe() const override { |
| 11307 | return "contains element " + Catch::Detail::stringify(m_desired); |
| 11308 | } |
| 11309 | |
| 11310 | template <typename RangeLike> |
| 11311 | bool match( RangeLike&& rng ) const { |
| 11312 | for ( auto&& elem : rng ) { |
| 11313 | if ( m_eq( elem, m_desired ) ) { return true; } |
| 11314 | } |
| 11315 | return false; |
| 11316 | } |
| 11317 | }; |
| 11318 | |
| 11319 | //! Meta-matcher for checking that an element in a range matches a specific matcher |
| 11320 | template <typename Matcher> |
| 11321 | class ContainsMatcherMatcher final : public MatcherGenericBase { |
| 11322 | Matcher m_matcher; |
| 11323 | public: |
| 11324 | // Note that we do a copy+move to avoid having to SFINAE this |
| 11325 | // constructor (and also avoid some perfect forwarding failure |
| 11326 | // cases) |
| 11327 | ContainsMatcherMatcher(Matcher matcher): |
| 11328 | m_matcher(CATCH_MOVE(matcher)) |
| 11329 | {} |
| 11330 | |
| 11331 | template <typename RangeLike> |
| 11332 | bool match(RangeLike&& rng) const { |
| 11333 | for (auto&& elem : rng) { |
| 11334 | if (m_matcher.match(elem)) { |
| 11335 | return true; |
| 11336 | } |
| 11337 | } |
| 11338 | return false; |
| 11339 | } |
| 11340 | |
| 11341 | std::string describe() const override { |
| 11342 | return "contains element matching " + m_matcher.describe(); |
| 11343 | } |
| 11344 | }; |
| 11345 | |
| 11346 | /** |
| 11347 | * Creates a matcher that checks whether a range contains a specific element. |
| 11348 | * |
| 11349 | * Uses `std::equal_to` to do the comparison |
| 11350 | */ |
| 11351 | template <typename T> |
| 11352 | std::enable_if_t<!Detail::is_matcher<T>::value, |
| 11353 | ContainsElementMatcher<T, std::equal_to<>>> Contains(T&& elem) { |
| 11354 | return { CATCH_FORWARD(elem), std::equal_to<>{} }; |
| 11355 | } |
| 11356 | |
| 11357 | //! Creates a matcher that checks whether a range contains element matching a matcher |
| 11358 | template <typename Matcher> |
| 11359 | std::enable_if_t<Detail::is_matcher<Matcher>::value, |
| 11360 | ContainsMatcherMatcher<Matcher>> Contains(Matcher&& matcher) { |
| 11361 | return { CATCH_FORWARD(matcher) }; |
| 11362 | } |
| 11363 | |
| 11364 | /** |
| 11365 | * Creates a matcher that checks whether a range contains a specific element. |
| 11366 | * |
| 11367 | * Uses `eq` to do the comparisons, the element is provided on the rhs |
| 11368 | */ |
| 11369 | template <typename T, typename Equality> |
| 11370 | ContainsElementMatcher<T, Equality> Contains(T&& elem, Equality&& eq) { |
| 11371 | return { CATCH_FORWARD(elem), CATCH_FORWARD(eq) }; |
| 11372 | } |
| 11373 | |
| 11374 | } |
| 11375 | } |
| 11376 | |
| 11377 | #endif // CATCH_MATCHERS_CONTAINS_HPP_INCLUDED |
| 11378 | |
| 11379 | |
| 11380 | #ifndef CATCH_MATCHERS_EXCEPTION_HPP_INCLUDED |
| 11381 | #define CATCH_MATCHERS_EXCEPTION_HPP_INCLUDED |
| 11382 | |
| 11383 | |
| 11384 | namespace Catch { |
| 11385 | namespace Matchers { |
| 11386 | |
| 11387 | class ExceptionMessageMatcher final : public MatcherBase<std::exception> { |
| 11388 | std::string m_message; |
| 11389 | public: |
| 11390 | |
| 11391 | ExceptionMessageMatcher(std::string const& message): |
| 11392 | m_message(message) |
| 11393 | {} |
| 11394 | |
| 11395 | bool match(std::exception const& ex) const override; |
| 11396 | |
| 11397 | std::string describe() const override; |
| 11398 | }; |
| 11399 | |
| 11400 | //! Creates a matcher that checks whether a std derived exception has the provided message |
| 11401 | ExceptionMessageMatcher Message(std::string const& message); |
| 11402 | |
| 11403 | template <typename StringMatcherType> |
| 11404 | class ExceptionMessageMatchesMatcher final |
| 11405 | : public MatcherBase<std::exception> { |
| 11406 | StringMatcherType m_matcher; |
| 11407 | |
| 11408 | public: |
| 11409 | ExceptionMessageMatchesMatcher( StringMatcherType matcher ): |
| 11410 | m_matcher( CATCH_MOVE( matcher ) ) {} |
| 11411 | |
| 11412 | bool match( std::exception const& ex ) const override { |
| 11413 | return m_matcher.match( ex.what() ); |
| 11414 | } |
| 11415 | |
| 11416 | std::string describe() const override { |
| 11417 | return " matches \"" + m_matcher.describe() + '"'; |
| 11418 | } |
| 11419 | }; |
| 11420 | |
| 11421 | //! Creates a matcher that checks whether a message from an std derived |
| 11422 | //! exception matches a provided matcher |
| 11423 | template <typename StringMatcherType> |
| 11424 | ExceptionMessageMatchesMatcher<StringMatcherType> |
| 11425 | MessageMatches( StringMatcherType&& matcher ) { |
| 11426 | return { CATCH_FORWARD( matcher ) }; |
| 11427 | } |
| 11428 | |
| 11429 | } // namespace Matchers |
| 11430 | } // namespace Catch |
| 11431 | |
| 11432 | #endif // CATCH_MATCHERS_EXCEPTION_HPP_INCLUDED |
| 11433 | |
| 11434 | |
| 11435 | #ifndef CATCH_MATCHERS_FLOATING_POINT_HPP_INCLUDED |
| 11436 | #define CATCH_MATCHERS_FLOATING_POINT_HPP_INCLUDED |
| 11437 | |
| 11438 | |
| 11439 | namespace Catch { |
| 11440 | namespace Matchers { |
| 11441 | |
| 11442 | namespace Detail { |
| 11443 | enum class FloatingPointKind : uint8_t; |
| 11444 | } |
| 11445 | |
| 11446 | class WithinAbsMatcher final : public MatcherBase<double> { |
| 11447 | public: |
| 11448 | WithinAbsMatcher(double target, double margin); |
| 11449 | bool match(double const& matchee) const override; |
| 11450 | std::string describe() const override; |
| 11451 | private: |
| 11452 | double m_target; |
| 11453 | double m_margin; |
| 11454 | }; |
| 11455 | |
| 11456 | //! Creates a matcher that accepts numbers within certain range of target |
| 11457 | WithinAbsMatcher WithinAbs( double target, double margin ); |
| 11458 | |
| 11459 | |
| 11460 | |
| 11461 | class WithinUlpsMatcher final : public MatcherBase<double> { |
| 11462 | public: |
| 11463 | WithinUlpsMatcher( double target, |
| 11464 | uint64_t ulps, |
| 11465 | Detail::FloatingPointKind baseType ); |
| 11466 | bool match(double const& matchee) const override; |
| 11467 | std::string describe() const override; |
| 11468 | private: |
| 11469 | double m_target; |
| 11470 | uint64_t m_ulps; |
| 11471 | Detail::FloatingPointKind m_type; |
| 11472 | }; |
| 11473 | |
| 11474 | //! Creates a matcher that accepts doubles within certain ULP range of target |
| 11475 | WithinUlpsMatcher WithinULP(double target, uint64_t maxUlpDiff); |
| 11476 | //! Creates a matcher that accepts floats within certain ULP range of target |
| 11477 | WithinUlpsMatcher WithinULP(float target, uint64_t maxUlpDiff); |
| 11478 | |
| 11479 | |
| 11480 | |
| 11481 | // Given IEEE-754 format for floats and doubles, we can assume |
| 11482 | // that float -> double promotion is lossless. Given this, we can |
| 11483 | // assume that if we do the standard relative comparison of |
| 11484 | // |lhs - rhs| <= epsilon * max(fabs(lhs), fabs(rhs)), then we get |
| 11485 | // the same result if we do this for floats, as if we do this for |
| 11486 | // doubles that were promoted from floats. |
| 11487 | class WithinRelMatcher final : public MatcherBase<double> { |
| 11488 | public: |
| 11489 | WithinRelMatcher( double target, double epsilon ); |
| 11490 | bool match(double const& matchee) const override; |
| 11491 | std::string describe() const override; |
| 11492 | private: |
| 11493 | double m_target; |
| 11494 | double m_epsilon; |
| 11495 | }; |
| 11496 | |
| 11497 | //! Creates a matcher that accepts doubles within certain relative range of target |
| 11498 | WithinRelMatcher WithinRel(double target, double eps); |
| 11499 | //! Creates a matcher that accepts doubles within 100*DBL_EPS relative range of target |
| 11500 | WithinRelMatcher WithinRel(double target); |
| 11501 | //! Creates a matcher that accepts doubles within certain relative range of target |
| 11502 | WithinRelMatcher WithinRel(float target, float eps); |
| 11503 | //! Creates a matcher that accepts floats within 100*FLT_EPS relative range of target |
| 11504 | WithinRelMatcher WithinRel(float target); |
| 11505 | |
| 11506 | |
| 11507 | |
| 11508 | class IsNaNMatcher final : public MatcherBase<double> { |
| 11509 | public: |
| 11510 | IsNaNMatcher() = default; |
| 11511 | bool match( double const& matchee ) const override; |
| 11512 | std::string describe() const override; |
| 11513 | }; |
| 11514 | |
| 11515 | IsNaNMatcher IsNaN(); |
| 11516 | |
| 11517 | } // namespace Matchers |
| 11518 | } // namespace Catch |
| 11519 | |
| 11520 | #endif // CATCH_MATCHERS_FLOATING_POINT_HPP_INCLUDED |
| 11521 | |
| 11522 | |
| 11523 | #ifndef CATCH_MATCHERS_PREDICATE_HPP_INCLUDED |
| 11524 | #define CATCH_MATCHERS_PREDICATE_HPP_INCLUDED |
| 11525 | |
| 11526 | |
| 11527 | #include <string> |
| 11528 | |
| 11529 | namespace Catch { |
| 11530 | namespace Matchers { |
| 11531 | |
| 11532 | namespace Detail { |
| 11533 | std::string finalizeDescription(const std::string& desc); |
| 11534 | } // namespace Detail |
| 11535 | |
| 11536 | template <typename T, typename Predicate> |
| 11537 | class PredicateMatcher final : public MatcherBase<T> { |
| 11538 | Predicate m_predicate; |
| 11539 | std::string m_description; |
| 11540 | public: |
| 11541 | |
| 11542 | PredicateMatcher(Predicate&& elem, std::string const& descr) |
| 11543 | :m_predicate(CATCH_FORWARD(elem)), |
| 11544 | m_description(Detail::finalizeDescription(descr)) |
| 11545 | {} |
| 11546 | |
| 11547 | bool match( T const& item ) const override { |
| 11548 | return m_predicate(item); |
| 11549 | } |
| 11550 | |
| 11551 | std::string describe() const override { |
| 11552 | return m_description; |
| 11553 | } |
| 11554 | }; |
| 11555 | |
| 11556 | /** |
| 11557 | * Creates a matcher that calls delegates `match` to the provided predicate. |
| 11558 | * |
| 11559 | * The user has to explicitly specify the argument type to the matcher |
| 11560 | */ |
| 11561 | template<typename T, typename Pred> |
| 11562 | PredicateMatcher<T, Pred> Predicate(Pred&& predicate, std::string const& description = "") { |
| 11563 | static_assert(is_callable<Pred(T)>::value, "Predicate not callable with argument T"); |
| 11564 | static_assert(std::is_same<bool, FunctionReturnType<Pred, T>>::value, "Predicate does not return bool"); |
| 11565 | return PredicateMatcher<T, Pred>(CATCH_FORWARD(predicate), description); |
| 11566 | } |
| 11567 | |
| 11568 | } // namespace Matchers |
| 11569 | } // namespace Catch |
| 11570 | |
| 11571 | #endif // CATCH_MATCHERS_PREDICATE_HPP_INCLUDED |
| 11572 | |
| 11573 | |
| 11574 | #ifndef CATCH_MATCHERS_QUANTIFIERS_HPP_INCLUDED |
| 11575 | #define CATCH_MATCHERS_QUANTIFIERS_HPP_INCLUDED |
| 11576 | |
| 11577 | |
| 11578 | namespace Catch { |
| 11579 | namespace Matchers { |
| 11580 | // Matcher for checking that all elements in range matches a given matcher. |
| 11581 | template <typename Matcher> |
| 11582 | class AllMatchMatcher final : public MatcherGenericBase { |
| 11583 | Matcher m_matcher; |
| 11584 | public: |
| 11585 | AllMatchMatcher(Matcher matcher): |
| 11586 | m_matcher(CATCH_MOVE(matcher)) |
| 11587 | {} |
| 11588 | |
| 11589 | std::string describe() const override { |
| 11590 | return "all match " + m_matcher.describe(); |
| 11591 | } |
| 11592 | |
| 11593 | template <typename RangeLike> |
| 11594 | bool match(RangeLike&& rng) const { |
| 11595 | for (auto&& elem : rng) { |
| 11596 | if (!m_matcher.match(elem)) { |
| 11597 | return false; |
| 11598 | } |
| 11599 | } |
| 11600 | return true; |
| 11601 | } |
| 11602 | }; |
| 11603 | |
| 11604 | // Matcher for checking that no element in range matches a given matcher. |
| 11605 | template <typename Matcher> |
| 11606 | class NoneMatchMatcher final : public MatcherGenericBase { |
| 11607 | Matcher m_matcher; |
| 11608 | public: |
| 11609 | NoneMatchMatcher(Matcher matcher): |
| 11610 | m_matcher(CATCH_MOVE(matcher)) |
| 11611 | {} |
| 11612 | |
| 11613 | std::string describe() const override { |
| 11614 | return "none match " + m_matcher.describe(); |
| 11615 | } |
| 11616 | |
| 11617 | template <typename RangeLike> |
| 11618 | bool match(RangeLike&& rng) const { |
| 11619 | for (auto&& elem : rng) { |
| 11620 | if (m_matcher.match(elem)) { |
| 11621 | return false; |
| 11622 | } |
| 11623 | } |
| 11624 | return true; |
| 11625 | } |
| 11626 | }; |
| 11627 | |
| 11628 | // Matcher for checking that at least one element in range matches a given matcher. |
| 11629 | template <typename Matcher> |
| 11630 | class AnyMatchMatcher final : public MatcherGenericBase { |
| 11631 | Matcher m_matcher; |
| 11632 | public: |
| 11633 | AnyMatchMatcher(Matcher matcher): |
| 11634 | m_matcher(CATCH_MOVE(matcher)) |
| 11635 | {} |
| 11636 | |
| 11637 | std::string describe() const override { |
| 11638 | return "any match " + m_matcher.describe(); |
| 11639 | } |
| 11640 | |
| 11641 | template <typename RangeLike> |
| 11642 | bool match(RangeLike&& rng) const { |
| 11643 | for (auto&& elem : rng) { |
| 11644 | if (m_matcher.match(elem)) { |
| 11645 | return true; |
| 11646 | } |
| 11647 | } |
| 11648 | return false; |
| 11649 | } |
| 11650 | }; |
| 11651 | |
| 11652 | // Matcher for checking that all elements in range are true. |
| 11653 | class AllTrueMatcher final : public MatcherGenericBase { |
| 11654 | public: |
| 11655 | std::string describe() const override; |
| 11656 | |
| 11657 | template <typename RangeLike> |
| 11658 | bool match(RangeLike&& rng) const { |
| 11659 | for (auto&& elem : rng) { |
| 11660 | if (!elem) { |
| 11661 | return false; |
| 11662 | } |
| 11663 | } |
| 11664 | return true; |
| 11665 | } |
| 11666 | }; |
| 11667 | |
| 11668 | // Matcher for checking that no element in range is true. |
| 11669 | class NoneTrueMatcher final : public MatcherGenericBase { |
| 11670 | public: |
| 11671 | std::string describe() const override; |
| 11672 | |
| 11673 | template <typename RangeLike> |
| 11674 | bool match(RangeLike&& rng) const { |
| 11675 | for (auto&& elem : rng) { |
| 11676 | if (elem) { |
| 11677 | return false; |
| 11678 | } |
| 11679 | } |
| 11680 | return true; |
| 11681 | } |
| 11682 | }; |
| 11683 | |
| 11684 | // Matcher for checking that any element in range is true. |
| 11685 | class AnyTrueMatcher final : public MatcherGenericBase { |
| 11686 | public: |
| 11687 | std::string describe() const override; |
| 11688 | |
| 11689 | template <typename RangeLike> |
| 11690 | bool match(RangeLike&& rng) const { |
| 11691 | for (auto&& elem : rng) { |
| 11692 | if (elem) { |
| 11693 | return true; |
| 11694 | } |
| 11695 | } |
| 11696 | return false; |
| 11697 | } |
| 11698 | }; |
| 11699 | |
| 11700 | // Creates a matcher that checks whether all elements in a range match a matcher |
| 11701 | template <typename Matcher> |
| 11702 | AllMatchMatcher<Matcher> AllMatch(Matcher&& matcher) { |
| 11703 | return { CATCH_FORWARD(matcher) }; |
| 11704 | } |
| 11705 | |
| 11706 | // Creates a matcher that checks whether no element in a range matches a matcher. |
| 11707 | template <typename Matcher> |
| 11708 | NoneMatchMatcher<Matcher> NoneMatch(Matcher&& matcher) { |
| 11709 | return { CATCH_FORWARD(matcher) }; |
| 11710 | } |
| 11711 | |
| 11712 | // Creates a matcher that checks whether any element in a range matches a matcher. |
| 11713 | template <typename Matcher> |
| 11714 | AnyMatchMatcher<Matcher> AnyMatch(Matcher&& matcher) { |
| 11715 | return { CATCH_FORWARD(matcher) }; |
| 11716 | } |
| 11717 | |
| 11718 | // Creates a matcher that checks whether all elements in a range are true |
| 11719 | AllTrueMatcher AllTrue(); |
| 11720 | |
| 11721 | // Creates a matcher that checks whether no element in a range is true |
| 11722 | NoneTrueMatcher NoneTrue(); |
| 11723 | |
| 11724 | // Creates a matcher that checks whether any element in a range is true |
| 11725 | AnyTrueMatcher AnyTrue(); |
| 11726 | } |
| 11727 | } |
| 11728 | |
| 11729 | #endif // CATCH_MATCHERS_QUANTIFIERS_HPP_INCLUDED |
| 11730 | |
| 11731 | |
| 11732 | #ifndef CATCH_MATCHERS_RANGE_EQUALS_HPP_INCLUDED |
| 11733 | #define CATCH_MATCHERS_RANGE_EQUALS_HPP_INCLUDED |
| 11734 | |
| 11735 | |
| 11736 | #include <algorithm> |
| 11737 | #include <utility> |
| 11738 | |
| 11739 | namespace Catch { |
| 11740 | namespace Matchers { |
| 11741 | |
| 11742 | /** |
| 11743 | * Matcher for checking that an element contains the same |
| 11744 | * elements in the same order |
| 11745 | */ |
| 11746 | template <typename TargetRangeLike, typename Equality> |
| 11747 | class RangeEqualsMatcher final : public MatcherGenericBase { |
| 11748 | TargetRangeLike m_desired; |
| 11749 | Equality m_predicate; |
| 11750 | |
| 11751 | public: |
| 11752 | template <typename TargetRangeLike2, typename Equality2> |
| 11753 | RangeEqualsMatcher( TargetRangeLike2&& range, |
| 11754 | Equality2&& predicate ): |
| 11755 | m_desired( CATCH_FORWARD( range ) ), |
| 11756 | m_predicate( CATCH_FORWARD( predicate ) ) {} |
| 11757 | |
| 11758 | template <typename RangeLike> |
| 11759 | bool match( RangeLike&& rng ) const { |
| 11760 | auto rng_start = begin( rng ); |
| 11761 | const auto rng_end = end( rng ); |
| 11762 | auto target_start = begin( m_desired ); |
| 11763 | const auto target_end = end( m_desired ); |
| 11764 | |
| 11765 | while (rng_start != rng_end && target_start != target_end) { |
| 11766 | if (!m_predicate(*rng_start, *target_start)) { |
| 11767 | return false; |
| 11768 | } |
| 11769 | ++rng_start; |
| 11770 | ++target_start; |
| 11771 | } |
| 11772 | return rng_start == rng_end && target_start == target_end; |
| 11773 | } |
| 11774 | |
| 11775 | std::string describe() const override { |
| 11776 | return "elements are " + Catch::Detail::stringify( m_desired ); |
| 11777 | } |
| 11778 | }; |
| 11779 | |
| 11780 | /** |
| 11781 | * Matcher for checking that an element contains the same |
| 11782 | * elements (but not necessarily in the same order) |
| 11783 | */ |
| 11784 | template <typename TargetRangeLike, typename Equality> |
| 11785 | class UnorderedRangeEqualsMatcher final : public MatcherGenericBase { |
| 11786 | TargetRangeLike m_desired; |
| 11787 | Equality m_predicate; |
| 11788 | |
| 11789 | public: |
| 11790 | template <typename TargetRangeLike2, typename Equality2> |
| 11791 | UnorderedRangeEqualsMatcher( TargetRangeLike2&& range, |
| 11792 | Equality2&& predicate ): |
| 11793 | m_desired( CATCH_FORWARD( range ) ), |
| 11794 | m_predicate( CATCH_FORWARD( predicate ) ) {} |
| 11795 | |
| 11796 | template <typename RangeLike> |
| 11797 | bool match( RangeLike&& rng ) const { |
| 11798 | using std::begin; |
| 11799 | using std::end; |
| 11800 | return Catch::Detail::is_permutation( begin( m_desired ), |
| 11801 | end( m_desired ), |
| 11802 | begin( rng ), |
| 11803 | end( rng ), |
| 11804 | m_predicate ); |
| 11805 | } |
| 11806 | |
| 11807 | std::string describe() const override { |
| 11808 | return "unordered elements are " + |
| 11809 | ::Catch::Detail::stringify( m_desired ); |
| 11810 | } |
| 11811 | }; |
| 11812 | |
| 11813 | /** |
| 11814 | * Creates a matcher that checks if all elements in a range are equal |
| 11815 | * to all elements in another range. |
| 11816 | * |
| 11817 | * Uses `std::equal_to` to do the comparison |
| 11818 | */ |
| 11819 | template <typename RangeLike> |
| 11820 | std::enable_if_t<!Detail::is_matcher<RangeLike>::value, |
| 11821 | RangeEqualsMatcher<RangeLike, std::equal_to<>>> |
| 11822 | RangeEquals( RangeLike&& range ) { |
| 11823 | return { CATCH_FORWARD( range ), std::equal_to<>{} }; |
| 11824 | } |
| 11825 | |
| 11826 | /** |
| 11827 | * Creates a matcher that checks if all elements in a range are equal |
| 11828 | * to all elements in another range. |
| 11829 | * |
| 11830 | * Uses to provided predicate `predicate` to do the comparisons |
| 11831 | */ |
| 11832 | template <typename RangeLike, typename Equality> |
| 11833 | RangeEqualsMatcher<RangeLike, Equality> |
| 11834 | RangeEquals( RangeLike&& range, Equality&& predicate ) { |
| 11835 | return { CATCH_FORWARD( range ), CATCH_FORWARD( predicate ) }; |
| 11836 | } |
| 11837 | |
| 11838 | /** |
| 11839 | * Creates a matcher that checks if all elements in a range are equal |
| 11840 | * to all elements in another range, in some permutation |
| 11841 | * |
| 11842 | * Uses `std::equal_to` to do the comparison |
| 11843 | */ |
| 11844 | template <typename RangeLike> |
| 11845 | std::enable_if_t< |
| 11846 | !Detail::is_matcher<RangeLike>::value, |
| 11847 | UnorderedRangeEqualsMatcher<RangeLike, std::equal_to<>>> |
| 11848 | UnorderedRangeEquals( RangeLike&& range ) { |
| 11849 | return { CATCH_FORWARD( range ), std::equal_to<>{} }; |
| 11850 | } |
| 11851 | |
| 11852 | /** |
| 11853 | * Creates a matcher that checks if all elements in a range are equal |
| 11854 | * to all elements in another range, in some permutation. |
| 11855 | * |
| 11856 | * Uses to provided predicate `predicate` to do the comparisons |
| 11857 | */ |
| 11858 | template <typename RangeLike, typename Equality> |
| 11859 | UnorderedRangeEqualsMatcher<RangeLike, Equality> |
| 11860 | UnorderedRangeEquals( RangeLike&& range, Equality&& predicate ) { |
| 11861 | return { CATCH_FORWARD( range ), CATCH_FORWARD( predicate ) }; |
| 11862 | } |
| 11863 | } // namespace Matchers |
| 11864 | } // namespace Catch |
| 11865 | |
| 11866 | #endif // CATCH_MATCHERS_RANGE_EQUALS_HPP_INCLUDED |
| 11867 | |
| 11868 | |
| 11869 | #ifndef CATCH_MATCHERS_STRING_HPP_INCLUDED |
| 11870 | #define CATCH_MATCHERS_STRING_HPP_INCLUDED |
| 11871 | |
| 11872 | |
| 11873 | #include <string> |
| 11874 | |
| 11875 | namespace Catch { |
| 11876 | namespace Matchers { |
| 11877 | |
| 11878 | struct CasedString { |
| 11879 | CasedString( std::string const& str, CaseSensitive caseSensitivity ); |
| 11880 | std::string adjustString( std::string const& str ) const; |
| 11881 | StringRef caseSensitivitySuffix() const; |
| 11882 | |
| 11883 | CaseSensitive m_caseSensitivity; |
| 11884 | std::string m_str; |
| 11885 | }; |
| 11886 | |
| 11887 | class StringMatcherBase : public MatcherBase<std::string> { |
| 11888 | protected: |
| 11889 | CasedString m_comparator; |
| 11890 | StringRef m_operation; |
| 11891 | |
| 11892 | public: |
| 11893 | StringMatcherBase( StringRef operation, |
| 11894 | CasedString const& comparator ); |
| 11895 | std::string describe() const override; |
| 11896 | }; |
| 11897 | |
| 11898 | class StringEqualsMatcher final : public StringMatcherBase { |
| 11899 | public: |
| 11900 | StringEqualsMatcher( CasedString const& comparator ); |
| 11901 | bool match( std::string const& source ) const override; |
| 11902 | }; |
| 11903 | class StringContainsMatcher final : public StringMatcherBase { |
| 11904 | public: |
| 11905 | StringContainsMatcher( CasedString const& comparator ); |
| 11906 | bool match( std::string const& source ) const override; |
| 11907 | }; |
| 11908 | class StartsWithMatcher final : public StringMatcherBase { |
| 11909 | public: |
| 11910 | StartsWithMatcher( CasedString const& comparator ); |
| 11911 | bool match( std::string const& source ) const override; |
| 11912 | }; |
| 11913 | class EndsWithMatcher final : public StringMatcherBase { |
| 11914 | public: |
| 11915 | EndsWithMatcher( CasedString const& comparator ); |
| 11916 | bool match( std::string const& source ) const override; |
| 11917 | }; |
| 11918 | |
| 11919 | class RegexMatcher final : public MatcherBase<std::string> { |
| 11920 | std::string m_regex; |
| 11921 | CaseSensitive m_caseSensitivity; |
| 11922 | |
| 11923 | public: |
| 11924 | RegexMatcher( std::string regex, CaseSensitive caseSensitivity ); |
| 11925 | bool match( std::string const& matchee ) const override; |
| 11926 | std::string describe() const override; |
| 11927 | }; |
| 11928 | |
| 11929 | //! Creates matcher that accepts strings that are exactly equal to `str` |
| 11930 | StringEqualsMatcher Equals( std::string const& str, CaseSensitive caseSensitivity = CaseSensitive::Yes ); |
| 11931 | //! Creates matcher that accepts strings that contain `str` |
| 11932 | StringContainsMatcher ContainsSubstring( std::string const& str, CaseSensitive caseSensitivity = CaseSensitive::Yes ); |
| 11933 | //! Creates matcher that accepts strings that _end_ with `str` |
| 11934 | EndsWithMatcher EndsWith( std::string const& str, CaseSensitive caseSensitivity = CaseSensitive::Yes ); |
| 11935 | //! Creates matcher that accepts strings that _start_ with `str` |
| 11936 | StartsWithMatcher StartsWith( std::string const& str, CaseSensitive caseSensitivity = CaseSensitive::Yes ); |
| 11937 | //! Creates matcher that accepts strings matching `regex` |
| 11938 | RegexMatcher Matches( std::string const& regex, CaseSensitive caseSensitivity = CaseSensitive::Yes ); |
| 11939 | |
| 11940 | } // namespace Matchers |
| 11941 | } // namespace Catch |
| 11942 | |
| 11943 | #endif // CATCH_MATCHERS_STRING_HPP_INCLUDED |
| 11944 | |
| 11945 | |
| 11946 | #ifndef CATCH_MATCHERS_VECTOR_HPP_INCLUDED |
| 11947 | #define CATCH_MATCHERS_VECTOR_HPP_INCLUDED |
| 11948 | |
| 11949 | |
| 11950 | #include <algorithm> |
| 11951 | |
| 11952 | namespace Catch { |
| 11953 | namespace Matchers { |
| 11954 | |
| 11955 | template<typename T, typename Alloc> |
| 11956 | class VectorContainsElementMatcher final : public MatcherBase<std::vector<T, Alloc>> { |
| 11957 | T const& m_comparator; |
| 11958 | |
| 11959 | public: |
| 11960 | VectorContainsElementMatcher(T const& comparator): |
| 11961 | m_comparator(comparator) |
| 11962 | {} |
| 11963 | |
| 11964 | bool match(std::vector<T, Alloc> const& v) const override { |
| 11965 | for (auto const& el : v) { |
| 11966 | if (el == m_comparator) { |
| 11967 | return true; |
| 11968 | } |
| 11969 | } |
| 11970 | return false; |
| 11971 | } |
| 11972 | |
| 11973 | std::string describe() const override { |
| 11974 | return "Contains: " + ::Catch::Detail::stringify( m_comparator ); |
| 11975 | } |
| 11976 | }; |
| 11977 | |
| 11978 | template<typename T, typename AllocComp, typename AllocMatch> |
| 11979 | class ContainsMatcher final : public MatcherBase<std::vector<T, AllocMatch>> { |
| 11980 | std::vector<T, AllocComp> const& m_comparator; |
| 11981 | |
| 11982 | public: |
| 11983 | ContainsMatcher(std::vector<T, AllocComp> const& comparator): |
| 11984 | m_comparator( comparator ) |
| 11985 | {} |
| 11986 | |
| 11987 | bool match(std::vector<T, AllocMatch> const& v) const override { |
| 11988 | // !TBD: see note in EqualsMatcher |
| 11989 | if (m_comparator.size() > v.size()) |
| 11990 | return false; |
| 11991 | for (auto const& comparator : m_comparator) { |
| 11992 | auto present = false; |
| 11993 | for (const auto& el : v) { |
| 11994 | if (el == comparator) { |
| 11995 | present = true; |
| 11996 | break; |
| 11997 | } |
| 11998 | } |
| 11999 | if (!present) { |
| 12000 | return false; |
| 12001 | } |
| 12002 | } |
| 12003 | return true; |
| 12004 | } |
| 12005 | std::string describe() const override { |
| 12006 | return "Contains: " + ::Catch::Detail::stringify( m_comparator ); |
| 12007 | } |
| 12008 | }; |
| 12009 | |
| 12010 | template<typename T, typename AllocComp, typename AllocMatch> |
| 12011 | class EqualsMatcher final : public MatcherBase<std::vector<T, AllocMatch>> { |
| 12012 | std::vector<T, AllocComp> const& m_comparator; |
| 12013 | |
| 12014 | public: |
| 12015 | EqualsMatcher(std::vector<T, AllocComp> const& comparator): |
| 12016 | m_comparator( comparator ) |
| 12017 | {} |
| 12018 | |
| 12019 | bool match(std::vector<T, AllocMatch> const& v) const override { |
| 12020 | // !TBD: This currently works if all elements can be compared using != |
| 12021 | // - a more general approach would be via a compare template that defaults |
| 12022 | // to using !=. but could be specialised for, e.g. std::vector<T> etc |
| 12023 | // - then just call that directly |
| 12024 | if ( m_comparator.size() != v.size() ) { return false; } |
| 12025 | for ( std::size_t i = 0; i < v.size(); ++i ) { |
| 12026 | if ( !( m_comparator[i] == v[i] ) ) { return false; } |
| 12027 | } |
| 12028 | return true; |
| 12029 | } |
| 12030 | std::string describe() const override { |
| 12031 | return "Equals: " + ::Catch::Detail::stringify( m_comparator ); |
| 12032 | } |
| 12033 | }; |
| 12034 | |
| 12035 | template<typename T, typename AllocComp, typename AllocMatch> |
| 12036 | class ApproxMatcher final : public MatcherBase<std::vector<T, AllocMatch>> { |
| 12037 | std::vector<T, AllocComp> const& m_comparator; |
| 12038 | mutable Catch::Approx approx = Catch::Approx::custom(); |
| 12039 | |
| 12040 | public: |
| 12041 | ApproxMatcher(std::vector<T, AllocComp> const& comparator): |
| 12042 | m_comparator( comparator ) |
| 12043 | {} |
| 12044 | |
| 12045 | bool match(std::vector<T, AllocMatch> const& v) const override { |
| 12046 | if (m_comparator.size() != v.size()) |
| 12047 | return false; |
| 12048 | for (std::size_t i = 0; i < v.size(); ++i) |
| 12049 | if (m_comparator[i] != approx(v[i])) |
| 12050 | return false; |
| 12051 | return true; |
| 12052 | } |
| 12053 | std::string describe() const override { |
| 12054 | return "is approx: " + ::Catch::Detail::stringify( m_comparator ); |
| 12055 | } |
| 12056 | template <typename = std::enable_if_t<std::is_constructible<double, T>::value>> |
| 12057 | ApproxMatcher& epsilon( T const& newEpsilon ) { |
| 12058 | approx.epsilon(static_cast<double>(newEpsilon)); |
| 12059 | return *this; |
| 12060 | } |
| 12061 | template <typename = std::enable_if_t<std::is_constructible<double, T>::value>> |
| 12062 | ApproxMatcher& margin( T const& newMargin ) { |
| 12063 | approx.margin(static_cast<double>(newMargin)); |
| 12064 | return *this; |
| 12065 | } |
| 12066 | template <typename = std::enable_if_t<std::is_constructible<double, T>::value>> |
| 12067 | ApproxMatcher& scale( T const& newScale ) { |
| 12068 | approx.scale(static_cast<double>(newScale)); |
| 12069 | return *this; |
| 12070 | } |
| 12071 | }; |
| 12072 | |
| 12073 | template<typename T, typename AllocComp, typename AllocMatch> |
| 12074 | class UnorderedEqualsMatcher final : public MatcherBase<std::vector<T, AllocMatch>> { |
| 12075 | std::vector<T, AllocComp> const& m_target; |
| 12076 | |
| 12077 | public: |
| 12078 | UnorderedEqualsMatcher(std::vector<T, AllocComp> const& target): |
| 12079 | m_target(target) |
| 12080 | {} |
| 12081 | bool match(std::vector<T, AllocMatch> const& vec) const override { |
| 12082 | if (m_target.size() != vec.size()) { |
| 12083 | return false; |
| 12084 | } |
| 12085 | return std::is_permutation(m_target.begin(), m_target.end(), vec.begin()); |
| 12086 | } |
| 12087 | |
| 12088 | std::string describe() const override { |
| 12089 | return "UnorderedEquals: " + ::Catch::Detail::stringify(m_target); |
| 12090 | } |
| 12091 | }; |
| 12092 | |
| 12093 | |
| 12094 | // The following functions create the actual matcher objects. |
| 12095 | // This allows the types to be inferred |
| 12096 | |
| 12097 | //! Creates a matcher that matches vectors that contain all elements in `comparator` |
| 12098 | template<typename T, typename AllocComp = std::allocator<T>, typename AllocMatch = AllocComp> |
| 12099 | ContainsMatcher<T, AllocComp, AllocMatch> Contains( std::vector<T, AllocComp> const& comparator ) { |
| 12100 | return ContainsMatcher<T, AllocComp, AllocMatch>(comparator); |
| 12101 | } |
| 12102 | |
| 12103 | //! Creates a matcher that matches vectors that contain `comparator` as an element |
| 12104 | template<typename T, typename Alloc = std::allocator<T>> |
| 12105 | VectorContainsElementMatcher<T, Alloc> VectorContains( T const& comparator ) { |
| 12106 | return VectorContainsElementMatcher<T, Alloc>(comparator); |
| 12107 | } |
| 12108 | |
| 12109 | //! Creates a matcher that matches vectors that are exactly equal to `comparator` |
| 12110 | template<typename T, typename AllocComp = std::allocator<T>, typename AllocMatch = AllocComp> |
| 12111 | EqualsMatcher<T, AllocComp, AllocMatch> Equals( std::vector<T, AllocComp> const& comparator ) { |
| 12112 | return EqualsMatcher<T, AllocComp, AllocMatch>(comparator); |
| 12113 | } |
| 12114 | |
| 12115 | //! Creates a matcher that matches vectors that `comparator` as an element |
| 12116 | template<typename T, typename AllocComp = std::allocator<T>, typename AllocMatch = AllocComp> |
| 12117 | ApproxMatcher<T, AllocComp, AllocMatch> Approx( std::vector<T, AllocComp> const& comparator ) { |
| 12118 | return ApproxMatcher<T, AllocComp, AllocMatch>(comparator); |
| 12119 | } |
| 12120 | |
| 12121 | //! Creates a matcher that matches vectors that is equal to `target` modulo permutation |
| 12122 | template<typename T, typename AllocComp = std::allocator<T>, typename AllocMatch = AllocComp> |
| 12123 | UnorderedEqualsMatcher<T, AllocComp, AllocMatch> UnorderedEquals(std::vector<T, AllocComp> const& target) { |
| 12124 | return UnorderedEqualsMatcher<T, AllocComp, AllocMatch>(target); |
| 12125 | } |
| 12126 | |
| 12127 | } // namespace Matchers |
| 12128 | } // namespace Catch |
| 12129 | |
| 12130 | #endif // CATCH_MATCHERS_VECTOR_HPP_INCLUDED |
| 12131 | |
| 12132 | #endif // CATCH_MATCHERS_ALL_HPP_INCLUDED |
| 12133 | |
| 12134 | |
| 12135 | /** \file |
| 12136 | * This is a convenience header for Catch2's Reporter support. It includes |
| 12137 | * **all** of Catch2 headers related to reporters, including all reporters. |
| 12138 | * |
| 12139 | * Generally the Catch2 users should use specific includes they need, |
| 12140 | * but this header can be used instead for ease-of-experimentation, or |
| 12141 | * just plain convenience, at the cost of (significantly) increased |
| 12142 | * compilation times. |
| 12143 | * |
| 12144 | * When a new header (reporter) is added to either the `reporter` folder, |
| 12145 | * or to the corresponding internal subfolder, it should be added here. |
| 12146 | */ |
| 12147 | |
| 12148 | #ifndef CATCH_REPORTERS_ALL_HPP_INCLUDED |
| 12149 | #define CATCH_REPORTERS_ALL_HPP_INCLUDED |
| 12150 | |
| 12151 | |
| 12152 | |
| 12153 | #ifndef CATCH_REPORTER_AUTOMAKE_HPP_INCLUDED |
| 12154 | #define CATCH_REPORTER_AUTOMAKE_HPP_INCLUDED |
| 12155 | |
| 12156 | |
| 12157 | |
| 12158 | #ifndef CATCH_REPORTER_STREAMING_BASE_HPP_INCLUDED |
| 12159 | #define CATCH_REPORTER_STREAMING_BASE_HPP_INCLUDED |
| 12160 | |
| 12161 | |
| 12162 | |
| 12163 | #ifndef CATCH_REPORTER_COMMON_BASE_HPP_INCLUDED |
| 12164 | #define CATCH_REPORTER_COMMON_BASE_HPP_INCLUDED |
| 12165 | |
| 12166 | |
| 12167 | #include <map> |
| 12168 | #include <string> |
| 12169 | |
| 12170 | namespace Catch { |
| 12171 | class ColourImpl; |
| 12172 | |
| 12173 | /** |
| 12174 | * This is the base class for all reporters. |
| 12175 | * |
| 12176 | * If are writing a reporter, you must derive from this type, or one |
| 12177 | * of the helper reporter bases that are derived from this type. |
| 12178 | * |
| 12179 | * ReporterBase centralizes handling of various common tasks in reporters, |
| 12180 | * like storing the right stream for the reporters to write to, and |
| 12181 | * providing the default implementation of the different listing events. |
| 12182 | */ |
| 12183 | class ReporterBase : public IEventListener { |
| 12184 | protected: |
| 12185 | //! The stream wrapper as passed to us by outside code |
| 12186 | Detail::unique_ptr<IStream> m_wrapped_stream; |
| 12187 | //! Cached output stream from `m_wrapped_stream` to reduce |
| 12188 | //! number of indirect calls needed to write output. |
| 12189 | std::ostream& m_stream; |
| 12190 | //! Colour implementation this reporter was configured for |
| 12191 | Detail::unique_ptr<ColourImpl> m_colour; |
| 12192 | //! The custom reporter options user passed down to the reporter |
| 12193 | std::map<std::string, std::string> m_customOptions; |
| 12194 | |
| 12195 | public: |
| 12196 | ReporterBase( ReporterConfig&& config ); |
| 12197 | ~ReporterBase() override; // = default; |
| 12198 | |
| 12199 | /** |
| 12200 | * Provides a simple default listing of reporters. |
| 12201 | * |
| 12202 | * Should look roughly like the reporter listing in v2 and earlier |
| 12203 | * versions of Catch2. |
| 12204 | */ |
| 12205 | void listReporters( |
| 12206 | std::vector<ReporterDescription> const& descriptions ) override; |
| 12207 | /** |
| 12208 | * Provides a simple default listing of listeners |
| 12209 | * |
| 12210 | * Looks similarly to listing of reporters, but with listener type |
| 12211 | * instead of reporter name. |
| 12212 | */ |
| 12213 | void listListeners( |
| 12214 | std::vector<ListenerDescription> const& descriptions ) override; |
| 12215 | /** |
| 12216 | * Provides a simple default listing of tests. |
| 12217 | * |
| 12218 | * Should look roughly like the test listing in v2 and earlier versions |
| 12219 | * of Catch2. Especially supports low-verbosity listing that mimics the |
| 12220 | * old `--list-test-names-only` output. |
| 12221 | */ |
| 12222 | void listTests( std::vector<TestCaseHandle> const& tests ) override; |
| 12223 | /** |
| 12224 | * Provides a simple default listing of tags. |
| 12225 | * |
| 12226 | * Should look roughly like the tag listing in v2 and earlier versions |
| 12227 | * of Catch2. |
| 12228 | */ |
| 12229 | void listTags( std::vector<TagInfo> const& tags ) override; |
| 12230 | }; |
| 12231 | } // namespace Catch |
| 12232 | |
| 12233 | #endif // CATCH_REPORTER_COMMON_BASE_HPP_INCLUDED |
| 12234 | |
| 12235 | #include <vector> |
| 12236 | |
| 12237 | namespace Catch { |
| 12238 | |
| 12239 | class StreamingReporterBase : public ReporterBase { |
| 12240 | public: |
| 12241 | // GCC5 compat: we cannot use inherited constructor, because it |
| 12242 | // doesn't implement backport of P0136 |
| 12243 | StreamingReporterBase(ReporterConfig&& _config): |
| 12244 | ReporterBase(CATCH_MOVE(_config)) |
| 12245 | {} |
| 12246 | ~StreamingReporterBase() override; |
| 12247 | |
| 12248 | void benchmarkPreparing( StringRef ) override {} |
| 12249 | void benchmarkStarting( BenchmarkInfo const& ) override {} |
| 12250 | void benchmarkEnded( BenchmarkStats<> const& ) override {} |
| 12251 | void benchmarkFailed( StringRef ) override {} |
| 12252 | |
| 12253 | void fatalErrorEncountered( StringRef /*error*/ ) override {} |
| 12254 | void noMatchingTestCases( StringRef /*unmatchedSpec*/ ) override {} |
| 12255 | void reportInvalidTestSpec( StringRef /*invalidArgument*/ ) override {} |
| 12256 | |
| 12257 | void testRunStarting( TestRunInfo const& _testRunInfo ) override; |
| 12258 | |
| 12259 | void testCaseStarting(TestCaseInfo const& _testInfo) override { |
| 12260 | currentTestCaseInfo = &_testInfo; |
| 12261 | } |
| 12262 | void testCasePartialStarting( TestCaseInfo const&, uint64_t ) override {} |
| 12263 | void sectionStarting(SectionInfo const& _sectionInfo) override { |
| 12264 | m_sectionStack.push_back(_sectionInfo); |
| 12265 | } |
| 12266 | |
| 12267 | void assertionStarting( AssertionInfo const& ) override {} |
| 12268 | void assertionEnded( AssertionStats const& ) override {} |
| 12269 | |
| 12270 | void sectionEnded(SectionStats const& /* _sectionStats */) override { |
| 12271 | m_sectionStack.pop_back(); |
| 12272 | } |
| 12273 | void testCasePartialEnded( TestCaseStats const&, uint64_t ) override {} |
| 12274 | void testCaseEnded(TestCaseStats const& /* _testCaseStats */) override { |
| 12275 | currentTestCaseInfo = nullptr; |
| 12276 | } |
| 12277 | void testRunEnded( TestRunStats const& /* _testRunStats */ ) override; |
| 12278 | |
| 12279 | void skipTest(TestCaseInfo const&) override { |
| 12280 | // Don't do anything with this by default. |
| 12281 | // It can optionally be overridden in the derived class. |
| 12282 | } |
| 12283 | |
| 12284 | protected: |
| 12285 | TestRunInfo currentTestRunInfo{ "test run has not started yet"_sr }; |
| 12286 | TestCaseInfo const* currentTestCaseInfo = nullptr; |
| 12287 | |
| 12288 | //! Stack of all _active_ sections in the _current_ test case |
| 12289 | std::vector<SectionInfo> m_sectionStack; |
| 12290 | }; |
| 12291 | |
| 12292 | } // end namespace Catch |
| 12293 | |
| 12294 | #endif // CATCH_REPORTER_STREAMING_BASE_HPP_INCLUDED |
| 12295 | |
| 12296 | #include <string> |
| 12297 | |
| 12298 | namespace Catch { |
| 12299 | |
| 12300 | class AutomakeReporter final : public StreamingReporterBase { |
| 12301 | public: |
| 12302 | // GCC5 compat: we cannot use inherited constructor, because it |
| 12303 | // doesn't implement backport of P0136 |
| 12304 | AutomakeReporter(ReporterConfig&& _config): |
| 12305 | StreamingReporterBase(CATCH_MOVE(_config)) |
| 12306 | {} |
| 12307 | ~AutomakeReporter() override; |
| 12308 | |
| 12309 | static std::string getDescription() { |
| 12310 | using namespace std::string_literals; |
| 12311 | return "Reports test results in the format of Automake .trs files"s; |
| 12312 | } |
| 12313 | |
| 12314 | void testCaseEnded(TestCaseStats const& _testCaseStats) override; |
| 12315 | void skipTest(TestCaseInfo const& testInfo) override; |
| 12316 | }; |
| 12317 | |
| 12318 | } // end namespace Catch |
| 12319 | |
| 12320 | #endif // CATCH_REPORTER_AUTOMAKE_HPP_INCLUDED |
| 12321 | |
| 12322 | |
| 12323 | #ifndef CATCH_REPORTER_COMPACT_HPP_INCLUDED |
| 12324 | #define CATCH_REPORTER_COMPACT_HPP_INCLUDED |
| 12325 | |
| 12326 | |
| 12327 | |
| 12328 | |
| 12329 | namespace Catch { |
| 12330 | |
| 12331 | class CompactReporter final : public StreamingReporterBase { |
| 12332 | public: |
| 12333 | using StreamingReporterBase::StreamingReporterBase; |
| 12334 | |
| 12335 | ~CompactReporter() override; |
| 12336 | |
| 12337 | static std::string getDescription(); |
| 12338 | |
| 12339 | void noMatchingTestCases( StringRef unmatchedSpec ) override; |
| 12340 | |
| 12341 | void testRunStarting( TestRunInfo const& _testInfo ) override; |
| 12342 | |
| 12343 | void assertionEnded(AssertionStats const& _assertionStats) override; |
| 12344 | |
| 12345 | void sectionEnded(SectionStats const& _sectionStats) override; |
| 12346 | |
| 12347 | void testRunEnded(TestRunStats const& _testRunStats) override; |
| 12348 | |
| 12349 | }; |
| 12350 | |
| 12351 | } // end namespace Catch |
| 12352 | |
| 12353 | #endif // CATCH_REPORTER_COMPACT_HPP_INCLUDED |
| 12354 | |
| 12355 | |
| 12356 | #ifndef CATCH_REPORTER_CONSOLE_HPP_INCLUDED |
| 12357 | #define CATCH_REPORTER_CONSOLE_HPP_INCLUDED |
| 12358 | |
| 12359 | |
| 12360 | namespace Catch { |
| 12361 | // Fwd decls |
| 12362 | class TablePrinter; |
| 12363 | |
| 12364 | class ConsoleReporter final : public StreamingReporterBase { |
| 12365 | Detail::unique_ptr<TablePrinter> m_tablePrinter; |
| 12366 | |
| 12367 | public: |
| 12368 | ConsoleReporter(ReporterConfig&& config); |
| 12369 | ~ConsoleReporter() override; |
| 12370 | static std::string getDescription(); |
| 12371 | |
| 12372 | void noMatchingTestCases( StringRef unmatchedSpec ) override; |
| 12373 | void reportInvalidTestSpec( StringRef arg ) override; |
| 12374 | |
| 12375 | void assertionStarting(AssertionInfo const&) override; |
| 12376 | |
| 12377 | void assertionEnded(AssertionStats const& _assertionStats) override; |
| 12378 | |
| 12379 | void sectionStarting(SectionInfo const& _sectionInfo) override; |
| 12380 | void sectionEnded(SectionStats const& _sectionStats) override; |
| 12381 | |
| 12382 | void benchmarkPreparing( StringRef name ) override; |
| 12383 | void benchmarkStarting(BenchmarkInfo const& info) override; |
| 12384 | void benchmarkEnded(BenchmarkStats<> const& stats) override; |
| 12385 | void benchmarkFailed( StringRef error ) override; |
| 12386 | |
| 12387 | void testCaseEnded(TestCaseStats const& _testCaseStats) override; |
| 12388 | void testRunEnded(TestRunStats const& _testRunStats) override; |
| 12389 | void testRunStarting(TestRunInfo const& _testRunInfo) override; |
| 12390 | |
| 12391 | private: |
| 12392 | void lazyPrint(); |
| 12393 | |
| 12394 | void lazyPrintWithoutClosingBenchmarkTable(); |
| 12395 | void lazyPrintRunInfo(); |
| 12396 | void printTestCaseAndSectionHeader(); |
| 12397 | |
| 12398 | void printClosedHeader(std::string const& _name); |
| 12399 | void printOpenHeader(std::string const& _name); |
| 12400 | |
| 12401 | // if string has a : in first line will set indent to follow it on |
| 12402 | // subsequent lines |
| 12403 | void printHeaderString(std::string const& _string, std::size_t indent = 0); |
| 12404 | |
| 12405 | void printTotalsDivider(Totals const& totals); |
| 12406 | |
| 12407 | bool m_headerPrinted = false; |
| 12408 | bool m_testRunInfoPrinted = false; |
| 12409 | }; |
| 12410 | |
| 12411 | } // end namespace Catch |
| 12412 | |
| 12413 | #endif // CATCH_REPORTER_CONSOLE_HPP_INCLUDED |
| 12414 | |
| 12415 | |
| 12416 | #ifndef CATCH_REPORTER_CUMULATIVE_BASE_HPP_INCLUDED |
| 12417 | #define CATCH_REPORTER_CUMULATIVE_BASE_HPP_INCLUDED |
| 12418 | |
| 12419 | |
| 12420 | #include <string> |
| 12421 | #include <vector> |
| 12422 | |
| 12423 | namespace Catch { |
| 12424 | |
| 12425 | namespace Detail { |
| 12426 | |
| 12427 | //! Represents either an assertion or a benchmark result to be handled by cumulative reporter later |
| 12428 | class AssertionOrBenchmarkResult { |
| 12429 | // This should really be a variant, but this is much faster |
| 12430 | // to write and the data layout here is already terrible |
| 12431 | // enough that we do not have to care about the object size. |
| 12432 | Optional<AssertionStats> m_assertion; |
| 12433 | Optional<BenchmarkStats<>> m_benchmark; |
| 12434 | public: |
| 12435 | AssertionOrBenchmarkResult(AssertionStats const& assertion); |
| 12436 | AssertionOrBenchmarkResult(BenchmarkStats<> const& benchmark); |
| 12437 | |
| 12438 | bool isAssertion() const; |
| 12439 | bool isBenchmark() const; |
| 12440 | |
| 12441 | AssertionStats const& asAssertion() const; |
| 12442 | BenchmarkStats<> const& asBenchmark() const; |
| 12443 | }; |
| 12444 | } |
| 12445 | |
| 12446 | /** |
| 12447 | * Utility base for reporters that need to handle all results at once |
| 12448 | * |
| 12449 | * It stores tree of all test cases, sections and assertions, and after the |
| 12450 | * test run is finished, calls into `testRunEndedCumulative` to pass the |
| 12451 | * control to the deriving class. |
| 12452 | * |
| 12453 | * If you are deriving from this class and override any testing related |
| 12454 | * member functions, you should first call into the base's implementation to |
| 12455 | * avoid breaking the tree construction. |
| 12456 | * |
| 12457 | * Due to the way this base functions, it has to expand assertions up-front, |
| 12458 | * even if they are later unused (e.g. because the deriving reporter does |
| 12459 | * not report successful assertions, or because the deriving reporter does |
| 12460 | * not use assertion expansion at all). Derived classes can use two |
| 12461 | * customization points, `m_shouldStoreSuccesfulAssertions` and |
| 12462 | * `m_shouldStoreFailedAssertions`, to disable the expansion and gain extra |
| 12463 | * performance. **Accessing the assertion expansions if it wasn't stored is |
| 12464 | * UB.** |
| 12465 | */ |
| 12466 | class CumulativeReporterBase : public ReporterBase { |
| 12467 | public: |
| 12468 | template<typename T, typename ChildNodeT> |
| 12469 | struct Node { |
| 12470 | explicit Node( T const& _value ) : value( _value ) {} |
| 12471 | |
| 12472 | using ChildNodes = std::vector<Detail::unique_ptr<ChildNodeT>>; |
| 12473 | T value; |
| 12474 | ChildNodes children; |
| 12475 | }; |
| 12476 | struct SectionNode { |
| 12477 | explicit SectionNode(SectionStats const& _stats) : stats(_stats) {} |
| 12478 | |
| 12479 | bool operator == (SectionNode const& other) const { |
| 12480 | return stats.sectionInfo.lineInfo == other.stats.sectionInfo.lineInfo; |
| 12481 | } |
| 12482 | |
| 12483 | bool hasAnyAssertions() const; |
| 12484 | |
| 12485 | SectionStats stats; |
| 12486 | std::vector<Detail::unique_ptr<SectionNode>> childSections; |
| 12487 | std::vector<Detail::AssertionOrBenchmarkResult> assertionsAndBenchmarks; |
| 12488 | std::string stdOut; |
| 12489 | std::string stdErr; |
| 12490 | }; |
| 12491 | |
| 12492 | |
| 12493 | using TestCaseNode = Node<TestCaseStats, SectionNode>; |
| 12494 | using TestRunNode = Node<TestRunStats, TestCaseNode>; |
| 12495 | |
| 12496 | // GCC5 compat: we cannot use inherited constructor, because it |
| 12497 | // doesn't implement backport of P0136 |
| 12498 | CumulativeReporterBase(ReporterConfig&& _config): |
| 12499 | ReporterBase(CATCH_MOVE(_config)) |
| 12500 | {} |
| 12501 | ~CumulativeReporterBase() override; |
| 12502 | |
| 12503 | void benchmarkPreparing( StringRef ) override {} |
| 12504 | void benchmarkStarting( BenchmarkInfo const& ) override {} |
| 12505 | void benchmarkEnded( BenchmarkStats<> const& benchmarkStats ) override; |
| 12506 | void benchmarkFailed( StringRef ) override {} |
| 12507 | |
| 12508 | void noMatchingTestCases( StringRef ) override {} |
| 12509 | void reportInvalidTestSpec( StringRef ) override {} |
| 12510 | void fatalErrorEncountered( StringRef /*error*/ ) override {} |
| 12511 | |
| 12512 | void testRunStarting( TestRunInfo const& ) override {} |
| 12513 | |
| 12514 | void testCaseStarting( TestCaseInfo const& ) override {} |
| 12515 | void testCasePartialStarting( TestCaseInfo const&, uint64_t ) override {} |
| 12516 | void sectionStarting( SectionInfo const& sectionInfo ) override; |
| 12517 | |
| 12518 | void assertionStarting( AssertionInfo const& ) override {} |
| 12519 | |
| 12520 | void assertionEnded( AssertionStats const& assertionStats ) override; |
| 12521 | void sectionEnded( SectionStats const& sectionStats ) override; |
| 12522 | void testCasePartialEnded( TestCaseStats const&, uint64_t ) override {} |
| 12523 | void testCaseEnded( TestCaseStats const& testCaseStats ) override; |
| 12524 | void testRunEnded( TestRunStats const& testRunStats ) override; |
| 12525 | //! Customization point: called after last test finishes (testRunEnded has been handled) |
| 12526 | virtual void testRunEndedCumulative() = 0; |
| 12527 | |
| 12528 | void skipTest(TestCaseInfo const&) override {} |
| 12529 | |
| 12530 | protected: |
| 12531 | //! Should the cumulative base store the assertion expansion for successful assertions? |
| 12532 | bool m_shouldStoreSuccesfulAssertions = true; |
| 12533 | //! Should the cumulative base store the assertion expansion for failed assertions? |
| 12534 | bool m_shouldStoreFailedAssertions = true; |
| 12535 | |
| 12536 | // We need lazy construction here. We should probably refactor it |
| 12537 | // later, after the events are redone. |
| 12538 | //! The root node of the test run tree. |
| 12539 | Detail::unique_ptr<TestRunNode> m_testRun; |
| 12540 | |
| 12541 | private: |
| 12542 | // Note: We rely on pointer identity being stable, which is why |
| 12543 | // we store pointers to the nodes rather than the values. |
| 12544 | std::vector<Detail::unique_ptr<TestCaseNode>> m_testCases; |
| 12545 | // Root section of the _current_ test case |
| 12546 | Detail::unique_ptr<SectionNode> m_rootSection; |
| 12547 | // Deepest section of the _current_ test case |
| 12548 | SectionNode* m_deepestSection = nullptr; |
| 12549 | // Stack of _active_ sections in the _current_ test case |
| 12550 | std::vector<SectionNode*> m_sectionStack; |
| 12551 | }; |
| 12552 | |
| 12553 | } // end namespace Catch |
| 12554 | |
| 12555 | #endif // CATCH_REPORTER_CUMULATIVE_BASE_HPP_INCLUDED |
| 12556 | |
| 12557 | |
| 12558 | #ifndef CATCH_REPORTER_EVENT_LISTENER_HPP_INCLUDED |
| 12559 | #define CATCH_REPORTER_EVENT_LISTENER_HPP_INCLUDED |
| 12560 | |
| 12561 | |
| 12562 | namespace Catch { |
| 12563 | |
| 12564 | /** |
| 12565 | * Base class to simplify implementing listeners. |
| 12566 | * |
| 12567 | * Provides empty default implementation for all IEventListener member |
| 12568 | * functions, so that a listener implementation can pick which |
| 12569 | * member functions it actually cares about. |
| 12570 | */ |
| 12571 | class EventListenerBase : public IEventListener { |
| 12572 | public: |
| 12573 | using IEventListener::IEventListener; |
| 12574 | |
| 12575 | void reportInvalidTestSpec( StringRef unmatchedSpec ) override; |
| 12576 | void fatalErrorEncountered( StringRef error ) override; |
| 12577 | |
| 12578 | void benchmarkPreparing( StringRef name ) override; |
| 12579 | void benchmarkStarting( BenchmarkInfo const& benchmarkInfo ) override; |
| 12580 | void benchmarkEnded( BenchmarkStats<> const& benchmarkStats ) override; |
| 12581 | void benchmarkFailed( StringRef error ) override; |
| 12582 | |
| 12583 | void assertionStarting( AssertionInfo const& assertionInfo ) override; |
| 12584 | void assertionEnded( AssertionStats const& assertionStats ) override; |
| 12585 | |
| 12586 | void listReporters( |
| 12587 | std::vector<ReporterDescription> const& descriptions ) override; |
| 12588 | void listListeners( |
| 12589 | std::vector<ListenerDescription> const& descriptions ) override; |
| 12590 | void listTests( std::vector<TestCaseHandle> const& tests ) override; |
| 12591 | void listTags( std::vector<TagInfo> const& tagInfos ) override; |
| 12592 | |
| 12593 | void noMatchingTestCases( StringRef unmatchedSpec ) override; |
| 12594 | void testRunStarting( TestRunInfo const& testRunInfo ) override; |
| 12595 | void testCaseStarting( TestCaseInfo const& testInfo ) override; |
| 12596 | void testCasePartialStarting( TestCaseInfo const& testInfo, |
| 12597 | uint64_t partNumber ) override; |
| 12598 | void sectionStarting( SectionInfo const& sectionInfo ) override; |
| 12599 | void sectionEnded( SectionStats const& sectionStats ) override; |
| 12600 | void testCasePartialEnded( TestCaseStats const& testCaseStats, |
| 12601 | uint64_t partNumber ) override; |
| 12602 | void testCaseEnded( TestCaseStats const& testCaseStats ) override; |
| 12603 | void testRunEnded( TestRunStats const& testRunStats ) override; |
| 12604 | void skipTest( TestCaseInfo const& testInfo ) override; |
| 12605 | }; |
| 12606 | |
| 12607 | } // end namespace Catch |
| 12608 | |
| 12609 | #endif // CATCH_REPORTER_EVENT_LISTENER_HPP_INCLUDED |
| 12610 | |
| 12611 | |
| 12612 | #ifndef CATCH_REPORTER_HELPERS_HPP_INCLUDED |
| 12613 | #define CATCH_REPORTER_HELPERS_HPP_INCLUDED |
| 12614 | |
| 12615 | #include <iosfwd> |
| 12616 | #include <string> |
| 12617 | #include <vector> |
| 12618 | |
| 12619 | |
| 12620 | namespace Catch { |
| 12621 | |
| 12622 | class IConfig; |
| 12623 | class TestCaseHandle; |
| 12624 | class ColourImpl; |
| 12625 | |
| 12626 | // Returns double formatted as %.3f (format expected on output) |
| 12627 | std::string getFormattedDuration( double duration ); |
| 12628 | |
| 12629 | //! Should the reporter show duration of test given current configuration? |
| 12630 | bool shouldShowDuration( IConfig const& config, double duration ); |
| 12631 | |
| 12632 | std::string serializeFilters( std::vector<std::string> const& filters ); |
| 12633 | |
| 12634 | struct lineOfChars { |
| 12635 | char c; |
| 12636 | constexpr lineOfChars( char c_ ): c( c_ ) {} |
| 12637 | |
| 12638 | friend std::ostream& operator<<( std::ostream& out, lineOfChars value ); |
| 12639 | }; |
| 12640 | |
| 12641 | /** |
| 12642 | * Lists reporter descriptions to the provided stream in user-friendly |
| 12643 | * format |
| 12644 | * |
| 12645 | * Used as the default listing implementation by the first party reporter |
| 12646 | * bases. The output should be backwards compatible with the output of |
| 12647 | * Catch2 v2 binaries. |
| 12648 | */ |
| 12649 | void |
| 12650 | defaultListReporters( std::ostream& out, |
| 12651 | std::vector<ReporterDescription> const& descriptions, |
| 12652 | Verbosity verbosity ); |
| 12653 | |
| 12654 | /** |
| 12655 | * Lists listeners descriptions to the provided stream in user-friendly |
| 12656 | * format |
| 12657 | */ |
| 12658 | void defaultListListeners( std::ostream& out, |
| 12659 | std::vector<ListenerDescription> const& descriptions ); |
| 12660 | |
| 12661 | /** |
| 12662 | * Lists tag information to the provided stream in user-friendly format |
| 12663 | * |
| 12664 | * Used as the default listing implementation by the first party reporter |
| 12665 | * bases. The output should be backwards compatible with the output of |
| 12666 | * Catch2 v2 binaries. |
| 12667 | */ |
| 12668 | void defaultListTags( std::ostream& out, std::vector<TagInfo> const& tags, bool isFiltered ); |
| 12669 | |
| 12670 | /** |
| 12671 | * Lists test case information to the provided stream in user-friendly |
| 12672 | * format |
| 12673 | * |
| 12674 | * Used as the default listing implementation by the first party reporter |
| 12675 | * bases. The output is backwards compatible with the output of Catch2 |
| 12676 | * v2 binaries, and also supports the format specific to the old |
| 12677 | * `--list-test-names-only` option, for people who used it in integrations. |
| 12678 | */ |
| 12679 | void defaultListTests( std::ostream& out, |
| 12680 | ColourImpl* streamColour, |
| 12681 | std::vector<TestCaseHandle> const& tests, |
| 12682 | bool isFiltered, |
| 12683 | Verbosity verbosity ); |
| 12684 | |
| 12685 | /** |
| 12686 | * Prints test run totals to the provided stream in user-friendly format |
| 12687 | * |
| 12688 | * Used by the console and compact reporters. |
| 12689 | */ |
| 12690 | void printTestRunTotals( std::ostream& stream, |
| 12691 | ColourImpl& streamColour, |
| 12692 | Totals const& totals ); |
| 12693 | |
| 12694 | } // end namespace Catch |
| 12695 | |
| 12696 | #endif // CATCH_REPORTER_HELPERS_HPP_INCLUDED |
| 12697 | |
| 12698 | |
| 12699 | #ifndef CATCH_REPORTER_JUNIT_HPP_INCLUDED |
| 12700 | #define CATCH_REPORTER_JUNIT_HPP_INCLUDED |
| 12701 | |
| 12702 | |
| 12703 | |
| 12704 | namespace Catch { |
| 12705 | |
| 12706 | class JunitReporter final : public CumulativeReporterBase { |
| 12707 | public: |
| 12708 | JunitReporter(ReporterConfig&& _config); |
| 12709 | |
| 12710 | ~JunitReporter() override = default; |
| 12711 | |
| 12712 | static std::string getDescription(); |
| 12713 | |
| 12714 | void testRunStarting(TestRunInfo const& runInfo) override; |
| 12715 | |
| 12716 | void testCaseStarting(TestCaseInfo const& testCaseInfo) override; |
| 12717 | void assertionEnded(AssertionStats const& assertionStats) override; |
| 12718 | |
| 12719 | void testCaseEnded(TestCaseStats const& testCaseStats) override; |
| 12720 | |
| 12721 | void testRunEndedCumulative() override; |
| 12722 | |
| 12723 | private: |
| 12724 | void writeRun(TestRunNode const& testRunNode, double suiteTime); |
| 12725 | |
| 12726 | void writeTestCase(TestCaseNode const& testCaseNode); |
| 12727 | |
| 12728 | void writeSection( std::string const& className, |
| 12729 | std::string const& rootName, |
| 12730 | SectionNode const& sectionNode, |
| 12731 | bool testOkToFail ); |
| 12732 | |
| 12733 | void writeAssertions(SectionNode const& sectionNode); |
| 12734 | void writeAssertion(AssertionStats const& stats); |
| 12735 | |
| 12736 | XmlWriter xml; |
| 12737 | Timer suiteTimer; |
| 12738 | std::string stdOutForSuite; |
| 12739 | std::string stdErrForSuite; |
| 12740 | unsigned int unexpectedExceptions = 0; |
| 12741 | bool m_okToFail = false; |
| 12742 | }; |
| 12743 | |
| 12744 | } // end namespace Catch |
| 12745 | |
| 12746 | #endif // CATCH_REPORTER_JUNIT_HPP_INCLUDED |
| 12747 | |
| 12748 | |
| 12749 | #ifndef CATCH_REPORTER_MULTI_HPP_INCLUDED |
| 12750 | #define CATCH_REPORTER_MULTI_HPP_INCLUDED |
| 12751 | |
| 12752 | |
| 12753 | namespace Catch { |
| 12754 | |
| 12755 | class MultiReporter final : public IEventListener { |
| 12756 | /* |
| 12757 | * Stores all added reporters and listeners |
| 12758 | * |
| 12759 | * All Listeners are stored before all reporters, and individual |
| 12760 | * listeners/reporters are stored in order of insertion. |
| 12761 | */ |
| 12762 | std::vector<IEventListenerPtr> m_reporterLikes; |
| 12763 | bool m_haveNoncapturingReporters = false; |
| 12764 | |
| 12765 | // Keep track of how many listeners we have already inserted, |
| 12766 | // so that we can insert them into the main vector at the right place |
| 12767 | size_t m_insertedListeners = 0; |
| 12768 | |
| 12769 | void updatePreferences(IEventListener const& reporterish); |
| 12770 | |
| 12771 | public: |
| 12772 | using IEventListener::IEventListener; |
| 12773 | |
| 12774 | void addListener( IEventListenerPtr&& listener ); |
| 12775 | void addReporter( IEventListenerPtr&& reporter ); |
| 12776 | |
| 12777 | public: // IEventListener |
| 12778 | |
| 12779 | void noMatchingTestCases( StringRef unmatchedSpec ) override; |
| 12780 | void fatalErrorEncountered( StringRef error ) override; |
| 12781 | void reportInvalidTestSpec( StringRef arg ) override; |
| 12782 | |
| 12783 | void benchmarkPreparing( StringRef name ) override; |
| 12784 | void benchmarkStarting( BenchmarkInfo const& benchmarkInfo ) override; |
| 12785 | void benchmarkEnded( BenchmarkStats<> const& benchmarkStats ) override; |
| 12786 | void benchmarkFailed( StringRef error ) override; |
| 12787 | |
| 12788 | void testRunStarting( TestRunInfo const& testRunInfo ) override; |
| 12789 | void testCaseStarting( TestCaseInfo const& testInfo ) override; |
| 12790 | void testCasePartialStarting(TestCaseInfo const& testInfo, uint64_t partNumber) override; |
| 12791 | void sectionStarting( SectionInfo const& sectionInfo ) override; |
| 12792 | void assertionStarting( AssertionInfo const& assertionInfo ) override; |
| 12793 | |
| 12794 | void assertionEnded( AssertionStats const& assertionStats ) override; |
| 12795 | void sectionEnded( SectionStats const& sectionStats ) override; |
| 12796 | void testCasePartialEnded(TestCaseStats const& testInfo, uint64_t partNumber) override; |
| 12797 | void testCaseEnded( TestCaseStats const& testCaseStats ) override; |
| 12798 | void testRunEnded( TestRunStats const& testRunStats ) override; |
| 12799 | |
| 12800 | void skipTest( TestCaseInfo const& testInfo ) override; |
| 12801 | |
| 12802 | void listReporters(std::vector<ReporterDescription> const& descriptions) override; |
| 12803 | void listListeners(std::vector<ListenerDescription> const& descriptions) override; |
| 12804 | void listTests(std::vector<TestCaseHandle> const& tests) override; |
| 12805 | void listTags(std::vector<TagInfo> const& tags) override; |
| 12806 | |
| 12807 | |
| 12808 | }; |
| 12809 | |
| 12810 | } // end namespace Catch |
| 12811 | |
| 12812 | #endif // CATCH_REPORTER_MULTI_HPP_INCLUDED |
| 12813 | |
| 12814 | |
| 12815 | #ifndef CATCH_REPORTER_REGISTRARS_HPP_INCLUDED |
| 12816 | #define CATCH_REPORTER_REGISTRARS_HPP_INCLUDED |
| 12817 | |
| 12818 | |
| 12819 | #include <type_traits> |
| 12820 | |
| 12821 | namespace Catch { |
| 12822 | |
| 12823 | namespace Detail { |
| 12824 | |
| 12825 | template <typename T, typename = void> |
| 12826 | struct has_description : std::false_type {}; |
| 12827 | |
| 12828 | template <typename T> |
| 12829 | struct has_description< |
| 12830 | T, |
| 12831 | void_t<decltype( T::getDescription() )>> |
| 12832 | : std::true_type {}; |
| 12833 | |
| 12834 | //! Indirection for reporter registration, so that the error handling is |
| 12835 | //! independent on the reporter's concrete type |
| 12836 | void registerReporterImpl( std::string const& name, |
| 12837 | IReporterFactoryPtr reporterPtr ); |
| 12838 | //! Actually registers the factory, independent on listener's concrete type |
| 12839 | void registerListenerImpl( Detail::unique_ptr<EventListenerFactory> listenerFactory ); |
| 12840 | } // namespace Detail |
| 12841 | |
| 12842 | class IEventListener; |
| 12843 | using IEventListenerPtr = Detail::unique_ptr<IEventListener>; |
| 12844 | |
| 12845 | template <typename T> |
| 12846 | class ReporterFactory : public IReporterFactory { |
| 12847 | |
| 12848 | IEventListenerPtr create( ReporterConfig&& config ) const override { |
| 12849 | return Detail::make_unique<T>( CATCH_MOVE(config) ); |
| 12850 | } |
| 12851 | |
| 12852 | std::string getDescription() const override { |
| 12853 | return T::getDescription(); |
| 12854 | } |
| 12855 | }; |
| 12856 | |
| 12857 | |
| 12858 | template<typename T> |
| 12859 | class ReporterRegistrar { |
| 12860 | public: |
| 12861 | explicit ReporterRegistrar( std::string const& name ) { |
| 12862 | registerReporterImpl( name, |
| 12863 | Detail::make_unique<ReporterFactory<T>>() ); |
| 12864 | } |
| 12865 | }; |
| 12866 | |
| 12867 | template<typename T> |
| 12868 | class ListenerRegistrar { |
| 12869 | |
| 12870 | class TypedListenerFactory : public EventListenerFactory { |
| 12871 | StringRef m_listenerName; |
| 12872 | |
| 12873 | std::string getDescriptionImpl( std::true_type ) const { |
| 12874 | return T::getDescription(); |
| 12875 | } |
| 12876 | |
| 12877 | std::string getDescriptionImpl( std::false_type ) const { |
| 12878 | return "(No description provided)"; |
| 12879 | } |
| 12880 | |
| 12881 | public: |
| 12882 | TypedListenerFactory( StringRef listenerName ): |
| 12883 | m_listenerName( listenerName ) {} |
| 12884 | |
| 12885 | IEventListenerPtr create( IConfig const* config ) const override { |
| 12886 | return Detail::make_unique<T>( config ); |
| 12887 | } |
| 12888 | |
| 12889 | StringRef getName() const override { |
| 12890 | return m_listenerName; |
| 12891 | } |
| 12892 | |
| 12893 | std::string getDescription() const override { |
| 12894 | return getDescriptionImpl( Detail::has_description<T>{} ); |
| 12895 | } |
| 12896 | }; |
| 12897 | |
| 12898 | public: |
| 12899 | ListenerRegistrar(StringRef listenerName) { |
| 12900 | registerListenerImpl( Detail::make_unique<TypedListenerFactory>(listenerName) ); |
| 12901 | } |
| 12902 | }; |
| 12903 | } |
| 12904 | |
| 12905 | #if !defined(CATCH_CONFIG_DISABLE) |
| 12906 | |
| 12907 | # define CATCH_REGISTER_REPORTER( name, reporterType ) \ |
| 12908 | CATCH_INTERNAL_START_WARNINGS_SUPPRESSION \ |
| 12909 | CATCH_INTERNAL_SUPPRESS_GLOBALS_WARNINGS \ |
| 12910 | namespace { \ |
| 12911 | Catch::ReporterRegistrar<reporterType> INTERNAL_CATCH_UNIQUE_NAME( \ |
| 12912 | catch_internal_RegistrarFor )( name ); \ |
| 12913 | } \ |
| 12914 | CATCH_INTERNAL_STOP_WARNINGS_SUPPRESSION |
| 12915 | |
| 12916 | # define CATCH_REGISTER_LISTENER( listenerType ) \ |
| 12917 | CATCH_INTERNAL_START_WARNINGS_SUPPRESSION \ |
| 12918 | CATCH_INTERNAL_SUPPRESS_GLOBALS_WARNINGS \ |
| 12919 | namespace { \ |
| 12920 | Catch::ListenerRegistrar<listenerType> INTERNAL_CATCH_UNIQUE_NAME( \ |
| 12921 | catch_internal_RegistrarFor )( #listenerType##_catch_sr ); \ |
| 12922 | } \ |
| 12923 | CATCH_INTERNAL_STOP_WARNINGS_SUPPRESSION |
| 12924 | |
| 12925 | #else // CATCH_CONFIG_DISABLE |
| 12926 | |
| 12927 | #define CATCH_REGISTER_REPORTER(name, reporterType) |
| 12928 | #define CATCH_REGISTER_LISTENER(listenerType) |
| 12929 | |
| 12930 | #endif // CATCH_CONFIG_DISABLE |
| 12931 | |
| 12932 | #endif // CATCH_REPORTER_REGISTRARS_HPP_INCLUDED |
| 12933 | |
| 12934 | |
| 12935 | #ifndef CATCH_REPORTER_SONARQUBE_HPP_INCLUDED |
| 12936 | #define CATCH_REPORTER_SONARQUBE_HPP_INCLUDED |
| 12937 | |
| 12938 | |
| 12939 | |
| 12940 | namespace Catch { |
| 12941 | |
| 12942 | class SonarQubeReporter final : public CumulativeReporterBase { |
| 12943 | public: |
| 12944 | SonarQubeReporter(ReporterConfig&& config) |
| 12945 | : CumulativeReporterBase(CATCH_MOVE(config)) |
| 12946 | , xml(m_stream) { |
| 12947 | m_preferences.shouldRedirectStdOut = true; |
| 12948 | m_preferences.shouldReportAllAssertions = true; |
| 12949 | m_shouldStoreSuccesfulAssertions = false; |
| 12950 | } |
| 12951 | |
| 12952 | ~SonarQubeReporter() override = default; |
| 12953 | |
| 12954 | static std::string getDescription() { |
| 12955 | using namespace std::string_literals; |
| 12956 | return "Reports test results in the Generic Test Data SonarQube XML format"s; |
| 12957 | } |
| 12958 | |
| 12959 | void testRunStarting( TestRunInfo const& testRunInfo ) override; |
| 12960 | |
| 12961 | void testRunEndedCumulative() override { |
| 12962 | writeRun( *m_testRun ); |
| 12963 | xml.endElement(); |
| 12964 | } |
| 12965 | |
| 12966 | void writeRun( TestRunNode const& groupNode ); |
| 12967 | |
| 12968 | void writeTestFile(StringRef filename, std::vector<TestCaseNode const*> const& testCaseNodes); |
| 12969 | |
| 12970 | void writeTestCase(TestCaseNode const& testCaseNode); |
| 12971 | |
| 12972 | void writeSection(std::string const& rootName, SectionNode const& sectionNode, bool okToFail); |
| 12973 | |
| 12974 | void writeAssertions(SectionNode const& sectionNode, bool okToFail); |
| 12975 | |
| 12976 | void writeAssertion(AssertionStats const& stats, bool okToFail); |
| 12977 | |
| 12978 | private: |
| 12979 | XmlWriter xml; |
| 12980 | }; |
| 12981 | |
| 12982 | |
| 12983 | } // end namespace Catch |
| 12984 | |
| 12985 | #endif // CATCH_REPORTER_SONARQUBE_HPP_INCLUDED |
| 12986 | |
| 12987 | |
| 12988 | #ifndef CATCH_REPORTER_TAP_HPP_INCLUDED |
| 12989 | #define CATCH_REPORTER_TAP_HPP_INCLUDED |
| 12990 | |
| 12991 | |
| 12992 | namespace Catch { |
| 12993 | |
| 12994 | class TAPReporter final : public StreamingReporterBase { |
| 12995 | public: |
| 12996 | TAPReporter( ReporterConfig&& config ): |
| 12997 | StreamingReporterBase( CATCH_MOVE(config) ) { |
| 12998 | m_preferences.shouldReportAllAssertions = true; |
| 12999 | } |
| 13000 | ~TAPReporter() override = default; |
| 13001 | |
| 13002 | static std::string getDescription() { |
| 13003 | using namespace std::string_literals; |
| 13004 | return "Reports test results in TAP format, suitable for test harnesses"s; |
| 13005 | } |
| 13006 | |
| 13007 | void testRunStarting( TestRunInfo const& testInfo ) override; |
| 13008 | |
| 13009 | void noMatchingTestCases( StringRef unmatchedSpec ) override; |
| 13010 | |
| 13011 | void assertionEnded(AssertionStats const& _assertionStats) override; |
| 13012 | |
| 13013 | void testRunEnded(TestRunStats const& _testRunStats) override; |
| 13014 | |
| 13015 | private: |
| 13016 | std::size_t counter = 0; |
| 13017 | }; |
| 13018 | |
| 13019 | } // end namespace Catch |
| 13020 | |
| 13021 | #endif // CATCH_REPORTER_TAP_HPP_INCLUDED |
| 13022 | |
| 13023 | |
| 13024 | #ifndef CATCH_REPORTER_TEAMCITY_HPP_INCLUDED |
| 13025 | #define CATCH_REPORTER_TEAMCITY_HPP_INCLUDED |
| 13026 | |
| 13027 | |
| 13028 | #include <cstring> |
| 13029 | |
| 13030 | #ifdef __clang__ |
| 13031 | # pragma clang diagnostic push |
| 13032 | # pragma clang diagnostic ignored "-Wpadded" |
| 13033 | #endif |
| 13034 | |
| 13035 | namespace Catch { |
| 13036 | |
| 13037 | class TeamCityReporter final : public StreamingReporterBase { |
| 13038 | public: |
| 13039 | TeamCityReporter( ReporterConfig&& _config ) |
| 13040 | : StreamingReporterBase( CATCH_MOVE(_config) ) |
| 13041 | { |
| 13042 | m_preferences.shouldRedirectStdOut = true; |
| 13043 | } |
| 13044 | |
| 13045 | ~TeamCityReporter() override; |
| 13046 | |
| 13047 | static std::string getDescription() { |
| 13048 | using namespace std::string_literals; |
| 13049 | return "Reports test results as TeamCity service messages"s; |
| 13050 | } |
| 13051 | |
| 13052 | void testRunStarting( TestRunInfo const& groupInfo ) override; |
| 13053 | void testRunEnded( TestRunStats const& testGroupStats ) override; |
| 13054 | |
| 13055 | |
| 13056 | void assertionEnded(AssertionStats const& assertionStats) override; |
| 13057 | |
| 13058 | void sectionStarting(SectionInfo const& sectionInfo) override { |
| 13059 | m_headerPrintedForThisSection = false; |
| 13060 | StreamingReporterBase::sectionStarting( sectionInfo ); |
| 13061 | } |
| 13062 | |
| 13063 | void testCaseStarting(TestCaseInfo const& testInfo) override; |
| 13064 | |
| 13065 | void testCaseEnded(TestCaseStats const& testCaseStats) override; |
| 13066 | |
| 13067 | private: |
| 13068 | void printSectionHeader(std::ostream& os); |
| 13069 | |
| 13070 | bool m_headerPrintedForThisSection = false; |
| 13071 | Timer m_testTimer; |
| 13072 | }; |
| 13073 | |
| 13074 | } // end namespace Catch |
| 13075 | |
| 13076 | #ifdef __clang__ |
| 13077 | # pragma clang diagnostic pop |
| 13078 | #endif |
| 13079 | |
| 13080 | #endif // CATCH_REPORTER_TEAMCITY_HPP_INCLUDED |
| 13081 | |
| 13082 | |
| 13083 | #ifndef CATCH_REPORTER_XML_HPP_INCLUDED |
| 13084 | #define CATCH_REPORTER_XML_HPP_INCLUDED |
| 13085 | |
| 13086 | |
| 13087 | |
| 13088 | |
| 13089 | namespace Catch { |
| 13090 | class XmlReporter : public StreamingReporterBase { |
| 13091 | public: |
| 13092 | XmlReporter(ReporterConfig&& _config); |
| 13093 | |
| 13094 | ~XmlReporter() override; |
| 13095 | |
| 13096 | static std::string getDescription(); |
| 13097 | |
| 13098 | virtual std::string getStylesheetRef() const; |
| 13099 | |
| 13100 | void writeSourceInfo(SourceLineInfo const& sourceInfo); |
| 13101 | |
| 13102 | public: // StreamingReporterBase |
| 13103 | |
| 13104 | void testRunStarting(TestRunInfo const& testInfo) override; |
| 13105 | |
| 13106 | void testCaseStarting(TestCaseInfo const& testInfo) override; |
| 13107 | |
| 13108 | void sectionStarting(SectionInfo const& sectionInfo) override; |
| 13109 | |
| 13110 | void assertionStarting(AssertionInfo const&) override; |
| 13111 | |
| 13112 | void assertionEnded(AssertionStats const& assertionStats) override; |
| 13113 | |
| 13114 | void sectionEnded(SectionStats const& sectionStats) override; |
| 13115 | |
| 13116 | void testCaseEnded(TestCaseStats const& testCaseStats) override; |
| 13117 | |
| 13118 | void testRunEnded(TestRunStats const& testRunStats) override; |
| 13119 | |
| 13120 | void benchmarkPreparing( StringRef name ) override; |
| 13121 | void benchmarkStarting(BenchmarkInfo const&) override; |
| 13122 | void benchmarkEnded(BenchmarkStats<> const&) override; |
| 13123 | void benchmarkFailed( StringRef error ) override; |
| 13124 | |
| 13125 | void listReporters(std::vector<ReporterDescription> const& descriptions) override; |
| 13126 | void listListeners(std::vector<ListenerDescription> const& descriptions) override; |
| 13127 | void listTests(std::vector<TestCaseHandle> const& tests) override; |
| 13128 | void listTags(std::vector<TagInfo> const& tags) override; |
| 13129 | |
| 13130 | private: |
| 13131 | Timer m_testCaseTimer; |
| 13132 | XmlWriter m_xml; |
| 13133 | int m_sectionDepth = 0; |
| 13134 | }; |
| 13135 | |
| 13136 | } // end namespace Catch |
| 13137 | |
| 13138 | #endif // CATCH_REPORTER_XML_HPP_INCLUDED |
| 13139 | |
| 13140 | #endif // CATCH_REPORTERS_ALL_HPP_INCLUDED |
| 13141 | |
| 13142 | #endif // CATCH_ALL_HPP_INCLUDED |
| 13143 | #endif // CATCH_AMALGAMATED_HPP_INCLUDED |