2014-03-08 11:31:38 +01:00
|
|
|
from __future__ import print_function
|
|
|
|
|
2012-11-29 09:41:17 +01:00
|
|
|
import os
|
|
|
|
import sys
|
|
|
|
import subprocess
|
|
|
|
import re
|
|
|
|
|
2013-04-24 19:58:57 +02:00
|
|
|
from scriptCommon import catchPath
|
|
|
|
|
2013-09-30 08:39:06 +02:00
|
|
|
rootPath = os.path.join( catchPath, 'projects/SelfTest/Baselines' )
|
|
|
|
|
2014-12-12 00:40:29 +01:00
|
|
|
filenameParser = re.compile( r'(.*)/(.*\..pp:)(.*)' )
|
2013-09-30 09:01:10 +02:00
|
|
|
filelineParser = re.compile( r'(.*\..pp:)([0-9]*)(.*)' )
|
2014-12-12 00:40:29 +01:00
|
|
|
pathParser = re.compile( r'(.*?)/(.*\..pp)(.*)' )
|
2013-06-29 13:04:38 +02:00
|
|
|
lineNumberParser = re.compile( r'(.*)line="[0-9]*"(.*)' )
|
2012-11-29 09:41:17 +01:00
|
|
|
hexParser = re.compile( r'(.*)\b(0[xX][0-9a-fA-F]+)\b(.*)' )
|
2013-08-15 19:50:40 +02:00
|
|
|
durationsParser = re.compile( r'(.*)time="[0-9]*\.[0-9]*"(.*)' )
|
2015-06-30 19:24:59 +02:00
|
|
|
versionParser = re.compile( r'(.*?)Catch v[0-9]*\.[0-9]*\.[0-9].?( .*)' )
|
2012-11-29 09:41:17 +01:00
|
|
|
|
2013-02-02 20:58:04 +01:00
|
|
|
if len(sys.argv) == 2:
|
|
|
|
cmdPath = sys.argv[1]
|
|
|
|
else:
|
2014-04-16 19:00:55 +02:00
|
|
|
cmdPath = os.path.join( catchPath, 'projects/XCode/CatchSelfTest/DerivedData/CatchSelfTest/Build/Products/Debug/CatchSelfTest' )
|
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
|
|
|
|
2013-09-27 20:01:14 +02:00
|
|
|
def filterLine( line ):
|
2012-11-29 09:41:17 +01:00
|
|
|
m = filenameParser.match( line )
|
|
|
|
if m:
|
2014-12-12 00:40:29 +01:00
|
|
|
line = m.group(2) + m.group(3)
|
|
|
|
m2 = filelineParser.match( line )
|
|
|
|
if m2:
|
|
|
|
line = m2.group(1) + "<line number>" + m2.group(3)
|
2013-06-29 13:04:38 +02:00
|
|
|
else:
|
2014-12-12 00:40:29 +01:00
|
|
|
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)
|
2013-09-30 09:05:14 +02:00
|
|
|
m = versionParser.match( line )
|
|
|
|
if m:
|
|
|
|
line = m.group(1) + "<version>" + m.group(2)
|
2012-11-29 09:41:17 +01:00
|
|
|
|
|
|
|
while True:
|
|
|
|
m = hexParser.match( line )
|
|
|
|
if m:
|
|
|
|
line = m.group(1) + "0x<hex digits>" + m.group(3)
|
|
|
|
else:
|
|
|
|
break
|
2013-08-15 19:50:40 +02:00
|
|
|
m = durationsParser.match( line )
|
|
|
|
if m:
|
|
|
|
line = m.group(1) + 'time="{duration}"' + m.group(2)
|
2013-09-27 20:01:14 +02:00
|
|
|
return line
|
2013-08-15 19:50:40 +02:00
|
|
|
|
2013-09-27 20:01:14 +02:00
|
|
|
def approve( baseName, args ):
|
|
|
|
global overallResult
|
|
|
|
args[0:0] = [cmdPath]
|
2014-12-12 00:40:29 +01:00
|
|
|
if not os.path.exists( cmdPath ):
|
|
|
|
raise Exception( "Executable doesn't exist at " + cmdPath )
|
2013-09-30 08:39:06 +02:00
|
|
|
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 ) )
|
2012-11-29 09:41:17 +01:00
|
|
|
|
2013-09-27 20:01:14 +02:00
|
|
|
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 )
|
2014-03-08 11:31:38 +01:00
|
|
|
print()
|
|
|
|
print( baseName + ":" )
|
2013-09-27 20:01:14 +02:00
|
|
|
if os.path.exists( baselinesPath ):
|
|
|
|
diffResult = subprocess.call([ "diff", baselinesPath, filteredResultsPath ] )
|
|
|
|
if diffResult == 0:
|
|
|
|
os.remove( filteredResultsPath )
|
2014-03-08 11:31:38 +01:00
|
|
|
print( " \033[92mResults matched" )
|
2013-09-27 20:01:14 +02:00
|
|
|
else:
|
2014-03-08 11:31:38 +01:00
|
|
|
print( " \n****************************\n \033[91mResults differed" )
|
2013-09-27 20:01:14 +02:00
|
|
|
if diffResult > overallResult:
|
|
|
|
overallResult = diffResult
|
2014-03-08 11:31:38 +01:00
|
|
|
print( "\033[0m" )
|
2013-09-27 20:01:14 +02:00
|
|
|
else:
|
2014-03-08 11:31:38 +01:00
|
|
|
print( " first approval" )
|
2013-09-27 20:01:14 +02:00
|
|
|
if overallResult == 0:
|
|
|
|
overallResult = 1
|
|
|
|
|
|
|
|
# Standard console reporter
|
|
|
|
approve( "console.std", ["~_"] )
|
|
|
|
# console reporter, include passes, warn about No Assertions
|
|
|
|
approve( "console.sw", ["~_", "-s", "-w", "NoAssertions"] )
|
|
|
|
# console reporter, include passes, warn about No Assertions, limit failures to first 4
|
|
|
|
approve( "console.swa4", ["~_", "-s", "-w", "NoAssertions", "-x", "4"] )
|
|
|
|
# junit reporter, include passes, warn about No Assertions
|
|
|
|
approve( "junit.sw", ["~_", "-s", "-w", "NoAssertions", "-r", "junit"] )
|
|
|
|
# xml reporter, include passes, warn about No Assertions
|
|
|
|
approve( "xml.sw", ["~_", "-s", "-w", "NoAssertions", "-r", "xml"] )
|
|
|
|
|
2014-03-08 11:31:11 +01:00
|
|
|
if overallResult != 0:
|
2014-03-08 11:31:38 +01:00
|
|
|
print( "run approve.py to approve new baselines" )
|
2014-03-08 11:31:11 +01:00
|
|
|
exit( overallResult)
|