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
47 # include <sys/wait.h>
48 # endif // GTEST_OS_WINDOWS
55 # include <sys/time.h>
56 # endif // GTEST_OS_LINUX
58 # include "gtest/gtest-spi.h"
59 # include "src/gtest-internal-inl.h"
61 namespace posix = ::testing::internal::posix;
66 using testing::internal::DeathTest;
67 using testing::internal::DeathTestFactory;
69 using testing::internal::GetLastErrnoDescription;
71 using testing::internal::InDeathTestChild;
72 using testing::internal::ParseNaturalNumber;
79 class ReplaceDeathTestFactory {
81 explicit ReplaceDeathTestFactory(DeathTestFactory* new_factory)
83 old_factory_ = unit_test_impl_->death_test_factory_.release();
84 unit_test_impl_->death_test_factory_.reset(new_factory);
87 ~ReplaceDeathTestFactory() {
88 unit_test_impl_->death_test_factory_.release();
89 unit_test_impl_->death_test_factory_.reset(old_factory_);
93 ReplaceDeathTestFactory(
const ReplaceDeathTestFactory&);
94 void operator=(
const ReplaceDeathTestFactory&);
96 UnitTestImpl* unit_test_impl_;
97 DeathTestFactory* old_factory_;
122 DieWithMessage(
"death inside " +
function +
"().");
129 TestForDeathTest() : original_dir_(
FilePath::GetCurrentDir()) {}
131 ~TestForDeathTest()
override {
posix::ChDir(original_dir_.c_str()); }
134 static void StaticMemberFunction() { DieInside(
"StaticMemberFunction"); }
137 void MemberFunction() {
139 DieInside(
"MemberFunction");
150 explicit MayDie(
bool should_die) : should_die_(should_die) {}
153 void MemberFunction()
const {
155 DieInside(
"MayDie::MemberFunction");
164 void GlobalFunction() { DieInside(
"GlobalFunction"); }
167 int NonVoidFunction() {
168 DieInside(
"NonVoidFunction");
173 void DieIf(
bool should_die) {
179 bool DieIfLessThan(
int x,
int y) {
181 DieInside(
"DieIfLessThan");
187 void DeathTestSubroutine() {
188 EXPECT_DEATH(GlobalFunction(),
"death.*GlobalFunction");
189 ASSERT_DEATH(GlobalFunction(),
"death.*GlobalFunction");
193 int DieInDebugElse12(
int* sideeffect) {
194 if (sideeffect) *sideeffect = 12;
198 DieInside(
"DieInDebugElse12");
205 # if GTEST_OS_WINDOWS || GTEST_OS_FUCHSIA
208 TEST(ExitStatusPredicateTest, ExitedWithCode) {
223 static int NormalExitStatus(
int exit_code) {
224 pid_t child_pid = fork();
225 if (child_pid == 0) {
229 waitpid(child_pid, &
status, 0);
238 static int KilledExitStatus(
int signum) {
239 pid_t child_pid = fork();
240 if (child_pid == 0) {
245 waitpid(child_pid, &
status, 0);
250 TEST(ExitStatusPredicateTest, ExitedWithCode) {
251 const int status0 = NormalExitStatus(0);
252 const int status1 = NormalExitStatus(1);
253 const int status42 = NormalExitStatus(42);
254 const testing::ExitedWithCode pred0(0);
255 const testing::ExitedWithCode pred1(1);
256 const testing::ExitedWithCode pred42(42);
266 TEST(ExitStatusPredicateTest, KilledBySignal) {
267 const int status_segv = KilledExitStatus(SIGSEGV);
268 const int status_kill = KilledExitStatus(
SIGKILL);
269 const testing::KilledBySignal pred_segv(SIGSEGV);
270 const testing::KilledBySignal pred_kill(
SIGKILL);
277 # endif // GTEST_OS_WINDOWS || GTEST_OS_FUCHSIA
282 TEST_F(TestForDeathTest, SingleStatement) {
285 ASSERT_DEATH(
return,
"");
288 EXPECT_DEATH(_exit(1),
"");
295 ASSERT_DEATH(
return,
"") <<
"did not die";
300 EXPECT_DEATH(_exit(1),
"") << 1 << 2 << 3;
305 void DieWithEmbeddedNul() {
306 fprintf(
stderr,
"Hello%cmy null world.\n",
'\0');
313 TEST_F(TestForDeathTest, EmbeddedNulInMessage) {
314 EXPECT_DEATH(DieWithEmbeddedNul(),
"my null world");
315 ASSERT_DEATH(DieWithEmbeddedNul(),
"my null world");
318 # endif // GTEST_USES_PCRE
322 TEST_F(TestForDeathTest, SwitchStatement) {
333 EXPECT_DEATH(_exit(1), "") << "exit
in switch case";
340 TEST_F(TestForDeathTest, StaticMemberFunctionFastStyle) {
342 ASSERT_DEATH(StaticMemberFunction(),
"death.*StaticMember");
347 TEST_F(TestForDeathTest, MemberFunctionFastStyle) {
350 EXPECT_DEATH(MemberFunction(),
"inside.*MemberFunction");
357 TEST_F(TestForDeathTest, FastDeathTestInChangedDir) {
361 EXPECT_EXIT(_exit(1), testing::ExitedWithCode(1),
"");
364 ASSERT_DEATH(_exit(1),
"");
368 void SigprofAction(
int, siginfo_t*,
void*) { }
371 void SetSigprofActionAndTimer() {
372 struct itimerval
timer;
373 timer.it_interval.tv_sec = 0;
374 timer.it_interval.tv_usec = 1;
386 void DisableSigprofActionAndTimer(
struct sigaction* old_signal_action) {
387 struct itimerval
timer;
388 timer.it_interval.tv_sec = 0;
389 timer.it_interval.tv_usec = 0;
400 TEST_F(TestForDeathTest, FastSigprofActionSet) {
402 SetSigprofActionAndTimer();
403 EXPECT_DEATH(_exit(1),
"");
404 struct sigaction old_signal_action;
405 DisableSigprofActionAndTimer(&old_signal_action);
406 EXPECT_TRUE(old_signal_action.sa_sigaction == SigprofAction);
409 TEST_F(TestForDeathTest, ThreadSafeSigprofActionSet) {
411 SetSigprofActionAndTimer();
412 EXPECT_DEATH(_exit(1),
"");
413 struct sigaction old_signal_action;
414 DisableSigprofActionAndTimer(&old_signal_action);
415 EXPECT_TRUE(old_signal_action.sa_sigaction == SigprofAction);
417 # endif // GTEST_OS_LINUX
421 TEST_F(TestForDeathTest, StaticMemberFunctionThreadsafeStyle) {
423 ASSERT_DEATH(StaticMemberFunction(),
"death.*StaticMember");
426 TEST_F(TestForDeathTest, MemberFunctionThreadsafeStyle) {
429 EXPECT_DEATH(MemberFunction(),
"inside.*MemberFunction");
432 TEST_F(TestForDeathTest, ThreadsafeDeathTestInLoop) {
435 for (
int i = 0;
i < 3; ++
i)
436 EXPECT_EXIT(_exit(
i), testing::ExitedWithCode(
i),
"") <<
": i = " <<
i;
439 TEST_F(TestForDeathTest, ThreadsafeDeathTestInChangedDir) {
443 EXPECT_EXIT(_exit(1), testing::ExitedWithCode(1),
"");
446 ASSERT_DEATH(_exit(1),
"");
449 TEST_F(TestForDeathTest, MixedStyles) {
451 EXPECT_DEATH(_exit(1),
"");
453 EXPECT_DEATH(_exit(1),
"");
456 # if GTEST_HAS_CLONE && GTEST_HAS_PTHREAD
460 void SetPthreadFlag() {
464 TEST_F(TestForDeathTest, DoesNotExecuteAtforkHooks) {
467 pthread_flag =
false;
468 ASSERT_EQ(0, pthread_atfork(&SetPthreadFlag,
nullptr,
nullptr));
469 ASSERT_DEATH(_exit(1),
"");
474 # endif // GTEST_HAS_CLONE && GTEST_HAS_PTHREAD
477 TEST_F(TestForDeathTest, MethodOfAnotherClass) {
478 const MayDie
x(
true);
479 ASSERT_DEATH(
x.MemberFunction(),
"MayDie\\:\\:MemberFunction");
483 TEST_F(TestForDeathTest, GlobalFunction) {
484 EXPECT_DEATH(GlobalFunction(),
"GlobalFunction");
489 TEST_F(TestForDeathTest, AcceptsAnythingConvertibleToRE) {
490 static const char regex_c_str[] =
"GlobalFunction";
491 EXPECT_DEATH(GlobalFunction(), regex_c_str);
494 EXPECT_DEATH(GlobalFunction(), regex);
496 # if GTEST_HAS_GLOBAL_STRING
499 EXPECT_DEATH(GlobalFunction(), regex_str);
503 EXPECT_DEATH(GlobalFunction(), ::
string(regex_c_str).
c_str());
505 # endif // GTEST_HAS_GLOBAL_STRING
507 # if !GTEST_USES_PCRE
510 EXPECT_DEATH(GlobalFunction(), regex_std_str);
516 # endif // !GTEST_USES_PCRE
520 TEST_F(TestForDeathTest, NonVoidFunction) {
521 ASSERT_DEATH(NonVoidFunction(),
"NonVoidFunction");
525 TEST_F(TestForDeathTest, FunctionWithParameter) {
526 EXPECT_DEATH(DieIf(
true),
"DieIf\\(\\)");
527 EXPECT_DEATH(DieIfLessThan(2, 3),
"DieIfLessThan");
531 TEST_F(TestForDeathTest, OutsideFixture) {
532 DeathTestSubroutine();
536 TEST_F(TestForDeathTest, InsideLoop) {
537 for (
int i = 0;
i < 5;
i++) {
538 EXPECT_DEATH(DieIfLessThan(-1,
i),
"DieIfLessThan") <<
"where i == " <<
i;
543 TEST_F(TestForDeathTest, CompoundStatement) {
553 TEST_F(TestForDeathTest, DoesNotDie) {
559 TEST_F(TestForDeathTest, ErrorMessageMismatch) {
561 EXPECT_DEATH(DieIf(
true),
"DieIfLessThan") <<
"End of death test message.";
562 },
"died but not with expected error");
567 void ExpectDeathTestHelper(
bool* aborted) {
569 EXPECT_DEATH(DieIf(
false),
"DieIf");
574 TEST_F(TestForDeathTest, EXPECT_DEATH) {
582 TEST_F(TestForDeathTest, ASSERT_DEATH) {
586 ASSERT_DEATH(DieIf(
false),
"DieIf");
593 TEST_F(TestForDeathTest, SingleEvaluation) {
595 EXPECT_DEATH(DieIf((++
x) == 4),
"DieIf");
597 const char* regex =
"DieIf";
598 const char* regex_save = regex;
599 EXPECT_DEATH(DieIfLessThan(3, 4), regex++);
604 TEST_F(TestForDeathTest, RunawayIsFailure) {
611 TEST_F(TestForDeathTest, ReturnIsFailure) {
613 "illegal return in test statement.");
623 TEST_F(TestForDeathTest, TestExpectDebugDeath) {
628 const char* regex =
"death.*DieInDebugElse12";
630 EXPECT_DEBUG_DEATH(DieInDebugElse12(&sideeffect), regex)
631 <<
"Must accept a streamed message";
653 TEST_F(TestForDeathTest, TestAssertDebugDeath) {
656 ASSERT_DEBUG_DEATH(DieInDebugElse12(&sideeffect),
"death.*DieInDebugElse12")
657 <<
"Must accept a streamed message";
674 void ExpectDebugDeathHelper(
bool* aborted) {
676 EXPECT_DEBUG_DEATH(
return,
"") <<
"This is expected to fail.";
680 # if GTEST_OS_WINDOWS
681 TEST(PopUpDeathTest, DoesNotShowPopUpOnAbort) {
682 printf(
"This test should be considered failing if it shows "
683 "any pop-up dialogs.\n");
691 # endif // GTEST_OS_WINDOWS
695 TEST_F(TestForDeathTest, ExpectDebugDeathDoesNotAbort) {
701 void AssertDebugDeathHelper(
bool* aborted) {
704 ASSERT_DEBUG_DEATH(
GTEST_LOG_(
INFO) <<
"In ASSERT_DEBUG_DEATH";
return,
"")
705 <<
"This is expected to fail.";
712 TEST_F(TestForDeathTest, AssertDebugDeathAborts) {
719 TEST_F(TestForDeathTest, AssertDebugDeathAborts2) {
726 TEST_F(TestForDeathTest, AssertDebugDeathAborts3) {
733 TEST_F(TestForDeathTest, AssertDebugDeathAborts4) {
740 TEST_F(TestForDeathTest, AssertDebugDeathAborts5) {
747 TEST_F(TestForDeathTest, AssertDebugDeathAborts6) {
754 TEST_F(TestForDeathTest, AssertDebugDeathAborts7) {
761 TEST_F(TestForDeathTest, AssertDebugDeathAborts8) {
768 TEST_F(TestForDeathTest, AssertDebugDeathAborts9) {
775 TEST_F(TestForDeathTest, AssertDebugDeathAborts10) {
785 static void TestExitMacros() {
786 EXPECT_EXIT(_exit(1), testing::ExitedWithCode(1),
"");
787 ASSERT_EXIT(_exit(42), testing::ExitedWithCode(42),
"");
789 # if GTEST_OS_WINDOWS
794 EXPECT_EXIT(
raise(SIGABRT), testing::ExitedWithCode(3),
"") <<
"b_ar";
796 # elif !GTEST_OS_FUCHSIA
799 EXPECT_EXIT(
raise(
SIGKILL), testing::KilledBySignal(
SIGKILL),
"") <<
"foo";
800 ASSERT_EXIT(
raise(SIGUSR2), testing::KilledBySignal(SIGUSR2),
"") <<
"bar";
803 ASSERT_EXIT(_exit(0), testing::KilledBySignal(SIGSEGV),
"")
804 <<
"This failure is expected, too.";
805 },
"This failure is expected, too.");
807 # endif // GTEST_OS_WINDOWS
810 EXPECT_EXIT(
raise(SIGSEGV), testing::ExitedWithCode(0),
"")
811 <<
"This failure is expected.";
812 },
"This failure is expected.");
815 TEST_F(TestForDeathTest, ExitMacros) {
819 TEST_F(TestForDeathTest, ExitMacrosUsingFork) {
824 TEST_F(TestForDeathTest, InvalidStyle) {
827 EXPECT_DEATH(_exit(0),
"") <<
"This failure is expected.";
828 },
"This failure is expected.");
831 TEST_F(TestForDeathTest, DeathTestFailedOutput) {
834 EXPECT_DEATH(DieWithMessage(
"death\n"),
837 "[ DEATH ] death\n");
840 TEST_F(TestForDeathTest, DeathTestUnexpectedReturnOutput) {
844 fprintf(
stderr,
"returning\n");
848 " Result: illegal return in test statement.\n"
850 "[ DEATH ] returning\n");
853 TEST_F(TestForDeathTest, DeathTestBadExitCodeOutput) {
856 EXPECT_EXIT(DieWithMessage(
"exiting with rc 1\n"),
857 testing::ExitedWithCode(3),
859 " Result: died but not with expected exit code:\n"
860 " Exited with exit status 1\n"
862 "[ DEATH ] exiting with rc 1\n");
865 TEST_F(TestForDeathTest, DeathTestMultiLineMatchFail) {
868 EXPECT_DEATH(DieWithMessage(
"line 1\nline 2\nline 3\n"),
869 "line 1\nxyz\nline 3\n"),
873 "[ DEATH ] line 3\n");
876 TEST_F(TestForDeathTest, DeathTestMultiLineMatchPass) {
878 EXPECT_DEATH(DieWithMessage(
"line 1\nline 2\nline 3\n"),
879 "line 1\nline 2\nline 3\n");
883 class MockDeathTestFactory :
public DeathTestFactory {
885 MockDeathTestFactory();
886 bool Create(
const char* statement,
888 int line, DeathTest**
test)
override;
891 void SetParameters(
bool create, DeathTest::TestRole role,
895 int AssumeRoleCalls()
const {
return assume_role_calls_; }
896 int WaitCalls()
const {
return wait_calls_; }
897 size_t PassedCalls()
const {
return passed_args_.size(); }
898 bool PassedArgument(
int n)
const {
return passed_args_[
n]; }
899 size_t AbortCalls()
const {
return abort_args_.size(); }
900 DeathTest::AbortReason AbortArgument(
int n)
const {
901 return abort_args_[
n];
903 bool TestDeleted()
const {
return test_deleted_; }
906 friend class MockDeathTest;
911 DeathTest::TestRole role_;
918 int assume_role_calls_;
923 std::vector<bool> passed_args_;
926 std::vector<DeathTest::AbortReason> abort_args_;
937 class MockDeathTest :
public DeathTest {
939 MockDeathTest(MockDeathTestFactory *parent,
940 TestRole role,
int status,
bool passed) :
943 ~MockDeathTest()
override {
parent_->test_deleted_ =
true; }
944 TestRole AssumeRole()
override {
948 int Wait()
override {
952 bool Passed(
bool exit_status_ok)
override {
953 parent_->passed_args_.push_back(exit_status_ok);
956 void Abort(AbortReason reason)
override {
957 parent_->abort_args_.push_back(reason);
961 MockDeathTestFactory*
const parent_;
962 const TestRole role_;
969 MockDeathTestFactory::MockDeathTestFactory()
971 role_(DeathTest::OVERSEE_TEST),
974 assume_role_calls_(0),
982 void MockDeathTestFactory::SetParameters(
bool create,
983 DeathTest::TestRole role,
984 int status,
bool passed) {
990 assume_role_calls_ = 0;
992 passed_args_.clear();
1000 bool MockDeathTestFactory::Create(
1002 const char* ,
int , DeathTest**
test) {
1003 test_deleted_ =
false;
1005 *
test =
new MockDeathTest(
this, role_,
status_, passed_);
1017 static testing::internal::ReplaceDeathTestFactory* replacer_;
1018 static MockDeathTestFactory* factory_;
1021 factory_ =
new MockDeathTestFactory;
1022 replacer_ =
new testing::internal::ReplaceDeathTestFactory(factory_);
1027 replacer_ =
nullptr;
1035 static void RunReturningDeathTest(
bool*
flag) {
1043 testing::internal::ReplaceDeathTestFactory* MacroLogicDeathTest::replacer_ =
1045 MockDeathTestFactory* MacroLogicDeathTest::factory_ =
nullptr;
1048 TEST_F(MacroLogicDeathTest, NothingHappens) {
1050 factory_->SetParameters(
false, DeathTest::OVERSEE_TEST, 0,
true);
1051 EXPECT_DEATH(
flag =
true,
"");
1053 EXPECT_EQ(0, factory_->AssumeRoleCalls());
1063 TEST_F(MacroLogicDeathTest, ChildExitsSuccessfully) {
1065 factory_->SetParameters(
true, DeathTest::OVERSEE_TEST, 0,
true);
1066 EXPECT_DEATH(
flag =
true,
"");
1068 EXPECT_EQ(1, factory_->AssumeRoleCalls());
1078 TEST_F(MacroLogicDeathTest, ChildExitsUnsuccessfully) {
1080 factory_->SetParameters(
true, DeathTest::OVERSEE_TEST, 1,
true);
1081 EXPECT_DEATH(
flag =
true,
"");
1083 EXPECT_EQ(1, factory_->AssumeRoleCalls());
1094 TEST_F(MacroLogicDeathTest, ChildPerformsReturn) {
1096 factory_->SetParameters(
true, DeathTest::EXECUTE_TEST, 0,
true);
1097 RunReturningDeathTest(&
flag);
1099 EXPECT_EQ(1, factory_->AssumeRoleCalls());
1103 EXPECT_EQ(DeathTest::TEST_ENCOUNTERED_RETURN_STATEMENT,
1104 factory_->AbortArgument(0));
1110 TEST_F(MacroLogicDeathTest, ChildDoesNotDie) {
1112 factory_->SetParameters(
true, DeathTest::EXECUTE_TEST, 0,
true);
1113 EXPECT_DEATH(
flag =
true,
"");
1115 EXPECT_EQ(1, factory_->AssumeRoleCalls());
1125 factory_->AbortArgument(0));
1126 EXPECT_EQ(DeathTest::TEST_ENCOUNTERED_RETURN_STATEMENT,
1127 factory_->AbortArgument(1));
1133 TEST(SuccessRegistrationDeathTest, NoSuccessPart) {
1134 EXPECT_DEATH(_exit(1),
"");
1138 TEST(StreamingAssertionsDeathTest, DeathTest) {
1139 EXPECT_DEATH(_exit(1),
"") <<
"unexpected failure";
1140 ASSERT_DEATH(_exit(1),
"") <<
"unexpected failure";
1142 EXPECT_DEATH(_exit(0),
"") <<
"expected failure";
1143 },
"expected failure");
1145 ASSERT_DEATH(_exit(0),
"") <<
"expected failure";
1146 },
"expected failure");
1151 TEST(GetLastErrnoDescription, GetLastErrnoDescriptionWorks) {
1158 # if GTEST_OS_WINDOWS
1159 TEST(AutoHandleTest, AutoHandleWorks) {
1164 testing::internal::AutoHandle auto_handle(
handle);
1169 auto_handle.Reset();
1176 auto_handle.Reset(
handle);
1180 testing::internal::AutoHandle auto_handle2;
1183 # endif // GTEST_OS_WINDOWS
1185 # if GTEST_OS_WINDOWS
1186 typedef unsigned __int64 BiggestParsable;
1187 typedef signed __int64 BiggestSignedParsable;
1189 typedef unsigned long long BiggestParsable;
1190 typedef signed long long BiggestSignedParsable;
1191 # endif // GTEST_OS_WINDOWS
1195 const BiggestParsable kBiggestParsableMax = ULLONG_MAX;
1196 const BiggestSignedParsable kBiggestSignedParsableMax = LLONG_MAX;
1198 TEST(ParseNaturalNumberTest, RejectsInvalidFormat) {
1199 BiggestParsable
result = 0;
1215 TEST(ParseNaturalNumberTest, RejectsOverflownNumbers) {
1216 BiggestParsable
result = 0;
1220 signed char char_result = 0;
1225 TEST(ParseNaturalNumberTest, AcceptsValidNumbers) {
1226 BiggestParsable
result = 0;
1242 TEST(ParseNaturalNumberTest, AcceptsTypeLimits) {
1244 msg << kBiggestParsableMax;
1246 BiggestParsable
result = 0;
1251 msg2 << kBiggestSignedParsableMax;
1253 BiggestSignedParsable signed_result = 0;
1254 EXPECT_TRUE(ParseNaturalNumber(msg2.GetString(), &signed_result));
1255 EXPECT_EQ(kBiggestSignedParsableMax, signed_result);
1261 EXPECT_TRUE(ParseNaturalNumber(msg3.GetString(), &int_result));
1267 unsigned int uint_result = 0;
1268 EXPECT_TRUE(ParseNaturalNumber(msg4.GetString(), &uint_result));
1272 TEST(ParseNaturalNumberTest, WorksForShorterIntegers) {
1273 short short_result = 0;
1274 ASSERT_TRUE(ParseNaturalNumber(
"123", &short_result));
1277 signed char char_result = 0;
1278 ASSERT_TRUE(ParseNaturalNumber(
"123", &char_result));
1282 # if GTEST_OS_WINDOWS
1283 TEST(EnvironmentTest, HandleFitsIntoSizeT) {
1286 # endif // GTEST_OS_WINDOWS
1290 TEST(ConditionalDeathMacrosDeathTest, ExpectsDeathWhenDeathTestsAvailable) {
1292 "death inside CondDeathTestExpectMacro");
1294 "death inside CondDeathTestAssertMacro");
1301 TEST(InDeathTestChildDeathTest, ReportsDeathTestCorrectlyInFastStyle) {
1305 fprintf(
stderr, InDeathTestChild() ?
"Inside" :
"Outside");
1311 TEST(InDeathTestChildDeathTest, ReportsDeathTestCorrectlyInThreadSafeStyle) {
1315 fprintf(
stderr, InDeathTestChild() ?
"Inside" :
"Outside");
1321 void DieWithMessage(
const char*
message) {
1327 TEST(MatcherDeathTest, DoesNotBreakBareRegexMatching) {
1330 EXPECT_DEATH(DieWithMessage(
"O, I die, Horatio."),
"I d[aeiou]e");
1333 TEST(MatcherDeathTest, MonomorphicMatcherMatches) {
1334 EXPECT_DEATH(DieWithMessage(
"Behind O, I am slain!"),
1338 TEST(MatcherDeathTest, MonomorphicMatcherDoesNotMatch) {
1341 DieWithMessage(
"Behind O, I am slain!"),
1342 Matcher<const std::string&>(
ContainsRegex(
"Ow, I am slain"))),
1343 "Expected: contains regular expression \"Ow, I am slain\"");
1346 TEST(MatcherDeathTest, PolymorphicMatcherMatches) {
1347 EXPECT_DEATH(DieWithMessage(
"The rest is silence."),
1351 TEST(MatcherDeathTest, PolymorphicMatcherDoesNotMatch) {
1353 EXPECT_DEATH(DieWithMessage(
"The rest is silence."),
1355 "Expected: contains regular expression \"rest is science\"");
1360 #else // !GTEST_HAS_DEATH_TEST follows
1370 TEST(ConditionalDeathMacrosTest, WarnsWhenDeathTestsNotAvailable) {
1377 "Death tests are not supported on this platform"));
1390 "Death tests are not supported on this platform"));
1399 void FuncWithAssert(
int*
n) {
1406 TEST(ConditionalDeathMacrosTest, AssertDeatDoesNotReturnhIfUnsupported) {
1414 #endif // !GTEST_HAS_DEATH_TEST
1423 TEST(ConditionalDeathMacrosSyntaxDeathTest, SingleStatement) {
1446 TEST(ConditionalDeathMacrosSyntaxDeathTest, SwitchStatement) {