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
679 TEST_F(TestForDeathTest, CRTDebugDeath) {
680 EXPECT_DEATH(DieInCRTDebugElse12(
nullptr),
"dup.* : Assertion failed")
681 <<
"Must accept a streamed message";
685 # endif // GTEST_OS_WINDOWS
694 TEST_F(TestForDeathTest, TestAssertDebugDeath) {
697 ASSERT_DEBUG_DEATH(DieInDebugElse12(&sideeffect),
"death.*DieInDebugElse12")
698 <<
"Must accept a streamed message";
715 void ExpectDebugDeathHelper(
bool* aborted) {
717 EXPECT_DEBUG_DEATH(
return,
"") <<
"This is expected to fail.";
721 # if GTEST_OS_WINDOWS
722 TEST(PopUpDeathTest, DoesNotShowPopUpOnAbort) {
723 printf(
"This test should be considered failing if it shows "
724 "any pop-up dialogs.\n");
734 # endif // GTEST_OS_WINDOWS
738 TEST_F(TestForDeathTest, ExpectDebugDeathDoesNotAbort) {
744 void AssertDebugDeathHelper(
bool* aborted) {
747 ASSERT_DEBUG_DEATH(
GTEST_LOG_(
INFO) <<
"In ASSERT_DEBUG_DEATH";
return,
"")
748 <<
"This is expected to fail.";
755 TEST_F(TestForDeathTest, AssertDebugDeathAborts) {
762 TEST_F(TestForDeathTest, AssertDebugDeathAborts2) {
769 TEST_F(TestForDeathTest, AssertDebugDeathAborts3) {
776 TEST_F(TestForDeathTest, AssertDebugDeathAborts4) {
783 TEST_F(TestForDeathTest, AssertDebugDeathAborts5) {
790 TEST_F(TestForDeathTest, AssertDebugDeathAborts6) {
797 TEST_F(TestForDeathTest, AssertDebugDeathAborts7) {
804 TEST_F(TestForDeathTest, AssertDebugDeathAborts8) {
811 TEST_F(TestForDeathTest, AssertDebugDeathAborts9) {
818 TEST_F(TestForDeathTest, AssertDebugDeathAborts10) {
828 static void TestExitMacros() {
829 EXPECT_EXIT(_exit(1), testing::ExitedWithCode(1),
"");
830 ASSERT_EXIT(_exit(42), testing::ExitedWithCode(42),
"");
832 # if GTEST_OS_WINDOWS
837 EXPECT_EXIT(
raise(SIGABRT), testing::ExitedWithCode(3),
"") <<
"b_ar";
839 # elif !GTEST_OS_FUCHSIA
842 EXPECT_EXIT(
raise(
SIGKILL), testing::KilledBySignal(
SIGKILL),
"") <<
"foo";
843 ASSERT_EXIT(
raise(SIGUSR2), testing::KilledBySignal(SIGUSR2),
"") <<
"bar";
846 ASSERT_EXIT(_exit(0), testing::KilledBySignal(SIGSEGV),
"")
847 <<
"This failure is expected, too.";
848 },
"This failure is expected, too.");
850 # endif // GTEST_OS_WINDOWS
853 EXPECT_EXIT(
raise(SIGSEGV), testing::ExitedWithCode(0),
"")
854 <<
"This failure is expected.";
855 },
"This failure is expected.");
858 TEST_F(TestForDeathTest, ExitMacros) {
862 TEST_F(TestForDeathTest, ExitMacrosUsingFork) {
867 TEST_F(TestForDeathTest, InvalidStyle) {
870 EXPECT_DEATH(_exit(0),
"") <<
"This failure is expected.";
871 },
"This failure is expected.");
874 TEST_F(TestForDeathTest, DeathTestFailedOutput) {
877 EXPECT_DEATH(DieWithMessage(
"death\n"),
880 "[ DEATH ] death\n");
883 TEST_F(TestForDeathTest, DeathTestUnexpectedReturnOutput) {
887 fprintf(
stderr,
"returning\n");
891 " Result: illegal return in test statement.\n"
893 "[ DEATH ] returning\n");
896 TEST_F(TestForDeathTest, DeathTestBadExitCodeOutput) {
899 EXPECT_EXIT(DieWithMessage(
"exiting with rc 1\n"),
900 testing::ExitedWithCode(3),
902 " Result: died but not with expected exit code:\n"
903 " Exited with exit status 1\n"
905 "[ DEATH ] exiting with rc 1\n");
908 TEST_F(TestForDeathTest, DeathTestMultiLineMatchFail) {
911 EXPECT_DEATH(DieWithMessage(
"line 1\nline 2\nline 3\n"),
912 "line 1\nxyz\nline 3\n"),
916 "[ DEATH ] line 3\n");
919 TEST_F(TestForDeathTest, DeathTestMultiLineMatchPass) {
921 EXPECT_DEATH(DieWithMessage(
"line 1\nline 2\nline 3\n"),
922 "line 1\nline 2\nline 3\n");
926 class MockDeathTestFactory :
public DeathTestFactory {
928 MockDeathTestFactory();
929 bool Create(
const char* statement,
931 int line, DeathTest**
test)
override;
934 void SetParameters(
bool create, DeathTest::TestRole role,
938 int AssumeRoleCalls()
const {
return assume_role_calls_; }
939 int WaitCalls()
const {
return wait_calls_; }
940 size_t PassedCalls()
const {
return passed_args_.size(); }
941 bool PassedArgument(
int n)
const {
942 return passed_args_[
static_cast<size_t>(
n)];
944 size_t AbortCalls()
const {
return abort_args_.size(); }
945 DeathTest::AbortReason AbortArgument(
int n)
const {
946 return abort_args_[
static_cast<size_t>(
n)];
948 bool TestDeleted()
const {
return test_deleted_; }
951 friend class MockDeathTest;
956 DeathTest::TestRole role_;
963 int assume_role_calls_;
968 std::vector<bool> passed_args_;
971 std::vector<DeathTest::AbortReason> abort_args_;
982 class MockDeathTest :
public DeathTest {
984 MockDeathTest(MockDeathTestFactory *parent,
985 TestRole role,
int status,
bool passed) :
988 ~MockDeathTest()
override {
parent_->test_deleted_ =
true; }
989 TestRole AssumeRole()
override {
993 int Wait()
override {
997 bool Passed(
bool exit_status_ok)
override {
998 parent_->passed_args_.push_back(exit_status_ok);
1001 void Abort(AbortReason reason)
override {
1002 parent_->abort_args_.push_back(reason);
1006 MockDeathTestFactory*
const parent_;
1007 const TestRole role_;
1014 MockDeathTestFactory::MockDeathTestFactory()
1016 role_(DeathTest::OVERSEE_TEST),
1019 assume_role_calls_(0),
1027 void MockDeathTestFactory::SetParameters(
bool create,
1028 DeathTest::TestRole role,
1029 int status,
bool passed) {
1035 assume_role_calls_ = 0;
1037 passed_args_.clear();
1038 abort_args_.clear();
1045 bool MockDeathTestFactory::Create(
1047 const char* ,
int , DeathTest**
test) {
1048 test_deleted_ =
false;
1050 *
test =
new MockDeathTest(
this, role_,
status_, passed_);
1062 static testing::internal::ReplaceDeathTestFactory* replacer_;
1063 static MockDeathTestFactory* factory_;
1066 factory_ =
new MockDeathTestFactory;
1067 replacer_ =
new testing::internal::ReplaceDeathTestFactory(factory_);
1072 replacer_ =
nullptr;
1080 static void RunReturningDeathTest(
bool*
flag) {
1088 testing::internal::ReplaceDeathTestFactory* MacroLogicDeathTest::replacer_ =
1090 MockDeathTestFactory* MacroLogicDeathTest::factory_ =
nullptr;
1093 TEST_F(MacroLogicDeathTest, NothingHappens) {
1095 factory_->SetParameters(
false, DeathTest::OVERSEE_TEST, 0,
true);
1096 EXPECT_DEATH(
flag =
true,
"");
1098 EXPECT_EQ(0, factory_->AssumeRoleCalls());
1108 TEST_F(MacroLogicDeathTest, ChildExitsSuccessfully) {
1110 factory_->SetParameters(
true, DeathTest::OVERSEE_TEST, 0,
true);
1111 EXPECT_DEATH(
flag =
true,
"");
1113 EXPECT_EQ(1, factory_->AssumeRoleCalls());
1123 TEST_F(MacroLogicDeathTest, ChildExitsUnsuccessfully) {
1125 factory_->SetParameters(
true, DeathTest::OVERSEE_TEST, 1,
true);
1126 EXPECT_DEATH(
flag =
true,
"");
1128 EXPECT_EQ(1, factory_->AssumeRoleCalls());
1139 TEST_F(MacroLogicDeathTest, ChildPerformsReturn) {
1141 factory_->SetParameters(
true, DeathTest::EXECUTE_TEST, 0,
true);
1142 RunReturningDeathTest(&
flag);
1144 EXPECT_EQ(1, factory_->AssumeRoleCalls());
1148 EXPECT_EQ(DeathTest::TEST_ENCOUNTERED_RETURN_STATEMENT,
1149 factory_->AbortArgument(0));
1155 TEST_F(MacroLogicDeathTest, ChildDoesNotDie) {
1157 factory_->SetParameters(
true, DeathTest::EXECUTE_TEST, 0,
true);
1158 EXPECT_DEATH(
flag =
true,
"");
1160 EXPECT_EQ(1, factory_->AssumeRoleCalls());
1170 factory_->AbortArgument(0));
1171 EXPECT_EQ(DeathTest::TEST_ENCOUNTERED_RETURN_STATEMENT,
1172 factory_->AbortArgument(1));
1178 TEST(SuccessRegistrationDeathTest, NoSuccessPart) {
1179 EXPECT_DEATH(_exit(1),
"");
1183 TEST(StreamingAssertionsDeathTest, DeathTest) {
1184 EXPECT_DEATH(_exit(1),
"") <<
"unexpected failure";
1185 ASSERT_DEATH(_exit(1),
"") <<
"unexpected failure";
1187 EXPECT_DEATH(_exit(0),
"") <<
"expected failure";
1188 },
"expected failure");
1190 ASSERT_DEATH(_exit(0),
"") <<
"expected failure";
1191 },
"expected failure");
1196 TEST(GetLastErrnoDescription, GetLastErrnoDescriptionWorks) {
1203 # if GTEST_OS_WINDOWS
1204 TEST(AutoHandleTest, AutoHandleWorks) {
1209 testing::internal::AutoHandle auto_handle(
handle);
1214 auto_handle.Reset();
1221 auto_handle.Reset(
handle);
1225 testing::internal::AutoHandle auto_handle2;
1228 # endif // GTEST_OS_WINDOWS
1230 # if GTEST_OS_WINDOWS
1231 typedef unsigned __int64 BiggestParsable;
1232 typedef signed __int64 BiggestSignedParsable;
1234 typedef unsigned long long BiggestParsable;
1235 typedef signed long long BiggestSignedParsable;
1236 # endif // GTEST_OS_WINDOWS
1240 const BiggestParsable kBiggestParsableMax = ULLONG_MAX;
1241 const BiggestSignedParsable kBiggestSignedParsableMax = LLONG_MAX;
1243 TEST(ParseNaturalNumberTest, RejectsInvalidFormat) {
1244 BiggestParsable
result = 0;
1260 TEST(ParseNaturalNumberTest, RejectsOverflownNumbers) {
1261 BiggestParsable
result = 0;
1265 signed char char_result = 0;
1270 TEST(ParseNaturalNumberTest, AcceptsValidNumbers) {
1271 BiggestParsable
result = 0;
1287 TEST(ParseNaturalNumberTest, AcceptsTypeLimits) {
1289 msg << kBiggestParsableMax;
1291 BiggestParsable
result = 0;
1296 msg2 << kBiggestSignedParsableMax;
1298 BiggestSignedParsable signed_result = 0;
1299 EXPECT_TRUE(ParseNaturalNumber(msg2.GetString(), &signed_result));
1300 EXPECT_EQ(kBiggestSignedParsableMax, signed_result);
1306 EXPECT_TRUE(ParseNaturalNumber(msg3.GetString(), &int_result));
1312 unsigned int uint_result = 0;
1313 EXPECT_TRUE(ParseNaturalNumber(msg4.GetString(), &uint_result));
1317 TEST(ParseNaturalNumberTest, WorksForShorterIntegers) {
1318 short short_result = 0;
1319 ASSERT_TRUE(ParseNaturalNumber(
"123", &short_result));
1322 signed char char_result = 0;
1323 ASSERT_TRUE(ParseNaturalNumber(
"123", &char_result));
1327 # if GTEST_OS_WINDOWS
1328 TEST(EnvironmentTest, HandleFitsIntoSizeT) {
1331 # endif // GTEST_OS_WINDOWS
1335 TEST(ConditionalDeathMacrosDeathTest, ExpectsDeathWhenDeathTestsAvailable) {
1337 "death inside CondDeathTestExpectMacro");
1339 "death inside CondDeathTestAssertMacro");
1346 TEST(InDeathTestChildDeathTest, ReportsDeathTestCorrectlyInFastStyle) {
1350 fprintf(
stderr, InDeathTestChild() ?
"Inside" :
"Outside");
1356 TEST(InDeathTestChildDeathTest, ReportsDeathTestCorrectlyInThreadSafeStyle) {
1360 fprintf(
stderr, InDeathTestChild() ?
"Inside" :
"Outside");
1366 void DieWithMessage(
const char*
message) {
1372 TEST(MatcherDeathTest, DoesNotBreakBareRegexMatching) {
1375 #if GTEST_USES_POSIX_RE
1376 EXPECT_DEATH(DieWithMessage(
"O, I die, Horatio."),
"I d[aeiou]e");
1378 EXPECT_DEATH(DieWithMessage(
"O, I die, Horatio."),
"I di?e");
1382 TEST(MatcherDeathTest, MonomorphicMatcherMatches) {
1383 EXPECT_DEATH(DieWithMessage(
"Behind O, I am slain!"),
1387 TEST(MatcherDeathTest, MonomorphicMatcherDoesNotMatch) {
1390 DieWithMessage(
"Behind O, I am slain!"),
1391 Matcher<const std::string&>(
ContainsRegex(
"Ow, I am slain"))),
1392 "Expected: contains regular expression \"Ow, I am slain\"");
1395 TEST(MatcherDeathTest, PolymorphicMatcherMatches) {
1396 EXPECT_DEATH(DieWithMessage(
"The rest is silence."),
1400 TEST(MatcherDeathTest, PolymorphicMatcherDoesNotMatch) {
1402 EXPECT_DEATH(DieWithMessage(
"The rest is silence."),
1404 "Expected: contains regular expression \"rest is science\"");
1409 #else // !GTEST_HAS_DEATH_TEST follows
1419 TEST(ConditionalDeathMacrosTest, WarnsWhenDeathTestsNotAvailable) {
1426 "Death tests are not supported on this platform"));
1439 "Death tests are not supported on this platform"));
1448 void FuncWithAssert(
int*
n) {
1455 TEST(ConditionalDeathMacrosTest, AssertDeatDoesNotReturnhIfUnsupported) {
1463 #endif // !GTEST_HAS_DEATH_TEST
1469 #pragma GCC diagnostic push
1470 #pragma GCC diagnostic ignored "-Wdangling-else"
1471 #pragma GCC diagnostic ignored "-Wempty-body"
1472 #pragma GCC diagnostic ignored "-Wpragmas"
1479 TEST(ConditionalDeathMacrosSyntaxDeathTest, SingleStatement) {
1500 #pragma GCC diagnostic pop
1505 TEST(ConditionalDeathMacrosSyntaxDeathTest, SwitchStatement) {