From 0320a58082f922b54cb36ce57064c07a9e781aa8 Mon Sep 17 00:00:00 2001 From: ZyX Date: Fri, 17 Mar 2017 00:04:03 +0300 Subject: functests: Check that `-s` works as expected --- test/helpers.lua | 39 +++++++++++++++++++++++++++++++++++++-- 1 file changed, 37 insertions(+), 2 deletions(-) (limited to 'test/helpers.lua') diff --git a/test/helpers.lua b/test/helpers.lua index e5224349c2..6ee95a4396 100644 --- a/test/helpers.lua +++ b/test/helpers.lua @@ -1,6 +1,38 @@ local assert = require('luassert') local lfs = require('lfs') +local quote_me = '[^.%w%+%-%@%_%/]' -- complement (needn't quote) +local function shell_quote(str) + if string.find(str, quote_me) or str == '' then + return '"' .. str:gsub('[$%%"\\]', '\\%0') .. '"' + else + return str + end +end + +local function argss_to_cmd(...) + local cmd = '' + for i = 1, select('#', ...) do + local arg = select(i, ...) + if type(arg) == 'string' then + cmd = cmd .. ' ' ..shell_quote(arg) + else + for _, arg in ipairs(arg) do + cmd = cmd .. ' ' .. shell_quote(arg) + end + end + end + return cmd +end + +local function popen_r(...) + return io.popen(argss_to_cmd(...), 'r') +end + +local function popen_w(...) + return io.popen(argss_to_cmd(...), 'w') +end + local check_logs_useless_lines = { ['Warning: noted but unhandled ioctl']=1, ['could cause spurious value errors to appear']=2, @@ -95,7 +127,7 @@ local uname = (function() return platform end - local status, f = pcall(io.popen, "uname -s") + local status, f = pcall(popen_r, 'uname', '-s') if status then platform = f:read("*l") f:close() @@ -215,7 +247,7 @@ local function check_cores(app) end local function which(exe) - local pipe = io.popen('which ' .. exe, 'r') + local pipe = popen_r('which', exe) local ret = pipe:read('*a') pipe:close() if ret == '' then @@ -238,4 +270,7 @@ return { check_cores = check_cores, hasenv = hasenv, which = which, + argss_to_cmd = argss_to_cmd, + popen_r = popen_r, + popen_w = popen_w, } -- cgit From 0e9286a19ed51ba9a2d6bfd06432c90e36cad4bd Mon Sep 17 00:00:00 2001 From: ZyX Date: Fri, 17 Mar 2017 10:57:19 +0300 Subject: tests: Fix CI failures --- test/helpers.lua | 18 ++++++++++++++++-- 1 file changed, 16 insertions(+), 2 deletions(-) (limited to 'test/helpers.lua') diff --git a/test/helpers.lua b/test/helpers.lua index 6ee95a4396..be83ff314b 100644 --- a/test/helpers.lua +++ b/test/helpers.lua @@ -17,8 +17,8 @@ local function argss_to_cmd(...) if type(arg) == 'string' then cmd = cmd .. ' ' ..shell_quote(arg) else - for _, arg in ipairs(arg) do - cmd = cmd .. ' ' .. shell_quote(arg) + for _, subarg in ipairs(arg) do + cmd = cmd .. ' ' .. shell_quote(subarg) end end end @@ -257,6 +257,19 @@ local function which(exe) end end +local function repeated_popen_r(...) + for _ = 1, 10 do + local stream = popen_r(...) + local ret = stream:read('*a') + stream:close() + if ret then + return ret + end + end + print('ERROR: Failed to execute ' .. argss_to_cmd(...) .. ': nil return after 10 attempts') + return nil +end + return { eq = eq, neq = neq, @@ -273,4 +286,5 @@ return { argss_to_cmd = argss_to_cmd, popen_r = popen_r, popen_w = popen_w, + repeated_popen_r = repeated_popen_r, } -- cgit From 3cd7bf31e2351eb2874f8431d290a3d36b0b075e Mon Sep 17 00:00:00 2001 From: ZyX Date: Sat, 18 Mar 2017 00:16:23 +0300 Subject: tests: Fix repeated_popen_r usage, rename the function --- test/helpers.lua | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) (limited to 'test/helpers.lua') diff --git a/test/helpers.lua b/test/helpers.lua index be83ff314b..d739400c71 100644 --- a/test/helpers.lua +++ b/test/helpers.lua @@ -257,7 +257,7 @@ local function which(exe) end end -local function repeated_popen_r(...) +local function repeated_read_cmd(...) for _ = 1, 10 do local stream = popen_r(...) local ret = stream:read('*a') @@ -286,5 +286,5 @@ return { argss_to_cmd = argss_to_cmd, popen_r = popen_r, popen_w = popen_w, - repeated_popen_r = repeated_popen_r, + repeated_read_cmd = repeated_read_cmd, } -- cgit