31 """Unit test for Google Test's --gtest_list_tests flag.
33 A 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
35 or --gtest_output=json, the tests are listed, with extra information in the
37 This script tests such functionality by invoking gtest_list_output_unittest_
38 (a program written with Google Test) the command line flags.
43 import gtest_test_utils
45 GTEST_LIST_TESTS_FLAG =
'--gtest_list_tests'
46 GTEST_OUTPUT_FLAG =
'--gtest_output'
48 EXPECTED_XML =
"""<\?xml version="1.0" encoding="UTF-8"\?>
49 <testsuites tests="2" 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" />
67 "file": ".*gtest_list_output_unittest_.cc",
72 "file": ".*gtest_list_output_unittest_.cc",
83 """Unit test for Google Test's list tests with output to file functionality.
87 """Verifies XML output for listing tests in a Google Test binary.
89 Runs a test program that generates an empty XML output, and
90 tests that the XML output is expected.
95 """Verifies XML output for listing tests in a Google Test binary.
97 Runs a test program that generates an empty XML output, and
98 tests that the XML output is expected.
104 'test_out.' + out_format)
106 'gtest_list_output_unittest_')
110 '%s=%s:%s' % (GTEST_OUTPUT_FLAG, out_format, file_path),
113 environ_copy = os.environ.copy()
117 self.assert_(p.exited)
118 self.assertEquals(0, p.exit_code)
119 with open(file_path)
as f:
125 actual_lines = actual.splitlines()
126 expected_lines = expected_output.splitlines()
128 for actual_line
in actual_lines:
129 expected_line = expected_lines[line_count]
130 expected_line_re = re.compile(expected_line.strip())
132 expected_line_re.match(actual_line.strip()),
133 (
'actual output of "%s",\n'
134 'which does not match expected regex of "%s"\n'
135 'on line %d' % (actual, expected_output, line_count)))
136 line_count = line_count + 1
139 if __name__ ==
'__main__':
140 os.environ[
'GTEST_STACK_TRACE_DEPTH'] =
'1'