From 3485f095ade58a51e40b106fcfdf97c6a1b0aa87 Mon Sep 17 00:00:00 2001 From: teto <886074+teto@users.noreply.github.com> Date: Mon, 19 Jan 2026 22:33:16 +0100 Subject: [PATCH] bustedCheckHook: init and convert luaPackages to use it - add bustedCheckHook in the nativeCheckInputs and busted will run when doCheck is enabled. You can customize its call via "bustedFlags" and prevent it from running with "dontBustedCheck". If "nlua" is available, busted will automatically run busted with nlua as interpreter (already done in lux). Goal is to standardize the writing of tests so that if feels less like copy & paste. - removed the default checkPhase from buildLuarocksPackage which was running "luarocks test". None of the plugins was using as far as I know because no plugin out there (maybe 2 or 3) uses that ? it could be considered a breaking change but in practice I dont think it is. --- .../lua-5/build-luarocks-package.nix | 14 +-- .../lua-5/hooks/busted-check-hook.sh | 24 ++++ .../interpreters/lua-5/hooks/default.nix | 13 +++ pkgs/development/lua-modules/overrides.nix | 108 ++++++------------ pkgs/top-level/lua-packages.nix | 1 + 5 files changed, 74 insertions(+), 86 deletions(-) create mode 100644 pkgs/development/interpreters/lua-5/hooks/busted-check-hook.sh diff --git a/pkgs/development/interpreters/lua-5/build-luarocks-package.nix b/pkgs/development/interpreters/lua-5/build-luarocks-package.nix index 736c9463521f..d692f069e1d2 100644 --- a/pkgs/development/interpreters/lua-5/build-luarocks-package.nix +++ b/pkgs/development/interpreters/lua-5/build-luarocks-package.nix @@ -99,7 +99,8 @@ let lua # for lua.h wrapLua luarocks_bootstrap - ]; + ] + ++ lib.optionals self.doCheck self.nativeCheckInputs; inherit doCheck @@ -115,10 +116,7 @@ let # example externalDeps': [ { name = "CRYPTO"; dep = pkgs.openssl; } ] externalDeps' = lib.filter (dep: !lib.isDerivation dep) self.externalDeps; in - [ luarocks_bootstrap ] - ++ buildInputs - ++ lib.optionals self.doCheck ([ luarocksCheckHook ] ++ self.nativeCheckInputs) - ++ (map (d: d.dep) externalDeps'); + [ luarocks_bootstrap ] ++ buildInputs ++ (map (d: d.dep) externalDeps'); # propagate lua to active setup-hook in nix-shell propagatedBuildInputs = propagatedBuildInputs ++ [ lua ]; @@ -227,12 +225,6 @@ let runHook postInstall ''; - checkPhase = '' - runHook preCheck - luarocks test - runHook postCheck - ''; - shellHook = '' runHook preShell export LUAROCKS_CONFIG="$PWD/${luarocks_config}"; diff --git a/pkgs/development/interpreters/lua-5/hooks/busted-check-hook.sh b/pkgs/development/interpreters/lua-5/hooks/busted-check-hook.sh new file mode 100644 index 000000000000..e8de6f0af522 --- /dev/null +++ b/pkgs/development/interpreters/lua-5/hooks/busted-check-hook.sh @@ -0,0 +1,24 @@ +# hook for running busted +# shellcheck shell=bash +echo "Sourcing busted-check-hook.sh" + +bustedCheckPhase () { + echo "Executing bustedCheckPhase" + runHook preCheck + + if command -v nlua && [ -z "${bustedNoNlua-}" ]; then + bustedFlags+=("--lua=nlua") + fi + + busted "${bustedFlags[@]}" + + runHook postCheck + echo "Finished executing bustedCheckPhase" +} + +if [ -z "${dontBustedCheck-}" ] && [ -z "${checkPhase-}" ]; then + echo "Using bustedCheckPhase" + checkPhase+=" bustedCheckPhase" +fi + + diff --git a/pkgs/development/interpreters/lua-5/hooks/default.nix b/pkgs/development/interpreters/lua-5/hooks/default.nix index 9f7396f2a518..318564ba52b1 100644 --- a/pkgs/development/interpreters/lua-5/hooks/default.nix +++ b/pkgs/development/interpreters/lua-5/hooks/default.nix @@ -8,6 +8,19 @@ let callPackage = lua.pkgs.callPackage; in { + /** + Accepts "bustedFlags" as an array. + You can customize the call by setting "bustedFlags" and prevent the test from running by setting "dontBustedCheck" + */ + bustedCheckHook = callPackage ( + { busted }: + makeSetupHook { + name = "busted-check-hook"; + propagatedBuildInputs = [ + busted + ]; + } ./busted-check-hook.sh + ) { }; luarocksCheckHook = callPackage ( { luarocks }: diff --git a/pkgs/development/lua-modules/overrides.nix b/pkgs/development/lua-modules/overrides.nix index ffb76d6fffbc..6bde9ab60f33 100644 --- a/pkgs/development/lua-modules/overrides.nix +++ b/pkgs/development/lua-modules/overrides.nix @@ -75,14 +75,10 @@ in # keep-sorted start block=yes case=no newline_separated=yes argparse = prev.argparse.overrideAttrs { doCheck = true; - nativeCheckInputs = [ final.busted ]; + nativeCheckInputs = [ final.bustedCheckHook ]; - checkPhase = '' - runHook preCheck - export LUA_PATH="src/?.lua;$LUA_PATH" - busted spec/ - runHook postCheck - ''; + preCheck = ''LUA_PATH="src/?.lua;$LUA_PATH"''; + bustedFlags = [ "spec/" ]; }; busted = prev.busted.overrideAttrs (old: { @@ -195,12 +191,8 @@ in fzy = prev.fzy.overrideAttrs { doCheck = true; - nativeCheckInputs = [ final.busted ]; - # Until https://github.com/swarn/fzy-lua/pull/8 is merged, - # we have to invoke busted manually - checkPhase = '' - busted - ''; + nativeCheckInputs = [ final.bustedCheckHook ]; + # bustedFlags = [ "." ]; }; grug-far-nvim = prev.grug-far-nvim.overrideAttrs { @@ -241,14 +233,9 @@ in doCheck = lua.luaversion == "5.1"; nativeCheckInputs = [ final.nlua - final.busted + final.bustedCheckHook writableTmpDirAsHomeHook ]; - checkPhase = '' - runHook preCheck - busted --lua=nlua - runHook postCheck - ''; }; image-nvim = prev.image-nvim.overrideAttrs { @@ -581,16 +568,19 @@ in lualine-nvim = prev.lualine-nvim.overrideAttrs (_: { doCheck = lua.luaversion == "5.1"; nativeCheckInputs = [ - final.nlua - final.busted final.nvim-web-devicons + final.bustedCheckHook + final.nlua gitMinimal writableTmpDirAsHomeHook ]; - checkPhase = '' - runHook preCheck - busted --lua=nlua --lpath='lua/?.lua' --lpath='lua/?/init.lua' tests/ - runHook postCheck + + bustedFlags = [ + "tests/" + ]; + + preCheck = '' + LUA_PATH="lua/?.lua;lua/?/init.lua;$LUA_PATH" ''; }); @@ -761,44 +751,27 @@ in doCheck = lua.luaversion == "5.1"; nativeCheckInputs = [ final.nlua - final.busted + final.bustedCheckHook writableTmpDirAsHomeHook ]; - checkPhase = '' - runHook preCheck - busted --lua=nlua - runHook postCheck - ''; }; lze = prev.lze.overrideAttrs { doCheck = lua.luaversion == "5.1"; nativeCheckInputs = [ final.nlua - final.busted + final.bustedCheckHook writableTmpDirAsHomeHook ]; - checkPhase = '' - runHook preCheck - busted --lua=nlua - runHook postCheck - ''; }; lzextras = prev.lzextras.overrideAttrs { doCheck = lua.luaversion == "5.1"; - checkInputs = [ - final.lze - ]; nativeCheckInputs = [ final.nlua - final.busted + lua.pkgs.bustedCheckHook + final.lze ]; - checkPhase = '' - runHook preCheck - busted --lua=nlua - runHook postCheck - ''; }; magick = prev.magick.overrideAttrs (old: { @@ -878,16 +851,17 @@ in doCheck = lua.luaversion == "5.1"; nativeCheckInputs = [ final.nlua - final.busted + # upstream uses PlenaryBusted which is a pain, run busted directly instead + final.bustedCheckHook writableTmpDirAsHomeHook ]; - # upstream uses PlenaryBusted which is a pain to setup - checkPhase = '' - runHook preCheck - busted --lua=nlua --lpath='lua/?.lua' --lpath='lua/?/init.lua' tests/ - runHook postCheck + preCheck = '' + LUA_PATH="lua/?.lua;lua/?/init.lua;$LUA_PATH" ''; + bustedFlags = [ + "tests/" + ]; }; orgmode = prev.orgmode.overrideAttrs { @@ -998,13 +972,9 @@ in doCheck = luaOlder "5.2"; nativeCheckInputs = [ final.nlua - final.busted + final.bustedCheckHook ]; - checkPhase = '' - runHook preCheck - busted spec - runHook postCheck - ''; + bustedFlags = [ "spec" ]; }; rocks-nvim = prev.rocks-nvim.overrideAttrs (oa: { @@ -1021,39 +991,27 @@ in "bootstrap" # tries to install luarocks from network ]; - checkPhase = '' - runHook preCheck - busted --run=offline - runHook postCheck - ''; + bustedFlags = [ + "--run=offline" + ]; }); rtp-nvim = prev.rtp-nvim.overrideAttrs { doCheck = lua.luaversion == "5.1"; nativeCheckInputs = [ final.nlua - final.busted + final.bustedCheckHook writableTmpDirAsHomeHook ]; - checkPhase = '' - runHook preCheck - busted --lua=nlua - runHook postCheck - ''; }; rustaceanvim = prev.rustaceanvim.overrideAttrs { doCheck = lua.luaversion == "5.1"; nativeCheckInputs = [ final.nlua - final.busted + final.bustedCheckHook writableTmpDirAsHomeHook ]; - checkPhase = '' - runHook preCheck - busted --lua=nlua - runHook postCheck - ''; }; sofa = prev.sofa.overrideAttrs (old: { diff --git a/pkgs/top-level/lua-packages.nix b/pkgs/top-level/lua-packages.nix index bc5b3bb649ae..8a67702ba256 100644 --- a/pkgs/top-level/lua-packages.nix +++ b/pkgs/top-level/lua-packages.nix @@ -48,6 +48,7 @@ rec { inherit (callPackage ../development/interpreters/lua-5/hooks { }) luarocksMoveDataFolder luarocksCheckHook + bustedCheckHook ; inherit lua;