Moving towards output verification

This commit is contained in:
Bruce Eckel 2015-05-02 23:49:25 -07:00
parent 8a0fa192e6
commit a6c4fb0807
4 changed files with 29 additions and 26 deletions

View File

@ -1,4 +1,4 @@
#!/usr/bin/python
#! python
"""
Runs a Java program, appends output if it's not there
@ -17,7 +17,7 @@ def makeOutputIncludedFile(path, fileName, changeReport, force = False):
package = ''
args = ''
command = None
for line in file(fileName):
for line in open(fileName):
if line.startswith("} /*"):
break # Out of for loop
if line.startswith("package"):
@ -32,20 +32,22 @@ def makeOutputIncludedFile(path, fileName, changeReport, force = False):
base = base[:-1]
if line.startswith("// {Exec:"):
command = line.split(':', 1)[1].strip()[:-1]
if "{TimeOutDuringTesting}" in line:
return # Don't run this one.
if not command:
command = "java " + package + base + args
command += " > " + base + "-output.txt"
print command
print(command)
result = os.system(command)
if(result != 0):
raise Exception, "Command returned nonzero value: " + str(result)
raise Exception("Command returned nonzero value: " + str(result))
# Read output file that was just generated:
results = file(base + "-output.txt").read().strip()
results = open(base + "-output.txt").read().strip()
# Strip off trailing spaces on each line:
results = "\n".join([line.rstrip() for line in results.split("\n")])
results = results.replace('\t', ' ')
if results:
if force or not oldOutput.findall(file(fileName).read()):
if force or not oldOutput.findall(open(fileName).read()):
processedText = createProcessedJavaText(results, fileName)
open(fileName, 'w').write(processedText + "\n")
if changeReport:
@ -53,17 +55,17 @@ def makeOutputIncludedFile(path, fileName, changeReport, force = False):
return # Don't need to try for error output
##### Duplicate for standard error output:
command += " 2> " + base + "-erroroutput.txt"
print command
print(command)
result = os.system(command)
if(result != 0):
raise Exception, "Command returned nonzero value: " + str(result)
raise Exception("Command returned nonzero value: " + str(result))
# Read error file that was just generated:
results = file(base + "-erroroutput.txt").read().strip()
results = open(base + "-erroroutput.txt").read().strip()
# Strip off trailing spaces on each line:
results = "\n".join([line.rstrip() for line in results.split("\n")])
results = results.replace('\t', ' ')
if results:
if force or not oldOutput.findall(file(fileName).read()):
if force or not oldOutput.findall(open(fileName).read()):
processedText = createProcessedJavaText(results, fileName)
open(fileName, 'w').write(processedText + "\n")
if changeReport:
@ -72,7 +74,7 @@ def makeOutputIncludedFile(path, fileName, changeReport, force = False):
def createProcessedJavaText(results, fileName):
processedJava = ''
for line in [line.rstrip() for line in file(fileName)]:
for line in [line.rstrip() for line in open(fileName)]:
if line.startswith("} ///:~"):
processedJava += "} /* Output:\n" + results + "\n*///:~"
return processedJava
@ -80,7 +82,7 @@ def createProcessedJavaText(results, fileName):
processedJava += line + "\n" + results + "\n*///:~" # Preserve modifiers
return processedJava
processedJava += line + "\n"
raise Exception, "No marker found at end of file " + path + " " + fileName
raise Exception("No marker found at end of file " + path + " " + fileName)
class ReportFile:
def __init__(self, filePath):
@ -88,9 +90,9 @@ class ReportFile:
self.file = None
def write(self, line):
if not self.file:
self.file = file(self.filePath, 'w')
self.file = open(self.filePath, 'w')
self.file.write(line)
print line
print(line)
def close(self):
if self.file:
self.file.close()
@ -102,7 +104,7 @@ if __name__ == "__main__":
if len(args):
if args[0] == "-force":
forceFlag = True
print "forceFlag = ", forceFlag
print("forceFlag = ", forceFlag)
del args[0]
if len(args) > 0:
for javaSource in args:
@ -115,19 +117,19 @@ if __name__ == "__main__":
for root, dirs, files in os.walk('.'):
if (os.sep + "gui") in root: continue
path = os.path.normpath(os.path.join(start,root))
print path
print(path)
for name in [name for name in files if name.endswith(".java")]:
java = file(os.path.join(path, name)).read()
java = open(os.path.join(path, name)).read()
if "public static void main(String" in java and \
not "{RunByHand}" in java and \
not "{ThrowsException}" in java and \
not "/* (Execute to see output) *///:~" in java and \
not "} /* Same output as" in java:
if forceFlag or not "} /* Output:" in java:
print "\t", name
print("\t", name)
makeOutputIncludedFile(path, name, changeReport, force = forceFlag)
changeReport.close()
os.system("uedit32 /f Changes.txt &")
os.system("subl /f Changes.txt &")

View File

@ -1,4 +1,4 @@
#!/usr/bin/python
#! py -2
"""
To do:

View File

@ -46,7 +46,6 @@
patterns/build.xml
references/build.xml
assertions/build.xml
database/build.xml
unittesting/build.xml
debugging/build.xml
logging/build.xml

View File

@ -165,7 +165,7 @@ def destDirs(pattern="**"):
return {str(file)[leader:] for file in destination.glob(pattern)}
def copyAntBuildFiles():
def copySupplementalFilesFromGithub():
for common in githubDirs().intersection(destDirs()):
print("->", common)
build = github / common / "build.xml"
@ -174,6 +174,8 @@ def copyAntBuildFiles():
shutil.copy(str(github / "Ant-Common.xml"), str(destination))
for face in (github / "gui").glob("*.gif"):
shutil.copy(str(face), str(destination / "gui"))
for verifier in ["OutputGenerator.py", "OutputVerifier.py"]:
shutil.copy(str(github/verifier), str(destination))
patterns = destination / "patterns"
trash = patterns / "recycleap" / "Trash.dat"
shutil.copy(str(trash), str(patterns / "recycleb"))
@ -376,7 +378,7 @@ def findNonJavaFiles():
def default():
clean()
extractExamples()
copyAntBuildFiles()
copySupplementalFilesFromGithub()
createAntFiles()
os.chdir("ExtractedExamples")
@ -388,14 +390,14 @@ if __name__ == '__main__':
if args.extract:
extractExamples()
copyAntBuildFiles()
copySupplementalFilesFromGithub()
createAntFiles()
if args.compare:
compareWithGithub()
if args.ant:
copyAntBuildFiles()
copySupplementalFilesFromGithub()
if args.makeant:
createAntFiles()