1
0
Fork 0
mirror of https://github.com/luanti-org/luanti.git synced 2025-07-02 16:38:41 +00:00

Reduce test framework macrosity

This commit is contained in:
Vitaliy 2023-12-15 12:23:32 +03:00 committed by GitHub
parent bd06466d3a
commit 64b59184d1
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
2 changed files with 55 additions and 46 deletions

View file

@ -330,7 +330,7 @@ std::string TestBase::getTestTempDirectory()
m_test_dir = fs::TempPath() + DIR_DELIM "mttest_" + buf;
if (!fs::CreateDir(m_test_dir))
throw TestFailedException();
UASSERT(false);
return m_test_dir;
}
@ -343,6 +343,26 @@ std::string TestBase::getTestTempFile()
return getTestTempDirectory() + DIR_DELIM + buf + ".tmp";
}
void TestBase::runTest(const char *name, std::function<void()> &&test)
{
u64 t1 = porting::getTimeMs();
try {
test();
rawstream << "[PASS] ";
} catch (TestFailedException &e) {
rawstream << "Test assertion failed: " << e.message << std::endl;
rawstream << " at " << e.file << ":" << e.line << std::endl;
rawstream << "[FAIL] ";
num_tests_failed++;
} catch (std::exception &e) {
rawstream << "Caught unhandled exception: " << e.what() << std::endl;
rawstream << "[FAIL] ";
num_tests_failed++;
}
num_tests_run++;
u64 tdiff = porting::getTimeMs() - t1;
rawstream << name << " - " << tdiff << "ms" << std::endl;
}
/*
NOTE: These tests became non-working then NodeContainer was removed.