mirror of
				https://github.com/catchorg/Catch2.git
				synced 2025-10-31 20:27:11 +01:00 
			
		
		
		
	Split approve file into multiple files
This commit is contained in:
		| @@ -10,28 +10,14 @@ 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]*"(.*)' ) | ||||
|  | ||||
| #catchPath = os.path.dirname(os.path.realpath( os.path.dirname(sys.argv[0]))) | ||||
|  | ||||
| baselinesPath = os.path.join( catchPath, 'projects/SelfTest/Baselines/approvedResults.txt' ) | ||||
| rawResultsPath = os.path.join( catchPath, 'projects/SelfTest/Baselines/_rawResults.tmp' ) | ||||
| filteredResultsPath = os.path.join( catchPath, 'projects/SelfTest/Baselines/unapprovedResults.txt' ) | ||||
|  | ||||
| if len(sys.argv) == 2: | ||||
| 	cmdPath = sys.argv[1] | ||||
| else: | ||||
| 	cmdPath = os.path.join( catchPath, 'projects/XCode4/CatchSelfTest/DerivedData/CatchSelfTest/Build/Products/Debug/CatchSelfTest' ) | ||||
|  | ||||
| f = open( rawResultsPath, 'w' ) | ||||
| subprocess.call([ cmdPath, "~dummy", "-r", "console" ], stdout=f, stderr=f ) | ||||
| subprocess.call([ cmdPath, "~dummy", "-s", "-w", "NoAssertions", "-r", "console" ], stdout=f, stderr=f ) | ||||
| subprocess.call([ cmdPath, "~dummy", "-s", "-w", "NoAssertions", "-r", "console", "-a", "4" ], stdout=f, stderr=f ) | ||||
| subprocess.call([ cmdPath, "~dummy", "-s", "-w", "NoAssertions", "-r", "junit" ], stdout=f, stderr=f ) | ||||
| subprocess.call([ cmdPath, "~dummy", "-s", "-w", "NoAssertions", "-r", "xml" ], stdout=f, stderr=f ) | ||||
| f.close() | ||||
| overallResult = 0 | ||||
|  | ||||
| rawFile = open( rawResultsPath, 'r' ) | ||||
| filteredFile = open( filteredResultsPath, 'w' ) | ||||
| for line in rawFile: | ||||
| def filterLine( line ): | ||||
| 	m = filenameParser.match( line ) | ||||
| 	if m: | ||||
| 		line = m.group(1) + m.group(3) | ||||
| @@ -49,18 +35,55 @@ for line in rawFile: | ||||
| 	m = durationsParser.match( line ) | ||||
| 	if m: | ||||
| 		line = m.group(1) + 'time="{duration}"' + m.group(2) | ||||
| 	return line | ||||
|  | ||||
| 	filteredFile.write( line.rstrip() + "\n" ) | ||||
| filteredFile.close() | ||||
| rawFile.close() | ||||
| def approve( baseName, args ): | ||||
| 	global overallResult | ||||
| 	args[0:0] = [cmdPath] | ||||
| 	baselinesPath = os.path.join( catchPath, 'projects/SelfTest/Baselines/{0}.approved.txt'.format( baseName ) ) | ||||
| 	rawResultsPath = os.path.join( catchPath, 'projects/SelfTest/Baselines/_{0}.tmp'.format( baseName ) ) | ||||
| 	filteredResultsPath = os.path.join( catchPath, 'projects/SelfTest/Baselines/{0}.unapproved.txt'.format( baseName ) ) | ||||
|  | ||||
| os.remove( rawResultsPath ) | ||||
| print | ||||
| diffResult = subprocess.call([ "diff", baselinesPath, filteredResultsPath ] ) | ||||
| if diffResult == 0: | ||||
| 	os.remove( filteredResultsPath ) | ||||
| 	print "\033[92mResults matched" | ||||
| else: | ||||
| 	print "\n****************************\n\033[91mResults differed" | ||||
| print "\033[0m" | ||||
| exit( diffResult) | ||||
| 	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) | ||||
| @@ -1,14 +1,29 @@ | ||||
| import os | ||||
| import sys | ||||
| import shutil | ||||
|  | ||||
| import glob | ||||
| from scriptCommon import catchPath | ||||
|  | ||||
| baselinesPath = os.path.join( catchPath, 'projects/SelfTest/Baselines/approvedResults.txt' ) | ||||
| filteredResultsPath = os.path.join( catchPath, 'projects/SelfTest/Baselines/unapprovedResults.txt' ) | ||||
| rootPath = os.path.join( catchPath, 'projects/SelfTest/Baselines' ) | ||||
|  | ||||
| if os.path.isfile( filteredResultsPath ): | ||||
| 	os.remove( baselinesPath ) | ||||
| 	os.rename( filteredResultsPath, baselinesPath ) | ||||
| if len(sys.argv) > 1: | ||||
| 	files = [os.path.join( rootPath, f ) for f in sys.argv[1:]] | ||||
| else: | ||||
| 	print "approval file " + filteredResultsPath + " does not exist" | ||||
| 	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" | ||||
		Reference in New Issue
	
	Block a user
	 Phil Nash
					Phil Nash