Files
claudeandClaude Opus 5.5 140c2e0866
test / test (push) Successful in 1m11s
Selftest: per-case timeouts so deep-map cases pass on the slow CI runner
Two layer cases timed out in CI (run 19916): the runner needed 49.5 s to
generate the deep test column against a 20 s case limit. Cases can now
set opts.timeout, the deep-map cases use 150 s, the column is one
mapchunk wide, and run.sh allows 420 s overall.

Refs #20

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
2026-11-12 01:26:15 -05:00

54 lines
2.0 KiB
Markdown

# Strata tests
Headless only: the graphical client is never started.
```bash
tests/run.sh [scratch_dir]
```
`run.sh` builds a throwaway world in `scratch_dir` (a fresh `mktemp -d` by
default), exposes this checkout as `games/strata` through
`MINETEST_GAME_PATH`, copies `strata_selftest/` into the world's `worldmods/`
and runs a dedicated server. The selftest emerges a test area, runs every
case, prints one `TEST pass <name>` or `FAIL <name>: <reason>` line per case
and a `TEST summary`, then shuts the server down.
A run passes only with **zero `FAIL` lines, zero `ERROR` lines** in the server
output, a summary line and a clean exit.
| Variable | Default | Purpose |
|---|---|---|
| `LUANTI` | first of `luanti`, `luantiserver`, … on `PATH` (+`/usr/games`) | engine binary |
| `STRATA_TEST_PORT` | `30777` | UDP port, change it to run several at once |
| `STRATA_TEST_TIMEOUT` | `420` | seconds before the run is killed and failed |
| `STRATA_TEST_FILTER` | empty | Lua pattern; only run cases whose name matches |
Lint with `luacheck .` (config in `.luacheckrc`). CI runs both in
`.gitea/workflows/test.yml` on a `debian:trixie` container (Luanti 5.10).
## Writing tests
Add cases to a file in `strata_selftest/tests/` (and list new files in
`strata_selftest/init.lua`):
```lua
selftest.register("area: what it checks", function(t)
t.eq(core.get_node({x = 0, y = 0, z = 0}).name, "strata_core:stone", "node")
t.assert(cond, "message")
end)
-- Async: call t.done() when finished. t.after(sec, f) and t.wrap(f) make
-- callbacks report their errors as a FAIL of this case.
-- A case gets 20 s; pass {async = true, timeout = <seconds>} for slow ones
-- (the CI runner generates map several times slower than a desktop).
selftest.register("area: something over time", function(t)
t.after(1, function()
t.assert(cond, "message")
t.done()
end)
end, {async = true})
```
The area `selftest.AREA_MIN`..`selftest.AREA_MAX` is emerged before the first
case runs, at a fixed seed (`1337`) and noon (`time_speed = 0`).