From 002aa69d0320d1034123f70433548759bb7fb408 Mon Sep 17 00:00:00 2001 From: Josh Holtrop Date: Tue, 30 Aug 2011 15:07:08 -0400 Subject: [PATCH] add tests folder and run-tests script --- run-tests | 36 ++++++++++++++++++++++++++++++++++++ tests/.gitignore | 1 + tests/test001.jtl | 10 ++++++++++ tests/test001.out | 1 + 4 files changed, 48 insertions(+) create mode 100755 run-tests create mode 100644 tests/.gitignore create mode 100644 tests/test001.jtl create mode 100644 tests/test001.out diff --git a/run-tests b/run-tests new file mode 100755 index 0000000..a6707c4 --- /dev/null +++ b/run-tests @@ -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)) diff --git a/tests/.gitignore b/tests/.gitignore new file mode 100644 index 0000000..d26c090 --- /dev/null +++ b/tests/.gitignore @@ -0,0 +1 @@ +test??? diff --git a/tests/test001.jtl b/tests/test001.jtl new file mode 100644 index 0000000..711e3d1 --- /dev/null +++ b/tests/test001.jtl @@ -0,0 +1,10 @@ + +C("#include "); + +C("int main(int argc, char *argv[])"); +C("{"); + + C("printf(\"Hello, World!\\n\");"); + C("return 42;"); + +C("}"); diff --git a/tests/test001.out b/tests/test001.out new file mode 100644 index 0000000..8ab686e --- /dev/null +++ b/tests/test001.out @@ -0,0 +1 @@ +Hello, World!