Add basic test
This commit is contained in:
parent
e283991f90
commit
4fbfa53dd7
3 changed files with 35 additions and 0 deletions
3
README.org
Normal file
3
README.org
Normal file
|
@ -0,0 +1,3 @@
|
|||
Run tests with:
|
||||
|
||||
: runtest --tool jlox --srcdir testsuite
|
3
jlox
Executable file
3
jlox
Executable file
|
@ -0,0 +1,3 @@
|
|||
#!/usr/bin/env sh
|
||||
|
||||
/usr/bin/java -jar src/_build/com/craftinginterpreters/lox/Lox.jar
|
29
testsuite/jlox.tests/tests.exp
Normal file
29
testsuite/jlox.tests/tests.exp
Normal file
|
@ -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" }
|
||||
}
|
Loading…
Reference in a new issue