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 (#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 <switch> <yes|no>`: 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).
This commit is contained in:
@@ -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 <text>, minimapclick <x> <z> the camera to the next stop of the station whose name holds the text / as a click on the map there
|
||||
// quit
|
||||
// trackcant <track> <path> <start mm> <end mm> the cant typed into the field of the inspector: the tracks joined at the ends follow,
|
||||
// in the same undo step
|
||||
// routegauge <mm> [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 <name>... the tracks made the set, one too, and deleted as Del deletes the set
|
||||
// mark <label> <track> <start|end> the height of the end of the first path kept, for expect lift
|
||||
// expect cant <track> <start|end> <mm> <tolerance mm> the cant at the end of the first path, as the inspector shows it
|
||||
// expect joint <track> <start|end> <gap m> <angle deg> <cant step mm> the end of the first path against the end of another track
|
||||
// nearest to it within 1 m: the gap, the kink and the step of the cant between them, each at most
|
||||
// expect records <name> <count> [kind] the records of the switch store of the name, with the connections having the switch among theirs
|
||||
// expect shaped <switch> <yes|no> the switch keeps the shape its record says, or was bent out of it
|
||||
// expect speed <track> <km/h> [tolerance], expect gauge <track> <m> [tolerance] as editor_track::velocity gives it / the gauge
|
||||
// expect track <name> <present|removed>
|
||||
// expect route <track> <in|out> the track is a part of the line open in the route tool, or not
|
||||
// expect norms gauge <mm> [tolerance] the rail axes distance of the norms the tracks are laid to
|
||||
// expect height <track> <start|end> <m> <tolerance> the height of the end of the first path
|
||||
// expect lift <track> <start|end> <label> <m> <tolerance> how far the end of the first path is above the height marked
|
||||
// expect includes <track> <count> the includes whose parameters name the track: the model and the events of a turntable
|
||||
// each expect logs SELFTEST PASS or SELFTEST FAIL; a failed one, or a command no group takes,
|
||||
// makes the run end with editor_selftest::failed_exit_code
|
||||
// quit logs SELFTEST result: <failed> failed of <expectations>, the editor closes
|
||||
void editor_mode::selftest_step()
|
||||
{
|
||||
auto &test{m_selftest};
|
||||
@@ -221,8 +241,13 @@ void editor_mode::selftest_step()
|
||||
std::ifstream stream(file);
|
||||
std::string line;
|
||||
while (std::getline(stream, line))
|
||||
if (false == line.empty() && line.front() != '#')
|
||||
test.lines.push_back(line);
|
||||
{
|
||||
// an indented comment or a line of blanks is no command either
|
||||
auto const first{line.find_first_not_of(" \t\r")};
|
||||
if (first == std::string::npos || line[first] == '#')
|
||||
continue;
|
||||
test.lines.push_back(line.substr(first));
|
||||
}
|
||||
WriteLog("SELFTEST: " + std::to_string(test.lines.size()) + " steps from " + file);
|
||||
}
|
||||
++editor_selftest::frames();
|
||||
@@ -262,7 +287,8 @@ void editor_mode::selftest_step()
|
||||
words >> test.wait;
|
||||
return;
|
||||
}
|
||||
if (auto const result{selftest_dispatch(command, words)}; result == selftest_result::pause || result == selftest_result::again)
|
||||
auto const result{selftest_dispatch(command, words)};
|
||||
if (result == selftest_result::pause || result == selftest_result::again)
|
||||
{
|
||||
if (result == selftest_result::again)
|
||||
--test.next;
|
||||
@@ -272,6 +298,7 @@ void editor_mode::selftest_step()
|
||||
{
|
||||
if (false == test.quitting)
|
||||
{
|
||||
WriteLog(format("SELFTEST result: %zu failed of %zu", editor_selftest::failures(), editor_selftest::expectations()));
|
||||
WriteLog("SELFTEST done");
|
||||
test.quitting = true;
|
||||
test.wait = 30;
|
||||
@@ -281,5 +308,12 @@ void editor_mode::selftest_step()
|
||||
Application.queue_quit(true);
|
||||
return;
|
||||
}
|
||||
// a command no group took does nothing: a script mistyped, whose expectations after it would pass for nothing
|
||||
if (result == selftest_result::unhandled)
|
||||
{
|
||||
++editor_selftest::expectations();
|
||||
++editor_selftest::failures();
|
||||
WriteLog("SELFTEST FAIL " + command + ": no group took the command");
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user