Skip to content

Commit

Permalink
GHI #32 Split death.cpp into h/cpp pair [skip ci]
Browse files Browse the repository at this point in the history
  • Loading branch information
doodspav committed Jul 13, 2024
1 parent c9a71b5 commit 53949f5
Show file tree
Hide file tree
Showing 3 changed files with 35 additions and 10 deletions.
24 changes: 14 additions & 10 deletions test/include/test/common/death.hpp
Original file line number Diff line number Diff line change
@@ -1,29 +1,33 @@
#ifndef PATOMIC_TEST_COMMON_KILLED_BY_HPP
#define PATOMIC_TEST_COMMON_KILLED_BY_HPP

#include <csignal>
#include <gtest/gtest.h>


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
Expand Down
1 change: 1 addition & 0 deletions test/src/common/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -2,5 +2,6 @@
target_sources(${test_target_name}-src PRIVATE
align.cpp
compare.cpp
death.cpp
make_ops.cpp
)
20 changes: 20 additions & 0 deletions test/src/common/death.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
#include <test/common/death.hpp>

#include <csignal>

namespace test
{


KilledBySignalType
KilledByAbort()
{
#if PATOMIC_GTEST_HAS_KILLED_BY_SIGNAL
return testing::KilledBySignal(SIGABRT);
#else
return testing::ExitedWithCode(3);
#endif
}


} // namespace test

0 comments on commit 53949f5

Please sign in to comment.