@@ -5,9 +5,8 @@ source check.vim
55source shared.vim
66
77func Test_shell_options ()
8- " For each shell, the following options are checked:
9- " 'shellcmdflag', 'shellpipe', 'shellquote', 'shellredir', 'shellxescape',
10- " 'shellxquote'
8+ " The expected value of 'shellcmdflag', 'shellpipe', 'shellquote',
9+ " 'shellredir', 'shellxescape', 'shellxquote' for the supported shells.
1110 let shells = []
1211 if has (' unix' )
1312 let shells += [[' sh' , ' -c' , ' 2>&1| tee' , ' ' , ' >%s 2>&1' , ' ' , ' ' ],
@@ -39,6 +38,8 @@ func Test_shell_options()
3938 \ [' tcsh.exe' , ' -c' , ' >&' , ' ' , ' >&' , ' "&|<>()@^' , ' "' ]]
4039 endif
4140
41+ " start a new Vim instance with 'shell' set to each of the supported shells
42+ " and check the default shell option settings
4243 let after = << trim END
4344 let l = [&shell , &shellcmdflag , &shellpipe , &shellquote ]
4445 let l += [&shellredir , &shellxescape , &shellxquote ]
@@ -51,6 +52,7 @@ func Test_shell_options()
5152 endif
5253 endfor
5354
55+ " Test shellescape() for each of the shells.
5456 for e in shells
5557 exe ' set shell=' .. e [0 ]
5658 if e [0 ] = ~# ' .*csh$' || e [0 ] = ~# ' .*csh.exe$'
@@ -62,8 +64,20 @@ func Test_shell_options()
6264 endif
6365 call assert_equal (str1, shellescape (" cmd \" arg1\" 'arg2' !%#" ), e [0 ])
6466 call assert_equal (str2, shellescape (" cmd \" arg1\" 'arg2' !%#" , 1 ), e [0 ])
67+
68+ " Try running an external command with the shell.
69+ if executable (e [0 ])
70+ " set the shell options for the current 'shell'
71+ let [&shellcmdflag , &shellpipe , &shellquote , &shellredir ,
72+ \ &shellxescape , &shellxquote ] = e [1 :6 ]
73+ new
74+ r ! echo hello
75+ call assert_equal (' hello' , substitute (getline (2 ), ' \W' , ' ' , ' g' ), e [0 ])
76+ bwipe!
77+ endif
6578 endfor
66- set shell &
79+ set shell & shellcmdflag & shellpipe & shellquote &
80+ set shellredir & shellxescape & shellxquote &
6781 call delete (' Xtestout' )
6882endfunc
6983
@@ -95,6 +109,7 @@ func Test_shellquote()
95109 call assert_match (' : "#echo Hello#"' , v )
96110endfunc
97111
112+ " Test for the 'shellescape' option
98113func Test_shellescape ()
99114 let save_shell = &shell
100115 set shell = bash
@@ -156,4 +171,26 @@ func Test_shellxquote()
156171 call delete (' Xlog' )
157172endfunc
158173
174+ " Test for using the shell set in the $SHELL environment variable
175+ func Test_set_shell ()
176+ let after = << trim [CODE]
177+ call writefile ([&shell ], " Xtestout" )
178+ quit !
179+ [CODE]
180+
181+ if has (' win32' )
182+ let $SHELL = ' C:\with space\cmd.exe'
183+ let expected = ' "C:\with space\cmd.exe"'
184+ else
185+ let $SHELL = ' /bin/with space/sh'
186+ let expected = ' /bin/with\ space/sh'
187+ endif
188+
189+ if RunVimPiped ([], after, ' ' , ' ' )
190+ let lines = readfile (' Xtestout' )
191+ call assert_equal (expected, lines [0 ])
192+ endif
193+ call delete (' Xtestout' )
194+ endfunc
195+
159196" vim: shiftwidth = 2 sts = 2 expandtab
0 commit comments