Initial commit.
This commit is contained in:
40
src/Tester/Test.hpp
Normal file
40
src/Tester/Test.hpp
Normal file
@@ -0,0 +1,40 @@
|
||||
#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
|
||||
Reference in New Issue
Block a user