annotate src/testdir/test_system.vim @ 12451:61450cb2b6a1 v8.0.1105

patch 8.0.1105: match() and matchend() are not tested commit https://github.com/vim/vim/commit/1190cf68e27a123cf9f6fb57897782a3b9f7b810 Author: Bram Moolenaar <Bram@vim.org> Date: Thu Sep 14 14:31:18 2017 +0200 patch 8.0.1105: match() and matchend() are not tested Problem: match() and matchend() are not tested. Solution: Add tests. (Ozaki Kiichi, closes https://github.com/vim/vim/issues/2088)
author Christian Brabandt <cb@256bit.org>
date Thu, 14 Sep 2017 14:45:04 +0200
parents bcab4e804c20
children 63b02fcf1361
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
10589
b0c9c1a05054 patch 8.0.0184: when an error is caught Vim still exits with non-zero result
Christian Brabandt <cb@256bit.org>
parents: 10528
diff changeset
49
b0c9c1a05054 patch 8.0.0184: when an error is caught Vim still exits with non-zero result
Christian Brabandt <cb@256bit.org>
parents: 10528
diff changeset
50 function! Test_system_exmode()
10615
de4aae865134 patch 8.0.0197: system() test skips some parts for MS-Windows
Christian Brabandt <cb@256bit.org>
parents: 10591
diff changeset
51 if has('unix') " echo $? only works on Unix
11637
bcab4e804c20 patch 8.0.0701: system test failing when using X11 forwarding
Christian Brabandt <cb@256bit.org>
parents: 10615
diff changeset
52 let cmd = ' -es -u NONE -c "source Xscript" +q; echo "result=$?"'
10615
de4aae865134 patch 8.0.0197: system() test skips some parts for MS-Windows
Christian Brabandt <cb@256bit.org>
parents: 10591
diff changeset
53 " Need to put this in a script, "catch" isn't found after an unknown
de4aae865134 patch 8.0.0197: system() test skips some parts for MS-Windows
Christian Brabandt <cb@256bit.org>
parents: 10591
diff changeset
54 " function.
de4aae865134 patch 8.0.0197: system() test skips some parts for MS-Windows
Christian Brabandt <cb@256bit.org>
parents: 10591
diff changeset
55 call writefile(['try', 'call doesnotexist()', 'catch', 'endtry'], 'Xscript')
de4aae865134 patch 8.0.0197: system() test skips some parts for MS-Windows
Christian Brabandt <cb@256bit.org>
parents: 10591
diff changeset
56 let a = system(v:progpath . cmd)
11637
bcab4e804c20 patch 8.0.0701: system test failing when using X11 forwarding
Christian Brabandt <cb@256bit.org>
parents: 10615
diff changeset
57 call assert_match('result=0', a)
10615
de4aae865134 patch 8.0.0197: system() test skips some parts for MS-Windows
Christian Brabandt <cb@256bit.org>
parents: 10591
diff changeset
58 call assert_equal(0, v:shell_error)
10591
234da476c4fd patch 8.0.0185: system() test fails on MS-Windows
Christian Brabandt <cb@256bit.org>
parents: 10589
diff changeset
59 endif
234da476c4fd patch 8.0.0185: system() test fails on MS-Windows
Christian Brabandt <cb@256bit.org>
parents: 10589
diff changeset
60
10589
b0c9c1a05054 patch 8.0.0184: when an error is caught Vim still exits with non-zero result
Christian Brabandt <cb@256bit.org>
parents: 10528
diff changeset
61 " Error before try does set error flag.
b0c9c1a05054 patch 8.0.0184: when an error is caught Vim still exits with non-zero result
Christian Brabandt <cb@256bit.org>
parents: 10528
diff changeset
62 call writefile(['call nosuchfunction()', 'try', 'call doesnotexist()', 'catch', 'endtry'], 'Xscript')
10615
de4aae865134 patch 8.0.0197: system() test skips some parts for MS-Windows
Christian Brabandt <cb@256bit.org>
parents: 10591
diff changeset
63 if has('unix') " echo $? only works on Unix
de4aae865134 patch 8.0.0197: system() test skips some parts for MS-Windows
Christian Brabandt <cb@256bit.org>
parents: 10591
diff changeset
64 let a = system(v:progpath . cmd)
de4aae865134 patch 8.0.0197: system() test skips some parts for MS-Windows
Christian Brabandt <cb@256bit.org>
parents: 10591
diff changeset
65 call assert_notequal('0', a[0])
de4aae865134 patch 8.0.0197: system() test skips some parts for MS-Windows
Christian Brabandt <cb@256bit.org>
parents: 10591
diff changeset
66 endif
10589
b0c9c1a05054 patch 8.0.0184: when an error is caught Vim still exits with non-zero result
Christian Brabandt <cb@256bit.org>
parents: 10528
diff changeset
67
10615
de4aae865134 patch 8.0.0197: system() test skips some parts for MS-Windows
Christian Brabandt <cb@256bit.org>
parents: 10591
diff changeset
68 let cmd = ' -es -u NONE -c "source Xscript" +q'
10589
b0c9c1a05054 patch 8.0.0184: when an error is caught Vim still exits with non-zero result
Christian Brabandt <cb@256bit.org>
parents: 10528
diff changeset
69 let a = system(v:progpath . cmd)
b0c9c1a05054 patch 8.0.0184: when an error is caught Vim still exits with non-zero result
Christian Brabandt <cb@256bit.org>
parents: 10528
diff changeset
70 call assert_notequal(0, v:shell_error)
10615
de4aae865134 patch 8.0.0197: system() test skips some parts for MS-Windows
Christian Brabandt <cb@256bit.org>
parents: 10591
diff changeset
71 call delete('Xscript')
10589
b0c9c1a05054 patch 8.0.0184: when an error is caught Vim still exits with non-zero result
Christian Brabandt <cb@256bit.org>
parents: 10528
diff changeset
72
10615
de4aae865134 patch 8.0.0197: system() test skips some parts for MS-Windows
Christian Brabandt <cb@256bit.org>
parents: 10591
diff changeset
73 if has('unix') " echo $? only works on Unix
de4aae865134 patch 8.0.0197: system() test skips some parts for MS-Windows
Christian Brabandt <cb@256bit.org>
parents: 10591
diff changeset
74 let cmd = ' -es -u NONE -c "call doesnotexist()" +q; echo $?'
de4aae865134 patch 8.0.0197: system() test skips some parts for MS-Windows
Christian Brabandt <cb@256bit.org>
parents: 10591
diff changeset
75 let a = system(v:progpath. cmd)
de4aae865134 patch 8.0.0197: system() test skips some parts for MS-Windows
Christian Brabandt <cb@256bit.org>
parents: 10591
diff changeset
76 call assert_notequal(0, a[0])
de4aae865134 patch 8.0.0197: system() test skips some parts for MS-Windows
Christian Brabandt <cb@256bit.org>
parents: 10591
diff changeset
77 endif
10589
b0c9c1a05054 patch 8.0.0184: when an error is caught Vim still exits with non-zero result
Christian Brabandt <cb@256bit.org>
parents: 10528
diff changeset
78
10615
de4aae865134 patch 8.0.0197: system() test skips some parts for MS-Windows
Christian Brabandt <cb@256bit.org>
parents: 10591
diff changeset
79 let cmd = ' -es -u NONE -c "call doesnotexist()" +q'
10589
b0c9c1a05054 patch 8.0.0184: when an error is caught Vim still exits with non-zero result
Christian Brabandt <cb@256bit.org>
parents: 10528
diff changeset
80 let a = system(v:progpath. cmd)
b0c9c1a05054 patch 8.0.0184: when an error is caught Vim still exits with non-zero result
Christian Brabandt <cb@256bit.org>
parents: 10528
diff changeset
81 call assert_notequal(0, v:shell_error)
b0c9c1a05054 patch 8.0.0184: when an error is caught Vim still exits with non-zero result
Christian Brabandt <cb@256bit.org>
parents: 10528
diff changeset
82
10615
de4aae865134 patch 8.0.0197: system() test skips some parts for MS-Windows
Christian Brabandt <cb@256bit.org>
parents: 10591
diff changeset
83 if has('unix') " echo $? only works on Unix
de4aae865134 patch 8.0.0197: system() test skips some parts for MS-Windows
Christian Brabandt <cb@256bit.org>
parents: 10591
diff changeset
84 let cmd = ' -es -u NONE -c "call doesnotexist()|let a=1" +q; echo $?'
de4aae865134 patch 8.0.0197: system() test skips some parts for MS-Windows
Christian Brabandt <cb@256bit.org>
parents: 10591
diff changeset
85 let a = system(v:progpath. cmd)
de4aae865134 patch 8.0.0197: system() test skips some parts for MS-Windows
Christian Brabandt <cb@256bit.org>
parents: 10591
diff changeset
86 call assert_notequal(0, a[0])
de4aae865134 patch 8.0.0197: system() test skips some parts for MS-Windows
Christian Brabandt <cb@256bit.org>
parents: 10591
diff changeset
87 endif
10589
b0c9c1a05054 patch 8.0.0184: when an error is caught Vim still exits with non-zero result
Christian Brabandt <cb@256bit.org>
parents: 10528
diff changeset
88
10615
de4aae865134 patch 8.0.0197: system() test skips some parts for MS-Windows
Christian Brabandt <cb@256bit.org>
parents: 10591
diff changeset
89 let cmd = ' -es -u NONE -c "call doesnotexist()|let a=1" +q'
10589
b0c9c1a05054 patch 8.0.0184: when an error is caught Vim still exits with non-zero result
Christian Brabandt <cb@256bit.org>
parents: 10528
diff changeset
90 let a = system(v:progpath. cmd)
b0c9c1a05054 patch 8.0.0184: when an error is caught Vim still exits with non-zero result
Christian Brabandt <cb@256bit.org>
parents: 10528
diff changeset
91 call assert_notequal(0, v:shell_error)
b0c9c1a05054 patch 8.0.0184: when an error is caught Vim still exits with non-zero result
Christian Brabandt <cb@256bit.org>
parents: 10528
diff changeset
92 endfunc