Adds support for debugger.
This commit is contained in:
parent
77dd8e708a
commit
7043b12f34
|
@ -19,7 +19,7 @@ if (CMAKE_CXX_COMPILER_ID STREQUAL "Clang")
|
||||||
endif ()
|
endif ()
|
||||||
|
|
||||||
|
|
||||||
file(GLOB_RECURSE SRC_FILES src/*.cpp src/*.hpp)
|
file(GLOB_RECURSE SRC_FILES src/*.cpp src/*.hpp extern/AngelscriptDebugger/src/*.cpp)
|
||||||
add_executable(PokemonScriptTester ${SRC_FILES})
|
add_executable(PokemonScriptTester ${SRC_FILES})
|
||||||
target_precompile_headers(PokemonScriptTester PUBLIC src/Precompiled.hxx)
|
target_precompile_headers(PokemonScriptTester PUBLIC src/Precompiled.hxx)
|
||||||
add_definitions(-DLEVEL_U8)
|
add_definitions(-DLEVEL_U8)
|
||||||
|
@ -44,3 +44,4 @@ set(PRE_CONFIGURE_FILE "git.h.in")
|
||||||
set(POST_CONFIGURE_FILE "src/git.h")
|
set(POST_CONFIGURE_FILE "src/git.h")
|
||||||
include(git_watcher.cmake)
|
include(git_watcher.cmake)
|
||||||
add_dependencies(PokemonScriptTester check_git)
|
add_dependencies(PokemonScriptTester check_git)
|
||||||
|
target_include_directories(PokemonScriptTester PRIVATE extern/AngelscriptDebugger/extern/asio-1.18.2/include)
|
||||||
|
|
|
@ -12,7 +12,7 @@
|
||||||
class BattleFunctions {
|
class BattleFunctions {
|
||||||
static CreatureLib::Battling::CreatureParty* CreateSimpleParty(CScriptArray* species, u8 level) {
|
static CreatureLib::Battling::CreatureParty* CreateSimpleParty(CScriptArray* species, u8 level) {
|
||||||
auto* ctx = asGetActiveContext();
|
auto* ctx = asGetActiveContext();
|
||||||
TestEnvironment* env = static_cast<TestEnvironment*>(ctx->GetUserData());
|
TestEnvironment* env = static_cast<TestEnvironment*>(ctx->GetUserData(684));
|
||||||
|
|
||||||
auto lib = Globals::Library.GetValue();
|
auto lib = Globals::Library.GetValue();
|
||||||
auto p1 = new PkmnLib::Battling::PokemonParty(species->GetSize());
|
auto p1 = new PkmnLib::Battling::PokemonParty(species->GetSize());
|
||||||
|
@ -34,7 +34,7 @@ class BattleFunctions {
|
||||||
static PkmnLib::Battling::Battle* CreateSimpleBattle(u32 seed, const ArbUt::StringView& species1,
|
static PkmnLib::Battling::Battle* CreateSimpleBattle(u32 seed, const ArbUt::StringView& species1,
|
||||||
const ArbUt::StringView& species2, u8 level) {
|
const ArbUt::StringView& species2, u8 level) {
|
||||||
auto* ctx = asGetActiveContext();
|
auto* ctx = asGetActiveContext();
|
||||||
TestEnvironment* env = static_cast<TestEnvironment*>(ctx->GetUserData());
|
TestEnvironment* env = static_cast<TestEnvironment*>(ctx->GetUserData(684));
|
||||||
auto lib = Globals::Library.GetValue();
|
auto lib = Globals::Library.GetValue();
|
||||||
|
|
||||||
auto mon1 = PkmnLib::Battling::CreatePokemon(lib, species1, level)
|
auto mon1 = PkmnLib::Battling::CreatePokemon(lib, species1, level)
|
||||||
|
@ -79,7 +79,7 @@ class BattleFunctions {
|
||||||
static PkmnLib::Battling::Battle* CreateSimpleBattleFromParties(u32 seed, PkmnLib::Battling::PokemonParty* p1,
|
static PkmnLib::Battling::Battle* CreateSimpleBattleFromParties(u32 seed, PkmnLib::Battling::PokemonParty* p1,
|
||||||
PkmnLib::Battling::PokemonParty* p2) {
|
PkmnLib::Battling::PokemonParty* p2) {
|
||||||
auto* ctx = asGetActiveContext();
|
auto* ctx = asGetActiveContext();
|
||||||
TestEnvironment* env = static_cast<TestEnvironment*>(ctx->GetUserData());
|
TestEnvironment* env = static_cast<TestEnvironment*>(ctx->GetUserData(684));
|
||||||
auto lib = Globals::Library.GetValue();
|
auto lib = Globals::Library.GetValue();
|
||||||
|
|
||||||
auto battle = new PkmnLib::Battling::Battle(
|
auto battle = new PkmnLib::Battling::Battle(
|
||||||
|
@ -109,7 +109,7 @@ class BattleFunctions {
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
auto* ctx = asGetActiveContext();
|
auto* ctx = asGetActiveContext();
|
||||||
TestEnvironment* env = static_cast<TestEnvironment*>(ctx->GetUserData());
|
TestEnvironment* env = static_cast<TestEnvironment*>(ctx->GetUserData(684));
|
||||||
|
|
||||||
auto learnedMove =
|
auto learnedMove =
|
||||||
new PkmnLib::Battling::LearnedMove(move.value(), CreatureLib::Battling::AttackLearnMethod::Unknown);
|
new PkmnLib::Battling::LearnedMove(move.value(), CreatureLib::Battling::AttackLearnMethod::Unknown);
|
||||||
|
|
|
@ -8,7 +8,7 @@ class MiscMockFunctions {
|
||||||
auto script = Globals::Library.GetValue()->GetScriptResolver()->LoadScript(ScriptCategory::Attack, name);
|
auto script = Globals::Library.GetValue()->GetScriptResolver()->LoadScript(ScriptCategory::Attack, name);
|
||||||
if (script != nullptr) {
|
if (script != nullptr) {
|
||||||
auto* ctx = asGetActiveContext();
|
auto* ctx = asGetActiveContext();
|
||||||
TestEnvironment* env = static_cast<TestEnvironment*>(ctx->GetUserData());
|
TestEnvironment* env = static_cast<TestEnvironment*>(ctx->GetUserData(684));
|
||||||
env->AddGarbage(script);
|
env->AddGarbage(script);
|
||||||
}
|
}
|
||||||
auto p = dynamic_cast<AngelScriptScript*>(script);
|
auto p = dynamic_cast<AngelScriptScript*>(script);
|
||||||
|
@ -21,7 +21,7 @@ class MiscMockFunctions {
|
||||||
PkmnLib::Battling::Pokemon* user,
|
PkmnLib::Battling::Pokemon* user,
|
||||||
PkmnLib::Battling::Pokemon* target) {
|
PkmnLib::Battling::Pokemon* target) {
|
||||||
auto* ctx = asGetActiveContext();
|
auto* ctx = asGetActiveContext();
|
||||||
TestEnvironment* env = static_cast<TestEnvironment*>(ctx->GetUserData());
|
TestEnvironment* env = static_cast<TestEnvironment*>(ctx->GetUserData(684));
|
||||||
|
|
||||||
auto move = Globals::Library.GetValue()->GetMoveLibrary()->TryGet(moveName);
|
auto move = Globals::Library.GetValue()->GetMoveLibrary()->TryGet(moveName);
|
||||||
if (!move.has_value()) {
|
if (!move.has_value()) {
|
||||||
|
@ -41,7 +41,7 @@ class MiscMockFunctions {
|
||||||
PkmnLib::Battling::Pokemon* user,
|
PkmnLib::Battling::Pokemon* user,
|
||||||
u8 targetSide, u8 target) {
|
u8 targetSide, u8 target) {
|
||||||
auto* ctx = asGetActiveContext();
|
auto* ctx = asGetActiveContext();
|
||||||
TestEnvironment* env = static_cast<TestEnvironment*>(ctx->GetUserData());
|
TestEnvironment* env = static_cast<TestEnvironment*>(ctx->GetUserData(684));
|
||||||
|
|
||||||
auto move = Globals::Library.GetValue()->GetMoveLibrary()->TryGet(moveName);
|
auto move = Globals::Library.GetValue()->GetMoveLibrary()->TryGet(moveName);
|
||||||
if (!move.has_value()) {
|
if (!move.has_value()) {
|
||||||
|
|
|
@ -23,7 +23,7 @@ private:
|
||||||
|
|
||||||
static bool Require(bool value) {
|
static bool Require(bool value) {
|
||||||
auto* ctx = asGetActiveContext();
|
auto* ctx = asGetActiveContext();
|
||||||
TestEnvironment* env = static_cast<TestEnvironment*>(ctx->GetUserData());
|
TestEnvironment* env = static_cast<TestEnvironment*>(ctx->GetUserData(684));
|
||||||
env->TotalRequirements += 1;
|
env->TotalRequirements += 1;
|
||||||
if (!value) {
|
if (!value) {
|
||||||
env->FailedRequirements += 1;
|
env->FailedRequirements += 1;
|
||||||
|
@ -43,7 +43,7 @@ private:
|
||||||
|
|
||||||
static bool RequireEqualsI32(i32 expected, i32 actual) {
|
static bool RequireEqualsI32(i32 expected, i32 actual) {
|
||||||
auto* ctx = asGetActiveContext();
|
auto* ctx = asGetActiveContext();
|
||||||
TestEnvironment* env = static_cast<TestEnvironment*>(ctx->GetUserData());
|
TestEnvironment* env = static_cast<TestEnvironment*>(ctx->GetUserData(684));
|
||||||
env->TotalRequirements += 1;
|
env->TotalRequirements += 1;
|
||||||
if (expected != actual) {
|
if (expected != actual) {
|
||||||
env->FailedRequirements += 1;
|
env->FailedRequirements += 1;
|
||||||
|
@ -56,7 +56,7 @@ private:
|
||||||
|
|
||||||
static bool RequireEqualsString(const std::string& expected, const std::string& actual) {
|
static bool RequireEqualsString(const std::string& expected, const std::string& actual) {
|
||||||
auto* ctx = asGetActiveContext();
|
auto* ctx = asGetActiveContext();
|
||||||
TestEnvironment* env = static_cast<TestEnvironment*>(ctx->GetUserData());
|
TestEnvironment* env = static_cast<TestEnvironment*>(ctx->GetUserData(684));
|
||||||
if (expected != actual) {
|
if (expected != actual) {
|
||||||
env->FailedRequirements += 1;
|
env->FailedRequirements += 1;
|
||||||
auto data = GetRequirementData(ctx);
|
auto data = GetRequirementData(ctx);
|
||||||
|
|
|
@ -13,8 +13,17 @@ public:
|
||||||
void Run(asIScriptContext* ctx) {
|
void Run(asIScriptContext* ctx) {
|
||||||
ctx->PushState();
|
ctx->PushState();
|
||||||
ctx->Prepare(_function);
|
ctx->Prepare(_function);
|
||||||
ctx->SetUserData(_env.get());
|
ctx->SetUserData(_env.get(), 684);
|
||||||
auto e = ctx->Execute();
|
auto e = ctx->Execute();
|
||||||
|
if (e == asEXECUTION_SUSPENDED) {
|
||||||
|
auto s = ctx->GetState();
|
||||||
|
while (s != asEXECUTION_FINISHED && s != asEXECUTION_EXCEPTION && s != asEXECUTION_ABORTED &&
|
||||||
|
s != asEXECUTION_ERROR) {
|
||||||
|
s = ctx->GetState();
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
_env->CollectGarbage();
|
_env->CollectGarbage();
|
||||||
if (e == asEXECUTION_EXCEPTION) {
|
if (e == asEXECUTION_EXCEPTION) {
|
||||||
_errorMessage = ctx->GetExceptionString();
|
_errorMessage = ctx->GetExceptionString();
|
||||||
|
@ -23,7 +32,6 @@ public:
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
ctx->PopState();
|
ctx->PopState();
|
||||||
Ensure(e == asEXECUTION_FINISHED);
|
|
||||||
_result = TestResult::Success;
|
_result = TestResult::Success;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -2,14 +2,17 @@
|
||||||
#define POKEMONSCRIPTTESTER_TESTRUNNER_HPP
|
#define POKEMONSCRIPTTESTER_TESTRUNNER_HPP
|
||||||
|
|
||||||
#include <PkmnLib/ScriptResolving/AngelScript/AngelScriptMetadata.hpp>
|
#include <PkmnLib/ScriptResolving/AngelScript/AngelScriptMetadata.hpp>
|
||||||
|
#include <PkmnLib/ScriptResolving/AngelScript/ContextPool.hpp>
|
||||||
|
#include "../../extern/AngelscriptDebugger/src/AngelscriptDebugger.hpp"
|
||||||
#include "../../extern/termcolor.hpp"
|
#include "../../extern/termcolor.hpp"
|
||||||
#include "Test.hpp"
|
#include "Test.hpp"
|
||||||
|
|
||||||
class TestRunner {
|
class TestRunner {
|
||||||
|
AngelScriptResolver* _scriptResolver;
|
||||||
ArbUt::Dictionary<std::string, std::unique_ptr<Test>> _tests;
|
ArbUt::Dictionary<std::string, std::unique_ptr<Test>> _tests;
|
||||||
|
|
||||||
public:
|
public:
|
||||||
TestRunner(AngelScriptResolver* scriptResolver) {
|
TestRunner(AngelScriptResolver* scriptResolver) : _scriptResolver(scriptResolver) {
|
||||||
const auto* module = scriptResolver->GetMainModule();
|
const auto* module = scriptResolver->GetMainModule();
|
||||||
auto builder = scriptResolver->GetBuilder();
|
auto builder = scriptResolver->GetBuilder();
|
||||||
for (u32 i = 0; i < module->GetFunctionCount(); ++i) {
|
for (u32 i = 0; i < module->GetFunctionCount(); ++i) {
|
||||||
|
@ -30,8 +33,20 @@ public:
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
i32 RunAll(asIScriptEngine* engine) {
|
i32 RunAll(bool waitForDebugger) {
|
||||||
auto ctx = engine->CreateContext();
|
auto ctx = _scriptResolver->GetContextPool()->RequestContext();
|
||||||
|
ctx->SetUserData(_scriptResolver->GetUserdata());
|
||||||
|
auto debugger = AngelscriptDebugger();
|
||||||
|
debugger.Run(8684);
|
||||||
|
debugger.RegisterContext(ctx);
|
||||||
|
if (waitForDebugger) {
|
||||||
|
std::cout << "Waiting for debugger" << std::endl;
|
||||||
|
while (!debugger.HasDebuggerAttached()) {
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
sleep(1);
|
||||||
|
}
|
||||||
|
|
||||||
for (auto& test : _tests) {
|
for (auto& test : _tests) {
|
||||||
test.second->Run(ctx);
|
test.second->Run(ctx);
|
||||||
}
|
}
|
||||||
|
|
|
@ -23,6 +23,7 @@ int main(int argc, char** argv) {
|
||||||
{"workdir"});
|
{"workdir"});
|
||||||
args::Flag logTimeFlag(parser, "time-log", "Whether to show time logging.", {'t', "time-log"});
|
args::Flag logTimeFlag(parser, "time-log", "Whether to show time logging.", {'t', "time-log"});
|
||||||
args::Flag forceColorFlag(parser, "force-color", "Whether to force color text output.", {'c', "force-color"});
|
args::Flag forceColorFlag(parser, "force-color", "Whether to force color text output.", {'c', "force-color"});
|
||||||
|
args::Flag waitForDebuggerFlag(parser, "wait-for-debugger", "Whether to wait until a debugger is connected or not.", {'w', "wait-for-debugger"});
|
||||||
try {
|
try {
|
||||||
parser.ParseCLI(argc, argv);
|
parser.ParseCLI(argc, argv);
|
||||||
} catch (args::Help&) {
|
} catch (args::Help&) {
|
||||||
|
@ -71,9 +72,8 @@ int main(int argc, char** argv) {
|
||||||
}
|
}
|
||||||
auto* scriptResolver = dynamic_cast<AngelScriptResolver*>(Globals::Library.GetValue()->GetScriptResolver().get());
|
auto* scriptResolver = dynamic_cast<AngelScriptResolver*>(Globals::Library.GetValue()->GetScriptResolver().get());
|
||||||
auto testRunner = TestRunner(scriptResolver);
|
auto testRunner = TestRunner(scriptResolver);
|
||||||
auto* engine = scriptResolver->GetBuilder().GetEngine();
|
|
||||||
std::chrono::steady_clock::time_point beginTests = std::chrono::steady_clock::now();
|
std::chrono::steady_clock::time_point beginTests = std::chrono::steady_clock::now();
|
||||||
auto v = testRunner.RunAll(engine);
|
auto v = testRunner.RunAll(waitForDebuggerFlag.Get());
|
||||||
std::chrono::steady_clock::time_point end = std::chrono::steady_clock::now();
|
std::chrono::steady_clock::time_point end = std::chrono::steady_clock::now();
|
||||||
std::cout << std::endl
|
std::cout << std::endl
|
||||||
<< "Total Run time: " << std::chrono::duration_cast<std::chrono::milliseconds>(end - begin).count()
|
<< "Total Run time: " << std::chrono::duration_cast<std::chrono::milliseconds>(end - begin).count()
|
||||||
|
|
Loading…
Reference in New Issue