|
|
76b11c |
From ec4b275c7dab0af781c8e2571021d4821736eef9 Mon Sep 17 00:00:00 2001
|
|
|
76b11c |
From: Michael Wallner <mike@php.net>
|
|
|
76b11c |
Date: Fri, 25 Jun 2021 08:17:53 +0200
|
|
|
76b11c |
Subject: [PATCH] fix gh issue #113
|
|
|
76b11c |
|
|
|
76b11c |
---
|
|
|
76b11c |
ChangeLog-1.1.md | 8 +
|
|
|
76b11c |
docs/source/ChangeLog-1.1.rst | 12 +
|
|
|
76b11c |
scripts/download_catch2.sh | 5 +
|
|
|
76b11c |
test/lib/catch.hpp | 548 +++++++++++++++++++++-------------
|
|
|
76b11c |
4 files changed, 368 insertions(+), 205 deletions(-)
|
|
|
76b11c |
create mode 100755 scripts/download_catch2.sh
|
|
|
76b11c |
|
|
|
76b11c |
diff --git a/test/lib/catch.hpp b/test/lib/catch.hpp
|
|
|
76b11c |
index cf1fae15..36eaeb27 100644
|
|
|
76b11c |
--- a/test/lib/catch.hpp
|
|
|
76b11c |
+++ b/test/lib/catch.hpp
|
|
|
76b11c |
@@ -1,9 +1,9 @@
|
|
|
76b11c |
/*
|
|
|
76b11c |
- * Catch v2.13.0
|
|
|
76b11c |
- * Generated: 2020-07-12 20:07:49.015950
|
|
|
76b11c |
+ * Catch v2.13.6
|
|
|
76b11c |
+ * Generated: 2021-04-16 18:23:38.044268
|
|
|
76b11c |
* ----------------------------------------------------------
|
|
|
76b11c |
* This file has been merged from multiple headers. Please don't edit it directly
|
|
|
76b11c |
- * Copyright (c) 2020 Two Blue Cubes Ltd. All rights reserved.
|
|
|
76b11c |
+ * Copyright (c) 2021 Two Blue Cubes Ltd. All rights reserved.
|
|
|
76b11c |
*
|
|
|
76b11c |
* Distributed under the Boost Software License, Version 1.0. (See accompanying
|
|
|
76b11c |
* file LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt)
|
|
|
76b11c |
@@ -15,7 +15,7 @@
|
|
|
76b11c |
|
|
|
76b11c |
#define CATCH_VERSION_MAJOR 2
|
|
|
76b11c |
#define CATCH_VERSION_MINOR 13
|
|
|
76b11c |
-#define CATCH_VERSION_PATCH 0
|
|
|
76b11c |
+#define CATCH_VERSION_PATCH 6
|
|
|
76b11c |
|
|
|
76b11c |
#ifdef __clang__
|
|
|
76b11c |
# pragma clang system_header
|
|
|
76b11c |
@@ -66,13 +66,16 @@
|
|
|
76b11c |
#if !defined(CATCH_CONFIG_IMPL_ONLY)
|
|
|
76b11c |
// start catch_platform.h
|
|
|
76b11c |
|
|
|
76b11c |
+// See e.g.:
|
|
|
76b11c |
+// https://opensource.apple.com/source/CarbonHeaders/CarbonHeaders-18.1/TargetConditionals.h.auto.html
|
|
|
76b11c |
#ifdef __APPLE__
|
|
|
76b11c |
-# include <TargetConditionals.h>
|
|
|
76b11c |
-# if TARGET_OS_OSX == 1
|
|
|
76b11c |
-# define CATCH_PLATFORM_MAC
|
|
|
76b11c |
-# elif TARGET_OS_IPHONE == 1
|
|
|
76b11c |
-# define CATCH_PLATFORM_IPHONE
|
|
|
76b11c |
-# endif
|
|
|
76b11c |
+# include <TargetConditionals.h>
|
|
|
76b11c |
+# if (defined(TARGET_OS_OSX) && TARGET_OS_OSX == 1) || \
|
|
|
76b11c |
+ (defined(TARGET_OS_MAC) && TARGET_OS_MAC == 1)
|
|
|
76b11c |
+# define CATCH_PLATFORM_MAC
|
|
|
76b11c |
+# elif (defined(TARGET_OS_IPHONE) && TARGET_OS_IPHONE == 1)
|
|
|
76b11c |
+# define CATCH_PLATFORM_IPHONE
|
|
|
76b11c |
+# endif
|
|
|
76b11c |
|
|
|
76b11c |
#elif defined(linux) || defined(__linux) || defined(__linux__)
|
|
|
76b11c |
# define CATCH_PLATFORM_LINUX
|
|
|
76b11c |
@@ -132,13 +135,9 @@ namespace Catch {
|
|
|
76b11c |
|
|
|
76b11c |
#endif
|
|
|
76b11c |
|
|
|
76b11c |
-#if defined(__cpp_lib_uncaught_exceptions)
|
|
|
76b11c |
-# define CATCH_INTERNAL_CONFIG_CPP17_UNCAUGHT_EXCEPTIONS
|
|
|
76b11c |
-#endif
|
|
|
76b11c |
-
|
|
|
76b11c |
-// We have to avoid both ICC and Clang, because they try to mask themselves
|
|
|
76b11c |
-// as gcc, and we want only GCC in this block
|
|
|
76b11c |
-#if defined(__GNUC__) && !defined(__clang__) && !defined(__ICC)
|
|
|
76b11c |
+// Only GCC compiler should be used in this block, so other compilers trying to
|
|
|
76b11c |
+// mask themselves as GCC should be ignored.
|
|
|
76b11c |
+#if defined(__GNUC__) && !defined(__clang__) && !defined(__ICC) && !defined(__CUDACC__) && !defined(__LCC__)
|
|
|
76b11c |
# define CATCH_INTERNAL_START_WARNINGS_SUPPRESSION _Pragma( "GCC diagnostic push" )
|
|
|
76b11c |
# define CATCH_INTERNAL_STOP_WARNINGS_SUPPRESSION _Pragma( "GCC diagnostic pop" )
|
|
|
76b11c |
|
|
|
76b11c |
@@ -162,7 +161,7 @@ namespace Catch {
|
|
|
76b11c |
// ```
|
|
|
76b11c |
//
|
|
|
76b11c |
// Therefore, `CATCH_INTERNAL_IGNORE_BUT_WARN` is not implemented.
|
|
|
76b11c |
-# if !defined(__ibmxl__)
|
|
|
76b11c |
+# if !defined(__ibmxl__) && !defined(__CUDACC__)
|
|
|
76b11c |
# define CATCH_INTERNAL_IGNORE_BUT_WARN(...) (void)__builtin_constant_p(__VA_ARGS__) /* NOLINT(cppcoreguidelines-pro-type-vararg, hicpp-vararg) */
|
|
|
76b11c |
# endif
|
|
|
76b11c |
|
|
|
76b11c |
@@ -244,10 +243,6 @@ namespace Catch {
|
|
|
76b11c |
# define CATCH_INTERNAL_START_WARNINGS_SUPPRESSION __pragma( warning(push) )
|
|
|
76b11c |
# define CATCH_INTERNAL_STOP_WARNINGS_SUPPRESSION __pragma( warning(pop) )
|
|
|
76b11c |
|
|
|
76b11c |
-# if _MSC_VER >= 1900 // Visual Studio 2015 or newer
|
|
|
76b11c |
-# define CATCH_INTERNAL_CONFIG_CPP17_UNCAUGHT_EXCEPTIONS
|
|
|
76b11c |
-# endif
|
|
|
76b11c |
-
|
|
|
76b11c |
// Universal Windows platform does not support SEH
|
|
|
76b11c |
// Or console colours (or console at all...)
|
|
|
76b11c |
# if defined(WINAPI_FAMILY) && (WINAPI_FAMILY == WINAPI_FAMILY_APP)
|
|
|
76b11c |
@@ -330,7 +325,10 @@ namespace Catch {
|
|
|
76b11c |
|
|
|
76b11c |
// Check if byte is available and usable
|
|
|
76b11c |
# if __has_include(<cstddef>) && defined(CATCH_CPP17_OR_GREATER)
|
|
|
76b11c |
- # define CATCH_INTERNAL_CONFIG_CPP17_BYTE
|
|
|
76b11c |
+ # include <cstddef>
|
|
|
76b11c |
+ # if __cpp_lib_byte > 0
|
|
|
76b11c |
+ # define CATCH_INTERNAL_CONFIG_CPP17_BYTE
|
|
|
76b11c |
+ # endif
|
|
|
76b11c |
# endif // __has_include(<cstddef>) && defined(CATCH_CPP17_OR_GREATER)
|
|
|
76b11c |
|
|
|
76b11c |
// Check if variant is available and usable
|
|
|
76b11c |
@@ -373,10 +371,6 @@ namespace Catch {
|
|
|
76b11c |
# define CATCH_CONFIG_CPP17_OPTIONAL
|
|
|
76b11c |
#endif
|
|
|
76b11c |
|
|
|
76b11c |
-#if defined(CATCH_INTERNAL_CONFIG_CPP17_UNCAUGHT_EXCEPTIONS) && !defined(CATCH_CONFIG_NO_CPP17_UNCAUGHT_EXCEPTIONS) && !defined(CATCH_CONFIG_CPP17_UNCAUGHT_EXCEPTIONS)
|
|
|
76b11c |
-# define CATCH_CONFIG_CPP17_UNCAUGHT_EXCEPTIONS
|
|
|
76b11c |
-#endif
|
|
|
76b11c |
-
|
|
|
76b11c |
#if defined(CATCH_INTERNAL_CONFIG_CPP17_STRING_VIEW) && !defined(CATCH_CONFIG_NO_CPP17_STRING_VIEW) && !defined(CATCH_CONFIG_CPP17_STRING_VIEW)
|
|
|
76b11c |
# define CATCH_CONFIG_CPP17_STRING_VIEW
|
|
|
76b11c |
#endif
|
|
|
76b11c |
@@ -1105,7 +1099,7 @@ struct AutoReg : NonCopyable {
|
|
|
76b11c |
int index = 0; \
|
|
|
76b11c |
constexpr char const* tmpl_types[] = {CATCH_REC_LIST(INTERNAL_CATCH_STRINGIZE_WITHOUT_PARENS, __VA_ARGS__)};\
|
|
|
76b11c |
using expander = int[];\
|
|
|
76b11c |
- (void)expander{(reg_test(Types{}, Catch::NameAndTags{ Name " - " + std::string(tmpl_types[index]), Tags } ), index++, 0)... };/* NOLINT */ \
|
|
|
76b11c |
+ (void)expander{(reg_test(Types{}, Catch::NameAndTags{ Name " - " + std::string(tmpl_types[index]), Tags } ), index++)... };/* NOLINT */ \
|
|
|
76b11c |
}\
|
|
|
76b11c |
};\
|
|
|
76b11c |
static int INTERNAL_CATCH_UNIQUE_NAME( globalRegistrar ) = [](){\
|
|
|
76b11c |
@@ -1151,7 +1145,7 @@ struct AutoReg : NonCopyable {
|
|
|
76b11c |
constexpr char const* tmpl_types[] = {CATCH_REC_LIST(INTERNAL_CATCH_STRINGIZE_WITHOUT_PARENS, INTERNAL_CATCH_REMOVE_PARENS(TmplTypes))};\
|
|
|
76b11c |
constexpr char const* types_list[] = {CATCH_REC_LIST(INTERNAL_CATCH_STRINGIZE_WITHOUT_PARENS, INTERNAL_CATCH_REMOVE_PARENS(TypesList))};\
|
|
|
76b11c |
constexpr auto num_types = sizeof(types_list) / sizeof(types_list[0]);\
|
|
|
76b11c |
- (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++, 0)... };/* NOLINT */\
|
|
|
76b11c |
+ (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 */\
|
|
|
76b11c |
} \
|
|
|
76b11c |
}; \
|
|
|
76b11c |
static int INTERNAL_CATCH_UNIQUE_NAME( globalRegistrar ) = [](){ \
|
|
|
76b11c |
@@ -1195,7 +1189,7 @@ struct AutoReg : NonCopyable {
|
|
|
76b11c |
void reg_tests() { \
|
|
|
76b11c |
int index = 0; \
|
|
|
76b11c |
using expander = int[]; \
|
|
|
76b11c |
- (void)expander{(Catch::AutoReg( Catch::makeTestInvoker( &TestFunc<Types> ), CATCH_INTERNAL_LINEINFO, Catch::StringRef(), Catch::NameAndTags{ Name " - " + std::string(INTERNAL_CATCH_STRINGIZE(TmplList)) + " - " + std::to_string(index), Tags } ), index++, 0)... };/* NOLINT */\
|
|
|
76b11c |
+ (void)expander{(Catch::AutoReg( Catch::makeTestInvoker( &TestFunc<Types> ), CATCH_INTERNAL_LINEINFO, Catch::StringRef(), Catch::NameAndTags{ Name " - " + std::string(INTERNAL_CATCH_STRINGIZE(TmplList)) + " - " + std::to_string(index), Tags } ), index++)... };/* NOLINT */\
|
|
|
76b11c |
} \
|
|
|
76b11c |
};\
|
|
|
76b11c |
static int INTERNAL_CATCH_UNIQUE_NAME( globalRegistrar ) = [](){ \
|
|
|
76b11c |
@@ -1229,7 +1223,7 @@ struct AutoReg : NonCopyable {
|
|
|
76b11c |
int index = 0; \
|
|
|
76b11c |
constexpr char const* tmpl_types[] = {CATCH_REC_LIST(INTERNAL_CATCH_STRINGIZE_WITHOUT_PARENS, __VA_ARGS__)};\
|
|
|
76b11c |
using expander = int[];\
|
|
|
76b11c |
- (void)expander{(reg_test(Types{}, #ClassName, Catch::NameAndTags{ Name " - " + std::string(tmpl_types[index]), Tags } ), index++, 0)... };/* NOLINT */ \
|
|
|
76b11c |
+ (void)expander{(reg_test(Types{}, #ClassName, Catch::NameAndTags{ Name " - " + std::string(tmpl_types[index]), Tags } ), index++)... };/* NOLINT */ \
|
|
|
76b11c |
}\
|
|
|
76b11c |
};\
|
|
|
76b11c |
static int INTERNAL_CATCH_UNIQUE_NAME( globalRegistrar ) = [](){\
|
|
|
76b11c |
@@ -1278,7 +1272,7 @@ struct AutoReg : NonCopyable {
|
|
|
76b11c |
constexpr char const* tmpl_types[] = {CATCH_REC_LIST(INTERNAL_CATCH_STRINGIZE_WITHOUT_PARENS, INTERNAL_CATCH_REMOVE_PARENS(TmplTypes))};\
|
|
|
76b11c |
constexpr char const* types_list[] = {CATCH_REC_LIST(INTERNAL_CATCH_STRINGIZE_WITHOUT_PARENS, INTERNAL_CATCH_REMOVE_PARENS(TypesList))};\
|
|
|
76b11c |
constexpr auto num_types = sizeof(types_list) / sizeof(types_list[0]);\
|
|
|
76b11c |
- (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++, 0)... };/* NOLINT */ \
|
|
|
76b11c |
+ (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 */ \
|
|
|
76b11c |
}\
|
|
|
76b11c |
};\
|
|
|
76b11c |
static int INTERNAL_CATCH_UNIQUE_NAME( globalRegistrar ) = [](){\
|
|
|
76b11c |
@@ -1325,7 +1319,7 @@ struct AutoReg : NonCopyable {
|
|
|
76b11c |
void reg_tests(){\
|
|
|
76b11c |
int index = 0;\
|
|
|
76b11c |
using expander = int[];\
|
|
|
76b11c |
- (void)expander{(Catch::AutoReg( Catch::makeTestInvoker( &TestName<Types>::test ), CATCH_INTERNAL_LINEINFO, #ClassName, Catch::NameAndTags{ Name " - " + std::string(INTERNAL_CATCH_STRINGIZE(TmplList)) + " - " + std::to_string(index), Tags } ), index++, 0)... };/* NOLINT */ \
|
|
|
76b11c |
+ (void)expander{(Catch::AutoReg( Catch::makeTestInvoker( &TestName<Types>::test ), CATCH_INTERNAL_LINEINFO, #ClassName, Catch::NameAndTags{ Name " - " + std::string(INTERNAL_CATCH_STRINGIZE(TmplList)) + " - " + std::to_string(index), Tags } ), index++)... };/* NOLINT */ \
|
|
|
76b11c |
}\
|
|
|
76b11c |
};\
|
|
|
76b11c |
static int INTERNAL_CATCH_UNIQUE_NAME( globalRegistrar ) = [](){\
|
|
|
76b11c |
@@ -1829,8 +1823,8 @@ namespace Catch {
|
|
|
76b11c |
#endif
|
|
|
76b11c |
|
|
|
76b11c |
namespace Detail {
|
|
|
76b11c |
- template<typename InputIterator>
|
|
|
76b11c |
- std::string rangeToString(InputIterator first, InputIterator last) {
|
|
|
76b11c |
+ template<typename InputIterator, typename Sentinel = InputIterator>
|
|
|
76b11c |
+ std::string rangeToString(InputIterator first, Sentinel last) {
|
|
|
76b11c |
ReusableStringStream rss;
|
|
|
76b11c |
rss << "{ ";
|
|
|
76b11c |
if (first != last) {
|
|
|
76b11c |
@@ -7063,8 +7057,8 @@ namespace Catch {
|
|
|
76b11c |
double b2 = bias - z1;
|
|
|
76b11c |
double a1 = a(b1);
|
|
|
76b11c |
double a2 = a(b2);
|
|
|
76b11c |
- auto lo = std::max(cumn(a1), 0);
|
|
|
76b11c |
- auto hi = std::min(cumn(a2), n - 1);
|
|
|
76b11c |
+ auto lo = (std::max)(cumn(a1), 0);
|
|
|
76b11c |
+ auto hi = (std::min)(cumn(a2), n - 1);
|
|
|
76b11c |
|
|
|
76b11c |
return { point, resample[lo], resample[hi], confidence_level };
|
|
|
76b11c |
}
|
|
|
76b11c |
@@ -7133,7 +7127,9 @@ namespace Catch {
|
|
|
76b11c |
}
|
|
|
76b11c |
template <typename Clock>
|
|
|
76b11c |
EnvironmentEstimate<FloatDuration<Clock>> estimate_clock_cost(FloatDuration<Clock> resolution) {
|
|
|
76b11c |
- auto time_limit = std::min(resolution * clock_cost_estimation_tick_limit, FloatDuration<Clock>(clock_cost_estimation_time_limit));
|
|
|
76b11c |
+ auto time_limit = (std::min)(
|
|
|
76b11c |
+ resolution * clock_cost_estimation_tick_limit,
|
|
|
76b11c |
+ FloatDuration<Clock>(clock_cost_estimation_time_limit));
|
|
|
76b11c |
auto time_clock = [](int k) {
|
|
|
76b11c |
return Detail::measure<Clock>([k] {
|
|
|
76b11c |
for (int i = 0; i < k; ++i) {
|
|
|
76b11c |
@@ -7611,6 +7607,10 @@ namespace TestCaseTracking {
|
|
|
76b11c |
|
|
|
76b11c |
void addInitialFilters( std::vector<std::string> const& filters );
|
|
|
76b11c |
void addNextFilters( std::vector<std::string> const& filters );
|
|
|
76b11c |
+ //! Returns filters active in this tracker
|
|
|
76b11c |
+ std::vector<std::string> const& getFilters() const;
|
|
|
76b11c |
+ //! Returns whitespace-trimmed name of the tracked section
|
|
|
76b11c |
+ std::string const& trimmedName() const;
|
|
|
76b11c |
};
|
|
|
76b11c |
|
|
|
76b11c |
} // namespace TestCaseTracking
|
|
|
76b11c |
@@ -7776,7 +7776,7 @@ namespace Catch {
|
|
|
76b11c |
double sb = stddev.point;
|
|
|
76b11c |
double mn = mean.point / n;
|
|
|
76b11c |
double mg_min = mn / 2.;
|
|
|
76b11c |
- double sg = std::min(mg_min / 4., sb / std::sqrt(n));
|
|
|
76b11c |
+ double sg = (std::min)(mg_min / 4., sb / std::sqrt(n));
|
|
|
76b11c |
double sg2 = sg * sg;
|
|
|
76b11c |
double sb2 = sb * sb;
|
|
|
76b11c |
|
|
|
76b11c |
@@ -7795,7 +7795,7 @@ namespace Catch {
|
|
|
76b11c |
return (nc / n) * (sb2 - nc * sg2);
|
|
|
76b11c |
};
|
|
|
76b11c |
|
|
|
76b11c |
- return std::min(var_out(1), var_out(std::min(c_max(0.), c_max(mg_min)))) / sb2;
|
|
|
76b11c |
+ return (std::min)(var_out(1), var_out((std::min)(c_max(0.), c_max(mg_min)))) / sb2;
|
|
|
76b11c |
}
|
|
|
76b11c |
|
|
|
76b11c |
bootstrap_analysis analyse_samples(double confidence_level, int n_resamples, std::vector<double>::iterator first, std::vector<double>::iterator last) {
|
|
|
76b11c |
@@ -7985,86 +7985,58 @@ namespace Catch {
|
|
|
76b11c |
|
|
|
76b11c |
// start catch_fatal_condition.h
|
|
|
76b11c |
|
|
|
76b11c |
-// start catch_windows_h_proxy.h
|
|
|
76b11c |
-
|
|
|
76b11c |
-
|
|
|
76b11c |
-#if defined(CATCH_PLATFORM_WINDOWS)
|
|
|
76b11c |
-
|
|
|
76b11c |
-#if !defined(NOMINMAX) && !defined(CATCH_CONFIG_NO_NOMINMAX)
|
|
|
76b11c |
-# define CATCH_DEFINED_NOMINMAX
|
|
|
76b11c |
-# define NOMINMAX
|
|
|
76b11c |
-#endif
|
|
|
76b11c |
-#if !defined(WIN32_LEAN_AND_MEAN) && !defined(CATCH_CONFIG_NO_WIN32_LEAN_AND_MEAN)
|
|
|
76b11c |
-# define CATCH_DEFINED_WIN32_LEAN_AND_MEAN
|
|
|
76b11c |
-# define WIN32_LEAN_AND_MEAN
|
|
|
76b11c |
-#endif
|
|
|
76b11c |
-
|
|
|
76b11c |
-#ifdef __AFXDLL
|
|
|
76b11c |
-#include <AfxWin.h>
|
|
|
76b11c |
-#else
|
|
|
76b11c |
-#include <windows.h>
|
|
|
76b11c |
-#endif
|
|
|
76b11c |
-
|
|
|
76b11c |
-#ifdef CATCH_DEFINED_NOMINMAX
|
|
|
76b11c |
-# undef NOMINMAX
|
|
|
76b11c |
-#endif
|
|
|
76b11c |
-#ifdef CATCH_DEFINED_WIN32_LEAN_AND_MEAN
|
|
|
76b11c |
-# undef WIN32_LEAN_AND_MEAN
|
|
|
76b11c |
-#endif
|
|
|
76b11c |
-
|
|
|
76b11c |
-#endif // defined(CATCH_PLATFORM_WINDOWS)
|
|
|
76b11c |
-
|
|
|
76b11c |
-// end catch_windows_h_proxy.h
|
|
|
76b11c |
-#if defined( CATCH_CONFIG_WINDOWS_SEH )
|
|
|
76b11c |
+#include <cassert>
|
|
|
76b11c |
|
|
|
76b11c |
namespace Catch {
|
|
|
76b11c |
|
|
|
76b11c |
- struct FatalConditionHandler {
|
|
|
76b11c |
-
|
|
|
76b11c |
- static LONG CALLBACK handleVectoredException(PEXCEPTION_POINTERS ExceptionInfo);
|
|
|
76b11c |
+ // Wrapper for platform-specific fatal error (signals/SEH) handlers
|
|
|
76b11c |
+ //
|
|
|
76b11c |
+ // Tries to be cooperative with other handlers, and not step over
|
|
|
76b11c |
+ // other handlers. This means that unknown structured exceptions
|
|
|
76b11c |
+ // are passed on, previous signal handlers are called, and so on.
|
|
|
76b11c |
+ //
|
|
|
76b11c |
+ // Can only be instantiated once, and assumes that once a signal
|
|
|
76b11c |
+ // is caught, the binary will end up terminating. Thus, there
|
|
|
76b11c |
+ class FatalConditionHandler {
|
|
|
76b11c |
+ bool m_started = false;
|
|
|
76b11c |
+
|
|
|
76b11c |
+ // Install/disengage implementation for specific platform.
|
|
|
76b11c |
+ // Should be if-defed to work on current platform, can assume
|
|
|
76b11c |
+ // engage-disengage 1:1 pairing.
|
|
|
76b11c |
+ void engage_platform();
|
|
|
76b11c |
+ void disengage_platform();
|
|
|
76b11c |
+ public:
|
|
|
76b11c |
+ // Should also have platform-specific implementations as needed
|
|
|
76b11c |
FatalConditionHandler();
|
|
|
76b11c |
- static void reset();
|
|
|
76b11c |
~FatalConditionHandler();
|
|
|
76b11c |
|
|
|
76b11c |
- private:
|
|
|
76b11c |
- static bool isSet;
|
|
|
76b11c |
- static ULONG guaranteeSize;
|
|
|
76b11c |
- static PVOID exceptionHandlerHandle;
|
|
|
76b11c |
- };
|
|
|
76b11c |
-
|
|
|
76b11c |
-} // namespace Catch
|
|
|
76b11c |
-
|
|
|
76b11c |
-#elif defined ( CATCH_CONFIG_POSIX_SIGNALS )
|
|
|
76b11c |
-
|
|
|
76b11c |
-#include <signal.h>
|
|
|
76b11c |
-
|
|
|
76b11c |
-namespace Catch {
|
|
|
76b11c |
-
|
|
|
76b11c |
- struct FatalConditionHandler {
|
|
|
76b11c |
-
|
|
|
76b11c |
- static bool isSet;
|
|
|
76b11c |
- static struct sigaction oldSigActions[];
|
|
|
76b11c |
- static stack_t oldSigStack;
|
|
|
76b11c |
- static char altStackMem[];
|
|
|
76b11c |
-
|
|
|
76b11c |
- static void handleSignal( int sig );
|
|
|
76b11c |
+ void engage() {
|
|
|
76b11c |
+ assert(!m_started && "Handler cannot be installed twice.");
|
|
|
76b11c |
+ m_started = true;
|
|
|
76b11c |
+ engage_platform();
|
|
|
76b11c |
+ }
|
|
|
76b11c |
|
|
|
76b11c |
- FatalConditionHandler();
|
|
|
76b11c |
- ~FatalConditionHandler();
|
|
|
76b11c |
- static void reset();
|
|
|
76b11c |
+ void disengage() {
|
|
|
76b11c |
+ assert(m_started && "Handler cannot be uninstalled without being installed first");
|
|
|
76b11c |
+ m_started = false;
|
|
|
76b11c |
+ disengage_platform();
|
|
|
76b11c |
+ }
|
|
|
76b11c |
};
|
|
|
76b11c |
|
|
|
76b11c |
-} // namespace Catch
|
|
|
76b11c |
-
|
|
|
76b11c |
-#else
|
|
|
76b11c |
-
|
|
|
76b11c |
-namespace Catch {
|
|
|
76b11c |
- struct FatalConditionHandler {
|
|
|
76b11c |
- void reset();
|
|
|
76b11c |
+ //! Simple RAII guard for (dis)engaging the FatalConditionHandler
|
|
|
76b11c |
+ class FatalConditionHandlerGuard {
|
|
|
76b11c |
+ FatalConditionHandler* m_handler;
|
|
|
76b11c |
+ public:
|
|
|
76b11c |
+ FatalConditionHandlerGuard(FatalConditionHandler* handler):
|
|
|
76b11c |
+ m_handler(handler) {
|
|
|
76b11c |
+ m_handler->engage();
|
|
|
76b11c |
+ }
|
|
|
76b11c |
+ ~FatalConditionHandlerGuard() {
|
|
|
76b11c |
+ m_handler->disengage();
|
|
|
76b11c |
+ }
|
|
|
76b11c |
};
|
|
|
76b11c |
-}
|
|
|
76b11c |
|
|
|
76b11c |
-#endif
|
|
|
76b11c |
+} // end namespace Catch
|
|
|
76b11c |
|
|
|
76b11c |
// end catch_fatal_condition.h
|
|
|
76b11c |
#include <string>
|
|
|
76b11c |
@@ -8190,6 +8162,7 @@ namespace Catch {
|
|
|
76b11c |
std::vector<SectionEndInfo> m_unfinishedSections;
|
|
|
76b11c |
std::vector<ITracker*> m_activeSections;
|
|
|
76b11c |
TrackerContext m_trackerContext;
|
|
|
76b11c |
+ FatalConditionHandler m_fatalConditionhandler;
|
|
|
76b11c |
bool m_lastAssertionPassed = false;
|
|
|
76b11c |
bool m_shouldReportUnexpected = true;
|
|
|
76b11c |
bool m_includeSuccessfulResults;
|
|
|
76b11c |
@@ -10062,6 +10035,36 @@ namespace Catch {
|
|
|
76b11c |
}
|
|
|
76b11c |
|
|
|
76b11c |
// end catch_errno_guard.h
|
|
|
76b11c |
+// start catch_windows_h_proxy.h
|
|
|
76b11c |
+
|
|
|
76b11c |
+
|
|
|
76b11c |
+#if defined(CATCH_PLATFORM_WINDOWS)
|
|
|
76b11c |
+
|
|
|
76b11c |
+#if !defined(NOMINMAX) && !defined(CATCH_CONFIG_NO_NOMINMAX)
|
|
|
76b11c |
+# define CATCH_DEFINED_NOMINMAX
|
|
|
76b11c |
+# define NOMINMAX
|
|
|
76b11c |
+#endif
|
|
|
76b11c |
+#if !defined(WIN32_LEAN_AND_MEAN) && !defined(CATCH_CONFIG_NO_WIN32_LEAN_AND_MEAN)
|
|
|
76b11c |
+# define CATCH_DEFINED_WIN32_LEAN_AND_MEAN
|
|
|
76b11c |
+# define WIN32_LEAN_AND_MEAN
|
|
|
76b11c |
+#endif
|
|
|
76b11c |
+
|
|
|
76b11c |
+#ifdef __AFXDLL
|
|
|
76b11c |
+#include <AfxWin.h>
|
|
|
76b11c |
+#else
|
|
|
76b11c |
+#include <windows.h>
|
|
|
76b11c |
+#endif
|
|
|
76b11c |
+
|
|
|
76b11c |
+#ifdef CATCH_DEFINED_NOMINMAX
|
|
|
76b11c |
+# undef NOMINMAX
|
|
|
76b11c |
+#endif
|
|
|
76b11c |
+#ifdef CATCH_DEFINED_WIN32_LEAN_AND_MEAN
|
|
|
76b11c |
+# undef WIN32_LEAN_AND_MEAN
|
|
|
76b11c |
+#endif
|
|
|
76b11c |
+
|
|
|
76b11c |
+#endif // defined(CATCH_PLATFORM_WINDOWS)
|
|
|
76b11c |
+
|
|
|
76b11c |
+// end catch_windows_h_proxy.h
|
|
|
76b11c |
#include <sstream>
|
|
|
76b11c |
|
|
|
76b11c |
namespace Catch {
|
|
|
76b11c |
@@ -10578,7 +10581,7 @@ namespace Catch {
|
|
|
76b11c |
// Extracts the actual name part of an enum instance
|
|
|
76b11c |
// In other words, it returns the Blue part of Bikeshed::Colour::Blue
|
|
|
76b11c |
StringRef extractInstanceName(StringRef enumInstance) {
|
|
|
76b11c |
- // Find last occurence of ":"
|
|
|
76b11c |
+ // Find last occurrence of ":"
|
|
|
76b11c |
size_t name_start = enumInstance.size();
|
|
|
76b11c |
while (name_start > 0 && enumInstance[name_start - 1] != ':') {
|
|
|
76b11c |
--name_start;
|
|
|
76b11c |
@@ -10740,25 +10743,47 @@ namespace Catch {
|
|
|
76b11c |
// end catch_exception_translator_registry.cpp
|
|
|
76b11c |
// start catch_fatal_condition.cpp
|
|
|
76b11c |
|
|
|
76b11c |
-#if defined(__GNUC__)
|
|
|
76b11c |
-# pragma GCC diagnostic push
|
|
|
76b11c |
-# pragma GCC diagnostic ignored "-Wmissing-field-initializers"
|
|
|
76b11c |
-#endif
|
|
|
76b11c |
+#include <algorithm>
|
|
|
76b11c |
+
|
|
|
76b11c |
+#if !defined( CATCH_CONFIG_WINDOWS_SEH ) && !defined( CATCH_CONFIG_POSIX_SIGNALS )
|
|
|
76b11c |
+
|
|
|
76b11c |
+namespace Catch {
|
|
|
76b11c |
+
|
|
|
76b11c |
+ // If neither SEH nor signal handling is required, the handler impls
|
|
|
76b11c |
+ // do not have to do anything, and can be empty.
|
|
|
76b11c |
+ void FatalConditionHandler::engage_platform() {}
|
|
|
76b11c |
+ void FatalConditionHandler::disengage_platform() {}
|
|
|
76b11c |
+ FatalConditionHandler::FatalConditionHandler() = default;
|
|
|
76b11c |
+ FatalConditionHandler::~FatalConditionHandler() = default;
|
|
|
76b11c |
+
|
|
|
76b11c |
+} // end namespace Catch
|
|
|
76b11c |
+
|
|
|
76b11c |
+#endif // !CATCH_CONFIG_WINDOWS_SEH && !CATCH_CONFIG_POSIX_SIGNALS
|
|
|
76b11c |
+
|
|
|
76b11c |
+#if defined( CATCH_CONFIG_WINDOWS_SEH ) && defined( CATCH_CONFIG_POSIX_SIGNALS )
|
|
|
76b11c |
+#error "Inconsistent configuration: Windows' SEH handling and POSIX signals cannot be enabled at the same time"
|
|
|
76b11c |
+#endif // CATCH_CONFIG_WINDOWS_SEH && CATCH_CONFIG_POSIX_SIGNALS
|
|
|
76b11c |
|
|
|
76b11c |
#if defined( CATCH_CONFIG_WINDOWS_SEH ) || defined( CATCH_CONFIG_POSIX_SIGNALS )
|
|
|
76b11c |
|
|
|
76b11c |
namespace {
|
|
|
76b11c |
- // Report the error condition
|
|
|
76b11c |
+ //! Signals fatal error message to the run context
|
|
|
76b11c |
void reportFatal( char const * const message ) {
|
|
|
76b11c |
Catch::getCurrentContext().getResultCapture()->handleFatalErrorCondition( message );
|
|
|
76b11c |
}
|
|
|
76b11c |
-}
|
|
|
76b11c |
|
|
|
76b11c |
-#endif // signals/SEH handling
|
|
|
76b11c |
+ //! Minimal size Catch2 needs for its own fatal error handling.
|
|
|
76b11c |
+ //! Picked anecdotally, so it might not be sufficient on all
|
|
|
76b11c |
+ //! platforms, and for all configurations.
|
|
|
76b11c |
+ constexpr std::size_t minStackSizeForErrors = 32 * 1024;
|
|
|
76b11c |
+} // end unnamed namespace
|
|
|
76b11c |
+
|
|
|
76b11c |
+#endif // CATCH_CONFIG_WINDOWS_SEH || CATCH_CONFIG_POSIX_SIGNALS
|
|
|
76b11c |
|
|
|
76b11c |
#if defined( CATCH_CONFIG_WINDOWS_SEH )
|
|
|
76b11c |
|
|
|
76b11c |
namespace Catch {
|
|
|
76b11c |
+
|
|
|
76b11c |
struct SignalDefs { DWORD id; const char* name; };
|
|
|
76b11c |
|
|
|
76b11c |
// There is no 1-1 mapping between signals and windows exceptions.
|
|
|
76b11c |
@@ -10771,7 +10796,7 @@ namespace Catch {
|
|
|
76b11c |
{ static_cast<DWORD>(EXCEPTION_INT_DIVIDE_BY_ZERO), "Divide by zero error" },
|
|
|
76b11c |
};
|
|
|
76b11c |
|
|
|
76b11c |
- LONG CALLBACK FatalConditionHandler::handleVectoredException(PEXCEPTION_POINTERS ExceptionInfo) {
|
|
|
76b11c |
+ static LONG CALLBACK handleVectoredException(PEXCEPTION_POINTERS ExceptionInfo) {
|
|
|
76b11c |
for (auto const& def : signalDefs) {
|
|
|
76b11c |
if (ExceptionInfo->ExceptionRecord->ExceptionCode == def.id) {
|
|
|
76b11c |
reportFatal(def.name);
|
|
|
76b11c |
@@ -10782,38 +10807,50 @@ namespace Catch {
|
|
|
76b11c |
return EXCEPTION_CONTINUE_SEARCH;
|
|
|
76b11c |
}
|
|
|
76b11c |
|
|
|
76b11c |
+ // Since we do not support multiple instantiations, we put these
|
|
|
76b11c |
+ // into global variables and rely on cleaning them up in outlined
|
|
|
76b11c |
+ // constructors/destructors
|
|
|
76b11c |
+ static PVOID exceptionHandlerHandle = nullptr;
|
|
|
76b11c |
+
|
|
|
76b11c |
+ // For MSVC, we reserve part of the stack memory for handling
|
|
|
76b11c |
+ // memory overflow structured exception.
|
|
|
76b11c |
FatalConditionHandler::FatalConditionHandler() {
|
|
|
76b11c |
- isSet = true;
|
|
|
76b11c |
- // 32k seems enough for Catch to handle stack overflow,
|
|
|
76b11c |
- // but the value was found experimentally, so there is no strong guarantee
|
|
|
76b11c |
- guaranteeSize = 32 * 1024;
|
|
|
76b11c |
- exceptionHandlerHandle = nullptr;
|
|
|
76b11c |
+ ULONG guaranteeSize = static_cast<ULONG>(minStackSizeForErrors);
|
|
|
76b11c |
+ if (!SetThreadStackGuarantee(&guaranteeSize)) {
|
|
|
76b11c |
+ // We do not want to fully error out, because needing
|
|
|
76b11c |
+ // the stack reserve should be rare enough anyway.
|
|
|
76b11c |
+ Catch::cerr()
|
|
|
76b11c |
+ << "Failed to reserve piece of stack."
|
|
|
76b11c |
+ << " Stack overflows will not be reported successfully.";
|
|
|
76b11c |
+ }
|
|
|
76b11c |
+ }
|
|
|
76b11c |
+
|
|
|
76b11c |
+ // We do not attempt to unset the stack guarantee, because
|
|
|
76b11c |
+ // Windows does not support lowering the stack size guarantee.
|
|
|
76b11c |
+ FatalConditionHandler::~FatalConditionHandler() = default;
|
|
|
76b11c |
+
|
|
|
76b11c |
+ void FatalConditionHandler::engage_platform() {
|
|
|
76b11c |
// Register as first handler in current chain
|
|
|
76b11c |
exceptionHandlerHandle = AddVectoredExceptionHandler(1, handleVectoredException);
|
|
|
76b11c |
- // Pass in guarantee size to be filled
|
|
|
76b11c |
- SetThreadStackGuarantee(&guaranteeSize);
|
|
|
76b11c |
+ if (!exceptionHandlerHandle) {
|
|
|
76b11c |
+ CATCH_RUNTIME_ERROR("Could not register vectored exception handler");
|
|
|
76b11c |
+ }
|
|
|
76b11c |
}
|
|
|
76b11c |
|
|
|
76b11c |
- void FatalConditionHandler::reset() {
|
|
|
76b11c |
- if (isSet) {
|
|
|
76b11c |
- RemoveVectoredExceptionHandler(exceptionHandlerHandle);
|
|
|
76b11c |
- SetThreadStackGuarantee(&guaranteeSize);
|
|
|
76b11c |
- exceptionHandlerHandle = nullptr;
|
|
|
76b11c |
- isSet = false;
|
|
|
76b11c |
+ void FatalConditionHandler::disengage_platform() {
|
|
|
76b11c |
+ if (!RemoveVectoredExceptionHandler(exceptionHandlerHandle)) {
|
|
|
76b11c |
+ CATCH_RUNTIME_ERROR("Could not unregister vectored exception handler");
|
|
|
76b11c |
}
|
|
|
76b11c |
+ exceptionHandlerHandle = nullptr;
|
|
|
76b11c |
}
|
|
|
76b11c |
|
|
|
76b11c |
- FatalConditionHandler::~FatalConditionHandler() {
|
|
|
76b11c |
- reset();
|
|
|
76b11c |
- }
|
|
|
76b11c |
+} // end namespace Catch
|
|
|
76b11c |
|
|
|
76b11c |
-bool FatalConditionHandler::isSet = false;
|
|
|
76b11c |
-ULONG FatalConditionHandler::guaranteeSize = 0;
|
|
|
76b11c |
-PVOID FatalConditionHandler::exceptionHandlerHandle = nullptr;
|
|
|
76b11c |
+#endif // CATCH_CONFIG_WINDOWS_SEH
|
|
|
76b11c |
|
|
|
76b11c |
-} // namespace Catch
|
|
|
76b11c |
+#if defined( CATCH_CONFIG_POSIX_SIGNALS )
|
|
|
76b11c |
|
|
|
76b11c |
-#elif defined( CATCH_CONFIG_POSIX_SIGNALS )
|
|
|
76b11c |
+#include <signal.h>
|
|
|
76b11c |
|
|
|
76b11c |
namespace Catch {
|
|
|
76b11c |
|
|
|
76b11c |
@@ -10822,10 +10859,6 @@ namespace Catch {
|
|
|
76b11c |
const char* name;
|
|
|
76b11c |
};
|
|
|
76b11c |
|
|
|
76b11c |
- // 32kb for the alternate stack seems to be sufficient. However, this value
|
|
|
76b11c |
- // is experimentally determined, so that's not guaranteed.
|
|
|
76b11c |
- static constexpr std::size_t sigStackSize = 32768 >= MINSIGSTKSZ ? 32768 : MINSIGSTKSZ;
|
|
|
76b11c |
-
|
|
|
76b11c |
static SignalDefs signalDefs[] = {
|
|
|
76b11c |
{ SIGINT, "SIGINT - Terminal interrupt signal" },
|
|
|
76b11c |
{ SIGILL, "SIGILL - Illegal instruction signal" },
|
|
|
76b11c |
@@ -10835,7 +10868,32 @@ namespace Catch {
|
|
|
76b11c |
{ SIGABRT, "SIGABRT - Abort (abnormal termination) signal" }
|
|
|
76b11c |
};
|
|
|
76b11c |
|
|
|
76b11c |
- void FatalConditionHandler::handleSignal( int sig ) {
|
|
|
76b11c |
+// Older GCCs trigger -Wmissing-field-initializers for T foo = {}
|
|
|
76b11c |
+// which is zero initialization, but not explicit. We want to avoid
|
|
|
76b11c |
+// that.
|
|
|
76b11c |
+#if defined(__GNUC__)
|
|
|
76b11c |
+# pragma GCC diagnostic push
|
|
|
76b11c |
+# pragma GCC diagnostic ignored "-Wmissing-field-initializers"
|
|
|
76b11c |
+#endif
|
|
|
76b11c |
+
|
|
|
76b11c |
+ static char* altStackMem = nullptr;
|
|
|
76b11c |
+ static std::size_t altStackSize = 0;
|
|
|
76b11c |
+ static stack_t oldSigStack{};
|
|
|
76b11c |
+ static struct sigaction oldSigActions[sizeof(signalDefs) / sizeof(SignalDefs)]{};
|
|
|
76b11c |
+
|
|
|
76b11c |
+ static void restorePreviousSignalHandlers() {
|
|
|
76b11c |
+ // We set signal handlers back to the previous ones. Hopefully
|
|
|
76b11c |
+ // nobody overwrote them in the meantime, and doesn't expect
|
|
|
76b11c |
+ // their signal handlers to live past ours given that they
|
|
|
76b11c |
+ // installed them after ours..
|
|
|
76b11c |
+ for (std::size_t i = 0; i < sizeof(signalDefs) / sizeof(SignalDefs); ++i) {
|
|
|
76b11c |
+ sigaction(signalDefs[i].id, &oldSigActions[i], nullptr);
|
|
|
76b11c |
+ }
|
|
|
76b11c |
+ // Return the old stack
|
|
|
76b11c |
+ sigaltstack(&oldSigStack, nullptr);
|
|
|
76b11c |
+ }
|
|
|
76b11c |
+
|
|
|
76b11c |
+ static void handleSignal( int sig ) {
|
|
|
76b11c |
char const * name = "<unknown signal>";
|
|
|
76b11c |
for (auto const& def : signalDefs) {
|
|
|
76b11c |
if (sig == def.id) {
|
|
|
76b11c |
@@ -10843,16 +10901,33 @@ namespace Catch {
|
|
|
76b11c |
break;
|
|
|
76b11c |
}
|
|
|
76b11c |
}
|
|
|
76b11c |
- reset();
|
|
|
76b11c |
- reportFatal(name);
|
|
|
76b11c |
+ // We need to restore previous signal handlers and let them do
|
|
|
76b11c |
+ // their thing, so that the users can have the debugger break
|
|
|
76b11c |
+ // when a signal is raised, and so on.
|
|
|
76b11c |
+ restorePreviousSignalHandlers();
|
|
|
76b11c |
+ reportFatal( name );
|
|
|
76b11c |
raise( sig );
|
|
|
76b11c |
}
|
|
|
76b11c |
|
|
|
76b11c |
FatalConditionHandler::FatalConditionHandler() {
|
|
|
76b11c |
- isSet = true;
|
|
|
76b11c |
+ assert(!altStackMem && "Cannot initialize POSIX signal handler when one already exists");
|
|
|
76b11c |
+ if (altStackSize == 0) {
|
|
|
76b11c |
+ altStackSize = std::max(static_cast<size_t>(SIGSTKSZ), minStackSizeForErrors);
|
|
|
76b11c |
+ }
|
|
|
76b11c |
+ altStackMem = new char[altStackSize]();
|
|
|
76b11c |
+ }
|
|
|
76b11c |
+
|
|
|
76b11c |
+ FatalConditionHandler::~FatalConditionHandler() {
|
|
|
76b11c |
+ delete[] altStackMem;
|
|
|
76b11c |
+ // We signal that another instance can be constructed by zeroing
|
|
|
76b11c |
+ // out the pointer.
|
|
|
76b11c |
+ altStackMem = nullptr;
|
|
|
76b11c |
+ }
|
|
|
76b11c |
+
|
|
|
76b11c |
+ void FatalConditionHandler::engage_platform() {
|
|
|
76b11c |
stack_t sigStack;
|
|
|
76b11c |
sigStack.ss_sp = altStackMem;
|
|
|
76b11c |
- sigStack.ss_size = sigStackSize;
|
|
|
76b11c |
+ sigStack.ss_size = altStackSize;
|
|
|
76b11c |
sigStack.ss_flags = 0;
|
|
|
76b11c |
sigaltstack(&sigStack, &oldSigStack);
|
|
|
76b11c |
struct sigaction sa = { };
|
|
|
76b11c |
@@ -10864,40 +10939,17 @@ namespace Catch {
|
|
|
76b11c |
}
|
|
|
76b11c |
}
|
|
|
76b11c |
|
|
|
76b11c |
- FatalConditionHandler::~FatalConditionHandler() {
|
|
|
76b11c |
- reset();
|
|
|
76b11c |
- }
|
|
|
76b11c |
+#if defined(__GNUC__)
|
|
|
76b11c |
+# pragma GCC diagnostic pop
|
|
|
76b11c |
+#endif
|
|
|
76b11c |
|
|
|
76b11c |
- void FatalConditionHandler::reset() {
|
|
|
76b11c |
- if( isSet ) {
|
|
|
76b11c |
- // Set signals back to previous values -- hopefully nobody overwrote them in the meantime
|
|
|
76b11c |
- for( std::size_t i = 0; i < sizeof(signalDefs)/sizeof(SignalDefs); ++i ) {
|
|
|
76b11c |
- sigaction(signalDefs[i].id, &oldSigActions[i], nullptr);
|
|
|
76b11c |
- }
|
|
|
76b11c |
- // Return the old stack
|
|
|
76b11c |
- sigaltstack(&oldSigStack, nullptr);
|
|
|
76b11c |
- isSet = false;
|
|
|
76b11c |
- }
|
|
|
76b11c |
+ void FatalConditionHandler::disengage_platform() {
|
|
|
76b11c |
+ restorePreviousSignalHandlers();
|
|
|
76b11c |
}
|
|
|
76b11c |
|
|
|
76b11c |
- bool FatalConditionHandler::isSet = false;
|
|
|
76b11c |
- struct sigaction FatalConditionHandler::oldSigActions[sizeof(signalDefs)/sizeof(SignalDefs)] = {};
|
|
|
76b11c |
- stack_t FatalConditionHandler::oldSigStack = {};
|
|
|
76b11c |
- char FatalConditionHandler::altStackMem[sigStackSize] = {};
|
|
|
76b11c |
-
|
|
|
76b11c |
-} // namespace Catch
|
|
|
76b11c |
-
|
|
|
76b11c |
-#else
|
|
|
76b11c |
-
|
|
|
76b11c |
-namespace Catch {
|
|
|
76b11c |
- void FatalConditionHandler::reset() {}
|
|
|
76b11c |
-}
|
|
|
76b11c |
-
|
|
|
76b11c |
-#endif // signals/SEH handling
|
|
|
76b11c |
+} // end namespace Catch
|
|
|
76b11c |
|
|
|
76b11c |
-#if defined(__GNUC__)
|
|
|
76b11c |
-# pragma GCC diagnostic pop
|
|
|
76b11c |
-#endif
|
|
|
76b11c |
+#endif // CATCH_CONFIG_POSIX_SIGNALS
|
|
|
76b11c |
// end catch_fatal_condition.cpp
|
|
|
76b11c |
// start catch_generators.cpp
|
|
|
76b11c |
|
|
|
76b11c |
@@ -11452,7 +11504,8 @@ namespace {
|
|
|
76b11c |
return lhs == rhs;
|
|
|
76b11c |
}
|
|
|
76b11c |
|
|
|
76b11c |
- auto ulpDiff = std::abs(lc - rc);
|
|
|
76b11c |
+ // static cast as a workaround for IBM XLC
|
|
|
76b11c |
+ auto ulpDiff = std::abs(static_cast<FP>(lc - rc));
|
|
|
76b11c |
return static_cast<uint64_t>(ulpDiff) <= maxUlpDiff;
|
|
|
76b11c |
}
|
|
|
76b11c |
|
|
|
76b11c |
@@ -11626,7 +11679,6 @@ Floating::WithinRelMatcher WithinRel(float target) {
|
|
|
76b11c |
|
|
|
76b11c |
} // namespace Matchers
|
|
|
76b11c |
} // namespace Catch
|
|
|
76b11c |
-
|
|
|
76b11c |
// end catch_matchers_floating.cpp
|
|
|
76b11c |
// start catch_matchers_generic.cpp
|
|
|
76b11c |
|
|
|
76b11c |
@@ -12042,7 +12094,7 @@ namespace Catch {
|
|
|
76b11c |
if (tmpnam_s(m_buffer)) {
|
|
|
76b11c |
CATCH_RUNTIME_ERROR("Could not get a temp filename");
|
|
|
76b11c |
}
|
|
|
76b11c |
- if (fopen_s(&m_file, m_buffer, "w")) {
|
|
|
76b11c |
+ if (fopen_s(&m_file, m_buffer, "w+")) {
|
|
|
76b11c |
char buffer[100];
|
|
|
76b11c |
if (strerror_s(buffer, errno)) {
|
|
|
76b11c |
CATCH_RUNTIME_ERROR("Could not translate errno to a string");
|
|
|
76b11c |
@@ -12580,13 +12632,53 @@ namespace Catch {
|
|
|
76b11c |
// `SECTION`s.
|
|
|
76b11c |
// **The check for m_children.empty cannot be removed**.
|
|
|
76b11c |
// doing so would break `GENERATE` _not_ followed by `SECTION`s.
|
|
|
76b11c |
- const bool should_wait_for_child =
|
|
|
76b11c |
- !m_children.empty() &&
|
|
|
76b11c |
- std::find_if( m_children.begin(),
|
|
|
76b11c |
- m_children.end(),
|
|
|
76b11c |
- []( TestCaseTracking::ITrackerPtr tracker ) {
|
|
|
76b11c |
- return tracker->hasStarted();
|
|
|
76b11c |
- } ) == m_children.end();
|
|
|
76b11c |
+ const bool should_wait_for_child = [&]() {
|
|
|
76b11c |
+ // No children -> nobody to wait for
|
|
|
76b11c |
+ if ( m_children.empty() ) {
|
|
|
76b11c |
+ return false;
|
|
|
76b11c |
+ }
|
|
|
76b11c |
+ // If at least one child started executing, don't wait
|
|
|
76b11c |
+ if ( std::find_if(
|
|
|
76b11c |
+ m_children.begin(),
|
|
|
76b11c |
+ m_children.end(),
|
|
|
76b11c |
+ []( TestCaseTracking::ITrackerPtr tracker ) {
|
|
|
76b11c |
+ return tracker->hasStarted();
|
|
|
76b11c |
+ } ) != m_children.end() ) {
|
|
|
76b11c |
+ return false;
|
|
|
76b11c |
+ }
|
|
|
76b11c |
+
|
|
|
76b11c |
+ // No children have started. We need to check if they _can_
|
|
|
76b11c |
+ // start, and thus we should wait for them, or they cannot
|
|
|
76b11c |
+ // start (due to filters), and we shouldn't wait for them
|
|
|
76b11c |
+ auto* parent = m_parent;
|
|
|
76b11c |
+ // This is safe: there is always at least one section
|
|
|
76b11c |
+ // tracker in a test case tracking tree
|
|
|
76b11c |
+ while ( !parent->isSectionTracker() ) {
|
|
|
76b11c |
+ parent = &( parent->parent() );
|
|
|
76b11c |
+ }
|
|
|
76b11c |
+ assert( parent &&
|
|
|
76b11c |
+ "Missing root (test case) level section" );
|
|
|
76b11c |
+
|
|
|
76b11c |
+ auto const& parentSection =
|
|
|
76b11c |
+ static_cast<SectionTracker&>( *parent );
|
|
|
76b11c |
+ auto const& filters = parentSection.getFilters();
|
|
|
76b11c |
+ // No filters -> no restrictions on running sections
|
|
|
76b11c |
+ if ( filters.empty() ) {
|
|
|
76b11c |
+ return true;
|
|
|
76b11c |
+ }
|
|
|
76b11c |
+
|
|
|
76b11c |
+ for ( auto const& child : m_children ) {
|
|
|
76b11c |
+ if ( child->isSectionTracker() &&
|
|
|
76b11c |
+ std::find( filters.begin(),
|
|
|
76b11c |
+ filters.end(),
|
|
|
76b11c |
+ static_cast<SectionTracker&>( *child )
|
|
|
76b11c |
+ .trimmedName() ) !=
|
|
|
76b11c |
+ filters.end() ) {
|
|
|
76b11c |
+ return true;
|
|
|
76b11c |
+ }
|
|
|
76b11c |
+ }
|
|
|
76b11c |
+ return false;
|
|
|
76b11c |
+ }();
|
|
|
76b11c |
|
|
|
76b11c |
// This check is a bit tricky, because m_generator->next()
|
|
|
76b11c |
// has a side-effect, where it consumes generator's current
|
|
|
76b11c |
@@ -12920,9 +13012,8 @@ namespace Catch {
|
|
|
76b11c |
}
|
|
|
76b11c |
|
|
|
76b11c |
void RunContext::invokeActiveTestCase() {
|
|
|
76b11c |
- FatalConditionHandler fatalConditionHandler; // Handle signals
|
|
|
76b11c |
+ FatalConditionHandlerGuard _(&m_fatalConditionhandler);
|
|
|
76b11c |
m_activeTestCase->invoke();
|
|
|
76b11c |
- fatalConditionHandler.reset();
|
|
|
76b11c |
}
|
|
|
76b11c |
|
|
|
76b11c |
void RunContext::handleUnfinishedSections() {
|
|
|
76b11c |
@@ -14091,24 +14182,28 @@ namespace Catch {
|
|
|
76b11c |
|
|
|
76b11c |
namespace {
|
|
|
76b11c |
struct TestHasher {
|
|
|
76b11c |
- explicit TestHasher(Catch::SimplePcg32& rng) {
|
|
|
76b11c |
- basis = rng();
|
|
|
76b11c |
- basis <<= 32;
|
|
|
76b11c |
- basis |= rng();
|
|
|
76b11c |
- }
|
|
|
76b11c |
+ using hash_t = uint64_t;
|
|
|
76b11c |
|
|
|
76b11c |
- uint64_t basis;
|
|
|
76b11c |
+ explicit TestHasher( hash_t hashSuffix ):
|
|
|
76b11c |
+ m_hashSuffix{ hashSuffix } {}
|
|
|
76b11c |
|
|
|
76b11c |
- uint64_t operator()(TestCase const& t) const {
|
|
|
76b11c |
- // Modified FNV-1a hash
|
|
|
76b11c |
- static constexpr uint64_t prime = 1099511628211;
|
|
|
76b11c |
- uint64_t hash = basis;
|
|
|
76b11c |
- for (const char c : t.name) {
|
|
|
76b11c |
+ uint32_t operator()( TestCase const& t ) const {
|
|
|
76b11c |
+ // FNV-1a hash with multiplication fold.
|
|
|
76b11c |
+ const hash_t prime = 1099511628211u;
|
|
|
76b11c |
+ hash_t hash = 14695981039346656037u;
|
|
|
76b11c |
+ for ( const char c : t.name ) {
|
|
|
76b11c |
hash ^= c;
|
|
|
76b11c |
hash *= prime;
|
|
|
76b11c |
}
|
|
|
76b11c |
- return hash;
|
|
|
76b11c |
+ hash ^= m_hashSuffix;
|
|
|
76b11c |
+ hash *= prime;
|
|
|
76b11c |
+ const uint32_t low{ static_cast<uint32_t>( hash ) };
|
|
|
76b11c |
+ const uint32_t high{ static_cast<uint32_t>( hash >> 32 ) };
|
|
|
76b11c |
+ return low * high;
|
|
|
76b11c |
}
|
|
|
76b11c |
+
|
|
|
76b11c |
+ private:
|
|
|
76b11c |
+ hash_t m_hashSuffix;
|
|
|
76b11c |
};
|
|
|
76b11c |
} // end unnamed namespace
|
|
|
76b11c |
|
|
|
76b11c |
@@ -14126,9 +14221,9 @@ namespace Catch {
|
|
|
76b11c |
|
|
|
76b11c |
case RunTests::InRandomOrder: {
|
|
|
76b11c |
seedRng( config );
|
|
|
76b11c |
- TestHasher h( rng() );
|
|
|
76b11c |
+ TestHasher h{ config.rngSeed() };
|
|
|
76b11c |
|
|
|
76b11c |
- using hashedTest = std::pair<uint64_t, TestCase const*>;
|
|
|
76b11c |
+ using hashedTest = std::pair<TestHasher::hash_t, TestCase const*>;
|
|
|
76b11c |
std::vector<hashedTest> indexed_tests;
|
|
|
76b11c |
indexed_tests.reserve( unsortedTestCases.size() );
|
|
|
76b11c |
|
|
|
76b11c |
@@ -14458,6 +14553,14 @@ namespace TestCaseTracking {
|
|
|
76b11c |
m_filters.insert( m_filters.end(), filters.begin()+1, filters.end() );
|
|
|
76b11c |
}
|
|
|
76b11c |
|
|
|
76b11c |
+ std::vector<std::string> const& SectionTracker::getFilters() const {
|
|
|
76b11c |
+ return m_filters;
|
|
|
76b11c |
+ }
|
|
|
76b11c |
+
|
|
|
76b11c |
+ std::string const& SectionTracker::trimmedName() const {
|
|
|
76b11c |
+ return m_trimmed_name;
|
|
|
76b11c |
+ }
|
|
|
76b11c |
+
|
|
|
76b11c |
} // namespace TestCaseTracking
|
|
|
76b11c |
|
|
|
76b11c |
using TestCaseTracking::ITracker;
|
|
|
76b11c |
@@ -15192,6 +15295,41 @@ namespace Catch {
|
|
|
76b11c |
// end catch_totals.cpp
|
|
|
76b11c |
// start catch_uncaught_exceptions.cpp
|
|
|
76b11c |
|
|
|
76b11c |
+// start catch_config_uncaught_exceptions.hpp
|
|
|
76b11c |
+
|
|
|
76b11c |
+// Copyright Catch2 Authors
|
|
|
76b11c |
+// Distributed under the Boost Software License, Version 1.0.
|
|
|
76b11c |
+// (See accompanying file LICENSE_1_0.txt or copy at
|
|
|
76b11c |
+// https://www.boost.org/LICENSE_1_0.txt)
|
|
|
76b11c |
+
|
|
|
76b11c |
+// SPDX-License-Identifier: BSL-1.0
|
|
|
76b11c |
+
|
|
|
76b11c |
+#ifndef CATCH_CONFIG_UNCAUGHT_EXCEPTIONS_HPP
|
|
|
76b11c |
+#define CATCH_CONFIG_UNCAUGHT_EXCEPTIONS_HPP
|
|
|
76b11c |
+
|
|
|
76b11c |
+#if defined(_MSC_VER)
|
|
|
76b11c |
+# if _MSC_VER >= 1900 // Visual Studio 2015 or newer
|
|
|
76b11c |
+# define CATCH_INTERNAL_CONFIG_CPP17_UNCAUGHT_EXCEPTIONS
|
|
|
76b11c |
+# endif
|
|
|
76b11c |
+#endif
|
|
|
76b11c |
+
|
|
|
76b11c |
+#include <exception>
|
|
|
76b11c |
+
|
|
|
76b11c |
+#if defined(__cpp_lib_uncaught_exceptions) \
|
|
|
76b11c |
+ && !defined(CATCH_INTERNAL_CONFIG_CPP17_UNCAUGHT_EXCEPTIONS)
|
|
|
76b11c |
+
|
|
|
76b11c |
+# define CATCH_INTERNAL_CONFIG_CPP17_UNCAUGHT_EXCEPTIONS
|
|
|
76b11c |
+#endif // __cpp_lib_uncaught_exceptions
|
|
|
76b11c |
+
|
|
|
76b11c |
+#if defined(CATCH_INTERNAL_CONFIG_CPP17_UNCAUGHT_EXCEPTIONS) \
|
|
|
76b11c |
+ && !defined(CATCH_CONFIG_NO_CPP17_UNCAUGHT_EXCEPTIONS) \
|
|
|
76b11c |
+ && !defined(CATCH_CONFIG_CPP17_UNCAUGHT_EXCEPTIONS)
|
|
|
76b11c |
+
|
|
|
76b11c |
+# define CATCH_CONFIG_CPP17_UNCAUGHT_EXCEPTIONS
|
|
|
76b11c |
+#endif
|
|
|
76b11c |
+
|
|
|
76b11c |
+#endif // CATCH_CONFIG_UNCAUGHT_EXCEPTIONS_HPP
|
|
|
76b11c |
+// end catch_config_uncaught_exceptions.hpp
|
|
|
76b11c |
#include <exception>
|
|
|
76b11c |
|
|
|
76b11c |
namespace Catch {
|
|
|
76b11c |
@@ -15238,7 +15376,7 @@ namespace Catch {
|
|
|
76b11c |
}
|
|
|
76b11c |
|
|
|
76b11c |
Version const& libraryVersion() {
|
|
|
76b11c |
- static Version version( 2, 13, 0, "", 0 );
|
|
|
76b11c |
+ static Version version( 2, 13, 6, "", 0 );
|
|
|
76b11c |
return version;
|
|
|
76b11c |
}
|
|
|
76b11c |
|