From 14d25520f3e056b9279c0458e7a1487bc4fb2bea Mon Sep 17 00:00:00 2001 From: jerrrrycho Date: Sun, 8 Nov 2026 11:23:02 +0100 Subject: [PATCH] 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. --- application/application.cpp | 11 +++++++---- tests/scenarios/README.md | 3 ++- utilities/Logs.cpp | 4 ++-- 3 files changed, 11 insertions(+), 7 deletions(-) diff --git a/application/application.cpp b/application/application.cpp index d0ef6a01a..4fe0911ac 100644 --- a/application/application.cpp +++ b/application/application.cpp @@ -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(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(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]" diff --git a/tests/scenarios/README.md b/tests/scenarios/README.md index 006a0fc69..d3f256782 100644 --- a/tests/scenarios/README.md +++ b/tests/scenarios/README.md @@ -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 diff --git a/utilities/Logs.cpp b/utilities/Logs.cpp index 38094d72e..e0949aba6 100644 --- a/utilities/Logs.cpp +++ b/utilities/Logs.cpp @@ -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());