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 8c7a656a6d..51e34fd7e9 100644 --- a/SerialPrograms/Source/ComputerPrograms/UnitTestRunner.h +++ b/SerialPrograms/Source/ComputerPrograms/UnitTestRunner.h @@ -75,17 +75,27 @@ 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: virtual void on_test_finished( std::shared_ptr test, UnitTestResult result ) override; + 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 7e592aa624..4c370bda69 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,16 @@ int run_test_space(const QFileInfo& space_info, size_t& num_passed, const std::v int run_command_line_tests(){ + { + 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; + } + } + + const auto& root_folder_name = GlobalSettings::instance().COMMAND_LINE_TEST_FOLDER; QDir test_root_dir(root_folder_name.c_str());