43 lines
1.1 KiB
JavaScript
43 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-unit-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")
|
|
local runner = __MODULE__.Import("tests.run_unit_tests")
|
|
local summary = runner.RunAllUnitTests()
|
|
if not summary or (summary.total or 0) <= 0 or (summary.failed or 0) > 0 then
|
|
os.exit(1)
|
|
end
|
|
`;
|
|
|
|
const result = spawnSync(luaBin, ["-e", code], {
|
|
stdio: "inherit",
|
|
cwd: luaRoot,
|
|
});
|
|
|
|
process.exit(result.status ?? 1);
|