aboutsummaryrefslogtreecommitdiff
path: root/test/unit/os/shell_spec.lua
diff options
context:
space:
mode:
Diffstat (limited to 'test/unit/os/shell_spec.lua')
-rw-r--r--test/unit/os/shell_spec.lua50
1 files changed, 21 insertions, 29 deletions
diff --git a/test/unit/os/shell_spec.lua b/test/unit/os/shell_spec.lua
index 3fb1afed44..ae162f2317 100644
--- a/test/unit/os/shell_spec.lua
+++ b/test/unit/os/shell_spec.lua
@@ -21,9 +21,7 @@ describe('shell functions', function()
end)
local function shell_build_argv(cmd, extra_args)
- local res = cimported.shell_build_argv(
- cmd and to_cstr(cmd),
- extra_args and to_cstr(extra_args))
+ local res = cimported.shell_build_argv(cmd and to_cstr(cmd), extra_args and to_cstr(extra_args))
-- `res` is zero-indexed (C pointer, not Lua table)!
local argc = 0
local ret = {}
@@ -40,9 +38,7 @@ describe('shell functions', function()
local function shell_argv_to_str(argv_table)
-- C string array (char **).
- local argv = (argv_table
- and ffi.new("char*[?]", #argv_table+1)
- or NULL)
+ local argv = (argv_table and ffi.new('char*[?]', #argv_table + 1) or NULL)
local argc = 1
while argv_table ~= nil and argv_table[argc] ~= nil do
@@ -64,8 +60,7 @@ describe('shell functions', function()
local output = ffi.new('char *[1]')
local nread = ffi.new('size_t[1]')
- local argv = ffi.cast('char**',
- cimported.shell_build_argv(to_cstr(cmd), nil))
+ local argv = ffi.cast('char**', cimported.shell_build_argv(to_cstr(cmd), nil))
local status = cimported.os_system(argv, input_or, input_len, output, nread)
return status, intern(output[0], nread[0])
@@ -101,37 +96,35 @@ describe('shell functions', function()
describe('shell_build_argv', function()
itp('works with NULL arguments', function()
- eq({'/bin/sh'}, shell_build_argv(nil, nil))
+ eq({ '/bin/sh' }, shell_build_argv(nil, nil))
end)
itp('works with cmd', function()
- eq({'/bin/sh', '-c', 'abc def'}, shell_build_argv('abc def', nil))
+ eq({ '/bin/sh', '-c', 'abc def' }, shell_build_argv('abc def', nil))
end)
itp('works with extra_args', function()
- eq({'/bin/sh', 'ghi jkl'}, shell_build_argv(nil, 'ghi jkl'))
+ eq({ '/bin/sh', 'ghi jkl' }, shell_build_argv(nil, 'ghi jkl'))
end)
itp('works with cmd and extra_args', function()
- eq({'/bin/sh', 'ghi jkl', '-c', 'abc def'}, shell_build_argv('abc def', 'ghi jkl'))
+ eq({ '/bin/sh', 'ghi jkl', '-c', 'abc def' }, shell_build_argv('abc def', 'ghi jkl'))
end)
itp('splits and unquotes &shell and &shellcmdflag', function()
cimported.p_sh = to_cstr('/Program" "Files/zsh -f')
cimported.p_shcf = to_cstr('-x -o "sh word split" "-"c')
- eq({'/Program Files/zsh', '-f',
- 'ghi jkl',
- '-x', '-o', 'sh word split',
- '-c', 'abc def'},
- shell_build_argv('abc def', 'ghi jkl'))
+ eq(
+ { '/Program Files/zsh', '-f', 'ghi jkl', '-x', '-o', 'sh word split', '-c', 'abc def' },
+ shell_build_argv('abc def', 'ghi jkl')
+ )
end)
itp('applies shellxescape (p_sxe) and shellxquote (p_sxq)', function()
cimported.p_sxq = to_cstr('(')
cimported.p_sxe = to_cstr('"&|<>()@^')
- local argv = ffi.cast('char**',
- cimported.shell_build_argv(to_cstr('echo &|<>()@^'), nil))
+ local argv = ffi.cast('char**', cimported.shell_build_argv(to_cstr('echo &|<>()@^'), nil))
eq(ffi.string(argv[0]), '/bin/sh')
eq(ffi.string(argv[1]), '-c')
eq(ffi.string(argv[2]), '(echo ^&^|^<^>^(^)^@^^)')
@@ -142,8 +135,7 @@ describe('shell functions', function()
cimported.p_sxq = to_cstr('"(')
cimported.p_sxe = to_cstr('"&|<>()@^')
- local argv = ffi.cast('char**', cimported.shell_build_argv(
- to_cstr('echo -n some text'), nil))
+ local argv = ffi.cast('char**', cimported.shell_build_argv(to_cstr('echo -n some text'), nil))
eq(ffi.string(argv[0]), '/bin/sh')
eq(ffi.string(argv[1]), '-c')
eq(ffi.string(argv[2]), '"(echo -n some text)"')
@@ -154,8 +146,7 @@ describe('shell functions', function()
cimported.p_sxq = to_cstr('"')
cimported.p_sxe = to_cstr('')
- local argv = ffi.cast('char**', cimported.shell_build_argv(
- to_cstr('echo -n some text'), nil))
+ local argv = ffi.cast('char**', cimported.shell_build_argv(to_cstr('echo -n some text'), nil))
eq(ffi.string(argv[0]), '/bin/sh')
eq(ffi.string(argv[1]), '-c')
eq(ffi.string(argv[2]), '"echo -n some text"')
@@ -163,8 +154,7 @@ describe('shell functions', function()
end)
itp('with empty shellxquote/shellxescape', function()
- local argv = ffi.cast('char**', cimported.shell_build_argv(
- to_cstr('echo -n some text'), nil))
+ local argv = ffi.cast('char**', cimported.shell_build_argv(to_cstr('echo -n some text'), nil))
eq(ffi.string(argv[0]), '/bin/sh')
eq(ffi.string(argv[1]), '-c')
eq(ffi.string(argv[2]), 'echo -n some text')
@@ -176,9 +166,11 @@ describe('shell functions', function()
eq('', shell_argv_to_str({ nil }))
eq("''", shell_argv_to_str({ '' }))
eq("'foo' '' 'bar'", shell_argv_to_str({ 'foo', '', 'bar' }))
- eq("'/bin/sh' '-c' 'abc def'", shell_argv_to_str({'/bin/sh', '-c', 'abc def'}))
- eq("'abc def' 'ghi jkl'", shell_argv_to_str({'abc def', 'ghi jkl'}))
- eq("'/bin/sh' '-c' 'abc def' '"..('x'):rep(225).."...",
- shell_argv_to_str({'/bin/sh', '-c', 'abc def', ('x'):rep(999)}))
+ eq("'/bin/sh' '-c' 'abc def'", shell_argv_to_str({ '/bin/sh', '-c', 'abc def' }))
+ eq("'abc def' 'ghi jkl'", shell_argv_to_str({ 'abc def', 'ghi jkl' }))
+ eq(
+ "'/bin/sh' '-c' 'abc def' '" .. ('x'):rep(225) .. '...',
+ shell_argv_to_str({ '/bin/sh', '-c', 'abc def', ('x'):rep(999) })
+ )
end)
end)