diff options
| author | Hisham Muhammad <hisham@gobolinux.org> | 2019-06-03 13:56:20 -0300 |
|---|---|---|
| committer | Hisham Muhammad <hisham@gobolinux.org> | 2019-06-03 18:48:42 -0300 |
| commit | a61d362c5a78edfe7a0f6662747934f0a2124603 (patch) | |
| tree | 6a3f7adc31f98a48caa8a5865badd6e6f7da74f9 | |
| parent | b0969db58997eea6b8f1a31a353384727b23a392 (diff) | |
| download | luarocks-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.lua | 34 | ||||
| -rw-r--r-- | src/luarocks/cmd.lua | 2 |
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 @@ | |||
| 1 | local test_env = require("spec.util.test_env") | ||
| 2 | local run = test_env.run | ||
| 3 | |||
| 4 | test_env.unload_luarocks() | ||
| 5 | |||
| 6 | describe("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 | |||
| 34 | 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, ...) | |||
| 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) |
