Avoid globbing target dir every test

This commit is contained in:
lumi 2025-06-27 04:45:53 +10:00
parent 3a7f2366e4
commit eb7b05d07a
Signed by: luaneko
GPG Key ID: 406809B8763FF07A
3 changed files with 19 additions and 9 deletions

View File

@ -31,7 +31,7 @@ dev.panic = "abort"
release.panic = "abort"
[[test]]
name = "main"
name = "test"
harness = false
[features]

View File

@ -1,5 +1,10 @@
if (...) ~= nil and (...).type == "group" then return end -- prevent recursive main call
local fs = require("lb:fs")
if (...) ~= nil and (...).type == "group" then return end -- prevent recursive harness call
local ok = pcall(require, "lb:task")
if not ok then error("lua test harness requires lb:task module") end
local ok, fs = pcall(require, "lb:fs")
if not ok then error("lua test harness requires lb:fs module") end
local global = _G
local colors = {
reset = "\x1b[0m",
@ -88,10 +93,15 @@ local function run(item)
end
return run(create_group("", function()
for entry in fs:glob("{tests,crates/*/tests}/**/*.lua") do
local path = entry:path():sub(3)
local f, err = loadfile(path)
if not f then error(err) end
describe(path, f)
local function glob(path, pat)
for entry in fs:glob_dir(path, pat) do
local path = entry:path()
local f, err = loadfile(path)
if not f then error(err) end
describe(path, f)
end
end
glob("tests", "**/*.lua")
glob("crates", "*/tests/**/*.lua")
end))

View File

@ -13,7 +13,7 @@ fn main() -> ExitCode {
rt.unhandled_error(error_cb).build().unwrap()
};
let path = "tests/main.lua";
let path = "tests/test.lua";
let main = lua.spawn(async move |s| {
if let Err(ref err) = s.load(Chunk::new(fs::read(path).unwrap()).path(path)) {
s.report_error(err);