45 lines
1.5 KiB
Python
Executable File
45 lines
1.5 KiB
Python
Executable File
#!/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)
|
|
rc = Popen(['./jtlc', '-E', '-o', exe + '.gen.c', test_source]).wait()
|
|
if rc != 0:
|
|
sys.stdout.write('Failed to compile test %s\n' % test_name)
|
|
passed = False
|
|
if passed:
|
|
rc = Popen(['./jtlc', '-o', exe, test_source]).wait()
|
|
if rc != 0:
|
|
sys.stdout.write('Failed to compile test %s\n' % test_name)
|
|
passed = False
|
|
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))
|