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
dfa853b6
Unverified
Commit
dfa853b6
authored
Mar 22, 2018
by
Gennadiy Civil
Committed by
GitHub
Mar 22, 2018
Browse files
Merge pull request #1510 from gennadiycivil/master
More merges, restruct some
parents
eaaa422c
a1692ed1
Changes
4
Hide whitespace changes
Inline
Side-by-side
Showing
4 changed files
with
38 additions
and
30 deletions
+38
-30
googletest/include/gtest/internal/gtest-port.h
googletest/include/gtest/internal/gtest-port.h
+2
-1
googletest/src/gtest-port.cc
googletest/src/gtest-port.cc
+26
-26
googletest/src/gtest.cc
googletest/src/gtest.cc
+7
-1
googletest/test/gtest_env_var_test.py
googletest/test/gtest_env_var_test.py
+3
-2
No files found.
googletest/include/gtest/internal/gtest-port.h
View file @
dfa853b6
...
@@ -2675,7 +2675,8 @@ bool ParseInt32(const Message& src_text, const char* str, Int32* value);
...
@@ -2675,7 +2675,8 @@ bool ParseInt32(const Message& src_text, const char* str, Int32* value);
// corresponding to the given Google Test flag.
// corresponding to the given Google Test flag.
bool
BoolFromGTestEnv
(
const
char
*
flag
,
bool
default_val
);
bool
BoolFromGTestEnv
(
const
char
*
flag
,
bool
default_val
);
GTEST_API_
Int32
Int32FromGTestEnv
(
const
char
*
flag
,
Int32
default_val
);
GTEST_API_
Int32
Int32FromGTestEnv
(
const
char
*
flag
,
Int32
default_val
);
std
::
string
StringFromGTestEnv
(
const
char
*
flag
,
const
char
*
default_val
);
std
::
string
OutputFlagAlsoCheckEnvVar
();
const
char
*
StringFromGTestEnv
(
const
char
*
flag
,
const
char
*
default_val
);
}
// namespace internal
}
// namespace internal
}
// namespace testing
}
// namespace testing
...
...
googletest/src/gtest-port.cc
View file @
dfa853b6
...
@@ -1185,11 +1185,12 @@ bool ParseInt32(const Message& src_text, const char* str, Int32* value) {
...
@@ -1185,11 +1185,12 @@ bool ParseInt32(const Message& src_text, const char* str, Int32* value) {
bool
BoolFromGTestEnv
(
const
char
*
flag
,
bool
default_value
)
{
bool
BoolFromGTestEnv
(
const
char
*
flag
,
bool
default_value
)
{
#if defined(GTEST_GET_BOOL_FROM_ENV_)
#if defined(GTEST_GET_BOOL_FROM_ENV_)
return
GTEST_GET_BOOL_FROM_ENV_
(
flag
,
default_value
);
return
GTEST_GET_BOOL_FROM_ENV_
(
flag
,
default_value
);
#e
ndif // defined(GTEST_GET_BOOL_FROM_ENV_)
#e
lse
const
std
::
string
env_var
=
FlagToEnvVar
(
flag
);
const
std
::
string
env_var
=
FlagToEnvVar
(
flag
);
const
char
*
const
string_value
=
posix
::
GetEnv
(
env_var
.
c_str
());
const
char
*
const
string_value
=
posix
::
GetEnv
(
env_var
.
c_str
());
return
string_value
==
NULL
?
return
string_value
==
NULL
?
default_value
:
strcmp
(
string_value
,
"0"
)
!=
0
;
default_value
:
strcmp
(
string_value
,
"0"
)
!=
0
;
#endif // defined(GTEST_GET_BOOL_FROM_ENV_)
}
}
// Reads and returns a 32-bit integer stored in the environment
// Reads and returns a 32-bit integer stored in the environment
...
@@ -1198,7 +1199,7 @@ bool BoolFromGTestEnv(const char* flag, bool default_value) {
...
@@ -1198,7 +1199,7 @@ bool BoolFromGTestEnv(const char* flag, bool default_value) {
Int32
Int32FromGTestEnv
(
const
char
*
flag
,
Int32
default_value
)
{
Int32
Int32FromGTestEnv
(
const
char
*
flag
,
Int32
default_value
)
{
#if defined(GTEST_GET_INT32_FROM_ENV_)
#if defined(GTEST_GET_INT32_FROM_ENV_)
return
GTEST_GET_INT32_FROM_ENV_
(
flag
,
default_value
);
return
GTEST_GET_INT32_FROM_ENV_
(
flag
,
default_value
);
#e
ndif // defined(GTEST_GET_INT32_FROM_ENV_)
#e
lse
const
std
::
string
env_var
=
FlagToEnvVar
(
flag
);
const
std
::
string
env_var
=
FlagToEnvVar
(
flag
);
const
char
*
const
string_value
=
posix
::
GetEnv
(
env_var
.
c_str
());
const
char
*
const
string_value
=
posix
::
GetEnv
(
env_var
.
c_str
());
if
(
string_value
==
NULL
)
{
if
(
string_value
==
NULL
)
{
...
@@ -1216,37 +1217,36 @@ Int32 Int32FromGTestEnv(const char* flag, Int32 default_value) {
...
@@ -1216,37 +1217,36 @@ Int32 Int32FromGTestEnv(const char* flag, Int32 default_value) {
}
}
return
result
;
return
result
;
#endif // defined(GTEST_GET_INT32_FROM_ENV_)
}
// As a special case for the 'output' flag, if GTEST_OUTPUT is not
// set, we look for XML_OUTPUT_FILE, which is set by the Bazel build
// system. The value of XML_OUTPUT_FILE is a filename without the
// "xml:" prefix of GTEST_OUTPUT.
// Note that this is meant to be called at the call site so it does
// not check that the flag is 'output'
// In essence this checks env. variable called XML_OUTPUT_FILE
// if it is set we prepend "xml:" to its value , if it not set we return ""
std
::
string
OutputFlagAlsoCheckEnvVar
(){
std
::
string
default_value_for_output_flag
=
""
;
const
char
*
xml_output_file_env
=
posix
::
GetEnv
(
"XML_OUTPUT_FILE"
);
if
(
NULL
!=
xml_output_file_env
)
{
default_value_for_output_flag
=
std
::
string
(
"xml:"
)
+
xml_output_file_env
;
}
return
default_value_for_output_flag
;
}
}
// Reads and returns the string environment variable corresponding to
// Reads and returns the string environment variable corresponding to
// the given flag; if it's not set, returns default_value.
// the given flag; if it's not set, returns default_value.
std
::
string
StringFromGTestEnv
(
const
char
*
flag
,
const
char
*
default_value
)
{
const
char
*
StringFromGTestEnv
(
const
char
*
flag
,
const
char
*
default_value
)
{
#if defined(GTEST_GET_STRING_FROM_ENV_)
#if defined(GTEST_GET_STRING_FROM_ENV_)
return
GTEST_GET_STRING_FROM_ENV_
(
flag
,
default_value
);
return
GTEST_GET_STRING_FROM_ENV_
(
flag
,
default_value
);
#e
ndif // defined(GTEST_GET_STRING_FROM_ENV_)
#e
lse
const
std
::
string
env_var
=
FlagToEnvVar
(
flag
);
const
std
::
string
env_var
=
FlagToEnvVar
(
flag
);
const
char
*
value
=
posix
::
GetEnv
(
env_var
.
c_str
());
const
char
*
const
value
=
posix
::
GetEnv
(
env_var
.
c_str
());
if
(
value
!=
NULL
)
{
return
value
==
NULL
?
default_value
:
value
;
return
value
;
#endif // defined(GTEST_GET_STRING_FROM_ENV_)
}
// As a special case for the 'output' flag, if GTEST_OUTPUT is not
// set, we look for XML_OUTPUT_FILE, which is set by the Bazel build
// system. The value of XML_OUTPUT_FILE is a filename without the
// "xml:" prefix of GTEST_OUTPUT.
//
// The net priority order after flag processing is thus:
// --gtest_output command line flag
// GTEST_OUTPUT environment variable
// XML_OUTPUT_FILE environment variable
// 'default_value'
if
(
strcmp
(
flag
,
"output"
)
==
0
)
{
value
=
posix
::
GetEnv
(
"XML_OUTPUT_FILE"
);
if
(
value
!=
NULL
)
{
return
std
::
string
(
"xml:"
)
+
value
;
}
}
return
default_value
;
}
}
}
// namespace internal
}
// namespace internal
...
...
googletest/src/gtest.cc
View file @
dfa853b6
...
@@ -230,9 +230,15 @@ GTEST_DEFINE_string_(
...
@@ -230,9 +230,15 @@ GTEST_DEFINE_string_(
GTEST_DEFINE_bool_
(
list_tests
,
false
,
GTEST_DEFINE_bool_
(
list_tests
,
false
,
"List all tests without running them."
);
"List all tests without running them."
);
// The net priority order after flag processing is thus:
// --gtest_output command line flag
// GTEST_OUTPUT environment variable
// XML_OUTPUT_FILE environment variable
// ''
GTEST_DEFINE_string_
(
GTEST_DEFINE_string_
(
output
,
output
,
internal
::
StringFromGTestEnv
(
"output"
,
""
),
internal
::
StringFromGTestEnv
(
"output"
,
internal
::
OutputFlagAlsoCheckEnvVar
().
c_str
()),
"A format (defaults to
\"
xml
\"
but can be specified to be
\"
json
\"
), "
"A format (defaults to
\"
xml
\"
but can be specified to be
\"
json
\"
), "
"optionally followed by a colon and an output file name or directory. "
"optionally followed by a colon and an output file name or directory. "
"A directory is indicated by a trailing pathname separator. "
"A directory is indicated by a trailing pathname separator. "
...
...
googletest/test/gtest_env_var_test.py
View file @
dfa853b6
...
@@ -81,13 +81,14 @@ def TestFlag(flag, test_val, default_val):
...
@@ -81,13 +81,14 @@ def TestFlag(flag, test_val, default_val):
class
GTestEnvVarTest
(
gtest_test_utils
.
TestCase
):
class
GTestEnvVarTest
(
gtest_test_utils
.
TestCase
):
def
testEnvVarAffectsFlag
(
self
):
def
testEnvVarAffectsFlag
(
self
):
"""Tests that environment variable should affect the corresponding flag."""
"""Tests that environment variable should affect the corresponding flag."""
TestFlag
(
'break_on_failure'
,
'1'
,
'0'
)
TestFlag
(
'break_on_failure'
,
'1'
,
'0'
)
TestFlag
(
'color'
,
'yes'
,
'auto'
)
TestFlag
(
'color'
,
'yes'
,
'auto'
)
TestFlag
(
'filter'
,
'FooTest.Bar'
,
'*'
)
TestFlag
(
'filter'
,
'FooTest.Bar'
,
'*'
)
SetEnvVar
(
'XML_OUTPUT_FILE'
,
None
)
# For 'output' test
SetEnvVar
(
'XML_OUTPUT_FILE'
,
None
)
# For 'output' test
TestFlag
(
'output'
,
'xml:tmp/foo.xml'
,
''
)
TestFlag
(
'output'
,
'xml:tmp/foo.xml'
,
''
)
TestFlag
(
'print_time'
,
'0'
,
'1'
)
TestFlag
(
'print_time'
,
'0'
,
'1'
)
TestFlag
(
'repeat'
,
'999'
,
'1'
)
TestFlag
(
'repeat'
,
'999'
,
'1'
)
...
@@ -107,7 +108,7 @@ class GTestEnvVarTest(gtest_test_utils.TestCase):
...
@@ -107,7 +108,7 @@ class GTestEnvVarTest(gtest_test_utils.TestCase):
AssertEq
(
'xml:tmp/bar.xml'
,
GetFlag
(
'output'
))
AssertEq
(
'xml:tmp/bar.xml'
,
GetFlag
(
'output'
))
def
testXmlOutputFileOverride
(
self
):
def
testXmlOutputFileOverride
(
self
):
"""Tests that $XML_OUTPUT_FILE is overridden by $GTEST_OUTPUT"""
"""Tests that $XML_OUTPUT_FILE is overridden by $GTEST_OUTPUT
.
"""
SetEnvVar
(
'GTEST_OUTPUT'
,
'xml:tmp/foo.xml'
)
SetEnvVar
(
'GTEST_OUTPUT'
,
'xml:tmp/foo.xml'
)
SetEnvVar
(
'XML_OUTPUT_FILE'
,
'tmp/bar.xml'
)
SetEnvVar
(
'XML_OUTPUT_FILE'
,
'tmp/bar.xml'
)
...
...
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