Skip to content

Commit 8bf0ec0

Browse files
MysticialDeveloper-Butters
authored andcommitted
Put new UI unit-tests onto existing command-line tests. (PokemonAutomation#1345)
* Inject new unit tests into existing commandline test infra. * Fix test wiring. * Try to fix logging.
1 parent 8154d3f commit 8bf0ec0

4 files changed

Lines changed: 52 additions & 3 deletions

File tree

SerialPrograms/Source/CommonFramework/Globals.cpp

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -211,6 +211,8 @@ std::string get_resource_path(){
211211
}
212212
std::string get_unittest_resource_path(){
213213
// Find the resource directory.
214+
215+
// Try the intended folder name first.
214216
QString base = get_application_base_dir_path();
215217
QString path = base;
216218
for (size_t c = 0; c < 5; c++){
@@ -221,6 +223,18 @@ std::string get_unittest_resource_path(){
221223
}
222224
path += "/..";
223225
}
226+
227+
// Now try with the old command-line folder.
228+
path = base;
229+
for (size_t c = 0; c < 5; c++){
230+
QString try_path = path + "/CommandLineTests/";
231+
QFile file(try_path);
232+
if (file.exists()){
233+
return try_path.toStdString();
234+
}
235+
path += "/..";
236+
}
237+
224238
return (base + "/UnitTestResources/").toStdString();
225239
}
226240
std::string get_training_path(){

SerialPrograms/Source/ComputerPrograms/UnitTestRunner.cpp

Lines changed: 15 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@
55
*/
66

77
#include "Common/Cpp/ScopeExit.h"
8+
#include "Common/Cpp/PrettyPrint.h"
89
#include "Common/Cpp/TestRunners/UnitTestDatabase.h"
910
#include "CommonFramework/Globals.h"
1011
#include "CommonFramework/ProgramStats/StatsTracking.h"
@@ -229,7 +230,7 @@ void UnitTestRunner::on_test_finished(
229230

230231

231232

232-
void CommandLineUnitTestRunner::run(){
233+
bool CommandLineUnitTestRunner::run(){
233234
PokemonAutomation::UnitTestRunner runner(
234235
m_logger,
235236
GlobalThreadPools::computation_normal()
@@ -239,6 +240,14 @@ void CommandLineUnitTestRunner::run(){
239240
runner.add_test(test.second);
240241
}
241242
runner.run();
243+
244+
m_logger.log(
245+
"Tests Finished:"
246+
"\n Passed: " + tostr_u_commas(m_passed_tests.load(std::memory_order_acquire)) +
247+
"\n Failed: " + tostr_u_commas(m_failed_tests.load(std::memory_order_acquire)) +
248+
"\n Skipped: " + tostr_u_commas(m_skipped_tests.load(std::memory_order_acquire))
249+
);
250+
return m_failed_tests.load(std::memory_order_acquire) != 0;
242251
}
243252
void CommandLineUnitTestRunner::on_test_finished(
244253
std::shared_ptr<const UnitTest> test,
@@ -247,18 +256,23 @@ void CommandLineUnitTestRunner::on_test_finished(
247256
switch (result.result){
248257
case UnitTestResult::NOT_RUN:
249258
m_logger.log("NOT RUN: " + test->name(), COLOR_ORANGE);
259+
m_skipped_tests++;
250260
break;
251261
case UnitTestResult::PASSED:
252262
m_logger.log("PASSED: " + test->name(), COLOR_BLUE);
263+
m_passed_tests++;
253264
break;
254265
case UnitTestResult::FAILED:
255266
m_logger.log("FAILED: " + test->name(), COLOR_RED);
267+
m_failed_tests++;
256268
break;
257269
case UnitTestResult::SKIPPED:
258270
m_logger.log("SKIPPED: " + test->name(), COLOR_ORANGE);
271+
m_skipped_tests++;
259272
break;
260273
case UnitTestResult::OOM:
261274
m_logger.log("OOM: " + test->name(), COLOR_RED);
275+
m_failed_tests++;
262276
break;
263277
}
264278
}

SerialPrograms/Source/ComputerPrograms/UnitTestRunner.h

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -75,17 +75,27 @@ class CommandLineUnitTestRunner : public PokemonAutomation::UnitTestRunner::List
7575
public:
7676
CommandLineUnitTestRunner(Logger& logger)
7777
: m_logger(logger)
78+
, m_skipped_tests(0)
79+
, m_passed_tests(0)
80+
, m_failed_tests(0)
7881
{}
7982

80-
void run();
83+
// Returns true if tests failed.
84+
bool run();
8185

86+
87+
private:
8288
virtual void on_test_finished(
8389
std::shared_ptr<const UnitTest> test,
8490
UnitTestResult result
8591
) override;
8692

93+
8794
private:
8895
Logger& m_logger;
96+
std::atomic<size_t> m_skipped_tests;
97+
std::atomic<size_t> m_passed_tests;
98+
std::atomic<size_t> m_failed_tests;
8999
};
90100

91101

SerialPrograms/Source/Tests/CommandLineTests.cpp

Lines changed: 12 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,8 @@
88
#include "CommandLineTests.h"
99
#include "Common/Cpp/Exceptions.h"
1010
#include "CommonFramework/GlobalSettingsPanel.h"
11-
#include "PokemonLA_Tests_Old.h"
11+
#include "CommonFramework/Logging/Logger.h"
12+
#include "ComputerPrograms/UnitTestRunner.h"
1213
#include "TestMap.h"
1314
#include <QDir>
1415
#include <QDirIterator>
@@ -170,6 +171,16 @@ int run_test_space(const QFileInfo& space_info, size_t& num_passed, const std::v
170171

171172

172173
int run_command_line_tests(){
174+
{
175+
cout << "Running parallel unit tests..." << endl;
176+
ComputerPrograms::CommandLineUnitTestRunner runner(global_logger_command_line());
177+
cout << "Running parallel unit tests... Done!" << endl;
178+
if (runner.run()){
179+
return 1;
180+
}
181+
}
182+
183+
173184
const auto& root_folder_name = GlobalSettings::instance().COMMAND_LINE_TEST_FOLDER;
174185

175186
QDir test_root_dir(root_folder_name.c_str());

0 commit comments

Comments
 (0)