diff --git a/pkgs/development/interpreters/lua-5/default.nix b/pkgs/development/interpreters/lua-5/default.nix index d236252e5bc7..478c5bdb34db 100644 --- a/pkgs/development/interpreters/lua-5/default.nix +++ b/pkgs/development/interpreters/lua-5/default.nix @@ -69,6 +69,8 @@ let inherit executable luaversion sourceVersion; luaOnBuild = luaOnBuildForHost.override { inherit packageOverrides; self = luaOnBuild; }; + tests = callPackage ./tests { inherit (luaPackages) wrapLua; }; + inherit luaAttr; }; diff --git a/pkgs/development/interpreters/lua-5/tests/assert.sh b/pkgs/development/interpreters/lua-5/tests/assert.sh new file mode 100644 index 000000000000..fe5582a0b062 --- /dev/null +++ b/pkgs/development/interpreters/lua-5/tests/assert.sh @@ -0,0 +1,16 @@ +# Always failing assertion with a message. +# +# Example: +# fail "It should have been but it wasn't to be" +function fail() { + echo "$1" + exit 1 +} + + +function assertStringEqual { + + if ! diff <(echo "$1") <(echo "$2") ; then + fail "Strings differ" + fi +} diff --git a/pkgs/development/interpreters/lua-5/tests/default.nix b/pkgs/development/interpreters/lua-5/tests/default.nix new file mode 100644 index 000000000000..38479af5f207 --- /dev/null +++ b/pkgs/development/interpreters/lua-5/tests/default.nix @@ -0,0 +1,50 @@ +{ lua +, hello +, wrapLua +, lib, fetchFromGitHub +, fetchFromGitLab +, pkgs +}: +let + + runTest = lua: { name, command }: + pkgs.runCommandLocal "test-${lua.name}" ({ + nativeBuildInputs = [lua]; + meta.platforms = lua.meta.platforms; + }) ('' + source ${./assert.sh} + '' + + command + + "touch $out" + ); + + wrappedHello = hello.overrideAttrs(oa: { + propagatedBuildInputs = [ + wrapLua + lua.pkgs.cjson + ]; + postFixup = '' + wrapLuaPrograms + ''; + }); +in + pkgs.recurseIntoAttrs ({ + + checkAliases = runTest lua { + name = "check-aliases"; + command = '' + generated=$(lua -e 'print(package.path)') + golden_LUA_PATH='./share/lua/${lua.luaversion}/?.lua;./?.lua;./?/init.lua' + + assertStringEqual "$generated" "$golden_LUA_PATH" + ''; + }; + + checkWrapping = pkgs.runCommandLocal "test-${lua.name}" ({ + }) ('' + grep -- 'LUA_PATH=' ${wrappedHello}/bin/hello + touch $out + ''); + +}) + diff --git a/pkgs/development/interpreters/lua-5/wrapper.nix b/pkgs/development/interpreters/lua-5/wrapper.nix index b9ac255d2432..9431522b71e5 100644 --- a/pkgs/development/interpreters/lua-5/wrapper.nix +++ b/pkgs/development/interpreters/lua-5/wrapper.nix @@ -60,6 +60,8 @@ let passthru = lua.passthru // { interpreter = "${env}/bin/lua"; inherit lua; + luaPath = lua.pkgs.lib.genLuaPathAbsStr env; + luaCpath = lua.pkgs.lib.genLuaCPathAbsStr env; env = stdenv.mkDerivation { name = "interactive-${lua.name}-environment"; nativeBuildInputs = [ env ];