diff --git a/pkgs/development/interpreters/lua-5/build-luarocks-package.nix b/pkgs/development/interpreters/lua-5/build-luarocks-package.nix index 34ae41e993cf..722ddfaed6f2 100644 --- a/pkgs/development/interpreters/lua-5/build-luarocks-package.nix +++ b/pkgs/development/interpreters/lua-5/build-luarocks-package.nix @@ -100,7 +100,8 @@ let lua # for lua.h wrapLua luarocks_bootstrap - ]; + ] + ++ lib.optionals self.doCheck self.nativeCheckInputs; inherit doCheck @@ -116,10 +117,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 ]; @@ -228,12 +226,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 bd6ed85c39ce..7008f98d6de0 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 { @@ -584,16 +571,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" ''; }); @@ -764,44 +754,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: { @@ -885,16 +858,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 { @@ -1010,13 +984,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: { @@ -1033,39 +1003,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;