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
6f50ccf3
"vscode:/vscode.git/clone" did not exist on "f08b1c350a660e9a64537b193710a6dca57186d3"
Commit
6f50ccf3
authored
Feb 15, 2010
by
vladlosev
Browse files
Google Test's Python tests now pass on Solaris.
parent
9d965bbe
Changes
6
Hide whitespace changes
Inline
Side-by-side
Showing
6 changed files
with
133 additions
and
59 deletions
+133
-59
test/gtest_break_on_failure_unittest.py
test/gtest_break_on_failure_unittest.py
+7
-4
test/gtest_env_var_test.py
test/gtest_env_var_test.py
+6
-4
test/gtest_filter_unittest.py
test/gtest_filter_unittest.py
+46
-15
test/gtest_output_test.py
test/gtest_output_test.py
+31
-15
test/gtest_shuffle_test.py
test/gtest_shuffle_test.py
+4
-10
test/gtest_test_utils.py
test/gtest_test_utils.py
+39
-11
No files found.
test/gtest_break_on_failure_unittest.py
View file @
6f50ccf3
...
@@ -69,21 +69,24 @@ EXE_PATH = gtest_test_utils.GetTestExecutablePath(
...
@@ -69,21 +69,24 @@ EXE_PATH = gtest_test_utils.GetTestExecutablePath(
# Utilities.
# Utilities.
environ
=
os
.
environ
.
copy
()
def
SetEnvVar
(
env_var
,
value
):
def
SetEnvVar
(
env_var
,
value
):
"""Sets an environment variable to a given value; unsets it when the
"""Sets an environment variable to a given value; unsets it when the
given value is None.
given value is None.
"""
"""
if
value
is
not
None
:
if
value
is
not
None
:
os
.
environ
[
env_var
]
=
value
environ
[
env_var
]
=
value
elif
env_var
in
os
.
environ
:
elif
env_var
in
environ
:
del
os
.
environ
[
env_var
]
del
environ
[
env_var
]
def
Run
(
command
):
def
Run
(
command
):
"""Runs a command; returns 1 if it was killed by a signal, or 0 otherwise."""
"""Runs a command; returns 1 if it was killed by a signal, or 0 otherwise."""
p
=
gtest_test_utils
.
Subprocess
(
command
)
p
=
gtest_test_utils
.
Subprocess
(
command
,
env
=
environ
)
if
p
.
terminated_by_signal
:
if
p
.
terminated_by_signal
:
return
1
return
1
else
:
else
:
...
...
test/gtest_env_var_test.py
View file @
6f50ccf3
...
@@ -42,6 +42,8 @@ IS_LINUX = os.name == 'posix' and os.uname()[0] == 'Linux'
...
@@ -42,6 +42,8 @@ IS_LINUX = os.name == 'posix' and os.uname()[0] == 'Linux'
COMMAND
=
gtest_test_utils
.
GetTestExecutablePath
(
'gtest_env_var_test_'
)
COMMAND
=
gtest_test_utils
.
GetTestExecutablePath
(
'gtest_env_var_test_'
)
environ
=
os
.
environ
.
copy
()
def
AssertEq
(
expected
,
actual
):
def
AssertEq
(
expected
,
actual
):
if
expected
!=
actual
:
if
expected
!=
actual
:
...
@@ -54,9 +56,9 @@ def SetEnvVar(env_var, value):
...
@@ -54,9 +56,9 @@ def SetEnvVar(env_var, value):
"""Sets the env variable to 'value'; unsets it when 'value' is None."""
"""Sets the env variable to 'value'; unsets it when 'value' is None."""
if
value
is
not
None
:
if
value
is
not
None
:
os
.
environ
[
env_var
]
=
value
environ
[
env_var
]
=
value
elif
env_var
in
os
.
environ
:
elif
env_var
in
environ
:
del
os
.
environ
[
env_var
]
del
environ
[
env_var
]
def
GetFlag
(
flag
):
def
GetFlag
(
flag
):
...
@@ -65,7 +67,7 @@ def GetFlag(flag):
...
@@ -65,7 +67,7 @@ def GetFlag(flag):
args
=
[
COMMAND
]
args
=
[
COMMAND
]
if
flag
is
not
None
:
if
flag
is
not
None
:
args
+=
[
flag
]
args
+=
[
flag
]
return
gtest_test_utils
.
Subprocess
(
args
).
output
return
gtest_test_utils
.
Subprocess
(
args
,
env
=
environ
).
output
def
TestFlag
(
flag
,
test_val
,
default_val
):
def
TestFlag
(
flag
,
test_val
,
default_val
):
...
...
test/gtest_filter_unittest.py
View file @
6f50ccf3
...
@@ -45,11 +45,42 @@ __author__ = 'wan@google.com (Zhanyong Wan)'
...
@@ -45,11 +45,42 @@ __author__ = 'wan@google.com (Zhanyong Wan)'
import
os
import
os
import
re
import
re
import
sets
import
sets
import
sys
import
gtest_test_utils
import
gtest_test_utils
# Constants.
# Constants.
IS_WINDOWS
=
os
.
name
==
'nt'
# Checks if this platform can pass empty environment variables to child
# processes. We set an env variable to an empty string and invoke a python
# script in a subprocess to print whether the variable is STILL in
# os.environ. We then use 'eval' to parse the child's output so that an
# exception is thrown if the input is anything other than 'True' nor 'False'.
os
.
environ
[
'EMPTY_VAR'
]
=
''
child
=
gtest_test_utils
.
Subprocess
(
[
sys
.
executable
,
'-c'
,
'import os; print
\'
EMPTY_VAR
\'
in os.environ'
])
CAN_PASS_EMPTY_ENV
=
eval
(
child
.
output
)
# Check if this platform can unset environment variables in child processes.
# We set an env variable to a non-empty string, unset it, and invoke
# a python script in a subprocess to print whether the variable
# is NO LONGER in os.environ.
# We use 'eval' to parse the child's output so that an exception
# is thrown if the input is neither 'True' nor 'False'.
os
.
environ
[
'UNSET_VAR'
]
=
'X'
del
os
.
environ
[
'UNSET_VAR'
]
child
=
gtest_test_utils
.
Subprocess
(
[
sys
.
executable
,
'-c'
,
'import os; print
\'
UNSET_VAR
\'
not in os.environ'
])
CAN_UNSET_ENV
=
eval
(
child
.
output
)
# Checks if we should test with an empty filter. This doesn't
# make sense on platforms that cannot pass empty env variables (Win32)
# and on platforms that cannot unset variables (since we cannot tell
# the difference between "" and NULL -- Borland and Solaris < 5.10)
CAN_TEST_EMPTY_FILTER
=
(
CAN_PASS_EMPTY_ENV
and
CAN_UNSET_ENV
)
# The environment variable for specifying the test filters.
# The environment variable for specifying the test filters.
FILTER_ENV_VAR
=
'GTEST_FILTER'
FILTER_ENV_VAR
=
'GTEST_FILTER'
...
@@ -119,26 +150,29 @@ param_tests_present = None
...
@@ -119,26 +150,29 @@ param_tests_present = None
# Utilities.
# Utilities.
environ
=
os
.
environ
.
copy
()
def
SetEnvVar
(
env_var
,
value
):
def
SetEnvVar
(
env_var
,
value
):
"""Sets the env variable to 'value'; unsets it when 'value' is None."""
"""Sets the env variable to 'value'; unsets it when 'value' is None."""
if
value
is
not
None
:
if
value
is
not
None
:
os
.
environ
[
env_var
]
=
value
environ
[
env_var
]
=
value
elif
env_var
in
os
.
environ
:
elif
env_var
in
environ
:
del
os
.
environ
[
env_var
]
del
environ
[
env_var
]
def
RunAndReturnOutput
(
args
=
None
):
def
RunAndReturnOutput
(
args
=
None
):
"""Runs the test program and returns its output."""
"""Runs the test program and returns its output."""
return
gtest_test_utils
.
Subprocess
([
COMMAND
]
+
(
args
or
[])).
output
return
gtest_test_utils
.
Subprocess
([
COMMAND
]
+
(
args
or
[]),
env
=
environ
).
output
def
RunAndExtractTestList
(
args
=
None
):
def
RunAndExtractTestList
(
args
=
None
):
"""Runs the test program and returns its exit code and a list of tests run."""
"""Runs the test program and returns its exit code and a list of tests run."""
p
=
gtest_test_utils
.
Subprocess
([
COMMAND
]
+
(
args
or
[]))
p
=
gtest_test_utils
.
Subprocess
([
COMMAND
]
+
(
args
or
[])
,
env
=
environ
)
tests_run
=
[]
tests_run
=
[]
test_case
=
''
test_case
=
''
test
=
''
test
=
''
...
@@ -157,15 +191,12 @@ def RunAndExtractTestList(args = None):
...
@@ -157,15 +191,12 @@ def RunAndExtractTestList(args = None):
def
InvokeWithModifiedEnv
(
extra_env
,
function
,
*
args
,
**
kwargs
):
def
InvokeWithModifiedEnv
(
extra_env
,
function
,
*
args
,
**
kwargs
):
"""Runs the given function and arguments in a modified environment."""
"""Runs the given function and arguments in a modified environment."""
try
:
try
:
original_env
=
os
.
environ
.
copy
()
original_env
=
environ
.
copy
()
os
.
environ
.
update
(
extra_env
)
environ
.
update
(
extra_env
)
return
function
(
*
args
,
**
kwargs
)
return
function
(
*
args
,
**
kwargs
)
finally
:
finally
:
for
key
in
extra_env
.
iterkeys
():
environ
.
clear
()
if
key
in
original_env
:
environ
.
update
(
original_env
)
os
.
environ
[
key
]
=
original_env
[
key
]
else
:
del
os
.
environ
[
key
]
def
RunWithSharding
(
total_shards
,
shard_index
,
command
):
def
RunWithSharding
(
total_shards
,
shard_index
,
command
):
...
@@ -223,7 +254,7 @@ class GTestFilterUnitTest(gtest_test_utils.TestCase):
...
@@ -223,7 +254,7 @@ class GTestFilterUnitTest(gtest_test_utils.TestCase):
# we can still test the case when the variable is not supplied (i.e.,
# we can still test the case when the variable is not supplied (i.e.,
# gtest_filter is None).
# gtest_filter is None).
# pylint: disable-msg=C6403
# pylint: disable-msg=C6403
if
not
IS_WINDOWS
or
gtest_filter
!=
''
:
if
CAN_TEST_EMPTY_FILTER
or
gtest_filter
!=
''
:
SetEnvVar
(
FILTER_ENV_VAR
,
gtest_filter
)
SetEnvVar
(
FILTER_ENV_VAR
,
gtest_filter
)
tests_run
=
RunAndExtractTestList
()[
0
]
tests_run
=
RunAndExtractTestList
()[
0
]
SetEnvVar
(
FILTER_ENV_VAR
,
None
)
SetEnvVar
(
FILTER_ENV_VAR
,
None
)
...
@@ -265,7 +296,7 @@ class GTestFilterUnitTest(gtest_test_utils.TestCase):
...
@@ -265,7 +296,7 @@ class GTestFilterUnitTest(gtest_test_utils.TestCase):
# we can still test the case when the variable is not supplied (i.e.,
# we can still test the case when the variable is not supplied (i.e.,
# gtest_filter is None).
# gtest_filter is None).
# pylint: disable-msg=C6403
# pylint: disable-msg=C6403
if
not
IS_WINDOWS
or
gtest_filter
!=
''
:
if
CAN_TEST_EMPTY_FILTER
or
gtest_filter
!=
''
:
SetEnvVar
(
FILTER_ENV_VAR
,
gtest_filter
)
SetEnvVar
(
FILTER_ENV_VAR
,
gtest_filter
)
partition
=
[]
partition
=
[]
for
i
in
range
(
0
,
total_shards
):
for
i
in
range
(
0
,
total_shards
):
...
...
test/gtest_output_test.py
View file @
6f50ccf3
...
@@ -48,6 +48,7 @@ import gtest_test_utils
...
@@ -48,6 +48,7 @@ import gtest_test_utils
# The flag for generating the golden file
# The flag for generating the golden file
GENGOLDEN_FLAG
=
'--gengolden'
GENGOLDEN_FLAG
=
'--gengolden'
CATCH_EXCEPTIONS_ENV_VAR_NAME
=
'GTEST_CATCH_EXCEPTIONS'
IS_WINDOWS
=
os
.
name
==
'nt'
IS_WINDOWS
=
os
.
name
==
'nt'
...
@@ -123,6 +124,20 @@ def RemoveTime(output):
...
@@ -123,6 +124,20 @@ def RemoveTime(output):
return
re
.
sub
(
r
'\(\d+ ms'
,
'(? ms'
,
output
)
return
re
.
sub
(
r
'\(\d+ ms'
,
'(? ms'
,
output
)
def
RemoveTypeInfoDetails
(
test_output
):
"""Removes compiler-specific type info from Google Test program's output.
Args:
test_output: the output of a Google Test program.
Returns:
output with type information normalized to canonical form.
"""
# some compilers output the name of type 'unsigned int' as 'unsigned'
return
re
.
sub
(
r
'unsigned int'
,
'unsigned'
,
test_output
)
def
RemoveTestCounts
(
output
):
def
RemoveTestCounts
(
output
):
"""Removes test counts from a Google Test program's output."""
"""Removes test counts from a Google Test program's output."""
...
@@ -184,16 +199,9 @@ def GetShellCommandOutput(env_cmd):
...
@@ -184,16 +199,9 @@ def GetShellCommandOutput(env_cmd):
# Spawns cmd in a sub-process, and gets its standard I/O file objects.
# Spawns cmd in a sub-process, and gets its standard I/O file objects.
# Set and save the environment properly.
# Set and save the environment properly.
old_env_vars
=
dict
(
os
.
environ
)
environ
=
os
.
environ
.
copy
()
os
.
environ
.
update
(
env_cmd
[
0
])
environ
.
update
(
env_cmd
[
0
])
p
=
gtest_test_utils
.
Subprocess
(
env_cmd
[
1
])
p
=
gtest_test_utils
.
Subprocess
(
env_cmd
[
1
],
env
=
environ
)
# Changes made by os.environ.clear are not inheritable by child processes
# until Python 2.6. To produce inheritable changes we have to delete
# environment items with the del statement.
for
key
in
os
.
environ
.
keys
():
del
os
.
environ
[
key
]
os
.
environ
.
update
(
old_env_vars
)
return
p
.
output
return
p
.
output
...
@@ -209,8 +217,10 @@ def GetCommandOutput(env_cmd):
...
@@ -209,8 +217,10 @@ def GetCommandOutput(env_cmd):
"""
"""
# Disables exception pop-ups on Windows.
# Disables exception pop-ups on Windows.
os
.
environ
[
'GTEST_CATCH_EXCEPTIONS'
]
=
'1'
environ
,
cmdline
=
env_cmd
return
NormalizeOutput
(
GetShellCommandOutput
(
env_cmd
))
environ
=
dict
(
environ
)
# Ensures we are modifying a copy.
environ
[
CATCH_EXCEPTIONS_ENV_VAR_NAME
]
=
'1'
return
NormalizeOutput
(
GetShellCommandOutput
((
environ
,
cmdline
)))
def
GetOutputOfAllCommands
():
def
GetOutputOfAllCommands
():
...
@@ -262,11 +272,17 @@ class GTestOutputTest(gtest_test_utils.TestCase):
...
@@ -262,11 +272,17 @@ class GTestOutputTest(gtest_test_utils.TestCase):
# We want the test to pass regardless of certain features being
# We want the test to pass regardless of certain features being
# supported or not.
# supported or not.
# We still have to remove type name specifics in all cases.
normalized_actual
=
RemoveTypeInfoDetails
(
output
)
normalized_golden
=
RemoveTypeInfoDetails
(
golden
)
if
CAN_GENERATE_GOLDEN_FILE
:
if
CAN_GENERATE_GOLDEN_FILE
:
self
.
assert_
(
golden
==
output
)
self
.
assert_
(
normalized_golden
==
normalized_actual
)
else
:
else
:
normalized_actual
=
RemoveTestCounts
(
output
)
normalized_actual
=
RemoveTestCounts
(
normalized_actual
)
normalized_golden
=
RemoveTestCounts
(
self
.
RemoveUnsupportedTests
(
golden
))
normalized_golden
=
RemoveTestCounts
(
self
.
RemoveUnsupportedTests
(
normalized_golden
))
# This code is very handy when debugging golden file differences:
# This code is very handy when debugging golden file differences:
if
os
.
getenv
(
'DEBUG_GTEST_OUTPUT_TEST'
):
if
os
.
getenv
(
'DEBUG_GTEST_OUTPUT_TEST'
):
...
...
test/gtest_shuffle_test.py
View file @
6f50ccf3
...
@@ -78,16 +78,10 @@ def RandomSeedFlag(n):
...
@@ -78,16 +78,10 @@ def RandomSeedFlag(n):
def
RunAndReturnOutput
(
extra_env
,
args
):
def
RunAndReturnOutput
(
extra_env
,
args
):
"""Runs the test program and returns its output."""
"""Runs the test program and returns its output."""
try
:
environ_copy
=
os
.
environ
.
copy
()
original_env
=
os
.
environ
.
copy
()
environ_copy
.
update
(
extra_env
)
os
.
environ
.
update
(
extra_env
)
return
gtest_test_utils
.
Subprocess
([
COMMAND
]
+
args
).
output
return
gtest_test_utils
.
Subprocess
([
COMMAND
]
+
args
,
env
=
environ_copy
).
output
finally
:
for
key
in
extra_env
.
iterkeys
():
if
key
in
original_env
:
os
.
environ
[
key
]
=
original_env
[
key
]
else
:
del
os
.
environ
[
key
]
def
GetTestsForAllIterations
(
extra_env
,
args
):
def
GetTestsForAllIterations
(
extra_env
,
args
):
...
...
test/gtest_test_utils.py
View file @
6f50ccf3
...
@@ -194,23 +194,28 @@ def GetExitStatus(exit_code):
...
@@ -194,23 +194,28 @@ def GetExitStatus(exit_code):
class
Subprocess
:
class
Subprocess
:
def
__init__
(
self
,
command
,
working_dir
=
None
,
capture_stderr
=
True
):
def
__init__
(
self
,
command
,
working_dir
=
None
,
capture_stderr
=
True
,
env
=
None
):
"""Changes into a specified directory, if provided, and executes a command.
"""Changes into a specified directory, if provided, and executes a command.
Restores the old directory afterwards. Execution results are returned
via the following attributes:
Restores the old directory afterwards.
terminated_by_sygnal True iff the child process has been terminated
by a signal.
signal Sygnal that terminated the child process.
exited True iff the child process exited normally.
exit_code The code with which the child proces exited.
output Child process's stdout and stderr output
combined in a string.
Args:
Args:
command: The command to run, in the form of sys.argv.
command: The command to run, in the form of sys.argv.
working_dir: The directory to change into.
working_dir: The directory to change into.
capture_stderr: Determines whether to capture stderr in the output member
capture_stderr: Determines whether to capture stderr in the output member
or to discard it.
or to discard it.
env: Dictionary with environment to pass to the subprocess.
Returns:
An object that represents outcome of the executed process. It has the
following attributes:
terminated_by_signal True iff the child process has been terminated
by a signal.
signal Sygnal that terminated the child process.
exited True iff the child process exited normally.
exit_code The code with which the child process exited.
output Child process's stdout and stderr output
combined in a string.
"""
"""
# The subprocess module is the preferrable way of running programs
# The subprocess module is the preferrable way of running programs
...
@@ -228,13 +233,30 @@ class Subprocess:
...
@@ -228,13 +233,30 @@ class Subprocess:
p
=
subprocess
.
Popen
(
command
,
p
=
subprocess
.
Popen
(
command
,
stdout
=
subprocess
.
PIPE
,
stderr
=
stderr
,
stdout
=
subprocess
.
PIPE
,
stderr
=
stderr
,
cwd
=
working_dir
,
universal_newlines
=
True
)
cwd
=
working_dir
,
universal_newlines
=
True
,
env
=
env
)
# communicate returns a tuple with the file obect for the child's
# communicate returns a tuple with the file obect for the child's
# output.
# output.
self
.
output
=
p
.
communicate
()[
0
]
self
.
output
=
p
.
communicate
()[
0
]
self
.
_return_code
=
p
.
returncode
self
.
_return_code
=
p
.
returncode
else
:
else
:
old_dir
=
os
.
getcwd
()
old_dir
=
os
.
getcwd
()
def
_ReplaceEnvDict
(
dest
,
src
):
# Changes made by os.environ.clear are not inheritable by child
# processes until Python 2.6. To produce inheritable changes we have
# to delete environment items with the del statement.
for
key
in
dest
:
del
dest
[
key
]
dest
.
update
(
src
)
# When 'env' is not None, backup the environment variables and replace
# them with the passed 'env'. When 'env' is None, we simply use the
# current 'os.environ' for compatibility with the subprocess.Popen
# semantics used above.
if
env
is
not
None
:
old_environ
=
os
.
environ
.
copy
()
_ReplaceEnvDict
(
os
.
environ
,
env
)
try
:
try
:
if
working_dir
is
not
None
:
if
working_dir
is
not
None
:
os
.
chdir
(
working_dir
)
os
.
chdir
(
working_dir
)
...
@@ -247,6 +269,12 @@ class Subprocess:
...
@@ -247,6 +269,12 @@ class Subprocess:
ret_code
=
p
.
wait
()
ret_code
=
p
.
wait
()
finally
:
finally
:
os
.
chdir
(
old_dir
)
os
.
chdir
(
old_dir
)
# Restore the old environment variables
# if they were replaced.
if
env
is
not
None
:
_ReplaceEnvDict
(
os
.
environ
,
old_environ
)
# Converts ret_code to match the semantics of
# Converts ret_code to match the semantics of
# subprocess.Popen.returncode.
# subprocess.Popen.returncode.
if
os
.
WIFSIGNALED
(
ret_code
):
if
os
.
WIFSIGNALED
(
ret_code
):
...
...
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