define-tests macro, evals body only when inside fennelrepl --test

This commit is contained in:
Daniel Barlow 2024-08-24 21:50:30 +01:00
parent 43612af71a
commit b475a680fb
2 changed files with 20 additions and 5 deletions

View File

@ -18,4 +18,8 @@
(.. "\nexpected " ve# "\ngot " va#)
))))
{ : expect : expect= }
(fn define-tests [& body]
(when _G.RUNNING_TESTS
`(do ,(unpack body))))
{ : define-tests : expect : expect= }

View File

@ -27,17 +27,28 @@ in writeScriptBin "fennelrepl" ''
package.path = ${lib.strings.escapeShellArg luapath} .. ";" .. package.path
package.cpath = ${lib.strings.escapeShellArg luacpath} .. ";" .. (package.cpath or "")
local fennel = require "fennel"
local specials = require("fennel.specials")
table.insert(package.loaders or package.searchers,1, fennel.searcher)
fennel['macro-path'] = "${anoia.dev}/share/lua/${lua.luaversion}/?.fnl;" .. fennel['macro-path']
local function eval_as_test(f)
local g = (specials["make-compiler-env"]())._G
g["RUNNING_TESTS"] = true
return fennel.dofile(f, {correlate = true, compilerEnv = g})
end
local more_fennel = os.getenv("FENNEL_PATH")
if more_fennel then
fennel.path = more_fennel .. ";" .. fennel.path
fennel.path = more_fennel .. ";" .. fennel.path
end
if #arg > 0 then
script = table.remove(arg, 1)
fennel.dofile(script, {correlate = true}, arg)
if arg[1] == '--test' then
eval_as_test(arg[2])
else
script = table.remove(arg, 1)
fennel.dofile(script, {correlate = true}, arg)
end
else
fennel.repl()
fennel.repl()
end
''