diff options
author | Matthieu Coudron <mcoudron@hotmail.com> | 2022-04-01 04:27:53 +0200 |
---|---|---|
committer | Matthieu Coudron <teto@users.noreply.github.com> | 2022-10-14 00:10:40 +0200 |
commit | c4b5c2574b6877d84a7bf5c2e57c85fc6cdd41bb (patch) | |
tree | 6c6b0285c5ce927996e8b7f704fdfde5a5797f44 /pkgs/development/interpreters/lua-5 | |
parent | 648fa5e8f79fb8832529a1f57d46579d918ff9db (diff) |
lua: test the interpreter
Test with: nix-build -A lua.tests pass Tests are very limited for now, goal is mostly to put the infra into place and enrich the tests when dealing with lua issues. add luaPath/luaCpath as passthrough makes it easier to generate LUA_PATH/LUA_CPATH
Diffstat (limited to 'pkgs/development/interpreters/lua-5')
4 files changed, 70 insertions, 0 deletions
diff --git a/pkgs/development/interpreters/lua-5/default.nix b/pkgs/development/interpreters/lua-5/default.nix index d236252e5bc72..478c5bdb34db8 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 0000000000000..fe5582a0b0623 --- /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 0000000000000..38479af5f2070 --- /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 b9ac255d24329..9431522b71e5d 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 ]; |