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
304 TEST_F(TestForDeathTest, SingleStatement) {
307 ASSERT_DEATH(
return,
"");
310 EXPECT_DEATH(_exit(1),
"");
317 ASSERT_DEATH(
return,
"") <<
"did not die";
322 EXPECT_DEATH(_exit(1),
"") << 1 << 2 << 3;
327 void DieWithEmbeddedNul() {
328 fprintf(
stderr,
"Hello%cmy null world.\n",
'\0');
335 TEST_F(TestForDeathTest, EmbeddedNulInMessage) {
336 EXPECT_DEATH(DieWithEmbeddedNul(),
"my null world");
337 ASSERT_DEATH(DieWithEmbeddedNul(),
"my null world");
340 # endif // GTEST_USES_PCRE
344 TEST_F(TestForDeathTest, SwitchStatement) {
355 EXPECT_DEATH(_exit(1), "") << "exit
in switch case";
362 TEST_F(TestForDeathTest, StaticMemberFunctionFastStyle) {
364 ASSERT_DEATH(StaticMemberFunction(),
"death.*StaticMember");
369 TEST_F(TestForDeathTest, MemberFunctionFastStyle) {
372 EXPECT_DEATH(MemberFunction(),
"inside.*MemberFunction");
379 TEST_F(TestForDeathTest, FastDeathTestInChangedDir) {
383 EXPECT_EXIT(_exit(1), testing::ExitedWithCode(1),
"");
386 ASSERT_DEATH(_exit(1),
"");
390 void SigprofAction(
int, siginfo_t*,
void*) { }
393 void SetSigprofActionAndTimer() {
394 struct itimerval
timer;
395 timer.it_interval.tv_sec = 0;
396 timer.it_interval.tv_usec = 1;
408 void DisableSigprofActionAndTimer(
struct sigaction* old_signal_action) {
409 struct itimerval
timer;
410 timer.it_interval.tv_sec = 0;
411 timer.it_interval.tv_usec = 0;
422 TEST_F(TestForDeathTest, FastSigprofActionSet) {
424 SetSigprofActionAndTimer();
425 EXPECT_DEATH(_exit(1),
"");
426 struct sigaction old_signal_action;
427 DisableSigprofActionAndTimer(&old_signal_action);
428 EXPECT_TRUE(old_signal_action.sa_sigaction == SigprofAction);
431 TEST_F(TestForDeathTest, ThreadSafeSigprofActionSet) {
433 SetSigprofActionAndTimer();
434 EXPECT_DEATH(_exit(1),
"");
435 struct sigaction old_signal_action;
436 DisableSigprofActionAndTimer(&old_signal_action);
437 EXPECT_TRUE(old_signal_action.sa_sigaction == SigprofAction);
439 # endif // GTEST_OS_LINUX
443 TEST_F(TestForDeathTest, StaticMemberFunctionThreadsafeStyle) {
445 ASSERT_DEATH(StaticMemberFunction(),
"death.*StaticMember");
448 TEST_F(TestForDeathTest, MemberFunctionThreadsafeStyle) {
451 EXPECT_DEATH(MemberFunction(),
"inside.*MemberFunction");
454 TEST_F(TestForDeathTest, ThreadsafeDeathTestInLoop) {
457 for (
int i = 0;
i < 3; ++
i)
458 EXPECT_EXIT(_exit(
i), testing::ExitedWithCode(
i),
"") <<
": i = " <<
i;
461 TEST_F(TestForDeathTest, ThreadsafeDeathTestInChangedDir) {
465 EXPECT_EXIT(_exit(1), testing::ExitedWithCode(1),
"");
468 ASSERT_DEATH(_exit(1),
"");
471 TEST_F(TestForDeathTest, MixedStyles) {
473 EXPECT_DEATH(_exit(1),
"");
475 EXPECT_DEATH(_exit(1),
"");
478 # if GTEST_HAS_CLONE && GTEST_HAS_PTHREAD
482 void SetPthreadFlag() {
486 TEST_F(TestForDeathTest, DoesNotExecuteAtforkHooks) {
489 pthread_flag =
false;
490 ASSERT_EQ(0, pthread_atfork(&SetPthreadFlag,
nullptr,
nullptr));
491 ASSERT_DEATH(_exit(1),
"");
496 # endif // GTEST_HAS_CLONE && GTEST_HAS_PTHREAD
499 TEST_F(TestForDeathTest, MethodOfAnotherClass) {
500 const MayDie
x(
true);
501 ASSERT_DEATH(
x.MemberFunction(),
"MayDie\\:\\:MemberFunction");
505 TEST_F(TestForDeathTest, GlobalFunction) {
506 EXPECT_DEATH(GlobalFunction(),
"GlobalFunction");
511 TEST_F(TestForDeathTest, AcceptsAnythingConvertibleToRE) {
512 static const char regex_c_str[] =
"GlobalFunction";
513 EXPECT_DEATH(GlobalFunction(), regex_c_str);
516 EXPECT_DEATH(GlobalFunction(), regex);
518 # if !GTEST_USES_PCRE
521 EXPECT_DEATH(GlobalFunction(), regex_std_str);
527 # endif // !GTEST_USES_PCRE
531 TEST_F(TestForDeathTest, NonVoidFunction) {
532 ASSERT_DEATH(NonVoidFunction(),
"NonVoidFunction");
536 TEST_F(TestForDeathTest, FunctionWithParameter) {
537 EXPECT_DEATH(DieIf(
true),
"DieIf\\(\\)");
538 EXPECT_DEATH(DieIfLessThan(2, 3),
"DieIfLessThan");
542 TEST_F(TestForDeathTest, OutsideFixture) {
543 DeathTestSubroutine();
547 TEST_F(TestForDeathTest, InsideLoop) {
548 for (
int i = 0;
i < 5;
i++) {
549 EXPECT_DEATH(DieIfLessThan(-1,
i),
"DieIfLessThan") <<
"where i == " <<
i;
554 TEST_F(TestForDeathTest, CompoundStatement) {
564 TEST_F(TestForDeathTest, DoesNotDie) {
570 TEST_F(TestForDeathTest, ErrorMessageMismatch) {
572 EXPECT_DEATH(DieIf(
true),
"DieIfLessThan") <<
"End of death test message.";
573 },
"died but not with expected error");
578 void ExpectDeathTestHelper(
bool* aborted) {
580 EXPECT_DEATH(DieIf(
false),
"DieIf");
585 TEST_F(TestForDeathTest, EXPECT_DEATH) {
593 TEST_F(TestForDeathTest, ASSERT_DEATH) {
597 ASSERT_DEATH(DieIf(
false),
"DieIf");
604 TEST_F(TestForDeathTest, SingleEvaluation) {
606 EXPECT_DEATH(DieIf((++
x) == 4),
"DieIf");
608 const char* regex =
"DieIf";
609 const char* regex_save = regex;
610 EXPECT_DEATH(DieIfLessThan(3, 4), regex++);
615 TEST_F(TestForDeathTest, RunawayIsFailure) {
622 TEST_F(TestForDeathTest, ReturnIsFailure) {
624 "illegal return in test statement.");
634 TEST_F(TestForDeathTest, TestExpectDebugDeath) {
639 const char* regex =
"death.*DieInDebugElse12";
641 EXPECT_DEBUG_DEATH(DieInDebugElse12(&sideeffect), regex)
642 <<
"Must accept a streamed message";
657 # if GTEST_OS_WINDOWS
666 TEST_F(TestForDeathTest, CRTDebugDeath) {
671 const char* regex =
"dup.* : Assertion failed";
673 EXPECT_DEBUG_DEATH(DieInCRTDebugElse12(&sideeffect), regex)
674 <<
"Must accept a streamed message";
689 # endif // GTEST_OS_WINDOWS
698 TEST_F(TestForDeathTest, TestAssertDebugDeath) {
701 ASSERT_DEBUG_DEATH(DieInDebugElse12(&sideeffect),
"death.*DieInDebugElse12")
702 <<
"Must accept a streamed message";
719 void ExpectDebugDeathHelper(
bool* aborted) {
721 EXPECT_DEBUG_DEATH(
return,
"") <<
"This is expected to fail.";
725 # if GTEST_OS_WINDOWS
726 TEST(PopUpDeathTest, DoesNotShowPopUpOnAbort) {
727 printf(
"This test should be considered failing if it shows "
728 "any pop-up dialogs.\n");
736 # endif // GTEST_OS_WINDOWS
740 TEST_F(TestForDeathTest, ExpectDebugDeathDoesNotAbort) {
746 void AssertDebugDeathHelper(
bool* aborted) {
749 ASSERT_DEBUG_DEATH(
GTEST_LOG_(
INFO) <<
"In ASSERT_DEBUG_DEATH";
return,
"")
750 <<
"This is expected to fail.";
757 TEST_F(TestForDeathTest, AssertDebugDeathAborts) {
764 TEST_F(TestForDeathTest, AssertDebugDeathAborts2) {
771 TEST_F(TestForDeathTest, AssertDebugDeathAborts3) {
778 TEST_F(TestForDeathTest, AssertDebugDeathAborts4) {
785 TEST_F(TestForDeathTest, AssertDebugDeathAborts5) {
792 TEST_F(TestForDeathTest, AssertDebugDeathAborts6) {
799 TEST_F(TestForDeathTest, AssertDebugDeathAborts7) {
806 TEST_F(TestForDeathTest, AssertDebugDeathAborts8) {
813 TEST_F(TestForDeathTest, AssertDebugDeathAborts9) {
820 TEST_F(TestForDeathTest, AssertDebugDeathAborts10) {
830 static void TestExitMacros() {
831 EXPECT_EXIT(_exit(1), testing::ExitedWithCode(1),
"");
832 ASSERT_EXIT(_exit(42), testing::ExitedWithCode(42),
"");
834 # if GTEST_OS_WINDOWS
839 EXPECT_EXIT(
raise(SIGABRT), testing::ExitedWithCode(3),
"") <<
"b_ar";
841 # elif !GTEST_OS_FUCHSIA
844 EXPECT_EXIT(
raise(
SIGKILL), testing::KilledBySignal(
SIGKILL),
"") <<
"foo";
845 ASSERT_EXIT(
raise(SIGUSR2), testing::KilledBySignal(SIGUSR2),
"") <<
"bar";
848 ASSERT_EXIT(_exit(0), testing::KilledBySignal(SIGSEGV),
"")
849 <<
"This failure is expected, too.";
850 },
"This failure is expected, too.");
852 # endif // GTEST_OS_WINDOWS
855 EXPECT_EXIT(
raise(SIGSEGV), testing::ExitedWithCode(0),
"")
856 <<
"This failure is expected.";
857 },
"This failure is expected.");
860 TEST_F(TestForDeathTest, ExitMacros) {
864 TEST_F(TestForDeathTest, ExitMacrosUsingFork) {
869 TEST_F(TestForDeathTest, InvalidStyle) {
872 EXPECT_DEATH(_exit(0),
"") <<
"This failure is expected.";
873 },
"This failure is expected.");
876 TEST_F(TestForDeathTest, DeathTestFailedOutput) {
879 EXPECT_DEATH(DieWithMessage(
"death\n"),
882 "[ DEATH ] death\n");
885 TEST_F(TestForDeathTest, DeathTestUnexpectedReturnOutput) {
889 fprintf(
stderr,
"returning\n");
893 " Result: illegal return in test statement.\n"
895 "[ DEATH ] returning\n");
898 TEST_F(TestForDeathTest, DeathTestBadExitCodeOutput) {
901 EXPECT_EXIT(DieWithMessage(
"exiting with rc 1\n"),
902 testing::ExitedWithCode(3),
904 " Result: died but not with expected exit code:\n"
905 " Exited with exit status 1\n"
907 "[ DEATH ] exiting with rc 1\n");
910 TEST_F(TestForDeathTest, DeathTestMultiLineMatchFail) {
913 EXPECT_DEATH(DieWithMessage(
"line 1\nline 2\nline 3\n"),
914 "line 1\nxyz\nline 3\n"),
918 "[ DEATH ] line 3\n");
921 TEST_F(TestForDeathTest, DeathTestMultiLineMatchPass) {
923 EXPECT_DEATH(DieWithMessage(
"line 1\nline 2\nline 3\n"),
924 "line 1\nline 2\nline 3\n");
928 class MockDeathTestFactory :
public DeathTestFactory {
930 MockDeathTestFactory();
931 bool Create(
const char* statement,
933 int line, DeathTest**
test)
override;
936 void SetParameters(
bool create, DeathTest::TestRole role,
940 int AssumeRoleCalls()
const {
return assume_role_calls_; }
941 int WaitCalls()
const {
return wait_calls_; }
942 size_t PassedCalls()
const {
return passed_args_.size(); }
943 bool PassedArgument(
int n)
const {
944 return passed_args_[
static_cast<size_t>(
n)];
946 size_t AbortCalls()
const {
return abort_args_.size(); }
947 DeathTest::AbortReason AbortArgument(
int n)
const {
948 return abort_args_[
static_cast<size_t>(
n)];
950 bool TestDeleted()
const {
return test_deleted_; }
953 friend class MockDeathTest;
958 DeathTest::TestRole role_;
965 int assume_role_calls_;
970 std::vector<bool> passed_args_;
973 std::vector<DeathTest::AbortReason> abort_args_;
984 class MockDeathTest :
public DeathTest {
986 MockDeathTest(MockDeathTestFactory *parent,
987 TestRole role,
int status,
bool passed) :
990 ~MockDeathTest()
override {
parent_->test_deleted_ =
true; }
991 TestRole AssumeRole()
override {
995 int Wait()
override {
999 bool Passed(
bool exit_status_ok)
override {
1000 parent_->passed_args_.push_back(exit_status_ok);
1003 void Abort(AbortReason reason)
override {
1004 parent_->abort_args_.push_back(reason);
1008 MockDeathTestFactory*
const parent_;
1009 const TestRole role_;
1016 MockDeathTestFactory::MockDeathTestFactory()
1018 role_(DeathTest::OVERSEE_TEST),
1021 assume_role_calls_(0),
1029 void MockDeathTestFactory::SetParameters(
bool create,
1030 DeathTest::TestRole role,
1031 int status,
bool passed) {
1037 assume_role_calls_ = 0;
1039 passed_args_.clear();
1040 abort_args_.clear();
1047 bool MockDeathTestFactory::Create(
1049 const char* ,
int , DeathTest**
test) {
1050 test_deleted_ =
false;
1052 *
test =
new MockDeathTest(
this, role_,
status_, passed_);
1064 static testing::internal::ReplaceDeathTestFactory* replacer_;
1065 static MockDeathTestFactory* factory_;
1068 factory_ =
new MockDeathTestFactory;
1069 replacer_ =
new testing::internal::ReplaceDeathTestFactory(factory_);
1074 replacer_ =
nullptr;
1082 static void RunReturningDeathTest(
bool*
flag) {
1090 testing::internal::ReplaceDeathTestFactory* MacroLogicDeathTest::replacer_ =
1092 MockDeathTestFactory* MacroLogicDeathTest::factory_ =
nullptr;
1095 TEST_F(MacroLogicDeathTest, NothingHappens) {
1097 factory_->SetParameters(
false, DeathTest::OVERSEE_TEST, 0,
true);
1098 EXPECT_DEATH(
flag =
true,
"");
1100 EXPECT_EQ(0, factory_->AssumeRoleCalls());
1110 TEST_F(MacroLogicDeathTest, ChildExitsSuccessfully) {
1112 factory_->SetParameters(
true, DeathTest::OVERSEE_TEST, 0,
true);
1113 EXPECT_DEATH(
flag =
true,
"");
1115 EXPECT_EQ(1, factory_->AssumeRoleCalls());
1125 TEST_F(MacroLogicDeathTest, ChildExitsUnsuccessfully) {
1127 factory_->SetParameters(
true, DeathTest::OVERSEE_TEST, 1,
true);
1128 EXPECT_DEATH(
flag =
true,
"");
1130 EXPECT_EQ(1, factory_->AssumeRoleCalls());
1141 TEST_F(MacroLogicDeathTest, ChildPerformsReturn) {
1143 factory_->SetParameters(
true, DeathTest::EXECUTE_TEST, 0,
true);
1144 RunReturningDeathTest(&
flag);
1146 EXPECT_EQ(1, factory_->AssumeRoleCalls());
1150 EXPECT_EQ(DeathTest::TEST_ENCOUNTERED_RETURN_STATEMENT,
1151 factory_->AbortArgument(0));
1157 TEST_F(MacroLogicDeathTest, ChildDoesNotDie) {
1159 factory_->SetParameters(
true, DeathTest::EXECUTE_TEST, 0,
true);
1160 EXPECT_DEATH(
flag =
true,
"");
1162 EXPECT_EQ(1, factory_->AssumeRoleCalls());
1172 factory_->AbortArgument(0));
1173 EXPECT_EQ(DeathTest::TEST_ENCOUNTERED_RETURN_STATEMENT,
1174 factory_->AbortArgument(1));
1180 TEST(SuccessRegistrationDeathTest, NoSuccessPart) {
1181 EXPECT_DEATH(_exit(1),
"");
1185 TEST(StreamingAssertionsDeathTest, DeathTest) {
1186 EXPECT_DEATH(_exit(1),
"") <<
"unexpected failure";
1187 ASSERT_DEATH(_exit(1),
"") <<
"unexpected failure";
1189 EXPECT_DEATH(_exit(0),
"") <<
"expected failure";
1190 },
"expected failure");
1192 ASSERT_DEATH(_exit(0),
"") <<
"expected failure";
1193 },
"expected failure");
1198 TEST(GetLastErrnoDescription, GetLastErrnoDescriptionWorks) {
1205 # if GTEST_OS_WINDOWS
1206 TEST(AutoHandleTest, AutoHandleWorks) {
1211 testing::internal::AutoHandle auto_handle(
handle);
1216 auto_handle.Reset();
1223 auto_handle.Reset(
handle);
1227 testing::internal::AutoHandle auto_handle2;
1230 # endif // GTEST_OS_WINDOWS
1232 # if GTEST_OS_WINDOWS
1233 typedef unsigned __int64 BiggestParsable;
1234 typedef signed __int64 BiggestSignedParsable;
1236 typedef unsigned long long BiggestParsable;
1237 typedef signed long long BiggestSignedParsable;
1238 # endif // GTEST_OS_WINDOWS
1242 const BiggestParsable kBiggestParsableMax = ULLONG_MAX;
1243 const BiggestSignedParsable kBiggestSignedParsableMax = LLONG_MAX;
1245 TEST(ParseNaturalNumberTest, RejectsInvalidFormat) {
1246 BiggestParsable
result = 0;
1262 TEST(ParseNaturalNumberTest, RejectsOverflownNumbers) {
1263 BiggestParsable
result = 0;
1267 signed char char_result = 0;
1272 TEST(ParseNaturalNumberTest, AcceptsValidNumbers) {
1273 BiggestParsable
result = 0;
1289 TEST(ParseNaturalNumberTest, AcceptsTypeLimits) {
1291 msg << kBiggestParsableMax;
1293 BiggestParsable
result = 0;
1298 msg2 << kBiggestSignedParsableMax;
1300 BiggestSignedParsable signed_result = 0;
1301 EXPECT_TRUE(ParseNaturalNumber(msg2.GetString(), &signed_result));
1302 EXPECT_EQ(kBiggestSignedParsableMax, signed_result);
1308 EXPECT_TRUE(ParseNaturalNumber(msg3.GetString(), &int_result));
1314 unsigned int uint_result = 0;
1315 EXPECT_TRUE(ParseNaturalNumber(msg4.GetString(), &uint_result));
1319 TEST(ParseNaturalNumberTest, WorksForShorterIntegers) {
1320 short short_result = 0;
1321 ASSERT_TRUE(ParseNaturalNumber(
"123", &short_result));
1324 signed char char_result = 0;
1325 ASSERT_TRUE(ParseNaturalNumber(
"123", &char_result));
1329 # if GTEST_OS_WINDOWS
1330 TEST(EnvironmentTest, HandleFitsIntoSizeT) {
1333 # endif // GTEST_OS_WINDOWS
1337 TEST(ConditionalDeathMacrosDeathTest, ExpectsDeathWhenDeathTestsAvailable) {
1339 "death inside CondDeathTestExpectMacro");
1341 "death inside CondDeathTestAssertMacro");
1348 TEST(InDeathTestChildDeathTest, ReportsDeathTestCorrectlyInFastStyle) {
1352 fprintf(
stderr, InDeathTestChild() ?
"Inside" :
"Outside");
1358 TEST(InDeathTestChildDeathTest, ReportsDeathTestCorrectlyInThreadSafeStyle) {
1362 fprintf(
stderr, InDeathTestChild() ?
"Inside" :
"Outside");
1368 void DieWithMessage(
const char*
message) {
1374 TEST(MatcherDeathTest, DoesNotBreakBareRegexMatching) {
1377 EXPECT_DEATH(DieWithMessage(
"O, I die, Horatio."),
"I d[aeiou]e");
1380 TEST(MatcherDeathTest, MonomorphicMatcherMatches) {
1381 EXPECT_DEATH(DieWithMessage(
"Behind O, I am slain!"),
1385 TEST(MatcherDeathTest, MonomorphicMatcherDoesNotMatch) {
1388 DieWithMessage(
"Behind O, I am slain!"),
1389 Matcher<const std::string&>(
ContainsRegex(
"Ow, I am slain"))),
1390 "Expected: contains regular expression \"Ow, I am slain\"");
1393 TEST(MatcherDeathTest, PolymorphicMatcherMatches) {
1394 EXPECT_DEATH(DieWithMessage(
"The rest is silence."),
1398 TEST(MatcherDeathTest, PolymorphicMatcherDoesNotMatch) {
1400 EXPECT_DEATH(DieWithMessage(
"The rest is silence."),
1402 "Expected: contains regular expression \"rest is science\"");
1407 #else // !GTEST_HAS_DEATH_TEST follows
1417 TEST(ConditionalDeathMacrosTest, WarnsWhenDeathTestsNotAvailable) {
1424 "Death tests are not supported on this platform"));
1437 "Death tests are not supported on this platform"));
1446 void FuncWithAssert(
int*
n) {
1453 TEST(ConditionalDeathMacrosTest, AssertDeatDoesNotReturnhIfUnsupported) {
1461 #endif // !GTEST_HAS_DEATH_TEST
1470 TEST(ConditionalDeathMacrosSyntaxDeathTest, SingleStatement) {
1493 TEST(ConditionalDeathMacrosSyntaxDeathTest, SwitchStatement) {