diff options
author | Matthieu Coudron <886074+teto@users.noreply.github.com> | 2024-01-22 23:11:46 +0100 |
---|---|---|
committer | Matthieu Coudron <886074+teto@users.noreply.github.com> | 2024-02-06 23:21:41 +0100 |
commit | ff5b2d7d00327321496052c87608b6d3f7f6d1ad (patch) | |
tree | cee940025582fb65f621e269bad0c462ec428cca /pkgs/development/interpreters | |
parent | 8656de96730d6dc61f12005c844ccbc2ba02f22a (diff) |
lua.tests: add test for relative import
better error message as well extracted from https://github.com/NixOS/nixpkgs/pull/273342 written by heyarne
Diffstat (limited to 'pkgs/development/interpreters')
-rw-r--r-- | pkgs/development/interpreters/lua-5/default.nix | 2 | ||||
-rw-r--r-- | pkgs/development/interpreters/lua-5/tests/assert.sh | 11 | ||||
-rw-r--r-- | pkgs/development/interpreters/lua-5/tests/default.nix | 26 |
3 files changed, 31 insertions, 8 deletions
diff --git a/pkgs/development/interpreters/lua-5/default.nix b/pkgs/development/interpreters/lua-5/default.nix index ce91b024ce841..bbd93c725f731 100644 --- a/pkgs/development/interpreters/lua-5/default.nix +++ b/pkgs/development/interpreters/lua-5/default.nix @@ -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; }; diff --git a/pkgs/development/interpreters/lua-5/tests/assert.sh b/pkgs/development/interpreters/lua-5/tests/assert.sh index fe5582a0b0623..c5783a24b2d7b 100644 --- a/pkgs/development/interpreters/lua-5/tests/assert.sh +++ b/pkgs/development/interpreters/lua-5/tests/assert.sh @@ -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 } diff --git a/pkgs/development/interpreters/lua-5/tests/default.nix b/pkgs/development/interpreters/lua-5/tests/default.nix index 38479af5f2070..7351fb7cd6f4d 100644 --- a/pkgs/development/interpreters/lua-5/tests/default.nix +++ b/pkgs/development/interpreters/lua-5/tests/default.nix @@ -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 + ''); +}) |