Skip to content

Instantly share code, notes, and snippets.

@csaftoiu
Created September 13, 2014 22:57
Show Gist options
  • Save csaftoiu/1d2b87d4870cd0d65c64 to your computer and use it in GitHub Desktop.
Save csaftoiu/1d2b87d4870cd0d65c64 to your computer and use it in GitHub Desktop.
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