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:
parent
648fa5e8f7
commit
c4b5c2574b
|
@ -69,6 +69,8 @@ let
|
|||
inherit executable luaversion sourceVersion;
|
||||
luaOnBuild = luaOnBuildForHost.override { inherit packageOverrides; self = luaOnBuild; };
|
||||
|
||||
tests = callPackage ./tests { inherit (luaPackages) wrapLua; };
|
||||
|
||||
inherit luaAttr;
|
||||
};
|
||||
|
||||
|
|
16
pkgs/development/interpreters/lua-5/tests/assert.sh
Normal file
16
pkgs/development/interpreters/lua-5/tests/assert.sh
Normal 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
|
||||
}
|
50
pkgs/development/interpreters/lua-5/tests/default.nix
Normal file
50
pkgs/development/interpreters/lua-5/tests/default.nix
Normal 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
|
||||
'');
|
||||
|
||||
})
|
||||
|
|
@ -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 ];
|
||||
|
|
Loading…
Reference in a new issue