From f8f7f9d5f5aead86541ffcd12e291b6dfb6811e5 Mon Sep 17 00:00:00 2001 From: "Justin M. Keyes" Date: Mon, 15 Jan 2018 23:14:20 +0100 Subject: 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) https://github.com/vim/vim/commit/12c4492dd35e0cd83c8816be2ec849b836109882 vim-patch:8.0.0153 Problem: system() test fails on MS-Windows. Solution: Deal when extra space and CR. https://github.com/vim/vim/commit/9d9c35651712b88c81f1ae11091de1fd0bbbd35c vim-patch:8.0.0154 Problem: system() test fails on OS/X. Solution: Deal with leading spaces. https://github.com/vim/vim/commit/31f19ce0a052f7c76d44a9a190e468c79cf5d56d --- src/nvim/testdir/Makefile | 1 + src/nvim/testdir/test_system.vim | 48 ++++++++++++++++++++++++++++++++++++++++ 2 files changed, 49 insertions(+) create mode 100644 src/nvim/testdir/test_system.vim (limited to 'src/nvim/testdir') diff --git a/src/nvim/testdir/Makefile b/src/nvim/testdir/Makefile index 0c25945274..c1e6eedf94 100644 --- a/src/nvim/testdir/Makefile +++ b/src/nvim/testdir/Makefile @@ -88,6 +88,7 @@ NEW_TESTS ?= \ test_startup_utf8.res \ test_substitute.res \ test_syntax.res \ + test_system.res \ test_tabpage.res \ test_textobjects.res \ test_timers.res \ diff --git a/src/nvim/testdir/test_system.vim b/src/nvim/testdir/test_system.vim new file mode 100644 index 0000000000..0446bd9105 --- /dev/null +++ b/src/nvim/testdir/test_system.vim @@ -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\df"], systemlist('cat', ["as\df"])) + + new Xdummy + call setline(1, ['asdf', "pw\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\er\r", "xxxx\r"] + call assert_equal(['asdf', "pw\er", 'xxxx'], out) + endif + bwipe! + + call assert_fails('call system("wc -l", 99999)', 'E86:') +endfunction -- cgit