Skip to content
GitLab
Menu
Projects
Groups
Snippets
Loading...
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
Menu
Open sidebar
yangql
googletest
Commits
69a40b7d
Commit
69a40b7d
authored
Oct 05, 2011
by
vladlosev
Browse files
Adds ability to inject death test child arguments for test purposes.
parent
879916a9
Changes
3
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
27 additions
and
9 deletions
+27
-9
include/gtest/internal/gtest-port.h
include/gtest/internal/gtest-port.h
+6
-5
src/gtest-death-test.cc
src/gtest-death-test.cc
+6
-1
src/gtest-port.cc
src/gtest-port.cc
+15
-3
No files found.
include/gtest/internal/gtest-port.h
View file @
69a40b7d
...
@@ -177,7 +177,7 @@
...
@@ -177,7 +177,7 @@
// GTEST_FLAG() - references a flag.
// GTEST_FLAG() - references a flag.
// GTEST_DECLARE_*() - declares a flag.
// GTEST_DECLARE_*() - declares a flag.
// GTEST_DEFINE_*() - defines a flag.
// GTEST_DEFINE_*() - defines a flag.
// Get
Argvs()
- returns the command line as a vector of strings.
// Get
InjectableArgvs()
- returns the command line as a vector of strings.
//
//
// Environment variable utilities:
// Environment variable utilities:
// GetEnv() - gets the value of an environment variable.
// GetEnv() - gets the value of an environment variable.
...
@@ -1069,11 +1069,12 @@ GTEST_API_ String GetCapturedStderr();
...
@@ -1069,11 +1069,12 @@ GTEST_API_ String GetCapturedStderr();
#if GTEST_HAS_DEATH_TEST
#if GTEST_HAS_DEATH_TEST
// A copy of all command line arguments. Set by InitGoogleTest().
const
::
std
::
vector
<
testing
::
internal
::
string
>&
GetInjectableArgvs
();
extern
::
std
::
vector
<
String
>
g_argvs
;
void
SetInjectableArgvs
(
const
::
std
::
vector
<
testing
::
internal
::
string
>*
new_argvs
);
//
GTEST_HAS_DEATH_TEST implies we have ::std::string
.
//
A copy of all command line arguments. Set by InitGoogleTest()
.
const
::
std
::
vector
<
String
>&
GetA
rgvs
()
;
extern
::
std
::
vector
<
testing
::
internal
::
string
>
g_a
rgvs
;
#endif // GTEST_HAS_DEATH_TEST
#endif // GTEST_HAS_DEATH_TEST
...
...
src/gtest-death-test.cc
View file @
69a40b7d
...
@@ -844,6 +844,11 @@ class ExecDeathTest : public ForkingDeathTest {
...
@@ -844,6 +844,11 @@ class ExecDeathTest : public ForkingDeathTest {
ForkingDeathTest
(
a_statement
,
a_regex
),
file_
(
file
),
line_
(
line
)
{
}
ForkingDeathTest
(
a_statement
,
a_regex
),
file_
(
file
),
line_
(
line
)
{
}
virtual
TestRole
AssumeRole
();
virtual
TestRole
AssumeRole
();
private:
private:
static
::
std
::
vector
<
testing
::
internal
::
string
>
GetArgvsForDeathTestChildProcess
()
{
::
std
::
vector
<
testing
::
internal
::
string
>
args
=
GetInjectableArgvs
();
return
args
;
}
// The name of the file in which the death test is located.
// The name of the file in which the death test is located.
const
char
*
const
file_
;
const
char
*
const
file_
;
// The line number on which the death test is located.
// The line number on which the death test is located.
...
@@ -1082,7 +1087,7 @@ DeathTest::TestRole ExecDeathTest::AssumeRole() {
...
@@ -1082,7 +1087,7 @@ DeathTest::TestRole ExecDeathTest::AssumeRole() {
GTEST_FLAG_PREFIX_
,
kInternalRunDeathTestFlag
,
GTEST_FLAG_PREFIX_
,
kInternalRunDeathTestFlag
,
file_
,
line_
,
death_test_index
,
pipe_fd
[
1
]);
file_
,
line_
,
death_test_index
,
pipe_fd
[
1
]);
Arguments
args
;
Arguments
args
;
args
.
AddArguments
(
GetArgvs
());
args
.
AddArguments
(
GetArgvs
ForDeathTestChildProcess
());
args
.
AddArgument
(
filter_flag
.
c_str
());
args
.
AddArgument
(
filter_flag
.
c_str
());
args
.
AddArgument
(
internal_flag
.
c_str
());
args
.
AddArgument
(
internal_flag
.
c_str
());
...
...
src/gtest-port.cc
View file @
69a40b7d
...
@@ -653,11 +653,23 @@ String GetCapturedStderr() { return GetCapturedStream(&g_captured_stderr); }
...
@@ -653,11 +653,23 @@ String GetCapturedStderr() { return GetCapturedStream(&g_captured_stderr); }
#if GTEST_HAS_DEATH_TEST
#if GTEST_HAS_DEATH_TEST
// A copy of all command line arguments. Set by InitGoogleTest().
// A copy of all command line arguments. Set by InitGoogleTest().
::
std
::
vector
<
S
tring
>
g_argvs
;
::
std
::
vector
<
testing
::
internal
::
s
tring
>
g_argvs
;
// Returns the command line as a vector of strings.
static
const
::
std
::
vector
<
testing
::
internal
::
string
>*
g_injected_test_argvs
=
const
::
std
::
vector
<
String
>&
GetArgvs
()
{
return
g_argvs
;
}
NULL
;
// Owned.
void
SetInjectableArgvs
(
const
::
std
::
vector
<
testing
::
internal
::
string
>*
argvs
)
{
if
(
g_injected_test_argvs
!=
argvs
)
delete
g_injected_test_argvs
;
g_injected_test_argvs
=
argvs
;
}
const
::
std
::
vector
<
testing
::
internal
::
string
>&
GetInjectableArgvs
()
{
if
(
g_injected_test_argvs
!=
NULL
)
{
return
*
g_injected_test_argvs
;
}
return
g_argvs
;
}
#endif // GTEST_HAS_DEATH_TEST
#endif // GTEST_HAS_DEATH_TEST
#if GTEST_OS_WINDOWS_MOBILE
#if GTEST_OS_WINDOWS_MOBILE
...
...
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