From d201456903f3ecae1f7794edfab0d5678e642265 Mon Sep 17 00:00:00 2001 From: shiqian Date: Thu, 3 Jul 2008 22:38:12 +0000 Subject: Initial import. --- test/gtest_output_test.py | 183 ++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 183 insertions(+) create mode 100755 test/gtest_output_test.py (limited to 'test/gtest_output_test.py') diff --git a/test/gtest_output_test.py b/test/gtest_output_test.py new file mode 100755 index 00000000..0fea034f --- /dev/null +++ b/test/gtest_output_test.py @@ -0,0 +1,183 @@ +#!/usr/bin/env python +# +# Copyright 2008, Google Inc. +# All rights reserved. +# +# Redistribution and use in source and binary forms, with or without +# modification, are permitted provided that the following conditions are +# met: +# +# * Redistributions of source code must retain the above copyright +# notice, this list of conditions and the following disclaimer. +# * Redistributions in binary form must reproduce the above +# copyright notice, this list of conditions and the following disclaimer +# in the documentation and/or other materials provided with the +# distribution. +# * Neither the name of Google Inc. nor the names of its +# contributors may be used to endorse or promote products derived from +# this software without specific prior written permission. +# +# THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS +# "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT +# LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR +# A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT +# OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, +# SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT +# LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, +# DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY +# THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT +# (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE +# OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + +"""Tests the text output of Google C++ Testing Framework. + +SYNOPSIS + gtest_output_test.py --gengolden + gtest_output_test.py +""" + +__author__ = 'wan@google.com (Zhanyong Wan)' + +import gtest_test_utils +import os +import re +import string +import sys +import unittest + + +# The flag for generating the golden file +GENGOLDEN_FLAG = '--gengolden' + +IS_WINDOWS = os.name == 'nt' + +if IS_WINDOWS: + PROGRAM = r'..\build.dbg8\gtest_output_test_.exe' + GOLDEN_NAME = 'gtest_output_test_golden_win.txt' +else: + PROGRAM = 'gtest_output_test_' + GOLDEN_NAME = 'gtest_output_test_golden_lin.txt' + +COMMAND = os.path.join(gtest_test_utils.GetBuildDir(), + PROGRAM) + ' --gtest_color=yes' + +GOLDEN_PATH = os.path.join(gtest_test_utils.GetSourceDir(), + GOLDEN_NAME) + +def ToUnixLineEnding(s): + """Changes all Windows/Mac line endings in s to UNIX line endings.""" + + return s.replace('\r\n', '\n').replace('\r', '\n') + + +def RemoveLocations(output): + """Removes all file location info from a Google Test program's output. + + Args: + output: the output of a Google Test program. + + Returns: + output with all file location info (in the form of + 'DIRECTORY/FILE_NAME:LINE_NUMBER: ') replaced by + 'FILE_NAME:#: '. + """ + + return re.sub(r'.*[/\\](.+)\:\d+\: ', r'\1:#: ', output) + + +def RemoveStackTraces(output): + """Removes all stack traces from a Google Test program's output.""" + + # *? means "find the shortest string that matches". + return re.sub(r'Stack trace:(.|\n)*?\n\n', + 'Stack trace: (omitted)\n\n', output) + + +def NormalizeOutput(output): + """Normalizes output (the output of gtest_output_test_.exe).""" + + output = ToUnixLineEnding(output) + output = RemoveLocations(output) + output = RemoveStackTraces(output) + return output + + +def IterShellCommandOutput(cmd, stdin_string=None): + """Runs a command in a sub-process, and iterates the lines in its STDOUT. + + Args: + + cmd: The shell command. + stdin_string: The string to be fed to the STDIN of the sub-process; + If None, the sub-process will inherit the STDIN + from the parent process. + """ + + # Spawns cmd in a sub-process, and gets its standard I/O file objects. + stdin_file, stdout_file = os.popen2(cmd, 'b') + + # If the caller didn't specify a string for STDIN, gets it from the + # parent process. + if stdin_string is None: + stdin_string = sys.stdin.read() + + # Feeds the STDIN string to the sub-process. + stdin_file.write(stdin_string) + stdin_file.close() + + while True: + line = stdout_file.readline() + if not line: # EOF + stdout_file.close() + break + + yield line + + +def GetShellCommandOutput(cmd, stdin_string=None): + """Runs a command in a sub-process, and returns its STDOUT in a string. + + Args: + + cmd: The shell command. + stdin_string: The string to be fed to the STDIN of the sub-process; + If None, the sub-process will inherit the STDIN + from the parent process. + """ + + lines = list(IterShellCommandOutput(cmd, stdin_string)) + return string.join(lines, '') + + +def GetCommandOutput(cmd): + """Runs a command and returns its output with all file location + info stripped off. + + Args: + cmd: the shell command. + """ + + # Disables exception pop-ups on Windows. + os.environ['GUNIT_CATCH_EXCEPTIONS'] = '1' + return NormalizeOutput(GetShellCommandOutput(cmd, '')) + + +class GTestOutputTest(unittest.TestCase): + def testOutput(self): + output = GetCommandOutput(COMMAND) + + golden_file = open(GOLDEN_PATH, 'rb') + golden = golden_file.read() + golden_file.close() + + self.assertEquals(golden, output) + + +if __name__ == '__main__': + if sys.argv[1:] == [GENGOLDEN_FLAG]: + output = GetCommandOutput(COMMAND) + golden_file = open(GOLDEN_PATH, 'wb') + golden_file.write(output) + golden_file.close() + else: + gtest_test_utils.Main() -- cgit v1.2.3 From e4e9a8bd7d2dbbad62030c8f80513e3c81b32213 Mon Sep 17 00:00:00 2001 From: shiqian Date: Tue, 8 Jul 2008 21:32:17 +0000 Subject: Makes the autotools scripts work on Mac OS X. Also hopefully makes gtest compile on Windows CE. --- test/gtest_output_test.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'test/gtest_output_test.py') diff --git a/test/gtest_output_test.py b/test/gtest_output_test.py index 0fea034f..7ecb4d1a 100755 --- a/test/gtest_output_test.py +++ b/test/gtest_output_test.py @@ -158,7 +158,7 @@ def GetCommandOutput(cmd): """ # Disables exception pop-ups on Windows. - os.environ['GUNIT_CATCH_EXCEPTIONS'] = '1' + os.environ['GTEST_CATCH_EXCEPTIONS'] = '1' return NormalizeOutput(GetShellCommandOutput(cmd, '')) -- cgit v1.2.3 From 253d2bc5760533c136f5b1b34b8c6f03d79fc538 Mon Sep 17 00:00:00 2001 From: shiqian Date: Wed, 23 Jul 2008 20:32:11 +0000 Subject: Makes the output understandable by VS when compiled by MSVC. --- test/gtest_output_test.py | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) (limited to 'test/gtest_output_test.py') diff --git a/test/gtest_output_test.py b/test/gtest_output_test.py index 7ecb4d1a..ee766ffd 100755 --- a/test/gtest_output_test.py +++ b/test/gtest_output_test.py @@ -78,11 +78,12 @@ def RemoveLocations(output): Returns: output with all file location info (in the form of - 'DIRECTORY/FILE_NAME:LINE_NUMBER: ') replaced by + 'DIRECTORY/FILE_NAME:LINE_NUMBER: 'or + 'DIRECTORY\\FILE_NAME(LINE_NUMBER): ') replaced by 'FILE_NAME:#: '. """ - return re.sub(r'.*[/\\](.+)\:\d+\: ', r'\1:#: ', output) + return re.sub(r'.*[/\\](.+)(\:\d+|\(\d+\))\: ', r'\1:#: ', output) def RemoveStackTraces(output): -- cgit v1.2.3 From 15cbe5f70adaade1a8a11afc37601fc6606e7e0d Mon Sep 17 00:00:00 2001 From: shiqian Date: Fri, 25 Jul 2008 04:06:16 +0000 Subject: Adds --gtest_print_test for printing the elapsed time of tests. --- test/gtest_output_test.py | 20 +++++++++++++++----- 1 file changed, 15 insertions(+), 5 deletions(-) (limited to 'test/gtest_output_test.py') diff --git a/test/gtest_output_test.py b/test/gtest_output_test.py index ee766ffd..05f49dc4 100755 --- a/test/gtest_output_test.py +++ b/test/gtest_output_test.py @@ -58,8 +58,10 @@ else: PROGRAM = 'gtest_output_test_' GOLDEN_NAME = 'gtest_output_test_golden_lin.txt' -COMMAND = os.path.join(gtest_test_utils.GetBuildDir(), - PROGRAM) + ' --gtest_color=yes' +PROGRAM_PATH = os.path.join(gtest_test_utils.GetBuildDir(), PROGRAM) +COMMAND_WITH_COLOR = PROGRAM_PATH + ' --gtest_color=yes' +COMMAND_WITH_TIME = (PROGRAM_PATH + ' --gtest_print_time ' + + '--gtest_filter="FatalFailureTest.*:LoggingTest.*"') GOLDEN_PATH = os.path.join(gtest_test_utils.GetSourceDir(), GOLDEN_NAME) @@ -94,12 +96,19 @@ def RemoveStackTraces(output): 'Stack trace: (omitted)\n\n', output) +def RemoveTime(output): + """Removes all time information from a Google Test program's output.""" + + return re.sub(r'\(\d+ ms', '(? ms', output) + + def NormalizeOutput(output): """Normalizes output (the output of gtest_output_test_.exe).""" output = ToUnixLineEnding(output) output = RemoveLocations(output) output = RemoveStackTraces(output) + output = RemoveTime(output) return output @@ -165,8 +174,8 @@ def GetCommandOutput(cmd): class GTestOutputTest(unittest.TestCase): def testOutput(self): - output = GetCommandOutput(COMMAND) - + output = (GetCommandOutput(COMMAND_WITH_COLOR) + + GetCommandOutput(COMMAND_WITH_TIME)) golden_file = open(GOLDEN_PATH, 'rb') golden = golden_file.read() golden_file.close() @@ -176,7 +185,8 @@ class GTestOutputTest(unittest.TestCase): if __name__ == '__main__': if sys.argv[1:] == [GENGOLDEN_FLAG]: - output = GetCommandOutput(COMMAND) + output = (GetCommandOutput(COMMAND_WITH_COLOR) + + GetCommandOutput(COMMAND_WITH_TIME)) golden_file = open(GOLDEN_PATH, 'wb') golden_file.write(output) golden_file.close() -- cgit v1.2.3 From a2b1a8556ea64014606d78b09333d9c522430a25 Mon Sep 17 00:00:00 2001 From: shiqian Date: Mon, 8 Sep 2008 17:55:52 +0000 Subject: Adds support for type-parameterized tests (by Zhanyong Wan); also adds case-insensitive wide string comparison to the String class (by Vlad Losev). --- test/gtest_output_test.py | 2 ++ 1 file changed, 2 insertions(+) (limited to 'test/gtest_output_test.py') diff --git a/test/gtest_output_test.py b/test/gtest_output_test.py index 05f49dc4..f91050c0 100755 --- a/test/gtest_output_test.py +++ b/test/gtest_output_test.py @@ -32,6 +32,8 @@ """Tests the text output of Google C++ Testing Framework. SYNOPSIS + gtest_output_test.py --gtest_build_dir=BUILD/DIR --gengolden + # where BUILD/DIR contains the built gtest_output_test_ file. gtest_output_test.py --gengolden gtest_output_test.py """ -- cgit v1.2.3 From f6b0dc0b408f38bb04079b14198d6bdf703e5e56 Mon Sep 17 00:00:00 2001 From: shiqian Date: Thu, 18 Sep 2008 18:06:35 +0000 Subject: Makes Google Test compile (and all tests pass) on cygwin (possibly on wingw too). --- test/gtest_output_test.py | 20 +++++++++++++++++++- 1 file changed, 19 insertions(+), 1 deletion(-) (limited to 'test/gtest_output_test.py') diff --git a/test/gtest_output_test.py b/test/gtest_output_test.py index f91050c0..68cfe5ec 100755 --- a/test/gtest_output_test.py +++ b/test/gtest_output_test.py @@ -104,6 +104,20 @@ def RemoveTime(output): return re.sub(r'\(\d+ ms', '(? ms', output) +def RemoveTestCounts(output): + """Removes test counts from a Google Test program's output.""" + + output = re.sub(r'\d+ tests from \d+ test cases', + '? tests from ? test cases', output) + return re.sub(r'\d+ tests\.', '? tests.', output) + + +def RemoveDeathTests(output): + """Removes death test information from a Google Test program's output.""" + + return re.sub(r'\n.*DeathTest.*', '', output) + + def NormalizeOutput(output): """Normalizes output (the output of gtest_output_test_.exe).""" @@ -182,7 +196,11 @@ class GTestOutputTest(unittest.TestCase): golden = golden_file.read() golden_file.close() - self.assertEquals(golden, output) + # We want the test to pass regardless of death tests being + # supported or not. + self.assert_(output == golden or + RemoveTestCounts(output) == + RemoveTestCounts(RemoveDeathTests(golden))) if __name__ == '__main__': -- cgit v1.2.3 From fe186c382905dcf57014985ccea8e067275e9f5f Mon Sep 17 00:00:00 2001 From: shiqian Date: Sat, 10 Jan 2009 01:16:33 +0000 Subject: Implements --gtest_also_run_disabled_tests. By Eric Roman. --- test/gtest_output_test.py | 11 ++++++++--- 1 file changed, 8 insertions(+), 3 deletions(-) (limited to 'test/gtest_output_test.py') diff --git a/test/gtest_output_test.py b/test/gtest_output_test.py index 68cfe5ec..42cf00c4 100755 --- a/test/gtest_output_test.py +++ b/test/gtest_output_test.py @@ -40,12 +40,12 @@ SYNOPSIS __author__ = 'wan@google.com (Zhanyong Wan)' -import gtest_test_utils import os import re import string import sys import unittest +import gtest_test_utils # The flag for generating the golden file @@ -64,10 +64,13 @@ PROGRAM_PATH = os.path.join(gtest_test_utils.GetBuildDir(), PROGRAM) COMMAND_WITH_COLOR = PROGRAM_PATH + ' --gtest_color=yes' COMMAND_WITH_TIME = (PROGRAM_PATH + ' --gtest_print_time ' + '--gtest_filter="FatalFailureTest.*:LoggingTest.*"') +COMMAND_WITH_DISABLED = (PROGRAM_PATH + ' --gtest_also_run_disabled_tests ' + + '--gtest_filter="*DISABLED_*"') GOLDEN_PATH = os.path.join(gtest_test_utils.GetSourceDir(), GOLDEN_NAME) + def ToUnixLineEnding(s): """Changes all Windows/Mac line endings in s to UNIX line endings.""" @@ -191,7 +194,8 @@ def GetCommandOutput(cmd): class GTestOutputTest(unittest.TestCase): def testOutput(self): output = (GetCommandOutput(COMMAND_WITH_COLOR) + - GetCommandOutput(COMMAND_WITH_TIME)) + GetCommandOutput(COMMAND_WITH_TIME) + + GetCommandOutput(COMMAND_WITH_DISABLED)) golden_file = open(GOLDEN_PATH, 'rb') golden = golden_file.read() golden_file.close() @@ -206,7 +210,8 @@ class GTestOutputTest(unittest.TestCase): if __name__ == '__main__': if sys.argv[1:] == [GENGOLDEN_FLAG]: output = (GetCommandOutput(COMMAND_WITH_COLOR) + - GetCommandOutput(COMMAND_WITH_TIME)) + GetCommandOutput(COMMAND_WITH_TIME) + + GetCommandOutput(COMMAND_WITH_DISABLED)) golden_file = open(GOLDEN_PATH, 'wb') golden_file.write(output) golden_file.close() -- cgit v1.2.3 From 37504994338c114247519331237831f88a9a7c40 Mon Sep 17 00:00:00 2001 From: "zhanyong.wan" Date: Fri, 6 Feb 2009 00:47:20 +0000 Subject: Adds tests for EXPECT_FATAL_FAILURE and reduces the golden file bloat (by Zhanyong Wan). Fixes more warnings on Windows (by Vlad Losev). --- test/gtest_output_test.py | 9 +++++++-- 1 file changed, 7 insertions(+), 2 deletions(-) (limited to 'test/gtest_output_test.py') diff --git a/test/gtest_output_test.py b/test/gtest_output_test.py index 42cf00c4..9aaade2e 100755 --- a/test/gtest_output_test.py +++ b/test/gtest_output_test.py @@ -61,11 +61,16 @@ else: GOLDEN_NAME = 'gtest_output_test_golden_lin.txt' PROGRAM_PATH = os.path.join(gtest_test_utils.GetBuildDir(), PROGRAM) + +# At least one command we exercise must not have the +# --gtest_internal_skip_environment_and_ad_hoc_tests flag. COMMAND_WITH_COLOR = PROGRAM_PATH + ' --gtest_color=yes' COMMAND_WITH_TIME = (PROGRAM_PATH + ' --gtest_print_time ' - + '--gtest_filter="FatalFailureTest.*:LoggingTest.*"') + '--gtest_internal_skip_environment_and_ad_hoc_tests ' + '--gtest_filter="FatalFailureTest.*:LoggingTest.*"') COMMAND_WITH_DISABLED = (PROGRAM_PATH + ' --gtest_also_run_disabled_tests ' - + '--gtest_filter="*DISABLED_*"') + '--gtest_internal_skip_environment_and_ad_hoc_tests ' + '--gtest_filter="*DISABLED_*"') GOLDEN_PATH = os.path.join(gtest_test_utils.GetSourceDir(), GOLDEN_NAME) -- cgit v1.2.3 From cd3e4016ea451c9ee5cb7925329f2611098cbcf9 Mon Sep 17 00:00:00 2001 From: "zhanyong.wan" Date: Mon, 9 Feb 2009 18:05:21 +0000 Subject: Implements the test sharding protocol. By Eric Fellheimer. --- test/gtest_output_test.py | 68 ++++++++++++++++++++++++++++++----------------- 1 file changed, 44 insertions(+), 24 deletions(-) (limited to 'test/gtest_output_test.py') diff --git a/test/gtest_output_test.py b/test/gtest_output_test.py index 9aaade2e..f35e0024 100755 --- a/test/gtest_output_test.py +++ b/test/gtest_output_test.py @@ -64,13 +64,17 @@ PROGRAM_PATH = os.path.join(gtest_test_utils.GetBuildDir(), PROGRAM) # At least one command we exercise must not have the # --gtest_internal_skip_environment_and_ad_hoc_tests flag. -COMMAND_WITH_COLOR = PROGRAM_PATH + ' --gtest_color=yes' -COMMAND_WITH_TIME = (PROGRAM_PATH + ' --gtest_print_time ' +COMMAND_WITH_COLOR = ({}, PROGRAM_PATH + ' --gtest_color=yes') +COMMAND_WITH_TIME = ({}, PROGRAM_PATH + ' --gtest_print_time ' '--gtest_internal_skip_environment_and_ad_hoc_tests ' '--gtest_filter="FatalFailureTest.*:LoggingTest.*"') -COMMAND_WITH_DISABLED = (PROGRAM_PATH + ' --gtest_also_run_disabled_tests ' +COMMAND_WITH_DISABLED = ({}, PROGRAM_PATH + ' --gtest_also_run_disabled_tests ' '--gtest_internal_skip_environment_and_ad_hoc_tests ' '--gtest_filter="*DISABLED_*"') +COMMAND_WITH_SHARDING = ({'GTEST_SHARD_INDEX': '1', 'GTEST_TOTAL_SHARDS': '2'}, + PROGRAM_PATH + + ' --gtest_internal_skip_environment_and_ad_hoc_tests ' + ' --gtest_filter="PassingTest.*"') GOLDEN_PATH = os.path.join(gtest_test_utils.GetSourceDir(), GOLDEN_NAME) @@ -136,19 +140,26 @@ def NormalizeOutput(output): return output -def IterShellCommandOutput(cmd, stdin_string=None): +def IterShellCommandOutput(env_cmd, stdin_string=None): """Runs a command in a sub-process, and iterates the lines in its STDOUT. Args: - cmd: The shell command. - stdin_string: The string to be fed to the STDIN of the sub-process; - If None, the sub-process will inherit the STDIN - from the parent process. + env_cmd: The shell command. A 2-tuple where element 0 is a dict + of extra environment variables to set, and element 1 + is a string with the command and any flags. + stdin_string: The string to be fed to the STDIN of the sub-process; + If None, the sub-process will inherit the STDIN + from the parent process. """ # Spawns cmd in a sub-process, and gets its standard I/O file objects. - stdin_file, stdout_file = os.popen2(cmd, 'b') + # Set and save the environment properly. + old_env_vars = dict(os.environ) + os.environ.update(env_cmd[0]) + stdin_file, stdout_file = os.popen2(env_cmd[1], 'b') + os.environ.clear() + os.environ.update(old_env_vars) # If the caller didn't specify a string for STDIN, gets it from the # parent process. @@ -168,39 +179,50 @@ def IterShellCommandOutput(cmd, stdin_string=None): yield line -def GetShellCommandOutput(cmd, stdin_string=None): +def GetShellCommandOutput(env_cmd, stdin_string=None): """Runs a command in a sub-process, and returns its STDOUT in a string. Args: - cmd: The shell command. - stdin_string: The string to be fed to the STDIN of the sub-process; - If None, the sub-process will inherit the STDIN - from the parent process. + env_cmd: The shell command. A 2-tuple where element 0 is a dict + of extra environment variables to set, and element 1 + is a string with the command and any flags. + stdin_string: The string to be fed to the STDIN of the sub-process; + If None, the sub-process will inherit the STDIN + from the parent process. """ - lines = list(IterShellCommandOutput(cmd, stdin_string)) + lines = list(IterShellCommandOutput(env_cmd, stdin_string)) return string.join(lines, '') -def GetCommandOutput(cmd): +def GetCommandOutput(env_cmd): """Runs a command and returns its output with all file location info stripped off. Args: - cmd: the shell command. + env_cmd: The shell command. A 2-tuple where element 0 is a dict of extra + environment variables to set, and element 1 is a string with + the command and any flags. """ # Disables exception pop-ups on Windows. os.environ['GTEST_CATCH_EXCEPTIONS'] = '1' - return NormalizeOutput(GetShellCommandOutput(cmd, '')) + return NormalizeOutput(GetShellCommandOutput(env_cmd, '')) + + +def GetOutputOfAllCommands(): + """Returns concatenated output from several representative commands.""" + + return (GetCommandOutput(COMMAND_WITH_COLOR) + + GetCommandOutput(COMMAND_WITH_TIME) + + GetCommandOutput(COMMAND_WITH_DISABLED) + + GetCommandOutput(COMMAND_WITH_SHARDING)) class GTestOutputTest(unittest.TestCase): def testOutput(self): - output = (GetCommandOutput(COMMAND_WITH_COLOR) + - GetCommandOutput(COMMAND_WITH_TIME) + - GetCommandOutput(COMMAND_WITH_DISABLED)) + output = GetOutputOfAllCommands() golden_file = open(GOLDEN_PATH, 'rb') golden = golden_file.read() golden_file.close() @@ -214,9 +236,7 @@ class GTestOutputTest(unittest.TestCase): if __name__ == '__main__': if sys.argv[1:] == [GENGOLDEN_FLAG]: - output = (GetCommandOutput(COMMAND_WITH_COLOR) + - GetCommandOutput(COMMAND_WITH_TIME) + - GetCommandOutput(COMMAND_WITH_DISABLED)) + output = GetOutputOfAllCommands() golden_file = open(GOLDEN_PATH, 'wb') golden_file.write(output) golden_file.close() -- cgit v1.2.3 From 7fa242a44b47ce74d7246440b14571f7a5dd1b17 Mon Sep 17 00:00:00 2001 From: "zhanyong.wan" Date: Thu, 9 Apr 2009 02:57:38 +0000 Subject: Makes the Python tests more stable (by Vlad Losev); fixes a memory leak in GetThreadCount() on Mac (by Vlad Losev); improves fuse_gtest_files.py to support fusing Google Mock files (by Zhanyong Wan). --- test/gtest_output_test.py | 69 ++++++++++++++++++++++++++++++++++++----------- 1 file changed, 54 insertions(+), 15 deletions(-) (limited to 'test/gtest_output_test.py') diff --git a/test/gtest_output_test.py b/test/gtest_output_test.py index f35e0024..52894064 100755 --- a/test/gtest_output_test.py +++ b/test/gtest_output_test.py @@ -54,16 +54,15 @@ GENGOLDEN_FLAG = '--gengolden' IS_WINDOWS = os.name == 'nt' if IS_WINDOWS: - PROGRAM = r'..\build.dbg8\gtest_output_test_.exe' GOLDEN_NAME = 'gtest_output_test_golden_win.txt' else: - PROGRAM = 'gtest_output_test_' GOLDEN_NAME = 'gtest_output_test_golden_lin.txt' -PROGRAM_PATH = os.path.join(gtest_test_utils.GetBuildDir(), PROGRAM) +PROGRAM_PATH = gtest_test_utils.GetTestExecutablePath('gtest_output_test_') # At least one command we exercise must not have the # --gtest_internal_skip_environment_and_ad_hoc_tests flag. +COMMAND_LIST_TESTS = ({}, PROGRAM_PATH + ' --gtest_list_tests') COMMAND_WITH_COLOR = ({}, PROGRAM_PATH + ' --gtest_color=yes') COMMAND_WITH_TIME = ({}, PROGRAM_PATH + ' --gtest_print_time ' '--gtest_internal_skip_environment_and_ad_hoc_tests ' @@ -76,8 +75,7 @@ COMMAND_WITH_SHARDING = ({'GTEST_SHARD_INDEX': '1', 'GTEST_TOTAL_SHARDS': '2'}, ' --gtest_internal_skip_environment_and_ad_hoc_tests ' ' --gtest_filter="PassingTest.*"') -GOLDEN_PATH = os.path.join(gtest_test_utils.GetSourceDir(), - GOLDEN_NAME) +GOLDEN_PATH = os.path.join(gtest_test_utils.GetSourceDir(), GOLDEN_NAME) def ToUnixLineEnding(s): @@ -119,15 +117,35 @@ def RemoveTime(output): def RemoveTestCounts(output): """Removes test counts from a Google Test program's output.""" + 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', '? tests from ? test cases', output) return re.sub(r'\d+ tests\.', '? tests.', output) -def RemoveDeathTests(output): - """Removes death test information from a Google Test program's output.""" +def RemoveMatchingTests(test_output, pattern): + """Removes typed test information from a Google Test program's output. - return re.sub(r'\n.*DeathTest.*', '', output) + This function strips not only the beginning and the end of a test but also all + output in between. + + Args: + test_output: A string containing the test output. + pattern: A string that matches names of test cases to remove. + + Returns: + Contents of test_output with removed test case whose names match pattern. + """ + + test_output = re.sub( + r'\[ RUN \] .*%s(.|\n)*?\[( FAILED | OK )\] .*%s.*\n' % ( + pattern, pattern), + '', + test_output) + return re.sub(r'.*%s.*\n' % pattern, '', test_output) def NormalizeOutput(output): @@ -220,7 +238,19 @@ def GetOutputOfAllCommands(): GetCommandOutput(COMMAND_WITH_SHARDING)) +test_list = GetShellCommandOutput(COMMAND_LIST_TESTS, '') +SUPPORTS_DEATH_TESTS = 'DeathTest' in test_list +SUPPORTS_TYPED_TESTS = 'TypedTest' in test_list + + class GTestOutputTest(unittest.TestCase): + def RemoveUnsupportedTests(self, test_output): + if not SUPPORTS_DEATH_TESTS: + test_output = RemoveMatchingTests(test_output, 'DeathTest') + if not SUPPORTS_TYPED_TESTS: + test_output = RemoveMatchingTests(test_output, 'TypedTest') + return test_output + def testOutput(self): output = GetOutputOfAllCommands() golden_file = open(GOLDEN_PATH, 'rb') @@ -229,16 +259,25 @@ class GTestOutputTest(unittest.TestCase): # We want the test to pass regardless of death tests being # supported or not. - self.assert_(output == golden or - RemoveTestCounts(output) == - RemoveTestCounts(RemoveDeathTests(golden))) + if SUPPORTS_DEATH_TESTS and SUPPORTS_TYPED_TESTS: + self.assert_(golden == output) + else: + print RemoveTestCounts(self.RemoveUnsupportedTests(golden)) + self.assert_(RemoveTestCounts(self.RemoveUnsupportedTests(golden)) == + RemoveTestCounts(output)) if __name__ == '__main__': if sys.argv[1:] == [GENGOLDEN_FLAG]: - output = GetOutputOfAllCommands() - golden_file = open(GOLDEN_PATH, 'wb') - golden_file.write(output) - golden_file.close() + if SUPPORTS_DEATH_TESTS and SUPPORTS_TYPED_TESTS: + output = GetOutputOfAllCommands() + golden_file = open(GOLDEN_PATH, 'wb') + golden_file.write(output) + golden_file.close() + else: + print >> sys.stderr, ('Unable to write a golden file when compiled in an ' + 'environment that does not support death tests and ' + 'typed tests. Are you using VC 7.1?') + sys.exit(1) else: gtest_test_utils.Main() -- cgit v1.2.3 From 9b23e3cc7677643f6adaf6c327275d0a7cdff02c Mon Sep 17 00:00:00 2001 From: "zhanyong.wan" Date: Tue, 5 May 2009 19:31:00 +0000 Subject: Removes dead code (by Vlad Losev). Fixes tr1 tuple's path on gcc version before 4.0.0 (by Zhanyong Wan). --- test/gtest_output_test.py | 1 - 1 file changed, 1 deletion(-) (limited to 'test/gtest_output_test.py') diff --git a/test/gtest_output_test.py b/test/gtest_output_test.py index 52894064..6cff1623 100755 --- a/test/gtest_output_test.py +++ b/test/gtest_output_test.py @@ -262,7 +262,6 @@ class GTestOutputTest(unittest.TestCase): if SUPPORTS_DEATH_TESTS and SUPPORTS_TYPED_TESTS: self.assert_(golden == output) else: - print RemoveTestCounts(self.RemoveUnsupportedTests(golden)) self.assert_(RemoveTestCounts(self.RemoveUnsupportedTests(golden)) == RemoveTestCounts(output)) -- cgit v1.2.3 From 1bd424d9608d85fc6b705a2370ed86db3118dcf6 Mon Sep 17 00:00:00 2001 From: "zhanyong.wan" Date: Fri, 29 May 2009 19:46:51 +0000 Subject: Adds missing copyright in test/gtest-test-part_test.cc (by Markus Heule). Minor format adjustments. --- test/gtest_output_test.py | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) (limited to 'test/gtest_output_test.py') diff --git a/test/gtest_output_test.py b/test/gtest_output_test.py index 6cff1623..2751fa66 100755 --- a/test/gtest_output_test.py +++ b/test/gtest_output_test.py @@ -253,8 +253,13 @@ class GTestOutputTest(unittest.TestCase): def testOutput(self): output = GetOutputOfAllCommands() + golden_file = open(GOLDEN_PATH, 'rb') - golden = golden_file.read() + # 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 + # unconditionally. + golden = ToUnixLineEnding(golden_file.read()) golden_file.close() # We want the test to pass regardless of death tests being -- cgit v1.2.3 From 532dc2de35f2cef191bc91c3587a9f8f4974756f Mon Sep 17 00:00:00 2001 From: "zhanyong.wan" Date: Wed, 17 Jun 2009 21:06:27 +0000 Subject: Implements a subset of TR1 tuple needed by gtest and gmock (by Zhanyong Wan); cleaned up the Python tests (by Vlad Losev); made run_tests.py invokable from any directory (by Vlad Losev). --- test/gtest_output_test.py | 87 +++++++++++++++++++++++++++++++++++------------ 1 file changed, 66 insertions(+), 21 deletions(-) (limited to 'test/gtest_output_test.py') diff --git a/test/gtest_output_test.py b/test/gtest_output_test.py index 2751fa66..91cf9153 100755 --- a/test/gtest_output_test.py +++ b/test/gtest_output_test.py @@ -44,7 +44,6 @@ import os import re import string import sys -import unittest import gtest_test_utils @@ -84,11 +83,11 @@ def ToUnixLineEnding(s): return s.replace('\r\n', '\n').replace('\r', '\n') -def RemoveLocations(output): +def RemoveLocations(test_output): """Removes all file location info from a Google Test program's output. Args: - output: the output of a Google Test program. + test_output: the output of a Google Test program. Returns: output with all file location info (in the form of @@ -97,10 +96,10 @@ def RemoveLocations(output): 'FILE_NAME:#: '. """ - return re.sub(r'.*[/\\](.+)(\:\d+|\(\d+\))\: ', r'\1:#: ', output) + return re.sub(r'.*[/\\](.+)(\:\d+|\(\d+\))\: ', r'\1:#: ', test_output) -def RemoveStackTraces(output): +def RemoveStackTraceDetails(output): """Removes all stack traces from a Google Test program's output.""" # *? means "find the shortest string that matches". @@ -108,6 +107,13 @@ def RemoveStackTraces(output): 'Stack trace: (omitted)\n\n', output) +def RemoveStackTraces(output): + """Removes all traces of stack traces from a Google Test program's output.""" + + # *? means "find the shortest string that matches". + return re.sub(r'Stack trace:(.|\n)*?\n\n', '', output) + + def RemoveTime(output): """Removes all time information from a Google Test program's output.""" @@ -123,25 +129,28 @@ def RemoveTestCounts(output): '? FAILED TESTS', output) 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_])', + r'? tests from \1', output) return re.sub(r'\d+ tests\.', '? tests.', output) def RemoveMatchingTests(test_output, pattern): - """Removes typed test information from a Google Test program's output. + """Removes output of specified tests from a Google Test program's output. - This function strips not only the beginning and the end of a test but also all - output in between. + This function strips not only the beginning and the end of a test but also + all output in between. Args: test_output: A string containing the test output. - pattern: A string that matches names of test cases to remove. + pattern: A regex string that matches names of test cases or + tests to remove. Returns: - Contents of test_output with removed test case whose names match pattern. + Contents of test_output with tests whose names match pattern removed. """ test_output = re.sub( - r'\[ RUN \] .*%s(.|\n)*?\[( FAILED | OK )\] .*%s.*\n' % ( + r'.*\[ RUN \] .*%s(.|\n)*?\[( FAILED | OK )\] .*%s.*\n' % ( pattern, pattern), '', test_output) @@ -153,7 +162,7 @@ def NormalizeOutput(output): output = ToUnixLineEnding(output) output = RemoveLocations(output) - output = RemoveStackTraces(output) + output = RemoveStackTraceDetails(output) output = RemoveTime(output) return output @@ -241,14 +250,28 @@ def GetOutputOfAllCommands(): 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 + +CAN_GENERATE_GOLDEN_FILE = SUPPORTS_DEATH_TESTS and SUPPORTS_TYPED_TESTS -class GTestOutputTest(unittest.TestCase): +class GTestOutputTest(gtest_test_utils.TestCase): def RemoveUnsupportedTests(self, test_output): if not SUPPORTS_DEATH_TESTS: test_output = RemoveMatchingTests(test_output, 'DeathTest') if not SUPPORTS_TYPED_TESTS: test_output = RemoveMatchingTests(test_output, 'TypedTest') + if not SUPPORTS_THREADS: + test_output = RemoveMatchingTests(test_output, + 'ExpectFailureWithThreadsTest') + test_output = RemoveMatchingTests(test_output, + 'ScopedFakeTestPartResultReporterTest') + test_output = RemoveMatchingTests(test_output, + 'WorksConcurrently') + if not SUPPORTS_STACK_TRACES: + test_output = RemoveStackTraces(test_output) + return test_output def testOutput(self): @@ -262,26 +285,48 @@ class GTestOutputTest(unittest.TestCase): golden = ToUnixLineEnding(golden_file.read()) golden_file.close() - # We want the test to pass regardless of death tests being + # We want the test to pass regardless of certain features being # supported or not. - if SUPPORTS_DEATH_TESTS and SUPPORTS_TYPED_TESTS: + if CAN_GENERATE_GOLDEN_FILE: self.assert_(golden == output) else: - self.assert_(RemoveTestCounts(self.RemoveUnsupportedTests(golden)) == - RemoveTestCounts(output)) + normalized_actual = RemoveTestCounts(output) + normalized_golden = RemoveTestCounts(self.RemoveUnsupportedTests(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.assert_(normalized_golden == normalized_actual) if __name__ == '__main__': if sys.argv[1:] == [GENGOLDEN_FLAG]: - if SUPPORTS_DEATH_TESTS and SUPPORTS_TYPED_TESTS: + if CAN_GENERATE_GOLDEN_FILE: output = GetOutputOfAllCommands() golden_file = open(GOLDEN_PATH, 'wb') golden_file.write(output) golden_file.close() else: - print >> sys.stderr, ('Unable to write a golden file when compiled in an ' - 'environment that does not support death tests and ' - 'typed tests. Are you using VC 7.1?') + message = ( + """Unable to write a golden file when compiled in an environment +that does not support all the required features (death tests""") + if IS_WINDOWS: + message += ( + """\nand typed tests). Please check that you are using VC++ 8.0 SP1 +or higher as your compiler.""") + else: + message += """\nand typed tests). Please generate the golden file +using a binary built with those features enabled.""" + + sys.stderr.write(message) sys.exit(1) else: gtest_test_utils.Main() -- cgit v1.2.3 From ae3247986bbbafcc913b5fe6132090ad6f1c3f36 Mon Sep 17 00:00:00 2001 From: "zhanyong.wan" Date: Fri, 19 Jun 2009 00:24:28 +0000 Subject: Fixes broken gtest_unittest on Cygwin and cleans it up (by Vlad Losev); fixes the wrong usage of os.environ.clear() in gtest_output_test.py (by Vlad Losev); fixes the logic for detecting Symbian (by Zhanyong Wan); moves TestProperty for event listener (by Vlad Losev). --- test/gtest_output_test.py | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) (limited to 'test/gtest_output_test.py') diff --git a/test/gtest_output_test.py b/test/gtest_output_test.py index 91cf9153..c6ea0f8c 100755 --- a/test/gtest_output_test.py +++ b/test/gtest_output_test.py @@ -185,7 +185,11 @@ def IterShellCommandOutput(env_cmd, stdin_string=None): old_env_vars = dict(os.environ) os.environ.update(env_cmd[0]) stdin_file, stdout_file = os.popen2(env_cmd[1], 'b') - os.environ.clear() + # 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) # If the caller didn't specify a string for STDIN, gets it from the -- cgit v1.2.3 From b2db677c9905a34ca6454aa526f7a0cc5cfaeca1 Mon Sep 17 00:00:00 2001 From: "zhanyong.wan" Date: Wed, 1 Jul 2009 04:58:05 +0000 Subject: Reduces the flakiness of gtest-port_test on Mac; improves the Python tests; hides methods that we don't want to publish; makes win-dbg8 the default scons configuration (all by Vlad Losev). --- test/gtest_output_test.py | 85 ++++++++++++++++------------------------------- 1 file changed, 28 insertions(+), 57 deletions(-) (limited to 'test/gtest_output_test.py') diff --git a/test/gtest_output_test.py b/test/gtest_output_test.py index c6ea0f8c..c8a38f53 100755 --- a/test/gtest_output_test.py +++ b/test/gtest_output_test.py @@ -42,7 +42,6 @@ __author__ = 'wan@google.com (Zhanyong Wan)' import os import re -import string import sys import gtest_test_utils @@ -61,18 +60,22 @@ PROGRAM_PATH = gtest_test_utils.GetTestExecutablePath('gtest_output_test_') # At least one command we exercise must not have the # --gtest_internal_skip_environment_and_ad_hoc_tests flag. -COMMAND_LIST_TESTS = ({}, PROGRAM_PATH + ' --gtest_list_tests') -COMMAND_WITH_COLOR = ({}, PROGRAM_PATH + ' --gtest_color=yes') -COMMAND_WITH_TIME = ({}, PROGRAM_PATH + ' --gtest_print_time ' - '--gtest_internal_skip_environment_and_ad_hoc_tests ' - '--gtest_filter="FatalFailureTest.*:LoggingTest.*"') -COMMAND_WITH_DISABLED = ({}, PROGRAM_PATH + ' --gtest_also_run_disabled_tests ' - '--gtest_internal_skip_environment_and_ad_hoc_tests ' - '--gtest_filter="*DISABLED_*"') -COMMAND_WITH_SHARDING = ({'GTEST_SHARD_INDEX': '1', 'GTEST_TOTAL_SHARDS': '2'}, - PROGRAM_PATH + - ' --gtest_internal_skip_environment_and_ad_hoc_tests ' - ' --gtest_filter="PassingTest.*"') +COMMAND_LIST_TESTS = ({}, [PROGRAM_PATH, '--gtest_list_tests']) +COMMAND_WITH_COLOR = ({}, [PROGRAM_PATH, '--gtest_color=yes']) +COMMAND_WITH_TIME = ({}, [PROGRAM_PATH, + '--gtest_print_time', + '--gtest_internal_skip_environment_and_ad_hoc_tests', + '--gtest_filter=FatalFailureTest.*:LoggingTest.*']) +COMMAND_WITH_DISABLED = ( + {}, [PROGRAM_PATH, + '--gtest_also_run_disabled_tests', + '--gtest_internal_skip_environment_and_ad_hoc_tests', + '--gtest_filter=*DISABLED_*']) +COMMAND_WITH_SHARDING = ( + {'GTEST_SHARD_INDEX': '1', 'GTEST_TOTAL_SHARDS': '2'}, + [PROGRAM_PATH, + '--gtest_internal_skip_environment_and_ad_hoc_tests', + '--gtest_filter=PassingTest.*']) GOLDEN_PATH = os.path.join(gtest_test_utils.GetSourceDir(), GOLDEN_NAME) @@ -167,24 +170,24 @@ def NormalizeOutput(output): return output -def IterShellCommandOutput(env_cmd, stdin_string=None): - """Runs a command in a sub-process, and iterates the lines in its STDOUT. +def GetShellCommandOutput(env_cmd): + """Runs a command in a sub-process, and returns its output in a string. Args: + env_cmd: The shell command. A 2-tuple where element 0 is a dict of extra + environment variables to set, and element 1 is a string with + the command and any flags. - env_cmd: The shell command. A 2-tuple where element 0 is a dict - of extra environment variables to set, and element 1 - is a string with the command and any flags. - stdin_string: The string to be fed to the STDIN of the sub-process; - If None, the sub-process will inherit the STDIN - from the parent process. + Returns: + A string with the command's combined standard and diagnostic output. """ # Spawns cmd in a sub-process, and gets its standard I/O file objects. # Set and save the environment properly. old_env_vars = dict(os.environ) os.environ.update(env_cmd[0]) - stdin_file, stdout_file = os.popen2(env_cmd[1], 'b') + 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. @@ -192,39 +195,7 @@ def IterShellCommandOutput(env_cmd, stdin_string=None): del os.environ[key] os.environ.update(old_env_vars) - # If the caller didn't specify a string for STDIN, gets it from the - # parent process. - if stdin_string is None: - stdin_string = sys.stdin.read() - - # Feeds the STDIN string to the sub-process. - stdin_file.write(stdin_string) - stdin_file.close() - - while True: - line = stdout_file.readline() - if not line: # EOF - stdout_file.close() - break - - yield line - - -def GetShellCommandOutput(env_cmd, stdin_string=None): - """Runs a command in a sub-process, and returns its STDOUT in a string. - - Args: - - env_cmd: The shell command. A 2-tuple where element 0 is a dict - of extra environment variables to set, and element 1 - is a string with the command and any flags. - stdin_string: The string to be fed to the STDIN of the sub-process; - If None, the sub-process will inherit the STDIN - from the parent process. - """ - - lines = list(IterShellCommandOutput(env_cmd, stdin_string)) - return string.join(lines, '') + return p.output def GetCommandOutput(env_cmd): @@ -239,7 +210,7 @@ def GetCommandOutput(env_cmd): # Disables exception pop-ups on Windows. os.environ['GTEST_CATCH_EXCEPTIONS'] = '1' - return NormalizeOutput(GetShellCommandOutput(env_cmd, '')) + return NormalizeOutput(GetShellCommandOutput(env_cmd)) def GetOutputOfAllCommands(): @@ -251,7 +222,7 @@ def GetOutputOfAllCommands(): GetCommandOutput(COMMAND_WITH_SHARDING)) -test_list = GetShellCommandOutput(COMMAND_LIST_TESTS, '') +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 -- cgit v1.2.3 From 88e97c822c988eaa9f8bcbaa1ea5d702ffd7d384 Mon Sep 17 00:00:00 2001 From: "zhanyong.wan" Date: Wed, 16 Dec 2009 23:34:59 +0000 Subject: Removes uses of GTEST_HAS_STD_STRING. --- test/gtest_output_test.py | 28 ++++++++++++++-------------- 1 file changed, 14 insertions(+), 14 deletions(-) (limited to 'test/gtest_output_test.py') diff --git a/test/gtest_output_test.py b/test/gtest_output_test.py index c8a38f53..8d9a40b0 100755 --- a/test/gtest_output_test.py +++ b/test/gtest_output_test.py @@ -126,15 +126,15 @@ def RemoveTime(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): @@ -268,16 +268,16 @@ class GTestOutputTest(gtest_test_utils.TestCase): normalized_actual = RemoveTestCounts(output) normalized_golden = RemoveTestCounts(self.RemoveUnsupportedTests(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) + # 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) self.assert_(normalized_golden == normalized_actual) -- cgit v1.2.3 From 6f50ccf32c31cb6e287cdfee149429ac3029bbdb Mon Sep 17 00:00:00 2001 From: vladlosev Date: Mon, 15 Feb 2010 21:31:41 +0000 Subject: Google Test's Python tests now pass on Solaris. --- test/gtest_output_test.py | 46 +++++++++++++++++++++++++++++++--------------- 1 file changed, 31 insertions(+), 15 deletions(-) (limited to 'test/gtest_output_test.py') diff --git a/test/gtest_output_test.py b/test/gtest_output_test.py index 8d9a40b0..a0aa64fd 100755 --- a/test/gtest_output_test.py +++ b/test/gtest_output_test.py @@ -48,6 +48,7 @@ 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' @@ -123,6 +124,20 @@ 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.""" @@ -184,16 +199,9 @@ def GetShellCommandOutput(env_cmd): # Spawns cmd in a sub-process, and gets its standard I/O file objects. # Set and save the environment properly. - 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) + environ = os.environ.copy() + environ.update(env_cmd[0]) + p = gtest_test_utils.Subprocess(env_cmd[1], env=environ) return p.output @@ -209,8 +217,10 @@ def GetCommandOutput(env_cmd): """ # Disables exception pop-ups on Windows. - os.environ['GTEST_CATCH_EXCEPTIONS'] = '1' - return NormalizeOutput(GetShellCommandOutput(env_cmd)) + 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))) def GetOutputOfAllCommands(): @@ -262,11 +272,17 @@ 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.assert_(golden == output) + self.assert_(normalized_golden == normalized_actual) else: - normalized_actual = RemoveTestCounts(output) - normalized_golden = RemoveTestCounts(self.RemoveUnsupportedTests(golden)) + normalized_actual = RemoveTestCounts(normalized_actual) + normalized_golden = RemoveTestCounts(self.RemoveUnsupportedTests( + normalized_golden)) # This code is very handy when debugging golden file differences: if os.getenv('DEBUG_GTEST_OUTPUT_TEST'): -- cgit v1.2.3 From 3bef459eac9aa84c579f34249aebc9ff56832054 Mon Sep 17 00:00:00 2001 From: "zhanyong.wan" Date: Wed, 24 Feb 2010 17:19:25 +0000 Subject: Adds threading support (by Miklos Fazekas, Vlad Losev, and Chandler Carruth); adds wide InitGoogleTest to gtest.def (by Vlad Losev); updates the version number (by Zhanyong Wan); updates the release notes for 1.5.0 (by Vlad Losev); removes scons scripts from the distribution (by Zhanyong Wan); adds the cmake build script to the distribution (by Zhanyong Wan); adds fused source files to the distribution (by Vlad Losev and Chandler Carruth). --- test/gtest_output_test.py | 8 +++++--- 1 file changed, 5 insertions(+), 3 deletions(-) (limited to 'test/gtest_output_test.py') diff --git a/test/gtest_output_test.py b/test/gtest_output_test.py index a0aa64fd..4374a96e 100755 --- a/test/gtest_output_test.py +++ b/test/gtest_output_test.py @@ -238,7 +238,9 @@ 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 +CAN_GENERATE_GOLDEN_FILE = (SUPPORTS_DEATH_TESTS and + SUPPORTS_TYPED_TESTS and + SUPPORTS_THREADS) class GTestOutputTest(gtest_test_utils.TestCase): @@ -314,8 +316,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 += """\nand typed tests). Please generate the golden file -using a binary built with those features enabled.""" + message += """\ntyped tests, and threads). Please generate the +golden file using a binary built with those features enabled.""" sys.stderr.write(message) sys.exit(1) -- cgit v1.2.3 From 70eceaf8e7c6eb5c58838418db1768d8f08e53f5 Mon Sep 17 00:00:00 2001 From: vladlosev Date: Sat, 27 Feb 2010 00:48:00 +0000 Subject: Fixes issue 216 (gtest_output_test broken on Solaris --- test/gtest_output_test.py | 2 ++ 1 file changed, 2 insertions(+) (limited to 'test/gtest_output_test.py') diff --git a/test/gtest_output_test.py b/test/gtest_output_test.py index 4374a96e..125970aa 100755 --- a/test/gtest_output_test.py +++ b/test/gtest_output_test.py @@ -249,6 +249,8 @@ 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') -- cgit v1.2.3 From 12a92c26fc0e0de81f687dbe739a6aa24f37f9dd Mon Sep 17 00:00:00 2001 From: "zhanyong.wan" Date: Thu, 4 Mar 2010 22:15:53 +0000 Subject: Renames ThreadStartSempahore to Notificaton (by Vlad Losev); adds threading tests for SCOPED_TRACE() (by Vlad Losev); replaces native pthread calls with gtest's threading constructs (by Vlad Losev); fixes flakiness in CountedDestructor (by Vlad Losev); minor MSVC 7.1 clean-up (by Zhanyong Wan). --- test/gtest_output_test.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) (limited to 'test/gtest_output_test.py') diff --git a/test/gtest_output_test.py b/test/gtest_output_test.py index 125970aa..192030a2 100755 --- a/test/gtest_output_test.py +++ b/test/gtest_output_test.py @@ -282,7 +282,7 @@ class GTestOutputTest(gtest_test_utils.TestCase): normalized_golden = RemoveTypeInfoDetails(golden) if CAN_GENERATE_GOLDEN_FILE: - self.assert_(normalized_golden == normalized_actual) + self.assertEqual(normalized_golden, normalized_actual) else: normalized_actual = RemoveTestCounts(normalized_actual) normalized_golden = RemoveTestCounts(self.RemoveUnsupportedTests( @@ -299,7 +299,7 @@ class GTestOutputTest(gtest_test_utils.TestCase): '_gtest_output_test_normalized_golden.txt'), 'wb').write( normalized_golden) - self.assert_(normalized_golden == normalized_actual) + self.assertEqual(normalized_golden, normalized_actual) if __name__ == '__main__': -- cgit v1.2.3 From 3678a248d35723d5e18c7c2a78d7da5b4f5a3e57 Mon Sep 17 00:00:00 2001 From: vladlosev Date: Thu, 13 May 2010 18:05:20 +0000 Subject: Renames test script flags. --- test/gtest_output_test.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'test/gtest_output_test.py') diff --git a/test/gtest_output_test.py b/test/gtest_output_test.py index 192030a2..dca4af04 100755 --- a/test/gtest_output_test.py +++ b/test/gtest_output_test.py @@ -32,7 +32,7 @@ """Tests the text output of Google C++ Testing Framework. SYNOPSIS - gtest_output_test.py --gtest_build_dir=BUILD/DIR --gengolden + gtest_output_test.py --build_dir=BUILD/DIR --gengolden # where BUILD/DIR contains the built gtest_output_test_ file. gtest_output_test.py --gengolden gtest_output_test.py -- cgit v1.2.3 From 1097b54dcf1cd393e64ec0adf54301a575bbbc1c Mon Sep 17 00:00:00 2001 From: vladlosev Date: Tue, 18 May 2010 21:13:48 +0000 Subject: Implements printing parameters of failed parameterized tests (issue 71). --- test/gtest_output_test.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'test/gtest_output_test.py') diff --git a/test/gtest_output_test.py b/test/gtest_output_test.py index dca4af04..425d9da4 100755 --- a/test/gtest_output_test.py +++ b/test/gtest_output_test.py @@ -240,7 +240,7 @@ SUPPORTS_STACK_TRACES = False CAN_GENERATE_GOLDEN_FILE = (SUPPORTS_DEATH_TESTS and SUPPORTS_TYPED_TESTS and - SUPPORTS_THREADS) + (SUPPORTS_THREADS or IS_WINDOWS)) class GTestOutputTest(gtest_test_utils.TestCase): -- cgit v1.2.3 From a9f380f5c7ff75cd715c58e11885dddc54baef02 Mon Sep 17 00:00:00 2001 From: "zhanyong.wan" Date: Thu, 19 Aug 2010 22:16:00 +0000 Subject: Removes the Windows golden file (by Vlad Losev); implements test result streaming (by Nikhil Jindal and cleaned up by Zhanyong Wan). --- test/gtest_output_test.py | 40 ++++++++++++++++++++++++---------------- 1 file changed, 24 insertions(+), 16 deletions(-) (limited to 'test/gtest_output_test.py') diff --git a/test/gtest_output_test.py b/test/gtest_output_test.py index 425d9da4..f409e2a7 100755 --- a/test/gtest_output_test.py +++ b/test/gtest_output_test.py @@ -52,10 +52,8 @@ CATCH_EXCEPTIONS_ENV_VAR_NAME = 'GTEST_CATCH_EXCEPTIONS' IS_WINDOWS = os.name == 'nt' -if IS_WINDOWS: - GOLDEN_NAME = 'gtest_output_test_golden_win.txt' -else: - GOLDEN_NAME = 'gtest_output_test_golden_lin.txt' +# TODO(vladl@google.com): remove the _lin suffix. +GOLDEN_NAME = 'gtest_output_test_golden_lin.txt' PROGRAM_PATH = gtest_test_utils.GetTestExecutablePath('gtest_output_test_') @@ -138,6 +136,20 @@ def RemoveTypeInfoDetails(test_output): return re.sub(r'unsigned int', 'unsigned', test_output) +def NormalizeToCurrentPlatform(test_output): + """Normalizes platform specific output details for easier comparison.""" + + if IS_WINDOWS: + # Removes the color information that is not present on Windows. + test_output = re.sub('\x1b\\[(0;3\d)?m', '', test_output) + # Changes failure message headers into the Windows format. + test_output = re.sub(r': Failure\n', r': error: ', test_output) + # Changes file(line_number) to file:line_number. + test_output = re.sub(r'((\w|\.)+)\((\d+)\):', r'\1:\3:', test_output) + + return test_output + + def RemoveTestCounts(output): """Removes test counts from a Google Test program's output.""" @@ -240,7 +252,7 @@ SUPPORTS_STACK_TRACES = False CAN_GENERATE_GOLDEN_FILE = (SUPPORTS_DEATH_TESTS and SUPPORTS_TYPED_TESTS and - (SUPPORTS_THREADS or IS_WINDOWS)) + SUPPORTS_THREADS) class GTestOutputTest(gtest_test_utils.TestCase): @@ -284,9 +296,10 @@ class GTestOutputTest(gtest_test_utils.TestCase): if CAN_GENERATE_GOLDEN_FILE: self.assertEqual(normalized_golden, normalized_actual) else: - normalized_actual = RemoveTestCounts(normalized_actual) - normalized_golden = RemoveTestCounts(self.RemoveUnsupportedTests( - normalized_golden)) + normalized_actual = NormalizeToCurrentPlatform( + RemoveTestCounts(normalized_actual)) + normalized_golden = NormalizeToCurrentPlatform( + RemoveTestCounts(self.RemoveUnsupportedTests(normalized_golden))) # This code is very handy when debugging golden file differences: if os.getenv('DEBUG_GTEST_OUTPUT_TEST'): @@ -312,14 +325,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""") - if IS_WINDOWS: - message += ( - """\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.""" +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.""") sys.stderr.write(message) sys.exit(1) -- cgit v1.2.3 From f0b86fc3b0f625e1db84f3632cb37bd9eae6ae19 Mon Sep 17 00:00:00 2001 From: jgm Date: Fri, 9 Mar 2012 17:12:39 +0000 Subject: Misc small updates to some debug death code, and to messages streaming to macros --- test/gtest_output_test.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'test/gtest_output_test.py') diff --git a/test/gtest_output_test.py b/test/gtest_output_test.py index f409e2a7..72b3ae00 100755 --- a/test/gtest_output_test.py +++ b/test/gtest_output_test.py @@ -213,7 +213,7 @@ def GetShellCommandOutput(env_cmd): # 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) + p = gtest_test_utils.Subprocess(env_cmd[1], env=environ, capture_stderr=False) return p.output -- cgit v1.2.3 From b535c1767e7ec4e9675bb7257d9bc34a84949741 Mon Sep 17 00:00:00 2001 From: vladlosev Date: Thu, 6 Sep 2012 17:09:27 +0000 Subject: Removes obsolete debug code. --- test/gtest_output_test.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'test/gtest_output_test.py') diff --git a/test/gtest_output_test.py b/test/gtest_output_test.py index 72b3ae00..f409e2a7 100755 --- a/test/gtest_output_test.py +++ b/test/gtest_output_test.py @@ -213,7 +213,7 @@ def GetShellCommandOutput(env_cmd): # 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, capture_stderr=False) + p = gtest_test_utils.Subprocess(env_cmd[1], env=environ) return p.output -- cgit v1.2.3 From a6340420b9cee27f77c5b91bea807121914a5831 Mon Sep 17 00:00:00 2001 From: kosak Date: Mon, 24 Mar 2014 21:58:25 +0000 Subject: Implement threading support for gtest on Windows. Also, stop using localtime(). Instead, use localtime_r() on most systems, localtime_s() on Windows. --- test/gtest_output_test.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) (limited to 'test/gtest_output_test.py') diff --git a/test/gtest_output_test.py b/test/gtest_output_test.py index f409e2a7..fa1a3117 100755 --- a/test/gtest_output_test.py +++ b/test/gtest_output_test.py @@ -252,8 +252,8 @@ SUPPORTS_STACK_TRACES = False CAN_GENERATE_GOLDEN_FILE = (SUPPORTS_DEATH_TESTS and SUPPORTS_TYPED_TESTS and - SUPPORTS_THREADS) - + SUPPORTS_THREADS and + not IS_WINDOWS) class GTestOutputTest(gtest_test_utils.TestCase): def RemoveUnsupportedTests(self, test_output): -- cgit v1.2.3 From 80167de7055d61ed54808995fb7d632781a5f70e Mon Sep 17 00:00:00 2001 From: kosak Date: Tue, 14 Jul 2015 22:29:59 +0000 Subject: Minor refactoring. --- test/gtest_output_test.py | 15 ++++++++++----- 1 file changed, 10 insertions(+), 5 deletions(-) (limited to 'test/gtest_output_test.py') diff --git a/test/gtest_output_test.py b/test/gtest_output_test.py index fa1a3117..d5c637b4 100755 --- a/test/gtest_output_test.py +++ b/test/gtest_output_test.py @@ -40,6 +40,7 @@ SYNOPSIS __author__ = 'wan@google.com (Zhanyong Wan)' +import difflib import os import re import sys @@ -58,22 +59,22 @@ GOLDEN_NAME = 'gtest_output_test_golden_lin.txt' PROGRAM_PATH = gtest_test_utils.GetTestExecutablePath('gtest_output_test_') # At least one command we exercise must not have the -# --gtest_internal_skip_environment_and_ad_hoc_tests flag. +# 'internal_skip_environment_and_ad_hoc_tests' argument. COMMAND_LIST_TESTS = ({}, [PROGRAM_PATH, '--gtest_list_tests']) COMMAND_WITH_COLOR = ({}, [PROGRAM_PATH, '--gtest_color=yes']) COMMAND_WITH_TIME = ({}, [PROGRAM_PATH, '--gtest_print_time', - '--gtest_internal_skip_environment_and_ad_hoc_tests', + 'internal_skip_environment_and_ad_hoc_tests', '--gtest_filter=FatalFailureTest.*:LoggingTest.*']) COMMAND_WITH_DISABLED = ( {}, [PROGRAM_PATH, '--gtest_also_run_disabled_tests', - '--gtest_internal_skip_environment_and_ad_hoc_tests', + 'internal_skip_environment_and_ad_hoc_tests', '--gtest_filter=*DISABLED_*']) COMMAND_WITH_SHARDING = ( {'GTEST_SHARD_INDEX': '1', 'GTEST_TOTAL_SHARDS': '2'}, [PROGRAM_PATH, - '--gtest_internal_skip_environment_and_ad_hoc_tests', + 'internal_skip_environment_and_ad_hoc_tests', '--gtest_filter=PassingTest.*']) GOLDEN_PATH = os.path.join(gtest_test_utils.GetSourceDir(), GOLDEN_NAME) @@ -294,7 +295,11 @@ class GTestOutputTest(gtest_test_utils.TestCase): normalized_golden = RemoveTypeInfoDetails(golden) if CAN_GENERATE_GOLDEN_FILE: - self.assertEqual(normalized_golden, normalized_actual) + self.assertEqual(normalized_golden, normalized_actual, + '\n'.join(difflib.unified_diff( + normalized_golden.split('\n'), + normalized_actual.split('\n'), + 'golden', 'actual'))) else: normalized_actual = NormalizeToCurrentPlatform( RemoveTestCounts(normalized_actual)) -- cgit v1.2.3