[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
Writing tests for the REPL: tab-completion, etc
From: |
Jose E. Marchesi |
Subject: |
Writing tests for the REPL: tab-completion, etc |
Date: |
Sun, 12 Apr 2020 09:24:09 +0200 |
User-agent: |
Gnus/5.13 (Gnus v5.13) Emacs/28.0.50 (gnu/linux) |
Hi people!
At the moment we have 3635 tests distributed among five testsuites:
poke.cmd -> Poke commands, like `dump', qsave', etc
poke.map -> Mapping.
poke.pkl -> Poke language constructions.
poke.std -> Poke standard library.
poke.repl -> REPL operations
The cmd, map, pkl and std testsuites are dg-based. This means they use
the infrastructure in testsuite/lib/poke-dg.exp, and each test is
basically a source .pk file with dg-commands embedded in comments.
Adding a new test to any of these testsuites involves a new .pk file,
which is picked automatically by the corresponding poke.FOO/FOO.exp
file.
poke.repl is different. This testsuite is intended to test features in
the interactive usage of poke. Therefore, it is not dg-based. Instead,
it uses the services provided by testsuite/lib/poke.exp. In a nutshell,
these services are:
poke_start
Run a new poke process and wait at the prompt.
poke_exit
Exit poke.
poke_test_cmd CMD PATTERN
Send CMD to poke, and expect the result PATTERN. CMD is sent as
virtual keystrokes. Therefore, sending \t or \n has the same effect
on the REPL than typing TAB or RET in the keyboard, respectively.
PATTERN shouldn't include the prompt.
We have had a few breakages recently related to tab-completion. It is
no coincidence that we didn't have any tab-completion related test in
poke.repl. In fact, we only had one test there. So we clearly need to
add more REPL tests.
Adding a new test to poke.repl involves editing poke.repl/repl.exp and
adding a new set of poke_test_cmd invocations, like this:
poke_start
set test "slashes are preserved"
poke_test_cmd {4 / 2} {2}
set test "tab-completion-1"
poke_test_cmd {.set obase 2} {}
poke_test_cmd ".se\t obase 16" {}
poke_test_cmd {.set obase} {16}
poke_exit
The snippet above implements two tests in the same poke run. First,
poke is started, then the test "slashes are preserved" runs, then the
test "tab-completion-1" runs. Then poke is exitted.
If your test, for whatever reason, needs a fresh instance of poke, just
poke_exit and then poke_start.
Happy repl testing!
- Writing tests for the REPL: tab-completion, etc,
Jose E. Marchesi <=