#ifndef POKEMONSCRIPTTESTER_TESTRUNNER_HPP #define POKEMONSCRIPTTESTER_TESTRUNNER_HPP #include #include "Test.hpp" class TestRunner { ArbUt::Dictionary _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.Insert(name, Test(name, func)); } } } } void RunAll(asIScriptEngine* engine) { auto ctx = engine->CreateContext(); for (auto& test : _tests) { test.second.Run(ctx); } 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; } } } }; #endif // POKEMONSCRIPTTESTER_TESTRUNNER_HPP