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)'
import
os
import
gtest_test_utils
IS_WINDOWS
=
os
.
name
=
'nt'
COLOR_ENV_VAR
=
'GTEST_COLOR'
...
...
googletest/test/gtest_filter_unittest.py
View file @
83fa0cb1
...
...
@@ -44,12 +44,8 @@ __author__ = 'wan@google.com (Zhanyong Wan)'
import
os
import
re
try
:
from
sets
import
Set
as
set
# For Python 2.3 compatibility
except
ImportError
:
pass
import
sets
import
sys
import
gtest_test_utils
# Constants.
...
...
@@ -59,10 +55,12 @@ import gtest_test_utils
# 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
)
CAN_PASS_EMPTY_ENV
=
False
if
sys
.
executable
:
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.
...
...
@@ -71,11 +69,14 @@ CAN_PASS_EMPTY_ENV = eval(child.output)
# 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
)
CAN_UNSET_ENV
=
False
if
sys
.
executable
:
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
...
...
@@ -97,7 +98,7 @@ SHARD_STATUS_FILE_ENV_VAR = 'GTEST_SHARD_STATUS_FILE'
FILTER_FLAG
=
'gtest_filter'
# 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
=
gtest_test_utils
.
GetTestExecutablePath
(
'gtest_filter_unittest_'
)
...
...
@@ -246,14 +247,14 @@ class GTestFilterUnitTest(gtest_test_utils.TestCase):
for
slice_var
in
list_of_sets
:
full_partition
.
extend
(
slice_var
)
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
):
"""Adjust tests_to_run in case value parameterized tests are disabled."""
global
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
:
return
tests_to_run
...
...
@@ -294,6 +295,7 @@ class GTestFilterUnitTest(gtest_test_utils.TestCase):
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
on each shard should be identical to tests_to_run, without duplicates.
If check_exit_0, .
Args:
gtest_filter: A filter to apply to the tests.
...
...
@@ -339,7 +341,7 @@ class GTestFilterUnitTest(gtest_test_utils.TestCase):
tests_to_run
=
self
.
AdjustForParameterizedTests
(
tests_to_run
)
# 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
:
args
.
append
(
'--%s=%s'
%
(
FILTER_FLAG
,
gtest_filter
))
...
...
googletest/test/gtest_output_test.py
View file @
83fa0cb1
...
...
@@ -31,6 +31,7 @@
"""Tests the text output of Google C++ Testing Framework.
SYNOPSIS
gtest_output_test.py --build_dir=BUILD/DIR --gengolden
# where BUILD/DIR contains the built gtest_output_test_ file.
...
...
@@ -51,6 +52,7 @@ import gtest_test_utils
GENGOLDEN_FLAG
=
'--gengolden'
CATCH_EXCEPTIONS_ENV_VAR_NAME
=
'GTEST_CATCH_EXCEPTIONS'
IS_LINUX
=
os
.
name
==
'posix'
and
os
.
uname
()[
0
]
==
'Linux'
IS_WINDOWS
=
os
.
name
==
'nt'
# TODO(vladl@google.com): remove the _lin suffix.
...
...
@@ -250,11 +252,12 @@ test_list = GetShellCommandOutput(COMMAND_LIST_TESTS)
SUPPORTS_DEATH_TESTS
=
'DeathTest'
in
test_list
SUPPORTS_TYPED_TESTS
=
'TypedTest'
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
SUPPORTS_TYPED_TESTS
and
SUPPORTS_THREADS
and
SUPPORTS_STACK_TRACES
and
not
IS_WINDOWS
)
class
GTestOutputTest
(
gtest_test_utils
.
TestCase
):
...
...
@@ -280,7 +283,7 @@ class GTestOutputTest(gtest_test_utils.TestCase):
def
testOutput
(
self
):
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
# sequences when we read the golden file irrespective of an operating
# system used. Therefore, we need to strip those \r's from newlines
...
...
@@ -331,9 +334,9 @@ if __name__ == '__main__':
else
:
message
=
(
"""Unable to write a golden file when compiled in an environment
that does not support all the required features (death tests,
typed tests,
and multiple threads). Please generate the golden file using a binary built
with those features enabled
."""
)
that does not support all the required features (death tests,
typed tests, stack traces, and multiple threads).
Please build this test and generate the golden file using Blaze on Linux
."""
)
sys
.
stderr
.
write
(
message
)
sys
.
exit
(
1
)
...
...
googletest/test/gtest_test_utils.py
View file @
83fa0cb1
#!/usr/bin/env python
#
# Copyright 2006, Google Inc.
# All rights reserved.
#
...
...
@@ -30,19 +28,24 @@
# OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
"""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)'
import
atexit
import
os
import
shutil
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
unittest
_test_module
=
unittest
# Suppresses the 'Import not at the top of the file' lint complaint.
# pylint: disable-msg=C6204
try
:
import
subprocess
_SUBPROCESS_MODULE_AVAILABLE
=
True
...
...
@@ -53,9 +56,6 @@ except:
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.
PREMATURE_EXIT_FILE_ENV_VAR
=
'TEST_PREMATURE_EXIT_FILE'
...
...
@@ -145,8 +145,6 @@ atexit.register(_RemoveTempDir)
def
GetTempDir
():
"""Returns a directory for temporary files."""
global
_temp_dir
if
not
_temp_dir
:
_temp_dir
=
tempfile
.
mkdtemp
()
...
...
@@ -178,7 +176,7 @@ def GetTestExecutablePath(executable_name, build_dir=None):
'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
'
'environment variable.'
%
path
)
sys
.
stdout
.
write
(
message
)
print
>>
sys
.
stderr
,
message
sys
.
exit
(
1
)
return
path
...
...
googletest/test/gtest_throw_on_failure_test.py
View file @
83fa0cb1
...
...
@@ -70,7 +70,7 @@ def SetEnvVar(env_var, value):
def
Run
(
command
):
"""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
)
return
p
.
exited
and
p
.
exit_code
==
0
...
...
googletest/test/gtest_uninitialized_test.py
View file @
83fa0cb1
...
...
@@ -33,6 +33,7 @@
__author__
=
'wan@google.com (Zhanyong Wan)'
import
os
import
gtest_test_utils
...
...
@@ -46,8 +47,8 @@ def Assert(condition):
def
AssertEq
(
expected
,
actual
):
if
expected
!=
actual
:
print
(
'Expected: %s'
%
(
expected
,)
)
print
(
' Actual: %s'
%
(
actual
,)
)
print
'Expected: %s'
%
(
expected
,)
print
' Actual: %s'
%
(
actual
,)
raise
AssertionError
...
...
googletest/test/gtest_xml_outfiles_test.py
View file @
83fa0cb1
...
...
@@ -31,15 +31,11 @@
"""Unit test for the gtest_xml_output module."""
__author__
=
"keith.ray@gmail.com (Keith Ray)"
import
os
from
xml.dom
import
minidom
,
Node
import
gtest_test_utils
import
gtest_xml_test_utils
GTEST_OUTPUT_SUBDIR
=
"xml_outfiles"
GTEST_OUTPUT_1_TEST
=
"gtest_xml_outfile1_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