cargo horizon-mod test: server mods' scripts
A test script drives a server mod as a server would: join = "Alex" brings a player in (ids stable per name, so a rejoin is the same player), as = "Steve" picks who acts (the first player on otherwise), and player, chat, command, break and place are that player's doing; leave = "Alex" lets them go. Server expectations: told (every players.tell, "Name: text") and broadcast; feedback and error read the reply to the player who typed the command. Ticks call both kinds of tick hooks, so one script format serves client and server mods. The welcome example gets two scripts (greeting, a newcomer announced once even after a reload, /online across dimensions, /mined per player), run by the sandbox tests with coords-hud's; docs/mods.md lists the server keys. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
+13
-1
@@ -244,7 +244,8 @@ key> --signature <file>.minisig`.
|
||||
`cargo horizon-mod test` builds the mod, then runs each `tests/<name>.toml` in
|
||||
the sandbox the game uses, with no game and no window: the test plays the
|
||||
game's part (the player and the clock the mod reads, ticks, frames, chat lines,
|
||||
commands) and checks what the mod showed. A script fails at its first wrong
|
||||
commands; for a server mod, players joining, chatting, typing commands,
|
||||
breaking and placing blocks and leaving) and checks what the mod showed. A script fails at its first wrong
|
||||
step, with what it expected and what it got; the command fails if any script
|
||||
does. `--debug` builds without optimizing, `--hmod <file>` tests a `.hmod`
|
||||
already built, and a name runs only the scripts whose path holds it. Each
|
||||
@@ -281,6 +282,16 @@ A step's parts happen in this order:
|
||||
| `ticks = n`, `frames = n` | that many ticks (the game's tick counter and the clock move on), then frames 1/60 s apart |
|
||||
| `chat = "<Steve> hi"` | a chat line the player receives |
|
||||
| `command = "where north"` | the player types `/where north`; a command the mod doesn't own fails the step |
|
||||
| `break = { x = 1, y = 63, z = 0, state = "minecraft:stone" }`, `place = { ... }` | server mods: the player breaks or places that block |
|
||||
| `leave = "Alex"` | server mods: that player leaves |
|
||||
|
||||
A server mod starts with nobody on: `join = "Alex"` (after `reload` and `title-screen`) brings a
|
||||
player in at the defaults, in survival, with the id
|
||||
`00000000-0000-4000-8000-000000000001` for the first name that joined, `...2`
|
||||
for the second, the same id when a name joins again. `player`, `chat`,
|
||||
`command`, `break` and `place` are then that player's doing: the one named by
|
||||
`as = "Steve"`, or the first one on. `player` takes `game-mode` there, and the
|
||||
script's own `[player]` and `[clock]` are a client mod's.
|
||||
|
||||
Then `expect` checks what the mod did during the step; a key left out is not
|
||||
checked:
|
||||
@@ -291,6 +302,7 @@ checked:
|
||||
| `chat = ["..."]` | every chat line it showed, in order (`[]`: none) |
|
||||
| `feedback = "..."`, `error = "..."` | the command's answer, shown plain or in red |
|
||||
| `panel = ["..."]`, `corner = "top-left"` | its HUD panel's lines (`[]`: no panel) and corner |
|
||||
| `told = ["Alex: Welcome!"]`, `broadcast = ["..."]` | server mods: every `players.tell` (as `name: text`) and `players.broadcast`, in order |
|
||||
| `stopped = "panic"` | the mod was turned off, for a reason holding this text; without it, a mod that traps, panics or overruns fails the test |
|
||||
|
||||
Unknown keys are errors, so a typo never passes silently. The same runner is
|
||||
|
||||
Reference in New Issue
Block a user