googletest-filter-unittest.py (googletest-release-1.11.0) | : | googletest-filter-unittest.py (googletest-release-1.12.0) | ||
---|---|---|---|---|
skipping to change at line 50 | skipping to change at line 50 | |||
we test that here also. | we test that here also. | |||
""" | """ | |||
import os | import os | |||
import re | import re | |||
try: | try: | |||
from sets import Set as set # For Python 2.3 compatibility | from sets import Set as set # For Python 2.3 compatibility | |||
except ImportError: | except ImportError: | |||
pass | pass | |||
import sys | import sys | |||
import gtest_test_utils | from googletest.test import gtest_test_utils | |||
# Constants. | # Constants. | |||
# Checks if this platform can pass empty environment variables to child | # 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 | # 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 | # 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'. | |||
CAN_PASS_EMPTY_ENV = False | CAN_PASS_EMPTY_ENV = False | |||
if sys.executable: | if sys.executable: | |||
skipping to change at line 113 | skipping to change at line 113 | |||
# Regex for determining whether parameterized tests are enabled in the binary. | # Regex for determining whether parameterized tests are enabled in the binary. | |||
PARAM_TEST_REGEX = re.compile(r'/ParamTest') | PARAM_TEST_REGEX = re.compile(r'/ParamTest') | |||
# Regex for parsing test case names from Google Test's output. | # Regex for parsing test case names from Google Test's output. | |||
TEST_CASE_REGEX = re.compile(r'^\[\-+\] \d+ tests? from (\w+(/\w+)?)') | TEST_CASE_REGEX = re.compile(r'^\[\-+\] \d+ tests? from (\w+(/\w+)?)') | |||
# Regex for parsing test names from Google Test's output. | # Regex for parsing test names from Google Test's output. | |||
TEST_REGEX = re.compile(r'^\[\s*RUN\s*\].*\.(\w+(/\w+)?)') | TEST_REGEX = re.compile(r'^\[\s*RUN\s*\].*\.(\w+(/\w+)?)') | |||
# Regex for parsing disabled banner from Google Test's output | ||||
DISABLED_BANNER_REGEX = re.compile(r'^\[\s*DISABLED\s*\] (.*)') | ||||
# The command line flag to tell Google Test to output the list of tests it | # The command line flag to tell Google Test to output the list of tests it | |||
# will run. | # will run. | |||
LIST_TESTS_FLAG = '--gtest_list_tests' | LIST_TESTS_FLAG = '--gtest_list_tests' | |||
# Indicates whether Google Test supports death tests. | # Indicates whether Google Test supports death tests. | |||
SUPPORTS_DEATH_TESTS = 'HasDeathTest' in gtest_test_utils.Subprocess( | SUPPORTS_DEATH_TESTS = 'HasDeathTest' in gtest_test_utils.Subprocess( | |||
[COMMAND, LIST_TESTS_FLAG]).output | [COMMAND, LIST_TESTS_FLAG]).output | |||
# Full names of all tests in googletest-filter-unittests_. | # Full names of all tests in googletest-filter-unittests_. | |||
PARAM_TESTS = [ | PARAM_TESTS = [ | |||
skipping to change at line 202 | skipping to change at line 205 | |||
match = TEST_CASE_REGEX.match(line) | match = TEST_CASE_REGEX.match(line) | |||
if match is not None: | if match is not None: | |||
test_case = match.group(1) | test_case = match.group(1) | |||
else: | else: | |||
match = TEST_REGEX.match(line) | match = TEST_REGEX.match(line) | |||
if match is not None: | if match is not None: | |||
test = match.group(1) | test = match.group(1) | |||
tests_run.append(test_case + '.' + test) | tests_run.append(test_case + '.' + test) | |||
return (tests_run, p.exit_code) | return (tests_run, p.exit_code) | |||
def RunAndExtractDisabledBannerList(args=None): | ||||
"""Runs the test program and returns tests that printed a disabled banner.""" | ||||
p = gtest_test_utils.Subprocess([COMMAND] + (args or []), env=environ) | ||||
banners_printed = [] | ||||
for line in p.output.split('\n'): | ||||
match = DISABLED_BANNER_REGEX.match(line) | ||||
if match is not None: | ||||
banners_printed.append(match.group(1)) | ||||
return banners_printed | ||||
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 = environ.copy() | original_env = environ.copy() | |||
environ.update(extra_env) | environ.update(extra_env) | |||
return function(*args, **kwargs) | return function(*args, **kwargs) | |||
finally: | finally: | |||
environ.clear() | environ.clear() | |||
environ.update(original_env) | environ.update(original_env) | |||
skipping to change at line 607 | skipping to change at line 620 | |||
# This assertion ensures that Google Test enumerated the tests as | # This assertion ensures that Google Test enumerated the tests as | |||
# opposed to running them. | # opposed to running them. | |||
self.assert_('[==========]' not in output, | self.assert_('[==========]' not in output, | |||
'Unexpected output during test enumeration.\n' | 'Unexpected output during test enumeration.\n' | |||
'Please ensure that LIST_TESTS_FLAG is assigned the\n' | 'Please ensure that LIST_TESTS_FLAG is assigned the\n' | |||
'correct flag value for listing Google Test tests.') | 'correct flag value for listing Google Test tests.') | |||
self.assert_(os.path.exists(shard_status_file)) | self.assert_(os.path.exists(shard_status_file)) | |||
os.remove(shard_status_file) | os.remove(shard_status_file) | |||
def testDisabledBanner(self): | ||||
"""Tests that the disabled banner prints only tests that match filter.""" | ||||
make_filter = lambda s: ['--%s=%s' % (FILTER_FLAG, s)] | ||||
banners = RunAndExtractDisabledBannerList(make_filter('*')) | ||||
self.AssertSetEqual(banners, [ | ||||
'BarTest.DISABLED_TestFour', 'BarTest.DISABLED_TestFive', | ||||
'BazTest.DISABLED_TestC' | ||||
]) | ||||
banners = RunAndExtractDisabledBannerList(make_filter('Bar*')) | ||||
self.AssertSetEqual( | ||||
banners, ['BarTest.DISABLED_TestFour', 'BarTest.DISABLED_TestFive']) | ||||
banners = RunAndExtractDisabledBannerList(make_filter('*-Bar*')) | ||||
self.AssertSetEqual(banners, ['BazTest.DISABLED_TestC']) | ||||
if SUPPORTS_DEATH_TESTS: | if SUPPORTS_DEATH_TESTS: | |||
def testShardingWorksWithDeathTests(self): | def testShardingWorksWithDeathTests(self): | |||
"""Tests integration with death tests and sharding.""" | """Tests integration with death tests and sharding.""" | |||
gtest_filter = 'HasDeathTest.*:SeqP/*' | gtest_filter = 'HasDeathTest.*:SeqP/*' | |||
expected_tests = [ | expected_tests = [ | |||
'HasDeathTest.Test1', | 'HasDeathTest.Test1', | |||
'HasDeathTest.Test2', | 'HasDeathTest.Test2', | |||
'SeqP/ParamTest.TestX/0', | 'SeqP/ParamTest.TestX/0', | |||
End of changes. 4 change blocks. | ||||
1 lines changed or deleted | 31 lines changed or added |