aboutsummaryrefslogtreecommitdiff
path: root/spec
diff options
context:
space:
mode:
authorHisham Muhammad <hisham@gobolinux.org>2018-06-20 10:28:49 -0300
committerHisham Muhammad <hisham@gobolinux.org>2018-07-01 15:51:13 -0300
commit4c1c170b9d344b6c069c8e6df5798f6e0bd63966 (patch)
tree21b0061a4c41434239320db45749ec5b4086be4c /spec
parent50cd8ea8941d38678e8e6cf82065108dc3217d91 (diff)
downloadluarocks-4c1c170b9d344b6c069c8e6df5798f6e0bd63966.tar.gz
luarocks-4c1c170b9d344b6c069c8e6df5798f6e0bd63966.tar.bz2
luarocks-4c1c170b9d344b6c069c8e6df5798f6e0bd63966.zip
cfg, cmd: major reorganization
* `--lua-dir` flag, specifying a prefix for the Lua installation to be used. This reconfigures LuaRocks entirely, including allowing a LuaRocks which is itself running using one Lua 5.x version to manage packages for a different Lua 5.y version. The resulting configuration can be checked with `luarocks config --lua-dir=<path>`. * requiring `luarocks.core.cfg` no longer has side-effects * configuration now needs to be initialized with `cfg.init([lua_data])`, where `lua_data` is a table with the configuration of the VM: * `lua_version` - e.g. `"5.3"` * `luajit_version` - e.g. `"2.1.0-beta3"` * `lua_interpreter` - e.g. `"lua5.3"` * `lua_bindir` - e.g. `"/usr/local/bin"` * `lua_libdir` - e.g. `"/usr/local/lib"` * `lua_incdir` - e.g. `"/usr/local/include/lua-5.3"` * `cfg.init` can be called multiple times, reconfiguring the global state. This is important since `luarocks.loader` now calls it, and the `--lua-dir` command line can override the configuration and reconfigure LuaRocks. * `site_config_*` is no more: LuaRocks is no longer dependent on a properly-written site_config file. Instead, it can *optionally* use `luarocks.core.hardcoded` for hardcoded values, or detect its configuration at runtime, based on OS detection, arg[-1] or command-line flags. * reduction of moving parts in the configuration: * `cfg.platforms` is no longer a globally-visible table; instead, `cfg` provides an API of read-only functions: `is_platform`, `each_platform`, `print_platforms`. * `cfg.*_proxy` options are no longer configured via the config files, but rather via the standard `*_proxy` environment variables. * `"windows"` is now the more general platform name of the Windows family. This is technically a breaking change but I don't expect it to cause problems with real-world rockspecs. * internal code reorganization in `luarocks.cmd` module
Diffstat (limited to 'spec')
-rw-r--r--spec/config_spec.lua16
-rw-r--r--spec/fetch_spec.lua2
-rw-r--r--spec/fs_spec.lua2
-rw-r--r--spec/tools_spec.lua2
-rw-r--r--spec/util/test_env.lua43
-rw-r--r--spec/util_spec.lua14
6 files changed, 44 insertions, 35 deletions
diff --git a/spec/config_spec.lua b/spec/config_spec.lua
index 94757244..e78c3de0 100644
--- a/spec/config_spec.lua
+++ b/spec/config_spec.lua
@@ -3,7 +3,7 @@ local lfs = require("lfs")
3local run = test_env.run 3local run = test_env.run
4local testing_paths = test_env.testing_paths 4local testing_paths = test_env.testing_paths
5local env_variables = test_env.env_variables 5local env_variables = test_env.env_variables
6local site_config 6local hardcoded
7 7
8test_env.unload_luarocks() 8test_env.unload_luarocks()
9 9
@@ -11,30 +11,30 @@ describe("LuaRocks config tests #integration", function()
11 11
12 before_each(function() 12 before_each(function()
13 test_env.setup_specs() 13 test_env.setup_specs()
14 test_env.unload_luarocks() -- need to be required here, because site_config is created after first loading of specs 14 test_env.unload_luarocks() -- need to be required here, because hardcoded is created after first loading of specs
15 site_config = require("luarocks.core.site_config_" .. test_env.lua_version:gsub("%.", "_")) 15 hardcoded = require("luarocks.core.hardcoded")
16 end) 16 end)
17 17
18 describe("LuaRocks config - basic tests", function() 18 describe("LuaRocks config - basic tests", function()
19 it("LuaRocks config with no flags/arguments", function() 19 it("LuaRocks config with no flags/arguments", function()
20 assert.is_false(run.luarocks_bool("config")) 20 assert.match("rocks_servers", run.luarocks("config"))
21 end) 21 end)
22 22
23 it("LuaRocks config include dir", function() 23 it("LuaRocks config include dir", function()
24 local output = run.luarocks("config --lua-incdir") 24 local output = run.luarocks("config --lua-incdir")
25 if test_env.TEST_TARGET_OS == "windows" then 25 if test_env.TEST_TARGET_OS == "windows" then
26 assert.are.same(output, site_config.LUA_INCDIR:gsub("\\","/")) 26 assert.are.same(output, hardcoded.LUA_INCDIR:gsub("\\","/"))
27 else 27 else
28 assert.are.same(output, site_config.LUA_INCDIR) 28 assert.are.same(output, hardcoded.LUA_INCDIR)
29 end 29 end
30 end) 30 end)
31 31
32 it("LuaRocks config library dir", function() 32 it("LuaRocks config library dir", function()
33 local output = run.luarocks("config --lua-libdir") 33 local output = run.luarocks("config --lua-libdir")
34 if test_env.TEST_TARGET_OS == "windows" then 34 if test_env.TEST_TARGET_OS == "windows" then
35 assert.are.same(output, site_config.LUA_LIBDIR:gsub("\\","/")) 35 assert.are.same(output, hardcoded.LUA_LIBDIR:gsub("\\","/"))
36 else 36 else
37 assert.are.same(output, site_config.LUA_LIBDIR) 37 assert.are.same(output, hardcoded.LUA_LIBDIR)
38 end 38 end
39 end) 39 end)
40 40
diff --git a/spec/fetch_spec.lua b/spec/fetch_spec.lua
index 6e00bc22..b878c1e6 100644
--- a/spec/fetch_spec.lua
+++ b/spec/fetch_spec.lua
@@ -3,6 +3,7 @@ local git_repo = require("spec.util.git_repo")
3 3
4test_env.unload_luarocks() 4test_env.unload_luarocks()
5test_env.setup_specs() 5test_env.setup_specs()
6local cfg = require("luarocks.core.cfg")
6local fs = require("luarocks.fs") 7local fs = require("luarocks.fs")
7local fetch = require("luarocks.fetch") 8local fetch = require("luarocks.fetch")
8local fs = require("luarocks.fs") 9local fs = require("luarocks.fs")
@@ -21,6 +22,7 @@ describe("Luarocks fetch test #unit #mock", function()
21 local runner 22 local runner
22 23
23 setup(function() 24 setup(function()
25 cfg.init()
24 fs.init() 26 fs.init()
25 test_env.mock_server_init() 27 test_env.mock_server_init()
26 28
diff --git a/spec/fs_spec.lua b/spec/fs_spec.lua
index b8091f75..3f115df9 100644
--- a/spec/fs_spec.lua
+++ b/spec/fs_spec.lua
@@ -3,6 +3,7 @@ local test_env = require("spec.util.test_env")
3test_env.unload_luarocks() 3test_env.unload_luarocks()
4test_env.setup_specs() 4test_env.setup_specs()
5local fs = require("luarocks.fs") 5local fs = require("luarocks.fs")
6local cfg = require("luarocks.core.cfg")
6local lfs = require("lfs") 7local lfs = require("lfs")
7local is_win = test_env.TEST_TARGET_OS == "windows" 8local is_win = test_env.TEST_TARGET_OS == "windows"
8local posix_ok = pcall(require, "posix") 9local posix_ok = pcall(require, "posix")
@@ -55,6 +56,7 @@ describe("Luarocks fs test #unit", function()
55 local runner 56 local runner
56 57
57 setup(function() 58 setup(function()
59 cfg.init()
58 fs.init() 60 fs.init()
59 runner = require("luacov.runner") 61 runner = require("luacov.runner")
60 runner.init(testing_paths.testrun_dir .. "/luacov.config") 62 runner.init(testing_paths.testrun_dir .. "/luacov.config")
diff --git a/spec/tools_spec.lua b/spec/tools_spec.lua
index 10dafb0b..c84dbab3 100644
--- a/spec/tools_spec.lua
+++ b/spec/tools_spec.lua
@@ -5,6 +5,7 @@ local write_file = test_env.write_file
5 5
6test_env.unload_luarocks() 6test_env.unload_luarocks()
7local fs = require("luarocks.fs") 7local fs = require("luarocks.fs")
8local cfg = require("luarocks.core.cfg")
8local patch = require("luarocks.tools.patch") 9local patch = require("luarocks.tools.patch")
9 10
10local lao = 11local lao =
@@ -148,6 +149,7 @@ describe("Luarocks patch test #unit", function()
148 local runner 149 local runner
149 150
150 setup(function() 151 setup(function()
152 cfg.init()
151 fs.init() 153 fs.init()
152 runner = require("luacov.runner") 154 runner = require("luacov.runner")
153 runner.init(testing_paths.testrun_dir .. "/luacov.config") 155 runner.init(testing_paths.testrun_dir .. "/luacov.config")
diff --git a/spec/util/test_env.lua b/spec/util/test_env.lua
index 6d8a962c..1d4e98d8 100644
--- a/spec/util/test_env.lua
+++ b/spec/util/test_env.lua
@@ -40,6 +40,10 @@ function test_env.exists(path)
40 return lfs.attributes(path, "mode") ~= nil 40 return lfs.attributes(path, "mode") ~= nil
41end 41end
42 42
43function test_env.file_if_exists(path)
44 return lfs.attributes(path, "mode") and path
45end
46
43--- Quote argument for shell processing. Fixes paths on Windows. 47--- Quote argument for shell processing. Fixes paths on Windows.
44-- Adds double quotes and escapes. Based on function in fs/win32.lua. 48-- Adds double quotes and escapes. Based on function in fs/win32.lua.
45-- @param arg string: Unquoted argument. 49-- @param arg string: Unquoted argument.
@@ -251,7 +255,15 @@ function test_env.set_args()
251 end 255 end
252 end 256 end
253 end 257 end
258 print(test_env.TEST_TARGET_OS)
259 end
260
261 if test_env.TEST_TARGET_OS == "windows" then
262 test_env.lib_extension = "dll"
263 else
264 test_env.lib_extension = "so"
254 end 265 end
266
255 return true 267 return true
256end 268end
257 269
@@ -394,12 +406,8 @@ local function create_env(testing_paths)
394 env_variables.LUA_PATH = env_variables.LUA_PATH .. testing_paths.testing_sys_tree .. "/share/lua/" .. luaversion_short .. "/?.lua;" 406 env_variables.LUA_PATH = env_variables.LUA_PATH .. testing_paths.testing_sys_tree .. "/share/lua/" .. luaversion_short .. "/?.lua;"
395 env_variables.LUA_PATH = env_variables.LUA_PATH .. testing_paths.testing_sys_tree .. "/share/lua/".. luaversion_short .. "/?/init.lua;" 407 env_variables.LUA_PATH = env_variables.LUA_PATH .. testing_paths.testing_sys_tree .. "/share/lua/".. luaversion_short .. "/?/init.lua;"
396 env_variables.LUA_PATH = env_variables.LUA_PATH .. testing_paths.src_dir .. "/?.lua;" 408 env_variables.LUA_PATH = env_variables.LUA_PATH .. testing_paths.src_dir .. "/?.lua;"
397 local lib_extension = "so" 409 env_variables.LUA_CPATH = testing_paths.testing_tree .. "/lib/lua/" .. luaversion_short .. "/?." .. test_env.lib_extension .. ";"
398 if test_env.TEST_TARGET_OS == "windows" then 410 .. testing_paths.testing_sys_tree .. "/lib/lua/" .. luaversion_short .. "/?." .. test_env.lib_extension .. ";"
399 lib_extension = "dll"
400 end
401 env_variables.LUA_CPATH = testing_paths.testing_tree .. "/lib/lua/" .. luaversion_short .. "/?." .. lib_extension .. ";"
402 .. testing_paths.testing_sys_tree .. "/lib/lua/" .. luaversion_short .. "/?." .. lib_extension .. ";"
403 env_variables.PATH = os.getenv("PATH") .. ";" .. testing_paths.testing_tree .. "/bin;" .. testing_paths.testing_sys_tree .. "/bin;" 411 env_variables.PATH = os.getenv("PATH") .. ";" .. testing_paths.testing_tree .. "/bin;" .. testing_paths.testing_sys_tree .. "/bin;"
404 412
405 return env_variables 413 return env_variables
@@ -584,8 +592,7 @@ function test_env.setup_specs(extra_rocks)
584 592
585 package.path = test_env.env_variables.LUA_PATH 593 package.path = test_env.env_variables.LUA_PATH
586 594
587 test_env.platform = execute_output(test_env.testing_paths.lua .. " -e \"print(require('luarocks.core.cfg').arch)\"", false, test_env.env_variables) 595 test_env.platform = execute_output(test_env.testing_paths.lua .. " -e \"cfg = require('luarocks.core.cfg'); cfg.init(); print(cfg.arch)\"", false, test_env.env_variables)
588 test_env.lib_extension = execute_output(test_env.testing_paths.lua .. " -e \"print(require('luarocks.core.cfg').lib_extension)\"", false, test_env.env_variables)
589 test_env.wrapper_extension = test_env.TEST_TARGET_OS == "windows" and ".bat" or "" 596 test_env.wrapper_extension = test_env.TEST_TARGET_OS == "windows" and ".bat" or ""
590 test_env.md5sums = create_md5sums(test_env.testing_paths) 597 test_env.md5sums = create_md5sums(test_env.testing_paths)
591 test_env.setup_done = true 598 test_env.setup_done = true
@@ -737,11 +744,21 @@ local function install_luarocks(install_env_vars)
737 assert(execute_bool("install.bat /LUA " .. testing_paths.luadir .. " " .. compiler_flag .. " /P " .. testing_paths.testing_lrprefix .. " /NOREG /NOADMIN /F /Q /CONFIG " .. testing_paths.testing_lrprefix .. "/etc/luarocks", false, install_env_vars)) 744 assert(execute_bool("install.bat /LUA " .. testing_paths.luadir .. " " .. compiler_flag .. " /P " .. testing_paths.testing_lrprefix .. " /NOREG /NOADMIN /F /Q /CONFIG " .. testing_paths.testing_lrprefix .. "/etc/luarocks", false, install_env_vars))
738 assert(execute_bool(testing_paths.win_tools .. "/cp " .. testing_paths.testing_lrprefix .. "/lua/luarocks/core/site_config* " .. testing_paths.src_dir .. "/luarocks/core")) 745 assert(execute_bool(testing_paths.win_tools .. "/cp " .. testing_paths.testing_lrprefix .. "/lua/luarocks/core/site_config* " .. testing_paths.src_dir .. "/luarocks/core"))
739 else 746 else
740 local configure_cmd = "./configure --with-lua=" .. testing_paths.luadir .. " --prefix=" .. testing_paths.testing_lrprefix 747 local incfile = test_env.file_if_exists(testing_paths.luadir .. "/include/lua.h")
741 assert(execute_bool(configure_cmd, false, install_env_vars)) 748 or test_env.file_if_exists(testing_paths.luadir .. "/include/lua/" .. test_env.lua_version .. "/lua.h")
742 assert(execute_bool("make clean", false, install_env_vars)) 749 or test_env.file_if_exists(testing_paths.luadir .. "/include/lua" .. test_env.lua_version .. "/lua.h")
743 assert(execute_bool("make src/luarocks/core/site_config_"..test_env.lua_version:gsub("%.", "_")..".lua", false, install_env_vars)) 750 local incdir = assert(incfile):gsub("/lua.h$", "")
744 assert(execute_bool("make dev", false, install_env_vars)) 751
752 local lines = {
753 "return {",
754 ("SYSCONFDIR = %q,"):format(testing_paths.testing_lrprefix .. "/etc/luarocks"),
755 ("LUA_DIR = %q,"):format(testing_paths.luadir),
756 ("LUA_INCDIR = %q,"):format(incdir),
757 ("LUA_LIBDIR = %q,"):format(testing_paths.luadir .. "/lib"),
758 ("LUA_BINDIR = %q,"):format(testing_paths.luadir .. "/bin"),
759 "}",
760 }
761 test_env.write_file("src/luarocks/core/hardcoded.lua", table.concat(lines, "\n") .. "\n")
745 end 762 end
746 print("LuaRocks installed correctly!") 763 print("LuaRocks installed correctly!")
747end 764end
diff --git a/spec/util_spec.lua b/spec/util_spec.lua
index 26e93e14..cbdde095 100644
--- a/spec/util_spec.lua
+++ b/spec/util_spec.lua
@@ -53,20 +53,6 @@ describe("Basic tests #integration", function()
53 assert.is.truthy(run.luarocks("--only-server=testing")) 53 assert.is.truthy(run.luarocks("--only-server=testing"))
54 end) 54 end)
55 55
56 it("#only LuaRocks test site config", function()
57 local scname = testing_paths.src_dir .. "/luarocks/core/site_config_"..test_env.lua_version:gsub("%.", "_")..".lua"
58
59 assert.is.truthy(os.rename(scname, scname..".tmp"))
60 assert.is.falsy(lfs.attributes(scname))
61 assert.is.truthy(lfs.attributes(scname..".tmp"))
62
63 assert.is.truthy(run.luarocks(""))
64
65 assert.is.truthy(os.rename(scname..".tmp", scname))
66 assert.is.falsy(lfs.attributes(scname..".tmp"))
67 assert.is.truthy(lfs.attributes(scname))
68 end)
69
70end) 56end)
71 57
72test_env.unload_luarocks() 58test_env.unload_luarocks()