From 4fbfa53dd79a84465256010a263dd4863e93032c Mon Sep 17 00:00:00 2001 From: Tom Willemse Date: Wed, 17 Feb 2021 21:42:37 -0800 Subject: Add basic test --- README.org | 3 +++ jlox | 3 +++ testsuite/jlox.tests/tests.exp | 29 +++++++++++++++++++++++++++++ 3 files changed, 35 insertions(+) create mode 100644 README.org create mode 100755 jlox create mode 100644 testsuite/jlox.tests/tests.exp diff --git a/README.org b/README.org new file mode 100644 index 0000000..83623d7 --- /dev/null +++ b/README.org @@ -0,0 +1,3 @@ +Run tests with: + +: runtest --tool jlox --srcdir testsuite diff --git a/jlox b/jlox new file mode 100755 index 0000000..4ef4503 --- /dev/null +++ b/jlox @@ -0,0 +1,3 @@ +#!/usr/bin/env sh + +/usr/bin/java -jar src/_build/com/craftinginterpreters/lox/Lox.jar diff --git a/testsuite/jlox.tests/tests.exp b/testsuite/jlox.tests/tests.exp new file mode 100644 index 0000000..9b9f620 --- /dev/null +++ b/testsuite/jlox.tests/tests.exp @@ -0,0 +1,29 @@ +set test_name "Printing" +set command_line "./jlox" + +spawn $command_line +send "print \"Hello, world!\";\n" + +expect { + "Error at" { fail "$test_name: error: $expect_out(buffer)\n" } + "> Hello, world!" { pass "$test_name" } + eof { fail "$test_name: Premature end of file: $expect_out(buffer)\n" } + timeout { fail "$test_name: timed out\n" } +} + + +set test_name "Local Functions and Closures" + +spawn $command_line +send "fun makeCounter() { var i = 0; fun count() { i = i + 1; print i; } return count; } +var counter = makeCounter(); +counter(); +counter(); +" + +expect { + "Error at" { fail "$test_name: error: $expect_out(buffer)\n" } + -re "> 1.*?> 2" { pass "$test_name" } + eof { fail "$test_name: Premature end of file: $expect_out(buffer)\n" } + timeout { fail "$test_name: timed out\n" } +} -- cgit v1.2.3-54-g00ecf