Skip to content
Projects
Groups
Snippets
Help
This project
Loading...
Sign in / Register
Toggle navigation
G
googletest
Project
Overview
Details
Activity
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Board
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
Chen Yisong
googletest
Commits
172b233a
Commit
172b233a
authored
Mar 02, 2010
by
vladlosev
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Modifies gtest-death-test_test not to use core-dumping API calls.
parent
fe787609
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
25 additions
and
28 deletions
+25
-28
gtest-death-test_test.cc
test/gtest-death-test_test.cc
+25
-28
No files found.
test/gtest-death-test_test.cc
View file @
172b233a
...
@@ -103,6 +103,16 @@ class ReplaceDeathTestFactory {
...
@@ -103,6 +103,16 @@ class ReplaceDeathTestFactory {
}
// namespace internal
}
// namespace internal
}
// namespace testing
}
// namespace testing
void
DieInside
(
const
char
*
function
)
{
fprintf
(
stderr
,
"death inside %s()."
,
function
);
fflush
(
stderr
);
// We call _exit() instead of exit(), as the former is a direct
// system call and thus safer in the presence of threads. exit()
// will invoke user-defined exit-hooks, which may do dangerous
// things that conflict with death tests.
_exit
(
1
);
}
// Tests that death tests work.
// Tests that death tests work.
class
TestForDeathTest
:
public
testing
::
Test
{
class
TestForDeathTest
:
public
testing
::
Test
{
...
@@ -114,23 +124,12 @@ class TestForDeathTest : public testing::Test {
...
@@ -114,23 +124,12 @@ class TestForDeathTest : public testing::Test {
}
}
// A static member function that's expected to die.
// A static member function that's expected to die.
static
void
StaticMemberFunction
()
{
static
void
StaticMemberFunction
()
{
DieInside
(
"StaticMemberFunction"
);
}
fprintf
(
stderr
,
"%s"
,
"death inside StaticMemberFunction()."
);
fflush
(
stderr
);
// We call _exit() instead of exit(), as the former is a direct
// system call and thus safer in the presence of threads. exit()
// will invoke user-defined exit-hooks, which may do dangerous
// things that conflict with death tests.
_exit
(
1
);
}
// A method of the test fixture that may die.
// A method of the test fixture that may die.
void
MemberFunction
()
{
void
MemberFunction
()
{
if
(
should_die_
)
{
if
(
should_die_
)
fprintf
(
stderr
,
"%s"
,
"death inside MemberFunction()."
);
DieInside
(
"MemberFunction"
);
fflush
(
stderr
);
_exit
(
1
);
}
}
}
// True iff MemberFunction() should die.
// True iff MemberFunction() should die.
...
@@ -145,9 +144,8 @@ class MayDie {
...
@@ -145,9 +144,8 @@ class MayDie {
// A member function that may die.
// A member function that may die.
void
MemberFunction
()
const
{
void
MemberFunction
()
const
{
if
(
should_die_
)
{
if
(
should_die_
)
GTEST_LOG_
(
FATAL
)
<<
"death inside MayDie::MemberFunction()."
;
DieInside
(
"MayDie::MemberFunction"
);
}
}
}
private
:
private
:
...
@@ -156,27 +154,24 @@ class MayDie {
...
@@ -156,27 +154,24 @@ class MayDie {
};
};
// A global function that's expected to die.
// A global function that's expected to die.
void
GlobalFunction
()
{
void
GlobalFunction
()
{
DieInside
(
"GlobalFunction"
);
}
GTEST_LOG_
(
FATAL
)
<<
"death inside GlobalFunction()."
;
}
// A non-void function that's expected to die.
// A non-void function that's expected to die.
int
NonVoidFunction
()
{
int
NonVoidFunction
()
{
GTEST_LOG_
(
FATAL
)
<<
"death inside NonVoidFunction()."
;
DieInside
(
"NonVoidFunction"
)
;
return
1
;
return
1
;
}
}
// A unary function that may die.
// A unary function that may die.
void
DieIf
(
bool
should_die
)
{
void
DieIf
(
bool
should_die
)
{
if
(
should_die
)
{
if
(
should_die
)
GTEST_LOG_
(
FATAL
)
<<
"death inside DieIf()."
;
DieInside
(
"DieIf"
);
}
}
}
// A binary function that may die.
// A binary function that may die.
bool
DieIfLessThan
(
int
x
,
int
y
)
{
bool
DieIfLessThan
(
int
x
,
int
y
)
{
if
(
x
<
y
)
{
if
(
x
<
y
)
{
GTEST_LOG_
(
FATAL
)
<<
"death inside DieIfLessThan()."
;
DieInside
(
"DieIfLessThan"
)
;
}
}
return
true
;
return
true
;
}
}
...
@@ -191,7 +186,7 @@ void DeathTestSubroutine() {
...
@@ -191,7 +186,7 @@ void DeathTestSubroutine() {
int
DieInDebugElse12
(
int
*
sideeffect
)
{
int
DieInDebugElse12
(
int
*
sideeffect
)
{
if
(
sideeffect
)
*
sideeffect
=
12
;
if
(
sideeffect
)
*
sideeffect
=
12
;
#ifndef NDEBUG
#ifndef NDEBUG
GTEST_LOG_
(
FATAL
)
<<
"debug death inside DieInDebugElse12()"
;
DieInside
(
"DieInDebugElse12"
)
;
#endif // NDEBUG
#endif // NDEBUG
return
12
;
return
12
;
}
}
...
@@ -1111,8 +1106,10 @@ TEST(EnvironmentTest, HandleFitsIntoSizeT) {
...
@@ -1111,8 +1106,10 @@ TEST(EnvironmentTest, HandleFitsIntoSizeT) {
// Tests that EXPECT_DEATH_IF_SUPPORTED/ASSERT_DEATH_IF_SUPPORTED trigger
// Tests that EXPECT_DEATH_IF_SUPPORTED/ASSERT_DEATH_IF_SUPPORTED trigger
// failures when death tests are available on the system.
// failures when death tests are available on the system.
TEST
(
ConditionalDeathMacrosDeathTest
,
ExpectsDeathWhenDeathTestsAvailable
)
{
TEST
(
ConditionalDeathMacrosDeathTest
,
ExpectsDeathWhenDeathTestsAvailable
)
{
EXPECT_DEATH_IF_SUPPORTED
(
GTEST_CHECK_
(
false
)
<<
"failure"
,
"false.*failure"
);
EXPECT_DEATH_IF_SUPPORTED
(
DieInside
(
"CondDeathTestExpectMacro"
),
ASSERT_DEATH_IF_SUPPORTED
(
GTEST_CHECK_
(
false
)
<<
"failure"
,
"false.*failure"
);
"death inside CondDeathTestExpectMacro"
);
ASSERT_DEATH_IF_SUPPORTED
(
DieInside
(
"CondDeathTestAssertMacro"
),
"death inside CondDeathTestAssertMacro"
);
// Empty statement will not crash, which must trigger a failure.
// Empty statement will not crash, which must trigger a failure.
EXPECT_NONFATAL_FAILURE
(
EXPECT_DEATH_IF_SUPPORTED
(;,
""
),
""
);
EXPECT_NONFATAL_FAILURE
(
EXPECT_DEATH_IF_SUPPORTED
(;,
""
),
""
);
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment