annotate src/testdir/test_system.vim @ 18241:85160a3649b9 v8.1.2115

patch 8.1.2115: MS-Windows: shell commands fail if &shell contains a space Commit: https://github.com/vim/vim/commit/2efc44b3f0b6bd8307cb281af095e08e15ab1c24 Author: Bram Moolenaar <Bram@vim.org> Date: Sat Oct 5 12:09:32 2019 +0200 patch 8.1.2115: MS-Windows: shell commands fail if &shell contains a space Problem: MS-Windows: shell commands fail if &shell contains a space. Solution: Use quotes instead of escaping. (closes https://github.com/vim/vim/issues/4920)
author Bram Moolenaar <Bram@vim.org>
date Sat, 05 Oct 2019 12:15:04 +0200
parents 78d4902b22df
children 0eeaa9a6e4e7
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
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
18241
85160a3649b9 patch 8.1.2115: MS-Windows: shell commands fail if &shell contains a space
Bram Moolenaar <Bram@vim.org>
parents: 18197
diff changeset
4 source check.vim
17698
131f1d8c5860 patch 8.1.1846: inconsistently using GetVimCommand() and v:progpath
Bram Moolenaar <Bram@vim.org>
parents: 17624
diff changeset
5
15406
63b02fcf1361 patch 8.1.0711: test files still use function!
Bram Moolenaar <Bram@vim.org>
parents: 11637
diff changeset
6 func Test_System()
18195
a81f0c936112 patch 8.1.2092: MS-Windows: redirect in system() does not work
Bram Moolenaar <Bram@vim.org>
parents: 17698
diff changeset
7 if !has('win32')
a81f0c936112 patch 8.1.2092: MS-Windows: redirect in system() does not work
Bram Moolenaar <Bram@vim.org>
parents: 17698
diff changeset
8 call assert_equal("123\n", system('echo 123'))
a81f0c936112 patch 8.1.2092: MS-Windows: redirect in system() does not work
Bram Moolenaar <Bram@vim.org>
parents: 17698
diff changeset
9 call assert_equal(['123'], systemlist('echo 123'))
a81f0c936112 patch 8.1.2092: MS-Windows: redirect in system() does not work
Bram Moolenaar <Bram@vim.org>
parents: 17698
diff changeset
10 call assert_equal('123', system('cat', '123'))
a81f0c936112 patch 8.1.2092: MS-Windows: redirect in system() does not work
Bram Moolenaar <Bram@vim.org>
parents: 17698
diff changeset
11 call assert_equal(['123'], systemlist('cat', '123'))
a81f0c936112 patch 8.1.2092: MS-Windows: redirect in system() does not work
Bram Moolenaar <Bram@vim.org>
parents: 17698
diff changeset
12 call assert_equal(["as\<NL>df"], systemlist('cat', ["as\<NL>df"]))
a81f0c936112 patch 8.1.2092: MS-Windows: redirect in system() does not work
Bram Moolenaar <Bram@vim.org>
parents: 17698
diff changeset
13 else
a81f0c936112 patch 8.1.2092: MS-Windows: redirect in system() does not work
Bram Moolenaar <Bram@vim.org>
parents: 17698
diff changeset
14 call assert_equal("123\n", system('echo 123'))
a81f0c936112 patch 8.1.2092: MS-Windows: redirect in system() does not work
Bram Moolenaar <Bram@vim.org>
parents: 17698
diff changeset
15 call assert_equal(["123\r"], systemlist('echo 123'))
18197
78d4902b22df patch 8.1.2093: MS-Windows: system() test fails
Bram Moolenaar <Bram@vim.org>
parents: 18195
diff changeset
16 call assert_equal("123\n", system('more', '123'))
78d4902b22df patch 8.1.2093: MS-Windows: system() test fails
Bram Moolenaar <Bram@vim.org>
parents: 18195
diff changeset
17 call assert_equal(["123\r"], systemlist('more', '123'))
78d4902b22df patch 8.1.2093: MS-Windows: system() test fails
Bram Moolenaar <Bram@vim.org>
parents: 18195
diff changeset
18 call assert_equal(["as\r", "df\r"], systemlist('more', ["as\<NL>df"]))
18195
a81f0c936112 patch 8.1.2092: MS-Windows: redirect in system() does not work
Bram Moolenaar <Bram@vim.org>
parents: 17698
diff changeset
19 endif
a81f0c936112 patch 8.1.2092: MS-Windows: redirect in system() does not work
Bram Moolenaar <Bram@vim.org>
parents: 17698
diff changeset
20
a81f0c936112 patch 8.1.2092: MS-Windows: redirect in system() does not work
Bram Moolenaar <Bram@vim.org>
parents: 17698
diff changeset
21 if !executable('cat') || !executable('wc')
10522
7232cd9f8a7c commit https://github.com/vim/vim/commit/12c4492dd35e0cd83c8816be2ec849b836109882
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
22 return
7232cd9f8a7c commit https://github.com/vim/vim/commit/12c4492dd35e0cd83c8816be2ec849b836109882
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
23 endif
18195
a81f0c936112 patch 8.1.2092: MS-Windows: redirect in system() does not work
Bram Moolenaar <Bram@vim.org>
parents: 17698
diff changeset
24
17624
4c7097a980a5 patch 8.1.1809: more functions can be used as a method
Bram Moolenaar <Bram@vim.org>
parents: 15406
diff changeset
25 let out = 'echo 123'->system()
10526
06724e21d8c1 commit https://github.com/vim/vim/commit/9d9c35651712b88c81f1ae11091de1fd0bbbd35c
Christian Brabandt <cb@256bit.org>
parents: 10522
diff changeset
26 " 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
27 if out != "123 \n"
06724e21d8c1 commit https://github.com/vim/vim/commit/9d9c35651712b88c81f1ae11091de1fd0bbbd35c
Christian Brabandt <cb@256bit.org>
parents: 10522
diff changeset
28 call assert_equal("123\n", out)
06724e21d8c1 commit https://github.com/vim/vim/commit/9d9c35651712b88c81f1ae11091de1fd0bbbd35c
Christian Brabandt <cb@256bit.org>
parents: 10522
diff changeset
29 endif
06724e21d8c1 commit https://github.com/vim/vim/commit/9d9c35651712b88c81f1ae11091de1fd0bbbd35c
Christian Brabandt <cb@256bit.org>
parents: 10522
diff changeset
30
17624
4c7097a980a5 patch 8.1.1809: more functions can be used as a method
Bram Moolenaar <Bram@vim.org>
parents: 15406
diff changeset
31 let out = 'echo 123'->systemlist()
18195
a81f0c936112 patch 8.1.2092: MS-Windows: redirect in system() does not work
Bram Moolenaar <Bram@vim.org>
parents: 17698
diff changeset
32 if !has('win32')
a81f0c936112 patch 8.1.2092: MS-Windows: redirect in system() does not work
Bram Moolenaar <Bram@vim.org>
parents: 17698
diff changeset
33 call assert_equal(["123"], out)
a81f0c936112 patch 8.1.2092: MS-Windows: redirect in system() does not work
Bram Moolenaar <Bram@vim.org>
parents: 17698
diff changeset
34 else
a81f0c936112 patch 8.1.2092: MS-Windows: redirect in system() does not work
Bram Moolenaar <Bram@vim.org>
parents: 17698
diff changeset
35 call assert_equal(["123\r"], out)
10526
06724e21d8c1 commit https://github.com/vim/vim/commit/9d9c35651712b88c81f1ae11091de1fd0bbbd35c
Christian Brabandt <cb@256bit.org>
parents: 10522
diff changeset
36 endif
06724e21d8c1 commit https://github.com/vim/vim/commit/9d9c35651712b88c81f1ae11091de1fd0bbbd35c
Christian Brabandt <cb@256bit.org>
parents: 10522
diff changeset
37
18195
a81f0c936112 patch 8.1.2092: MS-Windows: redirect in system() does not work
Bram Moolenaar <Bram@vim.org>
parents: 17698
diff changeset
38 if executable('cat')
a81f0c936112 patch 8.1.2092: MS-Windows: redirect in system() does not work
Bram Moolenaar <Bram@vim.org>
parents: 17698
diff changeset
39 call assert_equal('123', system('cat', '123'))
a81f0c936112 patch 8.1.2092: MS-Windows: redirect in system() does not work
Bram Moolenaar <Bram@vim.org>
parents: 17698
diff changeset
40 call assert_equal(['123'], systemlist('cat', '123'))
a81f0c936112 patch 8.1.2092: MS-Windows: redirect in system() does not work
Bram Moolenaar <Bram@vim.org>
parents: 17698
diff changeset
41 call assert_equal(["as\<NL>df"], systemlist('cat', ["as\<NL>df"]))
a81f0c936112 patch 8.1.2092: MS-Windows: redirect in system() does not work
Bram Moolenaar <Bram@vim.org>
parents: 17698
diff changeset
42 endif
10528
3ea703795a4f commit https://github.com/vim/vim/commit/31f19ce0a052f7c76d44a9a190e468c79cf5d56d
Christian Brabandt <cb@256bit.org>
parents: 10526
diff changeset
43
10522
7232cd9f8a7c commit https://github.com/vim/vim/commit/12c4492dd35e0cd83c8816be2ec849b836109882
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
44 new Xdummy
7232cd9f8a7c commit https://github.com/vim/vim/commit/12c4492dd35e0cd83c8816be2ec849b836109882
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
45 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
46 let out = system('wc -l', bufnr('%'))
3ea703795a4f commit https://github.com/vim/vim/commit/31f19ce0a052f7c76d44a9a190e468c79cf5d56d
Christian Brabandt <cb@256bit.org>
parents: 10526
diff changeset
47 " 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
48 let out = substitute(out, '^ *', '', '')
3ea703795a4f commit https://github.com/vim/vim/commit/31f19ce0a052f7c76d44a9a190e468c79cf5d56d
Christian Brabandt <cb@256bit.org>
parents: 10526
diff changeset
49 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
50
06724e21d8c1 commit https://github.com/vim/vim/commit/9d9c35651712b88c81f1ae11091de1fd0bbbd35c
Christian Brabandt <cb@256bit.org>
parents: 10522
diff changeset
51 let out = systemlist('wc -l', bufnr('%'))
06724e21d8c1 commit https://github.com/vim/vim/commit/9d9c35651712b88c81f1ae11091de1fd0bbbd35c
Christian Brabandt <cb@256bit.org>
parents: 10522
diff changeset
52 " 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
53 if out != ["3\r"]
10528
3ea703795a4f commit https://github.com/vim/vim/commit/31f19ce0a052f7c76d44a9a190e468c79cf5d56d
Christian Brabandt <cb@256bit.org>
parents: 10526
diff changeset
54 " 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
55 if type(out) == v:t_list
3ea703795a4f commit https://github.com/vim/vim/commit/31f19ce0a052f7c76d44a9a190e468c79cf5d56d
Christian Brabandt <cb@256bit.org>
parents: 10526
diff changeset
56 let out[0] = substitute(out[0], '^ *', '', '')
3ea703795a4f commit https://github.com/vim/vim/commit/31f19ce0a052f7c76d44a9a190e468c79cf5d56d
Christian Brabandt <cb@256bit.org>
parents: 10526
diff changeset
57 endif
10526
06724e21d8c1 commit https://github.com/vim/vim/commit/9d9c35651712b88c81f1ae11091de1fd0bbbd35c
Christian Brabandt <cb@256bit.org>
parents: 10522
diff changeset
58 call assert_equal(['3'], out)
06724e21d8c1 commit https://github.com/vim/vim/commit/9d9c35651712b88c81f1ae11091de1fd0bbbd35c
Christian Brabandt <cb@256bit.org>
parents: 10522
diff changeset
59 endif
06724e21d8c1 commit https://github.com/vim/vim/commit/9d9c35651712b88c81f1ae11091de1fd0bbbd35c
Christian Brabandt <cb@256bit.org>
parents: 10522
diff changeset
60
18195
a81f0c936112 patch 8.1.2092: MS-Windows: redirect in system() does not work
Bram Moolenaar <Bram@vim.org>
parents: 17698
diff changeset
61 if !has('win32')
a81f0c936112 patch 8.1.2092: MS-Windows: redirect in system() does not work
Bram Moolenaar <Bram@vim.org>
parents: 17698
diff changeset
62 let out = systemlist('cat', bufnr('%'))
a81f0c936112 patch 8.1.2092: MS-Windows: redirect in system() does not work
Bram Moolenaar <Bram@vim.org>
parents: 17698
diff changeset
63 call assert_equal(['asdf', "pw\<NL>er", 'xxxx'], out)
a81f0c936112 patch 8.1.2092: MS-Windows: redirect in system() does not work
Bram Moolenaar <Bram@vim.org>
parents: 17698
diff changeset
64 else
a81f0c936112 patch 8.1.2092: MS-Windows: redirect in system() does not work
Bram Moolenaar <Bram@vim.org>
parents: 17698
diff changeset
65 let out = systemlist('more', bufnr('%'))
18197
78d4902b22df patch 8.1.2093: MS-Windows: system() test fails
Bram Moolenaar <Bram@vim.org>
parents: 18195
diff changeset
66 call assert_equal(["asdf\r", "pw\r", "er\r", "xxxx\r"], out)
10526
06724e21d8c1 commit https://github.com/vim/vim/commit/9d9c35651712b88c81f1ae11091de1fd0bbbd35c
Christian Brabandt <cb@256bit.org>
parents: 10522
diff changeset
67 endif
10522
7232cd9f8a7c commit https://github.com/vim/vim/commit/12c4492dd35e0cd83c8816be2ec849b836109882
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
68 bwipe!
7232cd9f8a7c commit https://github.com/vim/vim/commit/12c4492dd35e0cd83c8816be2ec849b836109882
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
69
7232cd9f8a7c commit https://github.com/vim/vim/commit/12c4492dd35e0cd83c8816be2ec849b836109882
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
70 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
71 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
72
15406
63b02fcf1361 patch 8.1.0711: test files still use function!
Bram Moolenaar <Bram@vim.org>
parents: 11637
diff changeset
73 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
74 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
75 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
76 " 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
77 " function.
de4aae865134 patch 8.0.0197: system() test skips some parts for MS-Windows
Christian Brabandt <cb@256bit.org>
parents: 10591
diff changeset
78 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
79 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
80 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
81 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
82 endif
234da476c4fd patch 8.0.0185: system() test fails on MS-Windows
Christian Brabandt <cb@256bit.org>
parents: 10589
diff changeset
83
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
84 " 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
85 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
86 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
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 "source Xscript" +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)
10615
de4aae865134 patch 8.0.0197: system() test skips some parts for MS-Windows
Christian Brabandt <cb@256bit.org>
parents: 10591
diff changeset
94 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
95
10615
de4aae865134 patch 8.0.0197: system() test skips some parts for MS-Windows
Christian Brabandt <cb@256bit.org>
parents: 10591
diff changeset
96 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
97 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
98 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
99 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
100 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
101
17698
131f1d8c5860 patch 8.1.1846: inconsistently using GetVimCommand() and v:progpath
Bram Moolenaar <Bram@vim.org>
parents: 17624
diff changeset
102 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
103 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
104 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
105
10615
de4aae865134 patch 8.0.0197: system() test skips some parts for MS-Windows
Christian Brabandt <cb@256bit.org>
parents: 10591
diff changeset
106 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
107 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
108 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
109 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
110 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
111
17698
131f1d8c5860 patch 8.1.1846: inconsistently using GetVimCommand() and v:progpath
Bram Moolenaar <Bram@vim.org>
parents: 17624
diff changeset
112 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
113 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
114 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
115 endfunc
18241
85160a3649b9 patch 8.1.2115: MS-Windows: shell commands fail if &shell contains a space
Bram Moolenaar <Bram@vim.org>
parents: 18197
diff changeset
116
85160a3649b9 patch 8.1.2115: MS-Windows: shell commands fail if &shell contains a space
Bram Moolenaar <Bram@vim.org>
parents: 18197
diff changeset
117 func Test_system_with_shell_quote()
85160a3649b9 patch 8.1.2115: MS-Windows: shell commands fail if &shell contains a space
Bram Moolenaar <Bram@vim.org>
parents: 18197
diff changeset
118 CheckMSWindows
85160a3649b9 patch 8.1.2115: MS-Windows: shell commands fail if &shell contains a space
Bram Moolenaar <Bram@vim.org>
parents: 18197
diff changeset
119
85160a3649b9 patch 8.1.2115: MS-Windows: shell commands fail if &shell contains a space
Bram Moolenaar <Bram@vim.org>
parents: 18197
diff changeset
120 call mkdir('Xdir with spaces', 'p')
85160a3649b9 patch 8.1.2115: MS-Windows: shell commands fail if &shell contains a space
Bram Moolenaar <Bram@vim.org>
parents: 18197
diff changeset
121 call system('copy "%COMSPEC%" "Xdir with spaces\cmd.exe"')
85160a3649b9 patch 8.1.2115: MS-Windows: shell commands fail if &shell contains a space
Bram Moolenaar <Bram@vim.org>
parents: 18197
diff changeset
122
85160a3649b9 patch 8.1.2115: MS-Windows: shell commands fail if &shell contains a space
Bram Moolenaar <Bram@vim.org>
parents: 18197
diff changeset
123 let shell_save = &shell
85160a3649b9 patch 8.1.2115: MS-Windows: shell commands fail if &shell contains a space
Bram Moolenaar <Bram@vim.org>
parents: 18197
diff changeset
124 let shellxquote_save = &shellxquote
85160a3649b9 patch 8.1.2115: MS-Windows: shell commands fail if &shell contains a space
Bram Moolenaar <Bram@vim.org>
parents: 18197
diff changeset
125 try
85160a3649b9 patch 8.1.2115: MS-Windows: shell commands fail if &shell contains a space
Bram Moolenaar <Bram@vim.org>
parents: 18197
diff changeset
126 " Set 'shell' always needs noshellslash.
85160a3649b9 patch 8.1.2115: MS-Windows: shell commands fail if &shell contains a space
Bram Moolenaar <Bram@vim.org>
parents: 18197
diff changeset
127 let shellslash_save = &shellslash
85160a3649b9 patch 8.1.2115: MS-Windows: shell commands fail if &shell contains a space
Bram Moolenaar <Bram@vim.org>
parents: 18197
diff changeset
128 set noshellslash
85160a3649b9 patch 8.1.2115: MS-Windows: shell commands fail if &shell contains a space
Bram Moolenaar <Bram@vim.org>
parents: 18197
diff changeset
129 let shell_tests = [
85160a3649b9 patch 8.1.2115: MS-Windows: shell commands fail if &shell contains a space
Bram Moolenaar <Bram@vim.org>
parents: 18197
diff changeset
130 \ expand('$COMSPEC'),
85160a3649b9 patch 8.1.2115: MS-Windows: shell commands fail if &shell contains a space
Bram Moolenaar <Bram@vim.org>
parents: 18197
diff changeset
131 \ '"' . fnamemodify('Xdir with spaces\cmd.exe', ':p') . '"',
85160a3649b9 patch 8.1.2115: MS-Windows: shell commands fail if &shell contains a space
Bram Moolenaar <Bram@vim.org>
parents: 18197
diff changeset
132 \]
85160a3649b9 patch 8.1.2115: MS-Windows: shell commands fail if &shell contains a space
Bram Moolenaar <Bram@vim.org>
parents: 18197
diff changeset
133 let &shellslash = shellslash_save
85160a3649b9 patch 8.1.2115: MS-Windows: shell commands fail if &shell contains a space
Bram Moolenaar <Bram@vim.org>
parents: 18197
diff changeset
134
85160a3649b9 patch 8.1.2115: MS-Windows: shell commands fail if &shell contains a space
Bram Moolenaar <Bram@vim.org>
parents: 18197
diff changeset
135 let sxq_tests = ['', '(', '"']
85160a3649b9 patch 8.1.2115: MS-Windows: shell commands fail if &shell contains a space
Bram Moolenaar <Bram@vim.org>
parents: 18197
diff changeset
136
85160a3649b9 patch 8.1.2115: MS-Windows: shell commands fail if &shell contains a space
Bram Moolenaar <Bram@vim.org>
parents: 18197
diff changeset
137 " Matrix tests: 'shell' * 'shellxquote'
85160a3649b9 patch 8.1.2115: MS-Windows: shell commands fail if &shell contains a space
Bram Moolenaar <Bram@vim.org>
parents: 18197
diff changeset
138 for shell in shell_tests
85160a3649b9 patch 8.1.2115: MS-Windows: shell commands fail if &shell contains a space
Bram Moolenaar <Bram@vim.org>
parents: 18197
diff changeset
139 let &shell = shell
85160a3649b9 patch 8.1.2115: MS-Windows: shell commands fail if &shell contains a space
Bram Moolenaar <Bram@vim.org>
parents: 18197
diff changeset
140 for sxq in sxq_tests
85160a3649b9 patch 8.1.2115: MS-Windows: shell commands fail if &shell contains a space
Bram Moolenaar <Bram@vim.org>
parents: 18197
diff changeset
141 let &shellxquote = sxq
85160a3649b9 patch 8.1.2115: MS-Windows: shell commands fail if &shell contains a space
Bram Moolenaar <Bram@vim.org>
parents: 18197
diff changeset
142
85160a3649b9 patch 8.1.2115: MS-Windows: shell commands fail if &shell contains a space
Bram Moolenaar <Bram@vim.org>
parents: 18197
diff changeset
143 let msg = printf('shell=%s shellxquote=%s', &shell, &shellxquote)
85160a3649b9 patch 8.1.2115: MS-Windows: shell commands fail if &shell contains a space
Bram Moolenaar <Bram@vim.org>
parents: 18197
diff changeset
144
85160a3649b9 patch 8.1.2115: MS-Windows: shell commands fail if &shell contains a space
Bram Moolenaar <Bram@vim.org>
parents: 18197
diff changeset
145 try
85160a3649b9 patch 8.1.2115: MS-Windows: shell commands fail if &shell contains a space
Bram Moolenaar <Bram@vim.org>
parents: 18197
diff changeset
146 let out = 'echo 123'->system()
85160a3649b9 patch 8.1.2115: MS-Windows: shell commands fail if &shell contains a space
Bram Moolenaar <Bram@vim.org>
parents: 18197
diff changeset
147 catch
85160a3649b9 patch 8.1.2115: MS-Windows: shell commands fail if &shell contains a space
Bram Moolenaar <Bram@vim.org>
parents: 18197
diff changeset
148 call assert_report(printf('%s: %s', msg, v:exception))
85160a3649b9 patch 8.1.2115: MS-Windows: shell commands fail if &shell contains a space
Bram Moolenaar <Bram@vim.org>
parents: 18197
diff changeset
149 continue
85160a3649b9 patch 8.1.2115: MS-Windows: shell commands fail if &shell contains a space
Bram Moolenaar <Bram@vim.org>
parents: 18197
diff changeset
150 endtry
85160a3649b9 patch 8.1.2115: MS-Windows: shell commands fail if &shell contains a space
Bram Moolenaar <Bram@vim.org>
parents: 18197
diff changeset
151
85160a3649b9 patch 8.1.2115: MS-Windows: shell commands fail if &shell contains a space
Bram Moolenaar <Bram@vim.org>
parents: 18197
diff changeset
152 " On Windows we may get a trailing space and CR.
85160a3649b9 patch 8.1.2115: MS-Windows: shell commands fail if &shell contains a space
Bram Moolenaar <Bram@vim.org>
parents: 18197
diff changeset
153 if out != "123 \n"
85160a3649b9 patch 8.1.2115: MS-Windows: shell commands fail if &shell contains a space
Bram Moolenaar <Bram@vim.org>
parents: 18197
diff changeset
154 call assert_equal("123\n", out, msg)
85160a3649b9 patch 8.1.2115: MS-Windows: shell commands fail if &shell contains a space
Bram Moolenaar <Bram@vim.org>
parents: 18197
diff changeset
155 endif
85160a3649b9 patch 8.1.2115: MS-Windows: shell commands fail if &shell contains a space
Bram Moolenaar <Bram@vim.org>
parents: 18197
diff changeset
156
85160a3649b9 patch 8.1.2115: MS-Windows: shell commands fail if &shell contains a space
Bram Moolenaar <Bram@vim.org>
parents: 18197
diff changeset
157 endfor
85160a3649b9 patch 8.1.2115: MS-Windows: shell commands fail if &shell contains a space
Bram Moolenaar <Bram@vim.org>
parents: 18197
diff changeset
158 endfor
85160a3649b9 patch 8.1.2115: MS-Windows: shell commands fail if &shell contains a space
Bram Moolenaar <Bram@vim.org>
parents: 18197
diff changeset
159
85160a3649b9 patch 8.1.2115: MS-Windows: shell commands fail if &shell contains a space
Bram Moolenaar <Bram@vim.org>
parents: 18197
diff changeset
160 finally
85160a3649b9 patch 8.1.2115: MS-Windows: shell commands fail if &shell contains a space
Bram Moolenaar <Bram@vim.org>
parents: 18197
diff changeset
161 let &shell = shell_save
85160a3649b9 patch 8.1.2115: MS-Windows: shell commands fail if &shell contains a space
Bram Moolenaar <Bram@vim.org>
parents: 18197
diff changeset
162 let &shellxquote = shellxquote_save
85160a3649b9 patch 8.1.2115: MS-Windows: shell commands fail if &shell contains a space
Bram Moolenaar <Bram@vim.org>
parents: 18197
diff changeset
163 call delete('Xdir with spaces', 'rf')
85160a3649b9 patch 8.1.2115: MS-Windows: shell commands fail if &shell contains a space
Bram Moolenaar <Bram@vim.org>
parents: 18197
diff changeset
164 endtry
85160a3649b9 patch 8.1.2115: MS-Windows: shell commands fail if &shell contains a space
Bram Moolenaar <Bram@vim.org>
parents: 18197
diff changeset
165 endfunc