mirror of
https://github.com/NixOS/nixpkgs.git
synced 2024-11-26 00:43:20 +00:00
lua.tests: add test for relative import
better error message as well extracted from https://github.com/NixOS/nixpkgs/pull/273342 written by heyarne
This commit is contained in:
parent
8656de9673
commit
ff5b2d7d00
@ -71,7 +71,7 @@ let
|
||||
inherit executable luaversion;
|
||||
luaOnBuild = luaOnBuildForHost.override { inherit packageOverrides; self = luaOnBuild; };
|
||||
|
||||
tests = callPackage ./tests { inherit (luaPackages) wrapLua; };
|
||||
tests = callPackage ./tests { lua = self; inherit (luaPackages) wrapLua; };
|
||||
|
||||
inherit luaAttr;
|
||||
};
|
||||
|
@ -8,9 +8,14 @@ function fail() {
|
||||
}
|
||||
|
||||
|
||||
function assertStringEqual {
|
||||
|
||||
function assertStringEqual() {
|
||||
if ! diff <(echo "$1") <(echo "$2") ; then
|
||||
fail "Strings differ"
|
||||
fail "expected \"$1\" to be equal to \"$2\""
|
||||
fi
|
||||
}
|
||||
|
||||
function assertStringContains() {
|
||||
if ! echo "$1" | grep -q "$2" ; then
|
||||
fail "expected \"$1\" to contain \"$2\""
|
||||
fi
|
||||
}
|
||||
|
@ -8,7 +8,7 @@
|
||||
let
|
||||
|
||||
runTest = lua: { name, command }:
|
||||
pkgs.runCommandLocal "test-${lua.name}" ({
|
||||
pkgs.runCommandLocal "test-${lua.name}-${name}" ({
|
||||
nativeBuildInputs = [lua];
|
||||
meta.platforms = lua.meta.platforms;
|
||||
}) (''
|
||||
@ -27,6 +27,10 @@ let
|
||||
wrapLuaPrograms
|
||||
'';
|
||||
});
|
||||
|
||||
luaWithModule = lua.withPackages(ps: [
|
||||
ps.lua-cjson
|
||||
]);
|
||||
in
|
||||
pkgs.recurseIntoAttrs ({
|
||||
|
||||
@ -36,15 +40,29 @@ in
|
||||
generated=$(lua -e 'print(package.path)')
|
||||
golden_LUA_PATH='./share/lua/${lua.luaversion}/?.lua;./?.lua;./?/init.lua'
|
||||
|
||||
assertStringEqual "$generated" "$golden_LUA_PATH"
|
||||
assertStringContains "$generated" "$golden_LUA_PATH"
|
||||
'';
|
||||
};
|
||||
|
||||
checkWrapping = pkgs.runCommandLocal "test-${lua.name}" ({
|
||||
checkWrapping = pkgs.runCommandLocal "test-${lua.name}-wrapping" ({
|
||||
}) (''
|
||||
grep -- 'LUA_PATH=' ${wrappedHello}/bin/hello
|
||||
touch $out
|
||||
'');
|
||||
|
||||
})
|
||||
checkRelativeImports = pkgs.runCommandLocal "test-${lua.name}-relative-imports" ({
|
||||
}) (''
|
||||
source ${./assert.sh}
|
||||
|
||||
lua_vanilla_package_path="$(${lua}/bin/lua -e "print(package.path)")"
|
||||
lua_with_module_package_path="$(${luaWithModule}/bin/lua -e "print(package.path)")"
|
||||
|
||||
assertStringContains "$lua_vanilla_package_path" "./?.lua"
|
||||
assertStringContains "$lua_vanilla_package_path" "./?/init.lua"
|
||||
|
||||
assertStringContains "$lua_with_module_package_path" "./?.lua"
|
||||
assertStringContains "$lua_with_module_package_path" "./?/init.lua"
|
||||
|
||||
touch $out
|
||||
'');
|
||||
})
|
||||
|
Loading…
Reference in New Issue
Block a user