diff options
Diffstat (limited to 'test/unit/os/shell_spec.lua')
-rw-r--r-- | test/unit/os/shell_spec.lua | 63 |
1 files changed, 26 insertions, 37 deletions
diff --git a/test/unit/os/shell_spec.lua b/test/unit/os/shell_spec.lua index 3603403daf..37274502de 100644 --- a/test/unit/os/shell_spec.lua +++ b/test/unit/os/shell_spec.lua @@ -1,4 +1,5 @@ -local helpers = require('test.unit.helpers') +local helpers = require('test.unit.helpers')(after_each) +local itp = helpers.gen_itp(it) local cimported = helpers.cimport( './src/nvim/os/shell.h', './src/nvim/option_defs.h', @@ -14,7 +15,7 @@ local NULL = ffi.cast('void *', 0) describe('shell functions', 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_sh = to_cstr('/bin/sh') cimported.p_shcf = to_cstr('-c') cimported.p_sxq = to_cstr('') cimported.p_sxe = to_cstr('') @@ -51,63 +52,51 @@ describe('shell functions', function() end describe('os_system', function() - it('can echo some output (shell builtin)', function() - local cmd, text = 'echo -n', 'some text' + itp('can echo some output (shell builtin)', function() + local cmd, text = 'printf "%s "', 'some text ' local status, output = os_system(cmd .. ' ' .. text) eq(text, output) eq(0, status) end) - it('can deal with empty output', function() - local cmd = 'echo -n' + itp('can deal with empty output', function() + local cmd = 'printf ""' local status, output = os_system(cmd) eq('', output) eq(0, status) end) - it('can pass input on stdin', function() + itp('can pass input on stdin', function() local cmd, input = 'cat -', 'some text\nsome other text' local status, output = os_system(cmd, input) eq(input, output) eq(0, status) end) - it ('returns non-zero exit code', function() + itp('returns non-zero exit code', function() local status = os_system('exit 2') eq(2, status) end) end) describe('shell_build_argv', function() - local saved_opts = {} - - setup(function() - saved_opts.p_sh = cimported.p_sh - saved_opts.p_shcf = cimported.p_shcf - end) - - teardown(function() - cimported.p_sh = saved_opts.p_sh - cimported.p_shcf = saved_opts.p_shcf - end) - - it('works with NULL arguments', function() - eq({'/bin/bash'}, shell_build_argv(nil, nil)) + itp('works with NULL arguments', function() + eq({'/bin/sh'}, shell_build_argv(nil, nil)) end) - it('works with cmd', function() - eq({'/bin/bash', '-c', 'abc def'}, shell_build_argv('abc def', nil)) + itp('works with cmd', function() + eq({'/bin/sh', '-c', 'abc def'}, shell_build_argv('abc def', nil)) end) - it('works with extra_args', function() - eq({'/bin/bash', 'ghi jkl'}, shell_build_argv(nil, 'ghi jkl')) + itp('works with extra_args', function() + eq({'/bin/sh', 'ghi jkl'}, shell_build_argv(nil, 'ghi jkl')) end) - it('works with cmd and extra_args', function() - eq({'/bin/bash', 'ghi jkl', '-c', 'abc def'}, shell_build_argv('abc def', 'ghi jkl')) + itp('works with cmd and extra_args', function() + eq({'/bin/sh', 'ghi jkl', '-c', 'abc def'}, shell_build_argv('abc def', 'ghi jkl')) end) - it('splits and unquotes &shell and &shellcmdflag', function() + 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', @@ -117,46 +106,46 @@ describe('shell functions', function() shell_build_argv('abc def', 'ghi jkl')) end) - it('applies shellxescape (p_sxe) and shellxquote (p_sxq)', function() + 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)) - eq(ffi.string(argv[0]), '/bin/bash') + eq(ffi.string(argv[0]), '/bin/sh') eq(ffi.string(argv[1]), '-c') eq(ffi.string(argv[2]), '(echo ^&^|^<^>^(^)^@^^)') eq(nil, argv[3]) end) - it('applies shellxquote="(', function() + itp('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)) - eq(ffi.string(argv[0]), '/bin/bash') + eq(ffi.string(argv[0]), '/bin/sh') eq(ffi.string(argv[1]), '-c') eq(ffi.string(argv[2]), '"(echo -n some text)"') eq(nil, argv[3]) end) - it('applies shellxquote="', function() + itp('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)) - eq(ffi.string(argv[0]), '/bin/bash') + eq(ffi.string(argv[0]), '/bin/sh') eq(ffi.string(argv[1]), '-c') eq(ffi.string(argv[2]), '"echo -n some text"') eq(nil, argv[3]) end) - it('with empty shellxquote/shellxescape', function() + itp('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[0]), '/bin/sh') eq(ffi.string(argv[1]), '-c') eq(ffi.string(argv[2]), 'echo -n some text') eq(nil, argv[3]) |