32 """Unit test for Google Test's --gtest_list_tests flag. 34 A user can ask Google Test to list all tests by specifying the 35 --gtest_list_tests flag. This script tests such functionality 36 by invoking gtest_list_tests_unittest_ (a program written with 37 Google Test) the command line flags. 40 __author__ =
'phanna@google.com (Patrick Hanna)' 42 import gtest_test_utils
49 LIST_TESTS_FLAG =
'gtest_list_tests' 56 EXPECTED_OUTPUT_NO_FILTER_RE = re.compile(
r"""FooDeathTest\. 71 TypedTest/0\. # TypeParam = (VeryLo{245}|class VeryLo{239})\.\.\. 74 TypedTest/1\. # TypeParam = int\s*\* 77 TypedTest/2\. # TypeParam = .*MyArray<bool,\s*42> 80 My/TypeParamTest/0\. # TypeParam = (VeryLo{245}|class VeryLo{239})\.\.\. 83 My/TypeParamTest/1\. # TypeParam = int\s*\* 86 My/TypeParamTest/2\. # TypeParam = .*MyArray<bool,\s*42> 89 MyInstantiation/ValueParamTest\. 90 TestA/0 # GetParam\(\) = one line 91 TestA/1 # GetParam\(\) = two\\nlines 92 TestA/2 # GetParam\(\) = a very\\nlo{241}\.\.\. 93 TestB/0 # GetParam\(\) = one line 94 TestB/1 # GetParam\(\) = two\\nlines 95 TestB/2 # GetParam\(\) = a very\\nlo{241}\.\.\. 100 EXPECTED_OUTPUT_FILTER_FOO_RE = re.compile(
r"""FooDeathTest\. 118 """Runs gtest_list_tests_unittest_ and returns the list of tests printed.""" 121 capture_stderr=
False).output
127 """Tests using the --gtest_list_tests flag to list all tests.""" 130 """Runs gtest_list_tests_unittest_ and verifies that it prints 134 flag_value: value of the --gtest_list_tests flag; 135 None if the flag should not be present. 136 expected_output_re: regular expression that matches the expected 137 output after running command; 138 other_flag: a different flag to be passed to command 139 along with gtest_list_tests; 140 None if the flag should not be present. 143 if flag_value
is None:
145 flag_expression =
'not set' 146 elif flag_value ==
'0':
147 flag =
'--%s=0' % LIST_TESTS_FLAG
148 flag_expression =
'0' 150 flag =
'--%s' % LIST_TESTS_FLAG
151 flag_expression =
'1' 155 if other_flag
is not None:
160 if expected_output_re:
162 expected_output_re.match(output),
163 (
'when %s is %s, the output of "%s" is "%s",\n' 164 'which does not match regex "%s"' %
165 (LIST_TESTS_FLAG, flag_expression,
' '.join(args), output,
166 expected_output_re.pattern)))
169 not EXPECTED_OUTPUT_NO_FILTER_RE.match(output),
170 (
'when %s is %s, the output of "%s" is "%s"'%
171 (LIST_TESTS_FLAG, flag_expression,
' '.join(args), output)))
174 """Tests the behavior of the default mode.""" 177 expected_output_re=
None,
181 """Tests using the --gtest_list_tests flag.""" 184 expected_output_re=
None,
187 expected_output_re=EXPECTED_OUTPUT_NO_FILTER_RE,
191 """Tests that --gtest_list_tests overrides the non-filter flags.""" 194 expected_output_re=EXPECTED_OUTPUT_NO_FILTER_RE,
195 other_flag=
'--gtest_break_on_failure')
198 """Tests that --gtest_list_tests takes into account the 199 --gtest_filter flag.""" 202 expected_output_re=EXPECTED_OUTPUT_FILTER_FOO_RE,
203 other_flag=
'--gtest_filter=Foo*')
206 if __name__ ==
'__main__':
def RunAndVerify(self, flag_value, expected_output_re, other_flag)
def GetTestExecutablePath(executable_name, build_dir=None)
def testDefaultBehavior(self)
def testWithFilterFlags(self)
def testOverrideNonFilterFlags(self)