Makes --gtest_list_tests honor the test filter (by Jay Campan).

This commit is contained in:
zhanyong.wan
2009-04-24 20:27:29 +00:00
parent f2d0d0e3d5
commit fa2b06c52f
5 changed files with 86 additions and 41 deletions

View File

@@ -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.
"""
stdout_file = os.popen(command, "r")
def Run(command):
"""Runs a command and returns the list of tests printed."""
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()