Skip to content

Commit ffec6dd

Browse files
yegappanbrammool
authored andcommitted
patch 8.2.3070: not enough testing for shell use
Problem: Not enough testing for shell use. Solution: Add a bit more testing. (Yegappan Lakshmanan, closes #8469)
1 parent 108010a commit ffec6dd

3 files changed

Lines changed: 43 additions & 25 deletions

File tree

src/testdir/test_shell.vim

Lines changed: 41 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -5,9 +5,8 @@ source check.vim
55
source shared.vim
66

77
func 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')
6882
endfunc
6983

@@ -95,6 +109,7 @@ func Test_shellquote()
95109
call assert_match(': "#echo Hello#"', v)
96110
endfunc
97111

112+
" Test for the 'shellescape' option
98113
func Test_shellescape()
99114
let save_shell = &shell
100115
set shell=bash
@@ -156,4 +171,26 @@ func Test_shellxquote()
156171
call delete('Xlog')
157172
endfunc
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

src/testdir/test_startup.vim

Lines changed: 0 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -733,27 +733,6 @@ func Test_read_stdin()
733733
call delete('Xtestout')
734734
endfunc
735735

736-
func Test_set_shell()
737-
let after =<< trim [CODE]
738-
call writefile([&shell], "Xtestout")
739-
quit!
740-
[CODE]
741-
742-
if has('win32')
743-
let $SHELL = 'C:\with space\cmd.exe'
744-
let expected = '"C:\with space\cmd.exe"'
745-
else
746-
let $SHELL = '/bin/with space/sh'
747-
let expected = '/bin/with\ space/sh'
748-
endif
749-
750-
if RunVimPiped([], after, '', '')
751-
let lines = readfile('Xtestout')
752-
call assert_equal(expected, lines[0])
753-
endif
754-
call delete('Xtestout')
755-
endfunc
756-
757736
func Test_progpath()
758737
" Tests normally run with "./vim" or "../vim", these must have been expanded
759738
" to a full path.

src/version.c

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -755,6 +755,8 @@ static char *(features[]) =
755755

756756
static int included_patches[] =
757757
{ /* Add new patch number below this line */
758+
/**/
759+
3070,
758760
/**/
759761
3069,
760762
/**/

0 commit comments

Comments
 (0)