PokemonScriptTester/src/Tester/Test.hpp

41 lines
1.1 KiB
C++

#ifndef POKEMONSCRIPTTESTER_TEST_HPP
#define POKEMONSCRIPTTESTER_TEST_HPP
#include <angelscript.h>
#include "TestEnvironment.hpp"
#include "TestResult.hpp"
class Test {
public:
Test(const std::string name, asIScriptFunction* function)
: _name(name), _function(function), _env(new TestEnvironment()) {}
void Run(asIScriptContext* ctx) {
ctx->Prepare(_function);
ctx->SetUserData(_env);
auto e = ctx->Execute();
if (e == asEXECUTION_EXCEPTION) {
_errorMessage = ctx->GetExceptionString();
_result = TestResult::Failed;
ctx->Release();
return;
}
ctx->Release();
Ensure(e == asEXECUTION_FINISHED);
_result = TestResult::Success;
}
inline TestResult GetResult() const noexcept { return _result; }
inline const std::string& GetErrorMessage() const noexcept { return _errorMessage; }
private:
std::string _name;
asIScriptFunction* _function;
TestEnvironment* _env;
TestResult _result = TestResult::NotRan;
std::string _errorMessage = "";
};
#endif // POKEMONSCRIPTTESTER_TEST_HPP