add tests folder and run-tests script

This commit is contained in:
Josh Holtrop committed 2011-08-30 15:07:08 -04:00
1 parent f534f3e753
commit 002aa69d03
4 files changed
+48

No files matched your search

Executable
+36
View File
@@ -0,0 +1,36 @@
#!/usr/bin/env python
import os
import sys
import re
from subprocess import Popen, PIPE
def main(argv):
tests = sorted(filter(lambda x: x.endswith('.jtl'), os.listdir('tests')))
for t in tests:
passed = True
test_name = re.sub(r'\.jtl$', '', t)
test_source = 'tests/' + t
exe = 'tests/' + test_name
if os.path.exists(exe):
os.unlink(exe)
Popen(['./jtlc', '-o', exe, test_source]).wait()
if os.path.exists(exe):
output = Popen([exe], stdout=PIPE).communicate()[0]
if os.path.exists(exe + '.out'):
f = open(exe + '.out', 'r')
expected = f.read()
f.close()
if output != expected:
passed = False
sys.stdout.write('Expected:\n')
sys.stdout.write(expected)
sys.stdout.write('\n')
sys.stdout.write('Actual:\n')
sys.stdout.write(output)
sys.stdout.write(test_name + ': ')
sys.stdout.write('PASS' if passed else 'FAIL')
sys.stdout.write('\n')
if __name__ == '__main__':
sys.exit(main(sys.argv))