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. --- test/test_environment.lua | 22 +++++++++++++++++++--- 1 file changed, 19 insertions(+), 3 deletions(-) (limited to 'test') 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