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' )
|
|
|
|
|
2013-09-30 09:01:10 +02:00
|
|
|
filenameParser = re.compile( r'.*/(.*\..pp:)(.*)' )
|
|
|
|
filelineParser = re.compile( r'(.*\..pp:)([0-9]*)(.*)' )
|
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]*"(.*)' )
|
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:
|
2013-04-24 19:58:57 +02:00
|
|
|
cmdPath = os.path.join( catchPath, 'projects/XCode4/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:
|
2013-09-30 09:01:10 +02:00
|
|
|
line = m.group(1) + m.group(2)
|
|
|
|
m = filelineParser.match( line )
|
|
|
|
if m:
|
|
|
|
line = m.group(1) + "<line number>" + m.group(3)
|
2013-06-29 13:04:38 +02:00
|
|
|
else:
|
|
|
|
m = lineNumberParser.match( line )
|
|
|
|
if m:
|
|
|
|
line = m.group(1) + 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]
|
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 )
|
|
|
|
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
|
|
|
|
|
|
|
|
# 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"] )
|
|
|
|
|
|
|
|
if overallResult <> 0:
|
|
|
|
print "run approve.py to approve new baselines"
|
|
|
|
exit( overallResult)
|