18
0
mirror of https://github.com/MaSzyna-EU07/maszyna.git synced 2026-12-02 13:06:46 +01:00

test(editor): self-test scripts that fail, a runner, and a case for each fix of the track editing

The editor's self-test scripts only logged: nothing made a run fail. Now:

- `expect` commands check the state and log `SELFTEST PASS` or `SELFTEST FAIL ... got X, expected Y`:
  the cant at a track end, the joint at an end (gap, angle, cant step), the records of a switch and
  the connections naming it, speed, gauge, a track present or removed, the laying norms' gauge,
  heights and lifts against a mark, whether a track is in the line under the route tool, and the
  includes of a turntable. A command no group takes counts as a failure, so a mistyped one can't
  make the checks after it pass.
- At `quit` the result is logged, and a script whose expectations failed ends the editor with exit
  code 2 (a failed start stays 1; the simulator's test mode is unchanged).
- The commit of the inspector's cant field is `track_cant_commit`, which the inspector and the
  `trackcant` command both call; `routegauge` sets the laying norms as the route tool does, and
  `tracksetdelete` deletes a set of tracks by name.
- `tests/editor/run.py` runs each script of `tests/editor/cases` on a copy of the fixture scenery
  in the game folder, with a wall-time limit and a memory cap, reads the exit code and the
  `SELFTEST` lines, and deletes the copy. A `#> reopen` line restarts the editor on the saved
  scenery. See `tests/editor/README.md`.
- One case per fix of the track editing quick fixes (inspector cant, norms after deleting, the
  gauge paste group, turntable speed saved, deleting a set, a set with a double switch, a slip
  and a crossover, deleting a switch of a crossover, a bent switch). All pass; with the fixes
  reverted all fail.
This commit is contained in:
maj00r
2026-11-23 03:31:57 +01:00
parent c813c03865
commit 690c913ef0
21 changed files with 1573 additions and 24 deletions
+16 -1
View File
@@ -2093,6 +2093,21 @@ editor_mode::selftest_result editor_mode::selftest_props(std::string const &Comm
WriteLog(format("SELFTEST tracksel: %zu tracks selected", selected_tracks().size()));
return selftest_result::handled;
}
if (Command == "tracksetdelete")
{
// the set made of the tracks, also of one, and the last of them selected, as the set stays the selection only with it
m_track_set.clear();
for (std::string name; Words >> name;)
if (auto *track{simulation::Paths.find(name)}; track != nullptr && false == track->m_editorremoved)
m_track_set.push_back(track);
m_node = m_track_set.empty() ? nullptr : m_track_set.back();
m_track_point = {};
ui()->set_node(m_node);
auto const count{m_track_set.size()};
track_set_delete();
WriteLog(format("SELFTEST tracksetdelete: %zu tracks in the set", count));
return selftest_result::handled;
}
if (Command == "trackprop")
{
std::string key;
@@ -2140,7 +2155,7 @@ editor_mode::selftest_result editor_mode::selftest_props(std::string const &Comm
}
else if (action == "groups")
{
// the groups ticked, as their numbers: 0 speed ... 9 frogs, 10 sleeper placement
// the groups ticked, as their numbers: 0 speed ... 9 frogs, 10 sleeper placement, 11 gauge
m_track_style.groups.fill(false);
m_track_style.ticks.clear();
for (int group; Words >> group;)