diff options
author | Justin M. Keyes <justinkz@gmail.com> | 2016-09-11 01:50:58 +0200 |
---|---|---|
committer | Justin M. Keyes <justinkz@gmail.com> | 2016-09-11 03:04:57 +0200 |
commit | 395ef5642e6e61d8f59d1ef67dd7d203b9bb72e6 (patch) | |
tree | 016d512c7242c48813c38b06eb34cc4ac43b707d /test/unit/os/shell_spec.lua | |
parent | 0991041ae72e866add2a820a6b0401d21b9a8fab (diff) | |
download | rneovim-395ef5642e6e61d8f59d1ef67dd7d203b9bb72e6.tar.gz rneovim-395ef5642e6e61d8f59d1ef67dd7d203b9bb72e6.tar.bz2 rneovim-395ef5642e6e61d8f59d1ef67dd7d203b9bb72e6.zip |
shell_escape: rename; refactor
- rename to shell_xescape_xquote
- move to os/shell.c
- disallow NULL argument
- eliminate casts, nesting
- test: empty shellxquote/shellxescape
Diffstat (limited to 'test/unit/os/shell_spec.lua')
-rw-r--r-- | test/unit/os/shell_spec.lua | 33 |
1 files changed, 17 insertions, 16 deletions
diff --git a/test/unit/os/shell_spec.lua b/test/unit/os/shell_spec.lua index 613a2cfc2c..3603403daf 100644 --- a/test/unit/os/shell_spec.lua +++ b/test/unit/os/shell_spec.lua @@ -12,10 +12,12 @@ local to_cstr = helpers.to_cstr local NULL = ffi.cast('void *', 0) describe('shell functions', function() - setup(function() + before_each(function() -- os_system() can't work when the p_sh and p_shcf variables are unset cimported.p_sh = to_cstr('/bin/bash') cimported.p_shcf = to_cstr('-c') + cimported.p_sxq = to_cstr('') + cimported.p_sxe = to_cstr('') end) local function shell_build_argv(cmd, extra_args) @@ -35,13 +37,6 @@ 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 @@ -121,15 +116,11 @@ describe('shell functions', function() '-c', 'abc def'}, shell_build_argv('abc def', 'ghi jkl')) end) - end) - - describe('shell_build_argv can deal with sxe and sxq', function() - setup(function() + + it('applies shellxescape (p_sxe) and shellxquote (p_sxq)', 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') @@ -138,8 +129,9 @@ describe('shell functions', function() eq(nil, argv[3]) end) - it('applies shellxquote when shellxquote is "\\"("', function() + it('applies shellxquote="(', 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)) @@ -149,7 +141,7 @@ describe('shell functions', function() eq(nil, argv[3]) end) - it('applies shellxquote when shellxquote is "\\""', function() + it('applies shellxquote="', function() cimported.p_sxq = to_cstr('"') cimported.p_sxe = to_cstr('') @@ -160,5 +152,14 @@ describe('shell functions', function() eq(ffi.string(argv[2]), '"echo -n some text"') eq(nil, argv[3]) end) + + it('with empty shellxquote/shellxescape', function() + 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) |