termtris tests: six Lua harnesses are ~95% the same file (de-duplicate) #6

Closed
opened 2026-11-13 08:51:13 +02:00 by opencode.siil.arti.ee · 0 comments
Collaborator

The six termtris test drivers are near-identical copies of the loader harness, and a change to the shared machinery has to be made six times.

Evidence (head 58f8f44)

file lines
apps/termtris/tests/smoke.lua 355
apps/termtris/tests/fmt.lua 354
apps/termtris/tests/render.lua 347
apps/termtris/tests/input.lua 387
apps/termtris/tests/play.lua 350
apps/termtris/tests/play_keys.lua 390
total 2183

Each copy shares almost everything:

  • all six diverge from smoke.lua at line 28 (the ports/keys block) and reconverge;
  • compared with smoke.lua, every other file has only 7-46 unique lines (only 11-16 of smoke.lua's own lines are unique against any one of them);
  • the COFF poking, descriptor setup, create_process entry, result polling and exit logic is copied verbatim from dwt/loader/loader.lua (338 lines);
  • the copies still carry the header -- loader.lua -- debugger-assisted COFF loader acceptance harness., even though each now has test-specific hooks at the bottom.

play.lua has already diverged in its result format (DIAG: tick=... quit=...) from play_keys.lua (DIAG: loops=... events=... last=... focus=... rev=... quit=...), which is the first symptom of six independent copies.

Proposal

Extract the shared loader/COFF/debugger machinery into one module, e.g. apps/termtris/tests/harness.lua, and make each test a thin configuration + hooks file:

  • configuration: LOADER_AT, LOADER_END, snapshot flag, ports/keys it needs;
  • hooks: on_frame(frames), result_dump(), on_done(status);
  • shared code: COFF parsing, loader placement, create_process, status polling, snapshot, exit.

Keep every tests/*.sh and its environment contract unchanged. dwt/loader/loader.lua can stay as the reference for the general loader milestones; the termtris tests should not fork it.

Acceptance

  • apps/termtris/verify.sh --skip-mame still reports verify: PASS with the same DIAG values and regenerated evidence.
  • The six test files lose roughly 1800 lines; the shared part exists once.
  • At minimum, the result output is one format shared by play.lua and play_keys.lua.

This is a follow-up to PR #5, not a blocker for it.

The six termtris test drivers are near-identical copies of the loader harness, and a change to the shared machinery has to be made six times. ## Evidence (head `58f8f44`) | file | lines | |---|---:| | `apps/termtris/tests/smoke.lua` | 355 | | `apps/termtris/tests/fmt.lua` | 354 | | `apps/termtris/tests/render.lua` | 347 | | `apps/termtris/tests/input.lua` | 387 | | `apps/termtris/tests/play.lua` | 350 | | `apps/termtris/tests/play_keys.lua` | 390 | | **total** | **2183** | Each copy shares almost everything: - all six diverge from `smoke.lua` at line 28 (the ports/keys block) and reconverge; - compared with `smoke.lua`, every other file has only **7-46 unique lines** (only 11-16 of `smoke.lua`'s own lines are unique against any one of them); - the COFF poking, descriptor setup, `create_process` entry, result polling and exit logic is copied verbatim from `dwt/loader/loader.lua` (338 lines); - the copies still carry the header `-- loader.lua -- debugger-assisted COFF loader acceptance harness.`, even though each now has test-specific hooks at the bottom. `play.lua` has already diverged in its result format (`DIAG: tick=... quit=...`) from `play_keys.lua` (`DIAG: loops=... events=... last=... focus=... rev=... quit=...`), which is the first symptom of six independent copies. ## Proposal Extract the shared loader/COFF/debugger machinery into one module, e.g. `apps/termtris/tests/harness.lua`, and make each test a thin configuration + hooks file: - configuration: `LOADER_AT`, `LOADER_END`, snapshot flag, ports/keys it needs; - hooks: `on_frame(frames)`, `result_dump()`, `on_done(status)`; - shared code: COFF parsing, loader placement, `create_process`, status polling, snapshot, exit. Keep every `tests/*.sh` and its environment contract unchanged. `dwt/loader/loader.lua` can stay as the reference for the general loader milestones; the termtris tests should not fork it. ## Acceptance - `apps/termtris/verify.sh --skip-mame` still reports `verify: PASS` with the same DIAG values and regenerated evidence. - The six test files lose roughly 1800 lines; the shared part exists once. - At minimum, the result output is one format shared by `play.lua` and `play_keys.lua`. This is a follow-up to PR #5, not a blocker for it.
arti closed this issue 2026-11-13 11:56:51 +02:00
Sign in to join this conversation.
No labels
1 Participants
Notifications
Due Date
No due date set.
Dependencies

No dependencies set.

Reference: arti/vt1200#6