mirror of
https://github.com/catchorg/Catch2.git
synced 2024-11-25 23:06:10 +01:00
Approval tests now use Python std lib instead of call to diff
This needed to change to let it run on Windows as well as on the Unices
This commit is contained in:
parent
c4b5057094
commit
9acc6b9673
@ -1,9 +1,12 @@
|
||||
#!/usr/bin/env python
|
||||
|
||||
from __future__ import print_function
|
||||
|
||||
import os
|
||||
import sys
|
||||
import subprocess
|
||||
import re
|
||||
import difflib
|
||||
|
||||
import scriptCommon
|
||||
from scriptCommon import catchPath
|
||||
@ -26,6 +29,19 @@ else:
|
||||
|
||||
overallResult = 0
|
||||
|
||||
def diffFiles(fileA, fileB):
|
||||
with open(fileA, 'r') as file:
|
||||
aLines = file.readlines()
|
||||
with open(fileB, 'r') as file:
|
||||
bLines = file.readlines()
|
||||
|
||||
shortenedFilenameA = fileA.rsplit(os.sep, 1)[-1]
|
||||
shortenedFilenameB = fileB.rsplit(os.sep, 1)[-1]
|
||||
|
||||
diff = difflib.unified_diff(aLines, bLines, fromfile=shortenedFilenameA, tofile=shortenedFilenameB, n=0)
|
||||
return [line for line in diff if line[0] in ('+', '-')]
|
||||
|
||||
|
||||
def filterLine(line):
|
||||
# make paths relative to Catch root
|
||||
line = line.replace(catchPath + '/', '')
|
||||
@ -82,14 +98,15 @@ def approve(baseName, args):
|
||||
print()
|
||||
print(baseName + ":")
|
||||
if os.path.exists(baselinesPath):
|
||||
diffResult = subprocess.call(["diff", baselinesPath, filteredResultsPath])
|
||||
if diffResult == 0:
|
||||
diffResult = diffFiles(baselinesPath, filteredResultsPath)
|
||||
if diffResult:
|
||||
print(''.join(diffResult))
|
||||
print(" \n****************************\n \033[91mResults differed")
|
||||
if len(diffResult) > overallResult:
|
||||
overallResult = len(diffResult)
|
||||
else:
|
||||
os.remove(filteredResultsPath)
|
||||
print(" \033[92mResults matched")
|
||||
else:
|
||||
print(" \n****************************\n \033[91mResults differed")
|
||||
if diffResult > overallResult:
|
||||
overallResult = diffResult
|
||||
print("\033[0m")
|
||||
else:
|
||||
print(" first approval")
|
||||
|
Loading…
Reference in New Issue
Block a user