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
83fa0cb1
Unverified
Commit
83fa0cb1
authored
Jan 22, 2018
by
Gennadiy Civil
Committed by
GitHub
Jan 22, 2018
Browse files
Merge pull request #1415 from gennadiycivil/master
code merge
parents
62ba5d91
9bc86661
Changes
7
Hide whitespace changes
Inline
Side-by-side
Showing
7 changed files
with
42 additions
and
43 deletions
+42
-43
googletest/test/gtest_color_test.py
googletest/test/gtest_color_test.py
+0
-1
googletest/test/gtest_filter_unittest.py
googletest/test/gtest_filter_unittest.py
+20
-18
googletest/test/gtest_output_test.py
googletest/test/gtest_output_test.py
+8
-5
googletest/test/gtest_test_utils.py
googletest/test/gtest_test_utils.py
+10
-12
googletest/test/gtest_throw_on_failure_test.py
googletest/test/gtest_throw_on_failure_test.py
+1
-1
googletest/test/gtest_uninitialized_test.py
googletest/test/gtest_uninitialized_test.py
+3
-2
googletest/test/gtest_xml_outfiles_test.py
googletest/test/gtest_xml_outfiles_test.py
+0
-4
No files found.
googletest/test/gtest_color_test.py
View file @
83fa0cb1
...
@@ -36,7 +36,6 @@ __author__ = 'wan@google.com (Zhanyong Wan)'
...
@@ -36,7 +36,6 @@ __author__ = 'wan@google.com (Zhanyong Wan)'
import
os
import
os
import
gtest_test_utils
import
gtest_test_utils
IS_WINDOWS
=
os
.
name
=
'nt'
IS_WINDOWS
=
os
.
name
=
'nt'
COLOR_ENV_VAR
=
'GTEST_COLOR'
COLOR_ENV_VAR
=
'GTEST_COLOR'
...
...
googletest/test/gtest_filter_unittest.py
View file @
83fa0cb1
...
@@ -44,12 +44,8 @@ __author__ = 'wan@google.com (Zhanyong Wan)'
...
@@ -44,12 +44,8 @@ __author__ = 'wan@google.com (Zhanyong Wan)'
import
os
import
os
import
re
import
re
try
:
import
sets
from
sets
import
Set
as
set
# For Python 2.3 compatibility
except
ImportError
:
pass
import
sys
import
sys
import
gtest_test_utils
import
gtest_test_utils
# Constants.
# Constants.
...
@@ -59,10 +55,12 @@ import gtest_test_utils
...
@@ -59,10 +55,12 @@ import gtest_test_utils
# script in a subprocess to print whether the variable is STILL in
# 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
# 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'.
# exception is thrown if the input is anything other than 'True' nor 'False'.
os
.
environ
[
'EMPTY_VAR'
]
=
''
CAN_PASS_EMPTY_ENV
=
False
child
=
gtest_test_utils
.
Subprocess
(
if
sys
.
executable
:
[
sys
.
executable
,
'-c'
,
'import os; print(
\'
EMPTY_VAR
\'
in os.environ)'
])
os
.
environ
[
'EMPTY_VAR'
]
=
''
CAN_PASS_EMPTY_ENV
=
eval
(
child
.
output
)
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.
# Check if this platform can unset environment variables in child processes.
...
@@ -71,11 +69,14 @@ CAN_PASS_EMPTY_ENV = eval(child.output)
...
@@ -71,11 +69,14 @@ CAN_PASS_EMPTY_ENV = eval(child.output)
# is NO LONGER in os.environ.
# is NO LONGER in os.environ.
# We use 'eval' to parse the child's output so that an exception
# We use 'eval' to parse the child's output so that an exception
# is thrown if the input is neither 'True' nor 'False'.
# is thrown if the input is neither 'True' nor 'False'.
os
.
environ
[
'UNSET_VAR'
]
=
'X'
CAN_UNSET_ENV
=
False
del
os
.
environ
[
'UNSET_VAR'
]
if
sys
.
executable
:
child
=
gtest_test_utils
.
Subprocess
(
os
.
environ
[
'UNSET_VAR'
]
=
'X'
[
sys
.
executable
,
'-c'
,
'import os; print(
\'
UNSET_VAR
\'
not in os.environ)'
])
del
os
.
environ
[
'UNSET_VAR'
]
CAN_UNSET_ENV
=
eval
(
child
.
output
)
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
# Checks if we should test with an empty filter. This doesn't
...
@@ -97,7 +98,7 @@ SHARD_STATUS_FILE_ENV_VAR = 'GTEST_SHARD_STATUS_FILE'
...
@@ -97,7 +98,7 @@ SHARD_STATUS_FILE_ENV_VAR = 'GTEST_SHARD_STATUS_FILE'
FILTER_FLAG
=
'gtest_filter'
FILTER_FLAG
=
'gtest_filter'
# The command line flag for including disabled tests.
# The command line flag for including disabled tests.
ALSO_RUN_DISABED_TESTS_FLAG
=
'gtest_also_run_disabled_tests'
ALSO_RUN_DISAB
L
ED_TESTS_FLAG
=
'gtest_also_run_disabled_tests'
# Command to run the gtest_filter_unittest_ program.
# Command to run the gtest_filter_unittest_ program.
COMMAND
=
gtest_test_utils
.
GetTestExecutablePath
(
'gtest_filter_unittest_'
)
COMMAND
=
gtest_test_utils
.
GetTestExecutablePath
(
'gtest_filter_unittest_'
)
...
@@ -246,14 +247,14 @@ class GTestFilterUnitTest(gtest_test_utils.TestCase):
...
@@ -246,14 +247,14 @@ class GTestFilterUnitTest(gtest_test_utils.TestCase):
for
slice_var
in
list_of_sets
:
for
slice_var
in
list_of_sets
:
full_partition
.
extend
(
slice_var
)
full_partition
.
extend
(
slice_var
)
self
.
assertEqual
(
len
(
set_var
),
len
(
full_partition
))
self
.
assertEqual
(
len
(
set_var
),
len
(
full_partition
))
self
.
assertEqual
(
set
(
set_var
),
set
(
full_partition
))
self
.
assertEqual
(
set
s
.
Set
(
set_var
),
set
s
.
Set
(
full_partition
))
def
AdjustForParameterizedTests
(
self
,
tests_to_run
):
def
AdjustForParameterizedTests
(
self
,
tests_to_run
):
"""Adjust tests_to_run in case value parameterized tests are disabled."""
"""Adjust tests_to_run in case value parameterized tests are disabled."""
global
param_tests_present
global
param_tests_present
if
not
param_tests_present
:
if
not
param_tests_present
:
return
list
(
set
(
tests_to_run
)
-
set
(
PARAM_TESTS
))
return
list
(
set
s
.
Set
(
tests_to_run
)
-
set
s
.
Set
(
PARAM_TESTS
))
else
:
else
:
return
tests_to_run
return
tests_to_run
...
@@ -294,6 +295,7 @@ class GTestFilterUnitTest(gtest_test_utils.TestCase):
...
@@ -294,6 +295,7 @@ class GTestFilterUnitTest(gtest_test_utils.TestCase):
Runs all shards of gtest_filter_unittest_ with the given filter, and
Runs all shards of gtest_filter_unittest_ with the given filter, and
verifies that the right set of tests were run. The union of tests run
verifies that the right set of tests were run. The union of tests run
on each shard should be identical to tests_to_run, without duplicates.
on each shard should be identical to tests_to_run, without duplicates.
If check_exit_0, .
Args:
Args:
gtest_filter: A filter to apply to the tests.
gtest_filter: A filter to apply to the tests.
...
@@ -339,7 +341,7 @@ class GTestFilterUnitTest(gtest_test_utils.TestCase):
...
@@ -339,7 +341,7 @@ class GTestFilterUnitTest(gtest_test_utils.TestCase):
tests_to_run
=
self
.
AdjustForParameterizedTests
(
tests_to_run
)
tests_to_run
=
self
.
AdjustForParameterizedTests
(
tests_to_run
)
# Construct the command line.
# Construct the command line.
args
=
[
'--%s'
%
ALSO_RUN_DISABED_TESTS_FLAG
]
args
=
[
'--%s'
%
ALSO_RUN_DISAB
L
ED_TESTS_FLAG
]
if
gtest_filter
is
not
None
:
if
gtest_filter
is
not
None
:
args
.
append
(
'--%s=%s'
%
(
FILTER_FLAG
,
gtest_filter
))
args
.
append
(
'--%s=%s'
%
(
FILTER_FLAG
,
gtest_filter
))
...
...
googletest/test/gtest_output_test.py
View file @
83fa0cb1
...
@@ -31,6 +31,7 @@
...
@@ -31,6 +31,7 @@
"""Tests the text output of Google C++ Testing Framework.
"""Tests the text output of Google C++ Testing Framework.
SYNOPSIS
SYNOPSIS
gtest_output_test.py --build_dir=BUILD/DIR --gengolden
gtest_output_test.py --build_dir=BUILD/DIR --gengolden
# where BUILD/DIR contains the built gtest_output_test_ file.
# where BUILD/DIR contains the built gtest_output_test_ file.
...
@@ -51,6 +52,7 @@ import gtest_test_utils
...
@@ -51,6 +52,7 @@ import gtest_test_utils
GENGOLDEN_FLAG
=
'--gengolden'
GENGOLDEN_FLAG
=
'--gengolden'
CATCH_EXCEPTIONS_ENV_VAR_NAME
=
'GTEST_CATCH_EXCEPTIONS'
CATCH_EXCEPTIONS_ENV_VAR_NAME
=
'GTEST_CATCH_EXCEPTIONS'
IS_LINUX
=
os
.
name
==
'posix'
and
os
.
uname
()[
0
]
==
'Linux'
IS_WINDOWS
=
os
.
name
==
'nt'
IS_WINDOWS
=
os
.
name
==
'nt'
# TODO(vladl@google.com): remove the _lin suffix.
# TODO(vladl@google.com): remove the _lin suffix.
...
@@ -250,11 +252,12 @@ test_list = GetShellCommandOutput(COMMAND_LIST_TESTS)
...
@@ -250,11 +252,12 @@ test_list = GetShellCommandOutput(COMMAND_LIST_TESTS)
SUPPORTS_DEATH_TESTS
=
'DeathTest'
in
test_list
SUPPORTS_DEATH_TESTS
=
'DeathTest'
in
test_list
SUPPORTS_TYPED_TESTS
=
'TypedTest'
in
test_list
SUPPORTS_TYPED_TESTS
=
'TypedTest'
in
test_list
SUPPORTS_THREADS
=
'ExpectFailureWithThreadsTest'
in
test_list
SUPPORTS_THREADS
=
'ExpectFailureWithThreadsTest'
in
test_list
SUPPORTS_STACK_TRACES
=
False
SUPPORTS_STACK_TRACES
=
IS_LINUX
CAN_GENERATE_GOLDEN_FILE
=
(
SUPPORTS_DEATH_TESTS
and
CAN_GENERATE_GOLDEN_FILE
=
(
SUPPORTS_DEATH_TESTS
and
SUPPORTS_TYPED_TESTS
and
SUPPORTS_TYPED_TESTS
and
SUPPORTS_THREADS
and
SUPPORTS_THREADS
and
SUPPORTS_STACK_TRACES
and
not
IS_WINDOWS
)
not
IS_WINDOWS
)
class
GTestOutputTest
(
gtest_test_utils
.
TestCase
):
class
GTestOutputTest
(
gtest_test_utils
.
TestCase
):
...
@@ -280,7 +283,7 @@ class GTestOutputTest(gtest_test_utils.TestCase):
...
@@ -280,7 +283,7 @@ class GTestOutputTest(gtest_test_utils.TestCase):
def
testOutput
(
self
):
def
testOutput
(
self
):
output
=
GetOutputOfAllCommands
()
output
=
GetOutputOfAllCommands
()
golden_file
=
open
(
GOLDEN_PATH
,
'r'
)
golden_file
=
open
(
GOLDEN_PATH
,
'r
b
'
)
# A mis-configured source control system can cause \r appear in EOL
# A mis-configured source control system can cause \r appear in EOL
# sequences when we read the golden file irrespective of an operating
# sequences when we read the golden file irrespective of an operating
# system used. Therefore, we need to strip those \r's from newlines
# system used. Therefore, we need to strip those \r's from newlines
...
@@ -331,9 +334,9 @@ if __name__ == '__main__':
...
@@ -331,9 +334,9 @@ if __name__ == '__main__':
else
:
else
:
message
=
(
message
=
(
"""Unable to write a golden file when compiled in an environment
"""Unable to write a golden file when compiled in an environment
that does not support all the required features (death tests,
typed tests,
that does not support all the required features (death tests,
and multiple threads). Please generate the golden file using a binary built
typed tests, stack traces, and multiple threads).
with those features enabled
."""
)
Please build this test and generate the golden file using Blaze on Linux
."""
)
sys
.
stderr
.
write
(
message
)
sys
.
stderr
.
write
(
message
)
sys
.
exit
(
1
)
sys
.
exit
(
1
)
...
...
googletest/test/gtest_test_utils.py
View file @
83fa0cb1
#!/usr/bin/env python
#
# Copyright 2006, Google Inc.
# Copyright 2006, Google Inc.
# All rights reserved.
# All rights reserved.
#
#
...
@@ -30,19 +28,24 @@
...
@@ -30,19 +28,24 @@
# OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
# OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
"""Unit test utilities for Google C++ Testing Framework."""
"""Unit test utilities for Google C++ Testing Framework."""
# Suppresses the 'Import not at the top of the file' lint complaint.
# pylint: disable-msg=C6204
__author__
=
'wan@google.com (Zhanyong Wan)'
__author__
=
'wan@google.com (Zhanyong Wan)'
import
atexit
import
os
import
os
import
shutil
import
sys
import
sys
IS_LINUX
=
os
.
name
==
'posix'
and
os
.
uname
()[
0
]
==
'Linux'
IS_WINDOWS
=
os
.
name
==
'nt'
IS_CYGWIN
=
os
.
name
==
'posix'
and
'CYGWIN'
in
os
.
uname
()[
0
]
import
atexit
import
shutil
import
tempfile
import
tempfile
import
unittest
import
unittest
_test_module
=
unittest
_test_module
=
unittest
# Suppresses the 'Import not at the top of the file' lint complaint.
# pylint: disable-msg=C6204
try
:
try
:
import
subprocess
import
subprocess
_SUBPROCESS_MODULE_AVAILABLE
=
True
_SUBPROCESS_MODULE_AVAILABLE
=
True
...
@@ -53,9 +56,6 @@ except:
...
@@ -53,9 +56,6 @@ except:
GTEST_OUTPUT_VAR_NAME
=
'GTEST_OUTPUT'
GTEST_OUTPUT_VAR_NAME
=
'GTEST_OUTPUT'
IS_WINDOWS
=
os
.
name
==
'nt'
IS_CYGWIN
=
os
.
name
==
'posix'
and
'CYGWIN'
in
os
.
uname
()[
0
]
# The environment variable for specifying the path to the premature-exit file.
# The environment variable for specifying the path to the premature-exit file.
PREMATURE_EXIT_FILE_ENV_VAR
=
'TEST_PREMATURE_EXIT_FILE'
PREMATURE_EXIT_FILE_ENV_VAR
=
'TEST_PREMATURE_EXIT_FILE'
...
@@ -145,8 +145,6 @@ atexit.register(_RemoveTempDir)
...
@@ -145,8 +145,6 @@ atexit.register(_RemoveTempDir)
def
GetTempDir
():
def
GetTempDir
():
"""Returns a directory for temporary files."""
global
_temp_dir
global
_temp_dir
if
not
_temp_dir
:
if
not
_temp_dir
:
_temp_dir
=
tempfile
.
mkdtemp
()
_temp_dir
=
tempfile
.
mkdtemp
()
...
@@ -178,7 +176,7 @@ def GetTestExecutablePath(executable_name, build_dir=None):
...
@@ -178,7 +176,7 @@ def GetTestExecutablePath(executable_name, build_dir=None):
'Unable to find the test binary "%s". Please make sure to provide
\n
'
'Unable to find the test binary "%s". Please make sure to provide
\n
'
'a path to the binary via the --build_dir flag or the BUILD_DIR
\n
'
'a path to the binary via the --build_dir flag or the BUILD_DIR
\n
'
'environment variable.'
%
path
)
'environment variable.'
%
path
)
sys
.
stdout
.
write
(
message
)
print
>>
sys
.
stderr
,
message
sys
.
exit
(
1
)
sys
.
exit
(
1
)
return
path
return
path
...
...
googletest/test/gtest_throw_on_failure_test.py
View file @
83fa0cb1
...
@@ -70,7 +70,7 @@ def SetEnvVar(env_var, value):
...
@@ -70,7 +70,7 @@ def SetEnvVar(env_var, value):
def
Run
(
command
):
def
Run
(
command
):
"""Runs a command; returns True/False if its exit code is/isn't 0."""
"""Runs a command; returns True/False if its exit code is/isn't 0."""
print
(
'Running "%s". . .'
%
' '
.
join
(
command
)
)
print
'Running "%s". . .'
%
' '
.
join
(
command
)
p
=
gtest_test_utils
.
Subprocess
(
command
)
p
=
gtest_test_utils
.
Subprocess
(
command
)
return
p
.
exited
and
p
.
exit_code
==
0
return
p
.
exited
and
p
.
exit_code
==
0
...
...
googletest/test/gtest_uninitialized_test.py
View file @
83fa0cb1
...
@@ -33,6 +33,7 @@
...
@@ -33,6 +33,7 @@
__author__
=
'wan@google.com (Zhanyong Wan)'
__author__
=
'wan@google.com (Zhanyong Wan)'
import
os
import
gtest_test_utils
import
gtest_test_utils
...
@@ -46,8 +47,8 @@ def Assert(condition):
...
@@ -46,8 +47,8 @@ def Assert(condition):
def
AssertEq
(
expected
,
actual
):
def
AssertEq
(
expected
,
actual
):
if
expected
!=
actual
:
if
expected
!=
actual
:
print
(
'Expected: %s'
%
(
expected
,)
)
print
'Expected: %s'
%
(
expected
,)
print
(
' Actual: %s'
%
(
actual
,)
)
print
' Actual: %s'
%
(
actual
,)
raise
AssertionError
raise
AssertionError
...
...
googletest/test/gtest_xml_outfiles_test.py
View file @
83fa0cb1
...
@@ -31,15 +31,11 @@
...
@@ -31,15 +31,11 @@
"""Unit test for the gtest_xml_output module."""
"""Unit test for the gtest_xml_output module."""
__author__
=
"keith.ray@gmail.com (Keith Ray)"
import
os
import
os
from
xml.dom
import
minidom
,
Node
from
xml.dom
import
minidom
,
Node
import
gtest_test_utils
import
gtest_test_utils
import
gtest_xml_test_utils
import
gtest_xml_test_utils
GTEST_OUTPUT_SUBDIR
=
"xml_outfiles"
GTEST_OUTPUT_SUBDIR
=
"xml_outfiles"
GTEST_OUTPUT_1_TEST
=
"gtest_xml_outfile1_test_"
GTEST_OUTPUT_1_TEST
=
"gtest_xml_outfile1_test_"
GTEST_OUTPUT_2_TEST
=
"gtest_xml_outfile2_test_"
GTEST_OUTPUT_2_TEST
=
"gtest_xml_outfile2_test_"
...
...
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