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.
This commit is contained in:
teto
2026-01-23 17:32:33 +01:00
parent d37bf8ff6e
commit 3485f095ad
5 changed files with 74 additions and 86 deletions
@@ -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}";
@@ -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
@@ -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 }:
+33 -75
View File
@@ -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: {
+1
View File
@@ -48,6 +48,7 @@ rec {
inherit (callPackage ../development/interpreters/lua-5/hooks { })
luarocksMoveDataFolder
luarocksCheckHook
bustedCheckHook
;
inherit lua;