mirror of
https://github.com/neovim/neovim.git
synced 2024-09-17 20:58:20 -04:00
test: system([...])
This commit is contained in:
parent
a05ebf4a2d
commit
ac44d0ed54
@ -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)
|
||||
|
||||
|
@ -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(
|
||||
|
@ -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)
|
||||
|
9
test/functional/fixtures/printargs-test.c
Normal file
9
test/functional/fixtures/printargs-test.c
Normal file
@ -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;
|
||||
}
|
Loading…
Reference in New Issue
Block a user