annotate src/testdir/test_system.vim @ 23448:8f31b990ab1e v8.2.2267

patch 8.2.2267: Vim9: cannot use unlet for a dict member Commit: https://github.com/vim/vim/commit/c368957b1904bfaa2b0b52bbcade51b20173f3ed Author: Bram Moolenaar <Bram@vim.org> Date: Fri Jan 1 19:40:02 2021 +0100 patch 8.2.2267: Vim9: cannot use unlet for a dict member Problem: Vim9: cannot use unlet for a dict member. Solution: Pass GLV_NO_DECL to get_lval(). (closes https://github.com/vim/vim/issues/7585)
author Bram Moolenaar <Bram@vim.org>
date Fri, 01 Jan 2021 19:45:03 +0100
parents 756562af426e
children 82ae6fcd86c8
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'))
21451
756562af426e patch 8.2.1276: MS-Windows: system test may fail if more.exe is installed
Bram Moolenaar <Bram@vim.org>
parents: 20313
diff changeset
16 call assert_equal("123\n", system('more.com', '123'))
756562af426e patch 8.2.1276: MS-Windows: system test may fail if more.exe is installed
Bram Moolenaar <Bram@vim.org>
parents: 20313
diff changeset
17 call assert_equal(["123\r"], systemlist('more.com', '123'))
756562af426e patch 8.2.1276: MS-Windows: system test may fail if more.exe is installed
Bram Moolenaar <Bram@vim.org>
parents: 20313
diff changeset
18 call assert_equal(["as\r", "df\r"], systemlist('more.com', ["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
10522
7232cd9f8a7c commit https://github.com/vim/vim/commit/12c4492dd35e0cd83c8816be2ec849b836109882
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
21 new Xdummy
7232cd9f8a7c commit https://github.com/vim/vim/commit/12c4492dd35e0cd83c8816be2ec849b836109882
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
22 call setline(1, ['asdf', "pw\<NL>er", 'xxxx'])
18473
0eeaa9a6e4e7 patch 8.1.2230: MS-Windows: testing external commands can be improved
Bram Moolenaar <Bram@vim.org>
parents: 18241
diff changeset
23
0eeaa9a6e4e7 patch 8.1.2230: MS-Windows: testing external commands can be improved
Bram Moolenaar <Bram@vim.org>
parents: 18241
diff changeset
24 if executable('wc')
0eeaa9a6e4e7 patch 8.1.2230: MS-Windows: testing external commands can be improved
Bram Moolenaar <Bram@vim.org>
parents: 18241
diff changeset
25 let out = system('wc -l', bufnr('%'))
0eeaa9a6e4e7 patch 8.1.2230: MS-Windows: testing external commands can be improved
Bram Moolenaar <Bram@vim.org>
parents: 18241
diff changeset
26 " On OS/X we get leading spaces
0eeaa9a6e4e7 patch 8.1.2230: MS-Windows: testing external commands can be improved
Bram Moolenaar <Bram@vim.org>
parents: 18241
diff changeset
27 let out = substitute(out, '^ *', '', '')
0eeaa9a6e4e7 patch 8.1.2230: MS-Windows: testing external commands can be improved
Bram Moolenaar <Bram@vim.org>
parents: 18241
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
18473
0eeaa9a6e4e7 patch 8.1.2230: MS-Windows: testing external commands can be improved
Bram Moolenaar <Bram@vim.org>
parents: 18241
diff changeset
30 let out = systemlist('wc -l', bufnr('%'))
0eeaa9a6e4e7 patch 8.1.2230: MS-Windows: testing external commands can be improved
Bram Moolenaar <Bram@vim.org>
parents: 18241
diff changeset
31 " On Windows we may get a trailing CR.
0eeaa9a6e4e7 patch 8.1.2230: MS-Windows: testing external commands can be improved
Bram Moolenaar <Bram@vim.org>
parents: 18241
diff changeset
32 if out != ["3\r"]
0eeaa9a6e4e7 patch 8.1.2230: MS-Windows: testing external commands can be improved
Bram Moolenaar <Bram@vim.org>
parents: 18241
diff changeset
33 " On OS/X we get leading spaces
0eeaa9a6e4e7 patch 8.1.2230: MS-Windows: testing external commands can be improved
Bram Moolenaar <Bram@vim.org>
parents: 18241
diff changeset
34 if type(out) == v:t_list
0eeaa9a6e4e7 patch 8.1.2230: MS-Windows: testing external commands can be improved
Bram Moolenaar <Bram@vim.org>
parents: 18241
diff changeset
35 let out[0] = substitute(out[0], '^ *', '', '')
0eeaa9a6e4e7 patch 8.1.2230: MS-Windows: testing external commands can be improved
Bram Moolenaar <Bram@vim.org>
parents: 18241
diff changeset
36 endif
0eeaa9a6e4e7 patch 8.1.2230: MS-Windows: testing external commands can be improved
Bram Moolenaar <Bram@vim.org>
parents: 18241
diff changeset
37 call assert_equal(['3'], out)
10528
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 endif
06724e21d8c1 commit https://github.com/vim/vim/commit/9d9c35651712b88c81f1ae11091de1fd0bbbd35c
Christian Brabandt <cb@256bit.org>
parents: 10522
diff changeset
40
18195
a81f0c936112 patch 8.1.2092: MS-Windows: redirect in system() does not work
Bram Moolenaar <Bram@vim.org>
parents: 17698
diff changeset
41 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
42 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
43 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
44 else
21451
756562af426e patch 8.2.1276: MS-Windows: system test may fail if more.exe is installed
Bram Moolenaar <Bram@vim.org>
parents: 20313
diff changeset
45 let out = systemlist('more.com', bufnr('%'))
18197
78d4902b22df patch 8.1.2093: MS-Windows: system() test fails
Bram Moolenaar <Bram@vim.org>
parents: 18195
diff changeset
46 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
47 endif
10522
7232cd9f8a7c commit https://github.com/vim/vim/commit/12c4492dd35e0cd83c8816be2ec849b836109882
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
48 bwipe!
7232cd9f8a7c commit https://github.com/vim/vim/commit/12c4492dd35e0cd83c8816be2ec849b836109882
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
49
7232cd9f8a7c commit https://github.com/vim/vim/commit/12c4492dd35e0cd83c8816be2ec849b836109882
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
50 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
51 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
52
15406
63b02fcf1361 patch 8.1.0711: test files still use function!
Bram Moolenaar <Bram@vim.org>
parents: 11637
diff changeset
53 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
54 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
55 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
56 " 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
57 " function.
de4aae865134 patch 8.0.0197: system() test skips some parts for MS-Windows
Christian Brabandt <cb@256bit.org>
parents: 10591
diff changeset
58 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
59 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
60 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
61 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
62 endif
234da476c4fd patch 8.0.0185: system() test fails on MS-Windows
Christian Brabandt <cb@256bit.org>
parents: 10589
diff changeset
63
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
64 " 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
65 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
66 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
67 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
68 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
69 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
70
17698
131f1d8c5860 patch 8.1.1846: inconsistently using GetVimCommand() and v:progpath
Bram Moolenaar <Bram@vim.org>
parents: 17624
diff changeset
71 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
72 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
73 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
74 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
75
10615
de4aae865134 patch 8.0.0197: system() test skips some parts for MS-Windows
Christian Brabandt <cb@256bit.org>
parents: 10591
diff changeset
76 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
77 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
78 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
79 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
80 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
81
17698
131f1d8c5860 patch 8.1.1846: inconsistently using GetVimCommand() and v:progpath
Bram Moolenaar <Bram@vim.org>
parents: 17624
diff changeset
82 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
83 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
84 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
85
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 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
88 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
89 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
90 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
91
17698
131f1d8c5860 patch 8.1.1846: inconsistently using GetVimCommand() and v:progpath
Bram Moolenaar <Bram@vim.org>
parents: 17624
diff changeset
92 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
93 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
94 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
95 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
96
85160a3649b9 patch 8.1.2115: MS-Windows: shell commands fail if &shell contains a space
Bram Moolenaar <Bram@vim.org>
parents: 18197
diff changeset
97 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
98 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
99
85160a3649b9 patch 8.1.2115: MS-Windows: shell commands fail if &shell contains a space
Bram Moolenaar <Bram@vim.org>
parents: 18197
diff changeset
100 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
101 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
102
85160a3649b9 patch 8.1.2115: MS-Windows: shell commands fail if &shell contains a space
Bram Moolenaar <Bram@vim.org>
parents: 18197
diff changeset
103 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
104 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
105 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
106 " 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
107 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
108 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
109 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
110 \ 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
111 \ '"' . 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
112 \]
85160a3649b9 patch 8.1.2115: MS-Windows: shell commands fail if &shell contains a space
Bram Moolenaar <Bram@vim.org>
parents: 18197
diff changeset
113 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
114
85160a3649b9 patch 8.1.2115: MS-Windows: shell commands fail if &shell contains a space
Bram Moolenaar <Bram@vim.org>
parents: 18197
diff changeset
115 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
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 " 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
118 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
119 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
120 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
121 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
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 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
124
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 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
127 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
128 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
129 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
130 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
131
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 " 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
133 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
134 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
135 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
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 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
138 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
139
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 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
141 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
142 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
143 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
144 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
145 endfunc
20313
244eb8d8d100 patch 8.2.0712: various code not fully tested
Bram Moolenaar <Bram@vim.org>
parents: 18473
diff changeset
146
244eb8d8d100 patch 8.2.0712: various code not fully tested
Bram Moolenaar <Bram@vim.org>
parents: 18473
diff changeset
147 " Test for 'shellxquote'
244eb8d8d100 patch 8.2.0712: various code not fully tested
Bram Moolenaar <Bram@vim.org>
parents: 18473
diff changeset
148 func Test_Shellxquote()
244eb8d8d100 patch 8.2.0712: various code not fully tested
Bram Moolenaar <Bram@vim.org>
parents: 18473
diff changeset
149 CheckUnix
244eb8d8d100 patch 8.2.0712: various code not fully tested
Bram Moolenaar <Bram@vim.org>
parents: 18473
diff changeset
150
244eb8d8d100 patch 8.2.0712: various code not fully tested
Bram Moolenaar <Bram@vim.org>
parents: 18473
diff changeset
151 let save_shell = &shell
244eb8d8d100 patch 8.2.0712: various code not fully tested
Bram Moolenaar <Bram@vim.org>
parents: 18473
diff changeset
152 let save_sxq = &shellxquote
244eb8d8d100 patch 8.2.0712: various code not fully tested
Bram Moolenaar <Bram@vim.org>
parents: 18473
diff changeset
153 let save_sxe = &shellxescape
244eb8d8d100 patch 8.2.0712: various code not fully tested
Bram Moolenaar <Bram@vim.org>
parents: 18473
diff changeset
154
244eb8d8d100 patch 8.2.0712: various code not fully tested
Bram Moolenaar <Bram@vim.org>
parents: 18473
diff changeset
155 call writefile(['#!/bin/sh', 'echo "Cmd: [$*]" > Xlog'], 'Xtestshell')
244eb8d8d100 patch 8.2.0712: various code not fully tested
Bram Moolenaar <Bram@vim.org>
parents: 18473
diff changeset
156 call setfperm('Xtestshell', "r-x------")
244eb8d8d100 patch 8.2.0712: various code not fully tested
Bram Moolenaar <Bram@vim.org>
parents: 18473
diff changeset
157 set shell=./Xtestshell
244eb8d8d100 patch 8.2.0712: various code not fully tested
Bram Moolenaar <Bram@vim.org>
parents: 18473
diff changeset
158
244eb8d8d100 patch 8.2.0712: various code not fully tested
Bram Moolenaar <Bram@vim.org>
parents: 18473
diff changeset
159 set shellxquote=\\"
244eb8d8d100 patch 8.2.0712: various code not fully tested
Bram Moolenaar <Bram@vim.org>
parents: 18473
diff changeset
160 call feedkeys(":!pwd\<CR>\<CR>", 'xt')
244eb8d8d100 patch 8.2.0712: various code not fully tested
Bram Moolenaar <Bram@vim.org>
parents: 18473
diff changeset
161 call assert_equal(['Cmd: [-c "pwd"]'], readfile('Xlog'))
244eb8d8d100 patch 8.2.0712: various code not fully tested
Bram Moolenaar <Bram@vim.org>
parents: 18473
diff changeset
162
244eb8d8d100 patch 8.2.0712: various code not fully tested
Bram Moolenaar <Bram@vim.org>
parents: 18473
diff changeset
163 set shellxquote=(
244eb8d8d100 patch 8.2.0712: various code not fully tested
Bram Moolenaar <Bram@vim.org>
parents: 18473
diff changeset
164 call feedkeys(":!pwd\<CR>\<CR>", 'xt')
244eb8d8d100 patch 8.2.0712: various code not fully tested
Bram Moolenaar <Bram@vim.org>
parents: 18473
diff changeset
165 call assert_equal(['Cmd: [-c (pwd)]'], readfile('Xlog'))
244eb8d8d100 patch 8.2.0712: various code not fully tested
Bram Moolenaar <Bram@vim.org>
parents: 18473
diff changeset
166
244eb8d8d100 patch 8.2.0712: various code not fully tested
Bram Moolenaar <Bram@vim.org>
parents: 18473
diff changeset
167 set shellxquote=\\"(
244eb8d8d100 patch 8.2.0712: various code not fully tested
Bram Moolenaar <Bram@vim.org>
parents: 18473
diff changeset
168 call feedkeys(":!pwd\<CR>\<CR>", 'xt')
244eb8d8d100 patch 8.2.0712: various code not fully tested
Bram Moolenaar <Bram@vim.org>
parents: 18473
diff changeset
169 call assert_equal(['Cmd: [-c "(pwd)"]'], readfile('Xlog'))
244eb8d8d100 patch 8.2.0712: various code not fully tested
Bram Moolenaar <Bram@vim.org>
parents: 18473
diff changeset
170
244eb8d8d100 patch 8.2.0712: various code not fully tested
Bram Moolenaar <Bram@vim.org>
parents: 18473
diff changeset
171 set shellxescape=\"&<<()@^
244eb8d8d100 patch 8.2.0712: various code not fully tested
Bram Moolenaar <Bram@vim.org>
parents: 18473
diff changeset
172 set shellxquote=(
244eb8d8d100 patch 8.2.0712: various code not fully tested
Bram Moolenaar <Bram@vim.org>
parents: 18473
diff changeset
173 call feedkeys(":!pwd\"&<<{}@^\<CR>\<CR>", 'xt')
244eb8d8d100 patch 8.2.0712: various code not fully tested
Bram Moolenaar <Bram@vim.org>
parents: 18473
diff changeset
174 call assert_equal(['Cmd: [-c (pwd^"^&^<^<{}^@^^)]'], readfile('Xlog'))
244eb8d8d100 patch 8.2.0712: various code not fully tested
Bram Moolenaar <Bram@vim.org>
parents: 18473
diff changeset
175
244eb8d8d100 patch 8.2.0712: various code not fully tested
Bram Moolenaar <Bram@vim.org>
parents: 18473
diff changeset
176 let &shell = save_shell
244eb8d8d100 patch 8.2.0712: various code not fully tested
Bram Moolenaar <Bram@vim.org>
parents: 18473
diff changeset
177 let &shellxquote = save_sxq
244eb8d8d100 patch 8.2.0712: various code not fully tested
Bram Moolenaar <Bram@vim.org>
parents: 18473
diff changeset
178 let &shellxescape = save_sxe
244eb8d8d100 patch 8.2.0712: various code not fully tested
Bram Moolenaar <Bram@vim.org>
parents: 18473
diff changeset
179 call delete('Xtestshell')
244eb8d8d100 patch 8.2.0712: various code not fully tested
Bram Moolenaar <Bram@vim.org>
parents: 18473
diff changeset
180 call delete('Xlog')
244eb8d8d100 patch 8.2.0712: various code not fully tested
Bram Moolenaar <Bram@vim.org>
parents: 18473
diff changeset
181 endfunc
244eb8d8d100 patch 8.2.0712: various code not fully tested
Bram Moolenaar <Bram@vim.org>
parents: 18473
diff changeset
182
244eb8d8d100 patch 8.2.0712: various code not fully tested
Bram Moolenaar <Bram@vim.org>
parents: 18473
diff changeset
183 " vim: shiftwidth=2 sts=2 expandtab