33 #include "gtest/gtest-death-test.h"
35 #include "gtest/gtest.h"
36 #include "gtest/internal/gtest-filepath.h"
41 #if GTEST_HAS_DEATH_TEST
49 # include <sys/wait.h>
50 # endif // GTEST_OS_WINDOWS
57 # include <sys/time.h>
58 # endif // GTEST_OS_LINUX
60 # include "gtest/gtest-spi.h"
61 # include "src/gtest-internal-inl.h"
63 namespace posix = ::testing::internal::posix;
68 using testing::internal::DeathTest;
69 using testing::internal::DeathTestFactory;
71 using testing::internal::GetLastErrnoDescription;
73 using testing::internal::InDeathTestChild;
74 using testing::internal::ParseNaturalNumber;
81 class ReplaceDeathTestFactory {
83 explicit ReplaceDeathTestFactory(DeathTestFactory* new_factory)
85 old_factory_ = unit_test_impl_->death_test_factory_.release();
86 unit_test_impl_->death_test_factory_.reset(new_factory);
89 ~ReplaceDeathTestFactory() {
90 unit_test_impl_->death_test_factory_.release();
91 unit_test_impl_->death_test_factory_.reset(old_factory_);
95 ReplaceDeathTestFactory(
const ReplaceDeathTestFactory&);
96 void operator=(
const ReplaceDeathTestFactory&);
98 UnitTestImpl* unit_test_impl_;
99 DeathTestFactory* old_factory_;
124 DieWithMessage(
"death inside " +
function +
"().");
131 TestForDeathTest() : original_dir_(
FilePath::GetCurrentDir()) {}
133 ~TestForDeathTest()
override {
posix::ChDir(original_dir_.c_str()); }
136 static void StaticMemberFunction() { DieInside(
"StaticMemberFunction"); }
139 void MemberFunction() {
141 DieInside(
"MemberFunction");
152 explicit MayDie(
bool should_die) : should_die_(should_die) {}
155 void MemberFunction()
const {
157 DieInside(
"MayDie::MemberFunction");
166 void GlobalFunction() { DieInside(
"GlobalFunction"); }
169 int NonVoidFunction() {
170 DieInside(
"NonVoidFunction");
175 void DieIf(
bool should_die) {
181 bool DieIfLessThan(
int x,
int y) {
183 DieInside(
"DieIfLessThan");
189 void DeathTestSubroutine() {
190 EXPECT_DEATH(GlobalFunction(),
"death.*GlobalFunction");
191 ASSERT_DEATH(GlobalFunction(),
"death.*GlobalFunction");
195 int DieInDebugElse12(
int* sideeffect) {
196 if (sideeffect) *sideeffect = 12;
200 DieInside(
"DieInDebugElse12");
207 # if GTEST_OS_WINDOWS
210 int DieInCRTDebugElse12(
int* sideeffect) {
211 if (sideeffect) *sideeffect = 12;
225 #endif // GTEST_OS_WINDOWS
227 # if GTEST_OS_WINDOWS || GTEST_OS_FUCHSIA
230 TEST(ExitStatusPredicateTest, ExitedWithCode) {
245 static int NormalExitStatus(
int exit_code) {
246 pid_t child_pid = fork();
247 if (child_pid == 0) {
251 waitpid(child_pid, &
status, 0);
260 static int KilledExitStatus(
int signum) {
261 pid_t child_pid = fork();
262 if (child_pid == 0) {
267 waitpid(child_pid, &
status, 0);
272 TEST(ExitStatusPredicateTest, ExitedWithCode) {
273 const int status0 = NormalExitStatus(0);
274 const int status1 = NormalExitStatus(1);
275 const int status42 = NormalExitStatus(42);
276 const testing::ExitedWithCode pred0(0);
277 const testing::ExitedWithCode pred1(1);
278 const testing::ExitedWithCode pred42(42);
288 TEST(ExitStatusPredicateTest, KilledBySignal) {
289 const int status_segv = KilledExitStatus(SIGSEGV);
290 const int status_kill = KilledExitStatus(
SIGKILL);
291 const testing::KilledBySignal pred_segv(SIGSEGV);
292 const testing::KilledBySignal pred_kill(
SIGKILL);
299 # endif // GTEST_OS_WINDOWS || GTEST_OS_FUCHSIA
303 #pragma GCC diagnostic push
304 #pragma GCC diagnostic ignored "-Wdangling-else"
305 #pragma GCC diagnostic ignored "-Wempty-body"
306 #pragma GCC diagnostic ignored "-Wpragmas"
311 TEST_F(TestForDeathTest, SingleStatement) {
314 ASSERT_DEATH(
return,
"");
317 EXPECT_DEATH(_exit(1),
"");
324 ASSERT_DEATH(
return,
"") <<
"did not die";
329 EXPECT_DEATH(_exit(1),
"") << 1 << 2 << 3;
332 #pragma GCC diagnostic pop
337 void DieWithEmbeddedNul() {
338 fprintf(
stderr,
"Hello%cmy null world.\n",
'\0');
345 TEST_F(TestForDeathTest, EmbeddedNulInMessage) {
346 EXPECT_DEATH(DieWithEmbeddedNul(),
"my null world");
347 ASSERT_DEATH(DieWithEmbeddedNul(),
"my null world");
350 # endif // GTEST_USES_PCRE
354 TEST_F(TestForDeathTest, SwitchStatement) {
365 EXPECT_DEATH(_exit(1), "") << "exit
in switch case";
372 TEST_F(TestForDeathTest, StaticMemberFunctionFastStyle) {
374 ASSERT_DEATH(StaticMemberFunction(),
"death.*StaticMember");
379 TEST_F(TestForDeathTest, MemberFunctionFastStyle) {
382 EXPECT_DEATH(MemberFunction(),
"inside.*MemberFunction");
389 TEST_F(TestForDeathTest, FastDeathTestInChangedDir) {
393 EXPECT_EXIT(_exit(1), testing::ExitedWithCode(1),
"");
396 ASSERT_DEATH(_exit(1),
"");
400 void SigprofAction(
int, siginfo_t*,
void*) { }
403 void SetSigprofActionAndTimer() {
412 struct itimerval
timer;
413 timer.it_interval.tv_sec = 0;
414 timer.it_interval.tv_usec = 1;
420 void DisableSigprofActionAndTimer(
struct sigaction* old_signal_action) {
421 struct itimerval
timer;
422 timer.it_interval.tv_sec = 0;
423 timer.it_interval.tv_usec = 0;
434 TEST_F(TestForDeathTest, FastSigprofActionSet) {
436 SetSigprofActionAndTimer();
437 EXPECT_DEATH(_exit(1),
"");
438 struct sigaction old_signal_action;
439 DisableSigprofActionAndTimer(&old_signal_action);
440 EXPECT_TRUE(old_signal_action.sa_sigaction == SigprofAction);
443 TEST_F(TestForDeathTest, ThreadSafeSigprofActionSet) {
445 SetSigprofActionAndTimer();
446 EXPECT_DEATH(_exit(1),
"");
447 struct sigaction old_signal_action;
448 DisableSigprofActionAndTimer(&old_signal_action);
449 EXPECT_TRUE(old_signal_action.sa_sigaction == SigprofAction);
451 # endif // GTEST_OS_LINUX
455 TEST_F(TestForDeathTest, StaticMemberFunctionThreadsafeStyle) {
457 ASSERT_DEATH(StaticMemberFunction(),
"death.*StaticMember");
460 TEST_F(TestForDeathTest, MemberFunctionThreadsafeStyle) {
463 EXPECT_DEATH(MemberFunction(),
"inside.*MemberFunction");
466 TEST_F(TestForDeathTest, ThreadsafeDeathTestInLoop) {
469 for (
int i = 0;
i < 3; ++
i)
470 EXPECT_EXIT(_exit(
i), testing::ExitedWithCode(
i),
"") <<
": i = " <<
i;
473 TEST_F(TestForDeathTest, ThreadsafeDeathTestInChangedDir) {
477 EXPECT_EXIT(_exit(1), testing::ExitedWithCode(1),
"");
480 ASSERT_DEATH(_exit(1),
"");
483 TEST_F(TestForDeathTest, MixedStyles) {
485 EXPECT_DEATH(_exit(1),
"");
487 EXPECT_DEATH(_exit(1),
"");
490 # if GTEST_HAS_CLONE && GTEST_HAS_PTHREAD
494 void SetPthreadFlag() {
498 TEST_F(TestForDeathTest, DoesNotExecuteAtforkHooks) {
501 pthread_flag =
false;
502 ASSERT_EQ(0, pthread_atfork(&SetPthreadFlag,
nullptr,
nullptr));
503 ASSERT_DEATH(_exit(1),
"");
508 # endif // GTEST_HAS_CLONE && GTEST_HAS_PTHREAD
511 TEST_F(TestForDeathTest, MethodOfAnotherClass) {
512 const MayDie
x(
true);
513 ASSERT_DEATH(
x.MemberFunction(),
"MayDie\\:\\:MemberFunction");
517 TEST_F(TestForDeathTest, GlobalFunction) {
518 EXPECT_DEATH(GlobalFunction(),
"GlobalFunction");
523 TEST_F(TestForDeathTest, AcceptsAnythingConvertibleToRE) {
524 static const char regex_c_str[] =
"GlobalFunction";
525 EXPECT_DEATH(GlobalFunction(), regex_c_str);
528 EXPECT_DEATH(GlobalFunction(), regex);
530 # if !GTEST_USES_PCRE
533 EXPECT_DEATH(GlobalFunction(), regex_std_str);
539 # endif // !GTEST_USES_PCRE
543 TEST_F(TestForDeathTest, NonVoidFunction) {
544 ASSERT_DEATH(NonVoidFunction(),
"NonVoidFunction");
548 TEST_F(TestForDeathTest, FunctionWithParameter) {
549 EXPECT_DEATH(DieIf(
true),
"DieIf\\(\\)");
550 EXPECT_DEATH(DieIfLessThan(2, 3),
"DieIfLessThan");
554 TEST_F(TestForDeathTest, OutsideFixture) {
555 DeathTestSubroutine();
559 TEST_F(TestForDeathTest, InsideLoop) {
560 for (
int i = 0;
i < 5;
i++) {
561 EXPECT_DEATH(DieIfLessThan(-1,
i),
"DieIfLessThan") <<
"where i == " <<
i;
566 TEST_F(TestForDeathTest, CompoundStatement) {
576 TEST_F(TestForDeathTest, DoesNotDie) {
582 TEST_F(TestForDeathTest, ErrorMessageMismatch) {
584 EXPECT_DEATH(DieIf(
true),
"DieIfLessThan") <<
"End of death test message.";
585 },
"died but not with expected error");
590 void ExpectDeathTestHelper(
bool* aborted) {
592 EXPECT_DEATH(DieIf(
false),
"DieIf");
597 TEST_F(TestForDeathTest, EXPECT_DEATH) {
605 TEST_F(TestForDeathTest, ASSERT_DEATH) {
609 ASSERT_DEATH(DieIf(
false),
"DieIf");
616 TEST_F(TestForDeathTest, SingleEvaluation) {
618 EXPECT_DEATH(DieIf((++
x) == 4),
"DieIf");
620 const char* regex =
"DieIf";
621 const char* regex_save = regex;
622 EXPECT_DEATH(DieIfLessThan(3, 4), regex++);
627 TEST_F(TestForDeathTest, RunawayIsFailure) {
634 TEST_F(TestForDeathTest, ReturnIsFailure) {
636 "illegal return in test statement.");
646 TEST_F(TestForDeathTest, TestExpectDebugDeath) {
651 const char* regex =
"death.*DieInDebugElse12";
653 EXPECT_DEBUG_DEATH(DieInDebugElse12(&sideeffect), regex)
654 <<
"Must accept a streamed message";
669 # if GTEST_OS_WINDOWS
678 TEST_F(TestForDeathTest, CRTDebugDeath) {
683 const char* regex =
"dup.* : Assertion failed";
685 EXPECT_DEBUG_DEATH(DieInCRTDebugElse12(&sideeffect), regex)
686 <<
"Must accept a streamed message";
701 # endif // GTEST_OS_WINDOWS
710 TEST_F(TestForDeathTest, TestAssertDebugDeath) {
713 ASSERT_DEBUG_DEATH(DieInDebugElse12(&sideeffect),
"death.*DieInDebugElse12")
714 <<
"Must accept a streamed message";
731 void ExpectDebugDeathHelper(
bool* aborted) {
733 EXPECT_DEBUG_DEATH(
return,
"") <<
"This is expected to fail.";
737 # if GTEST_OS_WINDOWS
738 TEST(PopUpDeathTest, DoesNotShowPopUpOnAbort) {
739 printf(
"This test should be considered failing if it shows "
740 "any pop-up dialogs.\n");
748 # endif // GTEST_OS_WINDOWS
752 TEST_F(TestForDeathTest, ExpectDebugDeathDoesNotAbort) {
758 void AssertDebugDeathHelper(
bool* aborted) {
761 ASSERT_DEBUG_DEATH(
GTEST_LOG_(
INFO) <<
"In ASSERT_DEBUG_DEATH";
return,
"")
762 <<
"This is expected to fail.";
769 TEST_F(TestForDeathTest, AssertDebugDeathAborts) {
776 TEST_F(TestForDeathTest, AssertDebugDeathAborts2) {
783 TEST_F(TestForDeathTest, AssertDebugDeathAborts3) {
790 TEST_F(TestForDeathTest, AssertDebugDeathAborts4) {
797 TEST_F(TestForDeathTest, AssertDebugDeathAborts5) {
804 TEST_F(TestForDeathTest, AssertDebugDeathAborts6) {
811 TEST_F(TestForDeathTest, AssertDebugDeathAborts7) {
818 TEST_F(TestForDeathTest, AssertDebugDeathAborts8) {
825 TEST_F(TestForDeathTest, AssertDebugDeathAborts9) {
832 TEST_F(TestForDeathTest, AssertDebugDeathAborts10) {
842 static void TestExitMacros() {
843 EXPECT_EXIT(_exit(1), testing::ExitedWithCode(1),
"");
844 ASSERT_EXIT(_exit(42), testing::ExitedWithCode(42),
"");
846 # if GTEST_OS_WINDOWS
851 EXPECT_EXIT(
raise(SIGABRT), testing::ExitedWithCode(3),
"") <<
"b_ar";
853 # elif !GTEST_OS_FUCHSIA
856 EXPECT_EXIT(
raise(
SIGKILL), testing::KilledBySignal(
SIGKILL),
"") <<
"foo";
857 ASSERT_EXIT(
raise(SIGUSR2), testing::KilledBySignal(SIGUSR2),
"") <<
"bar";
860 ASSERT_EXIT(_exit(0), testing::KilledBySignal(SIGSEGV),
"")
861 <<
"This failure is expected, too.";
862 },
"This failure is expected, too.");
864 # endif // GTEST_OS_WINDOWS
867 EXPECT_EXIT(
raise(SIGSEGV), testing::ExitedWithCode(0),
"")
868 <<
"This failure is expected.";
869 },
"This failure is expected.");
872 TEST_F(TestForDeathTest, ExitMacros) {
876 TEST_F(TestForDeathTest, ExitMacrosUsingFork) {
881 TEST_F(TestForDeathTest, InvalidStyle) {
884 EXPECT_DEATH(_exit(0),
"") <<
"This failure is expected.";
885 },
"This failure is expected.");
888 TEST_F(TestForDeathTest, DeathTestFailedOutput) {
891 EXPECT_DEATH(DieWithMessage(
"death\n"),
894 "[ DEATH ] death\n");
897 TEST_F(TestForDeathTest, DeathTestUnexpectedReturnOutput) {
901 fprintf(
stderr,
"returning\n");
905 " Result: illegal return in test statement.\n"
907 "[ DEATH ] returning\n");
910 TEST_F(TestForDeathTest, DeathTestBadExitCodeOutput) {
913 EXPECT_EXIT(DieWithMessage(
"exiting with rc 1\n"),
914 testing::ExitedWithCode(3),
916 " Result: died but not with expected exit code:\n"
917 " Exited with exit status 1\n"
919 "[ DEATH ] exiting with rc 1\n");
922 TEST_F(TestForDeathTest, DeathTestMultiLineMatchFail) {
925 EXPECT_DEATH(DieWithMessage(
"line 1\nline 2\nline 3\n"),
926 "line 1\nxyz\nline 3\n"),
930 "[ DEATH ] line 3\n");
933 TEST_F(TestForDeathTest, DeathTestMultiLineMatchPass) {
935 EXPECT_DEATH(DieWithMessage(
"line 1\nline 2\nline 3\n"),
936 "line 1\nline 2\nline 3\n");
940 class MockDeathTestFactory :
public DeathTestFactory {
942 MockDeathTestFactory();
943 bool Create(
const char* statement,
945 int line, DeathTest**
test)
override;
948 void SetParameters(
bool create, DeathTest::TestRole role,
952 int AssumeRoleCalls()
const {
return assume_role_calls_; }
953 int WaitCalls()
const {
return wait_calls_; }
954 size_t PassedCalls()
const {
return passed_args_.size(); }
955 bool PassedArgument(
int n)
const {
956 return passed_args_[
static_cast<size_t>(
n)];
958 size_t AbortCalls()
const {
return abort_args_.size(); }
959 DeathTest::AbortReason AbortArgument(
int n)
const {
960 return abort_args_[
static_cast<size_t>(
n)];
962 bool TestDeleted()
const {
return test_deleted_; }
965 friend class MockDeathTest;
970 DeathTest::TestRole role_;
977 int assume_role_calls_;
982 std::vector<bool> passed_args_;
985 std::vector<DeathTest::AbortReason> abort_args_;
996 class MockDeathTest :
public DeathTest {
998 MockDeathTest(MockDeathTestFactory *parent,
999 TestRole role,
int status,
bool passed) :
1002 ~MockDeathTest()
override {
parent_->test_deleted_ =
true; }
1003 TestRole AssumeRole()
override {
1004 ++
parent_->assume_role_calls_;
1007 int Wait()
override {
1011 bool Passed(
bool exit_status_ok)
override {
1012 parent_->passed_args_.push_back(exit_status_ok);
1015 void Abort(AbortReason reason)
override {
1016 parent_->abort_args_.push_back(reason);
1020 MockDeathTestFactory*
const parent_;
1021 const TestRole role_;
1028 MockDeathTestFactory::MockDeathTestFactory()
1030 role_(DeathTest::OVERSEE_TEST),
1033 assume_role_calls_(0),
1041 void MockDeathTestFactory::SetParameters(
bool create,
1042 DeathTest::TestRole role,
1043 int status,
bool passed) {
1049 assume_role_calls_ = 0;
1051 passed_args_.clear();
1052 abort_args_.clear();
1059 bool MockDeathTestFactory::Create(
1061 const char* ,
int , DeathTest**
test) {
1062 test_deleted_ =
false;
1064 *
test =
new MockDeathTest(
this, role_,
status_, passed_);
1076 static testing::internal::ReplaceDeathTestFactory* replacer_;
1077 static MockDeathTestFactory* factory_;
1080 factory_ =
new MockDeathTestFactory;
1081 replacer_ =
new testing::internal::ReplaceDeathTestFactory(factory_);
1086 replacer_ =
nullptr;
1094 static void RunReturningDeathTest(
bool*
flag) {
1102 testing::internal::ReplaceDeathTestFactory* MacroLogicDeathTest::replacer_ =
1104 MockDeathTestFactory* MacroLogicDeathTest::factory_ =
nullptr;
1107 TEST_F(MacroLogicDeathTest, NothingHappens) {
1109 factory_->SetParameters(
false, DeathTest::OVERSEE_TEST, 0,
true);
1110 EXPECT_DEATH(
flag =
true,
"");
1112 EXPECT_EQ(0, factory_->AssumeRoleCalls());
1122 TEST_F(MacroLogicDeathTest, ChildExitsSuccessfully) {
1124 factory_->SetParameters(
true, DeathTest::OVERSEE_TEST, 0,
true);
1125 EXPECT_DEATH(
flag =
true,
"");
1127 EXPECT_EQ(1, factory_->AssumeRoleCalls());
1137 TEST_F(MacroLogicDeathTest, ChildExitsUnsuccessfully) {
1139 factory_->SetParameters(
true, DeathTest::OVERSEE_TEST, 1,
true);
1140 EXPECT_DEATH(
flag =
true,
"");
1142 EXPECT_EQ(1, factory_->AssumeRoleCalls());
1153 TEST_F(MacroLogicDeathTest, ChildPerformsReturn) {
1155 factory_->SetParameters(
true, DeathTest::EXECUTE_TEST, 0,
true);
1156 RunReturningDeathTest(&
flag);
1158 EXPECT_EQ(1, factory_->AssumeRoleCalls());
1162 EXPECT_EQ(DeathTest::TEST_ENCOUNTERED_RETURN_STATEMENT,
1163 factory_->AbortArgument(0));
1169 TEST_F(MacroLogicDeathTest, ChildDoesNotDie) {
1171 factory_->SetParameters(
true, DeathTest::EXECUTE_TEST, 0,
true);
1172 EXPECT_DEATH(
flag =
true,
"");
1174 EXPECT_EQ(1, factory_->AssumeRoleCalls());
1184 factory_->AbortArgument(0));
1185 EXPECT_EQ(DeathTest::TEST_ENCOUNTERED_RETURN_STATEMENT,
1186 factory_->AbortArgument(1));
1192 TEST(SuccessRegistrationDeathTest, NoSuccessPart) {
1193 EXPECT_DEATH(_exit(1),
"");
1197 TEST(StreamingAssertionsDeathTest, DeathTest) {
1198 EXPECT_DEATH(_exit(1),
"") <<
"unexpected failure";
1199 ASSERT_DEATH(_exit(1),
"") <<
"unexpected failure";
1201 EXPECT_DEATH(_exit(0),
"") <<
"expected failure";
1202 },
"expected failure");
1204 ASSERT_DEATH(_exit(0),
"") <<
"expected failure";
1205 },
"expected failure");
1210 TEST(GetLastErrnoDescription, GetLastErrnoDescriptionWorks) {
1217 # if GTEST_OS_WINDOWS
1218 TEST(AutoHandleTest, AutoHandleWorks) {
1223 testing::internal::AutoHandle auto_handle(
handle);
1228 auto_handle.Reset();
1235 auto_handle.Reset(
handle);
1239 testing::internal::AutoHandle auto_handle2;
1242 # endif // GTEST_OS_WINDOWS
1244 # if GTEST_OS_WINDOWS
1245 typedef unsigned __int64 BiggestParsable;
1246 typedef signed __int64 BiggestSignedParsable;
1248 typedef unsigned long long BiggestParsable;
1249 typedef signed long long BiggestSignedParsable;
1250 # endif // GTEST_OS_WINDOWS
1254 const BiggestParsable kBiggestParsableMax = ULLONG_MAX;
1255 const BiggestSignedParsable kBiggestSignedParsableMax = LLONG_MAX;
1257 TEST(ParseNaturalNumberTest, RejectsInvalidFormat) {
1258 BiggestParsable
result = 0;
1274 TEST(ParseNaturalNumberTest, RejectsOverflownNumbers) {
1275 BiggestParsable
result = 0;
1279 signed char char_result = 0;
1284 TEST(ParseNaturalNumberTest, AcceptsValidNumbers) {
1285 BiggestParsable
result = 0;
1301 TEST(ParseNaturalNumberTest, AcceptsTypeLimits) {
1303 msg << kBiggestParsableMax;
1305 BiggestParsable
result = 0;
1310 msg2 << kBiggestSignedParsableMax;
1312 BiggestSignedParsable signed_result = 0;
1313 EXPECT_TRUE(ParseNaturalNumber(msg2.GetString(), &signed_result));
1314 EXPECT_EQ(kBiggestSignedParsableMax, signed_result);
1320 EXPECT_TRUE(ParseNaturalNumber(msg3.GetString(), &int_result));
1326 unsigned int uint_result = 0;
1327 EXPECT_TRUE(ParseNaturalNumber(msg4.GetString(), &uint_result));
1331 TEST(ParseNaturalNumberTest, WorksForShorterIntegers) {
1332 short short_result = 0;
1333 ASSERT_TRUE(ParseNaturalNumber(
"123", &short_result));
1336 signed char char_result = 0;
1337 ASSERT_TRUE(ParseNaturalNumber(
"123", &char_result));
1341 # if GTEST_OS_WINDOWS
1342 TEST(EnvironmentTest, HandleFitsIntoSizeT) {
1345 # endif // GTEST_OS_WINDOWS
1349 TEST(ConditionalDeathMacrosDeathTest, ExpectsDeathWhenDeathTestsAvailable) {
1351 "death inside CondDeathTestExpectMacro");
1353 "death inside CondDeathTestAssertMacro");
1360 TEST(InDeathTestChildDeathTest, ReportsDeathTestCorrectlyInFastStyle) {
1364 fprintf(
stderr, InDeathTestChild() ?
"Inside" :
"Outside");
1370 TEST(InDeathTestChildDeathTest, ReportsDeathTestCorrectlyInThreadSafeStyle) {
1374 fprintf(
stderr, InDeathTestChild() ?
"Inside" :
"Outside");
1380 void DieWithMessage(
const char*
message) {
1386 TEST(MatcherDeathTest, DoesNotBreakBareRegexMatching) {
1389 #if GTEST_USES_POSIX_RE
1390 EXPECT_DEATH(DieWithMessage(
"O, I die, Horatio."),
"I d[aeiou]e");
1392 EXPECT_DEATH(DieWithMessage(
"O, I die, Horatio."),
"I di?e");
1396 TEST(MatcherDeathTest, MonomorphicMatcherMatches) {
1397 EXPECT_DEATH(DieWithMessage(
"Behind O, I am slain!"),
1401 TEST(MatcherDeathTest, MonomorphicMatcherDoesNotMatch) {
1404 DieWithMessage(
"Behind O, I am slain!"),
1405 Matcher<const std::string&>(
ContainsRegex(
"Ow, I am slain"))),
1406 "Expected: contains regular expression \"Ow, I am slain\"");
1409 TEST(MatcherDeathTest, PolymorphicMatcherMatches) {
1410 EXPECT_DEATH(DieWithMessage(
"The rest is silence."),
1414 TEST(MatcherDeathTest, PolymorphicMatcherDoesNotMatch) {
1416 EXPECT_DEATH(DieWithMessage(
"The rest is silence."),
1418 "Expected: contains regular expression \"rest is science\"");
1423 #else // !GTEST_HAS_DEATH_TEST follows
1433 TEST(ConditionalDeathMacrosTest, WarnsWhenDeathTestsNotAvailable) {
1440 "Death tests are not supported on this platform"));
1453 "Death tests are not supported on this platform"));
1462 void FuncWithAssert(
int*
n) {
1469 TEST(ConditionalDeathMacrosTest, AssertDeatDoesNotReturnhIfUnsupported) {
1477 #endif // !GTEST_HAS_DEATH_TEST
1483 #pragma GCC diagnostic push
1484 #pragma GCC diagnostic ignored "-Wdangling-else"
1485 #pragma GCC diagnostic ignored "-Wempty-body"
1486 #pragma GCC diagnostic ignored "-Wpragmas"
1493 TEST(ConditionalDeathMacrosSyntaxDeathTest, SingleStatement) {
1514 #pragma GCC diagnostic pop
1519 TEST(ConditionalDeathMacrosSyntaxDeathTest, SwitchStatement) {