diff options
author | Abseil Team <absl-team@google.com> | 2024-02-07 17:00:30 (GMT) |
---|---|---|
committer | Copybara-Service <copybara-worker@google.com> | 2024-02-07 17:01:25 (GMT) |
commit | 96519a4019ff084112db9e532a621f92721cda4b (patch) | |
tree | 96a66c8895b2c80e1a6fcd3d8fed711512bac0ee /googletest/test | |
parent | 64be1c79fa2cea015d816687120878a110775351 (diff) | |
download | googletest-96519a4019ff084112db9e532a621f92721cda4b.zip googletest-96519a4019ff084112db9e532a621f92721cda4b.tar.gz googletest-96519a4019ff084112db9e532a621f92721cda4b.tar.bz2 |
Use _Exit instead of _exit in GoogleTest
_Exit is standardized since C99, whereas _exit is POSIX-only.
Fixes: #4447
PiperOrigin-RevId: 605000352
Change-Id: Ibfa84edaa043bd003a21383e8148bf45be7217f6
Diffstat (limited to 'googletest/test')
-rw-r--r-- | googletest/test/googletest-death-test-test.cc | 76 |
1 files changed, 39 insertions, 37 deletions
diff --git a/googletest/test/googletest-death-test-test.cc b/googletest/test/googletest-death-test-test.cc index 4cc81b7..75742c9 100644 --- a/googletest/test/googletest-death-test-test.cc +++ b/googletest/test/googletest-death-test-test.cc @@ -30,6 +30,8 @@ // // Tests for death tests. +#include <stdlib.h> + #include "gtest/gtest-death-test.h" #include "gtest/gtest.h" #include "gtest/internal/gtest-filepath.h" @@ -111,15 +113,15 @@ void DieWithMessage(const ::std::string& message) { fprintf(stderr, "%s", message.c_str()); fflush(stderr); // Make sure the text is printed before the process exits. - // We call _exit() instead of exit(), as the former is a direct + // We call _Exit() instead of exit(), as the former is a direct // system call and thus safer in the presence of threads. exit() // will invoke user-defined exit-hooks, which may do dangerous // things that conflict with death tests. // - // Some compilers can recognize that _exit() never returns and issue the + // Some compilers can recognize that _Exit() never returns and issue the // 'unreachable code' warning for code following this function, unless // fooled by a fake condition. - if (AlwaysTrue()) _exit(1); + if (AlwaysTrue()) _Exit(1); } void DieInside(const ::std::string& function) { @@ -238,13 +240,13 @@ TEST(ExitStatusPredicateTest, ExitedWithCode) { #else -// Returns the exit status of a process that calls _exit(2) with a +// Returns the exit status of a process that calls _Exit(2) with a // given exit code. This is a helper function for the // ExitStatusPredicateTest test suite. static int NormalExitStatus(int exit_code) { pid_t child_pid = fork(); if (child_pid == 0) { - _exit(exit_code); + _Exit(exit_code); } int status; waitpid(child_pid, &status, 0); @@ -260,7 +262,7 @@ static int KilledExitStatus(int signum) { pid_t child_pid = fork(); if (child_pid == 0) { raise(signum); - _exit(1); + _Exit(1); } int status; waitpid(child_pid, &status, 0); @@ -313,7 +315,7 @@ TEST_F(TestForDeathTest, SingleStatement) { ASSERT_DEATH(return, ""); if (AlwaysTrue()) - EXPECT_DEATH(_exit(1), ""); + EXPECT_DEATH(_Exit(1), ""); else // This empty "else" branch is meant to ensure that EXPECT_DEATH // doesn't expand into an "if" statement without an "else" @@ -324,7 +326,7 @@ TEST_F(TestForDeathTest, SingleStatement) { if (AlwaysFalse()) ; else - EXPECT_DEATH(_exit(1), "") << 1 << 2 << 3; + EXPECT_DEATH(_Exit(1), "") << 1 << 2 << 3; } #ifdef __GNUC__ #pragma GCC diagnostic pop @@ -339,11 +341,11 @@ TEST_F(TestForDeathTest, SwitchStatement) { switch (0) default: - ASSERT_DEATH(_exit(1), "") << "exit in default switch handler"; + ASSERT_DEATH(_Exit(1), "") << "exit in default switch handler"; switch (0) case 0: - EXPECT_DEATH(_exit(1), "") << "exit in switch case"; + EXPECT_DEATH(_Exit(1), "") << "exit in switch case"; GTEST_DISABLE_MSC_WARNINGS_POP_() } @@ -371,10 +373,10 @@ TEST_F(TestForDeathTest, FastDeathTestInChangedDir) { GTEST_FLAG_SET(death_test_style, "fast"); ChangeToRootDir(); - EXPECT_EXIT(_exit(1), testing::ExitedWithCode(1), ""); + EXPECT_EXIT(_Exit(1), testing::ExitedWithCode(1), ""); ChangeToRootDir(); - ASSERT_DEATH(_exit(1), ""); + ASSERT_DEATH(_Exit(1), ""); } #ifdef GTEST_OS_LINUX @@ -416,7 +418,7 @@ void DisableSigprofActionAndTimer(struct sigaction* old_signal_action) { TEST_F(TestForDeathTest, FastSigprofActionSet) { GTEST_FLAG_SET(death_test_style, "fast"); SetSigprofActionAndTimer(); - EXPECT_DEATH(_exit(1), ""); + EXPECT_DEATH(_Exit(1), ""); struct sigaction old_signal_action; DisableSigprofActionAndTimer(&old_signal_action); EXPECT_TRUE(old_signal_action.sa_sigaction == SigprofAction); @@ -425,7 +427,7 @@ TEST_F(TestForDeathTest, FastSigprofActionSet) { TEST_F(TestForDeathTest, ThreadSafeSigprofActionSet) { GTEST_FLAG_SET(death_test_style, "threadsafe"); SetSigprofActionAndTimer(); - EXPECT_DEATH(_exit(1), ""); + EXPECT_DEATH(_Exit(1), ""); struct sigaction old_signal_action; DisableSigprofActionAndTimer(&old_signal_action); EXPECT_TRUE(old_signal_action.sa_sigaction == SigprofAction); @@ -449,24 +451,24 @@ TEST_F(TestForDeathTest, ThreadsafeDeathTestInLoop) { GTEST_FLAG_SET(death_test_style, "threadsafe"); for (int i = 0; i < 3; ++i) - EXPECT_EXIT(_exit(i), testing::ExitedWithCode(i), "") << ": i = " << i; + EXPECT_EXIT(_Exit(i), testing::ExitedWithCode(i), "") << ": i = " << i; } TEST_F(TestForDeathTest, ThreadsafeDeathTestInChangedDir) { GTEST_FLAG_SET(death_test_style, "threadsafe"); ChangeToRootDir(); - EXPECT_EXIT(_exit(1), testing::ExitedWithCode(1), ""); + EXPECT_EXIT(_Exit(1), testing::ExitedWithCode(1), ""); ChangeToRootDir(); - ASSERT_DEATH(_exit(1), ""); + ASSERT_DEATH(_Exit(1), ""); } TEST_F(TestForDeathTest, MixedStyles) { GTEST_FLAG_SET(death_test_style, "threadsafe"); - EXPECT_DEATH(_exit(1), ""); + EXPECT_DEATH(_Exit(1), ""); GTEST_FLAG_SET(death_test_style, "fast"); - EXPECT_DEATH(_exit(1), ""); + EXPECT_DEATH(_Exit(1), ""); } #if GTEST_HAS_CLONE && GTEST_HAS_PTHREAD @@ -480,7 +482,7 @@ TEST_F(TestForDeathTest, DoesNotExecuteAtforkHooks) { GTEST_FLAG_SET(death_test_style, "threadsafe"); pthread_flag = false; ASSERT_EQ(0, pthread_atfork(&SetPthreadFlag, nullptr, nullptr)); - ASSERT_DEATH(_exit(1), ""); + ASSERT_DEATH(_Exit(1), ""); ASSERT_FALSE(pthread_flag); } } @@ -805,8 +807,8 @@ TEST_F(TestForDeathTest, AssertDebugDeathAborts10) { // Tests the *_EXIT family of macros, using a variety of predicates. static void TestExitMacros() { - EXPECT_EXIT(_exit(1), testing::ExitedWithCode(1), ""); - ASSERT_EXIT(_exit(42), testing::ExitedWithCode(42), ""); + EXPECT_EXIT(_Exit(1), testing::ExitedWithCode(1), ""); + ASSERT_EXIT(_Exit(42), testing::ExitedWithCode(42), ""); #ifdef GTEST_OS_WINDOWS @@ -823,7 +825,7 @@ static void TestExitMacros() { EXPECT_FATAL_FAILURE( { // NOLINT - ASSERT_EXIT(_exit(0), testing::KilledBySignal(SIGSEGV), "") + ASSERT_EXIT(_Exit(0), testing::KilledBySignal(SIGSEGV), "") << "This failure is expected, too."; }, "This failure is expected, too."); @@ -849,7 +851,7 @@ TEST_F(TestForDeathTest, InvalidStyle) { GTEST_FLAG_SET(death_test_style, "rococo"); EXPECT_NONFATAL_FAILURE( { // NOLINT - EXPECT_DEATH(_exit(0), "") << "This failure is expected."; + EXPECT_DEATH(_Exit(0), "") << "This failure is expected."; }, "This failure is expected."); } @@ -1140,7 +1142,7 @@ TEST_F(MacroLogicDeathTest, ChildDoesNotDie) { // This time there are two calls to Abort: one since the test didn't // die, and another from the ReturnSentinel when it's destroyed. The // sentinel normally isn't destroyed if a test doesn't die, since - // _exit(2) is called in that case by ForkingDeathTest, but not by + // _Exit(2) is called in that case by ForkingDeathTest, but not by // our MockDeathTest. ASSERT_EQ(2U, factory_->AbortCalls()); EXPECT_EQ(DeathTest::TEST_DID_NOT_DIE, factory_->AbortArgument(0)); @@ -1152,21 +1154,21 @@ TEST_F(MacroLogicDeathTest, ChildDoesNotDie) { // Tests that a successful death test does not register a successful // test part. TEST(SuccessRegistrationDeathTest, NoSuccessPart) { - EXPECT_DEATH(_exit(1), ""); + EXPECT_DEATH(_Exit(1), ""); EXPECT_EQ(0, GetUnitTestImpl()->current_test_result()->total_part_count()); } TEST(StreamingAssertionsDeathTest, DeathTest) { - EXPECT_DEATH(_exit(1), "") << "unexpected failure"; - ASSERT_DEATH(_exit(1), "") << "unexpected failure"; + EXPECT_DEATH(_Exit(1), "") << "unexpected failure"; + ASSERT_DEATH(_Exit(1), "") << "unexpected failure"; EXPECT_NONFATAL_FAILURE( { // NOLINT - EXPECT_DEATH(_exit(0), "") << "expected failure"; + EXPECT_DEATH(_Exit(0), "") << "expected failure"; }, "expected failure"); EXPECT_FATAL_FAILURE( { // NOLINT - ASSERT_DEATH(_exit(0), "") << "expected failure"; + ASSERT_DEATH(_Exit(0), "") << "expected failure"; }, "expected failure"); } @@ -1330,7 +1332,7 @@ TEST(InDeathTestChildDeathTest, ReportsDeathTestCorrectlyInFastStyle) { { fprintf(stderr, InDeathTestChild() ? "Inside" : "Outside"); fflush(stderr); - _exit(1); + _Exit(1); }, "Inside"); } @@ -1342,7 +1344,7 @@ TEST(InDeathTestChildDeathTest, ReportsDeathTestCorrectlyInThreadSafeStyle) { { fprintf(stderr, InDeathTestChild() ? "Inside" : "Outside"); fflush(stderr); - _exit(1); + _Exit(1); }, "Inside"); } @@ -1350,7 +1352,7 @@ TEST(InDeathTestChildDeathTest, ReportsDeathTestCorrectlyInThreadSafeStyle) { void DieWithMessage(const char* message) { fputs(message, stderr); fflush(stderr); // Make sure the text is printed before the process exits. - _exit(1); + _Exit(1); } TEST(MatcherDeathTest, DoesNotBreakBareRegexMatching) { @@ -1466,7 +1468,7 @@ TEST(ConditionalDeathMacrosSyntaxDeathTest, SingleStatement) { ASSERT_DEATH_IF_SUPPORTED(return, ""); if (AlwaysTrue()) - EXPECT_DEATH_IF_SUPPORTED(_exit(1), ""); + EXPECT_DEATH_IF_SUPPORTED(_Exit(1), ""); else // This empty "else" branch is meant to ensure that EXPECT_DEATH // doesn't expand into an "if" statement without an "else" @@ -1477,7 +1479,7 @@ TEST(ConditionalDeathMacrosSyntaxDeathTest, SingleStatement) { if (AlwaysFalse()) ; // NOLINT else - EXPECT_DEATH_IF_SUPPORTED(_exit(1), "") << 1 << 2 << 3; + EXPECT_DEATH_IF_SUPPORTED(_Exit(1), "") << 1 << 2 << 3; } #ifdef __GNUC__ #pragma GCC diagnostic pop @@ -1492,11 +1494,11 @@ TEST(ConditionalDeathMacrosSyntaxDeathTest, SwitchStatement) { switch (0) default: - ASSERT_DEATH_IF_SUPPORTED(_exit(1), "") << "exit in default switch handler"; + ASSERT_DEATH_IF_SUPPORTED(_Exit(1), "") << "exit in default switch handler"; switch (0) case 0: - EXPECT_DEATH_IF_SUPPORTED(_exit(1), "") << "exit in switch case"; + EXPECT_DEATH_IF_SUPPORTED(_Exit(1), "") << "exit in switch case"; GTEST_DISABLE_MSC_WARNINGS_POP_() } |