From fa2b06c52fa3ffb1909ed8b928e106292609cfcb Mon Sep 17 00:00:00 2001 From: "zhanyong.wan" Date: Fri, 24 Apr 2009 20:27:29 +0000 Subject: Makes --gtest_list_tests honor the test filter (by Jay Campan). --- test/gtest_list_tests_unittest.py | 55 +++++++++++++++++++++++++++------------ 1 file changed, 38 insertions(+), 17 deletions(-) (limited to 'test/gtest_list_tests_unittest.py') diff --git a/test/gtest_list_tests_unittest.py b/test/gtest_list_tests_unittest.py index 147bd73a..3d006dfe 100755 --- a/test/gtest_list_tests_unittest.py +++ b/test/gtest_list_tests_unittest.py @@ -56,12 +56,12 @@ EXE_PATH = gtest_test_utils.GetTestExecutablePath('gtest_list_tests_unittest_') # The expected output when running gtest_list_tests_unittest_ with # --gtest_list_tests -EXPECTED_OUTPUT = """FooDeathTest. +EXPECTED_OUTPUT_NO_FILTER = """FooDeathTest. Test1 Foo. Bar1 Bar2 - Bar3 + DISABLED_Bar3 Abc. Xyz Def @@ -69,17 +69,33 @@ FooBar. Baz FooTest. Test1 - Test2 + DISABLED_Test2 + Test3 +""" + +# The expected output when running gtest_list_tests_unittest_ with +# --gtest_list_tests and --gtest_filter=Foo*. +EXPECTED_OUTPUT_FILTER_FOO = """FooDeathTest. + Test1 +Foo. + Bar1 + Bar2 + DISABLED_Bar3 +FooBar. + Baz +FooTest. + Test1 + DISABLED_Test2 Test3 """ # Utilities. + def Run(command): - """Runs a command and returns the list of tests printed. - """ + """Runs a command and returns the list of tests printed.""" - stdout_file = os.popen(command, "r") + stdout_file = os.popen(command, 'r') output = stdout_file.read() @@ -90,8 +106,7 @@ def Run(command): # The unit test. class GTestListTestsUnitTest(unittest.TestCase): - """Tests using the --gtest_list_tests flag to list all tests. - """ + """Tests using the --gtest_list_tests flag to list all tests.""" def RunAndVerify(self, flag_value, expected_output, other_flag): """Runs gtest_list_tests_unittest_ and verifies that it prints @@ -126,12 +141,12 @@ class GTestListTestsUnitTest(unittest.TestCase): output = Run(command) msg = ('when %s is %s, the output of "%s" is "%s".' % - (LIST_TESTS_FLAG, flag_expression, command, output)) + (LIST_TESTS_FLAG, flag_expression, command, output)) if expected_output is not None: self.assert_(output == expected_output, msg) else: - self.assert_(output != EXPECTED_OUTPUT, msg) + self.assert_(output != EXPECTED_OUTPUT_NO_FILTER, msg) def testDefaultBehavior(self): """Tests the behavior of the default mode.""" @@ -147,18 +162,24 @@ class GTestListTestsUnitTest(unittest.TestCase): expected_output=None, other_flag=None) self.RunAndVerify(flag_value='1', - expected_output=EXPECTED_OUTPUT, + expected_output=EXPECTED_OUTPUT_NO_FILTER, other_flag=None) - def testOverrideOtherFlags(self): - """Tests that --gtest_list_tests overrides all other flags.""" + def testOverrideNonFilterFlags(self): + """Tests that --gtest_list_tests overrides the non-filter flags.""" self.RunAndVerify(flag_value="1", - expected_output=EXPECTED_OUTPUT, - other_flag="--gtest_filter=*") - self.RunAndVerify(flag_value="1", - expected_output=EXPECTED_OUTPUT, + expected_output=EXPECTED_OUTPUT_NO_FILTER, other_flag="--gtest_break_on_failure") + def testWithFilterFlags(self): + """Tests that --gtest_list_tests takes into account the + --gtest_filter flag.""" + + self.RunAndVerify(flag_value="1", + expected_output=EXPECTED_OUTPUT_FILTER_FOO, + other_flag="--gtest_filter=Foo*") + + if __name__ == '__main__': gtest_test_utils.Main() -- cgit v1.2.3