From a88c758e1430473b13e3d2fccae56280728d7afa Mon Sep 17 00:00:00 2001 From: Masashi Fujita Date: Tue, 8 Nov 2022 14:01:58 +0900 Subject: [PATCH 1/6] feat: Handle PlayStation platforms --- docs/configuration.md | 3 ++ src/catch2/catch_user_config.hpp.in | 10 +++++++ .../internal/catch_compiler_capabilities.hpp | 30 ++++++++++++------- src/catch2/internal/catch_getenv.cpp | 5 ++-- src/catch2/internal/catch_platform.hpp | 4 +++ .../catch_test_case_registry_impl.cpp | 2 +- src/catch2/reporters/catch_reporter_junit.cpp | 2 ++ 7 files changed, 42 insertions(+), 14 deletions(-) diff --git a/docs/configuration.md b/docs/configuration.md index e19290c207..f3d9a4744e 100644 --- a/docs/configuration.md +++ b/docs/configuration.md @@ -147,6 +147,7 @@ by using `_NO_` in the macro, e.g. `CATCH_CONFIG_NO_CPP17_UNCAUGHT_EXCEPTIONS`. CATCH_CONFIG_WINDOWS_SEH // Enable SEH handling on Windows CATCH_CONFIG_FAST_COMPILE // Sacrifices some (rather minor) features for compilation speed CATCH_CONFIG_POSIX_SIGNALS // Enable handling POSIX signals + CATCH_CONFIG_GETENV // System has a working `getenv` CATCH_CONFIG_WINDOWS_CRTDBG // Enable leak checking using Windows's CRT Debug Heap CATCH_CONFIG_DISABLE_STRINGIFICATION // Disable stringifying the original expression CATCH_CONFIG_DISABLE // Disables assertions and test case registration @@ -162,6 +163,8 @@ Currently Catch enables `CATCH_CONFIG_WINDOWS_SEH` only when compiled with MSVC, `CATCH_CONFIG_POSIX_SIGNALS` is on by default, except when Catch is compiled under `Cygwin`, where it is disabled by default (but can be force-enabled by defining `CATCH_CONFIG_POSIX_SIGNALS`). +`CATCH_CONFIG_GETENV` is on by default, except when Catch is compiled under some platforms that lacks working `getenv` (currently Windows UWP and Playstation). + `CATCH_CONFIG_WINDOWS_CRTDBG` is off by default. If enabled, Windows's CRT is used to check for memory leaks, and displays them after the tests finish running. This option only works when linking against the default diff --git a/src/catch2/catch_user_config.hpp.in b/src/catch2/catch_user_config.hpp.in index b6a0f191f5..3f6b10e89d 100644 --- a/src/catch2/catch_user_config.hpp.in +++ b/src/catch2/catch_user_config.hpp.in @@ -130,6 +130,16 @@ +#cmakedefine CATCH_CONFIG_GETENV +#cmakedefine CATCH_CONFIG_NO_GETENV + +#if defined( CATCH_CONFIG_GETENV ) && \ + defined( CATCH_CONFIG_NO_GETENV ) +# error Cannot force GETENV to both ON and OFF +#endif + + + #cmakedefine CATCH_CONFIG_USE_ASYNC #cmakedefine CATCH_CONFIG_NO_USE_ASYNC diff --git a/src/catch2/internal/catch_compiler_capabilities.hpp b/src/catch2/internal/catch_compiler_capabilities.hpp index 90e4cec341..f7cdb18b6f 100644 --- a/src/catch2/internal/catch_compiler_capabilities.hpp +++ b/src/catch2/internal/catch_compiler_capabilities.hpp @@ -117,20 +117,26 @@ #endif // __clang__ -//////////////////////////////////////////////////////////////////////////////// -// Assume that non-Windows platforms support posix signals by default -#if !defined(CATCH_PLATFORM_WINDOWS) - #define CATCH_INTERNAL_CONFIG_POSIX_SIGNALS -#endif - //////////////////////////////////////////////////////////////////////////////// // We know some environments not to support full POSIX signals -#if defined(__CYGWIN__) || defined(__QNX__) || defined(__EMSCRIPTEN__) || defined(__DJGPP__) - #define CATCH_INTERNAL_CONFIG_NO_POSIX_SIGNALS +#if defined( CATCH_PLATFORM_WINDOWS ) || \ + defined( CATCH_PLATFORM_PLAYSTATION ) || \ + defined( __CYGWIN__ ) || \ + defined( __QNX__ ) || \ + defined( __EMSCRIPTEN__ ) || \ + defined( __DJGPP__ ) || \ + defined( __OS400__ ) +# define CATCH_INTERNAL_CONFIG_NO_POSIX_SIGNALS +#else +# define CATCH_INTERNAL_CONFIG_POSIX_SIGNALS #endif -#ifdef __OS400__ -# define CATCH_INTERNAL_CONFIG_NO_POSIX_SIGNALS +//////////////////////////////////////////////////////////////////////////////// +// Assume that some platforms do not support getenv. +#if defined(CATCH_PLATFORM_WINDOWS_UWP) || defined(CATCH_PLATFORM_PLAYSTATION) +# define CATCH_INTERNAL_CONFIG_NO_GETENV +#else +# define CATCH_INTERNAL_CONFIG_GETENV #endif //////////////////////////////////////////////////////////////////////////////// @@ -273,6 +279,10 @@ # define CATCH_CONFIG_POSIX_SIGNALS #endif +#if defined(CATCH_INTERNAL_CONFIG_GETENV) && !defined(CATCH_INTERNAL_CONFIG_NO_GETENV) && !defined(CATCH_CONFIG_NO_GETENV) && !defined(CATCH_CONFIG_GETENV) +# define CATCH_CONFIG_GETENV +#endif + #if !defined(CATCH_INTERNAL_CONFIG_NO_CPP11_TO_STRING) && !defined(CATCH_CONFIG_NO_CPP11_TO_STRING) && !defined(CATCH_CONFIG_CPP11_TO_STRING) # define CATCH_CONFIG_CPP11_TO_STRING #endif diff --git a/src/catch2/internal/catch_getenv.cpp b/src/catch2/internal/catch_getenv.cpp index da1c3922fe..993918ee61 100644 --- a/src/catch2/internal/catch_getenv.cpp +++ b/src/catch2/internal/catch_getenv.cpp @@ -14,7 +14,7 @@ namespace Catch { namespace Detail { -#if defined( CATCH_PLATFORM_WINDOWS_UWP ) +#if ! defined (CATCH_CONFIG_GETENV) char const* getEnv( char const* ) { return nullptr; } #else @@ -29,8 +29,7 @@ namespace Catch { # if defined( _MSC_VER ) # pragma warning( pop ) # endif + } #endif - } - } // namespace Detail } // namespace Catch diff --git a/src/catch2/internal/catch_platform.hpp b/src/catch2/internal/catch_platform.hpp index 175b36a031..b11d9ccde7 100644 --- a/src/catch2/internal/catch_platform.hpp +++ b/src/catch2/internal/catch_platform.hpp @@ -28,6 +28,10 @@ # if defined( WINAPI_FAMILY ) && ( WINAPI_FAMILY == WINAPI_FAMILY_APP ) # define CATCH_PLATFORM_WINDOWS_UWP # endif + +#elif defined(__ORBIS__) || defined(__PROSPERO__) +# define CATCH_PLATFORM_PLAYSTATION + #endif #endif // CATCH_PLATFORM_HPP_INCLUDED diff --git a/src/catch2/internal/catch_test_case_registry_impl.cpp b/src/catch2/internal/catch_test_case_registry_impl.cpp index b61fd661ff..4b3d2e4716 100644 --- a/src/catch2/internal/catch_test_case_registry_impl.cpp +++ b/src/catch2/internal/catch_test_case_registry_impl.cpp @@ -89,7 +89,7 @@ namespace Catch { TestCaseInfo const* rhs ) { return *lhs < *rhs; }; - std::set seenTests(testInfoCmp); + std::set seenTests(testInfoCmp); for ( auto const& test : tests ) { const auto infoPtr = &test.getTestCaseInfo(); const auto prev = seenTests.insert( infoPtr ); diff --git a/src/catch2/reporters/catch_reporter_junit.cpp b/src/catch2/reporters/catch_reporter_junit.cpp index 6b31ad404c..837d048986 100644 --- a/src/catch2/reporters/catch_reporter_junit.cpp +++ b/src/catch2/reporters/catch_reporter_junit.cpp @@ -31,6 +31,8 @@ namespace Catch { std::tm timeInfo = {}; #if defined (_MSC_VER) || defined (__MINGW32__) gmtime_s(&timeInfo, &rawtime); +#elif defined (CATCH_PLATFORM_PLAYSTATION) + gmtime_s(&rawtime, &timeInfo); #else gmtime_r(&rawtime, &timeInfo); #endif From e72372056e460b83a49fa52dad4da9a7fb8f0d8b Mon Sep 17 00:00:00 2001 From: Masashi Fujita Date: Tue, 8 Nov 2022 20:15:18 +0900 Subject: [PATCH 2/6] Adopt suggestions MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit https://github.com/catchorg/Catch2/pull/2562#discussion_r1016473806 Co-authored-by: Martin Hořeňovský --- docs/configuration.md | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/docs/configuration.md b/docs/configuration.md index f3d9a4744e..9b5e091c06 100644 --- a/docs/configuration.md +++ b/docs/configuration.md @@ -163,7 +163,9 @@ Currently Catch enables `CATCH_CONFIG_WINDOWS_SEH` only when compiled with MSVC, `CATCH_CONFIG_POSIX_SIGNALS` is on by default, except when Catch is compiled under `Cygwin`, where it is disabled by default (but can be force-enabled by defining `CATCH_CONFIG_POSIX_SIGNALS`). -`CATCH_CONFIG_GETENV` is on by default, except when Catch is compiled under some platforms that lacks working `getenv` (currently Windows UWP and Playstation). +`CATCH_CONFIG_GETENV` is on by default, except when Catch2 is compiled for +platforms that lacks working `std::getenv` (currently Windows UWP and +Playstation). `CATCH_CONFIG_WINDOWS_CRTDBG` is off by default. If enabled, Windows's CRT is used to check for memory leaks, and displays them after the tests From dd8e5c846b77aabedd30abe4d7a8cb543b524bc5 Mon Sep 17 00:00:00 2001 From: Masashi Fujita Date: Tue, 8 Nov 2022 20:40:17 +0900 Subject: [PATCH 3/6] fix: Include catch_compiler_capabilities.hpp explicitly Suggested in https://github.com/catchorg/Catch2/pull/2562#discussion_r1016478715 --- src/catch2/internal/catch_getenv.cpp | 2 ++ 1 file changed, 2 insertions(+) diff --git a/src/catch2/internal/catch_getenv.cpp b/src/catch2/internal/catch_getenv.cpp index 993918ee61..30f5938fea 100644 --- a/src/catch2/internal/catch_getenv.cpp +++ b/src/catch2/internal/catch_getenv.cpp @@ -7,7 +7,9 @@ // SPDX-License-Identifier: BSL-1.0 #include + #include +#include #include From 293d5f399424891101dee37752c257eb41ced62d Mon Sep 17 00:00:00 2001 From: Masashi Fujita Date: Tue, 8 Nov 2022 20:42:11 +0900 Subject: [PATCH 4/6] style: Align to project style Suggested in https://github.com/catchorg/Catch2/pull/2562#discussion_r1016476267 --- src/catch2/internal/catch_getenv.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/catch2/internal/catch_getenv.cpp b/src/catch2/internal/catch_getenv.cpp index 30f5938fea..a9a592c7d9 100644 --- a/src/catch2/internal/catch_getenv.cpp +++ b/src/catch2/internal/catch_getenv.cpp @@ -16,7 +16,7 @@ namespace Catch { namespace Detail { -#if ! defined (CATCH_CONFIG_GETENV) +#if !defined (CATCH_CONFIG_GETENV) char const* getEnv( char const* ) { return nullptr; } #else From 2df48173c2e423775a9eb92f3a342b77be93acb7 Mon Sep 17 00:00:00 2001 From: Masashi Fujita Date: Tue, 8 Nov 2022 20:43:45 +0900 Subject: [PATCH 5/6] style: Align to project style guideline Suggested in https://github.com/catchorg/Catch2/pull/2562#discussion_r1016472204 --- docs/configuration.md | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/docs/configuration.md b/docs/configuration.md index 9b5e091c06..1392caaa04 100644 --- a/docs/configuration.md +++ b/docs/configuration.md @@ -147,7 +147,6 @@ by using `_NO_` in the macro, e.g. `CATCH_CONFIG_NO_CPP17_UNCAUGHT_EXCEPTIONS`. CATCH_CONFIG_WINDOWS_SEH // Enable SEH handling on Windows CATCH_CONFIG_FAST_COMPILE // Sacrifices some (rather minor) features for compilation speed CATCH_CONFIG_POSIX_SIGNALS // Enable handling POSIX signals - CATCH_CONFIG_GETENV // System has a working `getenv` CATCH_CONFIG_WINDOWS_CRTDBG // Enable leak checking using Windows's CRT Debug Heap CATCH_CONFIG_DISABLE_STRINGIFICATION // Disable stringifying the original expression CATCH_CONFIG_DISABLE // Disables assertions and test case registration @@ -156,9 +155,12 @@ by using `_NO_` in the macro, e.g. `CATCH_CONFIG_NO_CPP17_UNCAUGHT_EXCEPTIONS`. CATCH_CONFIG_USE_ASYNC // Force parallel statistical processing of samples during benchmarking CATCH_CONFIG_ANDROID_LOGWRITE // Use android's logging system for debug output CATCH_CONFIG_GLOBAL_NEXTAFTER // Use nextafter{,f,l} instead of std::nextafter + CATCH_CONFIG_GETENV // System has a working `getenv` > [`CATCH_CONFIG_ANDROID_LOGWRITE`](https://github.com/catchorg/Catch2/issues/1743) and [`CATCH_CONFIG_GLOBAL_NEXTAFTER`](https://github.com/catchorg/Catch2/pull/1739) were introduced in Catch2 2.10.0 +> `CATCH_CONFIG_GETENV` was [introduced](https://github.com/catchorg/Catch2/pull/2562) in Catch2 X.Y.Z + Currently Catch enables `CATCH_CONFIG_WINDOWS_SEH` only when compiled with MSVC, because some versions of MinGW do not have the necessary Win32 API support. `CATCH_CONFIG_POSIX_SIGNALS` is on by default, except when Catch is compiled under `Cygwin`, where it is disabled by default (but can be force-enabled by defining `CATCH_CONFIG_POSIX_SIGNALS`). From 0c8129429ae4111114ef4c438342e0ea5526795c Mon Sep 17 00:00:00 2001 From: Masashi Fujita Date: Tue, 8 Nov 2022 20:45:35 +0900 Subject: [PATCH 6/6] fix: Add for CMake frontend Suggested in https://github.com/catchorg/Catch2/pull/2562#discussion_r1016475142 --- CMake/CatchConfigOptions.cmake | 1 + 1 file changed, 1 insertion(+) diff --git a/CMake/CatchConfigOptions.cmake b/CMake/CatchConfigOptions.cmake index 7b56695aa2..733ec65e2c 100644 --- a/CMake/CatchConfigOptions.cmake +++ b/CMake/CatchConfigOptions.cmake @@ -40,6 +40,7 @@ set(_OverridableOptions "USE_ASYNC" "WCHAR" "WINDOWS_SEH" + "GETENV" ) foreach(OptionName ${_OverridableOptions})