Files
simian/tests/script_engine_tests.cpp
T
nick 3e23f7da8e
CI / build-and-test (push) Failing after 10m16s
CI / build-and-test (pull_request) Successful in 3m2s
feat: added physFS
2026-03-11 16:43:36 +13:00

70 lines
1.9 KiB
C++

#define TEST_NO_MAIN
#include "acutest.h"
#include <filesystem>
#include <fstream>
#include "../include/scripting/ScriptEngine.h"
#include "physfs_test_utils.h"
void test_scriptengine_compile_and_call(void) {
std::filesystem::path tmpDir = std::filesystem::current_path() / "tmp_script";
std::filesystem::create_directories(tmpDir);
std::filesystem::path script = tmpDir / "simple.as";
{
std::ofstream ofs(script);
ofs << "float g_x = 0;\n";
ofs << "void Update(float dt) { g_x += dt * 10.0f; }\n";
}
TEST_CHECK(InitPhysFSTest(tmpDir) == true);
TEST_CHECK(MountPhysFSTest(tmpDir, "") == true);
ScriptEngine se;
TEST_CHECK(se.Initialize() == true);
bool ok = se.CompileScript("simple.as");
TEST_CHECK(ok == true);
asIScriptFunction* upd = se.GetUpdateFunction();
TEST_CHECK(upd != nullptr);
se.CallScriptFunction(upd, 0.1f);
se.Shutdown();
ShutdownPhysFSTest();
std::filesystem::remove(script);
std::filesystem::remove(tmpDir);
}
void test_scriptengine_include(void) {
std::filesystem::path tmpDir = std::filesystem::current_path() / "tmp_include";
std::filesystem::create_directories(tmpDir);
std::filesystem::path inc = tmpDir / "inc.as";
{
std::ofstream ofsinc(inc);
ofsinc << "void Included() { Print(\"Included called\"); }\n";
}
std::filesystem::path main = tmpDir / "main.as";
{
std::ofstream ofsmain(main);
ofsmain << "#include \"inc.as\"\n";
ofsmain << "void Update(float dt) { Included(); }\n";
}
TEST_CHECK(InitPhysFSTest(tmpDir) == true);
TEST_CHECK(MountPhysFSTest(tmpDir, "") == true);
ScriptEngine se;
TEST_CHECK(se.Initialize() == true);
bool ok = se.CompileScript("main.as");
TEST_CHECK(ok == true);
se.Shutdown();
ShutdownPhysFSTest();
std::filesystem::remove(inc);
std::filesystem::remove(main);
std::filesystem::remove(tmpDir);
}