plum
git clone https://git.pyrossh.dev/plum
A statically typed, imperative programming language inspired by rust, python
da625ef
— Peter John
2026-11-11T00:26:36+05:30
replay test: a failed check keeps its recording and says where
- compiler/cli/src/replay.rs +51 -6
compiler/cli/src/replay.rs
CHANGED
|
@@ -86,24 +86,69 @@ mod tests {
|
|
|
86
86
|
(g.recording(), g.backend().calls.clone())
|
|
87
87
|
}
|
|
88
88
|
|
|
89
|
+
/// Writes `text` (a recording that made a check fail) where it outlives the test run, and
|
|
90
|
+
/// returns what to say about it: its seed line and how to replay it. The seed is the
|
|
91
|
+
/// clock's, so without this a failure that depends on it can't be run again.
|
|
92
|
+
fn keepRecording(name: &str, text: &str) -> String {
|
|
93
|
+
let header = text.lines().next().unwrap_or("").to_string();
|
|
94
|
+
let dir = plum_core::loader::builtRepoRoot().join("target/replay-failures");
|
|
95
|
+
let file = dir.join(format!("{}-{}.txt", name.replace(['/', '.'], "_"), header.replace(' ', "_")));
|
|
96
|
+
let kept = std::fs::create_dir_all(&dir).and_then(|_| std::fs::write(&file, text));
|
|
97
|
+
match kept {
|
|
98
|
+
Ok(()) => format!("recording `{header}` kept at {} (`plum run examples/games/{name} --replay` it)", file.display()),
|
|
99
|
+
Err(e) => format!("recording `{header}` (not kept: {e})"),
|
|
100
|
+
}
|
|
101
|
+
}
|
|
102
|
+
|
|
103
|
+
/// The first draw call where `a` and `b` differ, for a failure message.
|
|
104
|
+
fn firstDifference(a: &[String], b: &[String]) -> String {
|
|
105
|
+
match a.iter().zip(b).position(|(x, y)| x != y) {
|
|
106
|
+
Some(i) => format!("call {i}: `{}` vs `{}`", a[i], b[i]),
|
|
107
|
+
None => format!("{} calls vs {}", a.len(), b.len()),
|
|
108
|
+
}
|
|
109
|
+
}
|
|
110
|
+
|
|
111
|
+
/// A recorded run of each game replays to the same last frame, and its input mattered. Its
|
|
112
|
+
/// seed is the clock's: a failure keeps the recording (`keepRecording`) and says where.
|
|
89
113
|
#[test]
|
|
90
114
|
fn eachExampleGameReplaysARecordedRun() {
|
|
91
115
|
for name in ["orb_run.plum", "kids/balloon_pop.plum"] {
|
|
92
116
|
let (wasm, assets) = exampleWasm(name);
|
|
93
117
|
let (text, recorded) = record(&wasm, &assets, 600);
|
|
94
|
-
let (ticks, replayed) = runReplay(&wasm, assets.clone(), &text)
|
|
118
|
+
let (ticks, replayed) = match runReplay(&wasm, assets.clone(), &text) {
|
|
119
|
+
Ok(r) => r,
|
|
120
|
+
Err(e) => panic!("{name}: the replay failed: {e:#}; {}", keepRecording(name, &text)),
|
|
121
|
+
};
|
|
95
|
-
assert!((590..=610).contains(&ticks), "{name}: {ticks} ticks");
|
|
122
|
+
assert!((590..=610).contains(&ticks), "{name}: {ticks} ticks; {}", keepRecording(name, &text));
|
|
96
|
-
assert!(!recorded.is_empty(), "{name}");
|
|
123
|
+
assert!(!recorded.is_empty(), "{name}: nothing drawn; {}", keepRecording(name, &text));
|
|
124
|
+
if replayed != recorded {
|
|
97
|
-
|
|
125
|
+
panic!("{name}: the replay ends somewhere else ({}); {}", firstDifference(&replayed, &recorded), keepRecording(name, &text));
|
|
126
|
+
}
|
|
98
127
|
|
|
99
128
|
// The input mattered: the same seed with no input ends elsewhere.
|
|
100
129
|
let header = text.lines().next().unwrap();
|
|
101
130
|
let idle = format!("{header}\n{}", "- 0 0 0 0\n".repeat(ticks));
|
|
102
|
-
let
|
|
131
|
+
let still = match runReplay(&wasm, assets, &idle) {
|
|
132
|
+
Ok((_, still)) => still,
|
|
133
|
+
Err(e) => panic!("{name}: the idle replay failed: {e:#}; {}", keepRecording(name, &text)),
|
|
134
|
+
};
|
|
103
|
-
|
|
135
|
+
assert!(still != recorded, "{name}: the scripted input changed nothing; {}", keepRecording(name, &text));
|
|
104
136
|
}
|
|
105
137
|
}
|
|
106
138
|
|
|
139
|
+
/// A failing check of `eachExampleGameReplaysARecordedRun` leaves its recording behind,
|
|
140
|
+
/// named by game and seed, with the seed line in the message.
|
|
141
|
+
#[test]
|
|
142
|
+
fn aFailedReplayCheckKeepsItsRecording() {
|
|
143
|
+
let text = "plum-replay 1 7 9 800 600\n- 0 0 0 0\n";
|
|
144
|
+
let said = keepRecording("kids/test_only.plum", text);
|
|
145
|
+
let file = plum_core::loader::builtRepoRoot().join("target/replay-failures/kids_test_only_plum-plum-replay_1_7_9_800_600.txt");
|
|
146
|
+
assert!(said.contains("plum-replay 1 7 9 800 600") && said.contains(&file.display().to_string()), "{said}");
|
|
147
|
+
assert_eq!(std::fs::read_to_string(&file).unwrap(), text);
|
|
148
|
+
std::fs::remove_file(&file).unwrap();
|
|
149
|
+
assert_eq!(firstDifference(&["a".into(), "b".into()], &["a".into(), "c".into()]), "call 1: `b` vs `c`");
|
|
150
|
+
}
|
|
151
|
+
|
|
107
152
|
#[test]
|
|
108
153
|
fn theReplayedSeedIsTheRecordedOne() {
|
|
109
154
|
let (wasm, assets) = exampleWasm("orb_run.plum");
|