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

View File

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

View File

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