Fixes several memory issues.

This commit is contained in:
2021-08-22 19:29:00 +02:00
parent a6013437b2
commit 3488339d51
4 changed files with 51 additions and 18 deletions

View File

@@ -5,7 +5,7 @@
#include "Test.hpp"
class TestRunner {
ArbUt::Dictionary<std::string, Test> _tests;
ArbUt::Dictionary<std::string, std::unique_ptr<Test>> _tests;
public:
TestRunner(AngelScriptResolver* scriptResolver) {
@@ -18,24 +18,42 @@ public:
auto meta = AngelscriptMetadata(m);
if (meta.GetIdentifier() == "Test"_cnc) {
auto name = meta.GetParameter("name"_cnc);
_tests.Insert(name, Test(name, func));
_tests.GetStdMap().insert({name, std::make_unique<Test>(name, func)});
}
}
}
}
void RunAll(asIScriptEngine* engine) {
i32 RunAll(asIScriptEngine* engine) {
auto ctx = engine->CreateContext();
for (auto& test : _tests) {
test.second.Run(ctx);
test.second->Run(ctx);
}
ctx->Release();
size_t notRunTests = 0;
size_t successfulTests = 0;
size_t failedTests = 0;
for (auto& test : _tests) {
if (test.second.GetResult() == TestResult::Failed) {
std::cout << "Test '" << test.first << "' failed with message: " << std::endl;
std::cout << test.second.GetErrorMessage() << std::endl << std::endl;
auto result = test.second->GetResult();
switch (result) {
case TestResult::NotRan: notRunTests += 1; break;
case TestResult::Success: successfulTests += 1; break;
case TestResult::Failed: {
std::cout << "Test '" << test.first << "' failed with message: " << std::endl;
std::cout << test.second->GetErrorMessage() << std::endl << std::endl;
failedTests += 1;
break;
}
}
}
std::cout << "Ran " << successfulTests + failedTests << " tests. Passed tests: " << successfulTests
<< ". Failed tests: " << failedTests << "." << std::endl;
if (failedTests > 0) {
return 1;
}
return 0;
}
};