Skip to main content

Module harness

Module harness 

Source
Expand description

A headless test driver for any game on the engine (game ADR-0007 layer 4): scripted key and controller-button presses and waits in, in frames of 1/60 s or by a tick stage’s fixed steps (Harness::steps), screen names, snapshots and the audio asked for out. No window, no clock, no sound card: it runs the game in an App on the HeadlessPlatform, through the same frame the devices run, and the headless backend’s Speaker says what music sounds, so a screen that keeps time with the music is tested too.

A game wraps it with its own start-up and lookups (its flow, its battle); the scripts are the same for every game. With the harness feature.

use shuyi_platform::harness::Harness;
use shuyi_ui::toy;

let mut h = Harness::new(toy::game());
h.keys("f");
assert_eq!(h.screens(), ["home", "menu"]);
h.keys("f");
assert_eq!(h.sounds(), ["click"]);

Harness::new takes a game already running. Harness::start runs it from its real Start, card and load first, as a device does; Harness::start_recording records that run (session), and Harness::from_session plays such a record to any frame (play_to).

Re-exports§

pub use crate::script::FRAME_DT;

Structs§

Harness
Drives a Game with simulated key presses and time, as the platform would: in an App, on the HeadlessPlatform.

Constants§

MAX_FRAMES
Most frames one Harness::hold or Harness::wait may run (about half a simulated minute), so a runaway script fails instead of hanging.
MAX_WAIT
The longest wait of one step of a Script the Harness plays, in seconds: MAX_FRAMES frames.

Functions§

assert_session
A test that the session record at path plays from start with no difference (check_session). With the environment variable SHUYI_BLESS=1 it writes the file again instead (bless_session).
bless_session
The session record in text made again from start: every frame played, differences and all, and recorded. The same inputs, this build’s stamp and hashes. The error says why it can’t be played, or that this build reads the platform differently, so its inputs are no longer the record’s.
check_session
Plays the session record in text from start, stamps checked, to its end (Harness::from_session). The error says why it can’t be played, or names the first frame that played differently.