From 1400b5e21893fca858d9058d2c2b0ce13a091b58 Mon Sep 17 00:00:00 2001 From: maj00r <73280030+maj00r@users.noreply.github.com> Date: Fri, 27 Nov 2026 03:54:13 +0100 Subject: [PATCH 01/11] test(editor): self-test scripts that fail, a runner, and a case for each fix of the track editing (#452) * fix(editor): track edits keep the joints, the norms, the records and the saved speed together - The cant typed in the inspector goes on into the track joined at that end, as the gizmo and the joints tool do it; the neighbours go into the same undo step. The joint stepped before. - A track laid on from a canted joint takes the cant off along the ramp the norms ask for at the speed (`alignment::cant_ramp_length`), not at a fixed 1.5 mm a metre whatever the speed and the norms: 120 mm at 100 km/h over 120 m, not 80 m. - Deleting a track of the line under the route tool keeps the laying norms. They went back to the defaults, and every later lay, extend and join used those. - The gauge is a paste group of its own, off by default: pasting how a track rides or sounds no longer changes its gauge. - The speed of a turntable set in the editor is the one saved. The editor changed the speed the turntable runs at, while the file keeps the limit it was loaded with. - Deleting a set of tracks does what Del does with each: a double switch, a slip and a crossover go whole, the records of the switches go with them, and the model and events of a turntable too. The records stayed behind and on saving were given to another switch, which then showed a wrong type. - Deleting a switch of a crossover takes the crossover out whole, as the connection tools do: the outer track of a crossover on a curve comes down by its lift and the record of the connection goes. Alone, the switch left the outer track up for good, and the connection to the next switch given its name. A switch bent out of the shape of its record is found by its name. Tests: a unit test of the norm ramp. The other changes are in the editor's UI, which the unit tests don't reach. * 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. * test(editor): a mistyped track fails the self-test, indented comments are skipped, case 7b checks the switch got bent - A blank line or an indented `#` comment in a script is no longer a command no group takes. - `trackcant`, `routegauge` and `tracksetdelete` with a track that isn't there count as a failed expectation. - `expect shaped `: 7b checks that the gizmo drag bent the switch out of its record before deleting it. - The ramp-length loop of test_alignment counts in an integer (Sonar S2193). --- CMakeLists.txt | 1 + EU07.cpp | 5 + application/editormode.h | 10 + application/editormodeselftest.cpp | 44 ++- application/editormodeselftest.h | 24 ++ application/editormodeselftestexpect.cpp | 380 +++++++++++++++++++ application/editormodeselftesttrack.cpp | 45 +++ application/editormodetrack.cpp | 49 ++- application/editormodetrackprops.cpp | 25 +- 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 | 21 + tests/editor/run.py | 367 ++++++++++++++++++ tests/editor/scenery/autotest_editor.scn | 376 ++++++++++++++++++ tests/unit/test_alignment.cpp | 3 +- 22 files changed, 1629 insertions(+), 27 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..76173a58c 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,27 @@ 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