"Fossies" - the Fresh Open Source Software Archive  

Source code changes of the file "googletest/test/googletest-death-test-test.cc" between
googletest-release-1.10.0.tar.gz and googletest-release-1.11.0.tar.gz

About: GoogleTest is Google's (unit) testing and mocking framework for C++ tests.

googletest-death-test-test.cc  (googletest-release-1.10.0):googletest-death-test-test.cc  (googletest-release-1.11.0)
skipping to change at line 301 skipping to change at line 301
const testing::KilledBySignal pred_segv(SIGSEGV); const testing::KilledBySignal pred_segv(SIGSEGV);
const testing::KilledBySignal pred_kill(SIGKILL); const testing::KilledBySignal pred_kill(SIGKILL);
EXPECT_PRED1(pred_segv, status_segv); EXPECT_PRED1(pred_segv, status_segv);
EXPECT_PRED1(pred_kill, status_kill); EXPECT_PRED1(pred_kill, status_kill);
EXPECT_FALSE(pred_segv(status_kill)); EXPECT_FALSE(pred_segv(status_kill));
EXPECT_FALSE(pred_kill(status_segv)); EXPECT_FALSE(pred_kill(status_segv));
} }
# endif // GTEST_OS_WINDOWS || GTEST_OS_FUCHSIA # endif // GTEST_OS_WINDOWS || GTEST_OS_FUCHSIA
// The following code intentionally tests a suboptimal syntax.
#ifdef __GNUC__
#pragma GCC diagnostic push
#pragma GCC diagnostic ignored "-Wdangling-else"
#pragma GCC diagnostic ignored "-Wempty-body"
#pragma GCC diagnostic ignored "-Wpragmas"
#endif
// Tests that the death test macros expand to code which may or may not // Tests that the death test macros expand to code which may or may not
// be followed by operator<<, and that in either case the complete text // be followed by operator<<, and that in either case the complete text
// comprises only a single C++ statement. // comprises only a single C++ statement.
TEST_F(TestForDeathTest, SingleStatement) { TEST_F(TestForDeathTest, SingleStatement) {
if (AlwaysFalse()) if (AlwaysFalse())
// This would fail if executed; this is a compilation test only // This would fail if executed; this is a compilation test only
ASSERT_DEATH(return, ""); ASSERT_DEATH(return, "");
if (AlwaysTrue()) if (AlwaysTrue())
EXPECT_DEATH(_exit(1), ""); EXPECT_DEATH(_exit(1), "");
skipping to change at line 324 skipping to change at line 331
; ;
if (AlwaysFalse()) if (AlwaysFalse())
ASSERT_DEATH(return, "") << "did not die"; ASSERT_DEATH(return, "") << "did not die";
if (AlwaysFalse()) if (AlwaysFalse())
; ;
else else
EXPECT_DEATH(_exit(1), "") << 1 << 2 << 3; EXPECT_DEATH(_exit(1), "") << 1 << 2 << 3;
} }
#ifdef __GNUC__
#pragma GCC diagnostic pop
#endif
# if GTEST_USES_PCRE # if GTEST_USES_PCRE
void DieWithEmbeddedNul() { void DieWithEmbeddedNul() {
fprintf(stderr, "Hello%cmy null world.\n", '\0'); fprintf(stderr, "Hello%cmy null world.\n", '\0');
fflush(stderr); fflush(stderr);
_exit(1); _exit(1);
} }
// Tests that EXPECT_DEATH and ASSERT_DEATH work when the error // Tests that EXPECT_DEATH and ASSERT_DEATH work when the error
skipping to change at line 394 skipping to change at line 404
ChangeToRootDir(); ChangeToRootDir();
ASSERT_DEATH(_exit(1), ""); ASSERT_DEATH(_exit(1), "");
} }
# if GTEST_OS_LINUX # if GTEST_OS_LINUX
void SigprofAction(int, siginfo_t*, void*) { /* no op */ } void SigprofAction(int, siginfo_t*, void*) { /* no op */ }
// Sets SIGPROF action and ITIMER_PROF timer (interval: 1ms). // Sets SIGPROF action and ITIMER_PROF timer (interval: 1ms).
void SetSigprofActionAndTimer() { void SetSigprofActionAndTimer() {
struct itimerval timer;
timer.it_interval.tv_sec = 0;
timer.it_interval.tv_usec = 1;
timer.it_value = timer.it_interval;
ASSERT_EQ(0, setitimer(ITIMER_PROF, &timer, nullptr));
struct sigaction signal_action; struct sigaction signal_action;
memset(&signal_action, 0, sizeof(signal_action)); memset(&signal_action, 0, sizeof(signal_action));
sigemptyset(&signal_action.sa_mask); sigemptyset(&signal_action.sa_mask);
signal_action.sa_sigaction = SigprofAction; signal_action.sa_sigaction = SigprofAction;
signal_action.sa_flags = SA_RESTART | SA_SIGINFO; signal_action.sa_flags = SA_RESTART | SA_SIGINFO;
ASSERT_EQ(0, sigaction(SIGPROF, &signal_action, nullptr)); ASSERT_EQ(0, sigaction(SIGPROF, &signal_action, nullptr));
// timer comes second, to avoid SIGPROF premature delivery, as suggested at
// https://www.gnu.org/software/libc/manual/html_node/Setting-an-Alarm.html
struct itimerval timer;
timer.it_interval.tv_sec = 0;
timer.it_interval.tv_usec = 1;
timer.it_value = timer.it_interval;
ASSERT_EQ(0, setitimer(ITIMER_PROF, &timer, nullptr));
} }
// Disables ITIMER_PROF timer and ignores SIGPROF signal. // Disables ITIMER_PROF timer and ignores SIGPROF signal.
void DisableSigprofActionAndTimer(struct sigaction* old_signal_action) { void DisableSigprofActionAndTimer(struct sigaction* old_signal_action) {
struct itimerval timer; struct itimerval timer;
timer.it_interval.tv_sec = 0; timer.it_interval.tv_sec = 0;
timer.it_interval.tv_usec = 0; timer.it_interval.tv_usec = 0;
timer.it_value = timer.it_interval; timer.it_value = timer.it_interval;
ASSERT_EQ(0, setitimer(ITIMER_PROF, &timer, nullptr)); ASSERT_EQ(0, setitimer(ITIMER_PROF, &timer, nullptr));
struct sigaction signal_action; struct sigaction signal_action;
skipping to change at line 1373 skipping to change at line 1385
void DieWithMessage(const char* message) { void DieWithMessage(const char* message) {
fputs(message, stderr); fputs(message, stderr);
fflush(stderr); // Make sure the text is printed before the process exits. fflush(stderr); // Make sure the text is printed before the process exits.
_exit(1); _exit(1);
} }
TEST(MatcherDeathTest, DoesNotBreakBareRegexMatching) { TEST(MatcherDeathTest, DoesNotBreakBareRegexMatching) {
// googletest tests this, of course; here we ensure that including googlemock // googletest tests this, of course; here we ensure that including googlemock
// has not broken it. // has not broken it.
#if GTEST_USES_POSIX_RE
EXPECT_DEATH(DieWithMessage("O, I die, Horatio."), "I d[aeiou]e"); EXPECT_DEATH(DieWithMessage("O, I die, Horatio."), "I d[aeiou]e");
#else
EXPECT_DEATH(DieWithMessage("O, I die, Horatio."), "I di?e");
#endif
} }
TEST(MatcherDeathTest, MonomorphicMatcherMatches) { TEST(MatcherDeathTest, MonomorphicMatcherMatches) {
EXPECT_DEATH(DieWithMessage("Behind O, I am slain!"), EXPECT_DEATH(DieWithMessage("Behind O, I am slain!"),
Matcher<const std::string&>(ContainsRegex("I am slain"))); Matcher<const std::string&>(ContainsRegex("I am slain")));
} }
TEST(MatcherDeathTest, MonomorphicMatcherDoesNotMatch) { TEST(MatcherDeathTest, MonomorphicMatcherDoesNotMatch) {
EXPECT_NONFATAL_FAILURE( EXPECT_NONFATAL_FAILURE(
EXPECT_DEATH( EXPECT_DEATH(
skipping to change at line 1461 skipping to change at line 1477
FuncWithAssert(&n); FuncWithAssert(&n);
EXPECT_EQ(1, n); EXPECT_EQ(1, n);
} }
} // namespace } // namespace
#endif // !GTEST_HAS_DEATH_TEST #endif // !GTEST_HAS_DEATH_TEST
namespace { namespace {
// The following code intentionally tests a suboptimal syntax.
#ifdef __GNUC__
#pragma GCC diagnostic push
#pragma GCC diagnostic ignored "-Wdangling-else"
#pragma GCC diagnostic ignored "-Wempty-body"
#pragma GCC diagnostic ignored "-Wpragmas"
#endif
// Tests that the death test macros expand to code which may or may not // Tests that the death test macros expand to code which may or may not
// be followed by operator<<, and that in either case the complete text // be followed by operator<<, and that in either case the complete text
// comprises only a single C++ statement. // comprises only a single C++ statement.
// //
// The syntax should work whether death tests are available or not. // The syntax should work whether death tests are available or not.
TEST(ConditionalDeathMacrosSyntaxDeathTest, SingleStatement) { TEST(ConditionalDeathMacrosSyntaxDeathTest, SingleStatement) {
if (AlwaysFalse()) if (AlwaysFalse())
// This would fail if executed; this is a compilation test only // This would fail if executed; this is a compilation test only
ASSERT_DEATH_IF_SUPPORTED(return, ""); ASSERT_DEATH_IF_SUPPORTED(return, "");
skipping to change at line 1486 skipping to change at line 1509
; // NOLINT ; // NOLINT
if (AlwaysFalse()) if (AlwaysFalse())
ASSERT_DEATH_IF_SUPPORTED(return, "") << "did not die"; ASSERT_DEATH_IF_SUPPORTED(return, "") << "did not die";
if (AlwaysFalse()) if (AlwaysFalse())
; // NOLINT ; // NOLINT
else 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
#endif
// Tests that conditional death test macros expand to code which interacts // Tests that conditional death test macros expand to code which interacts
// well with switch statements. // well with switch statements.
TEST(ConditionalDeathMacrosSyntaxDeathTest, SwitchStatement) { TEST(ConditionalDeathMacrosSyntaxDeathTest, SwitchStatement) {
// Microsoft compiler usually complains about switch statements without // Microsoft compiler usually complains about switch statements without
// case labels. We suppress that warning for this test. // case labels. We suppress that warning for this test.
GTEST_DISABLE_MSC_WARNINGS_PUSH_(4065) GTEST_DISABLE_MSC_WARNINGS_PUSH_(4065)
switch (0) switch (0)
default: default:
 End of changes. 8 change blocks. 
5 lines changed or deleted 31 lines changed or added

Home  |  About  |  Features  |  All  |  Newest  |  Dox  |  Diffs  |  RSS Feeds  |  Screenshots  |  Comments  |  Imprint  |  Privacy  |  HTTP(S)