From 88f6aaeb40958c10a3c7a6fb4d0d699481f2a7be Mon Sep 17 00:00:00 2001 From: Peter Melnichenko Date: Fri, 8 Jul 2016 12:35:01 +0300 Subject: Tests: infer Lua/LuaJIT version --- test/test_environment.lua | 52 ++++++++++++++++++++++------------------------- 1 file changed, 24 insertions(+), 28 deletions(-) (limited to 'test/test_environment.lua') diff --git a/test/test_environment.lua b/test/test_environment.lua index 6de501fb..fad862ce 100644 --- a/test/test_environment.lua +++ b/test/test_environment.lua @@ -11,10 +11,6 @@ local function help() Tests require to have Lua installed and added to PATH. Be sure sshd is runnig on your system, or use '--exclude-tags=ssh', to not execute tests which require sshd. USAGE -Xhelper - lua= (mandatory) type your full version of Lua (e.g. --lua 5.2.4) - OR - luajit= (mandatory) type your full version of LuaJIT (e.g. --luajit 2.0.3) - env= (default:"minimal") type what kind of environment to use ["minimal", "full"] clean remove existing testing environment travis add just if running on TravisCI @@ -70,50 +66,49 @@ local function execute_output(command, print_command, env_variables) return output:gsub("\n","") -- output adding new line, need to be removed end +--- Set test_env.LUA_V or test_env.LUAJIT_V based +-- on version of Lua used to run this script. +function test_env.set_lua_version() + if _G.jit then + test_env.LUAJIT_V = _G.jit.version:match("(2%.%d)%.%d") + else + test_env.LUA_V = _VERSION:match("5%.%d") + end +end + --- Set all arguments from input into global variables function test_env.set_args() if arg[1] == nil then help() end - - local args_position - + + local helper_arg + for i=1, #arg do - if arg[i]:find("-Xhelper") and arg[i+1]:find("lua=") and not arg[i+1]:find("luajit=") then - args_position = i+1 - test_env.LUA_V = arg[args_position]:gsub("(.*)lua=([^%,]+)(.*)","%2") - break - elseif arg[i]:find("-Xhelper") and not arg[i+1]:find("lua=") and arg[i+1]:find("luajit=") then - args_position = i+1 - test_env.LUAJIT_V = arg[args_position]:gsub("(.*)luajit=([^%,]+)(.*)","%2") - break - elseif arg[i]:find("-Xhelper") and arg[i+1]:find("lua=") and arg[i+1]:find("luajit=") then - print("Please specify just Lua or LuaJIT version for testing in format 'lua=X.X.X' or 'luajit=X.X.X', for -Xhelper flag") - os.exit(1) - elseif arg[i]:find("-Xhelper") and not arg[i+1]:find("lua=") and not arg[i+1]:find("luajit=") then - print("Please add mandatory argument - version of Lua or LuaJIT in format 'lua=X.X.X' or 'luajit=X.X.X', for -Xhelper flag") - os.exit(1) + if arg[i] == "-Xhelper" then + helper_arg = arg[i+1] + break end end - if not args_position then + if not helper_arg then help() end -- if at least Lua/LuaJIT version argument was found on input start to parse other arguments to env. variables test_env.TYPE_TEST_ENV = "minimal" - if arg[args_position]:find("env=") then - test_env.TYPE_TEST_ENV = arg[args_position]:gsub("(.*)env=([^%,]+)(.*)","%2") + if helper_arg:find("env=") then + test_env.TYPE_TEST_ENV = helper_arg:gsub("(.*)env=([^%,]+)(.*)","%2") end - if arg[args_position]:find("clean") then + if helper_arg:find("clean") then test_env.TEST_ENV_CLEAN = true end - if arg[args_position]:find("travis") then + if helper_arg:find("travis") then test_env.TRAVIS = true end - if arg[args_position]:find("os=") then - test_env.TEST_TARGET_OS = arg[args_position]:gsub("(.*)os=([^%,]+)(.*)","%2") + if helper_arg:find("os=") then + test_env.TEST_TARGET_OS = helper_arg:gsub("(.*)os=([^%,]+)(.*)","%2") end if not test_env.TEST_TARGET_OS then @@ -418,6 +413,7 @@ end function test_env.setup_specs(extra_rocks, luaversion_full) -- if global variable about successful creation of testing environment doesn't exists, build environment if not test_env.setup_done then + test_env.set_lua_version() test_env.set_args() if test_env.TRAVIS then -- cgit v1.2.3-55-g6feb From 54cf8ad4d527b0585f364b3d6cbe2c9eae58c3da Mon Sep 17 00:00:00 2001 From: Peter Melnichenko Date: Fri, 8 Jul 2016 13:36:24 +0300 Subject: Test suite: use test/test_environment as busted helper When parsing test options, instead of directly looking for '-Xhelper' in arguments and splitting the next arguments on commas add .busted config to set test/test_environment as busted helper. Then busted will do the splitting on its own and set global arg to split options. --- .busted | 5 +++++ test/test_environment.lua | 42 +++++++++++++----------------------------- 2 files changed, 18 insertions(+), 29 deletions(-) create mode 100644 .busted (limited to 'test/test_environment.lua') diff --git a/.busted b/.busted new file mode 100644 index 00000000..7c67e719 --- /dev/null +++ b/.busted @@ -0,0 +1,5 @@ +return { + default = { + helper = "test/test_environment" + } +} diff --git a/test/test_environment.lua b/test/test_environment.lua index fad862ce..bde43163 100644 --- a/test/test_environment.lua +++ b/test/test_environment.lua @@ -1,6 +1,6 @@ local lfs = require("lfs") local test_env = {} -local arg = arg or { ... } +local arg = arg local function help() print("LuaRocks test-suite\n\n".. @@ -78,37 +78,21 @@ end --- Set all arguments from input into global variables function test_env.set_args() - if arg[1] == nil then - help() - end - - local helper_arg - - for i=1, #arg do - if arg[i] == "-Xhelper" then - helper_arg = arg[i+1] - break - end - end - - if not helper_arg then - help() - end - -- if at least Lua/LuaJIT version argument was found on input start to parse other arguments to env. variables test_env.TYPE_TEST_ENV = "minimal" - if helper_arg:find("env=") then - test_env.TYPE_TEST_ENV = helper_arg:gsub("(.*)env=([^%,]+)(.*)","%2") - end - if helper_arg:find("clean") then - test_env.TEST_ENV_CLEAN = true - end - if helper_arg:find("travis") then - test_env.TRAVIS = true - end - if helper_arg:find("os=") then - test_env.TEST_TARGET_OS = helper_arg:gsub("(.*)os=([^%,]+)(.*)","%2") + for _, argument in ipairs(arg) do + if argument:find("^env=") then + test_env.TYPE_TEST_ENV = argument:match("^env=(.*)$") + elseif argument == "clean" then + test_env.TEST_ENV_CLEAN = true + elseif argument == "travis" then + test_env.TRAVIS = true + elseif argument:find("^os=") then + test_env.TEST_TARGET_OS = argument:match("^os=(.*)$") + else + help() + end end if not test_env.TEST_TARGET_OS then -- cgit v1.2.3-55-g6feb From 8867f3324d97584ed24f3a1082144e9b1375d663 Mon Sep 17 00:00:00 2001 From: Peter Melnichenko Date: Fri, 8 Jul 2016 14:30:00 +0300 Subject: Make env vars, paths and run commands available on test env load --- spec/add_spec.lua | 4 +- spec/build_spec.lua | 4 +- spec/config_spec.lua | 4 +- spec/deps_spec.lua | 2 + spec/doc_spec.lua | 3 +- spec/download_spec.lua | 2 +- spec/help_spec.lua | 2 +- spec/install_spec.lua | 6 +-- spec/lint_spec.lua | 4 +- spec/list_spec.lua | 4 +- spec/make_manifest_spec.lua | 2 +- spec/make_spec.lua | 4 +- spec/new_version_spec.lua | 4 +- spec/pack_spec.lua | 3 +- spec/path_spec.lua | 2 +- spec/purge_spec.lua | 4 +- spec/refresh_cache_spec.lua | 2 +- spec/remove_spec.lua | 4 +- spec/search_spec.lua | 2 +- spec/show_spec.lua | 2 +- spec/unpack_spec.lua | 4 +- spec/upload_spec.lua | 2 +- spec/util_spec.lua | 6 +-- spec/write_rockspec_spec.lua | 4 +- test/test_environment.lua | 94 ++++++++++++++++++++------------------------ 25 files changed, 82 insertions(+), 92 deletions(-) (limited to 'test/test_environment.lua') diff --git a/spec/add_spec.lua b/spec/add_spec.lua index 930c221d..dca6f850 100644 --- a/spec/add_spec.lua +++ b/spec/add_spec.lua @@ -1,4 +1,6 @@ local test_env = require("test/test_environment") +local run = test_env.run +local testing_paths = test_env.testing_paths test_env.unload_luarocks() @@ -11,8 +13,6 @@ describe("LuaRocks add tests #blackbox #b_add", function() before_each(function() test_env.setup_specs(extra_rocks) - testing_paths = test_env.testing_paths - run = test_env.run end) describe("LuaRocks-admin add tests", function() diff --git a/spec/build_spec.lua b/spec/build_spec.lua index 7248e8f0..1ce99089 100644 --- a/spec/build_spec.lua +++ b/spec/build_spec.lua @@ -1,5 +1,7 @@ local test_env = require("test/test_environment") local lfs = require("lfs") +local run = test_env.run +local testing_paths = test_env.testing_paths test_env.unload_luarocks() @@ -29,8 +31,6 @@ describe("LuaRocks build tests #blackbox #b_build", function() before_each(function() test_env.setup_specs(extra_rocks) - testing_paths = test_env.testing_paths - run = test_env.run end) describe("LuaRocks build - basic testing set", function() diff --git a/spec/config_spec.lua b/spec/config_spec.lua index df2480ac..4a09fdcf 100644 --- a/spec/config_spec.lua +++ b/spec/config_spec.lua @@ -1,5 +1,7 @@ local test_env = require("test/test_environment") local lfs = require("lfs") +local run = test_env.run +local testing_paths = test_env.testing_paths test_env.unload_luarocks() @@ -9,8 +11,6 @@ describe("LuaRocks config tests #blackbox #b_config", function() test_env.setup_specs(extra_rocks) test_env.unload_luarocks() -- need to be required here, because site_config is created after first loading of specs site_config = require("luarocks.site_config") - testing_paths = test_env.testing_paths - run = test_env.run end) describe("LuaRocks config - basic tests", function() diff --git a/spec/deps_spec.lua b/spec/deps_spec.lua index 9bb4709d..5df96452 100644 --- a/spec/deps_spec.lua +++ b/spec/deps_spec.lua @@ -1,5 +1,7 @@ local test_env = require("test/test_environment") local lfs = require("lfs") +local run = test_env.run +local testing_paths = test_env.testing_paths test_env.unload_luarocks() diff --git a/spec/doc_spec.lua b/spec/doc_spec.lua index e4e7f5f2..9dbeaab8 100644 --- a/spec/doc_spec.lua +++ b/spec/doc_spec.lua @@ -1,4 +1,5 @@ local test_env = require("test/test_environment") +local run = test_env.run test_env.unload_luarocks() @@ -10,8 +11,6 @@ describe("LuaRocks doc tests #blackbox #b_doc", function() before_each(function() test_env.setup_specs(extra_rocks) - testing_paths = test_env.testing_paths - run = test_env.run end) describe("LuaRocks doc basic tests", function() diff --git a/spec/download_spec.lua b/spec/download_spec.lua index 2485960d..320d9304 100644 --- a/spec/download_spec.lua +++ b/spec/download_spec.lua @@ -1,5 +1,6 @@ local test_env = require("test/test_environment") local lfs = require("lfs") +local run = test_env.run test_env.unload_luarocks() @@ -11,7 +12,6 @@ describe("LuaRocks download tests #blackbox #b_download", function() before_each(function() test_env.setup_specs(extra_rocks) - run = test_env.run end) it("LuaRocks download with no flags/arguments", function() diff --git a/spec/help_spec.lua b/spec/help_spec.lua index 376b6ceb..35bb6817 100644 --- a/spec/help_spec.lua +++ b/spec/help_spec.lua @@ -1,4 +1,5 @@ local test_env = require("test/test_environment") +local run = test_env.run test_env.unload_luarocks() @@ -6,7 +7,6 @@ describe("LuaRocks help tests #blackbox #b_help", function() before_each(function() test_env.setup_specs(extra_rocks) - run = test_env.run end) it("LuaRocks help with no flags/arguments", function() diff --git a/spec/install_spec.lua b/spec/install_spec.lua index f8869791..876e25fc 100644 --- a/spec/install_spec.lua +++ b/spec/install_spec.lua @@ -1,5 +1,8 @@ local test_env = require("test/test_environment") local lfs = require("lfs") +local run = test_env.run +local testing_paths = test_env.testing_paths +local env_variables = test_env.env_variables test_env.unload_luarocks() @@ -22,9 +25,6 @@ describe("LuaRocks install tests #blackbox #b_install", function() before_each(function() test_env.setup_specs(extra_rocks) - testing_paths = test_env.testing_paths - env_variables = test_env.env_variables - run = test_env.run platform = test_env.platform end) diff --git a/spec/lint_spec.lua b/spec/lint_spec.lua index ce753618..f7496037 100644 --- a/spec/lint_spec.lua +++ b/spec/lint_spec.lua @@ -1,4 +1,6 @@ local test_env = require("test/test_environment") +local run = test_env.run +local testing_paths = test_env.testing_paths test_env.unload_luarocks() @@ -10,8 +12,6 @@ describe("LuaRocks lint tests #blackbox #b_lint", function() before_each(function() test_env.setup_specs(extra_rocks) - testing_paths = test_env.testing_paths - run = test_env.run end) it("LuaRocks lint with no flags/arguments", function() diff --git a/spec/list_spec.lua b/spec/list_spec.lua index 344607e3..1b082ab6 100644 --- a/spec/list_spec.lua +++ b/spec/list_spec.lua @@ -1,4 +1,6 @@ local test_env = require("test/test_environment") +local run = test_env.run +local testing_paths = test_env.testing_paths test_env.unload_luarocks() @@ -11,8 +13,6 @@ describe("LuaRocks list tests #blackbox #b_list", function() before_each(function() test_env.setup_specs(extra_rocks) - run = test_env.run - testing_paths = test_env.testing_paths end) it("LuaRocks list with no flags/arguments", function() diff --git a/spec/make_manifest_spec.lua b/spec/make_manifest_spec.lua index c6b0753c..5bd9e2f3 100644 --- a/spec/make_manifest_spec.lua +++ b/spec/make_manifest_spec.lua @@ -1,4 +1,5 @@ local test_env = require("test/test_environment") +local run = test_env.run test_env.unload_luarocks() @@ -6,7 +7,6 @@ describe("LuaRocks make_manifest tests #blackbox #b_make_manifest", function() before_each(function() test_env.setup_specs(extra_rocks) - run = test_env.run end) describe("LuaRocks-admin make manifest tests", function() diff --git a/spec/make_spec.lua b/spec/make_spec.lua index 5ae23fd5..2821c143 100644 --- a/spec/make_spec.lua +++ b/spec/make_spec.lua @@ -1,5 +1,7 @@ local test_env = require("test/test_environment") local lfs = require("lfs") +local run = test_env.run +local testing_paths = test_env.testing_paths test_env.unload_luarocks() @@ -15,8 +17,6 @@ describe("LuaRocks make tests #blackbox #b_make", function() before_each(function() test_env.setup_specs(extra_rocks) - run = test_env.run - testing_paths = test_env.testing_paths end) it("LuaRocks make with no flags/arguments", function() diff --git a/spec/new_version_spec.lua b/spec/new_version_spec.lua index 140c9906..2274bce3 100644 --- a/spec/new_version_spec.lua +++ b/spec/new_version_spec.lua @@ -1,5 +1,7 @@ local test_env = require("test/test_environment") local lfs = require("lfs") +local run = test_env.run +local testing_paths = test_env.testing_paths test_env.unload_luarocks() @@ -11,8 +13,6 @@ describe("LuaRocks new_version tests #blackbox #b_new_version", function() before_each(function() test_env.setup_specs(extra_rocks) - testing_paths = test_env.testing_paths - run = test_env.run end) describe("LuaRocks new_version basic tests", function() diff --git a/spec/pack_spec.lua b/spec/pack_spec.lua index 1671152c..416184a8 100644 --- a/spec/pack_spec.lua +++ b/spec/pack_spec.lua @@ -1,5 +1,6 @@ local test_env = require("test/test_environment") local lfs = require("lfs") +local run = test_env.run test_env.unload_luarocks() @@ -13,8 +14,6 @@ describe("LuaRocks pack tests #blackbox #b_pack", function() before_each(function() test_env.setup_specs(extra_rocks) - testing_paths = test_env.testing_paths - run = test_env.run end) it("LuaRocks pack basic", function() diff --git a/spec/path_spec.lua b/spec/path_spec.lua index d201f337..fcdb36cf 100644 --- a/spec/path_spec.lua +++ b/spec/path_spec.lua @@ -1,11 +1,11 @@ local test_env = require("test/test_environment") +local run = test_env.run test_env.unload_luarocks() describe("LuaRocks path tests #blackbox #b_path", function() before_each(function() test_env.setup_specs(extra_rocks) - run = test_env.run end) it("LuaRocks path bin", function() diff --git a/spec/purge_spec.lua b/spec/purge_spec.lua index 30ce15e2..e6f12ddb 100644 --- a/spec/purge_spec.lua +++ b/spec/purge_spec.lua @@ -1,12 +1,12 @@ local test_env = require("test/test_environment") +local run = test_env.run +local testing_paths = test_env.testing_paths test_env.unload_luarocks() describe("LuaRocks purge tests #blackbox #b_purge", function() before_each(function() test_env.setup_specs(extra_rocks) - testing_paths = test_env.testing_paths - run = test_env.run end) describe("LuaRocks purge basic tests", function() diff --git a/spec/refresh_cache_spec.lua b/spec/refresh_cache_spec.lua index 764cbcb5..34d211ab 100644 --- a/spec/refresh_cache_spec.lua +++ b/spec/refresh_cache_spec.lua @@ -1,4 +1,5 @@ local test_env = require("test/test_environment") +local run = test_env.run test_env.unload_luarocks() @@ -6,7 +7,6 @@ describe("LuaRocks refresh_cache tests #blackbox #b_refresh_cache", function() before_each(function() test_env.setup_specs(extra_rocks) - run = test_env.run end) describe("LuaRocks-admin refresh cache tests #ssh", function() diff --git a/spec/remove_spec.lua b/spec/remove_spec.lua index 4129e755..41c6348a 100644 --- a/spec/remove_spec.lua +++ b/spec/remove_spec.lua @@ -1,5 +1,7 @@ local test_env = require("test/test_environment") local lfs = require("lfs") +local run = test_env.run +local testing_paths = test_env.testing_paths test_env.unload_luarocks() @@ -14,8 +16,6 @@ describe("LuaRocks remove tests #blackbox #b_remove", function() before_each(function() test_env.setup_specs(extra_rocks) - testing_paths = test_env.testing_paths - run = test_env.run end) describe("LuaRocks remove basic tests", function() diff --git a/spec/search_spec.lua b/spec/search_spec.lua index 93e85928..33c49856 100644 --- a/spec/search_spec.lua +++ b/spec/search_spec.lua @@ -1,4 +1,5 @@ local test_env = require("test/test_environment") +local run = test_env.run test_env.unload_luarocks() @@ -10,7 +11,6 @@ describe("LuaRocks search tests #blackbox #b_search", function() before_each(function() test_env.setup_specs(extra_rocks) - run = test_env.run end) it("LuaRocks search with no flags/arguments", function() diff --git a/spec/show_spec.lua b/spec/show_spec.lua index a58eea52..6f055612 100644 --- a/spec/show_spec.lua +++ b/spec/show_spec.lua @@ -1,4 +1,5 @@ local test_env = require("test/test_environment") +local run = test_env.run test_env.unload_luarocks() @@ -6,7 +7,6 @@ describe("LuaRocks show tests #blackbox #b_show", function() before_each(function() test_env.setup_specs(extra_rocks) - run = test_env.run end) it("LuaRocks show with no flags/arguments", function() diff --git a/spec/unpack_spec.lua b/spec/unpack_spec.lua index 1e9df811..db71aa06 100644 --- a/spec/unpack_spec.lua +++ b/spec/unpack_spec.lua @@ -1,4 +1,6 @@ local test_env = require("test/test_environment") +local run = test_env.run +local testing_paths = test_env.testing_paths test_env.unload_luarocks() @@ -11,8 +13,6 @@ describe("LuaRocks unpack tests #blackbox #b_unpack", function() before_each(function() test_env.setup_specs(extra_rocks) - testing_paths = test_env.testing_paths - run = test_env.run platform = test_env.platform end) diff --git a/spec/upload_spec.lua b/spec/upload_spec.lua index ce998987..c10ef0e9 100644 --- a/spec/upload_spec.lua +++ b/spec/upload_spec.lua @@ -1,4 +1,5 @@ local test_env = require("test/test_environment") +local run = test_env.run test_env.unload_luarocks() @@ -10,7 +11,6 @@ describe("LuaRocks upload tests #blackbox #b_upload", function() before_each(function() test_env.setup_specs(extra_rocks) - run = test_env.run end) it("LuaRocks upload with no flags/arguments", function() diff --git a/spec/util_spec.lua b/spec/util_spec.lua index 7e0289d6..39ce3c83 100644 --- a/spec/util_spec.lua +++ b/spec/util_spec.lua @@ -1,13 +1,13 @@ local test_env = require("test/test_environment") local lfs = require("lfs") +local run = test_env.run +local testing_paths = test_env.testing_paths +local env_variables = test_env.env_variables describe("Basic tests #blackbox #b_util", function() before_each(function() test_env.setup_specs(extra_rocks) - testing_paths = test_env.testing_paths - env_variables = test_env.env_variables - run = test_env.run end) it("LuaRocks version", function() diff --git a/spec/write_rockspec_spec.lua b/spec/write_rockspec_spec.lua index 4c29f204..cf0a642e 100644 --- a/spec/write_rockspec_spec.lua +++ b/spec/write_rockspec_spec.lua @@ -1,5 +1,6 @@ local test_env = require("test/test_environment") local lfs = require("lfs") +local run = test_env.run test_env.unload_luarocks() local write_rockspec = require("luarocks.write_rockspec") @@ -8,7 +9,6 @@ describe("LuaRocks write_rockspec tests #blackbox #b_write_rockspec", function() before_each(function() test_env.setup_specs(extra_rocks) - run = test_env.run end) describe("LuaRocks write_rockspec basic tests", function() @@ -71,4 +71,4 @@ describe("LuaRocks write_rockspec tests #blackbox #b_write_rockspec", function() assert.is_true(os.remove("luafcgi-scm-1.rockspec")) end) end) -end) \ No newline at end of file +end) diff --git a/test/test_environment.lua b/test/test_environment.lua index bde43163..b3ac3b18 100644 --- a/test/test_environment.lua +++ b/test/test_environment.lua @@ -254,44 +254,40 @@ local function create_md5sums(testing_paths) return md5sums end -local function run_luarocks(testing_paths, env_variables) - - local function make_command_function(exec_function, lua_cmd, do_print) - return function(cmd, new_vars) - local temp_vars = {} - for k, v in pairs(env_variables) do +local function make_run_function(cmd_name, exec_function, with_coverage, do_print) + local cmd_prefix = test_env.testing_paths.lua .. " " + + if with_coverage then + cmd_prefix = cmd_prefix .. "-e \"require('luacov.runner')('" .. test_env.testing_paths.testing_dir .. "/luacov.config')\" " + end + + cmd_prefix = cmd_prefix .. test_env.testing_paths.src_dir .. "/bin/" .. cmd_name .. " " + + return function(cmd, new_vars) + local temp_vars = {} + for k, v in pairs(test_env.env_variables) do + temp_vars[k] = v + end + if new_vars then + for k, v in pairs(new_vars) do temp_vars[k] = v end - if new_vars then - for k, v in pairs(new_vars) do - temp_vars[k] = v - end - end - return exec_function(lua_cmd .. cmd, do_print, temp_vars) end + return exec_function(cmd_prefix .. cmd, do_print, temp_vars) end +end - local run = {} - - local cov_str = testing_paths.lua .. " -e\"require('luacov.runner')('" .. testing_paths.testing_dir .. "/luacov.config')\" " - - local luarocks_cmd = cov_str .. testing_paths.src_dir .. "/bin/luarocks " - run.luarocks = make_command_function(execute_output, luarocks_cmd, true) - run.luarocks_bool = make_command_function(execute_bool, luarocks_cmd, true) - run.luarocks_noprint = make_command_function(execute_bool, luarocks_cmd, false) - - local luarocks_nocov_cmd = testing_paths.lua .. " " .. testing_paths.src_dir .. "/bin/luarocks " - run.luarocks_nocov = make_command_function(execute_bool, luarocks_nocov_cmd, true) - run.luarocks_noprint_nocov = make_command_function(execute_bool, luarocks_nocov_cmd, false) - - local luarocks_admin_cmd = cov_str .. testing_paths.src_dir .. "/bin/luarocks-admin " - run.luarocks_admin = make_command_function(execute_output, luarocks_admin_cmd, true) - run.luarocks_admin_bool = make_command_function(execute_bool, luarocks_admin_cmd, true) - - local luarocks_admin_nocov_cmd = testing_paths.lua .. " " .. testing_paths.src_dir .. "/bin/luarocks-admin " - run.luarocks_admin_nocov = make_command_function(execute_bool, luarocks_admin_nocov_cmd, false) - - return run +local function make_run_functions() + return { + luarocks = make_run_function("luarocks", execute_output, true, true), + luarocks_bool = make_run_function("luarocks", execute_bool, true, true), + luarocks_noprint = make_run_function("luarocks", execute_bool, true, false), + luarocks_nocov = make_run_function("luarocks", execute_bool, false, true), + luarocks_noprint_nocov = make_run_function("luarocks", execute_bool, false, false), + luarocks_admin = make_run_function("luarocks-admin", execute_output, true, true), + luarocks_admin_bool = make_run_function("luarocks-admin", execute_bool, true, true), + luarocks_admin_nocov = make_run_function("luarocks-admin", execute_bool, false, false) + } end --- Build environment for testing @@ -307,14 +303,13 @@ local function build_environment(env_rocks, testing_paths, env_variables) lfs.mkdir(testing_paths.testing_tree) lfs.mkdir(testing_paths.testing_sys_tree) - local run = run_luarocks(testing_paths, env_variables) - run.luarocks_admin_nocov("make_manifest " .. testing_paths.testing_server) - run.luarocks_admin_nocov("make_manifest " .. testing_paths.testing_cache) + test_env.run.luarocks_admin_nocov("make_manifest " .. testing_paths.testing_server) + test_env.run.luarocks_admin_nocov("make_manifest " .. testing_paths.testing_cache) for _,package in ipairs(env_rocks) do - if not run.luarocks_nocov("install --only-server=" .. testing_paths.testing_cache .. " --tree=" .. testing_paths.testing_sys_tree .. " " .. package, env_variables) then - run.luarocks_nocov("build --tree=" .. testing_paths.testing_sys_tree .. " " .. package, env_variables) - run.luarocks_nocov("pack --tree=" .. testing_paths.testing_sys_tree .. " " .. package .. "; mv " .. package .. "-*.rock " .. testing_paths.testing_cache, env_variables) + if not test_env.run.luarocks_nocov("install --only-server=" .. testing_paths.testing_cache .. " --tree=" .. testing_paths.testing_sys_tree .. " " .. package, env_variables) then + test_env.run.luarocks_nocov("build --tree=" .. testing_paths.testing_sys_tree .. " " .. package, env_variables) + test_env.run.luarocks_nocov("pack --tree=" .. testing_paths.testing_sys_tree .. " " .. package .. "; mv " .. package .. "-*.rock " .. testing_paths.testing_cache, env_variables) end end @@ -394,12 +389,9 @@ function test_env.unload_luarocks() end --- Function for initially setup of environment, variables, md5sums for spec files -function test_env.setup_specs(extra_rocks, luaversion_full) +function test_env.setup_specs(extra_rocks) -- if global variable about successful creation of testing environment doesn't exists, build environment if not test_env.setup_done then - test_env.set_lua_version() - test_env.set_args() - if test_env.TRAVIS then if not os.rename(os.getenv("HOME") .. "/.ssh/id_rsa.pub", os.getenv("HOME") .. "/.ssh/id_rsa.pub") then execute_bool("ssh-keygen -t rsa -P \"\" -f ~/.ssh/id_rsa") @@ -409,16 +401,9 @@ function test_env.setup_specs(extra_rocks, luaversion_full) end end - luaversion_full = luaversion_full or test_env.LUA_V or test_env.LUAJIT_V - test_env.main() - - -- Set paths, env_vars and functions for specs - test_env.testing_paths = create_paths(luaversion_full) - test_env.env_variables = create_env(test_env.testing_paths) package.path = test_env.env_variables.LUA_PATH - test_env.run = run_luarocks(test_env.testing_paths, test_env.env_variables) test_env.platform = execute_output(test_env.testing_paths.lua .. " -e 'print(require(\"luarocks.cfg\").arch)'", false, test_env.env_variables) test_env.md5sums = create_md5sums(test_env.testing_paths) test_env.setup_done = true @@ -427,8 +412,7 @@ function test_env.setup_specs(extra_rocks, luaversion_full) if extra_rocks then local make_manifest = download_rocks(extra_rocks, test_env.testing_paths.testing_server) if make_manifest then - local run = run_luarocks(test_env.testing_paths, test_env.env_variables) - run.luarocks_admin_nocov("make_manifest " .. test_env.testing_paths.testing_server) + test_env.run.luarocks_admin_nocov("make_manifest " .. test_env.testing_paths.testing_server) end end @@ -602,4 +586,10 @@ upload_servers = { print("----------------") end +test_env.set_lua_version() +test_env.set_args() +test_env.testing_paths = create_paths(test_env.LUA_V or test_env.LUAJIT_V) +test_env.env_variables = create_env(test_env.testing_paths) +test_env.run = make_run_functions() + return test_env -- cgit v1.2.3-55-g6feb From f5d35cf9cad5ad8cd9f6e201dda783657e4510a3 Mon Sep 17 00:00:00 2001 From: Peter Melnichenko Date: Fri, 8 Jul 2016 14:45:51 +0300 Subject: Tests: fix luabitop installation condition --- test/test_environment.lua | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'test/test_environment.lua') diff --git a/test/test_environment.lua b/test/test_environment.lua index b3ac3b18..d6561f68 100644 --- a/test/test_environment.lua +++ b/test/test_environment.lua @@ -567,7 +567,7 @@ upload_servers = { rocks[#rocks+1] = "/lzlib-0.4.1.53-1.src.rock" env_rocks = {"luafilesystem", "luasocket", "luaposix", "md5", "lzlib"} end - if env_type == "full" and luaversion_full ~= "5.1.5" then + if env_type == "full" and luaversion_full ~= "5.1" then rocks[#rocks+1] = "/luabitop-1.0.2-1.rockspec" rocks[#rocks+1] = "/luabitop-1.0.2-1.src.rock" table.insert(env_rocks, "luabitop") -- cgit v1.2.3-55-g6feb From c4f2a8404130696c503414876cf335a82aab359f Mon Sep 17 00:00:00 2001 From: Peter Melnichenko Date: Fri, 8 Jul 2016 15:08:31 +0300 Subject: Tests: refactor config creation --- test/test_environment.lua | 145 ++++++++++++++++++++++++++-------------------- 1 file changed, 81 insertions(+), 64 deletions(-) (limited to 'test/test_environment.lua') diff --git a/test/test_environment.lua b/test/test_environment.lua index d6561f68..4c1b13c8 100644 --- a/test/test_environment.lua +++ b/test/test_environment.lua @@ -441,6 +441,14 @@ function test_env.need_luasocket(luarocks_nocov, testing_cache, platform) return true end +--- For each key-value pair in replacements table +-- replace %{key} in given string with value. +local function substitute(str, replacements) + return (str:gsub("%%%b{}", function(marker) + return replacements[marker:sub(3, -2)] + end)) +end + --- -- Main function to create config files and testing environment function test_env.main(luaversion_full, env_type, env_clean) @@ -461,78 +469,87 @@ function test_env.main(luaversion_full, env_type, env_clean) lfs.mkdir(testing_paths.testing_cache) lfs.mkdir(testing_paths.luarocks_tmp) ---- CONFIG FILES --- testing_config.lua and testing_config_show_downloads.lua - local config_content = ([[rocks_trees = { - "%{testing_tree}", - { name = "system", root = "%{testing_sys_tree}" }, -} -rocks_servers = { - "%{testing_server}" -} -local_cache = "%{testing_cache}" -upload_server = "testing" -upload_user = "%{user}" -upload_servers = { - testing = { - rsync = "localhost/tmp/luarocks_testing", - }, -} -external_deps_dirs = { - "/usr/local", - "/usr", - -- These are used for a test that fails, so it - -- can point to invalid paths: - { - prefix = "/opt", - bin = "bin", - include = "include", - lib = { "lib", "lib64" }, - } -}]]):gsub("%%%b{}", { - ["%{user}"] = os.getenv("USER"), - ["%{testing_sys_tree}"] = testing_paths.testing_sys_tree, - ["%{testing_tree}"] = testing_paths.testing_tree, - ["%{testing_server}"] = testing_paths.testing_server, - ["%{testing_cache}"] = testing_paths.testing_cache}) + --- CONFIG FILES + -- testing_config.lua and testing_config_show_downloads.lua + local config_content = substitute([[ + rocks_trees = { + "%{testing_tree}", + { name = "system", root = "%{testing_sys_tree}" }, + } + rocks_servers = { + "%{testing_server}" + } + local_cache = "%{testing_cache}" + upload_server = "testing" + upload_user = "%{user}" + upload_servers = { + testing = { + rsync = "localhost/tmp/luarocks_testing", + }, + } + external_deps_dirs = { + "/usr/local", + "/usr", + -- These are used for a test that fails, so it + -- can point to invalid paths: + { + prefix = "/opt", + bin = "bin", + include = "include", + lib = { "lib", "lib64" }, + } + } + ]], { + user = os.getenv("USER"), + testing_sys_tree = testing_paths.testing_sys_tree, + testing_tree = testing_paths.testing_tree, + testing_server = testing_paths.testing_server, + testing_cache = testing_paths.testing_cache + }) create_config(testing_paths.testing_dir .. "/testing_config.lua", config_content .. " \nweb_browser = \"true\"") create_config(testing_paths.testing_dir .. "/testing_config_show_downloads.lua", config_content .. "show_downloads = true \n rocks_servers={\"http://luarocks.org/repositories/rocks\"}") --- testing_config_sftp.lua - config_content=([[rocks_trees = { - "%{testing_tree}", - "%{testing_sys_tree}", -} -local_cache = "%{testing_cache}" -upload_server = "testing" -upload_user = "%{user}" -upload_servers = { - testing = { - sftp = "localhost/tmp/luarocks_testing", - }, -}]]):gsub("%%%b{}", { - ["%{user}"] = os.getenv("USER"), - ["%{testing_sys_tree}"] = testing_paths.testing_sys_tree, - ["%{testing_tree}"] = testing_paths.testing_tree, - ["%{testing_cache}"] = testing_paths.testing_cache}) + -- testing_config_sftp.lua + config_content = substitute([[ + rocks_trees = { + "%{testing_tree}", + "%{testing_sys_tree}", + } + local_cache = "%{testing_cache}" + upload_server = "testing" + upload_user = "%{user}" + upload_servers = { + testing = { + sftp = "localhost/tmp/luarocks_testing", + }, + } + ]], { + user = os.getenv("USER"), + testing_sys_tree = testing_paths.testing_sys_tree, + testing_tree = testing_paths.testing_tree, + testing_cache = testing_paths.testing_cache + }) create_config(testing_paths.testing_dir .. "/testing_config_sftp.lua", config_content) --- luacov.config - config_content=([[return { - statsfile = "%{testing_dir}/luacov.stats.out", - reportfile = "%{testing_dir}/luacov.report.out", - modules = { - ["luarocks"] = "src/bin/luarocks", - ["luarocks-admin"] = "src/bin/luarocks-admin", - ["luarocks.*"] = "src", - ["luarocks.*.*"] = "src", - ["luarocks.*.*.*"] = "src" - } -}]]):gsub("%%%b{}", { - ["%{testing_dir}"] = testing_paths.testing_dir}) + -- luacov.config + config_content = substitute([[ + return { + statsfile = "%{testing_dir}/luacov.stats.out", + reportfile = "%{testing_dir}/luacov.report.out", + modules = { + ["luarocks"] = "src/bin/luarocks", + ["luarocks-admin"] = "src/bin/luarocks-admin", + ["luarocks.*"] = "src", + ["luarocks.*.*"] = "src", + ["luarocks.*.*.*"] = "src" + } + } + ]], { + testing_dir = testing_paths.testing_dir + }) create_config(testing_paths.testing_dir .. "/luacov.config", config_content) -- cgit v1.2.3-55-g6feb From c700cd6eee23a46cde73017f5e1e4c06867feb2b Mon Sep 17 00:00:00 2001 From: Peter Melnichenko Date: Fri, 8 Jul 2016 15:16:33 +0300 Subject: Tests: reformat help message --- test/test_environment.lua | 36 +++++++++++++++++++++--------------- 1 file changed, 21 insertions(+), 15 deletions(-) (limited to 'test/test_environment.lua') diff --git a/test/test_environment.lua b/test/test_environment.lua index 4c1b13c8..1edf3987 100644 --- a/test/test_environment.lua +++ b/test/test_environment.lua @@ -1,22 +1,28 @@ local lfs = require("lfs") local test_env = {} -local arg = arg + +local help_message = [[ +LuaRocks test-suite + +INFORMATION + New test-suite for LuaRocks project, using unit testing framework Busted. +REQUIREMENTS + Tests require to have Lua installed and added to PATH. Be sure sshd is + running on your system, or use '--exclude-tags=ssh', to not execute tests + which require sshd. +USAGE + busted [-Xhelper ] +ARGUMENTS + env= Set type of environment to use ("minimal" or "full", + default: "minimal"). + clean Remove existing testing environment. + travis Add if running on TravisCI. + os= Set OS ("linux", "osx", or "windows"). +]] local function help() - print("LuaRocks test-suite\n\n".. - [[ - INFORMATION - New test-suite for LuaRocks project, using unit testing framework Busted. - REQUIREMENTS - Tests require to have Lua installed and added to PATH. Be sure sshd is runnig on your system, or - use '--exclude-tags=ssh', to not execute tests which require sshd. - USAGE -Xhelper - env= (default:"minimal") type what kind of environment to use ["minimal", "full"] - clean remove existing testing environment - travis add just if running on TravisCI - os= type your OS ["linux", "osx", "windows"] - ]]); - os.exit(1) + print(help_message) + os.exit(1) end --- Helper function for execute_bool and execute_output -- cgit v1.2.3-55-g6feb From 34baafd3d7a7d32bc7a3a4c519071de6355d0351 Mon Sep 17 00:00:00 2001 From: Peter Melnichenko Date: Fri, 8 Jul 2016 15:25:54 +0300 Subject: Tests: fix config creation error handling --- test/test_environment.lua | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) (limited to 'test/test_environment.lua') diff --git a/test/test_environment.lua b/test/test_environment.lua index 1edf3987..9f22e701 100644 --- a/test/test_environment.lua +++ b/test/test_environment.lua @@ -198,8 +198,7 @@ end -- @param config_path string: path where to save config file -- @param config_content string: content of this config file local function create_config(config_path, config_content) - local file, err = io.open(config_path, "w+") - if not file then return nil, err end + local file = assert(io.open(config_path, "w")) file:write(config_content) file:close() end -- cgit v1.2.3-55-g6feb From e0f97460ba8d212c8336a7ff2ccec61cf0ec983c Mon Sep 17 00:00:00 2001 From: Peter Melnichenko Date: Fri, 8 Jul 2016 15:30:31 +0300 Subject: Tests: remove optional OS argument in hash_environment --- test/test_environment.lua | 22 ++++++++-------------- 1 file changed, 8 insertions(+), 14 deletions(-) (limited to 'test/test_environment.lua') diff --git a/test/test_environment.lua b/test/test_environment.lua index 9f22e701..372351de 100644 --- a/test/test_environment.lua +++ b/test/test_environment.lua @@ -205,22 +205,16 @@ end --- Create md5sum of directory structure recursively, based on filename and size -- @param path string: path to directory for generate md5sum --- @param testing_os string(optional): version of PC OS -- @return md5sum string: md5sum of directory -local function hash_environment(path, testing_os) - local md5sum = "" - testing_os = testing_os or test_env.TEST_TARGET_OS - - if testing_os == "linux" then - md5sum = execute_output("find " .. path .. " -printf \"%s %p\n\" | md5sum") - end - if testing_os == "osx" then - md5sum = execute_output("find " .. path .. " -type f -exec stat -f \"%z %N\" {} \\; | md5") +local function hash_environment(path) + if test_env.TEST_TARGET_OS == "linux" then + return execute_output("find " .. path .. " -printf \"%s %p\n\" | md5sum") + elseif test_env.TEST_TARGET_OS == "osx" then + return execute_output("find " .. path .. " -type f -exec stat -f \"%z %N\" {} \\; | md5") + else + -- TODO: Windows + return "" end - --TODO if testing_os == "windows" then - -- md5sum = execute_output("find . -printf \"%s %p\n\" | md5sum") - -- end - return md5sum end --- Create environment variables needed for tests -- cgit v1.2.3-55-g6feb From d13af5115615a851125b4b20df370ec4d79ba939 Mon Sep 17 00:00:00 2001 From: Peter Melnichenko Date: Fri, 8 Jul 2016 15:33:45 +0300 Subject: Tests: fix need_luasocket() Return false if installation failed. Also, remove optional arguments. --- test/test_environment.lua | 17 ++++++----------- 1 file changed, 6 insertions(+), 11 deletions(-) (limited to 'test/test_environment.lua') diff --git a/test/test_environment.lua b/test/test_environment.lua index 372351de..a3802cc0 100644 --- a/test/test_environment.lua +++ b/test/test_environment.lua @@ -421,23 +421,18 @@ function test_env.setup_specs(extra_rocks) end --- Helper function for tests which needs luasocket installed -function test_env.need_luasocket(luarocks_nocov, testing_cache, platform) - luarocks_nocov = luarocks_nocov or test_env.run.luarocks_nocov - testing_cache = testing_cache or test_env.testing_paths.testing_cache - platform = platform or test_env.platform - - if luarocks_nocov("show luasocket") then +function test_env.need_luasocket() + if test_env.run.luarocks_nocov("show luasocket") then return true else - testing_cache = testing_cache .. "/" - local luasocket_rock = "luasocket-3.0rc1-1." .. platform .. ".rock" + local testing_cache = test_env.testing_paths.testing_cache .. "/" + local luasocket_rock = "luasocket-3.0rc1-1." .. test_env.platform .. ".rock" if not os.rename( testing_cache .. luasocket_rock, testing_cache .. luasocket_rock) then - luarocks_nocov("build --pack-binary-rock luasocket 3.0rc1-1") + test_env.run.luarocks_nocov("build --pack-binary-rock luasocket 3.0rc1-1") os.rename(luasocket_rock, testing_cache .. luasocket_rock) end - luarocks_nocov("install " .. testing_cache .. luasocket_rock) + return test_env.run.luarocks_nocov("install " .. testing_cache .. luasocket_rock) end - return true end --- For each key-value pair in replacements table -- cgit v1.2.3-55-g6feb From c3975b3758e83486039c04cdd251445ed3e3b938 Mon Sep 17 00:00:00 2001 From: Peter Melnichenko Date: Fri, 8 Jul 2016 15:49:59 +0300 Subject: Tests: move config creation into its function --- test/test_environment.lua | 82 +++++++++++++++++++++++++---------------------- 1 file changed, 44 insertions(+), 38 deletions(-) (limited to 'test/test_environment.lua') diff --git a/test/test_environment.lua b/test/test_environment.lua index a3802cc0..f5cc701e 100644 --- a/test/test_environment.lua +++ b/test/test_environment.lua @@ -194,12 +194,12 @@ local function download_rocks(rocks, save_path) return make_manifest end ---- Create config files for testing --- @param config_path string: path where to save config file --- @param config_content string: content of this config file -local function create_config(config_path, config_content) - local file = assert(io.open(config_path, "w")) - file:write(config_content) +--- Create a file containing a string. +-- @param path string: path to file. +-- @param str string: content of the file. +local function write_file(path, str) + local file = assert(io.open(path, "w")) + file:write(str) file:close() end @@ -443,27 +443,10 @@ local function substitute(str, replacements) end)) end ---- --- Main function to create config files and testing environment -function test_env.main(luaversion_full, env_type, env_clean) - luaversion_full = luaversion_full or test_env.LUA_V or test_env.LUAJIT_V - local testing_paths = create_paths(luaversion_full) - env_clean = env_clean or test_env.TEST_ENV_CLEAN - if env_clean then - print("Cleaning testing directory...") - test_env.remove_dir(testing_paths.luarocks_tmp) - test_env.remove_dir_pattern(testing_paths.testing_dir, "testing_") - test_env.remove_dir_pattern(testing_paths.testing_dir, "testing-") - test_env.remove_files(testing_paths.testing_dir, "testing_") - test_env.remove_files(testing_paths.testing_dir, "luacov") - print("Cleaning done!") - end - - lfs.mkdir(testing_paths.testing_cache) - lfs.mkdir(testing_paths.luarocks_tmp) - - --- CONFIG FILES +--- Create configs for luacov and several versions of Luarocks +-- configs needed for some tests. +local function create_configs() -- testing_config.lua and testing_config_show_downloads.lua local config_content = substitute([[ rocks_trees = { @@ -495,14 +478,14 @@ function test_env.main(luaversion_full, env_type, env_clean) } ]], { user = os.getenv("USER"), - testing_sys_tree = testing_paths.testing_sys_tree, - testing_tree = testing_paths.testing_tree, - testing_server = testing_paths.testing_server, - testing_cache = testing_paths.testing_cache + testing_sys_tree = test_env.testing_paths.testing_sys_tree, + testing_tree = test_env.testing_paths.testing_tree, + testing_server = test_env.testing_paths.testing_server, + testing_cache = test_env.testing_paths.testing_cache }) - create_config(testing_paths.testing_dir .. "/testing_config.lua", config_content .. " \nweb_browser = \"true\"") - create_config(testing_paths.testing_dir .. "/testing_config_show_downloads.lua", config_content + write_file(test_env.testing_paths.testing_dir .. "/testing_config.lua", config_content .. " \nweb_browser = \"true\"") + write_file(test_env.testing_paths.testing_dir .. "/testing_config_show_downloads.lua", config_content .. "show_downloads = true \n rocks_servers={\"http://luarocks.org/repositories/rocks\"}") -- testing_config_sftp.lua @@ -521,12 +504,12 @@ function test_env.main(luaversion_full, env_type, env_clean) } ]], { user = os.getenv("USER"), - testing_sys_tree = testing_paths.testing_sys_tree, - testing_tree = testing_paths.testing_tree, - testing_cache = testing_paths.testing_cache + testing_sys_tree = test_env.testing_paths.testing_sys_tree, + testing_tree = test_env.testing_paths.testing_tree, + testing_cache = test_env.testing_paths.testing_cache }) - create_config(testing_paths.testing_dir .. "/testing_config_sftp.lua", config_content) + write_file(test_env.testing_paths.testing_dir .. "/testing_config_sftp.lua", config_content) -- luacov.config config_content = substitute([[ @@ -542,10 +525,33 @@ function test_env.main(luaversion_full, env_type, env_clean) } } ]], { - testing_dir = testing_paths.testing_dir + testing_dir = test_env.testing_paths.testing_dir }) - create_config(testing_paths.testing_dir .. "/luacov.config", config_content) + write_file(test_env.testing_paths.testing_dir .. "/luacov.config", config_content) +end + +--- +-- Main function to create config files and testing environment +function test_env.main(luaversion_full, env_type, env_clean) + luaversion_full = luaversion_full or test_env.LUA_V or test_env.LUAJIT_V + local testing_paths = create_paths(luaversion_full) + + env_clean = env_clean or test_env.TEST_ENV_CLEAN + if env_clean then + print("Cleaning testing directory...") + test_env.remove_dir(testing_paths.luarocks_tmp) + test_env.remove_dir_pattern(testing_paths.testing_dir, "testing_") + test_env.remove_dir_pattern(testing_paths.testing_dir, "testing-") + test_env.remove_files(testing_paths.testing_dir, "testing_") + test_env.remove_files(testing_paths.testing_dir, "luacov") + print("Cleaning done!") + end + + lfs.mkdir(testing_paths.testing_cache) + lfs.mkdir(testing_paths.luarocks_tmp) + + create_configs() -- Create environment variables for configuration local temp_env_variables = {LUAROCKS_CONFIG = testing_paths.testing_dir .. "/testing_config.lua",LUA_PATH="",LUA_CPATH=""} -- cgit v1.2.3-55-g6feb From 858c649db5107946184e30e67bf861826aa5c64d Mon Sep 17 00:00:00 2001 From: Peter Melnichenko Date: Fri, 8 Jul 2016 15:56:37 +0300 Subject: Tests: remove optional .main() arguments --- test/test_environment.lua | 23 ++++++++++------------- 1 file changed, 10 insertions(+), 13 deletions(-) (limited to 'test/test_environment.lua') diff --git a/test/test_environment.lua b/test/test_environment.lua index f5cc701e..8cc8e295 100644 --- a/test/test_environment.lua +++ b/test/test_environment.lua @@ -533,12 +533,10 @@ end --- -- Main function to create config files and testing environment -function test_env.main(luaversion_full, env_type, env_clean) - luaversion_full = luaversion_full or test_env.LUA_V or test_env.LUAJIT_V - local testing_paths = create_paths(luaversion_full) +function test_env.main() + local testing_paths = test_env.testing_paths - env_clean = env_clean or test_env.TEST_ENV_CLEAN - if env_clean then + if test_env.TEST_ENV_CLEAN then print("Cleaning testing directory...") test_env.remove_dir(testing_paths.luarocks_tmp) test_env.remove_dir_pattern(testing_paths.testing_dir, "testing_") @@ -568,14 +566,12 @@ function test_env.main(luaversion_full, env_type, env_clean) end -- Preparation of rocks for building environment - env_type = env_type or test_env.TYPE_TEST_ENV - local env_rocks = {} -- short names of rocks, required for building environment local rocks = {} -- full names of rocks required for download rocks[#rocks+1] = "/luacov-0.11.0-1.rockspec" rocks[#rocks+1] = "/luacov-0.11.0-1.src.rock" - if env_type == "full" then + if test_env.TYPE_TEST_ENV == "full" then rocks[#rocks+1] = "/luafilesystem-1.6.3-1.src.rock" rocks[#rocks+1] = "/luasocket-3.0rc1-1.src.rock" rocks[#rocks+1] = "/luasocket-3.0rc1-1.rockspec" @@ -583,11 +579,12 @@ function test_env.main(luaversion_full, env_type, env_clean) rocks[#rocks+1] = "/md5-1.2-1.src.rock" rocks[#rocks+1] = "/lzlib-0.4.1.53-1.src.rock" env_rocks = {"luafilesystem", "luasocket", "luaposix", "md5", "lzlib"} - end - if env_type == "full" and luaversion_full ~= "5.1" then - rocks[#rocks+1] = "/luabitop-1.0.2-1.rockspec" - rocks[#rocks+1] = "/luabitop-1.0.2-1.src.rock" - table.insert(env_rocks, "luabitop") + + if test_env.LUA_V ~= "5.1" then + rocks[#rocks+1] = "/luabitop-1.0.2-1.rockspec" + rocks[#rocks+1] = "/luabitop-1.0.2-1.src.rock" + table.insert(env_rocks, "luabitop") + end end table.insert(env_rocks, "luacov") -- luacov is needed for minimal or full environment -- cgit v1.2.3-55-g6feb From b57ce08dce1efa471bc1ae5fad2f154bae426f75 Mon Sep 17 00:00:00 2001 From: Peter Melnichenko Date: Fri, 8 Jul 2016 16:00:57 +0300 Subject: Tests: move clean() into separate function, fix a pattern --- test/test_environment.lua | 18 +++++++++++------- 1 file changed, 11 insertions(+), 7 deletions(-) (limited to 'test/test_environment.lua') diff --git a/test/test_environment.lua b/test/test_environment.lua index 8cc8e295..94acf1c8 100644 --- a/test/test_environment.lua +++ b/test/test_environment.lua @@ -531,19 +531,23 @@ local function create_configs() write_file(test_env.testing_paths.testing_dir .. "/luacov.config", config_content) end +--- Remove testing directories. +local function clean() + print("Cleaning testing directory...") + test_env.remove_dir(test_env.testing_paths.luarocks_tmp) + test_env.remove_dir_pattern(test_env.testing_paths.testing_dir, "testing[_%-]") + test_env.remove_files(test_env.testing_paths.testing_dir, "testing_") + test_env.remove_files(test_env.testing_paths.testing_dir, "luacov") + print("Cleaning done!") +end + --- -- Main function to create config files and testing environment function test_env.main() local testing_paths = test_env.testing_paths if test_env.TEST_ENV_CLEAN then - print("Cleaning testing directory...") - test_env.remove_dir(testing_paths.luarocks_tmp) - test_env.remove_dir_pattern(testing_paths.testing_dir, "testing_") - test_env.remove_dir_pattern(testing_paths.testing_dir, "testing-") - test_env.remove_files(testing_paths.testing_dir, "testing_") - test_env.remove_files(testing_paths.testing_dir, "luacov") - print("Cleaning done!") + clean() end lfs.mkdir(testing_paths.testing_cache) -- cgit v1.2.3-55-g6feb From 1097d6cbc877b22b343b4f4531ce0a1d3b286307 Mon Sep 17 00:00:00 2001 From: Peter Melnichenko Date: Fri, 8 Jul 2016 16:09:05 +0300 Subject: Tests: adjust file/dir removing functions --- test/test_environment.lua | 22 +++++++++------------- 1 file changed, 9 insertions(+), 13 deletions(-) (limited to 'test/test_environment.lua') diff --git a/test/test_environment.lua b/test/test_environment.lua index 94acf1c8..4f684f0a 100644 --- a/test/test_environment.lua +++ b/test/test_environment.lua @@ -122,11 +122,9 @@ function test_env.remove_dir(path) for file in lfs.dir(path) do if file ~= "." and file ~= ".." then local full_path = path..'/'..file - local attr = lfs.attributes(full_path) - if attr.mode == "directory" then + if lfs.attributes(full_path, "mode") == "directory" then test_env.remove_dir(full_path) - os.remove(full_path) else os.remove(full_path) end @@ -136,28 +134,26 @@ function test_env.remove_dir(path) os.remove(path) end ---- Remove directory recursively --- @param path string: directory path to delete --- @param pattern string: pattern in directories -function test_env.remove_dir_pattern(path, pattern) +--- Remove subdirectories of a directory that match a pattern +-- @param path string: path to directory +-- @param pattern string: pattern matching basenames of subdirectories to be removed +function test_env.remove_subdirs(path, pattern) if lfs.attributes(path) then for file in lfs.dir(path) do if file ~= "." and file ~= ".." then local full_path = path..'/'..file - local attr = lfs.attributes(full_path) - if attr.mode == "directory" and file:find(pattern) then + if lfs.attributes(full_path, "mode") == "directory" and file:find(pattern) then test_env.remove_dir(full_path) - os.remove(full_path) end end end end end ---- Remove files based on filename +--- Remove files matching a pattern -- @param path string: directory where to delete files --- @param pattern string: pattern in filenames +-- @param pattern string: pattern matching basenames of files to be deleted -- @return result_check boolean: true if one or more files deleted function test_env.remove_files(path, pattern) local result_check = false @@ -535,7 +531,7 @@ end local function clean() print("Cleaning testing directory...") test_env.remove_dir(test_env.testing_paths.luarocks_tmp) - test_env.remove_dir_pattern(test_env.testing_paths.testing_dir, "testing[_%-]") + test_env.remove_subdirs(test_env.testing_paths.testing_dir, "testing[_%-]") test_env.remove_files(test_env.testing_paths.testing_dir, "testing_") test_env.remove_files(test_env.testing_paths.testing_dir, "luacov") print("Cleaning done!") -- cgit v1.2.3-55-g6feb From f1dc482cdae4af3a7370fef9fea016d037270d51 Mon Sep 17 00:00:00 2001 From: Peter Melnichenko Date: Fri, 8 Jul 2016 16:15:26 +0300 Subject: Tests: move luarocks installation into its own function --- test/test_environment.lua | 31 ++++++++++++++++++------------- 1 file changed, 18 insertions(+), 13 deletions(-) (limited to 'test/test_environment.lua') diff --git a/test/test_environment.lua b/test/test_environment.lua index 4f684f0a..3b03f921 100644 --- a/test/test_environment.lua +++ b/test/test_environment.lua @@ -537,6 +537,17 @@ local function clean() print("Cleaning done!") end +--- Install luarocks into testing prefix. +local function install_luarocks(install_env_vars) + -- Configure LuaRocks testing environment + local configure_cmd = "./configure --with-lua=" .. test_env.testing_paths.luadir .. + " --prefix=" .. test_env.testing_paths.testing_lrprefix .. + " && make clean" + + assert(execute_bool(configure_cmd, false, install_env_vars)) + assert(execute_bool("make src/luarocks/site_config.lua && make dev", false, install_env_vars)) +end + --- -- Main function to create config files and testing environment function test_env.main() @@ -551,19 +562,13 @@ function test_env.main() create_configs() - -- Create environment variables for configuration - local temp_env_variables = {LUAROCKS_CONFIG = testing_paths.testing_dir .. "/testing_config.lua",LUA_PATH="",LUA_CPATH=""} + local install_env_vars = { + LUAROCKS_CONFIG = test_env.testing_paths.testing_dir .. "/testing_config.lua", + LUA_PATH = "", + LUA_CPATH = "" + } - -- Configure LuaRocks testing environment - local configure_cmd = "./configure --with-lua=" .. testing_paths.luadir .. " --prefix=" .. testing_paths.testing_lrprefix - configure_cmd = configure_cmd .. " && make clean" - - if not execute_bool(configure_cmd, false, temp_env_variables) then - os.exit(1) - end - if not execute_bool("make src/luarocks/site_config.lua && make dev", false, temp_env_variables) then - os.exit(1) - end + install_luarocks(install_env_vars) -- Preparation of rocks for building environment local env_rocks = {} -- short names of rocks, required for building environment @@ -593,7 +598,7 @@ function test_env.main() lfs.mkdir(testing_paths.testing_server) download_rocks(rocks, testing_paths.testing_server) - build_environment(env_rocks, testing_paths, temp_env_variables) + build_environment(env_rocks, testing_paths, install_env_vars) print("----------------") print(" RUNNING TESTS") -- cgit v1.2.3-55-g6feb From 3fd5bea3820777f7b1e6373529471b74d68fe523 Mon Sep 17 00:00:00 2001 From: Peter Melnichenko Date: Fri, 8 Jul 2016 16:27:47 +0300 Subject: Tests: utility function for marking sections --- test/test_environment.lua | 22 +++++++++++----------- 1 file changed, 11 insertions(+), 11 deletions(-) (limited to 'test/test_environment.lua') diff --git a/test/test_environment.lua b/test/test_environment.lua index 3b03f921..a3ce7ceb 100644 --- a/test/test_environment.lua +++ b/test/test_environment.lua @@ -25,6 +25,13 @@ local function help() os.exit(1) end +local function title(str) + print() + print(("-"):rep(#str)) + print(str) + print(("-"):rep(#str)) +end + --- Helper function for execute_bool and execute_output -- @param command string: command to execute -- @param print_command boolean: print command if 'true' @@ -102,7 +109,8 @@ function test_env.set_args() end if not test_env.TEST_TARGET_OS then - print("[OS CHECK]") + title("OS CHECK") + if execute_bool("sw_vers") then test_env.TEST_TARGET_OS = "osx" elseif execute_bool("uname -s") then @@ -110,7 +118,6 @@ function test_env.set_args() else test_env.TEST_TARGET_OS = "windows" end - print("--------------") end return true end @@ -287,9 +294,7 @@ end --- Build environment for testing local function build_environment(env_rocks, testing_paths, env_variables) - print("\n--------------------") - print("BUILDING ENVIRONMENT") - print("--------------------") + title("BUILDING ENVIRONMENT") test_env.remove_dir(testing_paths.testing_tree) test_env.remove_dir(testing_paths.testing_sys_tree) test_env.remove_dir(testing_paths.testing_tree_copy) @@ -402,6 +407,7 @@ function test_env.setup_specs(extra_rocks) test_env.platform = execute_output(test_env.testing_paths.lua .. " -e 'print(require(\"luarocks.cfg\").arch)'", false, test_env.env_variables) test_env.md5sums = create_md5sums(test_env.testing_paths) test_env.setup_done = true + title("RUNNING TESTS") end if extra_rocks then @@ -412,8 +418,6 @@ function test_env.setup_specs(extra_rocks) end reset_environment(test_env.testing_paths, test_env.md5sums, test_env.env_variables) - - return true end --- Helper function for tests which needs luasocket installed @@ -599,10 +603,6 @@ function test_env.main() download_rocks(rocks, testing_paths.testing_server) build_environment(env_rocks, testing_paths, install_env_vars) - - print("----------------") - print(" RUNNING TESTS") - print("----------------") end test_env.set_lua_version() -- cgit v1.2.3-55-g6feb From 9d233d0e474efa25e2e5e02bea9f9e54a532fbe0 Mon Sep 17 00:00:00 2001 From: Peter Melnichenko Date: Fri, 8 Jul 2016 16:36:19 +0300 Subject: Tests: adjust build_environment --- test/test_environment.lua | 18 +++++++++++------- 1 file changed, 11 insertions(+), 7 deletions(-) (limited to 'test/test_environment.lua') diff --git a/test/test_environment.lua b/test/test_environment.lua index a3ce7ceb..cfbab89b 100644 --- a/test/test_environment.lua +++ b/test/test_environment.lua @@ -292,9 +292,12 @@ local function make_run_functions() } end ---- Build environment for testing -local function build_environment(env_rocks, testing_paths, env_variables) +--- Rebuild environment. +-- Remove old installed rocks and install new ones, +-- updating manifests and tree copies. +local function build_environment(rocks, env_variables) title("BUILDING ENVIRONMENT") + local testing_paths = test_env.testing_paths test_env.remove_dir(testing_paths.testing_tree) test_env.remove_dir(testing_paths.testing_sys_tree) test_env.remove_dir(testing_paths.testing_tree_copy) @@ -306,10 +309,11 @@ local function build_environment(env_rocks, testing_paths, env_variables) test_env.run.luarocks_admin_nocov("make_manifest " .. testing_paths.testing_server) test_env.run.luarocks_admin_nocov("make_manifest " .. testing_paths.testing_cache) - for _,package in ipairs(env_rocks) do - if not test_env.run.luarocks_nocov("install --only-server=" .. testing_paths.testing_cache .. " --tree=" .. testing_paths.testing_sys_tree .. " " .. package, env_variables) then - test_env.run.luarocks_nocov("build --tree=" .. testing_paths.testing_sys_tree .. " " .. package, env_variables) - test_env.run.luarocks_nocov("pack --tree=" .. testing_paths.testing_sys_tree .. " " .. package .. "; mv " .. package .. "-*.rock " .. testing_paths.testing_cache, env_variables) + for _, rock in ipairs(rocks) do + if not test_env.run.luarocks_nocov("install --only-server=" .. testing_paths.testing_cache .. " --tree=" .. testing_paths.testing_sys_tree .. " " .. rock, env_variables) then + test_env.run.luarocks_nocov("build --tree=" .. testing_paths.testing_sys_tree .. " " .. rock, env_variables) + test_env.run.luarocks_nocov("pack --tree=" .. testing_paths.testing_sys_tree .. " " .. rock, env_variables) + execute_bool("mv " .. rock .. "-*.rock " .. testing_paths.testing_cache) end end @@ -602,7 +606,7 @@ function test_env.main() lfs.mkdir(testing_paths.testing_server) download_rocks(rocks, testing_paths.testing_server) - build_environment(env_rocks, testing_paths, install_env_vars) + build_environment(env_rocks, install_env_vars) end test_env.set_lua_version() -- cgit v1.2.3-55-g6feb From 325c7578cdd5421035930a3a7ee2bb385c10d8fc Mon Sep 17 00:00:00 2001 From: Peter Melnichenko Date: Fri, 8 Jul 2016 16:42:00 +0300 Subject: Tests: adjust rock/rockspec downloading --- test/test_environment.lua | 51 +++++++++++++++++++++++------------------------ 1 file changed, 25 insertions(+), 26 deletions(-) (limited to 'test/test_environment.lua') diff --git a/test/test_environment.lua b/test/test_environment.lua index cfbab89b..065a12c2 100644 --- a/test/test_environment.lua +++ b/test/test_environment.lua @@ -180,17 +180,17 @@ end --- Function for downloading rocks and rockspecs --- @param rocks table: table with full name of rocks/rockspecs to download +-- @param urls table: array of full names of rocks/rockspecs to download -- @param save_path string: path to directory, where to download rocks/rockspecs -- @return make_manifest boolean: true if new rocks downloaded -local function download_rocks(rocks, save_path) +local function download_rocks(urls, save_path) local luarocks_repo = "https://luarocks.org" local make_manifest = false - for _,rock in ipairs(rocks) do + for _, url in ipairs(urls) do -- check if already downloaded - if not os.rename( save_path .. rock, save_path .. rock) then - execute_bool("wget -cP " .. save_path .. " " .. luarocks_repo .. rock) + if not os.rename(save_path .. url, save_path .. url) then + execute_bool("wget -cP " .. save_path .. " " .. luarocks_repo .. url) make_manifest = true end end @@ -579,34 +579,33 @@ function test_env.main() install_luarocks(install_env_vars) -- Preparation of rocks for building environment - local env_rocks = {} -- short names of rocks, required for building environment - local rocks = {} -- full names of rocks required for download - rocks[#rocks+1] = "/luacov-0.11.0-1.rockspec" - rocks[#rocks+1] = "/luacov-0.11.0-1.src.rock" - - if test_env.TYPE_TEST_ENV == "full" then - rocks[#rocks+1] = "/luafilesystem-1.6.3-1.src.rock" - rocks[#rocks+1] = "/luasocket-3.0rc1-1.src.rock" - rocks[#rocks+1] = "/luasocket-3.0rc1-1.rockspec" - rocks[#rocks+1] = "/luaposix-33.2.1-1.src.rock" - rocks[#rocks+1] = "/md5-1.2-1.src.rock" - rocks[#rocks+1] = "/lzlib-0.4.1.53-1.src.rock" - env_rocks = {"luafilesystem", "luasocket", "luaposix", "md5", "lzlib"} + local rocks = {} -- names of rocks, required for building environment + local urls = {} -- names of rock and rockspec files to be downloaded + table.insert(urls, "/luacov-0.11.0-1.rockspec") + table.insert(urls, "/luacov-0.11.0-1.src.rock") + + if test_env.TYPE_TEST_ENV == "full" then + table.insert(urls, "/luafilesystem-1.6.3-1.src.rock") + table.insert(urls, "/luasocket-3.0rc1-1.src.rock") + table.insert(urls, "/luasocket-3.0rc1-1.rockspec") + table.insert(urls, "/luaposix-33.2.1-1.src.rock") + table.insert(urls, "/md5-1.2-1.src.rock") + table.insert(urls, "/lzlib-0.4.1.53-1.src.rock") + rocks = {"luafilesystem", "luasocket", "luaposix", "md5", "lzlib"} if test_env.LUA_V ~= "5.1" then - rocks[#rocks+1] = "/luabitop-1.0.2-1.rockspec" - rocks[#rocks+1] = "/luabitop-1.0.2-1.src.rock" - table.insert(env_rocks, "luabitop") + table.insert(urls, "/luabitop-1.0.2-1.rockspec") + table.insert(urls, "/luabitop-1.0.2-1.src.rock") + table.insert(rocks, "luabitop") end end - table.insert(env_rocks, "luacov") -- luacov is needed for minimal or full environment - + table.insert(rocks, "luacov") -- luacov is needed for minimal or full environment + -- Download rocks needed for LuaRocks testing environment lfs.mkdir(testing_paths.testing_server) - download_rocks(rocks, testing_paths.testing_server) - - build_environment(env_rocks, install_env_vars) + download_rocks(urls, testing_paths.testing_server) + build_environment(rocks, install_env_vars) end test_env.set_lua_version() -- cgit v1.2.3-55-g6feb From 09315362c8c1eb78311586247ddd46f1add1aae6 Mon Sep 17 00:00:00 2001 From: Peter Melnichenko Date: Fri, 8 Jul 2016 16:47:28 +0300 Subject: Tests: add file/dir existence check utility function Use it instead of os.rename(path, path). --- test/test_environment.lua | 30 ++++++++++++++++-------------- 1 file changed, 16 insertions(+), 14 deletions(-) (limited to 'test/test_environment.lua') diff --git a/test/test_environment.lua b/test/test_environment.lua index 065a12c2..a48a59a3 100644 --- a/test/test_environment.lua +++ b/test/test_environment.lua @@ -32,6 +32,10 @@ local function title(str) print(("-"):rep(#str)) end +local function exists(path) + return lfs.attributes(path, "mode") ~= nil +end + --- Helper function for execute_bool and execute_output -- @param command string: command to execute -- @param print_command boolean: print command if 'true' @@ -125,7 +129,7 @@ end --- Remove directory recursively -- @param path string: directory path to delete function test_env.remove_dir(path) - if lfs.attributes(path) then + if exists(path) then for file in lfs.dir(path) do if file ~= "." and file ~= ".." then local full_path = path..'/'..file @@ -145,7 +149,7 @@ end -- @param path string: path to directory -- @param pattern string: pattern matching basenames of subdirectories to be removed function test_env.remove_subdirs(path, pattern) - if lfs.attributes(path) then + if exists(path) then for file in lfs.dir(path) do if file ~= "." and file ~= ".." then local full_path = path..'/'..file @@ -164,7 +168,7 @@ end -- @return result_check boolean: true if one or more files deleted function test_env.remove_files(path, pattern) local result_check = false - if lfs.attributes(path) then + if exists(path) then for file in lfs.dir(path) do if file ~= "." and file ~= ".." then if file:find(pattern) then @@ -189,7 +193,7 @@ local function download_rocks(urls, save_path) for _, url in ipairs(urls) do -- check if already downloaded - if not os.rename(save_path .. url, save_path .. url) then + if not exists(save_path .. url) then execute_bool("wget -cP " .. save_path .. " " .. luarocks_repo .. url) make_manifest = true end @@ -346,21 +350,19 @@ local function create_paths(luaversion_full) if test_env.TRAVIS then testing_paths.luadir = lfs.currentdir() .. "/lua_install" testing_paths.lua = testing_paths.luadir .. "/bin/lua" - end - - if test_env.LUA_V and not test_env.TRAVIS then - if lfs.attributes("/usr/bin/lua") then + elseif test_env.LUA_V then + if exists("/usr/bin/lua") then testing_paths.luadir = "/usr" testing_paths.lua = testing_paths.luadir .. "/bin/lua" - elseif lfs.attributes("/usr/local/bin/lua") then + elseif exists("/usr/local/bin/lua") then testing_paths.luadir = "/usr/local" testing_paths.lua = testing_paths.luadir .. "/bin/lua" end - elseif test_env.LUAJIT_V and not test_env.TRAVIS then - if lfs.attributes("/usr/bin/luajit") then + elseif test_env.LUAJIT_V then + if exists("/usr/bin/luajit") then testing_paths.luadir = "/usr" testing_paths.lua = testing_paths.luadir .. "/bin/luajit" - elseif lfs.attributes("/usr/local/bin/luajit") then + elseif exists("/usr/local/bin/luajit") then testing_paths.luadir = "/usr/local" testing_paths.lua = testing_paths.luadir .. "/bin/luajit" end @@ -397,7 +399,7 @@ function test_env.setup_specs(extra_rocks) -- if global variable about successful creation of testing environment doesn't exists, build environment if not test_env.setup_done then if test_env.TRAVIS then - if not os.rename(os.getenv("HOME") .. "/.ssh/id_rsa.pub", os.getenv("HOME") .. "/.ssh/id_rsa.pub") then + if not exists(os.getenv("HOME") .. "/.ssh/id_rsa.pub") then execute_bool("ssh-keygen -t rsa -P \"\" -f ~/.ssh/id_rsa") execute_bool("cat ~/.ssh/id_rsa.pub >> ~/.ssh/authorized_keys") execute_bool("chmod og-wx ~/.ssh/authorized_keys") @@ -431,7 +433,7 @@ function test_env.need_luasocket() else local testing_cache = test_env.testing_paths.testing_cache .. "/" local luasocket_rock = "luasocket-3.0rc1-1." .. test_env.platform .. ".rock" - if not os.rename( testing_cache .. luasocket_rock, testing_cache .. luasocket_rock) then + if not exists(testing_cache .. luasocket_rock) then test_env.run.luarocks_nocov("build --pack-binary-rock luasocket 3.0rc1-1") os.rename(luasocket_rock, testing_cache .. luasocket_rock) end -- cgit v1.2.3-55-g6feb From a05ba7ce42ae4e42f80b5cacdd8770ae5e6cc04b Mon Sep 17 00:00:00 2001 From: Peter Melnichenko Date: Fri, 8 Jul 2016 20:28:43 +0300 Subject: Infer Lua version using luarocks.cfg when not on travis --- test/test_environment.lua | 32 ++++++-------------------------- 1 file changed, 6 insertions(+), 26 deletions(-) (limited to 'test/test_environment.lua') diff --git a/test/test_environment.lua b/test/test_environment.lua index a48a59a3..6de7a4e2 100644 --- a/test/test_environment.lua +++ b/test/test_environment.lua @@ -7,9 +7,8 @@ LuaRocks test-suite INFORMATION New test-suite for LuaRocks project, using unit testing framework Busted. REQUIREMENTS - Tests require to have Lua installed and added to PATH. Be sure sshd is - running on your system, or use '--exclude-tags=ssh', to not execute tests - which require sshd. + Be sure sshd is running on your system, or use '--exclude-tags=ssh', + to not execute tests which require sshd. USAGE busted [-Xhelper ] ARGUMENTS @@ -343,30 +342,11 @@ local function reset_environment(testing_paths, md5sums) end local function create_paths(luaversion_full) - local testing_paths = {} + local cfg = require("luarocks.cfg") - testing_paths.luadir = "" - - if test_env.TRAVIS then - testing_paths.luadir = lfs.currentdir() .. "/lua_install" - testing_paths.lua = testing_paths.luadir .. "/bin/lua" - elseif test_env.LUA_V then - if exists("/usr/bin/lua") then - testing_paths.luadir = "/usr" - testing_paths.lua = testing_paths.luadir .. "/bin/lua" - elseif exists("/usr/local/bin/lua") then - testing_paths.luadir = "/usr/local" - testing_paths.lua = testing_paths.luadir .. "/bin/lua" - end - elseif test_env.LUAJIT_V then - if exists("/usr/bin/luajit") then - testing_paths.luadir = "/usr" - testing_paths.lua = testing_paths.luadir .. "/bin/luajit" - elseif exists("/usr/local/bin/luajit") then - testing_paths.luadir = "/usr/local" - testing_paths.lua = testing_paths.luadir .. "/bin/luajit" - end - end + local testing_paths = {} + testing_paths.luadir = cfg.variables.LUA_BINDIR:gsub("/bin/?$", "") + testing_paths.lua = cfg.variables.LUA_BINDIR .. "/" .. cfg.lua_interpreter testing_paths.luarocks_tmp = "/tmp/luarocks_testing" --windows? -- cgit v1.2.3-55-g6feb