aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorHisham Muhammad <hisham@gobolinux.org>2019-06-03 13:56:20 -0300
committerHisham Muhammad <hisham@gobolinux.org>2019-06-03 18:48:42 -0300
commita61d362c5a78edfe7a0f6662747934f0a2124603 (patch)
tree6a3f7adc31f98a48caa8a5865badd6e6f7da74f9
parentb0969db58997eea6b8f1a31a353384727b23a392 (diff)
downloadluarocks-a61d362c5a78edfe7a0f6662747934f0a2124603.tar.gz
luarocks-a61d362c5a78edfe7a0f6662747934f0a2124603.tar.bz2
luarocks-a61d362c5a78edfe7a0f6662747934f0a2124603.zip
cmd: fix crash if LuaRocks is given a bad LUA_DIR
Includes a regression test.
-rw-r--r--spec/cmd_spec.lua34
-rw-r--r--src/luarocks/cmd.lua2
2 files changed, 36 insertions, 0 deletions
diff --git a/spec/cmd_spec.lua b/spec/cmd_spec.lua
new file mode 100644
index 00000000..70b9625d
--- /dev/null
+++ b/spec/cmd_spec.lua
@@ -0,0 +1,34 @@
1local test_env = require("spec.util.test_env")
2local run = test_env.run
3
4test_env.unload_luarocks()
5
6describe("LuaRocks command line #integration", function()
7
8 setup(function()
9 test_env.setup_specs()
10 end)
11
12 describe("--version", function()
13 it("returns the LuaRocks version", function()
14 local output = run.luarocks("--version")
15 assert.match("LuaRocks main command-line interface", output, 1, true)
16 end)
17
18 it("runs if Lua detection fails", function()
19 test_env.run_in_tmp(function(tmpdir)
20 test_env.write_file("bad_config.lua", [[
21 variables = {
22 LUA_DIR = "/bad/lua/dir",
23 }
24 ]], finally)
25 local env = {
26 LUAROCKS_CONFIG = "bad_config.lua"
27 }
28 local output = run.luarocks("--version", env)
29 assert.match("LuaRocks main command-line interface", output, 1, true)
30 end, finally)
31 end)
32 end)
33
34end)
diff --git a/src/luarocks/cmd.lua b/src/luarocks/cmd.lua
index cb669226..bbbdcba1 100644
--- a/src/luarocks/cmd.lua
+++ b/src/luarocks/cmd.lua
@@ -372,6 +372,8 @@ function cmd.run_command(description, commands, external_namespace, ...)
372 372
373 fs.init() 373 fs.init()
374 374
375 lua_version = cfg.lua_version
376
375 if not lua_found then 377 if not lua_found then
376 if cfg.variables.LUA_DIR then 378 if cfg.variables.LUA_DIR then
377 local found = util.find_lua(cfg.variables.LUA_DIR, cfg.lua_version) 379 local found = util.find_lua(cfg.variables.LUA_DIR, cfg.lua_version)