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