aboutsummaryrefslogtreecommitdiff
path: root/test
diff options
context:
space:
mode:
authorHisham <hisham@gobolinux.org>2016-09-08 14:04:40 -0300
committerHisham <hisham@gobolinux.org>2016-09-08 14:04:40 -0300
commitf91fc9a6ef9ef488c709894a29ce63db2bc1e399 (patch)
tree3b9dbbe28ad79f2d1115b2048f3cbf9738303373 /test
parentc6d48427430b6b96f88b249dee1533fb5e6ff681 (diff)
downloadluarocks-f91fc9a6ef9ef488c709894a29ce63db2bc1e399.tar.gz
luarocks-f91fc9a6ef9ef488c709894a29ce63db2bc1e399.tar.bz2
luarocks-f91fc9a6ef9ef488c709894a29ce63db2bc1e399.zip
Tests: luarocks_bool commands log their outputs on failure.
Diffstat (limited to 'test')
-rw-r--r--test/test_environment.lua22
1 files changed, 19 insertions, 3 deletions
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)
119end 119end
120 120
121--- Execute command and returns true/false 121--- Execute command and returns true/false
122-- In Lua5.1 os.execute returns numeric value, but in Lua5.2+ returns boolean
123-- @return true/false boolean: status of the command execution 122-- @return true/false boolean: status of the command execution
124local function execute_bool(command, print_command, env_variables) 123local function execute_bool(command, print_command, env_variables)
125 command = test_env.execute_helper(command, print_command, env_variables) 124 command = test_env.execute_helper(command, print_command, env_variables)
126 125
127 local ok = os.execute(command) 126 local redirect_filename
128 return ok == true or ok == 0 127 local redirect = ""
128 if print_command ~= nil then
129 redirect_filename = test_env.testing_paths.luarocks_tmp.."/output.txt"
130 redirect = " > "..redirect_filename
131 end
132 local ok = os.execute(command .. redirect)
133 ok = (ok == true or ok == 0) -- normalize Lua 5.1 output to boolean
134 if redirect ~= "" then
135 if not ok then
136 local fd = io.open(redirect_filename, "r")
137 if fd then
138 print(fd:read("*a"))
139 fd:close()
140 end
141 end
142 os.remove(redirect_filename)
143 end
144 return ok
129end 145end
130 146
131--- Execute command and returns output of command 147--- Execute command and returns output of command