aboutsummaryrefslogtreecommitdiffstats
path: root/testsuite/jlox.tests/tests.exp
diff options
context:
space:
mode:
authorGravatar Tom Willemse2021-02-17 21:42:37 -0800
committerGravatar Tom Willemse2021-02-17 21:42:37 -0800
commit4fbfa53dd79a84465256010a263dd4863e93032c (patch)
tree67fdb038cea9d5811d7750f7cf4b191f5e548246 /testsuite/jlox.tests/tests.exp
parente283991f902c38af8e6b5c6ae299911d120d8bcf (diff)
downloadcrafting-interpreters-4fbfa53dd79a84465256010a263dd4863e93032c.tar.gz
crafting-interpreters-4fbfa53dd79a84465256010a263dd4863e93032c.zip
Add basic test
Diffstat (limited to 'testsuite/jlox.tests/tests.exp')
-rw-r--r--testsuite/jlox.tests/tests.exp29
1 files changed, 29 insertions, 0 deletions
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" }
+}