From a61d362c5a78edfe7a0f6662747934f0a2124603 Mon Sep 17 00:00:00 2001 From: Hisham Muhammad Date: Mon, 3 Jun 2019 13:56:20 -0300 Subject: cmd: fix crash if LuaRocks is given a bad LUA_DIR Includes a regression test. --- spec/cmd_spec.lua | 34 ++++++++++++++++++++++++++++++++++ src/luarocks/cmd.lua | 2 ++ 2 files changed, 36 insertions(+) create mode 100644 spec/cmd_spec.lua 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 @@ +local test_env = require("spec.util.test_env") +local run = test_env.run + +test_env.unload_luarocks() + +describe("LuaRocks command line #integration", function() + + setup(function() + test_env.setup_specs() + end) + + describe("--version", function() + it("returns the LuaRocks version", function() + local output = run.luarocks("--version") + assert.match("LuaRocks main command-line interface", output, 1, true) + end) + + it("runs if Lua detection fails", function() + test_env.run_in_tmp(function(tmpdir) + test_env.write_file("bad_config.lua", [[ + variables = { + LUA_DIR = "/bad/lua/dir", + } + ]], finally) + local env = { + LUAROCKS_CONFIG = "bad_config.lua" + } + local output = run.luarocks("--version", env) + assert.match("LuaRocks main command-line interface", output, 1, true) + end, finally) + end) + end) + +end) 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, ...) fs.init() + lua_version = cfg.lua_version + if not lua_found then if cfg.variables.LUA_DIR then local found = util.find_lua(cfg.variables.LUA_DIR, cfg.lua_version) -- cgit v1.2.3-55-g6feb