18
0
mirror of https://github.com/MaSzyna-EU07/maszyna.git synced 2026-11-18 23:26:03 +01:00

fix(simulation): a test's standard output carries its result only

The log was printed in colour to stdout too (debuglog bit 2), so a script reading
the verdict of a test got the whole log with it. In test mode the log goes to the
log file only and stdout has the `test: ...` line alone; the usage text of a bad
command line goes to stderr. Whether the run is a test is now known before the
log service starts.
This commit is contained in:
jerrrrycho
2026-11-08 11:23:02 +01:00
parent 1626df2bc4
commit 14d25520f3
3 changed files with 11 additions and 7 deletions

View File

@@ -322,6 +322,9 @@ int eu07_application::init(int Argc, char *Argv[])
{
int result{0};
// a test run is known before anything is logged: whoever started it reads its result on the standard output,
// which the log isn't written to then (eu07/maszyna#541)
Global.test.enabled = simulation::parse_test_command_line(std::vector<char const *>(Argv, Argv + Argc)).enabled;
// start logging service
std::thread sLoggingService(LogService);
Global.threads.emplace("LogService", std::move(sLoggingService));
@@ -1150,10 +1153,9 @@ int eu07_application::init_settings(int Argc, char *Argv[])
{
Global.asVersion = VERSION_INFO;
// a test run is known before the rest of the command line is read, so a command line it can't take
// ends with the error code of the test, not with 0, which would pass it
// a test run is known before the rest of the command line is read (Global.test.enabled, see init()), so a
// command line it can't take ends with the error code of the test, not with 0, which would pass it
auto const testcommandline{simulation::parse_test_command_line(std::vector<char const *>(Argv, Argv + Argc))};
Global.test.enabled = testcommandline.enabled;
if (false == testcommandline.error.empty())
{
simulation::test().conclude(simulation::test_result::error, testcommandline.error);
@@ -1245,7 +1247,8 @@ int eu07_application::init_settings(int Argc, char *Argv[])
}
else
{
std::cout << "usage: " << std::string(Argv[0]) << " [-s sceneryfilepath]"
// a test's standard output carries its result only
(Global.test.enabled ? std::cerr : std::cout) << "usage: " << std::string(Argv[0]) << " [-s sceneryfilepath]"
<< " [-v vehiclename]"
<< " [-edit [sceneryfilepath]]"
<< " [-seed number|word]"

View File

@@ -40,7 +40,8 @@ With `--test` the simulator:
runs of a scenery come out the same (the physicslogs of two runs are byte for byte equal),
- quits when the test ends, and says how it ended in the exit code and in a `test: ...`
line on stdout and in the log. A command line it can't take, or a start that fails, ends
the same way with the `error` code.
the same way with the `error` code. That line is all there is on stdout: the log goes to
the log file only (`debuglog` doesn't print it on the console in test mode).
On Windows the simulator is a windowed program, which the `cmd` prompt and PowerShell don't wait
for. In a `.bat` file `eu07 --test ... > result.txt` waits and sets `%errorlevel%`; at the prompt

View File

@@ -125,8 +125,8 @@ void LogService()
if (log_scrollback.size() > 200)
log_scrollback.pop_front();
// log to console
if (Global.iWriteLogEnabled & 2)
// log to console; not in test mode, where the standard output carries the result of the test only
if ((Global.iWriteLogEnabled & 2) && false == Global.test.enabled)
{
if (isError)
printf("\033[1;37;41m%s\033[0m\n", msg.c_str());