From fb59c35d687015bf03fa2b795138fc124d20ce82 Mon Sep 17 00:00:00 2001 From: Alexander Yee Date: Sun, 26 Jul 2026 12:51:39 -0700 Subject: [PATCH 1/3] Inject new unit tests into existing commandline test infra. --- SerialPrograms/Source/ComputerPrograms/UnitTestRunner.h | 3 +++ SerialPrograms/Source/Tests/CommandLineTests.cpp | 9 ++++++++- 2 files changed, 11 insertions(+), 1 deletion(-) diff --git a/SerialPrograms/Source/ComputerPrograms/UnitTestRunner.h b/SerialPrograms/Source/ComputerPrograms/UnitTestRunner.h index 8c7a656a6d..1135c66f57 100644 --- a/SerialPrograms/Source/ComputerPrograms/UnitTestRunner.h +++ b/SerialPrograms/Source/ComputerPrograms/UnitTestRunner.h @@ -79,11 +79,14 @@ class CommandLineUnitTestRunner : public PokemonAutomation::UnitTestRunner::List void run(); + +private: virtual void on_test_finished( std::shared_ptr test, UnitTestResult result ) override; + private: Logger& m_logger; }; diff --git a/SerialPrograms/Source/Tests/CommandLineTests.cpp b/SerialPrograms/Source/Tests/CommandLineTests.cpp index 7e592aa624..95050be819 100644 --- a/SerialPrograms/Source/Tests/CommandLineTests.cpp +++ b/SerialPrograms/Source/Tests/CommandLineTests.cpp @@ -8,7 +8,8 @@ #include "CommandLineTests.h" #include "Common/Cpp/Exceptions.h" #include "CommonFramework/GlobalSettingsPanel.h" -#include "PokemonLA_Tests_Old.h" +#include "CommonFramework/Logging/Logger.h" +#include "ComputerPrograms/UnitTestRunner.h" #include "TestMap.h" #include #include @@ -170,6 +171,12 @@ int run_test_space(const QFileInfo& space_info, size_t& num_passed, const std::v int run_command_line_tests(){ + { + ComputerPrograms::CommandLineUnitTestRunner runner(global_logger_tagged()); + runner.run(); + } + + const auto& root_folder_name = GlobalSettings::instance().COMMAND_LINE_TEST_FOLDER; QDir test_root_dir(root_folder_name.c_str()); From 89f07df1254ce24eb7b1a1d8171912a8e5f8999b Mon Sep 17 00:00:00 2001 From: Alexander Yee Date: Sun, 26 Jul 2026 13:05:19 -0700 Subject: [PATCH 2/3] Fix test wiring. --- .../Source/CommonFramework/Globals.cpp | 14 ++++++++++++++ .../Source/ComputerPrograms/UnitTestRunner.cpp | 16 +++++++++++++++- .../Source/ComputerPrograms/UnitTestRunner.h | 9 ++++++++- SerialPrograms/Source/Tests/CommandLineTests.cpp | 4 +++- 4 files changed, 40 insertions(+), 3 deletions(-) diff --git a/SerialPrograms/Source/CommonFramework/Globals.cpp b/SerialPrograms/Source/CommonFramework/Globals.cpp index 6ca43ff8a9..40dedd55c1 100644 --- a/SerialPrograms/Source/CommonFramework/Globals.cpp +++ b/SerialPrograms/Source/CommonFramework/Globals.cpp @@ -211,6 +211,8 @@ std::string get_resource_path(){ } std::string get_unittest_resource_path(){ // Find the resource directory. + + // Try the intended folder name first. QString base = get_application_base_dir_path(); QString path = base; for (size_t c = 0; c < 5; c++){ @@ -221,6 +223,18 @@ std::string get_unittest_resource_path(){ } path += "/.."; } + + // Now try with the old command-line folder. + path = base; + for (size_t c = 0; c < 5; c++){ + QString try_path = path + "/CommandLineTests/"; + QFile file(try_path); + if (file.exists()){ + return try_path.toStdString(); + } + path += "/.."; + } + return (base + "/UnitTestResources/").toStdString(); } std::string get_training_path(){ diff --git a/SerialPrograms/Source/ComputerPrograms/UnitTestRunner.cpp b/SerialPrograms/Source/ComputerPrograms/UnitTestRunner.cpp index 93d96af334..86d8040879 100644 --- a/SerialPrograms/Source/ComputerPrograms/UnitTestRunner.cpp +++ b/SerialPrograms/Source/ComputerPrograms/UnitTestRunner.cpp @@ -5,6 +5,7 @@ */ #include "Common/Cpp/ScopeExit.h" +#include "Common/Cpp/PrettyPrint.h" #include "Common/Cpp/TestRunners/UnitTestDatabase.h" #include "CommonFramework/Globals.h" #include "CommonFramework/ProgramStats/StatsTracking.h" @@ -229,7 +230,7 @@ void UnitTestRunner::on_test_finished( -void CommandLineUnitTestRunner::run(){ +bool CommandLineUnitTestRunner::run(){ PokemonAutomation::UnitTestRunner runner( m_logger, GlobalThreadPools::computation_normal() @@ -239,6 +240,14 @@ void CommandLineUnitTestRunner::run(){ runner.add_test(test.second); } runner.run(); + + m_logger.log( + "Tests Finished:" + "\n Passed: " + tostr_u_commas(m_passed_tests.load(std::memory_order_acquire)) + + "\n Failed: " + tostr_u_commas(m_failed_tests.load(std::memory_order_acquire)) + + "\n Skipped: " + tostr_u_commas(m_skipped_tests.load(std::memory_order_acquire)) + ); + return m_failed_tests.load(std::memory_order_acquire) != 0; } void CommandLineUnitTestRunner::on_test_finished( std::shared_ptr test, @@ -247,18 +256,23 @@ void CommandLineUnitTestRunner::on_test_finished( switch (result.result){ case UnitTestResult::NOT_RUN: m_logger.log("NOT RUN: " + test->name(), COLOR_ORANGE); + m_skipped_tests++; break; case UnitTestResult::PASSED: m_logger.log("PASSED: " + test->name(), COLOR_BLUE); + m_passed_tests++; break; case UnitTestResult::FAILED: m_logger.log("FAILED: " + test->name(), COLOR_RED); + m_failed_tests++; break; case UnitTestResult::SKIPPED: m_logger.log("SKIPPED: " + test->name(), COLOR_ORANGE); + m_skipped_tests++; break; case UnitTestResult::OOM: m_logger.log("OOM: " + test->name(), COLOR_RED); + m_failed_tests++; break; } } diff --git a/SerialPrograms/Source/ComputerPrograms/UnitTestRunner.h b/SerialPrograms/Source/ComputerPrograms/UnitTestRunner.h index 1135c66f57..51e34fd7e9 100644 --- a/SerialPrograms/Source/ComputerPrograms/UnitTestRunner.h +++ b/SerialPrograms/Source/ComputerPrograms/UnitTestRunner.h @@ -75,9 +75,13 @@ class CommandLineUnitTestRunner : public PokemonAutomation::UnitTestRunner::List public: CommandLineUnitTestRunner(Logger& logger) : m_logger(logger) + , m_skipped_tests(0) + , m_passed_tests(0) + , m_failed_tests(0) {} - void run(); + // Returns true if tests failed. + bool run(); private: @@ -89,6 +93,9 @@ class CommandLineUnitTestRunner : public PokemonAutomation::UnitTestRunner::List private: Logger& m_logger; + std::atomic m_skipped_tests; + std::atomic m_passed_tests; + std::atomic m_failed_tests; }; diff --git a/SerialPrograms/Source/Tests/CommandLineTests.cpp b/SerialPrograms/Source/Tests/CommandLineTests.cpp index 95050be819..d4b69e079e 100644 --- a/SerialPrograms/Source/Tests/CommandLineTests.cpp +++ b/SerialPrograms/Source/Tests/CommandLineTests.cpp @@ -173,7 +173,9 @@ int run_test_space(const QFileInfo& space_info, size_t& num_passed, const std::v int run_command_line_tests(){ { ComputerPrograms::CommandLineUnitTestRunner runner(global_logger_tagged()); - runner.run(); + if (runner.run()){ + return 1; + } } From 556f5140840343f932b2bdef88e087fe53cf4d05 Mon Sep 17 00:00:00 2001 From: Alexander Yee Date: Sun, 26 Jul 2026 13:32:15 -0700 Subject: [PATCH 3/3] Try to fix logging. --- SerialPrograms/Source/Tests/CommandLineTests.cpp | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/SerialPrograms/Source/Tests/CommandLineTests.cpp b/SerialPrograms/Source/Tests/CommandLineTests.cpp index d4b69e079e..4c370bda69 100644 --- a/SerialPrograms/Source/Tests/CommandLineTests.cpp +++ b/SerialPrograms/Source/Tests/CommandLineTests.cpp @@ -172,7 +172,9 @@ int run_test_space(const QFileInfo& space_info, size_t& num_passed, const std::v int run_command_line_tests(){ { - ComputerPrograms::CommandLineUnitTestRunner runner(global_logger_tagged()); + cout << "Running parallel unit tests..." << endl; + ComputerPrograms::CommandLineUnitTestRunner runner(global_logger_command_line()); + cout << "Running parallel unit tests... Done!" << endl; if (runner.run()){ return 1; }