about summary refs log tree commit diff
path: root/pkgs/development/interpreters/lua-5
diff options
context:
space:
mode:
authorMatthieu Coudron <886074+teto@users.noreply.github.com>2024-03-06 22:40:01 +0100
committerMatthieu Coudron <886074+teto@users.noreply.github.com>2024-03-16 14:37:10 +0100
commit815d3683f70470e4c1b6c72535576e5e41d731ae (patch)
treef3f86966e072bcc48360afeaf10707bb55781ea3 /pkgs/development/interpreters/lua-5
parent640cdcb814ce7476d002a306816ed9d88baaf4f3 (diff)
lua.tests: update golden values for default LUA_PATH
when LUA_PATH contains `;;`, it is replaced by `;LUA_PATH_DEFAULT;` in
lua 5.1:
Updated https://github.com/lua/lua/blob/69ea087dff1daba25a2000dfb8f1883c17545b7a/loadlib.c#L599
More recent versions might be smarter ?
https://github.com/lua/lua/blob/65b07dd53d7938a60112fc4473f5cad3473e3534/loadlib.c#L301
Diffstat (limited to 'pkgs/development/interpreters/lua-5')
-rw-r--r--pkgs/development/interpreters/lua-5/tests/assert.sh4
-rw-r--r--pkgs/development/interpreters/lua-5/tests/default.nix56
2 files changed, 38 insertions, 22 deletions
diff --git a/pkgs/development/interpreters/lua-5/tests/assert.sh b/pkgs/development/interpreters/lua-5/tests/assert.sh
index c5783a24b2d7b..b0aa3825ef93a 100644
--- a/pkgs/development/interpreters/lua-5/tests/assert.sh
+++ b/pkgs/development/interpreters/lua-5/tests/assert.sh
@@ -3,14 +3,14 @@
 # Example:
 #     fail "It should have been but it wasn't to be"
 function fail() {
-    echo "$1"
+    echo -e "$1"
     exit 1
 }
 
 
 function assertStringEqual() {
     if ! diff <(echo "$1") <(echo "$2") ; then
-        fail "expected \"$1\" to be equal to \"$2\""
+        fail "Actual   value: \"$1\"\nExpected value: \"$2\""
     fi
 }
 
diff --git a/pkgs/development/interpreters/lua-5/tests/default.nix b/pkgs/development/interpreters/lua-5/tests/default.nix
index 7351fb7cd6f4d..6ca6b153c0b62 100644
--- a/pkgs/development/interpreters/lua-5/tests/default.nix
+++ b/pkgs/development/interpreters/lua-5/tests/default.nix
@@ -1,12 +1,10 @@
 { lua
 , hello
 , wrapLua
-, lib, fetchFromGitHub
-, fetchFromGitLab
+, lib
 , pkgs
 }:
 let
-
   runTest = lua: { name, command }:
     pkgs.runCommandLocal "test-${lua.name}-${name}" ({
       nativeBuildInputs = [lua];
@@ -18,29 +16,47 @@ let
     + "touch $out"
     );
 
-    wrappedHello = hello.overrideAttrs(oa: {
-      propagatedBuildInputs = [
-        wrapLua
-        lua.pkgs.cjson
-      ];
-      postFixup = ''
-        wrapLuaPrograms
-      '';
-    });
+  wrappedHello = hello.overrideAttrs(oa: {
+    propagatedBuildInputs = [
+      wrapLua
+      lua.pkgs.cjson
+    ];
+    postFixup = ''
+      wrapLuaPrograms
+    '';
+  });
+
+  luaWithModule = lua.withPackages(ps: [
+    ps.lua-cjson
+  ]);
+
+  golden_LUA_PATHS = {
 
-    luaWithModule = lua.withPackages(ps: [
-      ps.lua-cjson
-    ]);
+    # Looking at lua interpreter 'setpath' code
+    # for instance https://github.com/lua/lua/blob/69ea087dff1daba25a2000dfb8f1883c17545b7a/loadlib.c#L599
+    # replace ";;" by ";LUA_PATH_DEFAULT;"
+    "5.1" = ";./?.lua;${lua}/share/lua/5.1/?.lua;${lua}/share/lua/5.1/?/init.lua;${lua}/lib/lua/5.1/?.lua;${lua}/lib/lua/5.1/?/init.lua;";
+    "5.2" = ";${lua}/share/lua/5.2/?.lua;${lua}/share/lua/5.2/?/init.lua;${lua}/lib/lua/5.2/?.lua;${lua}/lib/lua/5.2/?/init.lua;./?.lua;";
+    "5.3" = ";${lua}/share/lua/5.3/?.lua;${lua}/share/lua/5.3/?/init.lua;${lua}/lib/lua/5.3/?.lua;${lua}/lib/lua/5.3/?/init.lua;./?.lua;./?/init.lua;";
+    # lua5.4 seems to be smarter about it and dont add the lua separators when nothing left or right
+    "5.4" = "${lua}/share/lua/5.4/?.lua;${lua}/share/lua/5.4/?/init.lua;${lua}/lib/lua/5.4/?.lua;${lua}/lib/lua/5.4/?/init.lua;./?.lua;./?/init.lua";
+
+    # luajit versions
+    "2.0" = ";./?.lua;${lua}/share/luajit-2.0/?.lua;/usr/local/share/lua/5.1/?.lua;/usr/local/share/lua/5.1/?/init.lua;${lua}/share/lua/5.1/?.lua;${lua}/share/lua/5.1/?/init.lua;";
+    "2.1" = ";./?.lua;${lua}/share/luajit-2.1/?.lua;/usr/local/share/lua/5.1/?.lua;/usr/local/share/lua/5.1/?/init.lua;${lua}/share/lua/5.1/?.lua;${lua}/share/lua/5.1/?/init.lua;";
+  };
 in
   pkgs.recurseIntoAttrs ({
 
-  checkAliases = runTest lua {
-    name = "check-aliases";
+  checkInterpreterPatch = let
+    golden_LUA_PATH = golden_LUA_PATHS.${lib.versions.majorMinor lua.version};
+  in
+    runTest lua {
+    name = "check-default-lua-path";
     command = ''
+      export LUA_PATH=";;"
       generated=$(lua -e 'print(package.path)')
-      golden_LUA_PATH='./share/lua/${lua.luaversion}/?.lua;./?.lua;./?/init.lua'
-
-      assertStringContains "$generated" "$golden_LUA_PATH"
+      assertStringEqual "$generated" "${golden_LUA_PATH}"
       '';
   };