From 0c534c71465474b92710a2951bf15370fcc8c663 Mon Sep 17 00:00:00 2001 From: FYP Date: Sun, 21 Oct 2018 20:46:36 +0300 Subject: cmd: fix setting up deployment paths from a tree (Amended with a regression test.) Co-authored-by: Hisham Muhammad --- spec/config_spec.lua | 17 +++++++++++++++++ src/luarocks/cmd.lua | 10 +++++----- 2 files changed, 22 insertions(+), 5 deletions(-) diff --git a/spec/config_spec.lua b/spec/config_spec.lua index f415909d..defc1d2f 100644 --- a/spec/config_spec.lua +++ b/spec/config_spec.lua @@ -3,6 +3,7 @@ local lfs = require("lfs") local run = test_env.run local testing_paths = test_env.testing_paths local env_variables = test_env.env_variables +local write_file = test_env.write_file local hardcoded test_env.unload_luarocks() @@ -52,6 +53,22 @@ describe("LuaRocks config tests #integration", function() local output = run.luarocks("config --user-config", {LUAROCKS_CONFIG = "missing_file.lua"}) assert.truthy(output:match("Warning")) end) + + it("LuaRocks config with --tree respects custom config", function() + write_file("my_config.lua", [[ + rocks_trees = { + { + name = "system", + root = "/example/tree", + lua_dir = "/example/luadir", + }, + } + ]], finally) + local output = run.luarocks("config", {LUAROCKS_CONFIG = "my_config.lua"}) + assert.match([[deploy_lua_dir = "/example/luadir"]], output) + output = run.luarocks("config --tree=system", {LUAROCKS_CONFIG = "my_config.lua"}) + assert.match([[deploy_lua_dir = "/example/luadir"]], output) + end) end) describe("LuaRocks config - more complex tests", function() diff --git a/src/luarocks/cmd.lua b/src/luarocks/cmd.lua index fc98e45f..996900ff 100644 --- a/src/luarocks/cmd.lua +++ b/src/luarocks/cmd.lua @@ -150,10 +150,10 @@ end local process_tree_flags do - local function replace_tree(flags, tree) - tree = dir.normalize(tree) - flags["tree"] = tree - path.use_tree(tree) + local function replace_tree(flags, root, tree) + root = dir.normalize(root) + flags["tree"] = root + path.use_tree(tree or root) end local function find_project_dir() @@ -195,7 +195,7 @@ do if not tree.root then return nil, "Configuration error: tree '"..tree.name.."' has no 'root' field." end - replace_tree(flags, tree.root) + replace_tree(flags, tree.root, tree) named = true break end -- cgit v1.2.3-55-g6feb