if (len(actual_array) > len(expected_array)):
raise ExtraOutput(actual_array[len(expected_array)].strip())
-# Compile the run's target program with all the requested plug-ins
-# then run the resulting executable and check that its output is as
-# expected.
-# Returns True if the run passes.
-def doRun(run):
+# Same as doRun but takes a temporary working directory (to place
+# compiled objects) as an input.
+def doRunInTempDir(run, tmp_dir):
print " Run:", run.name
- tmp_dir = tempfile.mkdtemp(prefix='test-out-')
-
# Compile all the plug-ins for this test.
plugin_libs = []
for i in range(len(run.plugin_list)):
test_executable = compileTestcase(tmp_dir, run.target_source,
run.hooks_source, plugin_libs)
- if test_executable is not None:
- test_proc = subprocess.Popen([test_executable], stdout = subprocess.PIPE)
- try:
- checkRun(test_proc, run.output)
- except TestProgramException as e:
- print e.getMessage()
- return False
- else:
+ if test_executable is None:
return False
+ # Open the compiled test program...
+ try:
+ test_proc = subprocess.Popen([test_executable],
+ stdout = subprocess.PIPE)
+ except OSError as e:
+ sys.stderr.write('Fatal error opening test program: {0:s}\n'
+ .format(e.strerror))
+ sys.exit(1)
+
+ # ... and run it.
+ try:
+ checkRun(test_proc, run.output)
+ except TestProgramException as e:
+ print e.getMessage()
+ return False
+
+ return True
+
+# Compile the run's target program with all the requested plug-ins
+# then run the resulting executable and check that its output is as
+# expected.
+# Returns True if the run passes.
+def doRun(run):
+ tmp_dir = tempfile.mkdtemp(prefix='test-out-')
+ result = doRunInTempDir(run, tmp_dir)
+
# Delete temp directory
shutil.rmtree(path = tmp_dir, ignore_errors = True)
- return True
+
+ return result
def usage():
sys.stderr.write(
sys.exit(1)
print "Testcase:", dh.name
+ passed = 0
for run in dh.run_list:
- doRun(run)
+ if doRun(run):
+ passed += 1
+
+ if passed == len(dh.run_list):
+ print "All runs passed!"
+ else:
+ print ("Testcase failed. {0:d} out of {0:d} runs passed."
+ .format(passed, len(dh.run_list)))