From 87d23e45f096c91c9e722b20bf15b733dbab0f80 Mon Sep 17 00:00:00 2001 From: "zhanyong.wan" Date: Wed, 11 Mar 2009 22:18:52 +0000 Subject: Implements the --help flag; fixes tests on Windows. --- test/gtest_help_test.py | 127 ++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 127 insertions(+) create mode 100755 test/gtest_help_test.py (limited to 'test/gtest_help_test.py') diff --git a/test/gtest_help_test.py b/test/gtest_help_test.py new file mode 100755 index 00000000..cc5819ce --- /dev/null +++ b/test/gtest_help_test.py @@ -0,0 +1,127 @@ +#!/usr/bin/python2.4 +# +# Copyright 2009, 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 --help flag of Google C++ Testing Framework. + +SYNOPSIS + gtest_help_test.py --gtest_build_dir=BUILD/DIR + # where BUILD/DIR contains the built gtest_help_test_ file. + gtest_help_test.py +""" + +__author__ = 'wan@google.com (Zhanyong Wan)' + +import gtest_test_utils +import os +import re +import unittest + + +IS_WINDOWS = os.name == 'nt' + +if IS_WINDOWS: + PROGRAM = 'gtest_help_test_.exe' +else: + PROGRAM = 'gtest_help_test_' + +PROGRAM_PATH = os.path.join(gtest_test_utils.GetBuildDir(), PROGRAM) +FLAG_PREFIX = '--gtest_' +CATCH_EXCEPTIONS_FLAG = FLAG_PREFIX + 'catch_exceptions' + +# The help message must match this regex. +HELP_REGEX = re.compile( + FLAG_PREFIX + r'list_tests.*' + + FLAG_PREFIX + r'filter=.*' + + FLAG_PREFIX + r'also_run_disabled_tests.*' + + FLAG_PREFIX + r'repeat=.*' + + FLAG_PREFIX + r'color=.*' + + FLAG_PREFIX + r'print_time.*' + + FLAG_PREFIX + r'output=.*' + + FLAG_PREFIX + r'break_on_failure.*' + + FLAG_PREFIX + r'throw_on_failure.*', + re.DOTALL) + + +def RunWithFlag(flag): + """Runs gtest_help_test_ with the given flag. + + Returns: + the exit code and the text output as a tuple. + Args: + flag: the command-line flag to pass to gtest_help_test_, or None. + """ + + if flag is None: + command = [PROGRAM_PATH] + else: + command = [PROGRAM_PATH, flag] + child = gtest_test_utils.Subprocess(command) + return child.exit_code, child.output + + +class GTestHelpTest(unittest.TestCase): + """Tests the --help flag and its equivalent forms.""" + + def TestHelpFlag(self, flag): + """Verifies that the right message is printed and the tests are + skipped when the given flag is specified.""" + + exit_code, output = RunWithFlag(flag) + self.assertEquals(0, exit_code) + self.assert_(HELP_REGEX.search(output), output) + if IS_WINDOWS: + self.assert_(CATCH_EXCEPTIONS_FLAG in output, output) + else: + self.assert_(CATCH_EXCEPTIONS_FLAG not in output, output) + + def testPrintsHelpWithFullFlag(self): + self.TestHelpFlag('--help') + + def testPrintsHelpWithShortFlag(self): + self.TestHelpFlag('-h') + + def testPrintsHelpWithQuestionFlag(self): + self.TestHelpFlag('-?') + + def testPrintsHelpWithWindowsStyleQuestionFlag(self): + self.TestHelpFlag('/?') + + def testRunsTestsWithoutHelpFlag(self): + """Verifies that when no help flag is specified, the tests are run + and the help message is not printed.""" + + exit_code, output = RunWithFlag(None) + self.assert_(exit_code != 0) + self.assert_(not HELP_REGEX.search(output), output) + + +if __name__ == '__main__': + gtest_test_utils.Main() -- cgit v1.2.3 From 61e953e8c39d9a82823cddc9581b5bcd583e49d4 Mon Sep 17 00:00:00 2001 From: "zhanyong.wan" Date: Tue, 17 Mar 2009 21:19:55 +0000 Subject: Fixes two tests on Cygwin, which has no python 2.4. --- test/gtest_help_test.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'test/gtest_help_test.py') diff --git a/test/gtest_help_test.py b/test/gtest_help_test.py index cc5819ce..98c8fe75 100755 --- a/test/gtest_help_test.py +++ b/test/gtest_help_test.py @@ -1,4 +1,4 @@ -#!/usr/bin/python2.4 +#!/usr/bin/env python # # Copyright 2009, Google Inc. # All rights reserved. -- cgit v1.2.3 From 3c7bbf5b46679aea4e0ac7d3ad241cb036146751 Mon Sep 17 00:00:00 2001 From: "zhanyong.wan" Date: Thu, 26 Mar 2009 19:03:47 +0000 Subject: Simplifies implementation by defining a POSIX portability layer; adds the death test style flag to --help. --- test/gtest_help_test.py | 3 +++ 1 file changed, 3 insertions(+) (limited to 'test/gtest_help_test.py') diff --git a/test/gtest_help_test.py b/test/gtest_help_test.py index 98c8fe75..62710192 100755 --- a/test/gtest_help_test.py +++ b/test/gtest_help_test.py @@ -55,6 +55,7 @@ else: PROGRAM_PATH = os.path.join(gtest_test_utils.GetBuildDir(), PROGRAM) FLAG_PREFIX = '--gtest_' CATCH_EXCEPTIONS_FLAG = FLAG_PREFIX + 'catch_exceptions' +DEATH_TEST_STYLE_FLAG = FLAG_PREFIX + 'death_test_style' # The help message must match this regex. HELP_REGEX = re.compile( @@ -99,8 +100,10 @@ class GTestHelpTest(unittest.TestCase): self.assert_(HELP_REGEX.search(output), output) if IS_WINDOWS: self.assert_(CATCH_EXCEPTIONS_FLAG in output, output) + self.assert_(DEATH_TEST_STYLE_FLAG not in output, output) else: self.assert_(CATCH_EXCEPTIONS_FLAG not in output, output) + self.assert_(DEATH_TEST_STYLE_FLAG in output, output) def testPrintsHelpWithFullFlag(self): self.TestHelpFlag('--help') -- 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_help_test.py | 7 +------ 1 file changed, 1 insertion(+), 6 deletions(-) (limited to 'test/gtest_help_test.py') diff --git a/test/gtest_help_test.py b/test/gtest_help_test.py index 62710192..d81f149f 100755 --- a/test/gtest_help_test.py +++ b/test/gtest_help_test.py @@ -47,12 +47,7 @@ import unittest IS_WINDOWS = os.name == 'nt' -if IS_WINDOWS: - PROGRAM = 'gtest_help_test_.exe' -else: - PROGRAM = 'gtest_help_test_' - -PROGRAM_PATH = os.path.join(gtest_test_utils.GetBuildDir(), PROGRAM) +PROGRAM_PATH = gtest_test_utils.GetTestExecutablePath('gtest_help_test_') FLAG_PREFIX = '--gtest_' CATCH_EXCEPTIONS_FLAG = FLAG_PREFIX + 'catch_exceptions' DEATH_TEST_STYLE_FLAG = FLAG_PREFIX + 'death_test_style' -- 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_help_test.py | 5 ++--- 1 file changed, 2 insertions(+), 3 deletions(-) (limited to 'test/gtest_help_test.py') diff --git a/test/gtest_help_test.py b/test/gtest_help_test.py index d81f149f..0a2a07b6 100755 --- a/test/gtest_help_test.py +++ b/test/gtest_help_test.py @@ -39,10 +39,9 @@ SYNOPSIS __author__ = 'wan@google.com (Zhanyong Wan)' -import gtest_test_utils import os import re -import unittest +import gtest_test_utils IS_WINDOWS = os.name == 'nt' @@ -83,7 +82,7 @@ def RunWithFlag(flag): return child.exit_code, child.output -class GTestHelpTest(unittest.TestCase): +class GTestHelpTest(gtest_test_utils.TestCase): """Tests the --help flag and its equivalent forms.""" def TestHelpFlag(self, flag): -- cgit v1.2.3 From 8bdb31e0540c46de485b362178f60e8bb947ff43 Mon Sep 17 00:00:00 2001 From: "zhanyong.wan" Date: Tue, 14 Jul 2009 22:56:46 +0000 Subject: Adds the command line flags needed for test shuffling. Most code by Josh Kelley. --- test/gtest_help_test.py | 2 ++ 1 file changed, 2 insertions(+) (limited to 'test/gtest_help_test.py') diff --git a/test/gtest_help_test.py b/test/gtest_help_test.py index 0a2a07b6..91081ad3 100755 --- a/test/gtest_help_test.py +++ b/test/gtest_help_test.py @@ -57,6 +57,8 @@ HELP_REGEX = re.compile( FLAG_PREFIX + r'filter=.*' + FLAG_PREFIX + r'also_run_disabled_tests.*' + FLAG_PREFIX + r'repeat=.*' + + FLAG_PREFIX + r'shuffle.*' + + FLAG_PREFIX + r'random_seed=.*' + FLAG_PREFIX + r'color=.*' + FLAG_PREFIX + r'print_time.*' + FLAG_PREFIX + r'output=.*' + -- cgit v1.2.3 From 6bfc4b2bd378940fa006bd32b9667ad4137d8f15 Mon Sep 17 00:00:00 2001 From: vladlosev Date: Thu, 22 Oct 2009 01:22:29 +0000 Subject: Prints help when encountering unrecognized Google Test flags. --- test/gtest_help_test.py | 46 +++++++++++++++++++++++++++++++++++++++++----- 1 file changed, 41 insertions(+), 5 deletions(-) (limited to 'test/gtest_help_test.py') diff --git a/test/gtest_help_test.py b/test/gtest_help_test.py index 91081ad3..7883c1c5 100755 --- a/test/gtest_help_test.py +++ b/test/gtest_help_test.py @@ -50,6 +50,11 @@ PROGRAM_PATH = gtest_test_utils.GetTestExecutablePath('gtest_help_test_') FLAG_PREFIX = '--gtest_' CATCH_EXCEPTIONS_FLAG = FLAG_PREFIX + 'catch_exceptions' DEATH_TEST_STYLE_FLAG = FLAG_PREFIX + 'death_test_style' +UNKNOWN_FLAG = FLAG_PREFIX + 'unknown_flag_for_testing' +INCORRECT_FLAG_VARIANTS = [re.sub('^--', '-', DEATH_TEST_STYLE_FLAG), + re.sub('^--', '/', DEATH_TEST_STYLE_FLAG), + re.sub('_', '-', DEATH_TEST_STYLE_FLAG)] +INTERNAL_FLAG_FOR_TESTING = FLAG_PREFIX + 'internal_flag_for_testing' # The help message must match this regex. HELP_REGEX = re.compile( @@ -88,8 +93,14 @@ class GTestHelpTest(gtest_test_utils.TestCase): """Tests the --help flag and its equivalent forms.""" def TestHelpFlag(self, flag): - """Verifies that the right message is printed and the tests are - skipped when the given flag is specified.""" + """Verifies correct behavior when help flag is specified. + + The right message must be printed and the tests must + skipped when the given flag is specified. + + Args: + flag: A flag to pass to the binary or None. + """ exit_code, output = RunWithFlag(flag) self.assertEquals(0, exit_code) @@ -101,6 +112,20 @@ class GTestHelpTest(gtest_test_utils.TestCase): self.assert_(CATCH_EXCEPTIONS_FLAG not in output, output) self.assert_(DEATH_TEST_STYLE_FLAG in output, output) + def TestNonHelpFlag(self, flag): + """Verifies correct behavior when no help flag is specified. + + Verifies that when no help flag is specified, the tests are run + and the help message is not printed. + + Args: + flag: A flag to pass to the binary or None. + """ + + exit_code, output = RunWithFlag(flag) + self.assert_(exit_code != 0) + self.assert_(not HELP_REGEX.search(output), output) + def testPrintsHelpWithFullFlag(self): self.TestHelpFlag('--help') @@ -113,13 +138,24 @@ class GTestHelpTest(gtest_test_utils.TestCase): def testPrintsHelpWithWindowsStyleQuestionFlag(self): self.TestHelpFlag('/?') + def testPrintsHelpWithUnrecognizedGoogleTestFlag(self): + self.TestHelpFlag(UNKNOWN_FLAG) + + def testPrintsHelpWithIncorrectFlagStyle(self): + for incorrect_flag in INCORRECT_FLAG_VARIANTS: + self.TestHelpFlag(incorrect_flag) + def testRunsTestsWithoutHelpFlag(self): """Verifies that when no help flag is specified, the tests are run and the help message is not printed.""" - exit_code, output = RunWithFlag(None) - self.assert_(exit_code != 0) - self.assert_(not HELP_REGEX.search(output), output) + self.TestNonHelpFlag(None) + + def testRunsTestsWithGtestInternalFlag(self): + """Verifies that the tests are run and no help message is printed when + a flag starting with Google Test prefix and 'internal_' is supplied.""" + + self.TestNonHelpFlag(INTERNAL_FLAG_FOR_TESTING) if __name__ == '__main__': -- cgit v1.2.3 From eddd9e85a829b91eb8d0a5ff10abed85abb33bdf Mon Sep 17 00:00:00 2001 From: vladlosev Date: Thu, 8 Apr 2010 01:01:12 +0000 Subject: Fixes gtest_filter_unittest and gtest_help_test on systems without death tests. --- test/gtest_help_test.py | 15 +++++++++++---- 1 file changed, 11 insertions(+), 4 deletions(-) (limited to 'test/gtest_help_test.py') diff --git a/test/gtest_help_test.py b/test/gtest_help_test.py index 7883c1c5..3cb4c48e 100755 --- a/test/gtest_help_test.py +++ b/test/gtest_help_test.py @@ -51,11 +51,15 @@ FLAG_PREFIX = '--gtest_' CATCH_EXCEPTIONS_FLAG = FLAG_PREFIX + 'catch_exceptions' DEATH_TEST_STYLE_FLAG = FLAG_PREFIX + 'death_test_style' UNKNOWN_FLAG = FLAG_PREFIX + 'unknown_flag_for_testing' -INCORRECT_FLAG_VARIANTS = [re.sub('^--', '-', DEATH_TEST_STYLE_FLAG), - re.sub('^--', '/', DEATH_TEST_STYLE_FLAG), - re.sub('_', '-', DEATH_TEST_STYLE_FLAG)] +LIST_TESTS_FLAG = FLAG_PREFIX + 'list_tests' +INCORRECT_FLAG_VARIANTS = [re.sub('^--', '-', LIST_TESTS_FLAG), + re.sub('^--', '/', LIST_TESTS_FLAG), + re.sub('_', '-', LIST_TESTS_FLAG)] INTERNAL_FLAG_FOR_TESTING = FLAG_PREFIX + 'internal_flag_for_testing' +SUPPORTS_DEATH_TESTS = "DeathTest" in gtest_test_utils.Subprocess( + [PROGRAM_PATH, LIST_TESTS_FLAG]).output + # The help message must match this regex. HELP_REGEX = re.compile( FLAG_PREFIX + r'list_tests.*' + @@ -107,10 +111,13 @@ class GTestHelpTest(gtest_test_utils.TestCase): self.assert_(HELP_REGEX.search(output), output) if IS_WINDOWS: self.assert_(CATCH_EXCEPTIONS_FLAG in output, output) - self.assert_(DEATH_TEST_STYLE_FLAG not in output, output) else: self.assert_(CATCH_EXCEPTIONS_FLAG not in output, output) + + if SUPPORTS_DEATH_TESTS and not IS_WINDOWS: self.assert_(DEATH_TEST_STYLE_FLAG in output, output) + else: + self.assert_(DEATH_TEST_STYLE_FLAG not in output, output) def TestNonHelpFlag(self, flag): """Verifies correct behavior when no help flag is specified. -- 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_help_test.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'test/gtest_help_test.py') diff --git a/test/gtest_help_test.py b/test/gtest_help_test.py index 3cb4c48e..dc67ed3d 100755 --- a/test/gtest_help_test.py +++ b/test/gtest_help_test.py @@ -32,7 +32,7 @@ """Tests the --help flag of Google C++ Testing Framework. SYNOPSIS - gtest_help_test.py --gtest_build_dir=BUILD/DIR + gtest_help_test.py --build_dir=BUILD/DIR # where BUILD/DIR contains the built gtest_help_test_ file. gtest_help_test.py """ -- 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_help_test.py | 13 ++++++++----- 1 file changed, 8 insertions(+), 5 deletions(-) (limited to 'test/gtest_help_test.py') diff --git a/test/gtest_help_test.py b/test/gtest_help_test.py index dc67ed3d..0777106a 100755 --- a/test/gtest_help_test.py +++ b/test/gtest_help_test.py @@ -44,12 +44,13 @@ import re import gtest_test_utils +IS_LINUX = os.name == 'posix' and os.uname()[0] == 'Linux' IS_WINDOWS = os.name == 'nt' PROGRAM_PATH = gtest_test_utils.GetTestExecutablePath('gtest_help_test_') FLAG_PREFIX = '--gtest_' -CATCH_EXCEPTIONS_FLAG = FLAG_PREFIX + 'catch_exceptions' DEATH_TEST_STYLE_FLAG = FLAG_PREFIX + 'death_test_style' +STREAM_RESULT_TO_FLAG = FLAG_PREFIX + 'stream_result_to' UNKNOWN_FLAG = FLAG_PREFIX + 'unknown_flag_for_testing' LIST_TESTS_FLAG = FLAG_PREFIX + 'list_tests' INCORRECT_FLAG_VARIANTS = [re.sub('^--', '-', LIST_TESTS_FLAG), @@ -72,7 +73,8 @@ HELP_REGEX = re.compile( FLAG_PREFIX + r'print_time.*' + FLAG_PREFIX + r'output=.*' + FLAG_PREFIX + r'break_on_failure.*' + - FLAG_PREFIX + r'throw_on_failure.*', + FLAG_PREFIX + r'throw_on_failure.*' + + FLAG_PREFIX + r'catch_exceptions.*', re.DOTALL) @@ -109,10 +111,11 @@ class GTestHelpTest(gtest_test_utils.TestCase): exit_code, output = RunWithFlag(flag) self.assertEquals(0, exit_code) self.assert_(HELP_REGEX.search(output), output) - if IS_WINDOWS: - self.assert_(CATCH_EXCEPTIONS_FLAG in output, output) + + if IS_LINUX: + self.assert_(STREAM_RESULT_TO_FLAG in output, output) else: - self.assert_(CATCH_EXCEPTIONS_FLAG not in output, output) + self.assert_(STREAM_RESULT_TO_FLAG not in output, output) if SUPPORTS_DEATH_TESTS and not IS_WINDOWS: self.assert_(DEATH_TEST_STYLE_FLAG in output, output) -- cgit v1.2.3 From 82cc1d1135879be3b901a10e224dbd827365f8bf Mon Sep 17 00:00:00 2001 From: vladlosev Date: Tue, 26 Oct 2010 23:12:47 +0000 Subject: Changes default of --gtest_catch_exceptions to true. --- test/gtest_help_test.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'test/gtest_help_test.py') diff --git a/test/gtest_help_test.py b/test/gtest_help_test.py index 0777106a..093c838d 100755 --- a/test/gtest_help_test.py +++ b/test/gtest_help_test.py @@ -74,7 +74,7 @@ HELP_REGEX = re.compile( FLAG_PREFIX + r'output=.*' + FLAG_PREFIX + r'break_on_failure.*' + FLAG_PREFIX + r'throw_on_failure.*' + - FLAG_PREFIX + r'catch_exceptions.*', + FLAG_PREFIX + r'catch_exceptions=0.*', re.DOTALL) -- cgit v1.2.3