Mercurial > vim
annotate src/testdir/test_system.vim @ 18130:1e5672da6a69
Updte runtime files
Commit: https://github.com/vim/vim/commit/589edb340454e7f1b19358f129287a636d53d0e1
Author: Bram Moolenaar <Bram@vim.org>
Date: Fri Sep 20 14:38:13 2019 +0200
Updte runtime files
author | Bram Moolenaar <Bram@vim.org> |
---|---|
date | Fri, 20 Sep 2019 14:45:05 +0200 |
parents | 131f1d8c5860 |
children | a81f0c936112 |
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 |
17698
131f1d8c5860
patch 8.1.1846: inconsistently using GetVimCommand() and v:progpath
Bram Moolenaar <Bram@vim.org>
parents:
17624
diff
changeset
|
3 source shared.vim |
131f1d8c5860
patch 8.1.1846: inconsistently using GetVimCommand() and v:progpath
Bram Moolenaar <Bram@vim.org>
parents:
17624
diff
changeset
|
4 |
15406
63b02fcf1361
patch 8.1.0711: test files still use function!
Bram Moolenaar <Bram@vim.org>
parents:
11637
diff
changeset
|
5 func Test_System() |
10522
7232cd9f8a7c
commit https://github.com/vim/vim/commit/12c4492dd35e0cd83c8816be2ec849b836109882
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
6 if !executable('echo') || !executable('cat') || !executable('wc') |
7232cd9f8a7c
commit https://github.com/vim/vim/commit/12c4492dd35e0cd83c8816be2ec849b836109882
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
7 return |
7232cd9f8a7c
commit https://github.com/vim/vim/commit/12c4492dd35e0cd83c8816be2ec849b836109882
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
8 endif |
17624
4c7097a980a5
patch 8.1.1809: more functions can be used as a method
Bram Moolenaar <Bram@vim.org>
parents:
15406
diff
changeset
|
9 let out = 'echo 123'->system() |
10526
06724e21d8c1
commit https://github.com/vim/vim/commit/9d9c35651712b88c81f1ae11091de1fd0bbbd35c
Christian Brabandt <cb@256bit.org>
parents:
10522
diff
changeset
|
10 " 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
|
11 if out != "123 \n" |
06724e21d8c1
commit https://github.com/vim/vim/commit/9d9c35651712b88c81f1ae11091de1fd0bbbd35c
Christian Brabandt <cb@256bit.org>
parents:
10522
diff
changeset
|
12 call assert_equal("123\n", out) |
06724e21d8c1
commit https://github.com/vim/vim/commit/9d9c35651712b88c81f1ae11091de1fd0bbbd35c
Christian Brabandt <cb@256bit.org>
parents:
10522
diff
changeset
|
13 endif |
06724e21d8c1
commit https://github.com/vim/vim/commit/9d9c35651712b88c81f1ae11091de1fd0bbbd35c
Christian Brabandt <cb@256bit.org>
parents:
10522
diff
changeset
|
14 |
17624
4c7097a980a5
patch 8.1.1809: more functions can be used as a method
Bram Moolenaar <Bram@vim.org>
parents:
15406
diff
changeset
|
15 let out = 'echo 123'->systemlist() |
10526
06724e21d8c1
commit https://github.com/vim/vim/commit/9d9c35651712b88c81f1ae11091de1fd0bbbd35c
Christian Brabandt <cb@256bit.org>
parents:
10522
diff
changeset
|
16 " 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
|
17 if out != ["123 \r"] |
06724e21d8c1
commit https://github.com/vim/vim/commit/9d9c35651712b88c81f1ae11091de1fd0bbbd35c
Christian Brabandt <cb@256bit.org>
parents:
10522
diff
changeset
|
18 call assert_equal(['123'], out) |
06724e21d8c1
commit https://github.com/vim/vim/commit/9d9c35651712b88c81f1ae11091de1fd0bbbd35c
Christian Brabandt <cb@256bit.org>
parents:
10522
diff
changeset
|
19 endif |
06724e21d8c1
commit https://github.com/vim/vim/commit/9d9c35651712b88c81f1ae11091de1fd0bbbd35c
Christian Brabandt <cb@256bit.org>
parents:
10522
diff
changeset
|
20 |
10522
7232cd9f8a7c
commit https://github.com/vim/vim/commit/12c4492dd35e0cd83c8816be2ec849b836109882
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
21 call assert_equal('123', system('cat', '123')) |
7232cd9f8a7c
commit https://github.com/vim/vim/commit/12c4492dd35e0cd83c8816be2ec849b836109882
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
22 call assert_equal(['123'], systemlist('cat', '123')) |
7232cd9f8a7c
commit https://github.com/vim/vim/commit/12c4492dd35e0cd83c8816be2ec849b836109882
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
23 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
|
24 |
10522
7232cd9f8a7c
commit https://github.com/vim/vim/commit/12c4492dd35e0cd83c8816be2ec849b836109882
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
25 new Xdummy |
7232cd9f8a7c
commit https://github.com/vim/vim/commit/12c4492dd35e0cd83c8816be2ec849b836109882
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
26 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
|
27 let out = system('wc -l', bufnr('%')) |
3ea703795a4f
commit https://github.com/vim/vim/commit/31f19ce0a052f7c76d44a9a190e468c79cf5d56d
Christian Brabandt <cb@256bit.org>
parents:
10526
diff
changeset
|
28 " 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
|
29 let out = substitute(out, '^ *', '', '') |
3ea703795a4f
commit https://github.com/vim/vim/commit/31f19ce0a052f7c76d44a9a190e468c79cf5d56d
Christian Brabandt <cb@256bit.org>
parents:
10526
diff
changeset
|
30 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
|
31 |
06724e21d8c1
commit https://github.com/vim/vim/commit/9d9c35651712b88c81f1ae11091de1fd0bbbd35c
Christian Brabandt <cb@256bit.org>
parents:
10522
diff
changeset
|
32 let out = systemlist('wc -l', bufnr('%')) |
06724e21d8c1
commit https://github.com/vim/vim/commit/9d9c35651712b88c81f1ae11091de1fd0bbbd35c
Christian Brabandt <cb@256bit.org>
parents:
10522
diff
changeset
|
33 " 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
|
34 if out != ["3\r"] |
10528
3ea703795a4f
commit https://github.com/vim/vim/commit/31f19ce0a052f7c76d44a9a190e468c79cf5d56d
Christian Brabandt <cb@256bit.org>
parents:
10526
diff
changeset
|
35 " 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
|
36 if type(out) == v:t_list |
3ea703795a4f
commit https://github.com/vim/vim/commit/31f19ce0a052f7c76d44a9a190e468c79cf5d56d
Christian Brabandt <cb@256bit.org>
parents:
10526
diff
changeset
|
37 let out[0] = substitute(out[0], '^ *', '', '') |
3ea703795a4f
commit https://github.com/vim/vim/commit/31f19ce0a052f7c76d44a9a190e468c79cf5d56d
Christian Brabandt <cb@256bit.org>
parents:
10526
diff
changeset
|
38 endif |
10526
06724e21d8c1
commit https://github.com/vim/vim/commit/9d9c35651712b88c81f1ae11091de1fd0bbbd35c
Christian Brabandt <cb@256bit.org>
parents:
10522
diff
changeset
|
39 call assert_equal(['3'], out) |
06724e21d8c1
commit https://github.com/vim/vim/commit/9d9c35651712b88c81f1ae11091de1fd0bbbd35c
Christian Brabandt <cb@256bit.org>
parents:
10522
diff
changeset
|
40 endif |
06724e21d8c1
commit https://github.com/vim/vim/commit/9d9c35651712b88c81f1ae11091de1fd0bbbd35c
Christian Brabandt <cb@256bit.org>
parents:
10522
diff
changeset
|
41 |
06724e21d8c1
commit https://github.com/vim/vim/commit/9d9c35651712b88c81f1ae11091de1fd0bbbd35c
Christian Brabandt <cb@256bit.org>
parents:
10522
diff
changeset
|
42 let out = systemlist('cat', bufnr('%')) |
06724e21d8c1
commit https://github.com/vim/vim/commit/9d9c35651712b88c81f1ae11091de1fd0bbbd35c
Christian Brabandt <cb@256bit.org>
parents:
10522
diff
changeset
|
43 " 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
|
44 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
|
45 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
|
46 endif |
10522
7232cd9f8a7c
commit https://github.com/vim/vim/commit/12c4492dd35e0cd83c8816be2ec849b836109882
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
47 bwipe! |
7232cd9f8a7c
commit https://github.com/vim/vim/commit/12c4492dd35e0cd83c8816be2ec849b836109882
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
48 |
7232cd9f8a7c
commit https://github.com/vim/vim/commit/12c4492dd35e0cd83c8816be2ec849b836109882
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
49 call assert_fails('call system("wc -l", 99999)', 'E86:') |
15406
63b02fcf1361
patch 8.1.0711: test files still use function!
Bram Moolenaar <Bram@vim.org>
parents:
11637
diff
changeset
|
50 endfunc |
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
|
51 |
15406
63b02fcf1361
patch 8.1.0711: test files still use function!
Bram Moolenaar <Bram@vim.org>
parents:
11637
diff
changeset
|
52 func 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
|
53 if has('unix') " echo $? only works on Unix |
17698
131f1d8c5860
patch 8.1.1846: inconsistently using GetVimCommand() and v:progpath
Bram Moolenaar <Bram@vim.org>
parents:
17624
diff
changeset
|
54 let cmd = ' -es -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
|
55 " 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
|
56 " function. |
de4aae865134
patch 8.0.0197: system() test skips some parts for MS-Windows
Christian Brabandt <cb@256bit.org>
parents:
10591
diff
changeset
|
57 call writefile(['try', 'call doesnotexist()', 'catch', 'endtry'], 'Xscript') |
17698
131f1d8c5860
patch 8.1.1846: inconsistently using GetVimCommand() and v:progpath
Bram Moolenaar <Bram@vim.org>
parents:
17624
diff
changeset
|
58 let a = system(GetVimCommand() . cmd) |
11637
bcab4e804c20
patch 8.0.0701: system test failing when using X11 forwarding
Christian Brabandt <cb@256bit.org>
parents:
10615
diff
changeset
|
59 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
|
60 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
|
61 endif |
234da476c4fd
patch 8.0.0185: system() test fails on MS-Windows
Christian Brabandt <cb@256bit.org>
parents:
10589
diff
changeset
|
62 |
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
|
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') |
10615
de4aae865134
patch 8.0.0197: system() test skips some parts for MS-Windows
Christian Brabandt <cb@256bit.org>
parents:
10591
diff
changeset
|
65 if has('unix') " echo $? only works on Unix |
17698
131f1d8c5860
patch 8.1.1846: inconsistently using GetVimCommand() and v:progpath
Bram Moolenaar <Bram@vim.org>
parents:
17624
diff
changeset
|
66 let a = system(GetVimCommand() . cmd) |
10615
de4aae865134
patch 8.0.0197: system() test skips some parts for MS-Windows
Christian Brabandt <cb@256bit.org>
parents:
10591
diff
changeset
|
67 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
|
68 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
|
69 |
17698
131f1d8c5860
patch 8.1.1846: inconsistently using GetVimCommand() and v:progpath
Bram Moolenaar <Bram@vim.org>
parents:
17624
diff
changeset
|
70 let cmd = ' -es -c "source Xscript" +q' |
131f1d8c5860
patch 8.1.1846: inconsistently using GetVimCommand() and v:progpath
Bram Moolenaar <Bram@vim.org>
parents:
17624
diff
changeset
|
71 let a = system(GetVimCommand() . cmd) |
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 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
|
73 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
|
74 |
10615
de4aae865134
patch 8.0.0197: system() test skips some parts for MS-Windows
Christian Brabandt <cb@256bit.org>
parents:
10591
diff
changeset
|
75 if has('unix') " echo $? only works on Unix |
17698
131f1d8c5860
patch 8.1.1846: inconsistently using GetVimCommand() and v:progpath
Bram Moolenaar <Bram@vim.org>
parents:
17624
diff
changeset
|
76 let cmd = ' -es -c "call doesnotexist()" +q; echo $?' |
131f1d8c5860
patch 8.1.1846: inconsistently using GetVimCommand() and v:progpath
Bram Moolenaar <Bram@vim.org>
parents:
17624
diff
changeset
|
77 let a = system(GetVimCommand() . cmd) |
10615
de4aae865134
patch 8.0.0197: system() test skips some parts for MS-Windows
Christian Brabandt <cb@256bit.org>
parents:
10591
diff
changeset
|
78 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
|
79 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
|
80 |
17698
131f1d8c5860
patch 8.1.1846: inconsistently using GetVimCommand() and v:progpath
Bram Moolenaar <Bram@vim.org>
parents:
17624
diff
changeset
|
81 let cmd = ' -es -c "call doesnotexist()" +q' |
131f1d8c5860
patch 8.1.1846: inconsistently using GetVimCommand() and v:progpath
Bram Moolenaar <Bram@vim.org>
parents:
17624
diff
changeset
|
82 let a = system(GetVimCommand(). cmd) |
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
|
83 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
|
84 |
10615
de4aae865134
patch 8.0.0197: system() test skips some parts for MS-Windows
Christian Brabandt <cb@256bit.org>
parents:
10591
diff
changeset
|
85 if has('unix') " echo $? only works on Unix |
17698
131f1d8c5860
patch 8.1.1846: inconsistently using GetVimCommand() and v:progpath
Bram Moolenaar <Bram@vim.org>
parents:
17624
diff
changeset
|
86 let cmd = ' -es -c "call doesnotexist()|let a=1" +q; echo $?' |
131f1d8c5860
patch 8.1.1846: inconsistently using GetVimCommand() and v:progpath
Bram Moolenaar <Bram@vim.org>
parents:
17624
diff
changeset
|
87 let a = system(GetVimCommand() . cmd) |
10615
de4aae865134
patch 8.0.0197: system() test skips some parts for MS-Windows
Christian Brabandt <cb@256bit.org>
parents:
10591
diff
changeset
|
88 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
|
89 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
|
90 |
17698
131f1d8c5860
patch 8.1.1846: inconsistently using GetVimCommand() and v:progpath
Bram Moolenaar <Bram@vim.org>
parents:
17624
diff
changeset
|
91 let cmd = ' -es -c "call doesnotexist()|let a=1" +q' |
131f1d8c5860
patch 8.1.1846: inconsistently using GetVimCommand() and v:progpath
Bram Moolenaar <Bram@vim.org>
parents:
17624
diff
changeset
|
92 let a = system(GetVimCommand() . cmd) |
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
|
93 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
|
94 endfunc |