32r"""Tests the text output of Google C++ Mocking Framework.
34To update the golden file:
35gmock_output_test.py --build_dir=BUILD/DIR --gengolden
36where BUILD/DIR contains the built gmock_output_test_ file.
37gmock_output_test.py --gengolden
46import gmock_test_utils
50GENGOLDEN_FLAG =
'--gengolden'
53COMMAND = [PROGRAM_PATH,
'--gtest_stack_trace_depth=0',
'--gtest_print_time=0']
54GOLDEN_NAME =
'gmock_output_test_golden.txt'
59 """Changes all Windows/Mac line endings in s to UNIX line endings."""
61 return s.replace(
'\r\n',
'\n').replace(
'\r',
'\n')
65 """Removes Google Test result report's header and footer from the output."""
67 output = re.sub(
r'.*gtest_main.*\n',
'', output)
68 output = re.sub(
r'\[.*\d+ tests.*\n',
'', output)
69 output = re.sub(
r'\[.* test environment .*\n',
'', output)
70 output = re.sub(
r'\[=+\] \d+ tests .* ran.*',
'', output)
71 output = re.sub(
r'.* FAILED TESTS\n',
'', output)
76 """Removes all file location info from a Google Test program's output.
79 output: the output of a Google Test program.
82 output with all file location info (
in the form of
83 'DIRECTORY/FILE_NAME:LINE_NUMBER: 'or
84 'DIRECTORY\\FILE_NAME(LINE_NUMBER): ') replaced by
88 return re.sub(
r'.*[/\\](.+)(\:\d+|\(\d+\))\:',
'FILE:#:', output)
92 """Normalizes the error marker, which is different on Windows vs on Linux."""
94 return re.sub(
r' error: ',
' Failure\n', output)
98 """Removes memory addresses from the test output."""
100 return re.sub(
r'@\w+',
'@0x#', output)
104 """Removes the test names of leaked mock objects from the test output."""
106 return re.sub(
r'\(used in test .+\) ',
'', output)
110 """Returns a list of test names that leak mock objects."""
115 return re.findall(
r'\(used in test (.+)\)', output)
119 """Normalizes the output of gmock_output_test_.
122 output: The test output.
125 A tuple (the normalized test output, the list of test names that have
138 """Runs a command in a sub-process, and returns its STDOUT in a string."""
144 """Runs a command and returns its normalized output and a list of leaky tests.
147 cmd: the shell command.
151 os.environ[
'GTEST_CATCH_EXCEPTIONS'] =
'1'
159 golden_file = open(GOLDEN_PATH,
'rb')
160 golden = golden_file.read().decode(
'utf-8')
164 self.assertEquals(golden, output)
168 self.assertEquals([
'GMockOutputTest.CatchesLeakedMocks',
169 'GMockOutputTest.CatchesLeakedMocks'],
173if __name__ ==
'__main__':
174 if sys.argv[1:] == [GENGOLDEN_FLAG]:
176 golden_file = open(GOLDEN_PATH,
'wb')
177 golden_file.write(output)
def GetShellCommandOutput(cmd)
def GetNormalizedCommandOutputAndLeakyTests(cmd)
def RemoveReportHeaderAndFooter(output)
def RemoveMemoryAddresses(output)
def GetNormalizedOutputAndLeakyTests(output)
def GetLeakyTests(output)
def RemoveLocations(output)
def RemoveTestNamesOfLeakedMocks(output)
def NormalizeErrorMarker(output)
def GetTestExecutablePath(executable_name)