aboutsummaryrefslogtreecommitdiffstats
path: root/testsuite/jlox.tests/tests.exp
blob: 9b9f6204087eb898c4da7c7213680dcc907580d9 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
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" }
}