Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We鈥檒l occasionally send you account related emails.

Already on GitHub? Sign in to your account

Handle PlayStation platforms #2562

Merged
merged 6 commits into from Nov 9, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
1 change: 1 addition & 0 deletions CMake/CatchConfigOptions.cmake
Expand Up @@ -40,6 +40,7 @@ set(_OverridableOptions
"USE_ASYNC"
"WCHAR"
"WINDOWS_SEH"
"GETENV"
)

foreach(OptionName ${_OverridableOptions})
Expand Down
7 changes: 7 additions & 0 deletions docs/configuration.md
Expand Up @@ -155,13 +155,20 @@ 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`).

`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
finish running. This option only works when linking against the default
Expand Down
10 changes: 10 additions & 0 deletions src/catch2/catch_user_config.hpp.in
Expand Up @@ -130,6 +130,16 @@



#cmakedefine CATCH_CONFIG_GETENV
#cmakedefine CATCH_CONFIG_NO_GETENV
objectx marked this conversation as resolved.
Show resolved Hide resolved

#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

Expand Down
30 changes: 20 additions & 10 deletions src/catch2/internal/catch_compiler_capabilities.hpp
Expand Up @@ -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

////////////////////////////////////////////////////////////////////////////////
Expand Down Expand Up @@ -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
Expand Down
7 changes: 4 additions & 3 deletions src/catch2/internal/catch_getenv.cpp
Expand Up @@ -7,14 +7,16 @@
// SPDX-License-Identifier: BSL-1.0

#include <catch2/internal/catch_getenv.hpp>

#include <catch2/internal/catch_platform.hpp>
#include <catch2/internal/catch_compiler_capabilities.hpp>

#include <cstdlib>

namespace Catch {
namespace Detail {

#if defined( CATCH_PLATFORM_WINDOWS_UWP )
#if !defined (CATCH_CONFIG_GETENV)
char const* getEnv( char const* ) { return nullptr; }
#else

Expand All @@ -29,8 +31,7 @@ namespace Catch {
# if defined( _MSC_VER )
# pragma warning( pop )
# endif
}
#endif
}

} // namespace Detail
} // namespace Catch
4 changes: 4 additions & 0 deletions src/catch2/internal/catch_platform.hpp
Expand Up @@ -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
2 changes: 1 addition & 1 deletion src/catch2/internal/catch_test_case_registry_impl.cpp
Expand Up @@ -89,7 +89,7 @@ namespace Catch {
TestCaseInfo const* rhs ) {
return *lhs < *rhs;
};
std::set<TestCaseInfo const*, decltype(testInfoCmp)> seenTests(testInfoCmp);
std::set<TestCaseInfo const*, decltype(testInfoCmp) &> seenTests(testInfoCmp);
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why is the ref here needed?

Copy link
Contributor Author

@objectx objectx Nov 8, 2022

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Without &, The std::set in PlayStation SDK's STL tried to invoke a copy-constructor (and failed).

STL Bug?

MSBuild version 17.4.0+18d5aef85 for .NET Framework
  catch_chronometer.cpp
  catch_benchmark_function.cpp
  catch_run_for_at_least.cpp
  catch_stats.cpp
  catch_get_random_seed.cpp
  catch_tag_alias_autoregistrar.cpp
  catch_test_spec.cpp
  catch_timer.cpp
  catch_tostring.cpp
  catch_totals.cpp
  catch_version.cpp
  catch_generator_exception.cpp
  catch_generators.cpp
  catch_generators_random.cpp
  catch_interfaces_capture.cpp
  catch_interfaces_config.cpp
  catch_interfaces_exception.cpp
  catch_interfaces_registry_hub.cpp
  catch_interfaces_reporter_factory.cpp
  catch_interfaces_reporter_registry.cpp
  catch_interfaces_testcase.cpp
  catch_decomposer.cpp
  catch_errno_guard.cpp
  catch_lazy_expr.cpp
  catch_leak_detector.cpp
  catch_message_info.cpp
  catch_polyfills.cpp
  catch_startup_exception_registry.cpp
  catch_test_case_info_hasher.cpp
  catch_test_case_registry_impl.cpp
  In file included from D:\dev\Catch2\src\src\catch2\internal\catch_test_case_registry_impl.cpp:14:
  In file included from D:\dev\Catch2\src\src\catch2\..\catch2/internal/catch_run_context.hpp:11:
  In file included from D:\dev\Catch2\src\src\catch2\..\catch2/interfaces/catch_interfaces_reporter.hpp:22:
  In file included from C:\tools\SCE\Orbis-SDK\10.000\target\include\map:10:
C:\tools\SCE\Orbis-SDK\10.000\target\include\xtree(1058,11): error : no matching constructor for initialization of 'std::_Tree_comp<false, std::_Tset_traits<const Catch::TestCaseInfo *, (lambda at D:\dev\Catch2\src\src\catch2\internal\catch_test_case_registry_impl.cpp:88:28), std::allocator<const Catch::TestCaseInfo *>, false>>::key_compare' (aka '(lambda at D:\dev\Catch2\src\src\catch2\internal\catch_test_case_registry_impl.cpp:88:28)') [D:\dev\Catch2\0.B\orbis\src\Catch2.vcxproj]
                  return (key_compare());
                          ^
  C:\tools\SCE\Orbis-SDK\10.000\target\include\xtree(1986,38): note: in instantiation of member function 'std::_Tree_comp<false, std::_Tset_traits<const Catch::TestCaseInfo *, (lambda at D:\dev\Catch2\src\src\catch2\internal\catch_test_case_registry_impl.cpp:88:28), std::allocator<const Catch::TestCaseInfo *>, false>>::_Getcomp' requested here
                                  _Addleft = !_DEBUG_LT_PRED(this->_Getcomp(),
                                                                   ^
  C:\tools\SCE\Orbis-SDK\10.000\target\include\xtree(1403,11): note: in instantiation of function template specialization 'std::_Tree<std::_Tset_traits<const Catch::TestCaseInfo *, (lambda at D:\dev\Catch2\src\src\catch2\internal\catch_test_case_registry_impl.cpp:88:28), std::allocator<const Catch::TestCaseInfo *>, false>>::_Insert_nohint<const std::_Tree<std::_Tset_traits<const Catch::TestCaseInfo *, (lambda at D:\dev\Catch2\src\src\catch2\internal\catch_test_case_registry_impl.cpp:88:28), std::allocator<const Catch::TestCaseInfo *>, false>>::value_type &, std::_Nil>' requested here
                  return (_Insert_nohint(false,
                          ^
  C:\tools\SCE\Orbis-SDK\10.000\target\include\set(226,20): note: in instantiation of member function 'std::_Tree<std::_Tset_traits<const Catch::TestCaseInfo *, (lambda at D:\dev\Catch2\src\src\catch2\internal\catch_test_case_registry_impl.cpp:88:28), std::allocator<const Catch::TestCaseInfo *>, false>>::insert' requested here
                  return (_Mybase::insert(_Val));
                                   ^
  D:\dev\Catch2\src\src\catch2\internal\catch_test_case_registry_impl.cpp(95,41): note: in instantiation of member function 'std::set<const Catch::TestCaseInfo *, (lambda at D:\dev\Catch2\src\src\catch2\internal\catch_test_case_registry_impl.cpp:88:28)>::insert' requested here
              const auto prev = seenTests.insert( infoPtr );
                                          ^
  D:\dev\Catch2\src\src\catch2\internal\catch_test_case_registry_impl.cpp(88,28): note: candidate constructor (the implicit copy constructor) not viable: requires 1 argument, but 0 were provided
          auto testInfoCmp = []( TestCaseInfo const* lhs,
                             ^
  D:\dev\Catch2\src\src\catch2\internal\catch_test_case_registry_impl.cpp(88,28): note: candidate constructor (the implicit move constructor) not viable: requires 1 argument, but 0 were provided
  1 error generated.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Bleh. This is an upstream bug and needs to be reported there.

I am willing to merge to workaround in the meantime though.

for ( auto const& test : tests ) {
const auto infoPtr = &test.getTestCaseInfo();
const auto prev = seenTests.insert( infoPtr );
Expand Down
2 changes: 2 additions & 0 deletions src/catch2/reporters/catch_reporter_junit.cpp
Expand Up @@ -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
Expand Down