From 53949f561a84b918ae3ac490371e4d1a7d27911f Mon Sep 17 00:00:00 2001 From: doodspav Date: Sat, 13 Jul 2024 19:26:02 +0100 Subject: [PATCH] GHI #32 Split death.cpp into h/cpp pair [skip ci] --- test/include/test/common/death.hpp | 24 ++++++++++++++---------- test/src/common/CMakeLists.txt | 1 + test/src/common/death.cpp | 20 ++++++++++++++++++++ 3 files changed, 35 insertions(+), 10 deletions(-) create mode 100644 test/src/common/death.cpp diff --git a/test/include/test/common/death.hpp b/test/include/test/common/death.hpp index ce022a12e..3a8e1e6aa 100644 --- a/test/include/test/common/death.hpp +++ b/test/include/test/common/death.hpp @@ -1,7 +1,6 @@ #ifndef PATOMIC_TEST_COMMON_KILLED_BY_HPP #define PATOMIC_TEST_COMMON_KILLED_BY_HPP -#include #include @@ -9,21 +8,26 @@ namespace test { +/// @brief +/// Helper type which can be passed by a matcher to any GTest macro which +/// passes an exit code. +#if defined(GTEST_OS_WINDOWS) || defined(GTEST_OS_FUCHSIA) +#define PATOMIC_GTEST_HAS_KILLED_BY_SIGNAL 0 +using KilledBySignalType = testing::ExitedWithCode; +#else +#define PATOMIC_GTEST_HAS_KILLED_BY_SIGNAL 1 +using KilledBySignalType = testing::KilledBySignal; +#endif + + /// @brief /// Produces a predicate that checks if an int exit code is what would be /// expected from a process killed by SIGABRT (or OS equivalent). /// /// @note /// Predicate is callable with the signature bool()(int). -inline auto -KilledByAbort() noexcept -{ -#if defined(_MSC_VER) - return testing::ExitedWithCode(3); -#else - return testing::KilledBySignal(SIGABRT); -#endif -} +KilledBySignalType +KilledByAbort(); } // namespace test diff --git a/test/src/common/CMakeLists.txt b/test/src/common/CMakeLists.txt index 1084f6ad3..6371d88a0 100644 --- a/test/src/common/CMakeLists.txt +++ b/test/src/common/CMakeLists.txt @@ -2,5 +2,6 @@ target_sources(${test_target_name}-src PRIVATE align.cpp compare.cpp + death.cpp make_ops.cpp ) diff --git a/test/src/common/death.cpp b/test/src/common/death.cpp new file mode 100644 index 000000000..e889a397c --- /dev/null +++ b/test/src/common/death.cpp @@ -0,0 +1,20 @@ +#include + +#include + +namespace test +{ + + +KilledBySignalType +KilledByAbort() +{ +#if PATOMIC_GTEST_HAS_KILLED_BY_SIGNAL + return testing::KilledBySignal(SIGABRT); +#else + return testing::ExitedWithCode(3); +#endif +} + + +} // namespace test