xref: /vim-8.2.3635/src/testdir/test_system.vim (revision 31f19ce0)
1" Tests for system() and systemlist()
2
3function! Test_System()
4  if !executable('echo') || !executable('cat') || !executable('wc')
5    return
6  endif
7  let out = system('echo 123')
8  " On Windows we may get a trailing space.
9  if out != "123 \n"
10    call assert_equal("123\n", out)
11  endif
12
13  let out = systemlist('echo 123')
14  " On Windows we may get a trailing space and CR.
15  if out != ["123 \r"]
16    call assert_equal(['123'], out)
17  endif
18
19  call assert_equal('123',   system('cat', '123'))
20  call assert_equal(['123'], systemlist('cat', '123'))
21  call assert_equal(["as\<NL>df"], systemlist('cat', ["as\<NL>df"]))
22
23  new Xdummy
24  call setline(1, ['asdf', "pw\<NL>er", 'xxxx'])
25  let out = system('wc -l', bufnr('%'))
26  " On OS/X we get leading spaces
27  let out = substitute(out, '^ *', '', '')
28  call assert_equal("3\n", out)
29
30  let out = systemlist('wc -l', bufnr('%'))
31  " On Windows we may get a trailing CR.
32  if out != ["3\r"]
33    " On OS/X we get leading spaces
34    if type(out) == v:t_list
35      let out[0] = substitute(out[0], '^ *', '', '')
36    endif
37    call assert_equal(['3'],  out)
38  endif
39
40  let out = systemlist('cat', bufnr('%'))
41  " On Windows we may get a trailing CR.
42  if out != ["asdf\r", "pw\<NL>er\r", "xxxx\r"]
43    call assert_equal(['asdf', "pw\<NL>er", 'xxxx'],  out)
44  endif
45  bwipe!
46
47  call assert_fails('call system("wc -l", 99999)', 'E86:')
48endfunction
49