61 lines
2.1 KiB
C++
61 lines
2.1 KiB
C++
#ifndef POKEMONSCRIPTTESTER_TESTRUNNER_HPP
|
|
#define POKEMONSCRIPTTESTER_TESTRUNNER_HPP
|
|
|
|
#include <PkmnLib/ScriptResolving/AngelScript/AngelScriptMetadata.hpp>
|
|
#include "Test.hpp"
|
|
|
|
class TestRunner {
|
|
ArbUt::Dictionary<std::string, std::unique_ptr<Test>> _tests;
|
|
|
|
public:
|
|
TestRunner(AngelScriptResolver* scriptResolver) {
|
|
const auto* module = scriptResolver->GetMainModule();
|
|
auto builder = scriptResolver->GetBuilder();
|
|
for (u32 i = 0; i < module->GetFunctionCount(); ++i) {
|
|
auto* func = module->GetFunctionByIndex(i);
|
|
auto metaData = builder.GetMetadataForFunc(func);
|
|
for (const auto& m : metaData) {
|
|
auto meta = AngelscriptMetadata(m);
|
|
if (meta.GetIdentifier() == "Test"_cnc) {
|
|
auto name = meta.GetParameter("name"_cnc);
|
|
_tests.GetStdMap().insert({name, std::make_unique<Test>(name, func)});
|
|
}
|
|
}
|
|
}
|
|
}
|
|
|
|
i32 RunAll(asIScriptEngine* engine) {
|
|
auto ctx = engine->CreateContext();
|
|
for (auto& test : _tests) {
|
|
test.second->Run(ctx);
|
|
}
|
|
ctx->Release();
|
|
|
|
size_t notRunTests = 0;
|
|
size_t successfulTests = 0;
|
|
size_t failedTests = 0;
|
|
for (auto& test : _tests) {
|
|
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;
|
|
}
|
|
};
|
|
|
|
#endif // POKEMONSCRIPTTESTER_TESTRUNNER_HPP
|