Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
14 changes: 14 additions & 0 deletions SerialPrograms/Source/CommonFramework/Globals.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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++){
Expand All @@ -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(){
Expand Down
16 changes: 15 additions & 1 deletion SerialPrograms/Source/ComputerPrograms/UnitTestRunner.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down Expand Up @@ -229,7 +230,7 @@ void UnitTestRunner::on_test_finished(



void CommandLineUnitTestRunner::run(){
bool CommandLineUnitTestRunner::run(){
PokemonAutomation::UnitTestRunner runner(
m_logger,
GlobalThreadPools::computation_normal()
Expand All @@ -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<const UnitTest> test,
Expand All @@ -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;
}
}
Expand Down
12 changes: 11 additions & 1 deletion SerialPrograms/Source/ComputerPrograms/UnitTestRunner.h
Original file line number Diff line number Diff line change
Expand Up @@ -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<const UnitTest> test,
UnitTestResult result
) override;


private:
Logger& m_logger;
std::atomic<size_t> m_skipped_tests;
std::atomic<size_t> m_passed_tests;
std::atomic<size_t> m_failed_tests;
};


Expand Down
13 changes: 12 additions & 1 deletion SerialPrograms/Source/Tests/CommandLineTests.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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 <QDir>
#include <QDirIterator>
Expand Down Expand Up @@ -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());
Expand Down
Loading