Skip to content

Instantly share code, notes, and snippets.

@csaftoiu csaftoiu/clemtest.py
Created Sep 13, 2014

Embed
What would you like to do?
import subprocess
from clemtest_data import test_data
TMPF = "____tmptest_____"
def run_test(test_name, program, expected_out, stdin=''):
with open(TMPF, "wb") as f:
f.write(program)
p = subprocess.Popen(["python", "clemint.py", TMPF],
stdin=subprocess.PIPE, stdout=subprocess.PIPE, stderr=subprocess.PIPE)
gold = subprocess.Popen(["./clem", TMPF],
stdin=subprocess.PIPE, stdout=subprocess.PIPE, stderr=subprocess.PIPE)
out, err = p.communicate(stdin)
out = out.replace('\r\n', '\n')
expected_out, _ = gold.communicate(stdin)
if out != expected_out:
print "FAILED TEST %s" % (test_name,)
print "expected:\n%s\ngot:\n%s" % (`expected_out`, `out`)
#print err
else:
print "PASSED TEST %s" % (test_name,)
for suite, runs in test_data:
for i, test in enumerate(runs):
run_test("%s #%d" % (suite, i+1), *test)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.