Files
UnrealLuaDemo/Script/ts/scripts/run-tests.mjs
T

41 lines
1.1 KiB
JavaScript

#!/usr/bin/env node
import * as path from "node:path";
import { spawnSync } from "node:child_process";
const tsRoot = path.resolve(import.meta.dirname, "..");
const luaRoot = path.resolve(tsRoot, "..", "lua");
const luaBin = ["lua5.4", "lua"].find((cmd) => {
const probe = spawnSync(cmd, ["-v"], { encoding: "utf8" });
return probe.status === 0 && /Lua 5\.4/.test((probe.stdout || "") + (probe.stderr || ""));
});
if (!luaBin) {
console.error("[run-tests] Lua 5.4 interpreter (lua5.4 / lua) not found in PATH.");
process.exit(1);
}
const luaPath = [
path.join(luaRoot, "?.lua"),
path.join(luaRoot, "?", "init.lua"),
process.env.LUA_PATH || "",
]
.filter(Boolean)
.join(";");
const code = `
package.path = ${JSON.stringify(luaPath)} .. ";" .. package.path
require("Lib.Module")
require("Lib.Class")
__MODULE__.Import("Tests.Harness.MockUnLuaRuntime").InstallIfNeeded()
_G.__TS2LUA_TEST_AUTO_RUN__ = true
__MODULE__.Import("Tests.RunAllTests")
`;
const result = spawnSync(luaBin, ["-e", code], {
stdio: "inherit",
cwd: luaRoot,
});
process.exit(result.status ?? 1);