2017-01-09 15:12:12 +01:00
|
|
|
from __future__ import print_function
|
2014-03-08 11:31:38 +01:00
|
|
|
|
2012-11-29 09:41:17 +01:00
|
|
|
import os
|
|
|
|
import sys
|
|
|
|
import subprocess
|
|
|
|
import re
|
|
|
|
|
2017-01-09 15:12:12 +01:00
|
|
|
import scriptCommon
|
2013-04-24 19:58:57 +02:00
|
|
|
from scriptCommon import catchPath
|
|
|
|
|
2017-01-09 15:12:12 +01:00
|
|
|
rootPath = os.path.join(catchPath, 'projects/SelfTest/Baselines')
|
2013-09-30 08:39:06 +02:00
|
|
|
|
2017-01-09 15:12:12 +01:00
|
|
|
filenameParser = re.compile(r'(.*)/(.*\..pp:)(.*)')
|
|
|
|
filelineParser = re.compile(r'(.*\..pp:)([0-9]*)(.*)')
|
|
|
|
pathParser = re.compile(r'(.*?)/(.*\..pp)(.*)')
|
|
|
|
lineNumberParser = re.compile(r'(.*)line="[0-9]*"(.*)')
|
|
|
|
hexParser = re.compile(r'(.*)\b(0[xX][0-9a-fA-F]+)\b(.*)')
|
|
|
|
durationsParser = re.compile(r'(.*)time="[0-9]*\.[0-9]*"(.*)')
|
|
|
|
versionParser = re.compile(r'(.*?)Catch v[0-9]*\.[0-9]*\.[0-9]*(.*)')
|
|
|
|
devVersionParser = re.compile(r'(.*?)Catch v[0-9]*\.[0-9]*\.[0-9]*-develop\.[0-9]*(.*)')
|
|
|
|
nullParser = re.compile(r'(.*?)\b(__null|nullptr)\b(.*)')
|
2017-01-09 15:33:03 +01:00
|
|
|
exeNameParser = re.compile(r'(.*?)\b(CatchSelfTest|SelfTest)\b(.*)')
|
2012-11-29 09:41:17 +01:00
|
|
|
|
2013-02-02 20:58:04 +01:00
|
|
|
if len(sys.argv) == 2:
|
2017-01-09 15:12:12 +01:00
|
|
|
cmdPath = sys.argv[1]
|
2013-02-02 20:58:04 +01:00
|
|
|
else:
|
2017-01-09 15:12:12 +01:00
|
|
|
cmdPath = scriptCommon.getBuildExecutable()
|
|
|
|
|
|
|
|
if not cmdPath.startswith("/"):
|
|
|
|
cmdPath = os.path.join(catchPath, cmdPath)
|
2012-11-29 09:41:17 +01:00
|
|
|
|
2013-09-27 20:01:14 +02:00
|
|
|
overallResult = 0
|
2012-11-29 09:41:17 +01:00
|
|
|
|
2017-01-09 15:12:12 +01:00
|
|
|
def filterLine(line):
|
|
|
|
m = filenameParser.match(line)
|
|
|
|
if m:
|
|
|
|
line = m.group(2) + m.group(3)
|
|
|
|
m2 = filelineParser.match(line)
|
|
|
|
if m2:
|
|
|
|
line = m2.group(1) + "<line number>" + m2.group(3)
|
|
|
|
else:
|
|
|
|
m2 = lineNumberParser.match(line)
|
|
|
|
if m2:
|
|
|
|
line = m2.group(1) + m2.group(2)
|
|
|
|
m = pathParser.match(line)
|
|
|
|
if m:
|
|
|
|
path = "/" + m.group(2)
|
|
|
|
if path.startswith(catchPath):
|
|
|
|
path = path[1 + len(catchPath):]
|
|
|
|
line = m.group(1) + path + m.group(3)
|
|
|
|
m = devVersionParser.match(line)
|
|
|
|
if m:
|
|
|
|
line = m.group(1) + "<version>" + m.group(2)
|
|
|
|
else:
|
|
|
|
m = versionParser.match(line)
|
|
|
|
if m:
|
|
|
|
line = m.group(1) + "<version>" + m.group(2)
|
|
|
|
|
|
|
|
m = nullParser.match(line)
|
|
|
|
if m:
|
|
|
|
line = m.group(1) + "0" + m.group(3)
|
|
|
|
|
2017-01-09 15:33:03 +01:00
|
|
|
m = exeNameParser.match(line)
|
|
|
|
if m:
|
|
|
|
line = m.group(1) + "<exe-name>" + m.group(3)
|
|
|
|
|
2017-01-09 15:12:12 +01:00
|
|
|
while True:
|
|
|
|
m = hexParser.match(line)
|
|
|
|
if m:
|
|
|
|
line = m.group(1) + "0x<hex digits>" + m.group(3)
|
|
|
|
else:
|
|
|
|
break
|
|
|
|
m = durationsParser.match(line)
|
|
|
|
if m:
|
|
|
|
line = m.group(1) + 'time="{duration}"' + m.group(2)
|
|
|
|
return line
|
|
|
|
|
|
|
|
|
|
|
|
def approve(baseName, args):
|
|
|
|
global overallResult
|
|
|
|
args[0:0] = [cmdPath]
|
|
|
|
if not os.path.exists(cmdPath):
|
|
|
|
raise Exception("Executable doesn't exist at " + cmdPath)
|
|
|
|
baselinesPath = os.path.join(rootPath, '{0}.approved.txt'.format(baseName))
|
|
|
|
rawResultsPath = os.path.join(rootPath, '_{0}.tmp'.format(baseName))
|
|
|
|
filteredResultsPath = os.path.join(rootPath, '{0}.unapproved.txt'.format(baseName))
|
|
|
|
|
|
|
|
f = open(rawResultsPath, 'w')
|
|
|
|
subprocess.call(args, stdout=f, stderr=f)
|
|
|
|
f.close()
|
|
|
|
|
|
|
|
rawFile = open(rawResultsPath, 'r')
|
|
|
|
filteredFile = open(filteredResultsPath, 'w')
|
|
|
|
for line in rawFile:
|
|
|
|
filteredFile.write(filterLine(line).rstrip() + "\n")
|
|
|
|
filteredFile.close()
|
|
|
|
rawFile.close()
|
|
|
|
|
|
|
|
os.remove(rawResultsPath)
|
|
|
|
print()
|
|
|
|
print(baseName + ":")
|
|
|
|
if os.path.exists(baselinesPath):
|
|
|
|
diffResult = subprocess.call(["diff", baselinesPath, filteredResultsPath])
|
|
|
|
if diffResult == 0:
|
|
|
|
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")
|
|
|
|
if overallResult == 0:
|
|
|
|
overallResult = 1
|
|
|
|
|
|
|
|
|
|
|
|
print("Running approvals against executable:")
|
|
|
|
print(" " + cmdPath)
|
2013-09-27 20:01:14 +02:00
|
|
|
|
|
|
|
# Standard console reporter
|
2017-01-09 15:26:59 +01:00
|
|
|
approve("console.std", ["~[c++11]", "--order", "lex"])
|
2013-09-27 20:01:14 +02:00
|
|
|
# console reporter, include passes, warn about No Assertions
|
2017-01-09 15:26:59 +01:00
|
|
|
approve("console.sw", ["~[c++11]", "-s", "-w", "NoAssertions", "--order", "lex"])
|
2013-09-27 20:01:14 +02:00
|
|
|
# console reporter, include passes, warn about No Assertions, limit failures to first 4
|
2017-01-09 15:26:59 +01:00
|
|
|
approve("console.swa4", ["~[c++11]", "-s", "-w", "NoAssertions", "-x", "4", "--order", "lex"])
|
2013-09-27 20:01:14 +02:00
|
|
|
# junit reporter, include passes, warn about No Assertions
|
2017-01-09 15:26:59 +01:00
|
|
|
approve("junit.sw", ["~[c++11]", "-s", "-w", "NoAssertions", "-r", "junit", "--order", "lex"])
|
2013-09-27 20:01:14 +02:00
|
|
|
# xml reporter, include passes, warn about No Assertions
|
2017-01-09 15:26:59 +01:00
|
|
|
approve("xml.sw", ["~[c++11]", "-s", "-w", "NoAssertions", "-r", "xml", "--order", "lex"])
|
2013-09-27 20:01:14 +02:00
|
|
|
|
2014-03-08 11:31:11 +01:00
|
|
|
if overallResult != 0:
|
2017-01-09 15:12:12 +01:00
|
|
|
print("If these differenecs are expected run approve.py to approve new baselines")
|
|
|
|
exit(overallResult)
|