diff --git a/Cargo.toml b/Cargo.toml index be681a2..309ae38 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -31,7 +31,7 @@ dev.panic = "abort" release.panic = "abort" [[test]] -name = "main" +name = "test" harness = false [features] diff --git a/tests/main.lua b/tests/test.lua similarity index 81% rename from tests/main.lua rename to tests/test.lua index 079ac1f..a3c70e3 100644 --- a/tests/main.lua +++ b/tests/test.lua @@ -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)) diff --git a/tests/main.rs b/tests/test.rs similarity index 96% rename from tests/main.rs rename to tests/test.rs index 3218d22..5d09542 100644 --- a/tests/main.rs +++ b/tests/test.rs @@ -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);