tesseract v5.3.3.20231005
gmock_output_test Namespace Reference

Classes

class  GMockOutputTest
 

Functions

def ToUnixLineEnding (s)
 
def RemoveReportHeaderAndFooter (output)
 
def RemoveLocations (output)
 
def NormalizeErrorMarker (output)
 
def RemoveMemoryAddresses (output)
 
def RemoveTestNamesOfLeakedMocks (output)
 
def GetLeakyTests (output)
 
def GetNormalizedOutputAndLeakyTests (output)
 
def GetShellCommandOutput (cmd)
 
def GetNormalizedCommandOutputAndLeakyTests (cmd)
 

Variables

string GENGOLDEN_FLAG = '--gengolden'
 
 PROGRAM_PATH = gmock_test_utils.GetTestExecutablePath('gmock_output_test_')
 
list COMMAND = [PROGRAM_PATH, '--gtest_stack_trace_depth=0', '--gtest_print_time=0']
 
string GOLDEN_NAME = 'gmock_output_test_golden.txt'
 
 GOLDEN_PATH = os.path.join(gmock_test_utils.GetSourceDir(), GOLDEN_NAME)
 
 output
 
 golden_file = open(GOLDEN_PATH, 'wb')
 

Function Documentation

◆ GetLeakyTests()

def gmock_output_test.GetLeakyTests (   output)
Returns a list of test names that leak mock objects.

Definition at line 109 of file gmock_output_test.py.

109def GetLeakyTests(output):
110 """Returns a list of test names that leak mock objects."""
111
112 # findall() returns a list of all matches of the regex in output.
113 # For example, if '(used in test FooTest.Bar)' is in output, the
114 # list will contain 'FooTest.Bar'.
115 return re.findall(r'\‍(used in test (.+)\‍)', output)
116
117
def GetLeakyTests(output)

◆ GetNormalizedCommandOutputAndLeakyTests()

def gmock_output_test.GetNormalizedCommandOutputAndLeakyTests (   cmd)
Runs a command and returns its normalized output and a list of leaky tests.

Args:
  cmd:  the shell command.

Definition at line 143 of file gmock_output_test.py.

144 """Runs a command and returns its normalized output and a list of leaky tests.
145
146 Args:
147 cmd: the shell command.
148 """
149
150 # Disables exception pop-ups on Windows.
151 os.environ['GTEST_CATCH_EXCEPTIONS'] = '1'
153
154
def GetShellCommandOutput(cmd)
def GetNormalizedCommandOutputAndLeakyTests(cmd)
def GetNormalizedOutputAndLeakyTests(output)

◆ GetNormalizedOutputAndLeakyTests()

def gmock_output_test.GetNormalizedOutputAndLeakyTests (   output)
Normalizes the output of gmock_output_test_.

Args:
  output: The test output.

Returns:
  A tuple (the normalized test output, the list of test names that have
  leaked mocks).

Definition at line 118 of file gmock_output_test.py.

119 """Normalizes the output of gmock_output_test_.
120
121 Args:
122 output: The test output.
123
124 Returns:
125 A tuple (the normalized test output, the list of test names that have
126 leaked mocks).
127 """
128
129 output = ToUnixLineEnding(output)
130 output = RemoveReportHeaderAndFooter(output)
131 output = NormalizeErrorMarker(output)
132 output = RemoveLocations(output)
133 output = RemoveMemoryAddresses(output)
134 return (RemoveTestNamesOfLeakedMocks(output), GetLeakyTests(output))
135
136
def RemoveReportHeaderAndFooter(output)
def RemoveMemoryAddresses(output)
def RemoveLocations(output)
def RemoveTestNamesOfLeakedMocks(output)
def NormalizeErrorMarker(output)

◆ GetShellCommandOutput()

def gmock_output_test.GetShellCommandOutput (   cmd)
Runs a command in a sub-process, and returns its STDOUT in a string.

Definition at line 137 of file gmock_output_test.py.

137def GetShellCommandOutput(cmd):
138 """Runs a command in a sub-process, and returns its STDOUT in a string."""
139
140 return gmock_test_utils.Subprocess(cmd, capture_stderr=False).output
141
142

◆ NormalizeErrorMarker()

def gmock_output_test.NormalizeErrorMarker (   output)
Normalizes the error marker, which is different on Windows vs on Linux.

Definition at line 91 of file gmock_output_test.py.

91def NormalizeErrorMarker(output):
92 """Normalizes the error marker, which is different on Windows vs on Linux."""
93
94 return re.sub(r' error: ', ' Failure\n', output)
95
96

◆ RemoveLocations()

def gmock_output_test.RemoveLocations (   output)
Removes all file location info from a Google Test program's output.

Args:
     output:  the output of a Google Test program.

Returns:
     output with all file location info (in the form of
     'DIRECTORY/FILE_NAME:LINE_NUMBER: 'or
     'DIRECTORY\\FILE_NAME(LINE_NUMBER): ') replaced by
     'FILE:#: '.

Definition at line 75 of file gmock_output_test.py.

75def RemoveLocations(output):
76 """Removes all file location info from a Google Test program's output.
77
78 Args:
79 output: the output of a Google Test program.
80
81 Returns:
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
85 'FILE:#: '.
86 """
87
88 return re.sub(r'.*[/\\](.+)(\:\d+|\‍(\d+\‍))\:', 'FILE:#:', output)
89
90

◆ RemoveMemoryAddresses()

def gmock_output_test.RemoveMemoryAddresses (   output)
Removes memory addresses from the test output.

Definition at line 97 of file gmock_output_test.py.

97def RemoveMemoryAddresses(output):
98 """Removes memory addresses from the test output."""
99
100 return re.sub(r'@\w+', '@0x#', output)
101
102

◆ RemoveReportHeaderAndFooter()

def gmock_output_test.RemoveReportHeaderAndFooter (   output)
Removes Google Test result report's header and footer from the output.

Definition at line 64 of file gmock_output_test.py.

65 """Removes Google Test result report's header and footer from the output."""
66
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)
72 return output
73
74

◆ RemoveTestNamesOfLeakedMocks()

def gmock_output_test.RemoveTestNamesOfLeakedMocks (   output)
Removes the test names of leaked mock objects from the test output.

Definition at line 103 of file gmock_output_test.py.

104 """Removes the test names of leaked mock objects from the test output."""
105
106 return re.sub(r'\‍(used in test .+\‍) ', '', output)
107
108

◆ ToUnixLineEnding()

def gmock_output_test.ToUnixLineEnding (   s)
Changes all Windows/Mac line endings in s to UNIX line endings.

Definition at line 58 of file gmock_output_test.py.

58def ToUnixLineEnding(s):
59 """Changes all Windows/Mac line endings in s to UNIX line endings."""
60
61 return s.replace('\r\n', '\n').replace('\r', '\n')
62
63

Variable Documentation

◆ COMMAND

list gmock_output_test.COMMAND = [PROGRAM_PATH, '--gtest_stack_trace_depth=0', '--gtest_print_time=0']

Definition at line 53 of file gmock_output_test.py.

◆ GENGOLDEN_FLAG

string gmock_output_test.GENGOLDEN_FLAG = '--gengolden'

Definition at line 50 of file gmock_output_test.py.

◆ golden_file

gmock_output_test.golden_file = open(GOLDEN_PATH, 'wb')

Definition at line 176 of file gmock_output_test.py.

◆ GOLDEN_NAME

string gmock_output_test.GOLDEN_NAME = 'gmock_output_test_golden.txt'

Definition at line 54 of file gmock_output_test.py.

◆ GOLDEN_PATH

gmock_output_test.GOLDEN_PATH = os.path.join(gmock_test_utils.GetSourceDir(), GOLDEN_NAME)

Definition at line 55 of file gmock_output_test.py.

◆ output

gmock_output_test.output

Definition at line 175 of file gmock_output_test.py.

◆ PROGRAM_PATH

gmock_output_test.PROGRAM_PATH = gmock_test_utils.GetTestExecutablePath('gmock_output_test_')

Definition at line 52 of file gmock_output_test.py.