diff options
Diffstat (limited to 'test')
-rw-r--r-- | test/test_environment.lua | 22 |
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) | |||
119 | end | 119 | end |
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 |
124 | local function execute_bool(command, print_command, env_variables) | 123 | local 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 | ||
129 | end | 145 | end |
130 | 146 | ||
131 | --- Execute command and returns output of command | 147 | --- Execute command and returns output of command |