31"""Unit test for Google Test's --gtest_list_tests flag.
33A user can ask Google Test to list all tests by specifying the
34--gtest_list_tests flag. If output is requested, via --gtest_output=xml
35or --gtest_output=json, the tests are listed, with extra information in the
37This script tests such functionality by invoking gtest_list_output_unittest_
38 (a program written with Google Test) the command line flags.
43import gtest_test_utils
45GTEST_LIST_TESTS_FLAG =
'--gtest_list_tests'
46GTEST_OUTPUT_FLAG =
'--gtest_output'
48EXPECTED_XML =
"""<\?xml version="1.0" encoding="UTF-8"\?>
49<testsuites tests="16" name="AllTests">
50 <testsuite name="FooTest" tests=
"2">
51 <testcase name=
"Test1" file=
".*gtest_list_output_unittest_.cc" line=
"43" />
52 <testcase name=
"Test2" file=
".*gtest_list_output_unittest_.cc" line=
"45" />
54 <testsuite name=
"FooTestFixture" tests=
"2">
55 <testcase name=
"Test3" file=
".*gtest_list_output_unittest_.cc" line=
"48" />
56 <testcase name=
"Test4" file=
".*gtest_list_output_unittest_.cc" line=
"49" />
58 <testsuite name=
"TypedTest/0" tests=
"2">
59 <testcase name=
"Test7" type_param=
"int" file=
".*gtest_list_output_unittest_.cc" line=
"60" />
60 <testcase name=
"Test8" type_param=
"int" file=
".*gtest_list_output_unittest_.cc" line=
"61" />
62 <testsuite name=
"TypedTest/1" tests=
"2">
63 <testcase name=
"Test7" type_param=
"bool" file=
".*gtest_list_output_unittest_.cc" line=
"60" />
64 <testcase name=
"Test8" type_param=
"bool" file=
".*gtest_list_output_unittest_.cc" line=
"61" />
66 <testsuite name=
"Single/TypeParameterizedTestSuite/0" tests=
"2">
67 <testcase name=
"Test9" type_param=
"int" file=
".*gtest_list_output_unittest_.cc" line=
"66" />
68 <testcase name=
"Test10" type_param=
"int" file=
".*gtest_list_output_unittest_.cc" line=
"67" />
70 <testsuite name=
"Single/TypeParameterizedTestSuite/1" tests=
"2">
71 <testcase name=
"Test9" type_param=
"bool" file=
".*gtest_list_output_unittest_.cc" line=
"66" />
72 <testcase name=
"Test10" type_param=
"bool" file=
".*gtest_list_output_unittest_.cc" line=
"67" />
74 <testsuite name=
"ValueParam/ValueParamTest" tests=
"4">
75 <testcase name=
"Test5/0" value_param=
"33" file=
".*gtest_list_output_unittest_.cc" line=
"52" />
76 <testcase name=
"Test5/1" value_param=
"42" file=
".*gtest_list_output_unittest_.cc" line=
"52" />
77 <testcase name=
"Test6/0" value_param=
"33" file=
".*gtest_list_output_unittest_.cc" line=
"53" />
78 <testcase name=
"Test6/1" value_param=
"42" file=
".*gtest_list_output_unittest_.cc" line=
"53" />
93 "file":
".*gtest_list_output_unittest_.cc",
98 "file":
".*gtest_list_output_unittest_.cc",
104 "name":
"FooTestFixture",
109 "file":
".*gtest_list_output_unittest_.cc",
114 "file":
".*gtest_list_output_unittest_.cc",
120 "name":
"TypedTest\\\\/0",
126 "file":
".*gtest_list_output_unittest_.cc",
132 "file":
".*gtest_list_output_unittest_.cc",
138 "name":
"TypedTest\\\\/1",
143 "type_param":
"bool",
144 "file":
".*gtest_list_output_unittest_.cc",
149 "type_param":
"bool",
150 "file":
".*gtest_list_output_unittest_.cc",
156 "name":
"Single\\\\/TypeParameterizedTestSuite\\\\/0",
162 "file":
".*gtest_list_output_unittest_.cc",
168 "file":
".*gtest_list_output_unittest_.cc",
174 "name":
"Single\\\\/TypeParameterizedTestSuite\\\\/1",
179 "type_param":
"bool",
180 "file":
".*gtest_list_output_unittest_.cc",
185 "type_param":
"bool",
186 "file":
".*gtest_list_output_unittest_.cc",
192 "name":
"ValueParam\\\\/ValueParamTest",
196 "name":
"Test5\\\\/0",
198 "file":
".*gtest_list_output_unittest_.cc",
202 "name":
"Test5\\\\/1",
204 "file":
".*gtest_list_output_unittest_.cc",
208 "name":
"Test6\\\\/0",
210 "file":
".*gtest_list_output_unittest_.cc",
214 "name":
"Test6\\\\/1",
216 "file":
".*gtest_list_output_unittest_.cc",
226class GTestListTestsOutputUnitTest(gtest_test_utils.TestCase):
227 """Unit test for Google Test's list tests with output to file functionality.
231 """Verifies XML output for listing tests in a Google Test binary.
233 Runs a test program that generates an empty XML output, and
234 tests that the XML output
is expected.
239 """Verifies XML output for listing tests in a Google Test binary.
241 Runs a test program that generates an empty XML output, and
242 tests that the XML output
is expected.
246 def _GetOutput(self, out_format):
248 'test_out.' + out_format)
250 'gtest_list_output_unittest_')
254 '%s=%s:%s' % (GTEST_OUTPUT_FLAG, out_format, file_path),
257 environ_copy = os.environ.copy()
261 self.assertTrue(p.exited)
262 self.assertEqual(0, p.exit_code)
263 self.assertTrue(os.path.isfile(file_path))
264 with open(file_path)
as f:
268 def _TestOutput(self, test_format, expected_output):
270 actual_lines = actual.splitlines()
271 expected_lines = expected_output.splitlines()
273 for actual_line
in actual_lines:
274 expected_line = expected_lines[line_count]
275 expected_line_re = re.compile(expected_line.strip())
277 expected_line_re.match(actual_line.strip()),
278 (
'actual output of "%s",\n'
279 'which does not match expected regex of "%s"\n'
280 'on line %d' % (actual, expected_output, line_count)))
281 line_count = line_count + 1
284if __name__ ==
'__main__':
285 os.environ[
'GTEST_STACK_TRACE_DEPTH'] =
'1'
def GetTestExecutablePath(executable_name, build_dir=None)
def _GetOutput(self, out_format)
def _TestOutput(self, test_format, expected_output)