annotate src/testdir/test_shell.vim @ 25082:5c7a09cf97a1 v8.2.3078

patch 8.2.3078: Vim9: profile test fails Commit: https://github.com/vim/vim/commit/834193afd7195bc96026d2aed696d64f8075cd35 Author: Bram Moolenaar <Bram@vim.org> Date: Wed Jun 30 20:39:15 2021 +0200 patch 8.2.3078: Vim9: profile test fails Problem: Vim9: profile test fails. Solution: Make throw in :catch jump to :finally.
author Bram Moolenaar <Bram@vim.org>
date Wed, 30 Jun 2021 20:45:04 +0200
parents 0ce24f734615
children beff72446e2e
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
25048
82ae6fcd86c8 patch 8.2.3061: testing the shell option is incomplete and spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1 " Test for the shell related options ('shell', 'shellcmdflag', 'shellpipe',
82ae6fcd86c8 patch 8.2.3061: testing the shell option is incomplete and spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2 " 'shellquote', 'shellredir', 'shellxescape', and 'shellxquote')
82ae6fcd86c8 patch 8.2.3061: testing the shell option is incomplete and spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
3
82ae6fcd86c8 patch 8.2.3061: testing the shell option is incomplete and spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
4 source check.vim
82ae6fcd86c8 patch 8.2.3061: testing the shell option is incomplete and spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
5 source shared.vim
82ae6fcd86c8 patch 8.2.3061: testing the shell option is incomplete and spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
6
82ae6fcd86c8 patch 8.2.3061: testing the shell option is incomplete and spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
7 func Test_shell_options()
25066
4c366bbf6073 patch 8.2.3070: not enough testing for shell use
Bram Moolenaar <Bram@vim.org>
parents: 25048
diff changeset
8 " The expected value of 'shellcmdflag', 'shellpipe', 'shellquote',
4c366bbf6073 patch 8.2.3070: not enough testing for shell use
Bram Moolenaar <Bram@vim.org>
parents: 25048
diff changeset
9 " 'shellredir', 'shellxescape', 'shellxquote' for the supported shells.
25048
82ae6fcd86c8 patch 8.2.3061: testing the shell option is incomplete and spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
10 let shells = []
82ae6fcd86c8 patch 8.2.3061: testing the shell option is incomplete and spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
11 if has('unix')
82ae6fcd86c8 patch 8.2.3061: testing the shell option is incomplete and spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
12 let shells += [['sh', '-c', '2>&1| tee', '', '>%s 2>&1', '', ''],
82ae6fcd86c8 patch 8.2.3061: testing the shell option is incomplete and spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
13 \ ['ksh', '-c', '2>&1| tee', '', '>%s 2>&1', '', ''],
82ae6fcd86c8 patch 8.2.3061: testing the shell option is incomplete and spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
14 \ ['mksh', '-c', '2>&1| tee', '', '>%s 2>&1', '', ''],
82ae6fcd86c8 patch 8.2.3061: testing the shell option is incomplete and spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
15 \ ['zsh', '-c', '2>&1| tee', '', '>%s 2>&1', '', ''],
82ae6fcd86c8 patch 8.2.3061: testing the shell option is incomplete and spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
16 \ ['zsh-beta', '-c', '2>&1| tee', '', '>%s 2>&1', '', ''],
82ae6fcd86c8 patch 8.2.3061: testing the shell option is incomplete and spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
17 \ ['bash', '-c', '2>&1| tee', '', '>%s 2>&1', '', ''],
82ae6fcd86c8 patch 8.2.3061: testing the shell option is incomplete and spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
18 \ ['fish', '-c', '2>&1| tee', '', '>%s 2>&1', '', ''],
82ae6fcd86c8 patch 8.2.3061: testing the shell option is incomplete and spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
19 \ ['ash', '-c', '2>&1| tee', '', '>%s 2>&1', '', ''],
82ae6fcd86c8 patch 8.2.3061: testing the shell option is incomplete and spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
20 \ ['dash', '-c', '2>&1| tee', '', '>%s 2>&1', '', ''],
82ae6fcd86c8 patch 8.2.3061: testing the shell option is incomplete and spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
21 \ ['csh', '-c', '|& tee', '', '>&', '', ''],
82ae6fcd86c8 patch 8.2.3061: testing the shell option is incomplete and spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
22 \ ['tcsh', '-c', '|& tee', '', '>&', '', '']]
82ae6fcd86c8 patch 8.2.3061: testing the shell option is incomplete and spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
23 endif
82ae6fcd86c8 patch 8.2.3061: testing the shell option is incomplete and spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
24 if has('win32')
82ae6fcd86c8 patch 8.2.3061: testing the shell option is incomplete and spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
25 let shells += [['cmd', '/c', '>%s 2>&1', '', '>%s 2>&1', '"&|<>()@^', ''],
82ae6fcd86c8 patch 8.2.3061: testing the shell option is incomplete and spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
26 \ ['cmd.exe', '/c', '>%s 2>&1', '', '>%s 2>&1', '"&|<>()@^', '('],
25068
0ce24f734615 patch 8.2.3071: shell options are not set properly for PowerShell
Bram Moolenaar <Bram@vim.org>
parents: 25066
diff changeset
27 \ ['powershell.exe', '-Command', '2>&1 | Out-File -Encoding default',
0ce24f734615 patch 8.2.3071: shell options are not set properly for PowerShell
Bram Moolenaar <Bram@vim.org>
parents: 25066
diff changeset
28 \ '', '2>&1 | Out-File -Encoding default', '"&|<>()@^', '"'],
0ce24f734615 patch 8.2.3071: shell options are not set properly for PowerShell
Bram Moolenaar <Bram@vim.org>
parents: 25066
diff changeset
29 \ ['powershell', '-Command', '2>&1 | Out-File -Encoding default', '',
0ce24f734615 patch 8.2.3071: shell options are not set properly for PowerShell
Bram Moolenaar <Bram@vim.org>
parents: 25066
diff changeset
30 \ '2>&1 | Out-File -Encoding default', '"&|<>()@^', '"'],
25048
82ae6fcd86c8 patch 8.2.3061: testing the shell option is incomplete and spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
31 \ ['sh.exe', '-c', '>%s 2>&1', '', '>%s 2>&1', '"&|<>()@^', '"'],
82ae6fcd86c8 patch 8.2.3061: testing the shell option is incomplete and spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
32 \ ['ksh.exe', '-c', '>%s 2>&1', '', '>%s 2>&1', '"&|<>()@^', '"'],
82ae6fcd86c8 patch 8.2.3061: testing the shell option is incomplete and spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
33 \ ['mksh.exe', '-c', '>%s 2>&1', '', '>%s 2>&1', '"&|<>()@^', '"'],
82ae6fcd86c8 patch 8.2.3061: testing the shell option is incomplete and spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
34 \ ['pdksh.exe', '-c', '>%s 2>&1', '', '>%s 2>&1', '"&|<>()@^', '"'],
82ae6fcd86c8 patch 8.2.3061: testing the shell option is incomplete and spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
35 \ ['zsh.exe', '-c', '>%s 2>&1', '', '>%s 2>&1', '"&|<>()@^', '"'],
82ae6fcd86c8 patch 8.2.3061: testing the shell option is incomplete and spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
36 \ ['zsh-beta.exe', '-c', '>%s 2>&1', '', '>%s 2>&1', '"&|<>()@^', '"'],
82ae6fcd86c8 patch 8.2.3061: testing the shell option is incomplete and spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
37 \ ['bash.exe', '-c', '>%s 2>&1', '', '>%s 2>&1', '"&|<>()@^', '"'],
82ae6fcd86c8 patch 8.2.3061: testing the shell option is incomplete and spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
38 \ ['dash.exe', '-c', '>%s 2>&1', '', '>%s 2>&1', '"&|<>()@^', '"'],
82ae6fcd86c8 patch 8.2.3061: testing the shell option is incomplete and spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
39 \ ['csh.exe', '-c', '>&', '', '>&', '"&|<>()@^', '"'],
82ae6fcd86c8 patch 8.2.3061: testing the shell option is incomplete and spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
40 \ ['tcsh.exe', '-c', '>&', '', '>&', '"&|<>()@^', '"']]
82ae6fcd86c8 patch 8.2.3061: testing the shell option is incomplete and spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
41 endif
82ae6fcd86c8 patch 8.2.3061: testing the shell option is incomplete and spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
42
25066
4c366bbf6073 patch 8.2.3070: not enough testing for shell use
Bram Moolenaar <Bram@vim.org>
parents: 25048
diff changeset
43 " start a new Vim instance with 'shell' set to each of the supported shells
4c366bbf6073 patch 8.2.3070: not enough testing for shell use
Bram Moolenaar <Bram@vim.org>
parents: 25048
diff changeset
44 " and check the default shell option settings
25048
82ae6fcd86c8 patch 8.2.3061: testing the shell option is incomplete and spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
45 let after =<< trim END
82ae6fcd86c8 patch 8.2.3061: testing the shell option is incomplete and spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
46 let l = [&shell, &shellcmdflag, &shellpipe, &shellquote]
82ae6fcd86c8 patch 8.2.3061: testing the shell option is incomplete and spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
47 let l += [&shellredir, &shellxescape, &shellxquote]
82ae6fcd86c8 patch 8.2.3061: testing the shell option is incomplete and spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
48 call writefile([json_encode(l)], 'Xtestout')
82ae6fcd86c8 patch 8.2.3061: testing the shell option is incomplete and spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
49 qall!
82ae6fcd86c8 patch 8.2.3061: testing the shell option is incomplete and spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
50 END
82ae6fcd86c8 patch 8.2.3061: testing the shell option is incomplete and spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
51 for e in shells
82ae6fcd86c8 patch 8.2.3061: testing the shell option is incomplete and spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
52 if RunVim([], after, '--cmd "set shell=' .. e[0] .. '"')
82ae6fcd86c8 patch 8.2.3061: testing the shell option is incomplete and spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
53 call assert_equal(e, json_decode(readfile('Xtestout')[0]))
82ae6fcd86c8 patch 8.2.3061: testing the shell option is incomplete and spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
54 endif
82ae6fcd86c8 patch 8.2.3061: testing the shell option is incomplete and spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
55 endfor
82ae6fcd86c8 patch 8.2.3061: testing the shell option is incomplete and spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
56
25066
4c366bbf6073 patch 8.2.3070: not enough testing for shell use
Bram Moolenaar <Bram@vim.org>
parents: 25048
diff changeset
57 " Test shellescape() for each of the shells.
25048
82ae6fcd86c8 patch 8.2.3061: testing the shell option is incomplete and spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
58 for e in shells
82ae6fcd86c8 patch 8.2.3061: testing the shell option is incomplete and spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
59 exe 'set shell=' .. e[0]
82ae6fcd86c8 patch 8.2.3061: testing the shell option is incomplete and spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
60 if e[0] =~# '.*csh$' || e[0] =~# '.*csh.exe$'
82ae6fcd86c8 patch 8.2.3061: testing the shell option is incomplete and spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
61 let str1 = "'cmd \"arg1\" '\\''arg2'\\'' \\!%#'"
82ae6fcd86c8 patch 8.2.3061: testing the shell option is incomplete and spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
62 let str2 = "'cmd \"arg1\" '\\''arg2'\\'' \\\\!\\%\\#'"
25068
0ce24f734615 patch 8.2.3071: shell options are not set properly for PowerShell
Bram Moolenaar <Bram@vim.org>
parents: 25066
diff changeset
63 elseif e[0] =~# '.*powershell$' || e[0] =~# '.*powershell.exe$'
0ce24f734615 patch 8.2.3071: shell options are not set properly for PowerShell
Bram Moolenaar <Bram@vim.org>
parents: 25066
diff changeset
64 let str1 = "'cmd \"arg1\" ''arg2'' !%#'"
0ce24f734615 patch 8.2.3071: shell options are not set properly for PowerShell
Bram Moolenaar <Bram@vim.org>
parents: 25066
diff changeset
65 let str2 = "'cmd \"arg1\" ''arg2'' \\!\\%\\#'"
25048
82ae6fcd86c8 patch 8.2.3061: testing the shell option is incomplete and spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
66 else
82ae6fcd86c8 patch 8.2.3061: testing the shell option is incomplete and spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
67 let str1 = "'cmd \"arg1\" '\\''arg2'\\'' !%#'"
82ae6fcd86c8 patch 8.2.3061: testing the shell option is incomplete and spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
68 let str2 = "'cmd \"arg1\" '\\''arg2'\\'' \\!\\%\\#'"
82ae6fcd86c8 patch 8.2.3061: testing the shell option is incomplete and spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
69 endif
82ae6fcd86c8 patch 8.2.3061: testing the shell option is incomplete and spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
70 call assert_equal(str1, shellescape("cmd \"arg1\" 'arg2' !%#"), e[0])
82ae6fcd86c8 patch 8.2.3061: testing the shell option is incomplete and spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
71 call assert_equal(str2, shellescape("cmd \"arg1\" 'arg2' !%#", 1), e[0])
25066
4c366bbf6073 patch 8.2.3070: not enough testing for shell use
Bram Moolenaar <Bram@vim.org>
parents: 25048
diff changeset
72
4c366bbf6073 patch 8.2.3070: not enough testing for shell use
Bram Moolenaar <Bram@vim.org>
parents: 25048
diff changeset
73 " Try running an external command with the shell.
4c366bbf6073 patch 8.2.3070: not enough testing for shell use
Bram Moolenaar <Bram@vim.org>
parents: 25048
diff changeset
74 if executable(e[0])
4c366bbf6073 patch 8.2.3070: not enough testing for shell use
Bram Moolenaar <Bram@vim.org>
parents: 25048
diff changeset
75 " set the shell options for the current 'shell'
4c366bbf6073 patch 8.2.3070: not enough testing for shell use
Bram Moolenaar <Bram@vim.org>
parents: 25048
diff changeset
76 let [&shellcmdflag, &shellpipe, &shellquote, &shellredir,
4c366bbf6073 patch 8.2.3070: not enough testing for shell use
Bram Moolenaar <Bram@vim.org>
parents: 25048
diff changeset
77 \ &shellxescape, &shellxquote] = e[1:6]
4c366bbf6073 patch 8.2.3070: not enough testing for shell use
Bram Moolenaar <Bram@vim.org>
parents: 25048
diff changeset
78 new
4c366bbf6073 patch 8.2.3070: not enough testing for shell use
Bram Moolenaar <Bram@vim.org>
parents: 25048
diff changeset
79 r !echo hello
4c366bbf6073 patch 8.2.3070: not enough testing for shell use
Bram Moolenaar <Bram@vim.org>
parents: 25048
diff changeset
80 call assert_equal('hello', substitute(getline(2), '\W', '', 'g'), e[0])
4c366bbf6073 patch 8.2.3070: not enough testing for shell use
Bram Moolenaar <Bram@vim.org>
parents: 25048
diff changeset
81 bwipe!
4c366bbf6073 patch 8.2.3070: not enough testing for shell use
Bram Moolenaar <Bram@vim.org>
parents: 25048
diff changeset
82 endif
25048
82ae6fcd86c8 patch 8.2.3061: testing the shell option is incomplete and spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
83 endfor
25066
4c366bbf6073 patch 8.2.3070: not enough testing for shell use
Bram Moolenaar <Bram@vim.org>
parents: 25048
diff changeset
84 set shell& shellcmdflag& shellpipe& shellquote&
4c366bbf6073 patch 8.2.3070: not enough testing for shell use
Bram Moolenaar <Bram@vim.org>
parents: 25048
diff changeset
85 set shellredir& shellxescape& shellxquote&
25048
82ae6fcd86c8 patch 8.2.3061: testing the shell option is incomplete and spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
86 call delete('Xtestout')
82ae6fcd86c8 patch 8.2.3061: testing the shell option is incomplete and spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
87 endfunc
82ae6fcd86c8 patch 8.2.3061: testing the shell option is incomplete and spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
88
82ae6fcd86c8 patch 8.2.3061: testing the shell option is incomplete and spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
89 " Test for the 'shell' option
82ae6fcd86c8 patch 8.2.3061: testing the shell option is incomplete and spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
90 func Test_shell()
82ae6fcd86c8 patch 8.2.3061: testing the shell option is incomplete and spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
91 CheckUnix
82ae6fcd86c8 patch 8.2.3061: testing the shell option is incomplete and spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
92 let save_shell = &shell
82ae6fcd86c8 patch 8.2.3061: testing the shell option is incomplete and spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
93 set shell=
82ae6fcd86c8 patch 8.2.3061: testing the shell option is incomplete and spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
94 let caught_e91 = 0
82ae6fcd86c8 patch 8.2.3061: testing the shell option is incomplete and spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
95 try
82ae6fcd86c8 patch 8.2.3061: testing the shell option is incomplete and spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
96 shell
82ae6fcd86c8 patch 8.2.3061: testing the shell option is incomplete and spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
97 catch /E91:/
82ae6fcd86c8 patch 8.2.3061: testing the shell option is incomplete and spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
98 let caught_e91 = 1
82ae6fcd86c8 patch 8.2.3061: testing the shell option is incomplete and spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
99 endtry
82ae6fcd86c8 patch 8.2.3061: testing the shell option is incomplete and spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
100 call assert_equal(1, caught_e91)
82ae6fcd86c8 patch 8.2.3061: testing the shell option is incomplete and spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
101 let &shell = save_shell
82ae6fcd86c8 patch 8.2.3061: testing the shell option is incomplete and spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
102 endfunc
82ae6fcd86c8 patch 8.2.3061: testing the shell option is incomplete and spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
103
82ae6fcd86c8 patch 8.2.3061: testing the shell option is incomplete and spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
104 " Test for the 'shellquote' option
82ae6fcd86c8 patch 8.2.3061: testing the shell option is incomplete and spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
105 func Test_shellquote()
82ae6fcd86c8 patch 8.2.3061: testing the shell option is incomplete and spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
106 CheckUnix
82ae6fcd86c8 patch 8.2.3061: testing the shell option is incomplete and spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
107 set shellquote=#
82ae6fcd86c8 patch 8.2.3061: testing the shell option is incomplete and spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
108 set verbose=20
82ae6fcd86c8 patch 8.2.3061: testing the shell option is incomplete and spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
109 redir => v
82ae6fcd86c8 patch 8.2.3061: testing the shell option is incomplete and spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
110 silent! !echo Hello
82ae6fcd86c8 patch 8.2.3061: testing the shell option is incomplete and spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
111 redir END
82ae6fcd86c8 patch 8.2.3061: testing the shell option is incomplete and spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
112 set verbose&
82ae6fcd86c8 patch 8.2.3061: testing the shell option is incomplete and spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
113 set shellquote&
82ae6fcd86c8 patch 8.2.3061: testing the shell option is incomplete and spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
114 call assert_match(': "#echo Hello#"', v)
82ae6fcd86c8 patch 8.2.3061: testing the shell option is incomplete and spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
115 endfunc
82ae6fcd86c8 patch 8.2.3061: testing the shell option is incomplete and spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
116
25066
4c366bbf6073 patch 8.2.3070: not enough testing for shell use
Bram Moolenaar <Bram@vim.org>
parents: 25048
diff changeset
117 " Test for the 'shellescape' option
25048
82ae6fcd86c8 patch 8.2.3061: testing the shell option is incomplete and spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
118 func Test_shellescape()
82ae6fcd86c8 patch 8.2.3061: testing the shell option is incomplete and spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
119 let save_shell = &shell
82ae6fcd86c8 patch 8.2.3061: testing the shell option is incomplete and spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
120 set shell=bash
82ae6fcd86c8 patch 8.2.3061: testing the shell option is incomplete and spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
121 call assert_equal("'text'", shellescape('text'))
82ae6fcd86c8 patch 8.2.3061: testing the shell option is incomplete and spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
122 call assert_equal("'te\"xt'", 'te"xt'->shellescape())
82ae6fcd86c8 patch 8.2.3061: testing the shell option is incomplete and spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
123 call assert_equal("'te'\\''xt'", shellescape("te'xt"))
82ae6fcd86c8 patch 8.2.3061: testing the shell option is incomplete and spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
124
82ae6fcd86c8 patch 8.2.3061: testing the shell option is incomplete and spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
125 call assert_equal("'te%xt'", shellescape("te%xt"))
82ae6fcd86c8 patch 8.2.3061: testing the shell option is incomplete and spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
126 call assert_equal("'te\\%xt'", shellescape("te%xt", 1))
82ae6fcd86c8 patch 8.2.3061: testing the shell option is incomplete and spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
127 call assert_equal("'te#xt'", shellescape("te#xt"))
82ae6fcd86c8 patch 8.2.3061: testing the shell option is incomplete and spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
128 call assert_equal("'te\\#xt'", shellescape("te#xt", 1))
82ae6fcd86c8 patch 8.2.3061: testing the shell option is incomplete and spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
129 call assert_equal("'te!xt'", shellescape("te!xt"))
82ae6fcd86c8 patch 8.2.3061: testing the shell option is incomplete and spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
130 call assert_equal("'te\\!xt'", shellescape("te!xt", 1))
82ae6fcd86c8 patch 8.2.3061: testing the shell option is incomplete and spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
131
82ae6fcd86c8 patch 8.2.3061: testing the shell option is incomplete and spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
132 call assert_equal("'te\nxt'", shellescape("te\nxt"))
82ae6fcd86c8 patch 8.2.3061: testing the shell option is incomplete and spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
133 call assert_equal("'te\\\nxt'", shellescape("te\nxt", 1))
82ae6fcd86c8 patch 8.2.3061: testing the shell option is incomplete and spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
134 set shell=tcsh
82ae6fcd86c8 patch 8.2.3061: testing the shell option is incomplete and spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
135 call assert_equal("'te\\!xt'", shellescape("te!xt"))
82ae6fcd86c8 patch 8.2.3061: testing the shell option is incomplete and spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
136 call assert_equal("'te\\\\!xt'", shellescape("te!xt", 1))
82ae6fcd86c8 patch 8.2.3061: testing the shell option is incomplete and spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
137 call assert_equal("'te\\\nxt'", shellescape("te\nxt"))
82ae6fcd86c8 patch 8.2.3061: testing the shell option is incomplete and spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
138 call assert_equal("'te\\\\\nxt'", shellescape("te\nxt", 1))
82ae6fcd86c8 patch 8.2.3061: testing the shell option is incomplete and spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
139
82ae6fcd86c8 patch 8.2.3061: testing the shell option is incomplete and spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
140 let &shell = save_shell
82ae6fcd86c8 patch 8.2.3061: testing the shell option is incomplete and spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
141 endfunc
82ae6fcd86c8 patch 8.2.3061: testing the shell option is incomplete and spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
142
25068
0ce24f734615 patch 8.2.3071: shell options are not set properly for PowerShell
Bram Moolenaar <Bram@vim.org>
parents: 25066
diff changeset
143 " Test for 'shellslash'
0ce24f734615 patch 8.2.3071: shell options are not set properly for PowerShell
Bram Moolenaar <Bram@vim.org>
parents: 25066
diff changeset
144 func Test_shellslash()
0ce24f734615 patch 8.2.3071: shell options are not set properly for PowerShell
Bram Moolenaar <Bram@vim.org>
parents: 25066
diff changeset
145 CheckOption shellslash
0ce24f734615 patch 8.2.3071: shell options are not set properly for PowerShell
Bram Moolenaar <Bram@vim.org>
parents: 25066
diff changeset
146 let save_shellslash = &shellslash
0ce24f734615 patch 8.2.3071: shell options are not set properly for PowerShell
Bram Moolenaar <Bram@vim.org>
parents: 25066
diff changeset
147 " The shell and cmdflag, and expected slash in tempname with shellslash set or
0ce24f734615 patch 8.2.3071: shell options are not set properly for PowerShell
Bram Moolenaar <Bram@vim.org>
parents: 25066
diff changeset
148 " unset. The assert checks the file separator before the leafname.
0ce24f734615 patch 8.2.3071: shell options are not set properly for PowerShell
Bram Moolenaar <Bram@vim.org>
parents: 25066
diff changeset
149 " ".*\\\\[^\\\\]*$"
0ce24f734615 patch 8.2.3071: shell options are not set properly for PowerShell
Bram Moolenaar <Bram@vim.org>
parents: 25066
diff changeset
150 let shells = [['cmd', '/c', '\\', '/'],
0ce24f734615 patch 8.2.3071: shell options are not set properly for PowerShell
Bram Moolenaar <Bram@vim.org>
parents: 25066
diff changeset
151 \ ['powershell', '-Command', '\\', '/'],
0ce24f734615 patch 8.2.3071: shell options are not set properly for PowerShell
Bram Moolenaar <Bram@vim.org>
parents: 25066
diff changeset
152 \ ['sh', '-c', '/', '/']]
0ce24f734615 patch 8.2.3071: shell options are not set properly for PowerShell
Bram Moolenaar <Bram@vim.org>
parents: 25066
diff changeset
153 for e in shells
0ce24f734615 patch 8.2.3071: shell options are not set properly for PowerShell
Bram Moolenaar <Bram@vim.org>
parents: 25066
diff changeset
154 exe 'set shell=' .. e[0] .. ' | set shellcmdflag=' .. e[1]
0ce24f734615 patch 8.2.3071: shell options are not set properly for PowerShell
Bram Moolenaar <Bram@vim.org>
parents: 25066
diff changeset
155 set noshellslash
0ce24f734615 patch 8.2.3071: shell options are not set properly for PowerShell
Bram Moolenaar <Bram@vim.org>
parents: 25066
diff changeset
156 let file = tempname()
0ce24f734615 patch 8.2.3071: shell options are not set properly for PowerShell
Bram Moolenaar <Bram@vim.org>
parents: 25066
diff changeset
157 call assert_match('^.\+' .. e[2] .. '[^' .. e[2] .. ']\+$', file, e[0] .. ' ' .. e[1] .. ' nossl')
0ce24f734615 patch 8.2.3071: shell options are not set properly for PowerShell
Bram Moolenaar <Bram@vim.org>
parents: 25066
diff changeset
158 set shellslash
0ce24f734615 patch 8.2.3071: shell options are not set properly for PowerShell
Bram Moolenaar <Bram@vim.org>
parents: 25066
diff changeset
159 let file = tempname()
0ce24f734615 patch 8.2.3071: shell options are not set properly for PowerShell
Bram Moolenaar <Bram@vim.org>
parents: 25066
diff changeset
160 call assert_match('^.\+' .. e[3] .. '[^' .. e[3] .. ']\+$', file, e[0] .. ' ' .. e[1] .. ' ssl')
0ce24f734615 patch 8.2.3071: shell options are not set properly for PowerShell
Bram Moolenaar <Bram@vim.org>
parents: 25066
diff changeset
161 endfor
0ce24f734615 patch 8.2.3071: shell options are not set properly for PowerShell
Bram Moolenaar <Bram@vim.org>
parents: 25066
diff changeset
162 let &shellslash = save_shellslash
0ce24f734615 patch 8.2.3071: shell options are not set properly for PowerShell
Bram Moolenaar <Bram@vim.org>
parents: 25066
diff changeset
163 endfunc
0ce24f734615 patch 8.2.3071: shell options are not set properly for PowerShell
Bram Moolenaar <Bram@vim.org>
parents: 25066
diff changeset
164
25048
82ae6fcd86c8 patch 8.2.3061: testing the shell option is incomplete and spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
165 " Test for 'shellxquote'
82ae6fcd86c8 patch 8.2.3061: testing the shell option is incomplete and spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
166 func Test_shellxquote()
82ae6fcd86c8 patch 8.2.3061: testing the shell option is incomplete and spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
167 CheckUnix
82ae6fcd86c8 patch 8.2.3061: testing the shell option is incomplete and spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
168
82ae6fcd86c8 patch 8.2.3061: testing the shell option is incomplete and spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
169 let save_shell = &shell
82ae6fcd86c8 patch 8.2.3061: testing the shell option is incomplete and spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
170 let save_sxq = &shellxquote
82ae6fcd86c8 patch 8.2.3061: testing the shell option is incomplete and spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
171 let save_sxe = &shellxescape
82ae6fcd86c8 patch 8.2.3061: testing the shell option is incomplete and spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
172
82ae6fcd86c8 patch 8.2.3061: testing the shell option is incomplete and spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
173 call writefile(['#!/bin/sh', 'echo "Cmd: [$*]" > Xlog'], 'Xtestshell')
82ae6fcd86c8 patch 8.2.3061: testing the shell option is incomplete and spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
174 call setfperm('Xtestshell', "r-x------")
82ae6fcd86c8 patch 8.2.3061: testing the shell option is incomplete and spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
175 set shell=./Xtestshell
82ae6fcd86c8 patch 8.2.3061: testing the shell option is incomplete and spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
176
82ae6fcd86c8 patch 8.2.3061: testing the shell option is incomplete and spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
177 set shellxquote=\\"
82ae6fcd86c8 patch 8.2.3061: testing the shell option is incomplete and spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
178 call feedkeys(":!pwd\<CR>\<CR>", 'xt')
82ae6fcd86c8 patch 8.2.3061: testing the shell option is incomplete and spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
179 call assert_equal(['Cmd: [-c "pwd"]'], readfile('Xlog'))
82ae6fcd86c8 patch 8.2.3061: testing the shell option is incomplete and spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
180
82ae6fcd86c8 patch 8.2.3061: testing the shell option is incomplete and spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
181 set shellxquote=(
82ae6fcd86c8 patch 8.2.3061: testing the shell option is incomplete and spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
182 call feedkeys(":!pwd\<CR>\<CR>", 'xt')
82ae6fcd86c8 patch 8.2.3061: testing the shell option is incomplete and spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
183 call assert_equal(['Cmd: [-c (pwd)]'], readfile('Xlog'))
82ae6fcd86c8 patch 8.2.3061: testing the shell option is incomplete and spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
184
82ae6fcd86c8 patch 8.2.3061: testing the shell option is incomplete and spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
185 set shellxquote=\\"(
82ae6fcd86c8 patch 8.2.3061: testing the shell option is incomplete and spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
186 call feedkeys(":!pwd\<CR>\<CR>", 'xt')
82ae6fcd86c8 patch 8.2.3061: testing the shell option is incomplete and spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
187 call assert_equal(['Cmd: [-c "(pwd)"]'], readfile('Xlog'))
82ae6fcd86c8 patch 8.2.3061: testing the shell option is incomplete and spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
188
82ae6fcd86c8 patch 8.2.3061: testing the shell option is incomplete and spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
189 set shellxescape=\"&<<()@^
82ae6fcd86c8 patch 8.2.3061: testing the shell option is incomplete and spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
190 set shellxquote=(
82ae6fcd86c8 patch 8.2.3061: testing the shell option is incomplete and spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
191 call feedkeys(":!pwd\"&<<{}@^\<CR>\<CR>", 'xt')
82ae6fcd86c8 patch 8.2.3061: testing the shell option is incomplete and spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
192 call assert_equal(['Cmd: [-c (pwd^"^&^<^<{}^@^^)]'], readfile('Xlog'))
82ae6fcd86c8 patch 8.2.3061: testing the shell option is incomplete and spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
193
82ae6fcd86c8 patch 8.2.3061: testing the shell option is incomplete and spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
194 let &shell = save_shell
82ae6fcd86c8 patch 8.2.3061: testing the shell option is incomplete and spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
195 let &shellxquote = save_sxq
82ae6fcd86c8 patch 8.2.3061: testing the shell option is incomplete and spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
196 let &shellxescape = save_sxe
82ae6fcd86c8 patch 8.2.3061: testing the shell option is incomplete and spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
197 call delete('Xtestshell')
82ae6fcd86c8 patch 8.2.3061: testing the shell option is incomplete and spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
198 call delete('Xlog')
82ae6fcd86c8 patch 8.2.3061: testing the shell option is incomplete and spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
199 endfunc
82ae6fcd86c8 patch 8.2.3061: testing the shell option is incomplete and spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
200
25066
4c366bbf6073 patch 8.2.3070: not enough testing for shell use
Bram Moolenaar <Bram@vim.org>
parents: 25048
diff changeset
201 " Test for using the shell set in the $SHELL environment variable
4c366bbf6073 patch 8.2.3070: not enough testing for shell use
Bram Moolenaar <Bram@vim.org>
parents: 25048
diff changeset
202 func Test_set_shell()
4c366bbf6073 patch 8.2.3070: not enough testing for shell use
Bram Moolenaar <Bram@vim.org>
parents: 25048
diff changeset
203 let after =<< trim [CODE]
4c366bbf6073 patch 8.2.3070: not enough testing for shell use
Bram Moolenaar <Bram@vim.org>
parents: 25048
diff changeset
204 call writefile([&shell], "Xtestout")
4c366bbf6073 patch 8.2.3070: not enough testing for shell use
Bram Moolenaar <Bram@vim.org>
parents: 25048
diff changeset
205 quit!
4c366bbf6073 patch 8.2.3070: not enough testing for shell use
Bram Moolenaar <Bram@vim.org>
parents: 25048
diff changeset
206 [CODE]
4c366bbf6073 patch 8.2.3070: not enough testing for shell use
Bram Moolenaar <Bram@vim.org>
parents: 25048
diff changeset
207
4c366bbf6073 patch 8.2.3070: not enough testing for shell use
Bram Moolenaar <Bram@vim.org>
parents: 25048
diff changeset
208 if has('win32')
4c366bbf6073 patch 8.2.3070: not enough testing for shell use
Bram Moolenaar <Bram@vim.org>
parents: 25048
diff changeset
209 let $SHELL = 'C:\with space\cmd.exe'
4c366bbf6073 patch 8.2.3070: not enough testing for shell use
Bram Moolenaar <Bram@vim.org>
parents: 25048
diff changeset
210 let expected = '"C:\with space\cmd.exe"'
4c366bbf6073 patch 8.2.3070: not enough testing for shell use
Bram Moolenaar <Bram@vim.org>
parents: 25048
diff changeset
211 else
4c366bbf6073 patch 8.2.3070: not enough testing for shell use
Bram Moolenaar <Bram@vim.org>
parents: 25048
diff changeset
212 let $SHELL = '/bin/with space/sh'
4c366bbf6073 patch 8.2.3070: not enough testing for shell use
Bram Moolenaar <Bram@vim.org>
parents: 25048
diff changeset
213 let expected = '/bin/with\ space/sh'
4c366bbf6073 patch 8.2.3070: not enough testing for shell use
Bram Moolenaar <Bram@vim.org>
parents: 25048
diff changeset
214 endif
4c366bbf6073 patch 8.2.3070: not enough testing for shell use
Bram Moolenaar <Bram@vim.org>
parents: 25048
diff changeset
215
4c366bbf6073 patch 8.2.3070: not enough testing for shell use
Bram Moolenaar <Bram@vim.org>
parents: 25048
diff changeset
216 if RunVimPiped([], after, '', '')
4c366bbf6073 patch 8.2.3070: not enough testing for shell use
Bram Moolenaar <Bram@vim.org>
parents: 25048
diff changeset
217 let lines = readfile('Xtestout')
4c366bbf6073 patch 8.2.3070: not enough testing for shell use
Bram Moolenaar <Bram@vim.org>
parents: 25048
diff changeset
218 call assert_equal(expected, lines[0])
4c366bbf6073 patch 8.2.3070: not enough testing for shell use
Bram Moolenaar <Bram@vim.org>
parents: 25048
diff changeset
219 endif
4c366bbf6073 patch 8.2.3070: not enough testing for shell use
Bram Moolenaar <Bram@vim.org>
parents: 25048
diff changeset
220 call delete('Xtestout')
4c366bbf6073 patch 8.2.3070: not enough testing for shell use
Bram Moolenaar <Bram@vim.org>
parents: 25048
diff changeset
221 endfunc
4c366bbf6073 patch 8.2.3070: not enough testing for shell use
Bram Moolenaar <Bram@vim.org>
parents: 25048
diff changeset
222
25048
82ae6fcd86c8 patch 8.2.3061: testing the shell option is incomplete and spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
223 " vim: shiftwidth=2 sts=2 expandtab