Mercurial > vim
annotate src/testdir/test_system.vim @ 10592:422e729296c4
Added tag v8.0.0185 for changeset 234da476c4fde6fb2c402ac36f4403b8d7db1130
author | Christian Brabandt <cb@256bit.org> |
---|---|
date | Sat, 14 Jan 2017 19:45:04 +0100 |
parents | 234da476c4fd |
children | de4aae865134 |
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() |
10591
234da476c4fd
patch 8.0.0185: system() test fails on MS-Windows
Christian Brabandt <cb@256bit.org>
parents:
10589
diff
changeset
|
51 if !has('unix') |
234da476c4fd
patch 8.0.0185: system() test fails on MS-Windows
Christian Brabandt <cb@256bit.org>
parents:
10589
diff
changeset
|
52 return |
234da476c4fd
patch 8.0.0185: system() test fails on MS-Windows
Christian Brabandt <cb@256bit.org>
parents:
10589
diff
changeset
|
53 endif |
234da476c4fd
patch 8.0.0185: system() test fails on MS-Windows
Christian Brabandt <cb@256bit.org>
parents:
10589
diff
changeset
|
54 |
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
|
55 let cmd=" -es -u NONE -c 'source Xscript' +q; echo $?" |
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
|
56 " Need to put this in a script, "catch" isn't found after an unknown |
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
|
57 " function. |
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
|
58 call writefile(['try', 'call doesnotexist()', 'catch', 'endtry'], 'Xscript') |
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
|
59 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
|
60 call assert_equal('0', a[0]) |
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 call assert_equal(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
|
62 |
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
|
63 " 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
|
64 call writefile(['call nosuchfunction()', 'try', 'call doesnotexist()', 'catch', 'endtry'], 'Xscript') |
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
|
65 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
|
66 call assert_notequal('0', a[0]) |
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 |
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
|
68 let cmd=" -es -u NONE -c 'source Xscript' +q" |
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) |
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
|
71 |
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 let cmd=" -es -u NONE -c 'call doesnotexist()' +q; echo $?" |
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
|
73 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
|
74 call assert_notequal(0, a[0]) |
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
|
75 |
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
|
76 let cmd=" -es -u NONE -c 'call doesnotexist()' +q" |
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
|
77 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
|
78 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
|
79 |
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 cmd=" -es -u NONE -c 'call doesnotexist()|let a=1' +q; echo $?" |
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 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
|
82 call assert_notequal(0, a[0]) |
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
|
83 |
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
|
84 let cmd=" -es -u NONE -c 'call doesnotexist()|let a=1' +q" |
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
|
85 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
|
86 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
|
87 |
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 call delete('Xscript') |
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
|
89 endfunc |