proxygen
gtest_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 __author__ = 'wan@google.com (Zhanyong Wan)'
 
string GENGOLDEN_FLAG = '--gengolden'
 
string CATCH_EXCEPTIONS_ENV_VAR_NAME = 'GTEST_CATCH_EXCEPTIONS'
 
string IS_WINDOWS = 'nt'
 
string GOLDEN_NAME = 'gtest_output_test_golden_lin.txt'
 
 PROGRAM_PATH = gtest_test_utils.GetTestExecutablePath('gtest_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)
 
 test_list = GetShellCommandOutput(COMMAND_LIST_TESTS)
 
string SUPPORTS_DEATH_TESTS = 'DeathTest'
 
string SUPPORTS_TYPED_TESTS = 'TypedTest'
 
string SUPPORTS_THREADS = 'ExpectFailureWithThreadsTest'
 
bool SUPPORTS_STACK_TRACES = False
 
tuple CAN_GENERATE_GOLDEN_FILE
 
 output = GetOutputOfAllCommands()
 
 golden_file = open(GOLDEN_PATH, 'wb')
 
tuple message
 

Function Documentation

def gtest_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 222 of file gtest_output_test.py.

References GetShellCommandOutput(), and NormalizeOutput().

Referenced by GetOutputOfAllCommands().

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

Definition at line 239 of file gtest_output_test.py.

References GetCommandOutput().

Referenced by gtest_output_test.GTestOutputTest.testOutput().

240  """Returns concatenated output from several representative commands."""
241 
242  return (GetCommandOutput(COMMAND_WITH_COLOR) +
243  GetCommandOutput(COMMAND_WITH_TIME) +
244  GetCommandOutput(COMMAND_WITH_DISABLED) +
245  GetCommandOutput(COMMAND_WITH_SHARDING))
246 
247 
def GetCommandOutput(env_cmd)
def gtest_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 201 of file gtest_output_test.py.

Referenced by GetCommandOutput().

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

Definition at line 191 of file gtest_output_test.py.

References RemoveLocations(), RemoveStackTraceDetails(), RemoveTime(), and ToUnixLineEnding().

Referenced by GetCommandOutput().

191 def NormalizeOutput(output):
192  """Normalizes output (the output of gtest_output_test_.exe)."""
193 
194  output = ToUnixLineEnding(output)
195  output = RemoveLocations(output)
196  output = RemoveStackTraceDetails(output)
197  output = RemoveTime(output)
198  return output
199 
200 
def RemoveStackTraceDetails(output)
def RemoveLocations(test_output)
def NormalizeOutput(output)
def gtest_output_test.NormalizeToCurrentPlatform (   test_output)
Normalizes platform specific output details for easier comparison.

Definition at line 140 of file gtest_output_test.py.

Referenced by gtest_output_test.GTestOutputTest.testOutput().

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

Referenced by NormalizeOutput().

89 def RemoveLocations(test_output):
90  """Removes all file location info from a Google Test program's output.
91 
92  Args:
93  test_output: the output of a Google Test program.
94 
95  Returns:
96  output with all file location info (in the form of
97  'DIRECTORY/FILE_NAME:LINE_NUMBER: 'or
98  'DIRECTORY\\FILE_NAME(LINE_NUMBER): ') replaced by
99  'FILE_NAME:#: '.
100  """
101 
102  return re.sub(r'.*[/\\](.+)(\:\d+|\(\d+\))\: ', r'\1:#: ', test_output)
103 
104 
def RemoveLocations(test_output)
def gtest_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 168 of file gtest_output_test.py.

Referenced by gtest_output_test.GTestOutputTest.RemoveUnsupportedTests().

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

Definition at line 105 of file gtest_output_test.py.

Referenced by NormalizeOutput().

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

Definition at line 113 of file gtest_output_test.py.

Referenced by gtest_output_test.GTestOutputTest.RemoveUnsupportedTests().

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

Definition at line 154 of file gtest_output_test.py.

Referenced by gtest_output_test.GTestOutputTest.testOutput().

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

Definition at line 120 of file gtest_output_test.py.

Referenced by NormalizeOutput().

120 def RemoveTime(output):
121  """Removes all time information from a Google Test program's output."""
122 
123  return re.sub(r'\(\d+ ms', '(? ms', output)
124 
125 
def gtest_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 126 of file gtest_output_test.py.

Referenced by gtest_output_test.GTestOutputTest.testOutput().

126 def RemoveTypeInfoDetails(test_output):
127  """Removes compiler-specific type info from Google Test program's output.
128 
129  Args:
130  test_output: the output of a Google Test program.
131 
132  Returns:
133  output with type information normalized to canonical form.
134  """
135 
136  # some compilers output the name of type 'unsigned int' as 'unsigned'
137  return re.sub(r'unsigned int', 'unsigned', test_output)
138 
139 
def RemoveTypeInfoDetails(test_output)
def gtest_output_test.ToUnixLineEnding (   s)
Changes all Windows/Mac line endings in s to UNIX line endings.

Definition at line 83 of file gtest_output_test.py.

References replace().

Referenced by NormalizeOutput(), and gtest_output_test.GTestOutputTest.testOutput().

84  """Changes all Windows/Mac line endings in s to UNIX line endings."""
85 
86  return s.replace('\r\n', '\n').replace('\r', '\n')
87 
88 
void BENCHFUN() replace(size_t iters, size_t arg)

Variable Documentation

string gtest_output_test.__author__ = 'wan@google.com (Zhanyong Wan)'
private

Definition at line 41 of file gtest_output_test.py.

tuple gtest_output_test.CAN_GENERATE_GOLDEN_FILE
Initial value:
1 = (SUPPORTS_DEATH_TESTS and
2  SUPPORTS_TYPED_TESTS and
3  SUPPORTS_THREADS and
4  not IS_WINDOWS)

Definition at line 254 of file gtest_output_test.py.

string gtest_output_test.CATCH_EXCEPTIONS_ENV_VAR_NAME = 'GTEST_CATCH_EXCEPTIONS'

Definition at line 52 of file gtest_output_test.py.

tuple gtest_output_test.COMMAND_LIST_TESTS = ({}, [PROGRAM_PATH, '--gtest_list_tests'])

Definition at line 63 of file gtest_output_test.py.

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

Definition at line 64 of file gtest_output_test.py.

tuple gtest_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 69 of file gtest_output_test.py.

tuple gtest_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 74 of file gtest_output_test.py.

tuple gtest_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 65 of file gtest_output_test.py.

string gtest_output_test.GENGOLDEN_FLAG = '--gengolden'

Definition at line 51 of file gtest_output_test.py.

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

Definition at line 327 of file gtest_output_test.py.

string gtest_output_test.GOLDEN_NAME = 'gtest_output_test_golden_lin.txt'

Definition at line 57 of file gtest_output_test.py.

gtest_output_test.GOLDEN_PATH = os.path.join(gtest_test_utils.GetSourceDir(), GOLDEN_NAME)

Definition at line 80 of file gtest_output_test.py.

string gtest_output_test.IS_WINDOWS = 'nt'

Definition at line 54 of file gtest_output_test.py.

tuple gtest_output_test.message
Initial value:
1 = (
2  )

Definition at line 331 of file gtest_output_test.py.

gtest_output_test.output = GetOutputOfAllCommands()

Definition at line 326 of file gtest_output_test.py.

gtest_output_test.PROGRAM_PATH = gtest_test_utils.GetTestExecutablePath('gtest_output_test_')

Definition at line 59 of file gtest_output_test.py.

string gtest_output_test.SUPPORTS_DEATH_TESTS = 'DeathTest'

Definition at line 249 of file gtest_output_test.py.

bool gtest_output_test.SUPPORTS_STACK_TRACES = False

Definition at line 252 of file gtest_output_test.py.

string gtest_output_test.SUPPORTS_THREADS = 'ExpectFailureWithThreadsTest'

Definition at line 251 of file gtest_output_test.py.

string gtest_output_test.SUPPORTS_TYPED_TESTS = 'TypedTest'

Definition at line 250 of file gtest_output_test.py.

gtest_output_test.test_list = GetShellCommandOutput(COMMAND_LIST_TESTS)

Definition at line 248 of file gtest_output_test.py.