From 3f0f3028321154cbacecd6690833d0e8c805ccd8 Mon Sep 17 00:00:00 2001 From: Hisham Muhammad Date: Wed, 28 Feb 2024 11:49:34 -0300 Subject: feat: more informative reports no bad LUA_{INC,LIB}DIR configs --- spec/cmd_spec.lua | 6 ---- spec/quick/cmd.q | 36 ++++++++++++++++++++ spec/quick/config.q | 90 +++++++++++++++++++++++++++++++++++++++++++++++--- spec/util/quick.lua | 2 +- spec/util/test_env.lua | 17 ++++++---- 5 files changed, 132 insertions(+), 19 deletions(-) create mode 100644 spec/quick/cmd.q (limited to 'spec') diff --git a/spec/cmd_spec.lua b/spec/cmd_spec.lua index 9067a160..20248af7 100644 --- a/spec/cmd_spec.lua +++ b/spec/cmd_spec.lua @@ -56,12 +56,6 @@ describe("LuaRocks command line #integration", function() assert.match("malformed", output, 1, true) end) - it("warns but continues if given an invalid version", function() - local output = run.luarocks("--lua-version=1.0") - assert.match("LUA *: %(not found%)", output) - assert.match("Version%s*:%s*1.0", output) - end) - it("sets the version independently of project tree", function() test_env.run_in_tmp(function(tmpdir) assert.truthy(run.luarocks_bool("init --lua-version=" .. test_env.lua_version .. " --lua-versions=" .. test_env.lua_version)) diff --git a/spec/quick/cmd.q b/spec/quick/cmd.q new file mode 100644 index 00000000..acde92b4 --- /dev/null +++ b/spec/quick/cmd.q @@ -0,0 +1,36 @@ +SUITE: luarocks CLI + +================================================================================ +TEST: warns but continues if given an invalid version + +RUN: luarocks --lua-version 1.0 + +STDOUT: +-------------------------------------------------------------------------------- +Version : 1.0 +LUA : (interpreter not found) +-------------------------------------------------------------------------------- + + + +================================================================================ +TEST: reports if lua.h header is not found + +RUN: luarocks LUA_INCDIR=/bad/dir + +STDOUT: +-------------------------------------------------------------------------------- +LUA_INCDIR : /bad/dir (lua.h not found) +-------------------------------------------------------------------------------- + + + +================================================================================ +TEST: reports if Lua library is not found + +RUN: luarocks LUA_LIBDIR=/bad/dir + +STDOUT: +-------------------------------------------------------------------------------- +LUA_LIBDIR : /bad/dir (Lua library itself not found) +-------------------------------------------------------------------------------- diff --git a/spec/quick/config.q b/spec/quick/config.q index 3150a9ce..d6230567 100644 --- a/spec/quick/config.q +++ b/spec/quick/config.q @@ -1,13 +1,11 @@ -================================================================================ -TEST: luarocks config --system-config shows the path of the system config +SUITE: luarocks config -MKDIR: %{testing_lrprefix}/etc/luarocks +================================================================================ +TEST: --system-config shows the path of the system config FILE: %{testing_lrprefix}/etc/luarocks/config-%{LUA_VERSION}.lua -------------------------------------------------------------------------------- - -------------------------------------------------------------------------------- - RUN: luarocks config --system-config STDOUT: @@ -15,3 +13,85 @@ STDOUT: %{path(%{testing_lrprefix}/etc/luarocks/config-%{LUA_VERSION}.lua)} -------------------------------------------------------------------------------- + + +================================================================================ +TEST: reports when setting a bad LUA_LIBDIR + +RUN: luarocks config variables.LUA_LIBDIR /some/bad/path + +LuaRocks writes configuration values as they are given, without auto-conversion +of slashes for Windows: + +STDOUT: +-------------------------------------------------------------------------------- +Wrote +variables.LUA_LIBDIR = "/some/bad/path" +-------------------------------------------------------------------------------- + +STDERR: +-------------------------------------------------------------------------------- +Warning: Failed finding the Lua library. +Tried: + +LuaRocks may not work correctly when building C modules using this configuration. +-------------------------------------------------------------------------------- + + + +================================================================================ +TEST: reports when setting a bad LUA_INCDIR + +RUN: luarocks config variables.LUA_INCDIR /some/bad/path + +STDOUT: +-------------------------------------------------------------------------------- +Wrote +variables.LUA_INCDIR = "/some/bad/path" +-------------------------------------------------------------------------------- + +LuaRocks uses configuration values as they are given, without auto-conversion +of slashes for Windows: + +STDERR: +-------------------------------------------------------------------------------- +Warning: Failed finding Lua header lua.h (searched at /some/bad/path). You may need to install Lua development headers. + +LuaRocks may not work correctly when building C modules using this configuration. +-------------------------------------------------------------------------------- + + + +================================================================================ +TEST: rejects setting bad lua_dir + +RUN: luarocks config lua_dir /some/bad/dir +EXIT: 1 + +STDERR: +-------------------------------------------------------------------------------- +Lua interpreter not found +-------------------------------------------------------------------------------- + + + +================================================================================ +TEST: reports when setting a bad LUA_INCDIR + +RUN: luarocks config variables.LUA_INCDIR /some/bad/path + +STDOUT: +-------------------------------------------------------------------------------- +Wrote +variables.LUA_INCDIR = "/some/bad/path" +-------------------------------------------------------------------------------- + +LuaRocks uses configuration values as they are given, without auto-conversion +of slashes for Windows: + +STDERR: +-------------------------------------------------------------------------------- +Warning: Failed finding Lua header lua.h (searched at /some/bad/path). You may need to install Lua development headers. + +LuaRocks may not work correctly when building C modules using this configuration. +-------------------------------------------------------------------------------- diff --git a/spec/util/quick.lua b/spec/util/quick.lua index cb4bb4cf..c313f575 100644 --- a/spec/util/quick.lua +++ b/spec/util/quick.lua @@ -347,7 +347,7 @@ function quick.compile(filename, env) write(([=[ ok, err = make_dir(%q) ]=]):format(op.file)) write(([=[ assert.truthy((lfs.attributes(%q) or {}).mode == "directory", error_message(%d, "MKDIR failed: " .. %q .. " - " .. (err or "") )) ]=]):format(op.file, op.line, op.file)) elseif op.op == "RUN" then - local cmd_helper = cmd_helpers[op.program] or op.program + local cmd_helper = cmd_helpers[op.program] or ("%q"):format(op.program) local redirs = " 1>stdout.txt 2>stderr.txt " write(([=[ local ok, _, code = os.execute(%s .. " " .. %q .. %q) ]=]):format(cmd_helper, op.args, redirs)) write([=[ if type(ok) == "number" then code = (ok >= 256 and ok / 256 or ok) end ]=]) diff --git a/spec/util/test_env.lua b/spec/util/test_env.lua index 24a1de9e..8ccb494b 100644 --- a/spec/util/test_env.lua +++ b/spec/util/test_env.lua @@ -207,13 +207,16 @@ function test_env.run_in_tmp(f, finally) end fs.change_dir(tmpdir) - if finally then - finally(function() - lfs.chdir(olddir) - lfs.rmdir(tmpdir) - fs.change_dir(olddir) - end) - end + local lr_config = test_env.env_variables.LUAROCKS_CONFIG + + test_env.copy(lr_config, lr_config .. ".bak") + + finally(function() + test_env.copy(lr_config .. ".bak", lr_config) + lfs.chdir(olddir) + lfs.rmdir(tmpdir) + fs.change_dir(olddir) + end) f(tmpdir) end -- cgit v1.2.3-55-g6feb