Improved path normalization in approvalTests.py

Instead of redoing the whole line where path was found, only the
directory part of the path is removed, instead of removing all
of the line before the path starts.

This results in slight change in how junit and sonarqube approvals
come out, and significant change in how TeamCity reporter approvals
come out. This latter difference is the reason for the change,
as now the lines with `testFailed` and `testIgnored` messages
are not completely butchered.
This commit is contained in:
Martin Hořeňovský 2022-12-31 21:17:54 +01:00
parent 72b60dfd28
commit ac93f19437
No known key found for this signature in database
GPG key ID: DE48307B8B0D381A
7 changed files with 940 additions and 943 deletions

View file

@ -48,11 +48,11 @@ def get_unapprovedResultsPath(baseName):
langFilenameParser = re.compile(r'(.+\.[ch]pp)')
filelocParser = re.compile(r'''
.*/
(.+\.[ch]pp) # filename
(?::|\() # : is starting separator between filename and line number on Linux, ( on Windows
([0-9]*) # line number
\)? # Windows also has an ending separator, )
(?P<path_prefix>tests/SelfTest/(?:\w+/)*) # We separate prefix and fname, so that
(?P<filename>\w+\.tests\.[ch]pp) # we can keep only filename
(?::|\() # Linux has : as separator between fname and line number, Windows uses (
(\d*) # line number
\)? # Windows also uses an ending separator, )
''', re.VERBOSE)
lineNumberParser = re.compile(r' line="[0-9]*"')
hexParser = re.compile(r'\b(0[xX][0-9a-fA-F]+)\b')
@ -119,14 +119,11 @@ def filterLine(line, isCompact):
line = normalizeFilepath(line)
# strip source line numbers
m = filelocParser.match(line)
if m:
# note that this also strips directories, leaving only the filename
filename, lnum = m.groups()
lnum = ":<line number>" if lnum else ""
line = filename + lnum + line[m.end():]
else:
line = lineNumberParser.sub(" ", line)
# Note that this parser assumes an already normalized filepath from above,
# and might break terribly if it is moved around before the normalization.
line = filelocParser.sub('\g<filename>:<line number>', line)
line = lineNumberParser.sub(" ", line)
if isCompact:
line = line.replace(': FAILED', ': failed')