aboutsummaryrefslogtreecommitdiff
path: root/unittest/Catch/scripts
diff options
context:
space:
mode:
Diffstat (limited to 'unittest/Catch/scripts')
-rw-r--r--unittest/Catch/scripts/approvalTests.py115
-rw-r--r--unittest/Catch/scripts/approve.py31
-rw-r--r--unittest/Catch/scripts/developBuild.py9
-rw-r--r--unittest/Catch/scripts/fixTrailingWhitespace.py46
-rw-r--r--unittest/Catch/scripts/generateSingleHeader.py103
-rw-r--r--unittest/Catch/scripts/majorRelease.py9
-rw-r--r--unittest/Catch/scripts/minorRelease.py9
-rw-r--r--unittest/Catch/scripts/patchRelease.py9
-rw-r--r--unittest/Catch/scripts/releaseCommon.py89
-rw-r--r--unittest/Catch/scripts/releaseNotes.py62
-rw-r--r--unittest/Catch/scripts/scriptCommon.py21
11 files changed, 503 insertions, 0 deletions
diff --git a/unittest/Catch/scripts/approvalTests.py b/unittest/Catch/scripts/approvalTests.py
new file mode 100644
index 0000000..618812f
--- /dev/null
+++ b/unittest/Catch/scripts/approvalTests.py
@@ -0,0 +1,115 @@
+from __future__ import print_function
+
+import os
+import sys
+import subprocess
+import re
+
+from scriptCommon import catchPath
+
+rootPath = os.path.join( catchPath, 'projects/SelfTest/Baselines' )
+
+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]*(.*)' )
+
+if len(sys.argv) == 2:
+ cmdPath = sys.argv[1]
+else:
+ cmdPath = os.path.join( catchPath, 'projects/XCode/CatchSelfTest/DerivedData/CatchSelfTest/Build/Products/Debug/CatchSelfTest' )
+
+overallResult = 0
+
+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)
+
+ 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
+
+# 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)
diff --git a/unittest/Catch/scripts/approve.py b/unittest/Catch/scripts/approve.py
new file mode 100644
index 0000000..f4b66aa
--- /dev/null
+++ b/unittest/Catch/scripts/approve.py
@@ -0,0 +1,31 @@
+from __future__ import print_function
+
+import os
+import sys
+import shutil
+import glob
+from scriptCommon import catchPath
+
+rootPath = os.path.join( catchPath, 'projects/SelfTest/Baselines' )
+
+if len(sys.argv) > 1:
+ files = [os.path.join( rootPath, f ) for f in sys.argv[1:]]
+else:
+ files = glob.glob( os.path.join( rootPath, "*.unapproved.txt" ) )
+
+
+def approveFile( approvedFile, unapprovedFile ):
+ justFilename = unapprovedFile[len(rootPath)+1:]
+ if os.path.exists( unapprovedFile ):
+ if os.path.exists( approvedFile ):
+ os.remove( approvedFile )
+ os.rename( unapprovedFile, approvedFile )
+ print( "approved " + justFilename )
+ else:
+ print( "approval file " + justFilename + " does not exist" )
+
+if len(files) > 0:
+ for unapprovedFile in files:
+ approveFile( unapprovedFile.replace( "unapproved.txt", "approved.txt" ), unapprovedFile )
+else:
+ print( "no files to approve" )
diff --git a/unittest/Catch/scripts/developBuild.py b/unittest/Catch/scripts/developBuild.py
new file mode 100644
index 0000000..c244871
--- /dev/null
+++ b/unittest/Catch/scripts/developBuild.py
@@ -0,0 +1,9 @@
+from __future__ import print_function
+from releaseCommon import Version
+
+v = Version()
+v.incrementBuildNumber()
+v.updateVersionFile()
+v.updateReadmeFile()
+
+print( "Updated Version.hpp and README to v{0}".format( v.getVersionString() ) ) \ No newline at end of file
diff --git a/unittest/Catch/scripts/fixTrailingWhitespace.py b/unittest/Catch/scripts/fixTrailingWhitespace.py
new file mode 100644
index 0000000..a1b6bbe
--- /dev/null
+++ b/unittest/Catch/scripts/fixTrailingWhitespace.py
@@ -0,0 +1,46 @@
+from __future__ import print_function
+import os
+from scriptCommon import catchPath
+
+changedFiles = 0
+
+def isSourceFile( path ):
+ return path.endswith( ".cpp" ) or path.endswith( ".h" ) or path.endswith( ".hpp" )
+
+def fixAllFilesInDir( dir ):
+ for f in os.listdir( dir ):
+ path = os.path.join( dir,f )
+ if os.path.isfile( path ):
+ if isSourceFile( path ):
+ fixFile( path )
+ else:
+ fixAllFilesInDir( path )
+
+def fixFile( path ):
+ f = open( path, 'r' )
+ lines = []
+ changed = 0
+ for line in f:
+ trimmed = line.rstrip() + "\n"
+ if trimmed != line:
+ changed = changed +1
+ lines.append( trimmed )
+ f.close()
+ if changed > 0:
+ global changedFiles
+ changedFiles = changedFiles + 1
+ print( path + ":" )
+ print( " - fixed " + str(changed) + " line(s)" )
+ altPath = path + ".backup"
+ os.rename( path, altPath )
+ f2 = open( path, 'w' )
+ for line in lines:
+ f2.write( line )
+ f2.close()
+ os.remove( altPath )
+
+fixAllFilesInDir(catchPath)
+if changedFiles > 0:
+ print( "Fixed " + str(changedFiles) + " file(s)" )
+else:
+ print( "No trailing whitespace found" )
diff --git a/unittest/Catch/scripts/generateSingleHeader.py b/unittest/Catch/scripts/generateSingleHeader.py
new file mode 100644
index 0000000..419633f
--- /dev/null
+++ b/unittest/Catch/scripts/generateSingleHeader.py
@@ -0,0 +1,103 @@
+from __future__ import print_function
+
+import os
+import sys
+import re
+import datetime
+import string
+
+from scriptCommon import catchPath
+from releaseCommon import Version
+
+
+includesParser = re.compile( r'\s*#include\s*"(.*)"' )
+guardParser = re.compile( r'\s*#.*TWOBLUECUBES_CATCH_.*_INCLUDED')
+defineParser = re.compile( r'\s*#define')
+ifParser = re.compile( r'\s*#ifndef TWOBLUECUBES_CATCH_.*_INCLUDED')
+endIfParser = re.compile( r'\s*#endif // TWOBLUECUBES_CATCH_.*_INCLUDED')
+ifImplParser = re.compile( r'\s*#ifdef CATCH_CONFIG_RUNNER' )
+commentParser1 = re.compile( r'^\s*/\*')
+commentParser2 = re.compile( r'^ \*')
+blankParser = re.compile( r'^\s*$')
+seenHeaders = set([])
+rootPath = os.path.join( catchPath, 'include/' )
+outputPath = os.path.join( catchPath, 'single_include/catch.hpp' )
+
+includeImpl = True
+
+for arg in sys.argv[1:]:
+ arg = string.lower(arg)
+ if arg == "noimpl":
+ includeImpl = False
+ print( "Not including impl code" )
+ else:
+ print( "\n** Unrecognised argument: " + arg + " **\n" )
+ exit(1)
+
+out = open( outputPath, 'w' )
+ifdefs = 0
+implIfDefs = -1
+
+def write( line ):
+ if includeImpl or implIfDefs == -1:
+ out.write( line )
+
+def parseFile( path, filename ):
+ global ifdefs
+ global implIfDefs
+
+ f = open( path + filename, 'r' )
+ blanks = 0
+ for line in f:
+ if ifParser.match( line ):
+ ifdefs = ifdefs + 1
+ elif endIfParser.match( line ):
+ ifdefs = ifdefs - 1
+ if ifdefs == implIfDefs:
+ implIfDefs = -1
+ m = includesParser.match( line )
+ if m:
+ header = m.group(1)
+ headerPath, sep, headerFile = header.rpartition( "/" )
+ if not headerFile in seenHeaders:
+ if headerFile != "tbc_text_format.h" and headerFile != "clara.h":
+ seenHeaders.add( headerFile )
+ write( "// #included from: {0}\n".format( header ) )
+ if( headerPath == "internal" and path.endswith( "internal/" ) ):
+ headerPath = ""
+ sep = ""
+ if os.path.exists( path + headerPath + sep + headerFile ):
+ parseFile( path + headerPath + sep, headerFile )
+ else:
+ parseFile( rootPath + headerPath + sep, headerFile )
+ else:
+ if ifImplParser.match(line):
+ implIfDefs = ifdefs
+ if (not guardParser.match( line ) or defineParser.match( line ) ) and not commentParser1.match( line )and not commentParser2.match( line ):
+ if blankParser.match( line ):
+ blanks = blanks + 1
+ else:
+ blanks = 0
+ if blanks < 2:
+ write( line.rstrip() + "\n" )
+
+
+v = Version()
+out.write( "/*\n" )
+out.write( " * Catch v{0}\n".format( v.getVersionString() ) )
+out.write( " * Generated: {0}\n".format( datetime.datetime.now() ) )
+out.write( " * ----------------------------------------------------------\n" )
+out.write( " * This file has been merged from multiple headers. Please don't edit it directly\n" )
+out.write( " * Copyright (c) 2012 Two Blue Cubes Ltd. All rights reserved.\n" )
+out.write( " *\n" )
+out.write( " * Distributed under the Boost Software License, Version 1.0. (See accompanying\n" )
+out.write( " * file LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt)\n" )
+out.write( " */\n" )
+out.write( "#ifndef TWOBLUECUBES_SINGLE_INCLUDE_CATCH_HPP_INCLUDED\n" )
+out.write( "#define TWOBLUECUBES_SINGLE_INCLUDE_CATCH_HPP_INCLUDED\n" )
+
+parseFile( rootPath, 'catch.hpp' )
+
+out.write( "#endif // TWOBLUECUBES_SINGLE_INCLUDE_CATCH_HPP_INCLUDED\n\n" )
+
+print ("Generated single include for Catch v{0}\n".format( v.getVersionString() ) )
diff --git a/unittest/Catch/scripts/majorRelease.py b/unittest/Catch/scripts/majorRelease.py
new file mode 100644
index 0000000..03b7e78
--- /dev/null
+++ b/unittest/Catch/scripts/majorRelease.py
@@ -0,0 +1,9 @@
+from __future__ import print_function
+from releaseCommon import Version
+
+v = Version()
+v.incrementMajorVersion()
+v.updateVersionFile()
+v.updateReadmeFile()
+
+print( "Updated Version.hpp and README to v{0}".format( v.getVersionString() ) ) \ No newline at end of file
diff --git a/unittest/Catch/scripts/minorRelease.py b/unittest/Catch/scripts/minorRelease.py
new file mode 100644
index 0000000..bbd97ed
--- /dev/null
+++ b/unittest/Catch/scripts/minorRelease.py
@@ -0,0 +1,9 @@
+from __future__ import print_function
+from releaseCommon import Version
+
+v = Version()
+v.incrementMinorVersion()
+v.updateVersionFile()
+v.updateReadmeFile()
+
+print( "Updated Version.hpp and README to v{0}".format( v.getVersionString() ) ) \ No newline at end of file
diff --git a/unittest/Catch/scripts/patchRelease.py b/unittest/Catch/scripts/patchRelease.py
new file mode 100644
index 0000000..6abf87a
--- /dev/null
+++ b/unittest/Catch/scripts/patchRelease.py
@@ -0,0 +1,9 @@
+from __future__ import print_function
+from releaseCommon import Version
+
+v = Version()
+v.incrementPatchNumber()
+v.updateVersionFile()
+v.updateReadmeFile()
+
+print( "Updated Version.hpp and README to v{0}".format( v.getVersionString() ) ) \ No newline at end of file
diff --git a/unittest/Catch/scripts/releaseCommon.py b/unittest/Catch/scripts/releaseCommon.py
new file mode 100644
index 0000000..14eb235
--- /dev/null
+++ b/unittest/Catch/scripts/releaseCommon.py
@@ -0,0 +1,89 @@
+from __future__ import print_function
+
+import os
+import sys
+import re
+import string
+
+from scriptCommon import catchPath
+
+versionParser = re.compile( r'(\s*Version\slibraryVersion)\s*\(\s*(.*)\s*,\s*(.*)\s*,\s*(.*)\s*,\s*\"(.*)\"\s*,\s*(.*)\s*\).*' )
+rootPath = os.path.join( catchPath, 'include/' )
+versionPath = os.path.join( rootPath, "internal/catch_version.hpp" )
+readmePath = os.path.join( catchPath, "README.md" )
+
+class Version:
+ def __init__(self):
+ f = open( versionPath, 'r' )
+ for line in f:
+ m = versionParser.match( line )
+ if m:
+ self.variableDecl = m.group(1)
+ self.majorVersion = int(m.group(2))
+ self.minorVersion = int(m.group(3))
+ self.patchNumber = int(m.group(4))
+ self.branchName = m.group(5)
+ self.buildNumber = int(m.group(6))
+ f.close()
+
+ def nonDevelopRelease(self):
+ if self.branchName != "":
+ self.branchName = ""
+ self.buildNumber = 0
+ def developBuild(self):
+ if self.branchName == "":
+ self.branchName = "develop"
+ self.buildNumber = 0
+
+ def incrementBuildNumber(self):
+ self.developBuild()
+ self.buildNumber = self.buildNumber+1
+
+ def incrementPatchNumber(self):
+ self.nonDevelopRelease()
+ self.patchNumber = self.patchNumber+1
+
+ def incrementMinorVersion(self):
+ self.nonDevelopRelease()
+ self.patchNumber = 0
+ self.minorVersion = self.minorVersion+1
+
+ def incrementMajorVersion(self):
+ self.nonDevelopRelease()
+ self.patchNumber = 0
+ self.minorVersion = 0
+ self.majorVersion = self.majorVersion+1
+
+ def getVersionString(self):
+ versionString = '{0}.{1}.{2}'.format( self.majorVersion, self.minorVersion, self.patchNumber )
+ if self.branchName != "":
+ versionString = versionString + '-{0}.{1}'.format( self.branchName, self.buildNumber )
+ return versionString
+
+ def updateVersionFile(self):
+ f = open( versionPath, 'r' )
+ lines = []
+ for line in f:
+ m = versionParser.match( line )
+ if m:
+ lines.append( '{0}( {1}, {2}, {3}, "{4}", {5} );'.format( self.variableDecl, self.majorVersion, self.minorVersion, self.patchNumber, self.branchName, self.buildNumber ) )
+ else:
+ lines.append( line.rstrip() )
+ f.close()
+ f = open( versionPath, 'w' )
+ for line in lines:
+ f.write( line + "\n" )
+
+ def updateReadmeFile(self):
+ f = open( readmePath, 'r' )
+ lines = []
+ for line in f:
+ lines.append( line.rstrip() )
+ f.close()
+ f = open( readmePath, 'w' )
+ for line in lines:
+ if line.startswith( "*v" ):
+ f.write( '*v{0}*\n'.format( self.getVersionString() ) )
+ else:
+ f.write( line + "\n" )
+
diff --git a/unittest/Catch/scripts/releaseNotes.py b/unittest/Catch/scripts/releaseNotes.py
new file mode 100644
index 0000000..e083ec9
--- /dev/null
+++ b/unittest/Catch/scripts/releaseNotes.py
@@ -0,0 +1,62 @@
+import os
+import re
+import urllib2
+import json
+
+from scriptCommon import catchPath
+from scriptCommon import runAndCapture
+
+issueNumberRe = re.compile( r'(.*?)#([0-9]*)([^0-9]?.*)' )
+
+rootPath = os.path.join( catchPath, 'include/' )
+versionPath = os.path.join( rootPath, "internal/catch_version.hpp" )
+
+
+hashes = runAndCapture( ['git', 'log', '-2', '--format="%H"', versionPath] )
+lines = runAndCapture( ['git', 'log', hashes[1] + ".." + hashes[0], catchPath] )
+
+prevLine = ""
+messages = []
+dates = []
+issues = {}
+
+def getIssueTitle( issueNumber ):
+ try:
+ s = urllib2.urlopen("https://api.github.com/repos/philsquared/catch/issues/" + issueNumber ).read()
+ except e:
+ return "#HTTP Error#"
+
+ try:
+ j = json.loads( s )
+ return j["title"]
+ except e:
+ return "#JSON Error#"
+
+for line in lines:
+ if line.startswith( "commit"):
+ pass
+ elif line.startswith( "Author:"):
+ pass
+ elif line.startswith( "Date:"):
+ dates.append( line[5:].lstrip() )
+ pass
+ elif line == "" and prevLine == "":
+ pass
+ else:
+ prevLine = line
+ match = issueNumberRe.match( line )
+ line2 = ""
+ while match:
+ issueNumber = match.group(2)
+ issue = '#{0} ("{1}")'.format( issueNumber, getIssueTitle( issueNumber ) )
+ line2 = line2 + match.group(1) + issue
+ match = issueNumberRe.match( match.group(3) )
+ if line2 == "":
+ messages.append( line )
+ else:
+ messages.append( line2 )
+
+print "All changes between {0} and {1}:\n".format( dates[-1], dates[0] )
+
+for line in messages:
+ print line
diff --git a/unittest/Catch/scripts/scriptCommon.py b/unittest/Catch/scripts/scriptCommon.py
new file mode 100644
index 0000000..6ac381a
--- /dev/null
+++ b/unittest/Catch/scripts/scriptCommon.py
@@ -0,0 +1,21 @@
+import os
+import sys
+import subprocess
+
+catchPath = os.path.dirname(os.path.realpath( os.path.dirname(sys.argv[0])))
+
+def runAndCapture( args ):
+ child = subprocess.Popen(" ".join( args ), shell=True, stdout=subprocess.PIPE)
+ lines = []
+ line = ""
+ while True:
+ out = child.stdout.read(1)
+ if out == '' and child.poll() != None:
+ break
+ if out != '':
+ if out == '\n':
+ lines.append( line )
+ line = ""
+ else:
+ line = line + out
+ return lines \ No newline at end of file