annotate 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
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
10522
7232cd9f8a7c commit https://github.com/vim/vim/commit/12c4492dd35e0cd83c8816be2ec849b836109882
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
1 " Tests for system() and systemlist()
7232cd9f8a7c commit https://github.com/vim/vim/commit/12c4492dd35e0cd83c8816be2ec849b836109882
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
2
7232cd9f8a7c commit https://github.com/vim/vim/commit/12c4492dd35e0cd83c8816be2ec849b836109882
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
3 function! Test_System()
7232cd9f8a7c commit https://github.com/vim/vim/commit/12c4492dd35e0cd83c8816be2ec849b836109882
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
4 if !executable('echo') || !executable('cat') || !executable('wc')
7232cd9f8a7c commit https://github.com/vim/vim/commit/12c4492dd35e0cd83c8816be2ec849b836109882
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
5 return
7232cd9f8a7c commit https://github.com/vim/vim/commit/12c4492dd35e0cd83c8816be2ec849b836109882
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
6 endif
10526
06724e21d8c1 commit https://github.com/vim/vim/commit/9d9c35651712b88c81f1ae11091de1fd0bbbd35c
Christian Brabandt <cb@256bit.org>
parents: 10522
diff changeset
7 let out = system('echo 123')
06724e21d8c1 commit https://github.com/vim/vim/commit/9d9c35651712b88c81f1ae11091de1fd0bbbd35c
Christian Brabandt <cb@256bit.org>
parents: 10522
diff changeset
8 " On Windows we may get a trailing space.
06724e21d8c1 commit https://github.com/vim/vim/commit/9d9c35651712b88c81f1ae11091de1fd0bbbd35c
Christian Brabandt <cb@256bit.org>
parents: 10522
diff changeset
9 if out != "123 \n"
06724e21d8c1 commit https://github.com/vim/vim/commit/9d9c35651712b88c81f1ae11091de1fd0bbbd35c
Christian Brabandt <cb@256bit.org>
parents: 10522
diff changeset
10 call assert_equal("123\n", out)
06724e21d8c1 commit https://github.com/vim/vim/commit/9d9c35651712b88c81f1ae11091de1fd0bbbd35c
Christian Brabandt <cb@256bit.org>
parents: 10522
diff changeset
11 endif
06724e21d8c1 commit https://github.com/vim/vim/commit/9d9c35651712b88c81f1ae11091de1fd0bbbd35c
Christian Brabandt <cb@256bit.org>
parents: 10522
diff changeset
12
06724e21d8c1 commit https://github.com/vim/vim/commit/9d9c35651712b88c81f1ae11091de1fd0bbbd35c
Christian Brabandt <cb@256bit.org>
parents: 10522
diff changeset
13 let out = systemlist('echo 123')
06724e21d8c1 commit https://github.com/vim/vim/commit/9d9c35651712b88c81f1ae11091de1fd0bbbd35c
Christian Brabandt <cb@256bit.org>
parents: 10522
diff changeset
14 " On Windows we may get a trailing space and CR.
06724e21d8c1 commit https://github.com/vim/vim/commit/9d9c35651712b88c81f1ae11091de1fd0bbbd35c
Christian Brabandt <cb@256bit.org>
parents: 10522
diff changeset
15 if out != ["123 \r"]
06724e21d8c1 commit https://github.com/vim/vim/commit/9d9c35651712b88c81f1ae11091de1fd0bbbd35c
Christian Brabandt <cb@256bit.org>
parents: 10522
diff changeset
16 call assert_equal(['123'], out)
06724e21d8c1 commit https://github.com/vim/vim/commit/9d9c35651712b88c81f1ae11091de1fd0bbbd35c
Christian Brabandt <cb@256bit.org>
parents: 10522
diff changeset
17 endif
06724e21d8c1 commit https://github.com/vim/vim/commit/9d9c35651712b88c81f1ae11091de1fd0bbbd35c
Christian Brabandt <cb@256bit.org>
parents: 10522
diff changeset
18
10522
7232cd9f8a7c commit https://github.com/vim/vim/commit/12c4492dd35e0cd83c8816be2ec849b836109882
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
19 call assert_equal('123', system('cat', '123'))
7232cd9f8a7c commit https://github.com/vim/vim/commit/12c4492dd35e0cd83c8816be2ec849b836109882
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
20 call assert_equal(['123'], systemlist('cat', '123'))
7232cd9f8a7c commit https://github.com/vim/vim/commit/12c4492dd35e0cd83c8816be2ec849b836109882
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
21 call assert_equal(["as\<NL>df"], systemlist('cat', ["as\<NL>df"]))
10528
3ea703795a4f commit https://github.com/vim/vim/commit/31f19ce0a052f7c76d44a9a190e468c79cf5d56d
Christian Brabandt <cb@256bit.org>
parents: 10526
diff changeset
22
10522
7232cd9f8a7c commit https://github.com/vim/vim/commit/12c4492dd35e0cd83c8816be2ec849b836109882
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
23 new Xdummy
7232cd9f8a7c commit https://github.com/vim/vim/commit/12c4492dd35e0cd83c8816be2ec849b836109882
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
24 call setline(1, ['asdf', "pw\<NL>er", 'xxxx'])
10528
3ea703795a4f commit https://github.com/vim/vim/commit/31f19ce0a052f7c76d44a9a190e468c79cf5d56d
Christian Brabandt <cb@256bit.org>
parents: 10526
diff changeset
25 let out = system('wc -l', bufnr('%'))
3ea703795a4f commit https://github.com/vim/vim/commit/31f19ce0a052f7c76d44a9a190e468c79cf5d56d
Christian Brabandt <cb@256bit.org>
parents: 10526
diff changeset
26 " On OS/X we get leading spaces
3ea703795a4f commit https://github.com/vim/vim/commit/31f19ce0a052f7c76d44a9a190e468c79cf5d56d
Christian Brabandt <cb@256bit.org>
parents: 10526
diff changeset
27 let out = substitute(out, '^ *', '', '')
3ea703795a4f commit https://github.com/vim/vim/commit/31f19ce0a052f7c76d44a9a190e468c79cf5d56d
Christian Brabandt <cb@256bit.org>
parents: 10526
diff changeset
28 call assert_equal("3\n", out)
10526
06724e21d8c1 commit https://github.com/vim/vim/commit/9d9c35651712b88c81f1ae11091de1fd0bbbd35c
Christian Brabandt <cb@256bit.org>
parents: 10522
diff changeset
29
06724e21d8c1 commit https://github.com/vim/vim/commit/9d9c35651712b88c81f1ae11091de1fd0bbbd35c
Christian Brabandt <cb@256bit.org>
parents: 10522
diff changeset
30 let out = systemlist('wc -l', bufnr('%'))
06724e21d8c1 commit https://github.com/vim/vim/commit/9d9c35651712b88c81f1ae11091de1fd0bbbd35c
Christian Brabandt <cb@256bit.org>
parents: 10522
diff changeset
31 " On Windows we may get a trailing CR.
06724e21d8c1 commit https://github.com/vim/vim/commit/9d9c35651712b88c81f1ae11091de1fd0bbbd35c
Christian Brabandt <cb@256bit.org>
parents: 10522
diff changeset
32 if out != ["3\r"]
10528
3ea703795a4f commit https://github.com/vim/vim/commit/31f19ce0a052f7c76d44a9a190e468c79cf5d56d
Christian Brabandt <cb@256bit.org>
parents: 10526
diff changeset
33 " On OS/X we get leading spaces
3ea703795a4f commit https://github.com/vim/vim/commit/31f19ce0a052f7c76d44a9a190e468c79cf5d56d
Christian Brabandt <cb@256bit.org>
parents: 10526
diff changeset
34 if type(out) == v:t_list
3ea703795a4f commit https://github.com/vim/vim/commit/31f19ce0a052f7c76d44a9a190e468c79cf5d56d
Christian Brabandt <cb@256bit.org>
parents: 10526
diff changeset
35 let out[0] = substitute(out[0], '^ *', '', '')
3ea703795a4f commit https://github.com/vim/vim/commit/31f19ce0a052f7c76d44a9a190e468c79cf5d56d
Christian Brabandt <cb@256bit.org>
parents: 10526
diff changeset
36 endif
10526
06724e21d8c1 commit https://github.com/vim/vim/commit/9d9c35651712b88c81f1ae11091de1fd0bbbd35c
Christian Brabandt <cb@256bit.org>
parents: 10522
diff changeset
37 call assert_equal(['3'], out)
06724e21d8c1 commit https://github.com/vim/vim/commit/9d9c35651712b88c81f1ae11091de1fd0bbbd35c
Christian Brabandt <cb@256bit.org>
parents: 10522
diff changeset
38 endif
06724e21d8c1 commit https://github.com/vim/vim/commit/9d9c35651712b88c81f1ae11091de1fd0bbbd35c
Christian Brabandt <cb@256bit.org>
parents: 10522
diff changeset
39
06724e21d8c1 commit https://github.com/vim/vim/commit/9d9c35651712b88c81f1ae11091de1fd0bbbd35c
Christian Brabandt <cb@256bit.org>
parents: 10522
diff changeset
40 let out = systemlist('cat', bufnr('%'))
06724e21d8c1 commit https://github.com/vim/vim/commit/9d9c35651712b88c81f1ae11091de1fd0bbbd35c
Christian Brabandt <cb@256bit.org>
parents: 10522
diff changeset
41 " On Windows we may get a trailing CR.
06724e21d8c1 commit https://github.com/vim/vim/commit/9d9c35651712b88c81f1ae11091de1fd0bbbd35c
Christian Brabandt <cb@256bit.org>
parents: 10522
diff changeset
42 if out != ["asdf\r", "pw\<NL>er\r", "xxxx\r"]
06724e21d8c1 commit https://github.com/vim/vim/commit/9d9c35651712b88c81f1ae11091de1fd0bbbd35c
Christian Brabandt <cb@256bit.org>
parents: 10522
diff changeset
43 call assert_equal(['asdf', "pw\<NL>er", 'xxxx'], out)
06724e21d8c1 commit https://github.com/vim/vim/commit/9d9c35651712b88c81f1ae11091de1fd0bbbd35c
Christian Brabandt <cb@256bit.org>
parents: 10522
diff changeset
44 endif
10522
7232cd9f8a7c commit https://github.com/vim/vim/commit/12c4492dd35e0cd83c8816be2ec849b836109882
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
45 bwipe!
7232cd9f8a7c commit https://github.com/vim/vim/commit/12c4492dd35e0cd83c8816be2ec849b836109882
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
46
7232cd9f8a7c commit https://github.com/vim/vim/commit/12c4492dd35e0cd83c8816be2ec849b836109882
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
47 call assert_fails('call system("wc -l", 99999)', 'E86:')
7232cd9f8a7c commit https://github.com/vim/vim/commit/12c4492dd35e0cd83c8816be2ec849b836109882
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
48 endfunction