From 690c913ef0bfb5a0e1bf81e9f65607e96c5ee5f8 Mon Sep 17 00:00:00 2001 From: maj00r <73280030+maj00r@users.noreply.github.com> Date: Mon, 23 Nov 2026 03:31:57 +0100 Subject: [PATCH] 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. --- CMakeLists.txt | 1 + EU07.cpp | 5 + application/editormode.h | 10 + application/editormodeselftest.cpp | 34 +- application/editormodeselftest.h | 17 + application/editormodeselftestexpect.cpp | 360 ++++++++++++++++++ application/editormodeselftesttrack.cpp | 37 ++ application/editormodetrack.cpp | 49 ++- application/editormodetrackprops.cpp | 17 +- tests/editor/.gitignore | 1 + tests/editor/README.md | 100 +++++ tests/editor/cases/1_inspector_cant.txt | 21 ++ tests/editor/cases/3_norms_after_delete.txt | 19 + tests/editor/cases/4_gauge_paste_group.txt | 23 ++ tests/editor/cases/5_turntable_speed.txt | 16 + tests/editor/cases/6_set_delete_records.txt | 40 ++ tests/editor/cases/6b_set_delete_whole.txt | 42 +++ tests/editor/cases/7_crossover_delete.txt | 44 +++ tests/editor/cases/7b_bent_switch_delete.txt | 18 + tests/editor/run.py | 367 ++++++++++++++++++ tests/editor/scenery/autotest_editor.scn | 376 +++++++++++++++++++ 21 files changed, 1573 insertions(+), 24 deletions(-) create mode 100644 application/editormodeselftestexpect.cpp create mode 100644 tests/editor/.gitignore create mode 100644 tests/editor/README.md create mode 100644 tests/editor/cases/1_inspector_cant.txt create mode 100644 tests/editor/cases/3_norms_after_delete.txt create mode 100644 tests/editor/cases/4_gauge_paste_group.txt create mode 100644 tests/editor/cases/5_turntable_speed.txt create mode 100644 tests/editor/cases/6_set_delete_records.txt create mode 100644 tests/editor/cases/6b_set_delete_whole.txt create mode 100644 tests/editor/cases/7_crossover_delete.txt create mode 100644 tests/editor/cases/7b_bent_switch_delete.txt create mode 100644 tests/editor/run.py create mode 100644 tests/editor/scenery/autotest_editor.scn diff --git a/CMakeLists.txt b/CMakeLists.txt index 294128b87..b2652535a 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -270,6 +270,7 @@ set(SOURCES "application/editormodeselftestterrain.cpp" "application/editormodeselftestrails.cpp" "application/editormodeselftestmonkey.cpp" +"application/editormodeselftestexpect.cpp" "application/scriptedinput.cpp" "input/editormouseinput.cpp" "application/editoruilayer.cpp" diff --git a/EU07.cpp b/EU07.cpp index fa6bb15f2..ccbc1e767 100644 --- a/EU07.cpp +++ b/EU07.cpp @@ -19,6 +19,7 @@ Stele, firleju, szociu, hunter, ZiomalCl, OLI_EU and others #include "stdafx.h" #include "application/application.h" +#include "application/editormodeselftest.h" #include "simulation/simulationtest.h" #include "utilities/Globals.h" #include "utilities/Logs.h" @@ -279,6 +280,10 @@ int main(int argc, char *argv[]) finish_log(); if (initresult < 0) exitcode = 1; + // a self-test script of the editor whose expectations failed ends with a code of its own, for the runner of the scripts; + // without a script there's none + else if (exitcode == 0 && editor_selftest::failures() > 0) + exitcode = editor_selftest::failed_exit_code; } #ifndef _WIN32 fflush(stdout); diff --git a/application/editormode.h b/application/editormode.h index cb852a238..de6bdb7d8 100644 --- a/application/editormode.h +++ b/application/editormode.h @@ -1086,6 +1086,13 @@ class editor_mode : public application_mode, private editor_track::observer, pri std::vector const &track_set() const override; editor_track_tab current_track_tab() const override; void render_path_ui(); + // the cant at an end of a path [mm] from its roll [deg] and back, as the inspector shows and takes it: over 1500 mm between the + // rail axes + static float cant_of_roll(float const Roll); + static float roll_of_cant(float const Cant); + // the cant of the track changed goes on into the tracks joined at its ends, as with the gizmo and the joints tool: the joints would + // step otherwise. The track, whose state before the change is Before, and its neighbours go into one undo step + void track_cant_commit(TTrack &Track, editor_track::state const &Before); void draw_track_overlay() const; editor_track::point_ref track_handle_hit() const; void select_track(scene::basic_node *Node); @@ -3143,6 +3150,7 @@ class editor_mode : public application_mode, private editor_track::observer, pri scripted_input input; std::string badge; // the mouse or the keys drawn over the view, for the clips of the tutorial glm::vec2 badge_at{0.0f}; // its bottom left corner, in the pixels of the window + std::map marks; // the heights of the ends of tracks kept by mark, for expect lift }; selftest m_selftest; using selftest_result = editor_selftest_result; @@ -3157,6 +3165,8 @@ class editor_mode : public application_mode, private editor_track::observer, pri selftest_result selftest_terrain(std::string const &command, std::istringstream &words); selftest_result selftest_props(std::string const &command, std::istringstream &words); selftest_result selftest_monkey(std::string const &command, std::istringstream &words); + // the expectations of the script, which make the run fail (editormodeselftestexpect.cpp) + selftest_result selftest_expect(std::string const &command, std::istringstream &words); selftest_result selftest_dispatch(std::string const &command, std::istringstream &words); void selftest_step(); // a value typed during a gesture, taken instead of the one the cursor gives diff --git a/application/editormodeselftest.cpp b/application/editormodeselftest.cpp index f81b73f3a..8bc62f626 100644 --- a/application/editormodeselftest.cpp +++ b/application/editormodeselftest.cpp @@ -53,7 +53,7 @@ http://mozilla.org/MPL/2.0/. editor_mode::selftest_result editor_mode::selftest_dispatch(std::string const &command, std::istringstream &words) { - for (auto const group : {&editor_mode::selftest_scene, &editor_mode::selftest_sleepers, &editor_mode::selftest_sweep, &editor_mode::selftest_track, &editor_mode::selftest_switch, &editor_mode::selftest_rails, &editor_mode::selftest_join, &editor_mode::selftest_signal, &editor_mode::selftest_terrain, &editor_mode::selftest_props, &editor_mode::selftest_monkey}) + for (auto const group : {&editor_mode::selftest_scene, &editor_mode::selftest_sleepers, &editor_mode::selftest_sweep, &editor_mode::selftest_track, &editor_mode::selftest_switch, &editor_mode::selftest_rails, &editor_mode::selftest_join, &editor_mode::selftest_signal, &editor_mode::selftest_terrain, &editor_mode::selftest_props, &editor_mode::selftest_monkey, &editor_mode::selftest_expect}) if (auto const result{(this->*group)(command, words)}; result != selftest_result::unhandled) return result; for (auto *tool : m_tools) @@ -208,7 +208,26 @@ editor_mode::selftest_result editor_mode::selftest_dispatch(std::string const &c // rideahead, rideprobe, rideleave logs the switch ahead from its blades / logs the place of the ride / ends the ride // minimap <0|1|2>, stations the minimap shown or hidden (2: the whole scenery in it) / logs the stations the W4 name with their stops // station , minimapclick the camera to the next stop of the station whose name holds the text / as a click on the map there -// quit +// trackcant the cant typed into the field of the inspector: the tracks joined at the ends follow, +// in the same undo step +// routegauge [track] the rail axes distance of the norms set as the route tool sets it, the line of the track opened in +// it first unless it's open already +// tracksetdelete ... the tracks made the set, one too, and deleted as Del deletes the set +// mark