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(-) 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