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 googletest-list-tests-unittest_ (a program written with
37 Google Test) the command line flags.
41 from googletest.test
import gtest_test_utils
46 LIST_TESTS_FLAG =
'gtest_list_tests'
53 EXPECTED_OUTPUT_NO_FILTER_RE = re.compile(
r"""FooDeathTest\.
68 TypedTest/0\. # TypeParam = (VeryLo{245}|class VeryLo{239})\.\.\.
71 TypedTest/1\. # TypeParam = int\s*\*( __ptr64)?
74 TypedTest/2\. # TypeParam = .*MyArray<bool,\s*42>
77 My/TypeParamTest/0\. # TypeParam = (VeryLo{245}|class VeryLo{239})\.\.\.
80 My/TypeParamTest/1\. # TypeParam = int\s*\*( __ptr64)?
83 My/TypeParamTest/2\. # TypeParam = .*MyArray<bool,\s*42>
86 MyInstantiation/ValueParamTest\.
87 TestA/0 # GetParam\(\) = one line
88 TestA/1 # GetParam\(\) = two\\nlines
89 TestA/2 # GetParam\(\) = a very\\nlo{241}\.\.\.
90 TestB/0 # GetParam\(\) = one line
91 TestB/1 # GetParam\(\) = two\\nlines
92 TestB/2 # GetParam\(\) = a very\\nlo{241}\.\.\.
97 EXPECTED_OUTPUT_FILTER_FOO_RE = re.compile(
r"""FooDeathTest\.
115 """Runs googletest-list-tests-unittest_ and returns the list of tests printed."""
118 capture_stderr=
False).output
125 """Tests using the --gtest_list_tests flag to list all tests."""
128 """Runs googletest-list-tests-unittest_ and verifies that it prints
132 flag_value: value of the --gtest_list_tests flag;
133 None if the flag should not be present.
134 expected_output_re: regular expression that matches the expected
135 output after running command;
136 other_flag: a different flag to be passed to command
137 along with gtest_list_tests;
138 None if the flag should not be present.
141 if flag_value
is None:
143 flag_expression =
'not set'
144 elif flag_value ==
'0':
145 flag =
'--%s=0' % LIST_TESTS_FLAG
146 flag_expression =
'0'
148 flag =
'--%s' % LIST_TESTS_FLAG
149 flag_expression =
'1'
153 if other_flag
is not None:
158 if expected_output_re:
160 expected_output_re.match(output),
161 (
'when %s is %s, the output of "%s" is "%s",\n'
162 'which does not match regex "%s"' %
163 (LIST_TESTS_FLAG, flag_expression,
' '.join(args), output,
164 expected_output_re.pattern)))
167 not EXPECTED_OUTPUT_NO_FILTER_RE.match(output),
168 (
'when %s is %s, the output of "%s" is "%s"'%
169 (LIST_TESTS_FLAG, flag_expression,
' '.join(args), output)))
172 """Tests the behavior of the default mode."""
175 expected_output_re=
None,
179 """Tests using the --gtest_list_tests flag."""
182 expected_output_re=
None,
185 expected_output_re=EXPECTED_OUTPUT_NO_FILTER_RE,
189 """Tests that --gtest_list_tests overrides the non-filter flags."""
192 expected_output_re=EXPECTED_OUTPUT_NO_FILTER_RE,
193 other_flag=
'--gtest_break_on_failure')
196 """Tests that --gtest_list_tests takes into account the
197 --gtest_filter flag."""
200 expected_output_re=EXPECTED_OUTPUT_FILTER_FOO_RE,
201 other_flag=
'--gtest_filter=Foo*')
204 if __name__ ==
'__main__':