Commit 1d8a3c36 authored by Matthew P. Russell's avatar Matthew P. Russell
Browse files

Update unit_test

parent 85f25099
......@@ -28,18 +28,29 @@ DRIVERFILE = './unit_test_driver.cpp' # Must match Makefile
FAILURE = "31"
SUCCESS = "32"
INFO = "34"
OSTREAM = "35"
OUTPUT = "37"
# inform prints the provided string to cout in the provided color
# if linebreak == True, add a dotted line
# if extraline == True, add an extra newline
def inform(s, color=INFO, linebreak=False, extraline=False):
def inform(s, color=INFO, linebreak=False):
if color == INFO:
sys.stderr.write("\n\n")
sys.stderr.write("\033[1;" + color + "m" + s + "\033[0m\n")
if linebreak:
sys.stderr.write("-----------------------------------\n")
if extraline:
sys.stderr.write("\n")
def std_out(s, color=OSTREAM, linebreak=False):
sys.stderr.write("\n\033[1;" + color + "m" + s + "\033[0m\n")
if linebreak:
sys.stderr.write("------\n")
# cleanup removes the copied driver
def cleanup():
......@@ -104,7 +115,7 @@ driver_contents = "".join(driver_contents)
with open(DRIVERFILE, 'w') as driver_file:
driver_file.write(driver_contents)
inform("tests were set up successfully", color=SUCCESS, extraline=True)
inform("tests were set up successfully", color=SUCCESS)
#-----------------------------------------------------------------------------#
......@@ -149,10 +160,10 @@ compilation_result = subprocess.run(['make'],
# if compilation fails, show the result and quit
if compilation_result.returncode == 0:
inform("compilation passed", color=SUCCESS, extraline=True)
inform("compilation passed", color=SUCCESS)
else:
inform("compilation failed", color=FAILURE, linebreak=True)
inform(compilation_result.stderr, color=FAILURE, extraline=True)
inform(compilation_result.stderr, color=FAILURE)
subprocess.run(['make', 'clean'])
cleanup()
sys.exit(1)
......@@ -206,20 +217,28 @@ for test in test_names:
break
if valgrind_passed:
inform("valgrind passed", color=SUCCESS, extraline=True)
inform("valgrind passed", color=SUCCESS)
score += valgrind_test_max
else:
inform("valgrind failed", color=FAILURE, linebreak=True)
inform(VALGRIND_RESULT.stderr, color=FAILURE, extraline=True)
inform(VALGRIND_RESULT.stderr, color=FAILURE)
# if here, then the regular test failed
else:
inform("test failed", color=FAILURE)
if abs(test_result.returncode) == 11:
inform("segmentation fault!", color=FAILURE)
inform("valgrind failed by default", color=FAILURE, extraline=True)
inform("output", color=FAILURE, linebreak=True)
inform(test_result.stderr, color=FAILURE, extraline=True)
inform("valgrind failed by default", color=FAILURE)
# print output streams if they exist in test
if test_result.stdout:
std_out("stdout", linebreak=True)
inform(test_result.stdout, color=OUTPUT)
if test_result.stderr:
std_out("stderr", linebreak=True)
inform(test_result.stderr, color=OUTPUT)
# make sure final score is <= max (might happen b/c we're rounding)
final_score = min([overall_score, round(score, 2)])
......@@ -228,8 +247,9 @@ final_score = min([overall_score, round(score, 2)])
if final_score > 99: final_score = 100
inform("final score: " + str(final_score) + " / " + str(overall_score),
color=INFO, extraline=True)
color=INFO)
# clean up
subprocess.run(['make','clean'])
cleanup()
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment