add tests folder and run-tests script

This commit is contained in:
Josh Holtrop 2011-08-30 15:07:08 -04:00
parent f534f3e753
commit 002aa69d03
4 changed files with 48 additions and 0 deletions

36
run-tests Executable file
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))

1
tests/.gitignore vendored Normal file
View File

@ -0,0 +1 @@
test???

10
tests/test001.jtl Normal file
View File

@ -0,0 +1,10 @@
C("#include <stdio.h>");
C("int main(int argc, char *argv[])");
C("{");
C("printf(\"Hello, World!\\n\");");
C("return 42;");
C("}");

1
tests/test001.out Normal file
View File

@ -0,0 +1 @@
Hello, World!