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
This commit is contained in:
Matthieu Coudron 2022-04-01 04:27:53 +02:00 committed by Matthieu Coudron
parent 648fa5e8f7
commit c4b5c2574b
4 changed files with 70 additions and 0 deletions

View file

@ -69,6 +69,8 @@ let
inherit executable luaversion sourceVersion;
luaOnBuild = luaOnBuildForHost.override { inherit packageOverrides; self = luaOnBuild; };
tests = callPackage ./tests { inherit (luaPackages) wrapLua; };
inherit luaAttr;
};

View file

@ -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
}

View file

@ -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
'');
})

View file

@ -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 ];