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 ()
|
||||
|
||||
|
||||
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})
|
||||
target_precompile_headers(PokemonScriptTester PUBLIC src/Precompiled.hxx)
|
||||
add_definitions(-DLEVEL_U8)
|
||||
|
@ -44,3 +44,4 @@ set(PRE_CONFIGURE_FILE "git.h.in")
|
|||
set(POST_CONFIGURE_FILE "src/git.h")
|
||||
include(git_watcher.cmake)
|
||||
add_dependencies(PokemonScriptTester check_git)
|
||||
target_include_directories(PokemonScriptTester PRIVATE extern/AngelscriptDebugger/extern/asio-1.18.2/include)
|
||||
|
|
|
@ -12,7 +12,7 @@
|
|||
class BattleFunctions {
|
||||
static CreatureLib::Battling::CreatureParty* CreateSimpleParty(CScriptArray* species, u8 level) {
|
||||
auto* ctx = asGetActiveContext();
|
||||
TestEnvironment* env = static_cast<TestEnvironment*>(ctx->GetUserData());
|
||||
TestEnvironment* env = static_cast<TestEnvironment*>(ctx->GetUserData(684));
|
||||
|
||||
auto lib = Globals::Library.GetValue();
|
||||
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,
|
||||
const ArbUt::StringView& species2, u8 level) {
|
||||
auto* ctx = asGetActiveContext();
|
||||
TestEnvironment* env = static_cast<TestEnvironment*>(ctx->GetUserData());
|
||||
TestEnvironment* env = static_cast<TestEnvironment*>(ctx->GetUserData(684));
|
||||
auto lib = Globals::Library.GetValue();
|
||||
|
||||
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,
|
||||
PkmnLib::Battling::PokemonParty* p2) {
|
||||
auto* ctx = asGetActiveContext();
|
||||
TestEnvironment* env = static_cast<TestEnvironment*>(ctx->GetUserData());
|
||||
TestEnvironment* env = static_cast<TestEnvironment*>(ctx->GetUserData(684));
|
||||
auto lib = Globals::Library.GetValue();
|
||||
|
||||
auto battle = new PkmnLib::Battling::Battle(
|
||||
|
@ -109,7 +109,7 @@ class BattleFunctions {
|
|||
return false;
|
||||
}
|
||||
auto* ctx = asGetActiveContext();
|
||||
TestEnvironment* env = static_cast<TestEnvironment*>(ctx->GetUserData());
|
||||
TestEnvironment* env = static_cast<TestEnvironment*>(ctx->GetUserData(684));
|
||||
|
||||
auto learnedMove =
|
||||
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);
|
||||
if (script != nullptr) {
|
||||
auto* ctx = asGetActiveContext();
|
||||
TestEnvironment* env = static_cast<TestEnvironment*>(ctx->GetUserData());
|
||||
TestEnvironment* env = static_cast<TestEnvironment*>(ctx->GetUserData(684));
|
||||
env->AddGarbage(script);
|
||||
}
|
||||
auto p = dynamic_cast<AngelScriptScript*>(script);
|
||||
|
@ -21,7 +21,7 @@ class MiscMockFunctions {
|
|||
PkmnLib::Battling::Pokemon* user,
|
||||
PkmnLib::Battling::Pokemon* target) {
|
||||
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);
|
||||
if (!move.has_value()) {
|
||||
|
@ -41,7 +41,7 @@ class MiscMockFunctions {
|
|||
PkmnLib::Battling::Pokemon* user,
|
||||
u8 targetSide, u8 target) {
|
||||
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);
|
||||
if (!move.has_value()) {
|
||||
|
|
|
@ -23,7 +23,7 @@ private:
|
|||
|
||||
static bool Require(bool value) {
|
||||
auto* ctx = asGetActiveContext();
|
||||
TestEnvironment* env = static_cast<TestEnvironment*>(ctx->GetUserData());
|
||||
TestEnvironment* env = static_cast<TestEnvironment*>(ctx->GetUserData(684));
|
||||
env->TotalRequirements += 1;
|
||||
if (!value) {
|
||||
env->FailedRequirements += 1;
|
||||
|
@ -43,7 +43,7 @@ private:
|
|||
|
||||
static bool RequireEqualsI32(i32 expected, i32 actual) {
|
||||
auto* ctx = asGetActiveContext();
|
||||
TestEnvironment* env = static_cast<TestEnvironment*>(ctx->GetUserData());
|
||||
TestEnvironment* env = static_cast<TestEnvironment*>(ctx->GetUserData(684));
|
||||
env->TotalRequirements += 1;
|
||||
if (expected != actual) {
|
||||
env->FailedRequirements += 1;
|
||||
|
@ -56,7 +56,7 @@ private:
|
|||
|
||||
static bool RequireEqualsString(const std::string& expected, const std::string& actual) {
|
||||
auto* ctx = asGetActiveContext();
|
||||
TestEnvironment* env = static_cast<TestEnvironment*>(ctx->GetUserData());
|
||||
TestEnvironment* env = static_cast<TestEnvironment*>(ctx->GetUserData(684));
|
||||
if (expected != actual) {
|
||||
env->FailedRequirements += 1;
|
||||
auto data = GetRequirementData(ctx);
|
||||
|
|
|
@ -13,8 +13,17 @@ public:
|
|||
void Run(asIScriptContext* ctx) {
|
||||
ctx->PushState();
|
||||
ctx->Prepare(_function);
|
||||
ctx->SetUserData(_env.get());
|
||||
ctx->SetUserData(_env.get(), 684);
|
||||
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();
|
||||
if (e == asEXECUTION_EXCEPTION) {
|
||||
_errorMessage = ctx->GetExceptionString();
|
||||
|
@ -23,7 +32,6 @@ public:
|
|||
return;
|
||||
}
|
||||
ctx->PopState();
|
||||
Ensure(e == asEXECUTION_FINISHED);
|
||||
_result = TestResult::Success;
|
||||
}
|
||||
|
||||
|
|
|
@ -2,14 +2,17 @@
|
|||
#define POKEMONSCRIPTTESTER_TESTRUNNER_HPP
|
||||
|
||||
#include <PkmnLib/ScriptResolving/AngelScript/AngelScriptMetadata.hpp>
|
||||
#include <PkmnLib/ScriptResolving/AngelScript/ContextPool.hpp>
|
||||
#include "../../extern/AngelscriptDebugger/src/AngelscriptDebugger.hpp"
|
||||
#include "../../extern/termcolor.hpp"
|
||||
#include "Test.hpp"
|
||||
|
||||
class TestRunner {
|
||||
AngelScriptResolver* _scriptResolver;
|
||||
ArbUt::Dictionary<std::string, std::unique_ptr<Test>> _tests;
|
||||
|
||||
public:
|
||||
TestRunner(AngelScriptResolver* scriptResolver) {
|
||||
TestRunner(AngelScriptResolver* scriptResolver) : _scriptResolver(scriptResolver) {
|
||||
const auto* module = scriptResolver->GetMainModule();
|
||||
auto builder = scriptResolver->GetBuilder();
|
||||
for (u32 i = 0; i < module->GetFunctionCount(); ++i) {
|
||||
|
@ -30,8 +33,20 @@ public:
|
|||
}
|
||||
}
|
||||
|
||||
i32 RunAll(asIScriptEngine* engine) {
|
||||
auto ctx = engine->CreateContext();
|
||||
i32 RunAll(bool waitForDebugger) {
|
||||
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) {
|
||||
test.second->Run(ctx);
|
||||
}
|
||||
|
|
|
@ -23,6 +23,7 @@ int main(int argc, char** argv) {
|
|||
{"workdir"});
|
||||
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 waitForDebuggerFlag(parser, "wait-for-debugger", "Whether to wait until a debugger is connected or not.", {'w', "wait-for-debugger"});
|
||||
try {
|
||||
parser.ParseCLI(argc, argv);
|
||||
} catch (args::Help&) {
|
||||
|
@ -71,9 +72,8 @@ int main(int argc, char** argv) {
|
|||
}
|
||||
auto* scriptResolver = dynamic_cast<AngelScriptResolver*>(Globals::Library.GetValue()->GetScriptResolver().get());
|
||||
auto testRunner = TestRunner(scriptResolver);
|
||||
auto* engine = scriptResolver->GetBuilder().GetEngine();
|
||||
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::cout << std::endl
|
||||
<< "Total Run time: " << std::chrono::duration_cast<std::chrono::milliseconds>(end - begin).count()
|
||||
|
|
Loading…
Reference in New Issue