view src/testdir/test_system.vim @ 10528:3ea703795a4f v8.0.0154

commit https://github.com/vim/vim/commit/31f19ce0a052f7c76d44a9a190e468c79cf5d56d Author: Bram Moolenaar <Bram@vim.org> Date: Sun Jan 8 14:14:43 2017 +0100 patch 8.0.0154: system() test fails on OS/X Problem: system() test fails on OS/X. Solution: Deal with leading spaces.
author Christian Brabandt <cb@256bit.org>
date Sun, 08 Jan 2017 14:15:04 +0100
parents 06724e21d8c1
children b0c9c1a05054
line wrap: on
line source

" 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