liminix

Unnamed repository; edit this file 'description' to name the repository.
Log | Files | Refs | README | LICENSE

commit b475a680fb6c7aa4a9dc23d9ae026be6ba731530
parent 43612af71afa43894a9e5d7451f396242506bbb6
Author: Daniel Barlow <dan@telent.net>
Date:   Sat, 24 Aug 2024 21:50:30 +0100

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

Diffstat:
Mpkgs/anoia/assert.fnl | 6+++++-
Mpkgs/fennelrepl/default.nix | 19+++++++++++++++----
2 files changed, 20 insertions(+), 5 deletions(-)

diff --git a/pkgs/anoia/assert.fnl b/pkgs/anoia/assert.fnl @@ -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= } diff --git a/pkgs/fennelrepl/default.nix b/pkgs/fennelrepl/default.nix @@ -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 ''