Improve path normalization for approvalTests.py

This fixes 3 problems:

* Relative paths on Windows are now supported
* Out-of-tree (paths starting with ../) builds are now supported
* Path separator normalization no longer affects non-path components of input (problem with Compact reporter)


Fixes #1379 
Fixes #1222 
Fixes #1200 
Fixes #1194
This commit is contained in:
MaciejPatro
2018-10-19 12:46:06 +02:00
committed by Martin Hořeňovský
parent ab98afe68b
commit 1faccd601d
2 changed files with 79 additions and 67 deletions

View File

@@ -18,7 +18,7 @@ if os.name == 'nt':
rootPath = os.path.join(catchPath, 'projects/SelfTest/Baselines')
langFilenameParser = re.compile(r'(.+\.[ch]pp)')
filelocParser = re.compile(r'''
.*/
(.+\.[ch]pp) # filename
@@ -91,12 +91,24 @@ def diffFiles(fileA, fileB):
return [line for line in diff if line[0] in ('+', '-')]
def filterLine(line, isCompact):
def normalizeFilepath(line):
if catchPath in line:
# make paths relative to Catch root
line = line.replace(catchPath + os.sep, '')
m = langFilenameParser.match(line)
if m:
filepath = m.group(0)
# go from \ in windows paths to /
line = line.replace('\\', '/')
filepath = filepath.replace('\\', '/')
# remove start of relative path
filepath = filepath.replace('../', '')
line = line[:m.start()] + filepath + line[m.end():]
return line
def filterLine(line, isCompact):
line = normalizeFilepath(line)
# strip source line numbers
m = filelocParser.match(line)