summaryrefslogtreecommitdiffstats
path: root/gtest/test/gtest_output_test.py
diff options
context:
space:
mode:
Diffstat (limited to 'gtest/test/gtest_output_test.py')
-rwxr-xr-xgtest/test/gtest_output_test.py86
1 files changed, 33 insertions, 53 deletions
diff --git a/gtest/test/gtest_output_test.py b/gtest/test/gtest_output_test.py
index 192030a..c8a38f5 100755
--- a/gtest/test/gtest_output_test.py
+++ b/gtest/test/gtest_output_test.py
@@ -48,7 +48,6 @@ import gtest_test_utils
# The flag for generating the golden file
GENGOLDEN_FLAG = '--gengolden'
-CATCH_EXCEPTIONS_ENV_VAR_NAME = 'GTEST_CATCH_EXCEPTIONS'
IS_WINDOWS = os.name == 'nt'
@@ -124,32 +123,18 @@ def RemoveTime(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):
"""Removes test counts from a Google Test program's output."""
- output = re.sub(r'\d+ tests?, listed below',
+ output = re.sub(r'\d+ tests, listed below',
'? tests, listed below', output)
output = re.sub(r'\d+ FAILED TESTS',
'? FAILED TESTS', output)
- output = re.sub(r'\d+ tests? from \d+ test cases?',
+ output = re.sub(r'\d+ tests from \d+ test cases',
'? tests from ? test cases', output)
- output = re.sub(r'\d+ tests? from ([a-zA-Z_])',
+ output = re.sub(r'\d+ tests from ([a-zA-Z_])',
r'? tests from \1', output)
- return re.sub(r'\d+ tests?\.', '? tests.', output)
+ return re.sub(r'\d+ tests\.', '? tests.', output)
def RemoveMatchingTests(test_output, pattern):
@@ -199,9 +184,16 @@ def GetShellCommandOutput(env_cmd):
# Spawns cmd in a sub-process, and gets its standard I/O file objects.
# Set and save the environment properly.
- environ = os.environ.copy()
- environ.update(env_cmd[0])
- p = gtest_test_utils.Subprocess(env_cmd[1], env=environ)
+ old_env_vars = dict(os.environ)
+ os.environ.update(env_cmd[0])
+ p = gtest_test_utils.Subprocess(env_cmd[1])
+
+ # 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
@@ -217,10 +209,8 @@ def GetCommandOutput(env_cmd):
"""
# Disables exception pop-ups on Windows.
- environ, cmdline = env_cmd
- environ = dict(environ) # Ensures we are modifying a copy.
- environ[CATCH_EXCEPTIONS_ENV_VAR_NAME] = '1'
- return NormalizeOutput(GetShellCommandOutput((environ, cmdline)))
+ os.environ['GTEST_CATCH_EXCEPTIONS'] = '1'
+ return NormalizeOutput(GetShellCommandOutput(env_cmd))
def GetOutputOfAllCommands():
@@ -238,9 +228,7 @@ SUPPORTS_TYPED_TESTS = 'TypedTest' in test_list
SUPPORTS_THREADS = 'ExpectFailureWithThreadsTest' in test_list
SUPPORTS_STACK_TRACES = False
-CAN_GENERATE_GOLDEN_FILE = (SUPPORTS_DEATH_TESTS and
- SUPPORTS_TYPED_TESTS and
- SUPPORTS_THREADS)
+CAN_GENERATE_GOLDEN_FILE = SUPPORTS_DEATH_TESTS and SUPPORTS_TYPED_TESTS
class GTestOutputTest(gtest_test_utils.TestCase):
@@ -249,8 +237,6 @@ class GTestOutputTest(gtest_test_utils.TestCase):
test_output = RemoveMatchingTests(test_output, 'DeathTest')
if not SUPPORTS_TYPED_TESTS:
test_output = RemoveMatchingTests(test_output, 'TypedTest')
- test_output = RemoveMatchingTests(test_output, 'TypedDeathTest')
- test_output = RemoveMatchingTests(test_output, 'TypeParamDeathTest')
if not SUPPORTS_THREADS:
test_output = RemoveMatchingTests(test_output,
'ExpectFailureWithThreadsTest')
@@ -276,30 +262,24 @@ class GTestOutputTest(gtest_test_utils.TestCase):
# We want the test to pass regardless of certain features being
# 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:
- self.assertEqual(normalized_golden, normalized_actual)
+ self.assert_(golden == output)
else:
- normalized_actual = RemoveTestCounts(normalized_actual)
- normalized_golden = RemoveTestCounts(self.RemoveUnsupportedTests(
- normalized_golden))
+ normalized_actual = RemoveTestCounts(output)
+ normalized_golden = RemoveTestCounts(self.RemoveUnsupportedTests(golden))
- # This code is very handy when debugging golden file differences:
- if os.getenv('DEBUG_GTEST_OUTPUT_TEST'):
- open(os.path.join(
- gtest_test_utils.GetSourceDir(),
- '_gtest_output_test_normalized_actual.txt'), 'wb').write(
- normalized_actual)
- open(os.path.join(
- gtest_test_utils.GetSourceDir(),
- '_gtest_output_test_normalized_golden.txt'), 'wb').write(
- normalized_golden)
+ # This code is very handy when debugging test differences so I left it
+ # here, commented.
+ # open(os.path.join(
+ # gtest_test_utils.GetSourceDir(),
+ # '_gtest_output_test_normalized_actual.txt'), 'wb').write(
+ # normalized_actual)
+ # open(os.path.join(
+ # gtest_test_utils.GetSourceDir(),
+ # '_gtest_output_test_normalized_golden.txt'), 'wb').write(
+ # normalized_golden)
- self.assertEqual(normalized_golden, normalized_actual)
+ self.assert_(normalized_golden == normalized_actual)
if __name__ == '__main__':
@@ -318,8 +298,8 @@ that does not support all the required features (death tests""")
"""\nand typed tests). Please check that you are using VC++ 8.0 SP1
or higher as your compiler.""")
else:
- message += """\ntyped tests, and threads). Please generate the
-golden file using a binary built with those features enabled."""
+ message += """\nand typed tests). Please generate the golden file
+using a binary built with those features enabled."""
sys.stderr.write(message)
sys.exit(1)