nixpkgs mirror (for testing) github.com/NixOS/nixpkgs
nix
at haskell-updates 128 lines 4.1 kB view raw
1{ 2 lua, 3 hello, 4 wrapLua, 5 lib, 6 pkgs, 7}: 8let 9 runTest = 10 lua: 11 { name, command }: 12 pkgs.runCommandLocal "test-${lua.name}-${name}" 13 { 14 nativeBuildInputs = [ lua ]; 15 meta.platforms = lua.meta.platforms; 16 } 17 ( 18 '' 19 source ${./assert.sh} 20 '' 21 + command 22 + "touch $out" 23 ); 24 25 wrappedHello = hello.overrideAttrs { 26 propagatedBuildInputs = [ 27 wrapLua 28 lua.pkgs.cjson 29 ]; 30 postFixup = '' 31 wrapLuaPrograms 32 ''; 33 }; 34 35 luaWithModule = lua.withPackages (ps: [ 36 ps.lua-cjson 37 ]); 38 39 golden_LUA_PATHS = { 40 41 # Looking at lua interpreter 'setpath' code 42 # for instance https://github.com/lua/lua/blob/69ea087dff1daba25a2000dfb8f1883c17545b7a/loadlib.c#L599 43 # replace ";;" by ";LUA_PATH_DEFAULT;" 44 "5.1" = 45 ";./?.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;"; 46 "5.2" = 47 ";${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;"; 48 "5.3" = 49 ";${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;"; 50 # lua > 5.4 seems to be smarter about it and dont add the lua separators when nothing left or right 51 "5.4" = 52 "${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"; 53 "5.5" = 54 "${lua}/share/lua/5.5/?.lua;${lua}/share/lua/5.5/?/init.lua;${lua}/lib/lua/5.5/?.lua;${lua}/lib/lua/5.5/?/init.lua;./?.lua;./?/init.lua"; 55 56 # luajit versions 57 "2.0" = 58 ";./?.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;"; 59 "2.1" = 60 ";./?.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;"; 61 }; 62in 63lib.recurseIntoAttrs { 64 65 checkInterpreterPath = 66 let 67 golden_LUA_PATH = golden_LUA_PATHS.${lib.versions.majorMinor lua.version}; 68 in 69 runTest lua { 70 name = "check-default-lua-path"; 71 command = '' 72 export LUA_PATH=";;" 73 generated=$(lua -e 'print(package.path)') 74 assertStringEqual "$generated" "${golden_LUA_PATH}" 75 ''; 76 }; 77 78 checkWrapping = pkgs.runCommandLocal "test-${lua.name}-wrapping" { } '' 79 grep -- 'LUA_PATH=' ${wrappedHello}/bin/hello 80 touch $out 81 ''; 82 83 # checks that lua's setup-hook adds dependencies to LUA_PATH 84 # Prevents the following regressions 85 # $ env NIX_PATH=nixpkgs=. nix-shell --pure -Q -p luajitPackages.lua luajitPackages.alt-getopt 86 # nix-shell$ luajit 87 # > require('alt-getopt') 88 # stdin:1: module 'alt-getopt' not found: 89 checkSetupHook = 90 pkgs.runCommandLocal "test-${lua.name}-setup-hook" 91 { 92 nativeBuildInputs = [ lua ]; 93 buildInputs = [ lua.pkgs.alt-getopt ]; 94 meta.platforms = lua.meta.platforms; 95 } 96 '' 97 ${lua}/bin/lua -e "require'alt_getopt'" 98 touch $out 99 ''; 100 101 checkRelativeImports = pkgs.runCommandLocal "test-${lua.name}-relative-imports" { } '' 102 source ${./assert.sh} 103 104 lua_vanilla_package_path="$(${lua}/bin/lua -e "print(package.path)")" 105 lua_with_module_package_path="$(${luaWithModule}/bin/lua -e "print(package.path)")" 106 107 assertStringContains "$lua_vanilla_package_path" "./?.lua" 108 assertStringContains "$lua_vanilla_package_path" "./?/init.lua" 109 110 assertStringContains "$lua_with_module_package_path" "./?.lua" 111 assertStringContains "$lua_with_module_package_path" "./?/init.lua" 112 113 touch $out 114 ''; 115 116 # Check that a lua package's propagatedBuildInputs end up in LUA_PATH 117 checkPropagatedBuildInputs = 118 pkgs.runCommandLocal "test-${lua.name}-setup-hook" 119 { 120 buildInputs = [ lua.pkgs.luacov ]; 121 } 122 # `datafile` is a propagatedBuildInput of luacov 123 '' 124 ${lua}/bin/lua -e "require'datafile'" 125 touch $out 126 ''; 127 128}