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 From 7225a3d4513137a8e13a5db39538e007b8faa886 Mon Sep 17 00:00:00 2001 From: roboo Date: Mon, 22 Aug 2016 20:57:26 +0200 Subject: Change APPVEYOR_OPENSSL to OPENSSL_DIRS for better test readability --- test/test_environment.lua | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) (limited to 'test') diff --git a/test/test_environment.lua b/test/test_environment.lua index 37bd38f1..ab6c3edd 100644 --- a/test/test_environment.lua +++ b/test/test_environment.lua @@ -153,6 +153,7 @@ end function test_env.set_args() -- 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" + test_env.OPENSSL_DIRS = "" test_env.RESET_ENV = true for _, argument in ipairs(arg) do @@ -168,7 +169,7 @@ function test_env.set_args() 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" + test_env.OPENSSL_DIRS = "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 -- cgit v1.2.3-55-g6feb From 523af94efbedba37bf62279b88e1334fb64c4924 Mon Sep 17 00:00:00 2001 From: Hisham Date: Mon, 22 Aug 2016 16:01:43 -0300 Subject: Add support for testing using MinGW --- appveyor.yml | 18 +++++++++++++++++- test/test_environment.lua | 11 ++++++----- 2 files changed, 23 insertions(+), 6 deletions(-) (limited to 'test') diff --git a/appveyor.yml b/appveyor.yml index 66a12896..0220514f 100644 --- a/appveyor.yml +++ b/appveyor.yml @@ -7,10 +7,25 @@ environment: matrix: - LUA: "lua 5.1" + COMPILER: "msvc" - LUA: "lua 5.2" + COMPILER: "msvc" - LUA: "lua 5.3" + COMPILER: "msvc" - LUA: "luajit 2.0" + COMPILER: "msvc" - LUA: "luajit 2.1" + COMPILER: "msvc" + - LUA: "lua 5.1" + COMPILER: "mingw" + - LUA: "lua 5.2" + COMPILER: "mingw" + - LUA: "lua 5.3" + COMPILER: "mingw" + - LUA: "luajit 2.0" + COMPILER: "mingw" + - LUA: "luajit 2.1" + COMPILER: "mingw" init: @@ -28,7 +43,8 @@ build_script: - luarocks install busted 1> NUL 2> NUL test_script: - - busted --lpath=.//?.lua --exclude-tags=ssh,unix,mock -Xhelper appveyor + - set PATH=C:\MinGW\bin;%PATH% # Add MinGW compiler to the path + - busted --lpath=.//?.lua --exclude-tags=ssh,unix,mock -Xhelper appveyor,%COMPILER% after_test: - if "%LUA%"=="lua 5.1" (luarocks show bit32 || luarocks install bit32) diff --git a/test/test_environment.lua b/test/test_environment.lua index 37bd38f1..f7cdcaa1 100644 --- a/test/test_environment.lua +++ b/test/test_environment.lua @@ -171,6 +171,10 @@ function test_env.set_args() 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=(.*)$") + elseif argument == "mingw" then + test_env.MINGW = true + elseif argument == "msvc" then + test_env.MINGW = false else help() end @@ -629,11 +633,8 @@ local function install_luarocks(install_env_vars) local testing_paths = test_env.testing_paths title("Installing LuaRocks") 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 + local compiler_flag = test_env.MINGW and "/MW" or "" + 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)) 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 -- cgit v1.2.3-55-g6feb From ec177a4227d14ad28556baa5132376337feea7fb Mon Sep 17 00:00:00 2001 From: Hisham Date: Mon, 22 Aug 2016 17:24:22 -0300 Subject: Build Lua using the same compiler as the one we're testing --- appveyor.yml | 20 ++++++++++---------- test/test_environment.lua | 2 +- 2 files changed, 11 insertions(+), 11 deletions(-) (limited to 'test') diff --git a/appveyor.yml b/appveyor.yml index 0220514f..94fd6289 100644 --- a/appveyor.yml +++ b/appveyor.yml @@ -7,23 +7,23 @@ environment: matrix: - LUA: "lua 5.1" - COMPILER: "msvc" - - LUA: "lua 5.2" - COMPILER: "msvc" - - LUA: "lua 5.3" - COMPILER: "msvc" - - LUA: "luajit 2.0" - COMPILER: "msvc" - - LUA: "luajit 2.1" - COMPILER: "msvc" + COMPILER: "vs" - LUA: "lua 5.1" COMPILER: "mingw" + - LUA: "lua 5.2" + COMPILER: "vs" - LUA: "lua 5.2" COMPILER: "mingw" + - LUA: "lua 5.3" + COMPILER: "vs" - LUA: "lua 5.3" COMPILER: "mingw" + - LUA: "luajit 2.0" + COMPILER: "vs" - LUA: "luajit 2.0" COMPILER: "mingw" + - LUA: "luajit 2.1" + COMPILER: "vs" - LUA: "luajit 2.1" COMPILER: "mingw" @@ -36,7 +36,7 @@ init: before_build: - set PATH=C:\Python27\Scripts;%PATH% # Add directory containing 'pip' to PATH - pip install hererocks - - hererocks env --%LUA% -rlatest + - hererocks env --%LUA% -rlatest --target=%COMPILER% - call env\bin\activate build_script: diff --git a/test/test_environment.lua b/test/test_environment.lua index f7cdcaa1..764cd65f 100644 --- a/test/test_environment.lua +++ b/test/test_environment.lua @@ -173,7 +173,7 @@ function test_env.set_args() test_env.TEST_TARGET_OS = argument:match("^os=(.*)$") elseif argument == "mingw" then test_env.MINGW = true - elseif argument == "msvc" then + elseif argument == "vs" then test_env.MINGW = false else help() -- cgit v1.2.3-55-g6feb From f91fc9a6ef9ef488c709894a29ce63db2bc1e399 Mon Sep 17 00:00:00 2001 From: Hisham Date: Thu, 8 Sep 2016 14:04:40 -0300 Subject: Tests: luarocks_bool commands log their outputs on failure. --- spec/build_spec.lua | 8 ++++---- spec/help_spec.lua | 4 ++-- spec/install_spec.lua | 12 ++++++------ spec/make_spec.lua | 8 ++++---- spec/pack_spec.lua | 4 ++-- spec/search_spec.lua | 2 +- test/test_environment.lua | 22 +++++++++++++++++++--- 7 files changed, 38 insertions(+), 22 deletions(-) (limited to 'test') diff --git a/spec/build_spec.lua b/spec/build_spec.lua index 8f08f0a0..2ff7cbe6 100644 --- a/spec/build_spec.lua +++ b/spec/build_spec.lua @@ -92,7 +92,7 @@ describe("LuaRocks build tests #blackbox #b_build", function() describe("LuaRocks build - basic builds", function() it("LuaRocks build luadoc", function() - assert.is_true(run.luarocks_bool(test_env.quiet("build luadoc"))) + assert.is_true(run.luarocks_bool("build luadoc")) end) it("LuaRocks build luacov diff version", function() @@ -114,7 +114,7 @@ describe("LuaRocks build tests #blackbox #b_build", function() if test_env.TEST_TARGET_OS == "windows" then assert.is_false(run.luarocks_bool("build lpty")) --Error: This rockspec for lpty does not support win32, windows platforms else - assert.is_true(run.luarocks_bool(test_env.quiet("build lpty"))) + assert.is_true(run.luarocks_bool("build lpty")) assert.is.truthy(lfs.attributes(testing_paths.testing_sys_tree .. "/lib/luarocks/rocks/lpty/1.0.1-1/lpty-1.0.1-1.rockspec")) end end) @@ -146,7 +146,7 @@ describe("LuaRocks build tests #blackbox #b_build", function() end it("LuaRocks build luasec only deps", function() - assert.is_true(run.luarocks_bool(test_env.quiet("build luasec " .. test_env.OPENSSL_DIRS .. " --only-deps"))) + assert.is_true(run.luarocks_bool("build luasec " .. test_env.OPENSSL_DIRS .. " --only-deps")) assert.is_false(run.luarocks_bool("show luasec")) assert.is.falsy(lfs.attributes(testing_paths.testing_sys_tree .. "/lib/luarocks/rocks/luasec/0.6-1/luasec-0.6-1.rockspec")) end) @@ -181,7 +181,7 @@ describe("LuaRocks build tests #blackbox #b_build", function() it("LuaRocks build with https", function() assert.is_true(run.luarocks_bool("download --rockspec validate-args 1.5.4-1")) - assert.is_true(run.luarocks_bool(test_env.quiet("install luasec " .. test_env.OPENSSL_DIRS))) + assert.is_true(run.luarocks_bool("install luasec " .. test_env.OPENSSL_DIRS)) assert.is_true(run.luarocks_bool("build validate-args-1.5.4-1.rockspec")) assert.is.truthy(run.luarocks("show validate-args")) diff --git a/spec/help_spec.lua b/spec/help_spec.lua index 88aa5030..71b1b9f6 100644 --- a/spec/help_spec.lua +++ b/spec/help_spec.lua @@ -10,7 +10,7 @@ describe("LuaRocks help tests #blackbox #b_help", function() end) it("LuaRocks help with no flags/arguments", function() - assert.is_true(run.luarocks_bool(test_env.quiet("help"))) + assert.is_true(run.luarocks_bool("help")) end) it("LuaRocks help invalid argument", function() @@ -18,7 +18,7 @@ describe("LuaRocks help tests #blackbox #b_help", function() end) it("LuaRocks help config", function() - assert.is_true(run.luarocks_bool(test_env.quiet("help config"))) + assert.is_true(run.luarocks_bool("help config")) end) it("LuaRocks-admin help with no flags/arguments", function() diff --git a/spec/install_spec.lua b/spec/install_spec.lua index e5b9e2cc..8857e4bd 100644 --- a/spec/install_spec.lua +++ b/spec/install_spec.lua @@ -66,15 +66,15 @@ describe("LuaRocks install tests #blackbox #b_install", function() end) it("LuaRocks install luasec and show luasocket (dependency)", function() - assert.is_true(run.luarocks_bool(test_env.quiet("install luasec " .. test_env.OPENSSL_DIRS))) + assert.is_true(run.luarocks_bool("install luasec " .. test_env.OPENSSL_DIRS)) assert.is_true(run.luarocks_bool("show luasocket")) end) end) describe("LuaRocks install - more complex tests", function() it('LuaRocks install luasec with skipping dependency checks', function() - assert.is_true(run.luarocks_bool(test_env.quiet("install luasec " .. test_env.OPENSSL_DIRS .. " --nodeps"))) - assert.is_true(run.luarocks_bool(test_env.quiet("show luasec"))) + assert.is_true(run.luarocks_bool("install luasec " .. test_env.OPENSSL_DIRS .. " --nodeps")) + assert.is_true(run.luarocks_bool("show luasec")) if env_variables.TYPE_TEST_ENV == "minimal" then assert.is_false(run.luarocks_bool(test_env.quiet("show luasocket"))) assert.is.falsy(lfs.attributes(testing_paths.testing_sys_tree .. "/lib/luarocks/rocks/luasocket")) @@ -83,21 +83,21 @@ describe("LuaRocks install tests #blackbox #b_install", function() end) it("LuaRocks install only-deps of luasocket packed rock", function() - assert.is_true(run.luarocks_bool(test_env.quiet("build --pack-binary-rock luasocket 3.0rc1-2"))) + assert.is_true(run.luarocks_bool("build --pack-binary-rock luasocket 3.0rc1-2")) local output = run.luarocks("install --only-deps " .. "luasocket-3.0rc1-2." .. test_env.platform .. ".rock") assert.are.same(output, "Successfully installed dependencies for luasocket 3.0rc1-2") assert.is_true(os.remove("luasocket-3.0rc1-2." .. test_env.platform .. ".rock")) end) it("LuaRocks install reinstall", function() - assert.is_true(run.luarocks_bool(test_env.quiet("build --pack-binary-rock luasocket 3.0rc1-2"))) + assert.is_true(run.luarocks_bool("build --pack-binary-rock luasocket 3.0rc1-2")) assert.is_true(run.luarocks_bool("install " .. "luasocket-3.0rc1-2." .. test_env.platform .. ".rock")) assert.is_true(run.luarocks_bool("install --deps-mode=none " .. "luasocket-3.0rc1-2." .. test_env.platform .. ".rock")) assert.is_true(os.remove("luasocket-3.0rc1-2." .. test_env.platform .. ".rock")) end) it("LuaRocks install binary rock of cprint", function() - assert.is_true(run.luarocks_bool(test_env.quiet("build --pack-binary-rock cprint"))) + assert.is_true(run.luarocks_bool("build --pack-binary-rock cprint")) assert.is_true(run.luarocks_bool("install cprint-0.1-2." .. test_env.platform .. ".rock")) assert.is_true(os.remove("cprint-0.1-2." .. test_env.platform .. ".rock")) end) diff --git a/spec/make_spec.lua b/spec/make_spec.lua index 624badff..ae79a29c 100644 --- a/spec/make_spec.lua +++ b/spec/make_spec.lua @@ -30,10 +30,10 @@ describe("LuaRocks make tests #blackbox #b_make", function() assert.is_true(run.luarocks_bool("download --source luasocket 3.0rc1-2")) assert.is_true(run.luarocks_bool("unpack luasocket-3.0rc1-2.src.rock")) lfs.chdir("luasocket-3.0rc1-2/luasocket-3.0-rc1/") - assert.is_true(run.luarocks_bool(test_env.quiet("make luasocket-3.0rc1-2.rockspec"))) + assert.is_true(run.luarocks_bool("make luasocket-3.0rc1-2.rockspec")) -- test it - assert.is_true(run.luarocks_bool(test_env.quiet("show luasocket"))) + assert.is_true(run.luarocks_bool("show luasocket")) assert.is.truthy(lfs.attributes(testing_paths.testing_sys_tree .. "/lib/luarocks/rocks/luasocket/3.0rc1-2/luasocket-3.0rc1-2.rockspec")) -- delete downloaded and unpacked files @@ -69,7 +69,7 @@ describe("LuaRocks make tests #blackbox #b_make", function() test_env.copy("lxsh-0.8.6-2.rockspec", "rockspec") assert.is_true(run.luarocks_bool("make")) - assert.is_true(run.luarocks_bool(test_env.quiet("show lxsh"))) + assert.is_true(run.luarocks_bool("show lxsh")) assert.is.truthy(lfs.attributes(testing_paths.testing_sys_tree .. "/lib/luarocks/rocks/lxsh/0.8.6-2/lxsh-0.8.6-2.rockspec")) os.remove("rockspec") end) @@ -94,7 +94,7 @@ describe("LuaRocks make tests #blackbox #b_make", function() end) it("LuaRocks make pack binary rock", function() - assert.is_true(run.luarocks_bool(test_env.quiet("make --deps-mode=none --pack-binary-rock"))) + assert.is_true(run.luarocks_bool("make --deps-mode=none --pack-binary-rock")) assert.is.truthy(lfs.attributes("lxsh-0.8.6-2.all.rock")) end) end) diff --git a/spec/pack_spec.lua b/spec/pack_spec.lua index 3191e80c..3c9ed9fd 100644 --- a/spec/pack_spec.lua +++ b/spec/pack_spec.lua @@ -25,7 +25,7 @@ describe("LuaRocks pack tests #blackbox #b_pack", function() end) it("LuaRocks pack basic", function() - assert.is_true(run.luarocks_bool(test_env.quiet("pack luacov"))) + assert.is_true(run.luarocks_bool("pack luacov")) assert.is_true(test_env.remove_files(lfs.currentdir(), "luacov-")) end) @@ -49,7 +49,7 @@ describe("LuaRocks pack tests #blackbox #b_pack", function() end) it("LuaRocks pack src", function() - assert.is_true(run.luarocks_bool(test_env.quiet("install luasec " .. test_env.OPENSSL_DIRS))) + assert.is_true(run.luarocks_bool("install luasec " .. test_env.OPENSSL_DIRS)) assert.is_true(run.luarocks_bool("download --rockspec luasocket 3.0rc1-2")) assert.is_true(run.luarocks_bool("pack luasocket-3.0rc1-2.rockspec")) assert.is_true(test_env.remove_files(lfs.currentdir(), "luasocket-")) diff --git a/spec/search_spec.lua b/spec/search_spec.lua index f75bc3c1..04f84eeb 100644 --- a/spec/search_spec.lua +++ b/spec/search_spec.lua @@ -30,6 +30,6 @@ describe("LuaRocks search tests #blackbox #b_search", function() end) it("LuaRocks search with flag all", function() - assert.is_true(run.luarocks_bool(test_env.quiet("search --all"))) + assert.is_true(run.luarocks_bool("search --all")) end) end) diff --git a/test/test_environment.lua b/test/test_environment.lua index 00213d31..8239795d 100644 --- a/test/test_environment.lua +++ b/test/test_environment.lua @@ -119,13 +119,29 @@ function test_env.execute_helper(command, print_command, env_variables) end --- Execute command and returns true/false --- In Lua5.1 os.execute returns numeric value, but in Lua5.2+ returns boolean -- @return true/false boolean: status of the command execution local function execute_bool(command, print_command, env_variables) command = test_env.execute_helper(command, print_command, env_variables) - local ok = os.execute(command) - return ok == true or ok == 0 + local redirect_filename + local redirect = "" + if print_command ~= nil then + redirect_filename = test_env.testing_paths.luarocks_tmp.."/output.txt" + redirect = " > "..redirect_filename + end + local ok = os.execute(command .. redirect) + ok = (ok == true or ok == 0) -- normalize Lua 5.1 output to boolean + if redirect ~= "" then + if not ok then + local fd = io.open(redirect_filename, "r") + if fd then + print(fd:read("*a")) + fd:close() + end + end + os.remove(redirect_filename) + end + return ok end --- Execute command and returns output of command -- cgit v1.2.3-55-g6feb From 87f2b81d3bf95e9c3bd99b1c09a8260c90a07d3b Mon Sep 17 00:00:00 2001 From: Hisham Date: Thu, 8 Sep 2016 14:59:47 -0300 Subject: Remove old testing.bat --- test/testing.bat | 9 --------- 1 file changed, 9 deletions(-) delete mode 100644 test/testing.bat (limited to 'test') diff --git a/test/testing.bat b/test/testing.bat deleted file mode 100644 index 7083678b..00000000 --- a/test/testing.bat +++ /dev/null @@ -1,9 +0,0 @@ -@echo off -Setlocal EnableDelayedExpansion EnableExtensions - -if not defined LUAROCKS_REPO set LUAROCKS_REPO=https://luarocks.org - -appveyor DownloadFile %LUAROCKS_REPO%/stdlib-41.0.0-1.src.rock -luarocks build stdlib - -endlocal -- cgit v1.2.3-55-g6feb