From 2f3c8648289bb4e22eee5f8ff8d27afca6592fa4 Mon Sep 17 00:00:00 2001 From: roboo Date: Sun, 21 Aug 2016 21:50:38 +0200 Subject: Windows and appveyor support for tests --- test/test_environment.lua | 173 +++++++++++++++++++++++++++++++++++----------- 1 file changed, 131 insertions(+), 42 deletions(-) (limited to 'test') diff --git a/test/test_environment.lua b/test/test_environment.lua index 13e548f9..42473b38 100644 --- a/test/test_environment.lua +++ b/test/test_environment.lua @@ -17,6 +17,7 @@ ARGUMENTS noreset Don't reset environment after each test clean Remove existing testing environment. travis Add if running on TravisCI. + appveyor Add if running on Appveyor. os= Set OS ("linux", "osx", or "windows"). ]] @@ -36,18 +37,54 @@ local function exists(path) return lfs.attributes(path, "mode") ~= nil end -function test_env.quiet(commad) +--- Quote argument for shell processing. Fixes paths on Windows. +-- Adds double quotes and escapes. Based on function in fs/win32.lua. +-- @param arg string: Unquoted argument. +-- @return string: Quoted argument. +local function Q(arg) + if test_env.TEST_TARGET_OS == "windows" then + local drive_letter = "[%.a-zA-Z]?:?[\\/]" + -- Quote DIR for Windows + if arg:match("^"..drive_letter) then + arg = arg:gsub("/", "\\") + end + + if arg == "\\" then + return '\\' -- CHDIR needs special handling for root dir + end + + return '"' .. arg .. '"' + else + return "'" .. arg:gsub("'", "'\\''") .. "'" + end +end + +function test_env.quiet(command) if not test_env.VERBOSE then - if test_env.TEST_TARGET_OS == "linux" or test_env.TEST_TARGET_OS == "osx" then - return commad .. " 1> /dev/null 2> /dev/null" - elseif test_env.TEST_TARGET_OS == "windows" then - return commad .. " 2> NUL 1> NUL" + if test_env.TEST_TARGET_OS == "windows" then + return command .. " 1> NUL 2> NUL" + else + return command .. " 1> /dev/null 2> /dev/null" end else return command end end +function test_env.copy(source, destination) + local r_source, err = io.open(source, "r") + local r_destination, err = io.open(destination, "w") + + while true do + local block = r_source:read(8192) + if not block then break end + r_destination:write(block) + end + + r_source:close() + r_destination:close() +end + --- Helper function for execute_bool and execute_output -- @param command string: command to execute -- @param print_command boolean: print command if 'true' @@ -61,15 +98,22 @@ function test_env.execute_helper(command, print_command, env_variables) end if env_variables then - final_command = "export " - for k,v in pairs(env_variables) do - final_command = final_command .. k .. "='" .. v .. "' " + if test_env.TEST_TARGET_OS == "windows" then + for k,v in pairs(env_variables) do + final_command = final_command .. "set " .. k .. "=" .. v .. "&" + end + final_command = final_command:sub(1, -2) .. "&" + else + final_command = "export " + for k,v in pairs(env_variables) do + final_command = final_command .. k .. "='" .. v .. "' " + end + -- remove last space and add ';' to separate exporting variables from command + final_command = final_command:sub(1, -2) .. "; " end - -- remove last space and add ';' to separate exporting variables from command - final_command = final_command:sub(1, -2) .. "; " end - final_command = final_command .. command + final_command = final_command .. command .. " 2>&1" return final_command end @@ -122,6 +166,9 @@ function test_env.set_args() test_env.VERBOSE = true elseif argument == "travis" then test_env.TRAVIS = true + elseif argument == "appveyor" then + test_env.APPVEYOR = true + test_env.APPVEYOR_OPENSSL = "OPENSSL_LIBDIR=C:\\OpenSSL-Win32\\lib OPENSSL_INCDIR=C:\\OpenSSL-Win32\\include" elseif argument:find("^os=") then test_env.TEST_TARGET_OS = argument:match("^os=(.*)$") else @@ -143,6 +190,15 @@ function test_env.set_args() return true end +local function copy_dir(source_path, target_path) + local testing_paths = test_env.testing_paths + if test_env.TEST_TARGET_OS == "windows" then + execute_bool(testing_paths.win_tools .. "/cp -R ".. source_path .. "/. " .. target_path) + else + execute_bool("cp -a ".. source_path .. "/. " .. target_path) + end +end + --- Remove directory recursively -- @param path string: directory path to delete function test_env.remove_dir(path) @@ -159,7 +215,7 @@ function test_env.remove_dir(path) end end end - os.remove(path) + lfs.rmdir(path) end --- Remove subdirectories of a directory that match a pattern @@ -205,13 +261,17 @@ end -- @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(urls, save_path) - local luarocks_repo = "https://luarocks.org" + local luarocks_repo = "https://www.luarocks.org" local make_manifest = false for _, url in ipairs(urls) do -- check if already downloaded if not exists(save_path .. url) then - execute_bool("wget -cP " .. save_path .. " " .. luarocks_repo .. url) + if test_env.TEST_TARGET_OS == "windows" then + execute_bool(test_env.testing_paths.win_tools .. "/wget -cP " .. save_path .. " " .. luarocks_repo .. url .. " --no-check-certificate") + else + execute_bool("wget -cP " .. save_path .. " " .. luarocks_repo .. url) + end make_manifest = true end end @@ -235,9 +295,9 @@ local function hash_environment(path) 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 "" + elseif test_env.TEST_TARGET_OS == "windows" then + return execute_output("\"" .. Q(test_env.testing_paths.win_tools .. "/find") .. " " .. Q(path) + .. " -printf \"%s %p\"\" > temp_sum.txt && certUtil -hashfile temp_sum.txt && del temp_sum.txt") end end @@ -278,13 +338,17 @@ local function create_md5sums(testing_paths) end local function make_run_function(cmd_name, exec_function, with_coverage, do_print) - local cmd_prefix = test_env.testing_paths.lua .. " " + local cmd_prefix = Q(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 .. " " + + if test_env.TEST_TARGET_OS == "windows" then + cmd_prefix = cmd_prefix .. Q(test_env.testing_paths.testing_lrprefix .. "/" .. cmd_name .. ".lua") .. " " + else + cmd_prefix = cmd_prefix .. test_env.testing_paths.src_dir .. "/bin/" .. cmd_name .. " " + end return function(cmd, new_vars) local temp_vars = {} @@ -327,19 +391,23 @@ local function build_environment(rocks, env_variables) lfs.mkdir(testing_paths.testing_tree) lfs.mkdir(testing_paths.testing_sys_tree) - test_env.run.luarocks_admin_nocov("make_manifest " .. testing_paths.testing_server) - test_env.run.luarocks_admin_nocov("make_manifest " .. testing_paths.testing_cache) + test_env.run.luarocks_admin_nocov("make_manifest " .. Q(testing_paths.testing_server)) + test_env.run.luarocks_admin_nocov("make_manifest " .. Q(testing_paths.testing_cache)) 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) + if not test_env.run.luarocks_nocov("install --only-server=" .. testing_paths.testing_cache .. " --tree=" .. testing_paths.testing_sys_tree .. " " .. Q(rock), env_variables) then + test_env.run.luarocks_nocov("build --tree=" .. Q(testing_paths.testing_sys_tree) .. " " .. Q(rock) .. "", env_variables) + test_env.run.luarocks_nocov("pack --tree=" .. Q(testing_paths.testing_sys_tree) .. " " .. Q(rock), env_variables) + if test_env.TEST_TARGET_OS == "windows" then + execute_bool(testing_paths.win_tools .. "/mv " .. rock .. "-*.rock " .. testing_paths.testing_cache) + else + execute_bool("mv " .. rock .. "-*.rock " .. testing_paths.testing_cache) + end end end - - execute_bool("cp -a " .. testing_paths.testing_tree .. "/. " .. testing_paths.testing_tree_copy) - execute_bool("cp -a " .. testing_paths.testing_sys_tree .. "/. " .. testing_paths.testing_sys_tree_copy) + + copy_dir(testing_paths.testing_tree, testing_paths.testing_tree_copy) + copy_dir(testing_paths.testing_sys_tree, testing_paths.testing_sys_tree_copy) end --- Reset testing environment @@ -349,14 +417,13 @@ local function reset_environment(testing_paths, md5sums) if testing_tree_md5 ~= md5sums.testing_tree_copy_md5 then test_env.remove_dir(testing_paths.testing_tree) - execute_bool("cp -a " .. testing_paths.testing_tree_copy .. "/. " .. testing_paths.testing_tree) + copy_dir(testing_paths.testing_tree_copy, testing_paths.testing_tree) end if testing_sys_tree_md5 ~= md5sums.testing_sys_tree_copy_md5 then test_env.remove_dir(testing_paths.testing_sys_tree) - execute_bool("cp -a " .. testing_paths.testing_sys_tree_copy .. "/. " .. testing_paths.testing_sys_tree) + copy_dir(testing_paths.testing_sys_tree_copy, testing_paths.testing_sys_tree) end - print("\n[ENVIRONMENT RESET]") end @@ -367,9 +434,18 @@ local function create_paths(luaversion_full) 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? + if test_env.TEST_TARGET_OS == "windows" then + testing_paths.luarocks_tmp = os.getenv("TEMP") + else + testing_paths.luarocks_tmp = "/tmp/luarocks_testing" + end testing_paths.luarocks_dir = lfs.currentdir() + + if test_env.TEST_TARGET_OS == "windows" then + testing_paths.luarocks_dir = testing_paths.luarocks_dir:gsub("\\","/") + end + testing_paths.testing_dir = testing_paths.luarocks_dir .. "/test" testing_paths.src_dir = testing_paths.luarocks_dir .. "/src" testing_paths.testing_lrprefix = testing_paths.testing_dir .. "/testing_lrprefix-" .. luaversion_full @@ -380,6 +456,10 @@ local function create_paths(luaversion_full) testing_paths.testing_cache = testing_paths.testing_dir .. "/testing_cache-" .. luaversion_full testing_paths.testing_server = testing_paths.testing_dir .. "/testing_server-" .. luaversion_full + if test_env.TEST_TARGET_OS == "windows" then + testing_paths.win_tools = testing_paths.testing_lrprefix .. "/tools" + end + return testing_paths end @@ -409,7 +489,7 @@ function test_env.setup_specs(extra_rocks) test_env.main() package.path = test_env.env_variables.LUA_PATH - test_env.platform = execute_output(test_env.testing_paths.lua .. " -e 'print(require(\"luarocks.cfg\").arch)'", false, 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 title("RUNNING TESTS") @@ -546,13 +626,22 @@ end --- Install luarocks into testing prefix. local function install_luarocks(install_env_vars) - -- Configure LuaRocks testing environment + local testing_paths = test_env.testing_paths title("Installing LuaRocks") - local configure_cmd = "./configure --with-lua=" .. test_env.testing_paths.luadir .. " --prefix=" .. test_env.testing_paths.testing_lrprefix - assert(execute_bool(test_env.quiet(configure_cmd), false, install_env_vars)) - assert(execute_bool(test_env.quiet("make clean"), false, install_env_vars)) - assert(execute_bool(test_env.quiet("make src/luarocks/site_config.lua"), false, install_env_vars)) - assert(execute_bool(test_env.quiet("make dev"), false, install_env_vars)) + if test_env.TEST_TARGET_OS == "windows" then + if test_env.LUA_V then + assert(execute_bool("install.bat /LUA " .. testing_paths.luadir .. " /LV " .. test_env.LUA_V .. " /P " .. testing_paths.testing_lrprefix .. " /NOREG /NOADMIN /F /Q /CONFIG " .. testing_paths.testing_lrprefix .. "/etc/luarocks", false, install_env_vars)) + else + assert(execute_bool("install.bat /LUA " .. testing_paths.luadir .. " /P " .. testing_paths.testing_lrprefix .. " /NOREG /NOADMIN /F /Q /CONFIG " .. testing_paths.testing_lrprefix .. "/etc/luarocks", false, install_env_vars)) + end + assert(execute_bool(testing_paths.win_tools .. "/cp " .. testing_paths.testing_lrprefix .. "/lua/luarocks/site_config* " .. testing_paths.src_dir .. "/luarocks/site_config.lua")) + else + local configure_cmd = "./configure --with-lua=" .. testing_paths.luadir .. " --prefix=" .. testing_paths.testing_lrprefix + assert(execute_bool(configure_cmd, false, install_env_vars)) + assert(execute_bool("make clean", false, install_env_vars)) + assert(execute_bool("make src/luarocks/site_config.lua", false, install_env_vars)) + assert(execute_bool("make dev", false, install_env_vars)) + end print("LuaRocks installed correctly!") end @@ -572,8 +661,8 @@ function test_env.main() local install_env_vars = { LUAROCKS_CONFIG = test_env.testing_paths.testing_dir .. "/testing_config.lua", - LUA_PATH = "", - LUA_CPATH = "" + LUA_PATH, + LUA_CPATH } install_luarocks(install_env_vars) -- cgit v1.2.3-55-g6feb From cb212b167b120490d872cc9e1b8548a0770dd4c4 Mon Sep 17 00:00:00 2001 From: roboo Date: Sun, 21 Aug 2016 22:36:23 +0200 Subject: Update of README --- test/README.md | 11 ++++++++++- 1 file changed, 10 insertions(+), 1 deletion(-) (limited to 'test') diff --git a/test/README.md b/test/README.md index c374438f..5deaa175 100644 --- a/test/README.md +++ b/test/README.md @@ -12,7 +12,7 @@ Test suite for LuaRocks project with Busted unit testing framework(http://olivin ##Usage -Running of tests is based on basic Busted usage. *-Xhelper* flag is mandatory for inserting arguments into testing (primary black-box). Flag *--tags=* or *-t* is mandatory for specifying which tests will run. Mandatory *-Xhelper* flag always needs version of Lua or LuaJIT (e.g. *lua=5.2.4* or *luajit=2.0.3*). Start tests inside LuaRocks folder or specify with *-C* flag. +Running of tests is based on basic Busted usage. *-Xhelper* flag is mandatory for inserting arguments into testing (primary black-box). Flag *--tags=* or *-t* is mandatory for specifying which tests will run. Start tests inside LuaRocks folder or specify with *-C* flag. **Arguments for Busted helper script** @@ -22,7 +22,9 @@ OR luajit=, !mandatory! type your full version of LuaJIT (e.g. luajit=5.2.4) env=, (default:"minimal") type what kind of environment to use ["minimal", "full"] +noreset, Don't reset environment after each test clean, remove existing testing environment +appveyor, add just if running on TravisCI travis, add just if running on TravisCI os=, type your OS ["linux", "os x", "windows"] ``` @@ -35,6 +37,10 @@ os=, type your OS ["linux", "os x", "windows"] **ssh** - run all tests which require ssh +**mock** - run all tests which require mock LuaRocks server (upload tests) + +**unix** - run all tests which are UNIX based, won't work on Windows systems + **w**\_*name-of-command* - whitebox testing of command **b**\_*name-of-command* - blackbox testing of command @@ -42,6 +48,9 @@ os=, type your OS ["linux", "os x", "windows"] for example: `b_install` or `w_help` ###Examples +To run all tests: +`busted` + To run white-box tests in LuaRocks directory type : `busted -t "whitebox"` -- cgit v1.2.3-55-g6feb From beaecdbccb9fa244bbc0253aedd26d372aa312aa Mon Sep 17 00:00:00 2001 From: roboo Date: Sun, 21 Aug 2016 22:46:19 +0200 Subject: Fix of test_environment --- test/test_environment.lua | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) (limited to 'test') diff --git a/test/test_environment.lua b/test/test_environment.lua index 42473b38..1c31462c 100644 --- a/test/test_environment.lua +++ b/test/test_environment.lua @@ -181,7 +181,7 @@ function test_env.set_args() if execute_bool("sw_vers") then test_env.TEST_TARGET_OS = "osx" - elseif execute_bool("uname -s") then + elseif execute_output("uname -s") == "Linux" then test_env.TEST_TARGET_OS = "linux" else test_env.TEST_TARGET_OS = "windows" @@ -321,7 +321,7 @@ local function create_env(testing_paths) env_variables.LUA_PATH = env_variables.LUA_PATH .. testing_paths.src_dir .. "/?.lua;" env_variables.LUA_CPATH = testing_paths.testing_tree .. "/lib/lua/" .. luaversion_short .. "/?.so;" .. testing_paths.testing_sys_tree .. "/lib/lua/" .. luaversion_short .. "/?.so;" - env_variables.PATH = os.getenv("PATH") .. ":" .. testing_paths.testing_tree .. "/bin:" .. testing_paths.testing_sys_tree .. "/bin" + env_variables.PATH = os.getenv("PATH") .. ";" .. testing_paths.testing_tree .. "/bin;" .. testing_paths.testing_sys_tree .. "/bin;" return env_variables end -- cgit v1.2.3-55-g6feb From de72b50eb21fa264a6090c3d062217963c52f74b Mon Sep 17 00:00:00 2001 From: roboo Date: Mon, 22 Aug 2016 16:08:34 +0200 Subject: Remove unused global variables --- test/test_environment.lua | 4 +--- 1 file changed, 1 insertion(+), 3 deletions(-) (limited to 'test') diff --git a/test/test_environment.lua b/test/test_environment.lua index 1c31462c..37bd38f1 100644 --- a/test/test_environment.lua +++ b/test/test_environment.lua @@ -660,9 +660,7 @@ function test_env.main() create_configs() local install_env_vars = { - LUAROCKS_CONFIG = test_env.testing_paths.testing_dir .. "/testing_config.lua", - LUA_PATH, - LUA_CPATH + LUAROCKS_CONFIG = test_env.testing_paths.testing_dir .. "/testing_config.lua" } install_luarocks(install_env_vars) -- cgit v1.2.3-55-g6feb