mirror of
https://github.com/MaSzyna-EU07/maszyna.git
synced 2026-12-02 20:05:23 +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:
@@ -399,6 +399,43 @@ editor_mode::selftest_result editor_mode::selftest_track(std::string const &comm
|
||||
WriteLog("SELFTEST " + command + ": " + m_route.status + " " + m_route.error);
|
||||
return selftest_result::handled;
|
||||
}
|
||||
if (command == "routegauge")
|
||||
{
|
||||
double gauge{1500.0};
|
||||
std::string name;
|
||||
words >> gauge >> name;
|
||||
// the line of the track opened in the route tool, as a click on it with the tool does, unless it's in the line open already
|
||||
if (auto *track{simulation::Paths.find(name)}; track != nullptr && false == track->m_editorremoved && std::ranges::find(m_route.chain.tracks, track) == m_route.chain.tracks.end())
|
||||
{
|
||||
m_track_tab = track_tab::route;
|
||||
m_route.single = false;
|
||||
route_load(*track);
|
||||
}
|
||||
// as the field of the rail axes distance among the norms of the route tool sets it
|
||||
m_route.design.norms.gauge = std::max(100.0, gauge);
|
||||
WriteLog(format("SELFTEST routegauge: %.0f mm, the line of %zu paths open", m_route.design.norms.gauge, m_route.chain.tracks.size()));
|
||||
return selftest_result::handled;
|
||||
}
|
||||
if (command == "trackcant")
|
||||
{
|
||||
std::string name;
|
||||
int index{0};
|
||||
std::array<float, 2> cants{0.0f, 0.0f};
|
||||
words >> name >> index >> cants[0] >> cants[1];
|
||||
auto *track{simulation::Paths.find(name)};
|
||||
std::string reason;
|
||||
if (track == nullptr || track->m_editorremoved || index < 0 || index >= static_cast<int>(track->m_paths.size()) || false == editor_track::can_edit_geometry(*track, reason))
|
||||
{
|
||||
WriteLog("SELFTEST trackcant: no path " + name + " " + std::to_string(index) + " to edit " + reason);
|
||||
return selftest_result::handled;
|
||||
}
|
||||
// as the field of the inspector takes it: the rolls of the path set, then the edit committed with the track as it was before
|
||||
auto const before{editor_track::capture(*track)};
|
||||
track->m_paths[index].rolls = {roll_of_cant(cants[0]), roll_of_cant(cants[1])};
|
||||
track_cant_commit(*track, before);
|
||||
WriteLog(format("SELFTEST trackcant %s %d: %.1f %.1f mm", name.c_str(), index, cant_of_roll(track->m_paths[index].rolls[0]), cant_of_roll(track->m_paths[index].rolls[1])));
|
||||
return selftest_result::handled;
|
||||
}
|
||||
if (command == "digitizescenery")
|
||||
{
|
||||
// "digitizescenery write" digitizes, without the word only counts what it would do
|
||||
|
||||
Reference in New Issue
Block a user