mirror of
https://github.com/catchorg/Catch2.git
synced 2025-08-01 12:55:40 +02:00
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:

committed by
Martin Hořeňovský

parent
ab98afe68b
commit
1faccd601d
@@ -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)
|
||||
|
Reference in New Issue
Block a user