tesseract v5.3.3.20231005
googletest-output-test Namespace Reference

Classes

class  GTestOutputTest
 

Functions

def ToUnixLineEnding (s)
 
def RemoveLocations (test_output)
 
def RemoveStackTraceDetails (output)
 
def RemoveStackTraces (output)
 
def RemoveTime (output)
 
def RemoveTypeInfoDetails (test_output)
 
def NormalizeToCurrentPlatform (test_output)
 
def RemoveTestCounts (output)
 
def RemoveMatchingTests (test_output, pattern)
 
def NormalizeOutput (output)
 
def GetShellCommandOutput (env_cmd)
 
def GetCommandOutput (env_cmd)
 
def GetOutputOfAllCommands ()
 

Variables

string GENGOLDEN_FLAG = '--gengolden'
 
string CATCH_EXCEPTIONS_ENV_VAR_NAME = 'GTEST_CATCH_EXCEPTIONS'
 
string NO_STACKTRACE_SUPPORT_FLAG = '--no_stacktrace_support'
 
string IS_LINUX = 'Linux'
 
string IS_WINDOWS = 'nt'
 
string GOLDEN_NAME = 'googletest-output-test-golden-lin.txt'
 
 PROGRAM_PATH = gtest_test_utils.GetTestExecutablePath('googletest-output-test_')
 
tuple COMMAND_LIST_TESTS = ({}, [PROGRAM_PATH, '--gtest_list_tests'])
 
tuple COMMAND_WITH_COLOR = ({}, [PROGRAM_PATH, '--gtest_color=yes'])
 
tuple COMMAND_WITH_TIME
 
tuple COMMAND_WITH_DISABLED
 
tuple COMMAND_WITH_SHARDING
 
 GOLDEN_PATH = os.path.join(gtest_test_utils.GetSourceDir(), GOLDEN_NAME)
 
def test_list = GetShellCommandOutput(COMMAND_LIST_TESTS)
 
string SUPPORTS_DEATH_TESTS = 'DeathTest' in test_list
 
string SUPPORTS_TYPED_TESTS = 'TypedTest' in test_list
 
string SUPPORTS_THREADS = 'ExpectFailureWithThreadsTest' in test_list
 
string SUPPORTS_STACK_TRACES = NO_STACKTRACE_SUPPORT_FLAG not in sys.argv
 
tuple CAN_GENERATE_GOLDEN_FILE
 
def output = GetOutputOfAllCommands()
 
 golden_file = open(GOLDEN_PATH, 'wb')
 
tuple message
 

Function Documentation

◆ GetCommandOutput()

def googletest-output-test.GetCommandOutput (   env_cmd)
Runs a command and returns its output with all file location
info stripped off.

Args:
  env_cmd:  The shell command. A 2-tuple where element 0 is a dict of extra
            environment variables to set, and element 1 is a string with
            the command and any flags.

Definition at line 224 of file googletest-output-test.py.

224def GetCommandOutput(env_cmd):
225 """Runs a command and returns its output with all file location
226 info stripped off.
227
228 Args:
229 env_cmd: The shell command. A 2-tuple where element 0 is a dict of extra
230 environment variables to set, and element 1 is a string with
231 the command and any flags.
232 """
233
234 # Disables exception pop-ups on Windows.
235 environ, cmdline = env_cmd
236 environ = dict(environ) # Ensures we are modifying a copy.
237 environ[CATCH_EXCEPTIONS_ENV_VAR_NAME] = '1'
238 return NormalizeOutput(GetShellCommandOutput((environ, cmdline)))
239
240

◆ GetOutputOfAllCommands()

def googletest-output-test.GetOutputOfAllCommands ( )
Returns concatenated output from several representative commands.

Definition at line 241 of file googletest-output-test.py.

242 """Returns concatenated output from several representative commands."""
243
244 return (GetCommandOutput(COMMAND_WITH_COLOR) +
245 GetCommandOutput(COMMAND_WITH_TIME) +
246 GetCommandOutput(COMMAND_WITH_DISABLED) +
247 GetCommandOutput(COMMAND_WITH_SHARDING))
248
249

◆ GetShellCommandOutput()

def googletest-output-test.GetShellCommandOutput (   env_cmd)
Runs a command in a sub-process, and returns its output in a string.

Args:
  env_cmd: The shell command. A 2-tuple where element 0 is a dict of extra
           environment variables to set, and element 1 is a string with
           the command and any flags.

Returns:
  A string with the command's combined standard and diagnostic output.

Definition at line 203 of file googletest-output-test.py.

203def GetShellCommandOutput(env_cmd):
204 """Runs a command in a sub-process, and returns its output in a string.
205
206 Args:
207 env_cmd: The shell command. A 2-tuple where element 0 is a dict of extra
208 environment variables to set, and element 1 is a string with
209 the command and any flags.
210
211 Returns:
212 A string with the command's combined standard and diagnostic output.
213 """
214
215 # Spawns cmd in a sub-process, and gets its standard I/O file objects.
216 # Set and save the environment properly.
217 environ = os.environ.copy()
218 environ.update(env_cmd[0])
219 p = gtest_test_utils.Subprocess(env_cmd[1], env=environ)
220
221 return p.output
222
223

◆ NormalizeOutput()

def googletest-output-test.NormalizeOutput (   output)
Normalizes output (the output of googletest-output-test_.exe).

Definition at line 193 of file googletest-output-test.py.

193def NormalizeOutput(output):
194 """Normalizes output (the output of googletest-output-test_.exe)."""
195
196 output = ToUnixLineEnding(output)
197 output = RemoveLocations(output)
198 output = RemoveStackTraceDetails(output)
199 output = RemoveTime(output)
200 return output
201
202
def RemoveLocations(test_output)

◆ NormalizeToCurrentPlatform()

def googletest-output-test.NormalizeToCurrentPlatform (   test_output)
Normalizes platform specific output details for easier comparison.

Definition at line 142 of file googletest-output-test.py.

142def NormalizeToCurrentPlatform(test_output):
143 """Normalizes platform specific output details for easier comparison."""
144
145 if IS_WINDOWS:
146 # Removes the color information that is not present on Windows.
147 test_output = re.sub('\x1b\\[(0;3\d)?m', '', test_output)
148 # Changes failure message headers into the Windows format.
149 test_output = re.sub(r': Failure\n', r': error: ', test_output)
150 # Changes file(line_number) to file:line_number.
151 test_output = re.sub(r'((\w|\.)+)\‍((\d+)\‍):', r'\1:\3:', test_output)
152
153 return test_output
154
155
def NormalizeToCurrentPlatform(test_output)

◆ RemoveLocations()

def googletest-output-test.RemoveLocations (   test_output)
Removes all file location info from a Google Test program's output.

Args:
     test_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_NAME:#: '.

Definition at line 90 of file googletest-output-test.py.

90def RemoveLocations(test_output):
91 """Removes all file location info from a Google Test program's output.
92
93 Args:
94 test_output: the output of a Google Test program.
95
96 Returns:
97 output with all file location info (in the form of
98 'DIRECTORY/FILE_NAME:LINE_NUMBER: 'or
99 'DIRECTORY\\FILE_NAME(LINE_NUMBER): ') replaced by
100 'FILE_NAME:#: '.
101 """
102
103 return re.sub(r'.*[/\\]((googletest-output-test_|gtest).cc)(\:\d+|\‍(\d+\‍))\: ',
104 r'\1:#: ', test_output)
105
106

◆ RemoveMatchingTests()

def googletest-output-test.RemoveMatchingTests (   test_output,
  pattern 
)
Removes output of specified tests from a Google Test program's output.

This function strips not only the beginning and the end of a test but also
all output in between.

Args:
  test_output:       A string containing the test output.
  pattern:           A regex string that matches names of test cases or
                     tests to remove.

Returns:
  Contents of test_output with tests whose names match pattern removed.

Definition at line 170 of file googletest-output-test.py.

170def RemoveMatchingTests(test_output, pattern):
171 """Removes output of specified tests from a Google Test program's output.
172
173 This function strips not only the beginning and the end of a test but also
174 all output in between.
175
176 Args:
177 test_output: A string containing the test output.
178 pattern: A regex string that matches names of test cases or
179 tests to remove.
180
181 Returns:
182 Contents of test_output with tests whose names match pattern removed.
183 """
184
185 test_output = re.sub(
186 r'.*\[ RUN \] .*%s(.|\n)*?\[( FAILED | OK )\] .*%s.*\n' % (
187 pattern, pattern),
188 '',
189 test_output)
190 return re.sub(r'.*%s.*\n' % pattern, '', test_output)
191
192
def RemoveMatchingTests(test_output, pattern)

◆ RemoveStackTraceDetails()

def googletest-output-test.RemoveStackTraceDetails (   output)
Removes all stack traces from a Google Test program's output.

Definition at line 107 of file googletest-output-test.py.

107def RemoveStackTraceDetails(output):
108 """Removes all stack traces from a Google Test program's output."""
109
110 # *? means "find the shortest string that matches".
111 return re.sub(r'Stack trace:(.|\n)*?\n\n',
112 'Stack trace: (omitted)\n\n', output)
113
114

◆ RemoveStackTraces()

def googletest-output-test.RemoveStackTraces (   output)
Removes all traces of stack traces from a Google Test program's output.

Definition at line 115 of file googletest-output-test.py.

115def RemoveStackTraces(output):
116 """Removes all traces of stack traces from a Google Test program's output."""
117
118 # *? means "find the shortest string that matches".
119 return re.sub(r'Stack trace:(.|\n)*?\n\n', '', output)
120
121

◆ RemoveTestCounts()

def googletest-output-test.RemoveTestCounts (   output)
Removes test counts from a Google Test program's output.

Definition at line 156 of file googletest-output-test.py.

156def RemoveTestCounts(output):
157 """Removes test counts from a Google Test program's output."""
158
159 output = re.sub(r'\d+ tests?, listed below',
160 '? tests, listed below', output)
161 output = re.sub(r'\d+ FAILED TESTS',
162 '? FAILED TESTS', output)
163 output = re.sub(r'\d+ tests? from \d+ test cases?',
164 '? tests from ? test cases', output)
165 output = re.sub(r'\d+ tests? from ([a-zA-Z_])',
166 r'? tests from \1', output)
167 return re.sub(r'\d+ tests?\.', '? tests.', output)
168
169

◆ RemoveTime()

def googletest-output-test.RemoveTime (   output)
Removes all time information from a Google Test program's output.

Definition at line 122 of file googletest-output-test.py.

122def RemoveTime(output):
123 """Removes all time information from a Google Test program's output."""
124
125 return re.sub(r'\‍(\d+ ms', '(? ms', output)
126
127

◆ RemoveTypeInfoDetails()

def googletest-output-test.RemoveTypeInfoDetails (   test_output)
Removes compiler-specific type info from Google Test program's output.

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

Returns:
     output with type information normalized to canonical form.

Definition at line 128 of file googletest-output-test.py.

128def RemoveTypeInfoDetails(test_output):
129 """Removes compiler-specific type info from Google Test program's output.
130
131 Args:
132 test_output: the output of a Google Test program.
133
134 Returns:
135 output with type information normalized to canonical form.
136 """
137
138 # some compilers output the name of type 'unsigned int' as 'unsigned'
139 return re.sub(r'unsigned int', 'unsigned', test_output)
140
141
def RemoveTypeInfoDetails(test_output)

◆ ToUnixLineEnding()

def googletest-output-test.ToUnixLineEnding (   s)
Changes all Windows/Mac line endings in s to UNIX line endings.

Definition at line 84 of file googletest-output-test.py.

84def ToUnixLineEnding(s):
85 """Changes all Windows/Mac line endings in s to UNIX line endings."""
86
87 return s.replace('\r\n', '\n').replace('\r', '\n')
88
89

Variable Documentation

◆ CAN_GENERATE_GOLDEN_FILE

tuple googletest-output-test.CAN_GENERATE_GOLDEN_FILE
Initial value:
1= (SUPPORTS_DEATH_TESTS and
2 SUPPORTS_TYPED_TESTS and
3 SUPPORTS_THREADS and
4 SUPPORTS_STACK_TRACES)

Definition at line 256 of file googletest-output-test.py.

◆ CATCH_EXCEPTIONS_ENV_VAR_NAME

string googletest-output-test.CATCH_EXCEPTIONS_ENV_VAR_NAME = 'GTEST_CATCH_EXCEPTIONS'

Definition at line 50 of file googletest-output-test.py.

◆ COMMAND_LIST_TESTS

tuple googletest-output-test.COMMAND_LIST_TESTS = ({}, [PROGRAM_PATH, '--gtest_list_tests'])

Definition at line 64 of file googletest-output-test.py.

◆ COMMAND_WITH_COLOR

tuple googletest-output-test.COMMAND_WITH_COLOR = ({}, [PROGRAM_PATH, '--gtest_color=yes'])

Definition at line 65 of file googletest-output-test.py.

◆ COMMAND_WITH_DISABLED

tuple googletest-output-test.COMMAND_WITH_DISABLED
Initial value:
1= (
2 {}, [PROGRAM_PATH,
3 '--gtest_also_run_disabled_tests',
4 'internal_skip_environment_and_ad_hoc_tests',
5 '--gtest_filter=*DISABLED_*'])

Definition at line 70 of file googletest-output-test.py.

◆ COMMAND_WITH_SHARDING

tuple googletest-output-test.COMMAND_WITH_SHARDING
Initial value:
1= (
2 {'GTEST_SHARD_INDEX': '1', 'GTEST_TOTAL_SHARDS': '2'},
3 [PROGRAM_PATH,
4 'internal_skip_environment_and_ad_hoc_tests',
5 '--gtest_filter=PassingTest.*'])

Definition at line 75 of file googletest-output-test.py.

◆ COMMAND_WITH_TIME

tuple googletest-output-test.COMMAND_WITH_TIME
Initial value:
1= ({}, [PROGRAM_PATH,
2 '--gtest_print_time',
3 'internal_skip_environment_and_ad_hoc_tests',
4 '--gtest_filter=FatalFailureTest.*:LoggingTest.*'])

Definition at line 66 of file googletest-output-test.py.

◆ GENGOLDEN_FLAG

string googletest-output-test.GENGOLDEN_FLAG = '--gengolden'

Definition at line 49 of file googletest-output-test.py.

◆ golden_file

googletest-output-test.golden_file = open(GOLDEN_PATH, 'wb')

Definition at line 333 of file googletest-output-test.py.

◆ GOLDEN_NAME

string googletest-output-test.GOLDEN_NAME = 'googletest-output-test-golden-lin.txt'

Definition at line 58 of file googletest-output-test.py.

◆ GOLDEN_PATH

googletest-output-test.GOLDEN_PATH = os.path.join(gtest_test_utils.GetSourceDir(), GOLDEN_NAME)

Definition at line 81 of file googletest-output-test.py.

◆ IS_LINUX

string googletest-output-test.IS_LINUX = 'Linux'

Definition at line 55 of file googletest-output-test.py.

◆ IS_WINDOWS

string googletest-output-test.IS_WINDOWS = 'nt'

Definition at line 56 of file googletest-output-test.py.

◆ message

tuple googletest-output-test.message
Initial value:
1= (
2 )

Definition at line 337 of file googletest-output-test.py.

◆ NO_STACKTRACE_SUPPORT_FLAG

string googletest-output-test.NO_STACKTRACE_SUPPORT_FLAG = '--no_stacktrace_support'

Definition at line 53 of file googletest-output-test.py.

◆ output

def googletest-output-test.output = GetOutputOfAllCommands()

Definition at line 332 of file googletest-output-test.py.

◆ PROGRAM_PATH

googletest-output-test.PROGRAM_PATH = gtest_test_utils.GetTestExecutablePath('googletest-output-test_')

Definition at line 60 of file googletest-output-test.py.

◆ SUPPORTS_DEATH_TESTS

string googletest-output-test.SUPPORTS_DEATH_TESTS = 'DeathTest' in test_list

Definition at line 251 of file googletest-output-test.py.

◆ SUPPORTS_STACK_TRACES

string googletest-output-test.SUPPORTS_STACK_TRACES = NO_STACKTRACE_SUPPORT_FLAG not in sys.argv

Definition at line 254 of file googletest-output-test.py.

◆ SUPPORTS_THREADS

string googletest-output-test.SUPPORTS_THREADS = 'ExpectFailureWithThreadsTest' in test_list

Definition at line 253 of file googletest-output-test.py.

◆ SUPPORTS_TYPED_TESTS

string googletest-output-test.SUPPORTS_TYPED_TESTS = 'TypedTest' in test_list

Definition at line 252 of file googletest-output-test.py.

◆ test_list

def googletest-output-test.test_list = GetShellCommandOutput(COMMAND_LIST_TESTS)

Definition at line 250 of file googletest-output-test.py.