aboutsummaryrefslogtreecommitdiff
path: root/test/unit
diff options
context:
space:
mode:
authorZhaosheng Pan <brglng@gmail.com>2015-06-03 19:01:17 +0800
committerJustin M. Keyes <justinkz@gmail.com>2016-09-10 22:21:40 +0200
commit0991041ae72e866add2a820a6b0401d21b9a8fab (patch)
tree830b721746e9734b221210d7dbaac32c5186a399 /test/unit
parentbccb49bedb9b5fe0a3635e2be4aa2d168c5d3051 (diff)
downloadrneovim-0991041ae72e866add2a820a6b0401d21b9a8fab.tar.gz
rneovim-0991041ae72e866add2a820a6b0401d21b9a8fab.tar.bz2
rneovim-0991041ae72e866add2a820a6b0401d21b9a8fab.zip
system(): Respect 'sxe' and 'sxq' #2789
Fixes #2773
Diffstat (limited to 'test/unit')
-rw-r--r--test/unit/os/shell_spec.lua58
1 files changed, 46 insertions, 12 deletions
diff --git a/test/unit/os/shell_spec.lua b/test/unit/os/shell_spec.lua
index 906f950308..613a2cfc2c 100644
--- a/test/unit/os/shell_spec.lua
+++ b/test/unit/os/shell_spec.lua
@@ -1,15 +1,3 @@
--- not all operating systems support the system()-tests, as of yet.
-local allowed_os = {
- Linux = true,
- OSX = true,
- BSD = true,
- POSIX = true
-}
-
-if allowed_os[jit.os] ~= true then
- return
-end
-
local helpers = require('test.unit.helpers')
local cimported = helpers.cimport(
'./src/nvim/os/shell.h',
@@ -47,6 +35,13 @@ describe('shell functions', function()
return ret
end
+ after_each(function()
+ cimported.p_sxq = to_cstr('')
+ cimported.p_sxe = to_cstr('')
+ cimported.p_sh = to_cstr('/bin/bash')
+ cimported.p_shcf = to_cstr('-c')
+ end)
+
local function os_system(cmd, input)
local input_or = input and to_cstr(input) or NULL
local input_len = (input ~= nil) and string.len(input) or 0
@@ -127,4 +122,43 @@ describe('shell functions', function()
shell_build_argv('abc def', 'ghi jkl'))
end)
end)
+
+ describe('shell_build_argv can deal with sxe and sxq', function()
+ setup(function()
+ cimported.p_sxq = to_cstr('(')
+ cimported.p_sxe = to_cstr('"&|<>()@^')
+ end)
+
+ it('applies shellxescape and shellxquote', function()
+ local argv = ffi.cast('char**',
+ cimported.shell_build_argv(to_cstr('echo &|<>()@^'), nil))
+ eq(ffi.string(argv[0]), '/bin/bash')
+ eq(ffi.string(argv[1]), '-c')
+ eq(ffi.string(argv[2]), '(echo ^&^|^<^>^(^)^@^^)')
+ eq(nil, argv[3])
+ end)
+
+ it('applies shellxquote when shellxquote is "\\"("', function()
+ cimported.p_sxq = to_cstr('"(')
+
+ local argv = ffi.cast('char**', cimported.shell_build_argv(
+ to_cstr('echo -n some text'), nil))
+ eq(ffi.string(argv[0]), '/bin/bash')
+ eq(ffi.string(argv[1]), '-c')
+ eq(ffi.string(argv[2]), '"(echo -n some text)"')
+ eq(nil, argv[3])
+ end)
+
+ it('applies shellxquote when shellxquote is "\\""', 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))
+ eq(ffi.string(argv[0]), '/bin/bash')
+ eq(ffi.string(argv[1]), '-c')
+ eq(ffi.string(argv[2]), '"echo -n some text"')
+ eq(nil, argv[3])
+ end)
+ end)
end)