vim-patch:8.0.0151,3,4 #7389

vim-patch:8.0.0151
Problem:    To pass buffer content to system() and systemlist() one has to
            first create a string or list.
Solution:   Allow passing a buffer number. (LemonBoy,
            closes vim/vim#1240)
12c4492dd3

vim-patch:8.0.0153
Problem:    system() test fails on MS-Windows.
Solution:   Deal when extra space and CR.
9d9c356517

vim-patch:8.0.0154
Problem:    system() test fails on OS/X.
Solution:   Deal with leading spaces.
31f19ce0a0
This commit is contained in:
Justin M. Keyes
2018-01-15 23:14:20 +01:00
parent de0a9548f7
commit f8f7f9d5f5
6 changed files with 101 additions and 13 deletions

View File

@@ -0,0 +1,48 @@
" Tests for system() and systemlist()
function! Test_System()
if !executable('echo') || !executable('cat') || !executable('wc')
return
endif
let out = system('echo 123')
" On Windows we may get a trailing space.
if out != "123 \n"
call assert_equal("123\n", out)
endif
let out = systemlist('echo 123')
" On Windows we may get a trailing space and CR.
if out != ["123 \r"]
call assert_equal(['123'], out)
endif
call assert_equal('123', system('cat', '123'))
call assert_equal(['123'], systemlist('cat', '123'))
call assert_equal(["as\<NL>df"], systemlist('cat', ["as\<NL>df"]))
new Xdummy
call setline(1, ['asdf', "pw\<NL>er", 'xxxx'])
let out = system('wc -l', bufnr('%'))
" On OS/X we get leading spaces
let out = substitute(out, '^ *', '', '')
call assert_equal("3\n", out)
let out = systemlist('wc -l', bufnr('%'))
" On Windows we may get a trailing CR.
if out != ["3\r"]
" On OS/X we get leading spaces
if type(out) == v:t_list
let out[0] = substitute(out[0], '^ *', '', '')
endif
call assert_equal(['3'], out)
endif
let out = systemlist('cat', bufnr('%'))
" On Windows we may get a trailing CR.
if out != ["asdf\r", "pw\<NL>er\r", "xxxx\r"]
call assert_equal(['asdf', "pw\<NL>er", 'xxxx'], out)
endif
bwipe!
call assert_fails('call system("wc -l", 99999)', 'E86:')
endfunction