mirror of
https://github.com/luanti-org/luanti.git
synced 2025-07-02 16:38:41 +00:00
Allow running individual unit tests
This commit is contained in:
parent
aada2403c9
commit
2f6a9d12f1
3 changed files with 54 additions and 6 deletions
|
@ -226,12 +226,12 @@ bool run_tests()
|
|||
u32 num_total_tests_failed = 0;
|
||||
u32 num_total_tests_run = 0;
|
||||
std::vector<TestBase *> &testmods = TestManager::getTestModules();
|
||||
for (size_t i = 0; i != testmods.size(); i++) {
|
||||
if (!testmods[i]->testModule(&gamedef))
|
||||
for (auto *testmod: testmods) {
|
||||
if (!testmod->testModule(&gamedef))
|
||||
num_modules_failed++;
|
||||
|
||||
num_total_tests_failed += testmods[i]->num_tests_failed;
|
||||
num_total_tests_run += testmods[i]->num_tests_run;
|
||||
num_total_tests_failed += testmod->num_tests_failed;
|
||||
num_total_tests_run += testmod->num_tests_run;
|
||||
}
|
||||
|
||||
u64 tdiff = porting::getTimeMs() - t1;
|
||||
|
@ -251,7 +251,49 @@ bool run_tests()
|
|||
<< "++++++++++++++++++++++++++++++++++++++++"
|
||||
<< "++++++++++++++++++++++++++++++++++++++++" << std::endl;
|
||||
|
||||
return num_modules_failed;
|
||||
return num_modules_failed == 0;
|
||||
}
|
||||
|
||||
static TestBase *findTestModule(const std::string &module_name) {
|
||||
std::vector<TestBase *> &testmods = TestManager::getTestModules();
|
||||
for (auto *testmod: testmods) {
|
||||
if (module_name == testmod->getName())
|
||||
return testmod;
|
||||
}
|
||||
return nullptr;
|
||||
}
|
||||
|
||||
bool run_tests(const std::string &module_name)
|
||||
{
|
||||
TestGameDef gamedef;
|
||||
|
||||
auto testmod = findTestModule(module_name);
|
||||
if (!testmod) {
|
||||
errorstream << "Test module not found: " << module_name << std::endl;
|
||||
return 1;
|
||||
}
|
||||
|
||||
g_logger.setLevelSilenced(LL_ERROR, true);
|
||||
u64 t1 = porting::getTimeMs();
|
||||
|
||||
bool ok = testmod->testModule(&gamedef);
|
||||
|
||||
u64 tdiff = porting::getTimeMs() - t1;
|
||||
g_logger.setLevelSilenced(LL_ERROR, false);
|
||||
|
||||
const char *overall_status = ok ? "PASSED" : "FAILED";
|
||||
|
||||
rawstream
|
||||
<< "++++++++++++++++++++++++++++++++++++++++"
|
||||
<< "++++++++++++++++++++++++++++++++++++++++" << std::endl
|
||||
<< "Unit Test Results: " << overall_status << std::endl
|
||||
<< " " << testmod->num_tests_failed << " / "
|
||||
<< testmod->num_tests_run << " failed tests." << std::endl
|
||||
<< " Testing took " << tdiff << "ms." << std::endl
|
||||
<< "++++++++++++++++++++++++++++++++++++++++"
|
||||
<< "++++++++++++++++++++++++++++++++++++++++" << std::endl;
|
||||
|
||||
return ok;
|
||||
}
|
||||
|
||||
////
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue