43 lines
1.2 KiB
C++
43 lines
1.2 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->PushState();
|
|
ctx->Prepare(_function);
|
|
ctx->SetUserData(_env.get());
|
|
auto e = ctx->Execute();
|
|
_env->CollectGarbage();
|
|
if (e == asEXECUTION_EXCEPTION) {
|
|
_errorMessage = ctx->GetExceptionString();
|
|
_result = TestResult::Failed;
|
|
ctx->PopState();
|
|
return;
|
|
}
|
|
ctx->PopState();
|
|
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;
|
|
std::unique_ptr<TestEnvironment> _env;
|
|
|
|
TestResult _result = TestResult::NotRan;
|
|
std::string _errorMessage = "";
|
|
};
|
|
|
|
#endif // POKEMONSCRIPTTESTER_TEST_HPP
|