diff options
author | Rui Abreu Ferreira <raf-ep@gmx.com> | 2016-08-25 17:28:54 +0100 |
---|---|---|
committer | Justin M. Keyes <justinkz@gmail.com> | 2017-01-11 01:05:55 +0100 |
commit | ac44d0ed540671f528358149edfd58942d7f6536 (patch) | |
tree | 6eada28fc8a14a48b6f4b128f3a5f90adcf302c2 | |
parent | a05ebf4a2dd82e7e440777b3814f9f3c2d18456e (diff) | |
download | rneovim-ac44d0ed540671f528358149edfd58942d7f6536.tar.gz rneovim-ac44d0ed540671f528358149edfd58942d7f6536.tar.bz2 rneovim-ac44d0ed540671f528358149edfd58942d7f6536.zip |
test: system([...])
-rw-r--r-- | CMakeLists.txt | 7 | ||||
-rw-r--r-- | test/functional/eval/system_spec.lua | 72 | ||||
-rw-r--r-- | test/functional/fixtures/CMakeLists.txt | 1 | ||||
-rw-r--r-- | test/functional/fixtures/printargs-test.c | 9 |
4 files changed, 62 insertions, 27 deletions
diff --git a/CMakeLists.txt b/CMakeLists.txt index cb8302deb7..fdd6f0ed79 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -489,10 +489,9 @@ if(BUSTED_PRG) ${CMAKE_BINARY_DIR}/test/config/paths.lua) set(UNITTEST_PREREQS nvim-test unittest-headers) - if(WIN32) - set(FUNCTIONALTEST_PREREQS nvim shell-test) - else() - set(FUNCTIONALTEST_PREREQS nvim tty-test shell-test) + set(FUNCTIONALTEST_PREREQS nvim printargs-test shell-test) + if(NOT WIN32) + list(APPEND FUNCTIONALTEST_PREREQS tty-test) endif() set(BENCHMARK_PREREQS nvim tty-test) diff --git a/test/functional/eval/system_spec.lua b/test/functional/eval/system_spec.lua index 6393477260..09497e85c2 100644 --- a/test/functional/eval/system_spec.lua +++ b/test/functional/eval/system_spec.lua @@ -1,12 +1,10 @@ local helpers = require('test.functional.helpers')(after_each) -local eq, clear, eval, execute, feed, nvim = - helpers.eq, helpers.clear, helpers.eval, helpers.execute, helpers.feed, - helpers.nvim +local eq, call, clear, eval, execute, feed, nvim = + helpers.eq, helpers.call, helpers.clear, helpers.eval, helpers.execute, + helpers.feed, helpers.nvim local Screen = require('test.functional.ui.screen') -if helpers.pending_win32(pending) then return end - local function create_file_with_nuls(name) return function() feed('ipart1<C-V>000part2<C-V>000part3<ESC>:w '..name..'<CR>') @@ -31,7 +29,41 @@ end describe('system()', function() before_each(clear) - it('sets the v:shell_error variable', function() + describe('command passed as a List', function() + local printargs_path = helpers.nvim_dir..'/printargs-test' + .. (helpers.os_name() == 'windows' and '.exe' or '') + + it('quotes arguments correctly #5280', function() + local out = call('system', + { printargs_path, [[1]], [[2 "3]], [[4 ' 5]], [[6 ' 7']] }) + eq(0, eval('v:shell_error')) + eq([[arg1=1;arg2=2 "3;arg3=4 ' 5;arg4=6 ' 7';]], out) + + out = call('system', { printargs_path, [['1]], [[2 "3]] }) + eq(0, eval('v:shell_error')) + eq([[arg1='1;arg2=2 "3;]], out) + + out = call('system', { printargs_path, "A\nB" }) + eq(0, eval('v:shell_error')) + eq("arg1=A\nB;", out) + end) + + it('calls executable in $PATH', function() + if 0 == eval("executable('python')") then pending("missing `python`") end + eq("foo\n", eval([[system(['python', '-c', 'print("foo")'])]])) + eq(0, eval('v:shell_error')) + end) + + it('does NOT run in shell', function() + if helpers.os_name() ~= 'windows' then + eq("* $PATH %PATH%\n", eval("system(['echo', '*', '$PATH', '%PATH%'])")) + end + end) + end) + + if helpers.pending_win32(pending) then return end + + it('sets v:shell_error', function() eval([[system("sh -c 'exit'")]]) eq(0, eval('v:shell_error')) eval([[system("sh -c 'exit 1'")]]) @@ -158,7 +190,7 @@ describe('system()', function() end) end) - describe('passing number as input', function() + describe('input passed as Number', function() it('stringifies the input', function() eq('1', eval('system("cat", 1)')) end) @@ -175,8 +207,8 @@ describe('system()', function() end) end) - describe('passing list as input', function() - it('joins list items with linefeed characters', function() + describe('input passed as List', function() + it('joins List items with linefeed characters', function() eq('line1\nline2\nline3', eval("system('cat -', ['line1', 'line2', 'line3'])")) end) @@ -185,7 +217,7 @@ describe('system()', function() -- is inconsistent and is a good reason for the existence of the -- `systemlist()` function, where input and output map to the same -- characters(see the following tests with `systemlist()` below) - describe('with linefeed characters inside list items', function() + describe('with linefeed characters inside List items', function() it('converts linefeed characters to NULs', function() eq('l1\001p2\nline2\001a\001b\nl3', eval([[system('cat -', ["l1\np2", "line2\na\nb", 'l3'])]])) @@ -202,7 +234,7 @@ describe('system()', function() describe("with a program that doesn't close stdout", function() if not xclip then - pending('skipped (missing xclip)', function() end) + pending('missing `xclip`', function() end) else it('will exit properly after passing input', function() eq('', eval([[system('xclip -i -selection clipboard', 'clip-data')]])) @@ -210,18 +242,12 @@ describe('system()', function() end) end end) - - describe('command passed as a list', function() - it('does not execute &shell', function() - eq('* $NOTHING ~/file', - eval("system(['echo', '-n', '*', '$NOTHING', '~/file'])")) - end) - end) end) +if helpers.pending_win32(pending) then return end + describe('systemlist()', function() - -- behavior is similar to `system()` but it returns a list instead of a - -- string. + -- Similar to `system()`, but returns List instead of String. before_each(clear) it('sets the v:shell_error variable', function() @@ -334,14 +360,14 @@ describe('systemlist()', function() end) end) - describe('passing list as input', function() + describe('input passed as List', function() it('joins list items with linefeed characters', function() eq({'line1', 'line2', 'line3'}, eval("systemlist('cat -', ['line1', 'line2', 'line3'])")) end) -- Unlike `system()` which uses SOH to represent NULs, with `systemlist()` - -- input and ouput are the same + -- input and ouput are the same. describe('with linefeed characters inside list items', function() it('converts linefeed characters to NULs', function() eq({'l1\np2', 'line2\na\nb', 'l3'}, @@ -381,7 +407,7 @@ describe('systemlist()', function() describe("with a program that doesn't close stdout", function() if not xclip then - pending('skipped (missing xclip)', function() end) + pending('missing `xclip`', function() end) else it('will exit properly after passing input', function() eq({}, eval( diff --git a/test/functional/fixtures/CMakeLists.txt b/test/functional/fixtures/CMakeLists.txt index 70aee6efa9..8537ea390f 100644 --- a/test/functional/fixtures/CMakeLists.txt +++ b/test/functional/fixtures/CMakeLists.txt @@ -2,3 +2,4 @@ add_executable(tty-test tty-test.c) target_link_libraries(tty-test ${LIBUV_LIBRARIES}) add_executable(shell-test shell-test.c) +add_executable(printargs-test printargs-test.c) diff --git a/test/functional/fixtures/printargs-test.c b/test/functional/fixtures/printargs-test.c new file mode 100644 index 0000000000..2c25cf8447 --- /dev/null +++ b/test/functional/fixtures/printargs-test.c @@ -0,0 +1,9 @@ +#include <stdio.h> + +int main(int argc, char **argv) +{ + for (int i=1; i<argc; i++) { + printf("arg%d=%s;", i, argv[i]); + } + return 0; +} |