Write script tests
On this page
The all-routes test checks whether every line can be reached. Whether the story goes the way you decided, such as “picking in this order sets this variable to this value and passes this scene,” can be written down as tests and checked all at once with lim test. Run them after editing the script, and you’ll know whether anything changed that you didn’t mean to change.
The examples on this page use the English sample story, “Waiting for Stars” (choose “A sample story” and English in New Project, or run lim new --lang en; the characters are Akari and Sou).
Tests play from New Game without a screen, so they need neither an export nor Chromium. Studio doesn’t have a screen for running tests yet, so use lim on the command line (for how to install it, see Start with the command line).
Put the test files in place
Tests go in the tests folder directly inside the project folder, as text files with the .limtest extension. One file can hold as many tests as you like, each starting with a # name line.
A project made by choosing “A sample story” in Studio’s New Project has tests/start.limtest from the start. Here, the tests are written for that sample story (the story is in Japanese, so the choice text below is translated).
// Check how the story ends for each set of choices
# Look through the telescope and wish, and get the lens cap
choose Look through the telescope
choose Go outside and look up at the sky
choose Try making a wish
expect game.looked && game.wished
expect text "lens cap"
expect reach epilogue#dawn
expect end
# Watch quietly, and the door is left open
choose Go outside and look up at the sky
choose Watch quietly
expect !game.wished
expect text "left the door open just a little"
expect no-errors
chooseis what to pick at a choice. They’re used in the order written. Write the choice text as is, or part of it (choose Go outsidealso picks it). To write a number, count from 1 at the top.expectis what to check when it’s over. The example above checks the values of variables, text that appeared, scenes passed, reaching the end of the script, and that there were no runtime errors.- Each test plays as a newly started playthrough. Values set in a previous test don’t carry over.
- Lines starting with
//are comments. Indentation is only for looks and has no meaning.
Run them
In the project folder, run the following command. It runs every test in the tests folder. Add --lang en to get the results in English.
lim test --lang en
tests/start.limtest
pass Look through the telescope and wish, and get the lens cap (46 pages)
pass Watch quietly, and the door is left open (40 pages)
2 of 2 tests passed
| Option | What it does |
|---|---|
lim test tests/start.limtest | Runs only the tests in that file (or folder) |
--lang en | Prints the results in English |
--json | Outputs the results as JSON |
--github | Also prints failures as GitHub Actions annotations |
If there are no tests at all, it says so and doesn’t fail.
When a test fails
Change expect !game.wished in the second test to expect game.wished and run it, and you get this.
tests/start.limtest
pass Look through the telescope and wish, and get the lens cap (46 pages)
FAIL Watch quietly, and the door is left open (40 pages)
tests/start.limtest:15 expect game.wished is false (game.wished = false)
1 of 2 tests passed
Under a failed test, the line in the test file and what was different are shown: for an expression, the values of the variables; for choose, the choice that wasn’t there; and when it ended before the choice came up, the choose line that wasn’t used.
If even one test fails or there’s a line that can’t be read, the command ends in failure (exit code 1). Runtime errors count as failures even without expect no-errors.
Lines you can write
| Line | Meaning |
|---|---|
# name | The start of a test. The name appears in the results |
from place | Where to start (file or file#label). If left out, the same place as New Game |
from-state file.json | Starts from save data (a path relative to the test file) |
set variable = expression | A value put in a variable before starting (game., system., temp.). It takes priority over the initial value |
seed number | The random seed (1 by default). With the same seed, random numbers come out the same every time |
choose text / choose number | What to pick at a choice |
rest stop / rest first / rest rotate | How to pick once the choose lines are used up. stop (the default) stops at the next choice, first always picks the first one, and rotate picks the next one each time it comes back to the same choice |
limit number | Stops after showing this many pages. If not written, it stops at 5000 pages and fails if it hasn’t ended by then |
expect expression | The expression is true when it’s over |
expect reach place / expect not reach place | It passed (didn’t pass) that place. The place is file, file#label or file:line |
expect text "text" / expect not text "text" | The text appeared (didn’t appear) in the text or name box of some page |
expect ending kind | It ended with an ending of that kind (ending= in @title-screen, such as bad). With text that isn’t a kind, it ended with an ending whose name (title=) contains that text |
expect end | It reached the end of the script or a command that ends the playthrough (such as @title-screen), and didn’t stop because the choices ran out or the page limit was reached |
expect no-errors / expect no-warnings | There were no runtime errors (with no-warnings, no warnings either) |
Start partway through
In a long game, starting from the beginning means writing every choice up to the scene you want to check. Set where to start with from, and put in the values that should be decided by then with set, and you can check from partway through.
# From midnight, having looked through the telescope, make a wish
from start#midnight
set game.looked = true
choose Try making a wish
expect text "lens cap"
expect not reach start#watch
To start from save data, pass a save data file to from-state. The save from the output of lim trace --json, saved to a file, also works.
Find choices that reach a place and turn them into a test
For a scene where the order of choices is complicated, look for choices that reach it with lim reach, and it also prints them as a test. You can paste the lines it prints into a file in tests as is. For how to use it, see “Find the choices that reach an unreached line” in Find gaps with the all-routes test.
Run them in CI
For a project managed on GitHub, you can run the tests on every push and PR. With --github, failures become annotations on the lines of the test file and appear on those lines on the PR’s diff screen. The CI template (templates/ci/liminalia-check.yml) also runs lim test . --github. For how to set up the template, see Check the scenario in CI.
Make a project with lim new --ci, and it gets the CI template and a test in the tests folder. For a blank project (--blank), the test only checks that it plays from New Game to the end.