From ae8ca6120fd1e0a763319f5a73c5dbb2459c651b Mon Sep 17 00:00:00 2001 From: Anthony Nicholls Date: Wed, 2 Jul 2025 14:34:20 +0100 Subject: [PATCH] UnitTestRunner: Include failure messages in failure summary --- extras/UnitTestRunner/Source/Main.cpp | 32 ++++++++++++++++++--------- 1 file changed, 21 insertions(+), 11 deletions(-) diff --git a/extras/UnitTestRunner/Source/Main.cpp b/extras/UnitTestRunner/Source/Main.cpp index c48f7b6fac..f6a8831c92 100644 --- a/extras/UnitTestRunner/Source/Main.cpp +++ b/extras/UnitTestRunner/Source/Main.cpp @@ -91,9 +91,15 @@ int main (int argc, char **argv) ConsoleLogger logger; Logger::setCurrentLogger (&logger); + const ScopeGuard onExit { [&] + { + Logger::setCurrentLogger (nullptr); + DeletedAtShutdown::deleteAll(); + }}; + ConsoleUnitTestRunner runner; - auto seed = [&args] + const auto seed = std::invoke ([&] { if (args.containsOption (seedOption)) { @@ -106,7 +112,7 @@ int main (int argc, char **argv) } return Random::getSystemRandom().nextInt64(); - }(); + }); if (args.containsOption (categoryOption)) runner.runTestsInCategory (args.getValueForOption (categoryOption), seed); @@ -122,24 +128,28 @@ int main (int argc, char **argv) auto* result = runner.getResult (i); if (result->failures > 0) - failures.push_back (result->unitTestName + " / " + result->subcategoryName + ": " + String (result->failures) + " test failure" + (result->failures > 1 ? "s" : "")); + { + const auto testName = result->unitTestName + " / " + result->subcategoryName; + const auto testSummary = String (result->failures) + " test failure" + (result->failures > 1 ? "s" : ""); + const auto newLineAndTab = newLine + "\t"; + + failures.push_back (testName + ": " + testSummary + newLineAndTab + + result->messages.joinIntoString (newLineAndTab)); + } } + logger.writeToLog (newLine + String::repeatedString ("-", 65)); + if (! failures.empty()) { - logger.writeToLog (newLine + "Test failure summary:" + newLine); + logger.writeToLog ("Test failure summary:"); for (const auto& failure : failures) - logger.writeToLog (failure); + logger.writeToLog (newLine + failure); - Logger::setCurrentLogger (nullptr); return 1; } - logger.writeToLog (newLine + "All tests completed successfully"); - Logger::setCurrentLogger (nullptr); - - DeletedAtShutdown::deleteAll(); - + logger.writeToLog ("All tests completed successfully"); return 0; }