18
0
mirror of https://github.com/MaSzyna-EU07/maszyna.git synced 2026-11-18 22:16:02 +01:00

fix(simulation): any exception ends a test run with error, other runs as on master

main() tells a test run (--test) apart before anything runs. Only a test run
catches every exception and installs a std::terminate handler, both ending the
run with the error code and a test: line; any other run keeps master's
exception handling, so on Linux an uncaught runtime_error aborts at the throw
site again.

A test run doesn't start the Discord RPC thread: it published the test
scenery as the player's presence and held the closing up to 5 s.

run.py drops a case scenery's .sbt cache after a run cut short (wall_timeout,
error, a crash, killed by run.py), which could have been writing it.

The -edit branch of the test command line parser had no effect (a token that
isn't an option is ignored either way) and is gone; its test checks what can
be seen instead.
This commit is contained in:
jerrrrycho
2026-11-08 19:46:16 +01:00
parent cea92f0170
commit 8fb596f218
7 changed files with 125 additions and 41 deletions

View File

@@ -4,6 +4,9 @@
#include "simulation/simulationtestrules.h"
#include <array>
#include <exception>
#include <new>
#include <stdexcept>
#include <vector>
// the test mode of the simulator (eu07 --test, eu07/maszyna#541): its exit codes, command line and end conditions
@@ -117,10 +120,13 @@ TEST_CASE("test mode: the command line")
CHECK_FALSE(commandline.enabled);
CHECK(commandline.error.empty());
}
SUBCASE("the scenery of -edit is optional")
SUBCASE("-edit takes no option for its scenery, which is optional")
{
// a scenery after -edit or none: the option after it is read either way
CHECK(parse({"-edit", "--test", "-s", "td.scn"}).enabled);
CHECK_FALSE(parse({"-edit", "td.scn"}).enabled);
CHECK(parse({"-edit", "td.scn", "--test"}).enabled);
// -edit leaves -s alone, which takes --test for its scenery, as the simulator reads it
CHECK_FALSE(parse({"-edit", "-s", "--test"}).enabled);
}
}
@@ -241,3 +247,22 @@ TEST_CASE("test mode: the end conditions")
CHECK(verdict->result == test_result::fail);
}
}
TEST_CASE("test mode: what ended a run the simulator didn't end")
{
SUBCASE("an exception says what it was")
{
CHECK(simulation::describe_exception(std::make_exception_ptr(std::runtime_error("no scenery"))) == "critical error: no scenery");
// e.g. std::stof on a token of a scenery which isn't a number
CHECK(simulation::describe_exception(std::make_exception_ptr(std::invalid_argument("stof"))) == "critical error: stof");
CHECK(simulation::describe_exception(std::make_exception_ptr(std::bad_alloc())).starts_with("critical error: "));
}
SUBCASE("something thrown which isn't a std::exception")
{
CHECK(simulation::describe_exception(std::make_exception_ptr(42)) == "critical error: an exception of unknown type");
}
SUBCASE("terminated without an exception")
{
CHECK(simulation::describe_exception(nullptr) == "the simulator was terminated");
}
}