32 """Tests the text output of Google C++ Mocking Framework.
35 gmock_output_test.py --build_dir=BUILD/DIR --gengolden
36 # where BUILD/DIR contains the built gmock_output_test_ file.
37 gmock_output_test.py --gengolden
41 __author__ =
'wan@google.com (Zhanyong Wan)'
47 import gmock_test_utils
51 GENGOLDEN_FLAG =
'--gengolden'
54 COMMAND = [PROGRAM_PATH,
'--gtest_stack_trace_depth=0',
'--gtest_print_time=0']
55 GOLDEN_NAME =
'gmock_output_test_golden.txt'
60 """Changes all Windows/Mac line endings in s to UNIX line endings."""
62 return s.replace(
'\r\n',
'\n').replace(
'\r',
'\n')
66 """Removes Google Test result report's header and footer from the output."""
68 output = re.sub(
r'.*gtest_main.*\n',
'', output)
69 output = re.sub(
r'\[.*\d+ tests.*\n',
'', output)
70 output = re.sub(
r'\[.* test environment .*\n',
'', output)
71 output = re.sub(
r'\[=+\] \d+ tests .* ran.*',
'', output)
72 output = re.sub(
r'.* FAILED TESTS\n',
'', output)
77 """Removes all file location info from a Google Test program's output.
80 output: the output of a Google Test program.
83 output with all file location info (in the form of
84 'DIRECTORY/FILE_NAME:LINE_NUMBER: 'or
85 'DIRECTORY\\FILE_NAME(LINE_NUMBER): ') replaced by
89 return re.sub(
r'.*[/\\](.+)(\:\d+|\(\d+\))\:',
'FILE:#:', output)
93 """Normalizes the error marker, which is different on Windows vs on Linux."""
95 return re.sub(
r' error: ',
' Failure\n', output)
99 """Removes memory addresses from the test output."""
101 return re.sub(
r'@\w+',
'@0x#', output)
105 """Removes the test names of leaked mock objects from the test output."""
107 return re.sub(
r'\(used in test .+\) ',
'', output)
111 """Returns a list of test names that leak mock objects."""
116 return re.findall(
r'\(used in test (.+)\)', output)
120 """Normalizes the output of gmock_output_test_.
123 output: The test output.
126 A tuple (the normalized test output, the list of test names that have
139 """Runs a command in a sub-process, and returns its STDOUT in a string."""
145 """Runs a command and returns its normalized output and a list of leaky tests.
148 cmd: the shell command.
152 os.environ[
'GTEST_CATCH_EXCEPTIONS'] =
'1'
159 golden_file =
open(GOLDEN_PATH,
'rb')
160 golden = golden_file.read()
164 self.assertEquals(golden, output)
168 self.assertEquals([
'GMockOutputTest.CatchesLeakedMocks',
169 'GMockOutputTest.CatchesLeakedMocks'],
173 if __name__ ==
'__main__':
174 if sys.argv[1:] == [GENGOLDEN_FLAG]:
176 golden_file =
open(GOLDEN_PATH,
'wb')
177 golden_file.write(output)