blob: 17ac94d695cdc439c5901cf364a1e4df3b4e9e50 [file] [log] [blame]
Bram Moolenaar66459b72016-08-06 19:01:55 +02001" Tests for startup.
Bram Moolenaarb9a46fe2016-07-29 18:13:42 +02002
Bram Moolenaar66459b72016-08-06 19:01:55 +02003source shared.vim
Bram Moolenaarc75e8122019-04-21 15:55:10 +02004source screendump.vim
Bram Moolenaarcde0ff32020-04-04 14:00:39 +02005source term_util.vim
Bram Moolenaar8c5a2782019-08-07 23:07:07 +02006source check.vim
Bram Moolenaar66459b72016-08-06 19:01:55 +02007
8" Check that loading startup.vim works.
Bram Moolenaarb9a46fe2016-07-29 18:13:42 +02009func Test_startup_script()
10 set compatible
11 source $VIMRUNTIME/defaults.vim
12
13 call assert_equal(0, &compatible)
Bram Moolenaarcde0ff32020-04-04 14:00:39 +020014 " Restore some options, so that the following tests doesn't break
15 set nomore
16 set noshowmode
Bram Moolenaarb9a46fe2016-07-29 18:13:42 +020017endfunc
Bram Moolenaar66459b72016-08-06 19:01:55 +020018
19" Verify the order in which plugins are loaded:
20" 1. plugins in non-after directories
21" 2. packages
22" 3. plugins in after directories
23func Test_after_comes_later()
Bram Moolenaar6d91bcb2020-08-12 18:50:36 +020024 CheckFeature packages
Bram Moolenaarc79745a2019-05-20 22:12:34 +020025 let before =<< trim [CODE]
26 set nocp viminfo+=nviminfo
27 set guioptions+=M
28 let $HOME = "/does/not/exist"
29 set loadplugins
30 set rtp=Xhere,Xafter,Xanother
31 set packpath=Xhere,Xafter
32 set nomore
33 let g:sequence = ""
34 [CODE]
35
36 let after =<< trim [CODE]
37 redir! > Xtestout
38 scriptnames
39 redir END
40 redir! > Xsequence
41 echo g:sequence
42 redir END
43 quit
44 [CODE]
45
Bram Moolenaar66459b72016-08-06 19:01:55 +020046 call mkdir('Xhere/plugin', 'p')
Bram Moolenaar07ecfa62017-06-27 14:43:55 +020047 call writefile(['let g:sequence .= "here "'], 'Xhere/plugin/here.vim')
48 call mkdir('Xanother/plugin', 'p')
49 call writefile(['let g:sequence .= "another "'], 'Xanother/plugin/another.vim')
Bram Moolenaar66459b72016-08-06 19:01:55 +020050 call mkdir('Xhere/pack/foo/start/foobar/plugin', 'p')
Bram Moolenaar07ecfa62017-06-27 14:43:55 +020051 call writefile(['let g:sequence .= "pack "'], 'Xhere/pack/foo/start/foobar/plugin/foo.vim')
Bram Moolenaar66459b72016-08-06 19:01:55 +020052
53 call mkdir('Xafter/plugin', 'p')
Bram Moolenaar07ecfa62017-06-27 14:43:55 +020054 call writefile(['let g:sequence .= "after "'], 'Xafter/plugin/later.vim')
Bram Moolenaar66459b72016-08-06 19:01:55 +020055
Bram Moolenaar472a0a82016-08-06 22:31:42 +020056 if RunVim(before, after, '')
Bram Moolenaar66459b72016-08-06 19:01:55 +020057
Bram Moolenaar83b3c3d2016-08-06 19:16:43 +020058 let lines = readfile('Xtestout')
Bram Moolenaar07ecfa62017-06-27 14:43:55 +020059 let expected = ['Xbefore.vim', 'here.vim', 'another.vim', 'foo.vim', 'later.vim', 'Xafter.vim']
Bram Moolenaar83b3c3d2016-08-06 19:16:43 +020060 let found = []
61 for line in lines
62 for one in expected
63 if line =~ one
64 call add(found, one)
65 endif
66 endfor
Bram Moolenaar66459b72016-08-06 19:01:55 +020067 endfor
Bram Moolenaar83b3c3d2016-08-06 19:16:43 +020068 call assert_equal(expected, found)
69 endif
Bram Moolenaar66459b72016-08-06 19:01:55 +020070
Bram Moolenaar07ecfa62017-06-27 14:43:55 +020071 call assert_equal('here another pack after', substitute(join(readfile('Xsequence', 1), ''), '\s\+$', '', ''))
72
Bram Moolenaar66459b72016-08-06 19:01:55 +020073 call delete('Xtestout')
Bram Moolenaar07ecfa62017-06-27 14:43:55 +020074 call delete('Xsequence')
Bram Moolenaar66459b72016-08-06 19:01:55 +020075 call delete('Xhere', 'rf')
Bram Moolenaar07ecfa62017-06-27 14:43:55 +020076 call delete('Xanother', 'rf')
Bram Moolenaar66459b72016-08-06 19:01:55 +020077 call delete('Xafter', 'rf')
78endfunc
Bram Moolenaar472a0a82016-08-06 22:31:42 +020079
Bram Moolenaarce876aa2017-06-04 17:47:42 +020080func Test_pack_in_rtp_when_plugins_run()
Bram Moolenaar6d91bcb2020-08-12 18:50:36 +020081 CheckFeature packages
Bram Moolenaarc79745a2019-05-20 22:12:34 +020082 let before =<< trim [CODE]
83 set nocp viminfo+=nviminfo
84 set guioptions+=M
85 let $HOME = "/does/not/exist"
86 set loadplugins
87 set rtp=Xhere
88 set packpath=Xhere
89 set nomore
90 [CODE]
91
Bram Moolenaarce876aa2017-06-04 17:47:42 +020092 let after = [
93 \ 'quit',
94 \ ]
95 call mkdir('Xhere/plugin', 'p')
96 call writefile(['redir! > Xtestout', 'silent set runtimepath?', 'silent! call foo#Trigger()', 'redir END'], 'Xhere/plugin/here.vim')
97 call mkdir('Xhere/pack/foo/start/foobar/autoload', 'p')
98 call writefile(['function! foo#Trigger()', 'echo "autoloaded foo"', 'endfunction'], 'Xhere/pack/foo/start/foobar/autoload/foo.vim')
99
100 if RunVim(before, after, '')
101
102 let lines = filter(readfile('Xtestout'), '!empty(v:val)')
103 call assert_match('Xhere[/\\]pack[/\\]foo[/\\]start[/\\]foobar', get(lines, 0))
104 call assert_match('autoloaded foo', get(lines, 1))
105 endif
106
107 call delete('Xtestout')
108 call delete('Xhere', 'rf')
109endfunc
110
Bram Moolenaar472a0a82016-08-06 22:31:42 +0200111func Test_help_arg()
Bram Moolenaarf8c52e82021-03-17 12:27:23 +0100112 " This does not work with a GUI-only binary, such as on MS-Windows.
113 CheckAnyOf Unix NotGui
Bram Moolenaar240309c2021-03-14 16:20:37 +0100114
Bram Moolenaar472a0a82016-08-06 22:31:42 +0200115 if RunVim([], [], '--help >Xtestout')
116 let lines = readfile('Xtestout')
117 call assert_true(len(lines) > 20)
Bram Moolenaarba98bef2016-08-07 15:51:39 +0200118 call assert_match('Vi IMproved', lines[0])
Bram Moolenaar472a0a82016-08-06 22:31:42 +0200119
120 " check if couple of lines are there
Bram Moolenaar50fa8dd2016-08-09 22:58:21 +0200121 let found = []
Bram Moolenaar472a0a82016-08-06 22:31:42 +0200122 for line in lines
123 if line =~ '-R.*Readonly mode'
Bram Moolenaar50fa8dd2016-08-09 22:58:21 +0200124 call add(found, 'Readonly mode')
Bram Moolenaar472a0a82016-08-06 22:31:42 +0200125 endif
Bram Moolenaar50fa8dd2016-08-09 22:58:21 +0200126 " Watch out for a second --version line in the Gnome version.
127 if line =~ '--version.*Print version information and exit'
128 call add(found, "--version")
Bram Moolenaar472a0a82016-08-06 22:31:42 +0200129 endif
130 endfor
Bram Moolenaar50fa8dd2016-08-09 22:58:21 +0200131 call assert_equal(['Readonly mode', '--version'], found)
Bram Moolenaar472a0a82016-08-06 22:31:42 +0200132 endif
133 call delete('Xtestout')
134endfunc
Bram Moolenaarba98bef2016-08-07 15:51:39 +0200135
136func Test_compatible_args()
Bram Moolenaarc79745a2019-05-20 22:12:34 +0200137 let after =<< trim [CODE]
138 call writefile([string(&compatible)], "Xtestout")
139 set viminfo+=nviminfo
140 quit
141 [CODE]
142
Bram Moolenaarba98bef2016-08-07 15:51:39 +0200143 if RunVim([], after, '-C')
144 let lines = readfile('Xtestout')
145 call assert_equal('1', lines[0])
146 endif
147
148 if RunVim([], after, '-N')
149 let lines = readfile('Xtestout')
150 call assert_equal('0', lines[0])
151 endif
152
153 call delete('Xtestout')
154endfunc
155
Bram Moolenaar8f4499b2018-09-16 16:28:11 +0200156" Test the -o[N] and -O[N] arguments to open N windows split
157" horizontally or vertically.
158func Test_o_arg()
Bram Moolenaarc79745a2019-05-20 22:12:34 +0200159 let after =<< trim [CODE]
Bram Moolenaare96a2492019-06-25 04:12:16 +0200160 set cpo&vim
Bram Moolenaarc79745a2019-05-20 22:12:34 +0200161 call writefile([winnr("$"),
162 \ winheight(1), winheight(2), &lines,
163 \ winwidth(1), winwidth(2), &columns,
164 \ bufname(winbufnr(1)), bufname(winbufnr(2))],
165 \ "Xtestout")
166 qall
167 [CODE]
168
Bram Moolenaar8f4499b2018-09-16 16:28:11 +0200169 if RunVim([], after, '-o2')
170 " Open 2 windows split horizontally. Expect:
171 " - 2 windows
172 " - both windows should have the same or almost the same height
173 " - sum of both windows height (+ 3 for both statusline and Ex command)
174 " should be equal to the number of lines
175 " - both windows should have the same width which should be equal to the
176 " number of columns
177 " - buffer of both windows should have no name
178 let [wn, wh1, wh2, ln, ww1, ww2, cn, bn1, bn2] = readfile('Xtestout')
179 call assert_equal('2', wn)
180 call assert_inrange(0, 1, wh1 - wh2)
181 call assert_equal(string(wh1 + wh2 + 3), ln)
182 call assert_equal(ww1, ww2)
183 call assert_equal(ww1, cn)
184 call assert_equal('', bn1)
185 call assert_equal('', bn2)
186 endif
187
188 if RunVim([], after, '-o foo bar')
189 " Same expectations as for -o2 but buffer names should be foo and bar
190 let [wn, wh1, wh2, ln, ww1, ww2, cn, bn1, bn2] = readfile('Xtestout')
191 call assert_equal('2', wn)
192 call assert_inrange(0, 1, wh1 - wh2)
193 call assert_equal(string(wh1 + wh2 + 3), ln)
194 call assert_equal(ww1, ww2)
195 call assert_equal(ww1, cn)
196 call assert_equal('foo', bn1)
197 call assert_equal('bar', bn2)
198 endif
199
200 if RunVim([], after, '-O2')
201 " Open 2 windows split vertically. Expect:
202 " - 2 windows
203 " - both windows should have the same or almost the same width
Bram Moolenaar036b09c2018-09-21 12:54:06 +0200204 " - sum of both windows width (+ 1 for the separator) should be equal to
205 " the number of columns
Bram Moolenaar8f4499b2018-09-16 16:28:11 +0200206 " - both windows should have the same height
207 " - window height (+ 2 for the statusline and Ex command) should be equal
208 " to the number of lines
Bram Moolenaar9e81db92018-09-18 22:37:31 +0200209 " - buffer of both windows should have no name
Bram Moolenaar8f4499b2018-09-16 16:28:11 +0200210 let [wn, wh1, wh2, ln, ww1, ww2, cn, bn1, bn2] = readfile('Xtestout')
211 call assert_equal('2', wn)
212 call assert_inrange(0, 1, ww1 - ww2)
213 call assert_equal(string(ww1 + ww2 + 1), cn)
214 call assert_equal(wh1, wh2)
215 call assert_equal(string(wh1 + 2), ln)
216 call assert_equal('', bn1)
217 call assert_equal('', bn2)
218 endif
219
220 if RunVim([], after, '-O foo bar')
221 " Same expectations as for -O2 but buffer names should be foo and bar
222 let [wn, wh1, wh2, ln, ww1, ww2, cn, bn1, bn2] = readfile('Xtestout')
223 call assert_equal('2', wn)
224 call assert_inrange(0, 1, ww1 - ww2)
225 call assert_equal(string(ww1 + ww2 + 1), cn)
226 call assert_equal(wh1, wh2)
227 call assert_equal(string(wh1 + 2), ln)
228 call assert_equal('foo', bn1)
229 call assert_equal('bar', bn2)
230 endif
231
232 call delete('Xtestout')
233endfunc
234
Bram Moolenaar9e81db92018-09-18 22:37:31 +0200235" Test the -p[N] argument to open N tabpages.
236func Test_p_arg()
Bram Moolenaarc79745a2019-05-20 22:12:34 +0200237 let after =<< trim [CODE]
238 call writefile(split(execute("tabs"), "\n"), "Xtestout")
239 qall
240 [CODE]
241
Bram Moolenaar9e81db92018-09-18 22:37:31 +0200242 if RunVim([], after, '-p2')
243 let lines = readfile('Xtestout')
244 call assert_equal(4, len(lines))
245 call assert_equal('Tab page 1', lines[0])
246 call assert_equal('> [No Name]', lines[1])
247 call assert_equal('Tab page 2', lines[2])
248 call assert_equal(' [No Name]', lines[3])
249 endif
250
251 if RunVim([], after, '-p foo bar')
252 let lines = readfile('Xtestout')
253 call assert_equal(4, len(lines))
254 call assert_equal('Tab page 1', lines[0])
255 call assert_equal('> foo', lines[1])
256 call assert_equal('Tab page 2', lines[2])
257 call assert_equal(' bar', lines[3])
258 endif
259
260 call delete('Xtestout')
261endfunc
262
Bram Moolenaar4b1c9a92018-09-19 21:06:31 +0200263" Test the -V[N] argument to set the 'verbose' option to [N]
Bram Moolenaar9e81db92018-09-18 22:37:31 +0200264func Test_V_arg()
Bram Moolenaar8c5a2782019-08-07 23:07:07 +0200265 " Can't catch the output of gvim.
266 CheckNotGui
267
Bram Moolenaar9e81db92018-09-18 22:37:31 +0200268 let out = system(GetVimCommand() . ' --clean -es -X -V0 -c "set verbose?" -cq')
269 call assert_equal(" verbose=0\n", out)
270
271 let out = system(GetVimCommand() . ' --clean -es -X -V2 -c "set verbose?" -cq')
Bram Moolenaar4515bcd2020-05-03 18:21:04 +0200272 call assert_match("sourcing \"$VIMRUNTIME[\\/]defaults\.vim\"\r\nline \\d\\+: sourcing \"[^\"]*runtime[\\/]filetype\.vim\".*\n", out)
Bram Moolenaar4b1c9a92018-09-19 21:06:31 +0200273 call assert_match(" verbose=2\n", out)
Bram Moolenaar9e81db92018-09-18 22:37:31 +0200274
275 let out = system(GetVimCommand() . ' --clean -es -X -V15 -c "set verbose?" -cq')
Bram Moolenaar4b1c9a92018-09-19 21:06:31 +0200276 call assert_match("sourcing \"$VIMRUNTIME[\\/]defaults\.vim\"\r\nline 1: \" The default vimrc file\..* verbose=15\n", out)
Bram Moolenaar9e81db92018-09-18 22:37:31 +0200277endfunc
278
Bram Moolenaar54948182018-12-28 18:32:56 +0100279" Test the '-q [errorfile]' argument.
280func Test_q_arg()
Bram Moolenaar5a4c3082019-12-01 15:23:11 +0100281 CheckFeature quickfix
282
Bram Moolenaar1e1f6122020-07-15 11:19:11 +0200283 let lines =<< trim END
284 /* some file with an error */
285 main() {
286 functionCall(arg; arg, arg);
287 return 666
288 }
289 END
290 call writefile(lines, 'Xbadfile.c')
291
Bram Moolenaarc79745a2019-05-20 22:12:34 +0200292 let after =<< trim [CODE]
293 call writefile([&errorfile, string(getpos("."))], "Xtestout")
294 copen
295 w >> Xtestout
296 qall
297 [CODE]
Bram Moolenaar54948182018-12-28 18:32:56 +0100298
299 " Test with default argument '-q'.
300 call assert_equal('errors.err', &errorfile)
Bram Moolenaar1e1f6122020-07-15 11:19:11 +0200301 call writefile(["Xbadfile.c:4:12: error: expected ';' before '}' token"], 'errors.err')
Bram Moolenaar54948182018-12-28 18:32:56 +0100302 if RunVim([], after, '-q')
303 let lines = readfile('Xtestout')
304 call assert_equal(['errors.err',
Bram Moolenaar1e1f6122020-07-15 11:19:11 +0200305 \ '[0, 4, 12, 0]',
306 \ "Xbadfile.c|4 col 12| error: expected ';' before '}' token"],
Bram Moolenaar54948182018-12-28 18:32:56 +0100307 \ lines)
308 endif
309 call delete('Xtestout')
310 call delete('errors.err')
311
312 " Test with explicit argument '-q Xerrors' (with space).
Bram Moolenaar1e1f6122020-07-15 11:19:11 +0200313 call writefile(["Xbadfile.c:4:12: error: expected ';' before '}' token"], 'Xerrors')
Bram Moolenaar54948182018-12-28 18:32:56 +0100314 if RunVim([], after, '-q Xerrors')
315 let lines = readfile('Xtestout')
316 call assert_equal(['Xerrors',
Bram Moolenaar1e1f6122020-07-15 11:19:11 +0200317 \ '[0, 4, 12, 0]',
318 \ "Xbadfile.c|4 col 12| error: expected ';' before '}' token"],
Bram Moolenaar54948182018-12-28 18:32:56 +0100319 \ lines)
320 endif
321 call delete('Xtestout')
322
323 " Test with explicit argument '-qXerrors' (without space).
324 if RunVim([], after, '-qXerrors')
325 let lines = readfile('Xtestout')
326 call assert_equal(['Xerrors',
Bram Moolenaar1e1f6122020-07-15 11:19:11 +0200327 \ '[0, 4, 12, 0]',
328 \ "Xbadfile.c|4 col 12| error: expected ';' before '}' token"],
Bram Moolenaar54948182018-12-28 18:32:56 +0100329 \ lines)
330 endif
331
Bram Moolenaarcde0ff32020-04-04 14:00:39 +0200332 " Test with a non-existing error file (exits with value 3)
333 let out = system(GetVimCommand() .. ' -q xyz.err')
334 call assert_equal(3, v:shell_error)
335
Bram Moolenaar1e1f6122020-07-15 11:19:11 +0200336 call delete('Xbadfile.c')
Bram Moolenaar54948182018-12-28 18:32:56 +0100337 call delete('Xtestout')
338 call delete('Xerrors')
339endfunc
340
Bram Moolenaar036b09c2018-09-21 12:54:06 +0200341" Test the -V[N]{filename} argument to set the 'verbose' option to N
342" and set 'verbosefile' to filename.
343func Test_V_file_arg()
Bram Moolenaar4841a7c2018-09-22 14:08:49 +0200344 if RunVim([], [], ' --clean -V2Xverbosefile -c "set verbose? verbosefile?" -cq')
Bram Moolenaar036b09c2018-09-21 12:54:06 +0200345 let out = join(readfile('Xverbosefile'), "\n")
346 call assert_match("sourcing \"$VIMRUNTIME[\\/]defaults\.vim\"\n", out)
347 call assert_match("\n verbose=2\n", out)
348 call assert_match("\n verbosefile=Xverbosefile", out)
349 endif
350
351 call delete('Xverbosefile')
352endfunc
353
354" Test the -m, -M and -R arguments:
355" -m resets 'write'
356" -M resets 'modifiable' and 'write'
357" -R sets 'readonly'
358func Test_m_M_R()
Bram Moolenaarc79745a2019-05-20 22:12:34 +0200359 let after =<< trim [CODE]
360 call writefile([&write, &modifiable, &readonly, &updatecount], "Xtestout")
361 qall
362 [CODE]
363
Bram Moolenaar036b09c2018-09-21 12:54:06 +0200364 if RunVim([], after, '')
365 let lines = readfile('Xtestout')
366 call assert_equal(['1', '1', '0', '200'], lines)
367 endif
368 if RunVim([], after, '-m')
369 let lines = readfile('Xtestout')
370 call assert_equal(['0', '1', '0', '200'], lines)
371 endif
372 if RunVim([], after, '-M')
373 let lines = readfile('Xtestout')
374 call assert_equal(['0', '0', '0', '200'], lines)
375 endif
376 if RunVim([], after, '-R')
377 let lines = readfile('Xtestout')
378 call assert_equal(['1', '1', '1', '10000'], lines)
379 endif
380
381 call delete('Xtestout')
382endfunc
383
Bram Moolenaar9e81db92018-09-18 22:37:31 +0200384" Test the -A, -F and -H arguments (Arabic, Farsi and Hebrew modes).
385func Test_A_F_H_arg()
Bram Moolenaarc79745a2019-05-20 22:12:34 +0200386 let after =<< trim [CODE]
387 call writefile([&rightleft, &arabic, &fkmap, &hkmap], "Xtestout")
388 qall
389 [CODE]
390
Bram Moolenaar4b1c9a92018-09-19 21:06:31 +0200391 " Use silent Ex mode to avoid the hit-Enter prompt for the warning that
392 " 'encoding' is not utf-8.
393 if has('arabic') && &encoding == 'utf-8' && RunVim([], after, '-e -s -A')
Bram Moolenaar9e81db92018-09-18 22:37:31 +0200394 let lines = readfile('Xtestout')
395 call assert_equal(['1', '1', '0', '0'], lines)
396 endif
397
398 if has('farsi') && RunVim([], after, '-F')
399 let lines = readfile('Xtestout')
400 call assert_equal(['1', '0', '1', '0'], lines)
401 endif
402
403 if has('rightleft') && RunVim([], after, '-H')
404 let lines = readfile('Xtestout')
405 call assert_equal(['1', '0', '0', '1'], lines)
406 endif
407
408 call delete('Xtestout')
409endfunc
410
Bram Moolenaar240309c2021-03-14 16:20:37 +0100411" Test the --echo-wid argument (for GTK GUI only).
412func Test_echo_wid()
413 CheckCanRunGui
414 CheckFeature gui_gtk
415
416 if RunVim([], [], '-g --echo-wid -cq >Xtest_echo_wid')
417 let lines = readfile('Xtest_echo_wid')
418 call assert_equal(1, len(lines))
419 call assert_match('^WID: \d\+$', lines[0])
420 endif
421
422 call delete('Xtest_echo_wid')
423endfunction
424
425" Test the -reverse and +reverse arguments (for GUI only).
426func Test_reverse()
427 CheckCanRunGui
Bram Moolenaarf8c52e82021-03-17 12:27:23 +0100428 CheckAnyOf Feature:gui_gtk Feature:gui_motif Feature:gui_athena
Bram Moolenaar240309c2021-03-14 16:20:37 +0100429
430 let after =<< trim [CODE]
431 call writefile([&background], "Xtest_reverse")
432 qall
433 [CODE]
434 if RunVim([], after, '-f -g -reverse')
435 let lines = readfile('Xtest_reverse')
436 call assert_equal(['dark'], lines)
437 endif
438 if RunVim([], after, '-f -g +reverse')
439 let lines = readfile('Xtest_reverse')
440 call assert_equal(['light'], lines)
441 endif
442
443 call delete('Xtest_reverse')
444endfunc
445
446" Test the -background and -foreground arguments (for GUI only).
447func Test_background_foreground()
448 CheckCanRunGui
Bram Moolenaarf8c52e82021-03-17 12:27:23 +0100449 CheckAnyOf Feature:gui_gtk Feature:gui_motif Feature:gui_athena
Bram Moolenaar240309c2021-03-14 16:20:37 +0100450
451 " Is there a better way to check the effect of -background & -foreground
452 " other than merely looking at &background (dark or light)?
453 let after =<< trim [CODE]
454 call writefile([&background], "Xtest_fg_bg")
455 qall
456 [CODE]
457 if RunVim([], after, '-f -g -background darkred -foreground yellow')
458 let lines = readfile('Xtest_fg_bg')
459 call assert_equal(['dark'], lines)
460 endif
461 if RunVim([], after, '-f -g -background ivory -foreground darkgreen')
462 let lines = readfile('Xtest_fg_bg')
463 call assert_equal(['light'], lines)
464 endif
465
466 call delete('Xtest_fg_bg')
467endfunc
468
469" Test the -font argument (for GUI only).
470func Test_font()
471 CheckCanRunGui
472 CheckNotMSWindows
473
474 if has('gui_gtk')
475 let font = 'Courier 14'
476 elseif has('gui_motif') || has('gui_athena')
477 let font = '-misc-fixed-bold-*'
478 else
479 throw 'Skipped: test does not set a valid font for this GUI'
480 endif
481
482 let after =<< trim [CODE]
483 call writefile([&guifont], "Xtest_font")
484 qall
485 [CODE]
486
487 if RunVim([], after, '--nofork -g -font "' .. font .. '"')
488 let lines = readfile('Xtest_font')
489 call assert_equal([font], lines)
490 endif
491
492 call delete('Xtest_font')
493endfunc
494
495" Test the -geometry argument (for GUI only).
496func Test_geometry()
497 CheckCanRunGui
Bram Moolenaarf8c52e82021-03-17 12:27:23 +0100498 CheckAnyOf Feature:gui_gtk Feature:gui_motif Feature:gui_athena
Bram Moolenaar240309c2021-03-14 16:20:37 +0100499
500 if has('gui_motif') || has('gui_athena')
501 " FIXME: With GUI Athena or Motif, the value of getwinposx(),
502 " getwinposy() and getwinpos() do not match exactly the
503 " value given in -geometry. Why?
504 " So only check &columns and &lines for those GUIs.
505 let after =<< trim [CODE]
506 call writefile([&columns, &lines], "Xtest_geometry")
507 qall
508 [CODE]
509 if RunVim([], after, '-f -g -geometry 31x13+41+43')
510 let lines = readfile('Xtest_geometry')
511 call assert_equal(['31', '13'], lines)
512 endif
513 else
514 let after =<< trim [CODE]
515 call writefile([&columns, &lines, getwinposx(), getwinposy(), string(getwinpos())], "Xtest_geometry")
516 qall
517 [CODE]
518 if RunVim([], after, '-f -g -geometry 31x13+41+43')
519 let lines = readfile('Xtest_geometry')
520 call assert_equal(['31', '13', '41', '43', '[41, 43]'], lines)
521 endif
522 endif
523
524 call delete('Xtest_geometry')
525endfunc
526
527" Test the -iconic argument (for GUI only).
528func Test_iconic()
529 CheckCanRunGui
Bram Moolenaarf8c52e82021-03-17 12:27:23 +0100530 CheckAnyOf Feature:gui_gtk Feature:gui_motif Feature:gui_athena
Bram Moolenaar240309c2021-03-14 16:20:37 +0100531
532 call RunVim([], [], '-f -g -iconic -cq')
533
534 " TODO: currently only start vim iconified, but does not
535 " check that vim is iconified. How could this be checked?
536endfunc
537
538
Bram Moolenaarba9ea912019-05-07 22:10:50 +0200539func Test_invalid_args()
Bram Moolenaar8c5a2782019-08-07 23:07:07 +0200540 " must be able to get the output of Vim.
541 CheckUnix
542 CheckNotGui
Bram Moolenaarba9ea912019-05-07 22:10:50 +0200543
544 for opt in ['-Y', '--does-not-exist']
545 let out = split(system(GetVimCommand() .. ' ' .. opt), "\n")
546 call assert_equal(1, v:shell_error)
547 call assert_match('^VIM - Vi IMproved .* (.*)$', out[0])
548 call assert_equal('Unknown option argument: "' .. opt .. '"', out[1])
549 call assert_equal('More info with: "vim -h"', out[2])
550 endfor
551
552 for opt in ['-c', '-i', '-s', '-t', '-T', '-u', '-U', '-w', '-W', '--cmd', '--startuptime']
553 let out = split(system(GetVimCommand() .. ' ' .. opt), "\n")
554 call assert_equal(1, v:shell_error)
555 call assert_match('^VIM - Vi IMproved .* (.*)$', out[0])
556 call assert_equal('Argument missing after: "' .. opt .. '"', out[1])
557 call assert_equal('More info with: "vim -h"', out[2])
558 endfor
559
560 if has('clientserver')
Bram Moolenaarba9ea912019-05-07 22:10:50 +0200561 for opt in ['--remote', '--remote-send', '--remote-silent', '--remote-expr',
562 \ '--remote-tab', '--remote-tab-wait',
563 \ '--remote-tab-wait-silent', '--remote-tab-silent',
564 \ '--remote-wait', '--remote-wait-silent',
Bram Moolenaar27821262019-05-08 16:41:09 +0200565 \ '--servername',
Bram Moolenaarba9ea912019-05-07 22:10:50 +0200566 \ ]
567 let out = split(system(GetVimCommand() .. ' ' .. opt), "\n")
568 call assert_equal(1, v:shell_error)
569 call assert_match('^VIM - Vi IMproved .* (.*)$', out[0])
570 call assert_equal('Argument missing after: "' .. opt .. '"', out[1])
571 call assert_equal('More info with: "vim -h"', out[2])
572 endfor
573 endif
574
Bram Moolenaar240f7ab2019-05-08 17:58:15 +0200575 if has('gui_gtk')
Bram Moolenaar27821262019-05-08 16:41:09 +0200576 let out = split(system(GetVimCommand() .. ' --display'), "\n")
577 call assert_equal(1, v:shell_error)
578 call assert_match('^VIM - Vi IMproved .* (.*)$', out[0])
579 call assert_equal('Argument missing after: "--display"', out[1])
580 call assert_equal('More info with: "vim -h"', out[2])
581 endif
Bram Moolenaarba9ea912019-05-07 22:10:50 +0200582
Bram Moolenaar5416b752019-05-08 18:36:43 +0200583 if has('xterm_clipboard')
Bram Moolenaar240f7ab2019-05-08 17:58:15 +0200584 let out = split(system(GetVimCommand() .. ' -display'), "\n")
585 call assert_equal(1, v:shell_error)
586 call assert_match('^VIM - Vi IMproved .* (.*)$', out[0])
587 call assert_equal('Argument missing after: "-display"', out[1])
588 call assert_equal('More info with: "vim -h"', out[2])
589 endif
590
Bram Moolenaarba9ea912019-05-07 22:10:50 +0200591 let out = split(system(GetVimCommand() .. ' -ix'), "\n")
592 call assert_equal(1, v:shell_error)
593 call assert_match('^VIM - Vi IMproved .* (.*)$', out[0])
594 call assert_equal('Garbage after option argument: "-ix"', out[1])
595 call assert_equal('More info with: "vim -h"', out[2])
596
597 let out = split(system(GetVimCommand() .. ' - xxx'), "\n")
598 call assert_equal(1, v:shell_error)
599 call assert_match('^VIM - Vi IMproved .* (.*)$', out[0])
600 call assert_equal('Too many edit arguments: "xxx"', out[1])
601 call assert_equal('More info with: "vim -h"', out[2])
602
Bram Moolenaar5a4c3082019-12-01 15:23:11 +0100603 if has('quickfix')
604 " Detect invalid repeated arguments '-t foo -t foo", '-q foo -q foo'.
605 for opt in ['-t', '-q']
606 let out = split(system(GetVimCommand() .. repeat(' ' .. opt .. ' foo', 2)), "\n")
607 call assert_equal(1, v:shell_error)
608 call assert_match('^VIM - Vi IMproved .* (.*)$', out[0])
609 call assert_equal('Too many edit arguments: "' .. opt .. '"', out[1])
610 call assert_equal('More info with: "vim -h"', out[2])
611 endfor
612 endif
Bram Moolenaarba9ea912019-05-07 22:10:50 +0200613
614 for opt in [' -cq', ' --cmd q', ' +', ' -S foo']
615 let out = split(system(GetVimCommand() .. repeat(opt, 11)), "\n")
616 call assert_equal(1, v:shell_error)
617 " FIXME: The error message given by Vim is not ideal in case of repeated
618 " -S foo since it does not mention -S.
619 call assert_match('^VIM - Vi IMproved .* (.*)$', out[0])
620 call assert_equal('Too many "+command", "-c command" or "--cmd command" arguments', out[1])
621 call assert_equal('More info with: "vim -h"', out[2])
622 endfor
623
Bram Moolenaar27821262019-05-08 16:41:09 +0200624 if has('gui_gtk')
625 for opt in ['--socketid x', '--socketid 0xg']
626 let out = split(system(GetVimCommand() .. ' ' .. opt), "\n")
627 call assert_equal(1, v:shell_error)
628 call assert_match('^VIM - Vi IMproved .* (.*)$', out[0])
629 call assert_equal('Invalid argument for: "--socketid"', out[1])
630 call assert_equal('More info with: "vim -h"', out[2])
631 endfor
632 endif
Bram Moolenaarba9ea912019-05-07 22:10:50 +0200633endfunc
634
Bram Moolenaarba98bef2016-08-07 15:51:39 +0200635func Test_file_args()
Bram Moolenaarc79745a2019-05-20 22:12:34 +0200636 let after =<< trim [CODE]
637 call writefile(argv(), "Xtestout")
638 qall
639 [CODE]
640
Bram Moolenaarba98bef2016-08-07 15:51:39 +0200641 if RunVim([], after, '')
642 let lines = readfile('Xtestout')
643 call assert_equal(0, len(lines))
644 endif
645
646 if RunVim([], after, 'one')
647 let lines = readfile('Xtestout')
648 call assert_equal(1, len(lines))
649 call assert_equal('one', lines[0])
650 endif
651
652 if RunVim([], after, 'one two three')
653 let lines = readfile('Xtestout')
654 call assert_equal(3, len(lines))
655 call assert_equal('one', lines[0])
656 call assert_equal('two', lines[1])
657 call assert_equal('three', lines[2])
658 endif
659
660 if RunVim([], after, 'one -c echo two')
661 let lines = readfile('Xtestout')
662 call assert_equal(2, len(lines))
663 call assert_equal('one', lines[0])
664 call assert_equal('two', lines[1])
665 endif
666
667 if RunVim([], after, 'one -- -c echo two')
668 let lines = readfile('Xtestout')
669 call assert_equal(4, len(lines))
670 call assert_equal('one', lines[0])
671 call assert_equal('-c', lines[1])
672 call assert_equal('echo', lines[2])
673 call assert_equal('two', lines[3])
674 endif
675
676 call delete('Xtestout')
677endfunc
678
679func Test_startuptime()
Bram Moolenaar6d91bcb2020-08-12 18:50:36 +0200680 CheckFeature startuptime
Bram Moolenaarba98bef2016-08-07 15:51:39 +0200681 let after = ['qall']
682 if RunVim([], after, '--startuptime Xtestout one')
683 let lines = readfile('Xtestout')
684 let expected = ['--- VIM STARTING ---', 'parsing arguments',
685 \ 'shell init', 'inits 3', 'start termcap', 'opening buffers']
686 let found = []
687 for line in lines
688 for exp in expected
689 if line =~ exp
690 call add(found, exp)
691 endif
692 endfor
693 endfor
694 call assert_equal(expected, found)
695 endif
696 call delete('Xtestout')
697endfunc
Bram Moolenaar3a938382016-08-07 16:36:40 +0200698
699func Test_read_stdin()
Bram Moolenaarc79745a2019-05-20 22:12:34 +0200700 let after =<< trim [CODE]
701 write Xtestout
702 quit!
703 [CODE]
704
Bram Moolenaar3a938382016-08-07 16:36:40 +0200705 if RunVimPiped([], after, '-', 'echo something | ')
706 let lines = readfile('Xtestout')
Bram Moolenaare4a76ad2016-08-07 16:50:10 +0200707 " MS-Windows adds a space after the word
708 call assert_equal(['something'], split(lines[0]))
Bram Moolenaar3a938382016-08-07 16:36:40 +0200709 endif
710 call delete('Xtestout')
711endfunc
Bram Moolenaar08cab962017-03-04 14:37:18 +0100712
Bram Moolenaar4bfa8af2018-02-03 15:14:46 +0100713func Test_set_shell()
Bram Moolenaarc79745a2019-05-20 22:12:34 +0200714 let after =<< trim [CODE]
715 call writefile([&shell], "Xtestout")
716 quit!
717 [CODE]
718
Bram Moolenaar2efc44b2019-10-05 12:09:32 +0200719 if has('win32')
720 let $SHELL = 'C:\with space\cmd.exe'
721 let expected = '"C:\with space\cmd.exe"'
722 else
723 let $SHELL = '/bin/with space/sh'
724 let expected = '/bin/with\ space/sh'
725 endif
726
Bram Moolenaar4bfa8af2018-02-03 15:14:46 +0100727 if RunVimPiped([], after, '', '')
728 let lines = readfile('Xtestout')
Bram Moolenaar2efc44b2019-10-05 12:09:32 +0200729 call assert_equal(expected, lines[0])
Bram Moolenaar4bfa8af2018-02-03 15:14:46 +0100730 endif
731 call delete('Xtestout')
732endfunc
733
Bram Moolenaar08cab962017-03-04 14:37:18 +0100734func Test_progpath()
735 " Tests normally run with "./vim" or "../vim", these must have been expanded
736 " to a full path.
737 if has('unix')
738 call assert_equal('/', v:progpath[0])
739 elseif has('win32')
740 call assert_equal(':', v:progpath[1])
741 call assert_match('[/\\]', v:progpath[2])
742 endif
743
744 " Only expect "vim" to appear in v:progname.
745 call assert_match('vim\c', v:progname)
746endfunc
Bram Moolenaard5d37532017-03-27 23:02:07 +0200747
748func Test_silent_ex_mode()
Bram Moolenaar8c5a2782019-08-07 23:07:07 +0200749 " must be able to get the output of Vim.
750 CheckUnix
751 CheckNotGui
Bram Moolenaard5d37532017-03-27 23:02:07 +0200752
753 " This caused an ml_get error.
754 let out = system(GetVimCommand() . '-u NONE -es -c''set verbose=1|h|exe "%norm\<c-y>\<c-d>"'' -c cq')
755 call assert_notmatch('E315:', out)
756endfunc
Bram Moolenaar85045a72017-04-02 16:54:09 +0200757
758func Test_default_term()
Bram Moolenaar8c5a2782019-08-07 23:07:07 +0200759 " must be able to get the output of Vim.
760 CheckUnix
761 CheckNotGui
Bram Moolenaar85045a72017-04-02 16:54:09 +0200762
763 let save_term = $TERM
Bram Moolenaar08f88b12017-04-02 17:21:16 +0200764 let $TERM = 'unknownxxx'
Bram Moolenaar85045a72017-04-02 16:54:09 +0200765 let out = system(GetVimCommand() . ' -c''set term'' -c cq')
766 call assert_match("defaulting to 'ansi'", out)
767 let $TERM = save_term
768endfunc
Bram Moolenaar09ca9322017-09-26 17:40:45 +0200769
770func Test_zzz_startinsert()
771 " Test :startinsert
772 call writefile(['123456'], 'Xtestout')
Bram Moolenaarc79745a2019-05-20 22:12:34 +0200773 let after =<< trim [CODE]
774 :startinsert
775 call feedkeys("foobar\<c-o>:wq\<cr>","t")
776 [CODE]
777
Bram Moolenaar09ca9322017-09-26 17:40:45 +0200778 if RunVim([], after, 'Xtestout')
779 let lines = readfile('Xtestout')
780 call assert_equal(['foobar123456'], lines)
781 endif
782 " Test :startinsert!
783 call writefile(['123456'], 'Xtestout')
Bram Moolenaarc79745a2019-05-20 22:12:34 +0200784 let after =<< trim [CODE]
785 :startinsert!
786 call feedkeys("foobar\<c-o>:wq\<cr>","t")
787 [CODE]
788
Bram Moolenaar09ca9322017-09-26 17:40:45 +0200789 if RunVim([], after, 'Xtestout')
790 let lines = readfile('Xtestout')
791 call assert_equal(['123456foobar'], lines)
792 endif
793 call delete('Xtestout')
794endfunc
Bram Moolenaar97c2c052019-02-22 13:42:07 +0100795
796func Test_issue_3969()
Bram Moolenaar8c5a2782019-08-07 23:07:07 +0200797 " Can't catch the output of gvim.
798 CheckNotGui
799
Bram Moolenaar97c2c052019-02-22 13:42:07 +0100800 " Check that message is not truncated.
801 let out = system(GetVimCommand() . ' -es -X -V1 -c "echon ''hello''" -cq')
802 call assert_equal('hello', out)
803endfunc
Bram Moolenaarc75e8122019-04-21 15:55:10 +0200804
805func Test_start_with_tabs()
Bram Moolenaar494e9062020-05-31 21:28:02 +0200806 CheckRunVimInTerminal
Bram Moolenaarc75e8122019-04-21 15:55:10 +0200807
808 let buf = RunVimInTerminal('-p a b c', {})
809 call VerifyScreenDump(buf, 'Test_start_with_tabs', {})
810
811 " clean up
812 call StopVimInTerminal(buf)
813endfunc
Bram Moolenaar69bf6342019-10-29 04:16:57 +0100814
815func Test_v_argv()
816 " Can't catch the output of gvim.
817 CheckNotGui
818
819 let out = system(GetVimCommand() . ' -es -V1 -X arg1 --cmd "echo v:argv" --cmd q')
820 let list = out->split("', '")
821 call assert_match('vim', list[0])
822 let idx = index(list, 'arg1')
823 call assert_true(idx > 2)
824 call assert_equal(['arg1', '--cmd', 'echo v:argv', '--cmd', 'q'']'], list[idx:])
825endfunc
Bram Moolenaarcde0ff32020-04-04 14:00:39 +0200826
827" Test for the "-r" recovery mode option
828func Test_r_arg()
829 " Can't catch the output of gvim.
830 CheckNotGui
831 CheckUnix
832 CheckEnglish
833 let cmd = GetVimCommand()
834 " There can be swap files anywhere, only check for the headers.
835 let expected =<< trim END
836 Swap files found:.*
837 In current directory:.*
838 In directory \~/tmp:.*
839 In directory /var/tmp:.*
840 In directory /tmp:.*
841 END
842 call assert_match(join(expected, ""), system(cmd .. " -r")->substitute("[\r\n]\\+", '', ''))
843endfunc
844
845" Test for the '-t' option to jump to a tag
846func Test_t_arg()
847 let before =<< trim [CODE]
848 set tags=Xtags
849 [CODE]
850 let after =<< trim [CODE]
851 let s = bufname('') .. ':L' .. line('.') .. 'C' .. col('.')
852 call writefile([s], "Xtestout")
853 qall
854 [CODE]
855
856 call writefile(["!_TAG_FILE_ENCODING\tutf-8\t//",
857 \ "first\tXfile1\t/^ \\zsfirst$/",
858 \ "second\tXfile1\t/^ \\zssecond$/",
859 \ "third\tXfile1\t/^ \\zsthird$/"],
860 \ 'Xtags')
861 call writefile([' first', ' second', ' third'], 'Xfile1')
862
863 if RunVim(before, after, '-t second')
864 call assert_equal(['Xfile1:L2C5'], readfile('Xtestout'))
865 call delete('Xtestout')
866 endif
867
868 call delete('Xtags')
869 call delete('Xfile1')
870endfunc
871
Bram Moolenaar1f33e0a2020-12-19 13:32:07 +0100872" Test the '-T' argument which sets the 'term' option.
873func Test_T_arg()
874 CheckNotGui
875 let after =<< trim [CODE]
876 call writefile([&term], "Xtest_T_arg")
877 qall
878 [CODE]
879
880 for t in ['builtin_dumb', 'builtin_ansi']
881 if RunVim([], after, '-T ' .. t)
882 let lines = readfile('Xtest_T_arg')
883 call assert_equal([t], lines)
884 endif
885 endfor
886
887 call delete('Xtest_T_arg')
888endfunc
889
890" Test the '-x' argument to read/write encrypted files.
891func Test_x_arg()
892 CheckRunVimInTerminal
893 CheckFeature cryptv
894
895 " Create an encrypted file Xtest_x_arg.
896 let buf = RunVimInTerminal('-n -x Xtest_x_arg', #{rows: 10, wait_for_ruler: 0})
897 call WaitForAssert({-> assert_match('^Enter encryption key: ', term_getline(buf, 10))})
898 call term_sendkeys(buf, "foo\n")
899 call WaitForAssert({-> assert_match('^Enter same key again: ', term_getline(buf, 10))})
900 call term_sendkeys(buf, "foo\n")
901 call WaitForAssert({-> assert_match(' All$', term_getline(buf, 10))})
902 call term_sendkeys(buf, "itest\<Esc>:w\<Enter>")
903 call WaitForAssert({-> assert_match('"Xtest_x_arg" \[New\]\[blowfish2\] 1L, 5B written',
904 \ term_getline(buf, 10))})
905 call StopVimInTerminal(buf)
906
907 " Read the encrypted file and check that it contains the expected content "test"
908 let buf = RunVimInTerminal('-n -x Xtest_x_arg', #{rows: 10, wait_for_ruler: 0})
909 call WaitForAssert({-> assert_match('^Enter encryption key: ', term_getline(buf, 10))})
910 call term_sendkeys(buf, "foo\n")
911 call WaitForAssert({-> assert_match('^Enter same key again: ', term_getline(buf, 10))})
912 call term_sendkeys(buf, "foo\n")
913 call WaitForAssert({-> assert_match('^test', term_getline(buf, 1))})
914 call StopVimInTerminal(buf)
915
916 call delete('Xtest_x_arg')
917endfunc
918
Bram Moolenaarcde0ff32020-04-04 14:00:39 +0200919" Test for entering the insert mode on startup
920func Test_start_insertmode()
921 let before =<< trim [CODE]
922 set insertmode
923 [CODE]
924 let after =<< trim [CODE]
925 call writefile(['insertmode=' .. &insertmode], 'Xtestout')
926 qall
927 [CODE]
928 if RunVim(before, after, '')
929 call assert_equal(['insertmode=1'], readfile('Xtestout'))
930 call delete('Xtestout')
931 endif
932endfunc
933
934" Test for enabling the binary mode on startup
935func Test_b_arg()
936 let after =<< trim [CODE]
937 call writefile(['binary=' .. &binary], 'Xtestout')
938 qall
939 [CODE]
940 if RunVim([], after, '-b')
941 call assert_equal(['binary=1'], readfile('Xtestout'))
942 call delete('Xtestout')
943 endif
944endfunc
945
946" Test for enabling the lisp mode on startup
947func Test_l_arg()
948 let after =<< trim [CODE]
949 let s = 'lisp=' .. &lisp .. ', showmatch=' .. &showmatch
950 call writefile([s], 'Xtestout')
951 qall
952 [CODE]
953 if RunVim([], after, '-l')
954 call assert_equal(['lisp=1, showmatch=1'], readfile('Xtestout'))
955 call delete('Xtestout')
956 endif
957endfunc
958
959" Test for specifying a non-existing vimrc file using "-u"
960func Test_missing_vimrc()
Bram Moolenaar494e9062020-05-31 21:28:02 +0200961 CheckRunVimInTerminal
Bram Moolenaarcde0ff32020-04-04 14:00:39 +0200962 let after =<< trim [CODE]
963 call assert_match('^E282:', v:errmsg)
964 call writefile(v:errors, 'Xtestout')
965 [CODE]
966 call writefile(after, 'Xafter')
967
968 let cmd = GetVimCommandCleanTerm() . ' -u Xvimrc_missing -S Xafter'
969 let buf = term_start(cmd, {'term_rows' : 10})
970 call WaitForAssert({-> assert_equal("running", term_getstatus(buf))})
Bram Moolenaar6a2c5a72020-04-08 21:50:25 +0200971 call TermWait(buf)
Bram Moolenaarcde0ff32020-04-04 14:00:39 +0200972 call term_sendkeys(buf, "\n:")
Bram Moolenaar6a2c5a72020-04-08 21:50:25 +0200973 call TermWait(buf)
Bram Moolenaarcde0ff32020-04-04 14:00:39 +0200974 call WaitForAssert({-> assert_match(':', term_getline(buf, 10))})
975 call StopVimInTerminal(buf)
976 call assert_equal([], readfile('Xtestout'))
977 call delete('Xafter')
978 call delete('Xtestout')
979endfunc
980
981" Test for using the $VIMINIT environment variable
982func Test_VIMINIT()
983 let after =<< trim [CODE]
984 call assert_equal(1, exists('viminit_found'))
985 call assert_equal('yes', viminit_found)
986 call writefile(v:errors, 'Xtestout')
987 qall
988 [CODE]
989 call writefile(after, 'Xafter')
990 let cmd = GetVimProg() . ' --not-a-term -S Xafter --cmd "set enc=utf8"'
991 call setenv('VIMINIT', 'let viminit_found="yes"')
992 exe "silent !" . cmd
993 call assert_equal([], readfile('Xtestout'))
994 call delete('Xtestout')
995 call delete('Xafter')
996endfunc
997
998" Test for using the $EXINIT environment variable
999func Test_EXINIT()
1000 let after =<< trim [CODE]
1001 call assert_equal(1, exists('exinit_found'))
1002 call assert_equal('yes', exinit_found)
1003 call writefile(v:errors, 'Xtestout')
1004 qall
1005 [CODE]
1006 call writefile(after, 'Xafter')
1007 let cmd = GetVimProg() . ' --not-a-term -S Xafter --cmd "set enc=utf8"'
1008 call setenv('EXINIT', 'let exinit_found="yes"')
1009 exe "silent !" . cmd
1010 call assert_equal([], readfile('Xtestout'))
1011 call delete('Xtestout')
1012 call delete('Xafter')
1013endfunc
1014
1015" Test for using the 'exrc' option
1016func Test_exrc()
1017 let after =<< trim [CODE]
1018 call assert_equal(1, &exrc)
1019 call assert_equal(1, &secure)
1020 call assert_equal(37, exrc_found)
1021 call writefile(v:errors, 'Xtestout')
1022 qall
1023 [CODE]
1024 call mkdir('Xdir')
1025 call writefile(['let exrc_found=37'], 'Xdir/.exrc')
1026 call writefile(after, 'Xdir/Xafter')
1027 let cmd = GetVimProg() . ' --not-a-term -S Xafter --cmd "cd Xdir" --cmd "set enc=utf8 exrc secure"'
1028 exe "silent !" . cmd
1029 call assert_equal([], readfile('Xdir/Xtestout'))
1030 call delete('Xdir', 'rf')
1031endfunc
1032
1033" Test for starting Vim with a non-terminal as input/output
1034func Test_io_not_a_terminal()
1035 " Can't catch the output of gvim.
1036 CheckNotGui
1037 CheckUnix
1038 CheckEnglish
1039 let l = systemlist(GetVimProg() .. ' --ttyfail')
1040 call assert_equal(['Vim: Warning: Output is not to a terminal',
1041 \ 'Vim: Warning: Input is not from a terminal'], l)
1042endfunc
1043
1044" Test for the "-w scriptout" argument
1045func Test_w_arg()
1046 " Can't catch the output of gvim.
1047 CheckNotGui
1048 call writefile(["iVim Editor\<Esc>:q!\<CR>"], 'Xscriptin', 'b')
1049 if RunVim([], [], '-s Xscriptin -w Xscriptout')
1050 call assert_equal(["iVim Editor\e:q!\r"], readfile('Xscriptout'))
1051 call delete('Xscriptout')
1052 endif
1053 call delete('Xscriptin')
1054
1055 " Test for failing to open the script output file. This test works only when
1056 " the language is English.
1057 if v:lang == "C" || v:lang =~ '^[Ee]n'
1058 call mkdir("Xdir")
1059 let m = system(GetVimCommand() .. " -w Xdir")
1060 call assert_equal("Cannot open for script output: \"Xdir\"\n", m)
1061 call delete("Xdir", 'rf')
1062 endif
1063endfunc
1064
1065" Test for the "-s scriptin" argument
1066func Test_s_arg()
1067 " Can't catch the output of gvim.
1068 CheckNotGui
1069 CheckEnglish
1070 " Test for failing to open the script input file.
1071 let m = system(GetVimCommand() .. " -s abcxyz")
1072 call assert_equal("Cannot open for reading: \"abcxyz\"\n", m)
1073
1074 call writefile([], 'Xinput')
1075 let m = system(GetVimCommand() .. " -s Xinput -s Xinput")
1076 call assert_equal("Attempt to open script file again: \"-s Xinput\"\n", m)
1077 call delete('Xinput')
1078endfunc
1079
1080" Test for the "-n" (no swap file) argument
1081func Test_n_arg()
1082 let after =<< trim [CODE]
1083 call assert_equal(0, &updatecount)
1084 call writefile(v:errors, 'Xtestout')
1085 qall
1086 [CODE]
1087 if RunVim([], after, '-n')
1088 call assert_equal([], readfile('Xtestout'))
1089 call delete('Xtestout')
1090 endif
Bram Moolenaarcde0ff32020-04-04 14:00:39 +02001091endfunc
1092
1093" Test for the "-h" (help) argument
1094func Test_h_arg()
1095 " Can't catch the output of gvim.
1096 CheckNotGui
1097 let l = systemlist(GetVimProg() .. ' -h')
1098 call assert_match('^VIM - Vi IMproved', l[0])
1099 let l = systemlist(GetVimProg() .. ' -?')
1100 call assert_match('^VIM - Vi IMproved', l[0])
1101endfunc
1102
1103" Test for the "-F" (farsi) argument
1104func Test_F_arg()
1105 " Can't catch the output of gvim.
1106 CheckNotGui
1107 let l = systemlist(GetVimProg() .. ' -F')
1108 call assert_match('^E27:', l[0])
1109endfunc
1110
1111" Test for the "-E" (improved Ex mode) argument
1112func Test_E_arg()
1113 let after =<< trim [CODE]
1114 call assert_equal('cv', mode(1))
1115 call writefile(v:errors, 'Xtestout')
1116 qall
1117 [CODE]
1118 if RunVim([], after, '-E')
1119 call assert_equal([], readfile('Xtestout'))
1120 call delete('Xtestout')
1121 endif
Bram Moolenaarcde0ff32020-04-04 14:00:39 +02001122endfunc
1123
1124" Test for too many edit argument errors
1125func Test_too_many_edit_args()
1126 " Can't catch the output of gvim.
1127 CheckNotGui
1128 CheckEnglish
1129 let l = systemlist(GetVimProg() .. ' - -')
1130 call assert_match('^Too many edit arguments: "-"', l[1])
1131endfunc
1132
Bram Moolenaardf4c9af2021-01-11 19:54:42 +01001133" Test starting vim with various names: vim, ex, view, evim, etc.
1134func Test_progname()
1135 CheckUnix
1136
1137 call mkdir('Xprogname', 'p')
1138 call writefile(['silent !date',
1139 \ 'call writefile([mode(1), '
1140 \ .. '&insertmode, &diff, &readonly, &updatecount, '
1141 \ .. 'join(split(execute("message"), "\n")[1:])], "Xprogname_out")',
1142 \ 'qall'], 'Xprogname_after')
1143
1144 " +---------------------------------------------- progname
1145 " | +--------------------------------- mode(1)
1146 " | | +--------------------------- &insertmode
1147 " | | | +---------------------- &diff
1148 " | | | | +----------------- &readonly
1149 " | | | | | +-------- &updatecount
1150 " | | | | | | +--- :messages
1151 " | | | | | | |
1152 let expectations = {
1153 \ 'vim': ['n', '0', '0', '0', '200', ''],
1154 \ 'gvim': ['n', '0', '0', '0', '200', ''],
1155 \ 'ex': ['ce', '0', '0', '0', '200', ''],
1156 \ 'exim': ['cv', '0', '0', '0', '200', ''],
1157 \ 'view': ['n', '0', '0', '1', '10000', ''],
1158 \ 'gview': ['n', '0', '0', '1', '10000', ''],
1159 \ 'evim': ['n', '1', '0', '0', '200', ''],
1160 \ 'eview': ['n', '1', '0', '1', '10000', ''],
1161 \ 'rvim': ['n', '0', '0', '0', '200', 'line 1: E145: Shell commands and some functionality not allowed in rvim'],
1162 \ 'rgvim': ['n', '0', '0', '0', '200', 'line 1: E145: Shell commands and some functionality not allowed in rvim'],
1163 \ 'rview': ['n', '0', '0', '1', '10000', 'line 1: E145: Shell commands and some functionality not allowed in rvim'],
1164 \ 'rgview': ['n', '0', '0', '1', '10000', 'line 1: E145: Shell commands and some functionality not allowed in rvim'],
1165 \ 'vimdiff': ['n', '0', '1', '0', '200', ''],
1166 \ 'gvimdiff': ['n', '0', '1', '0', '200', '']}
1167
1168 let prognames = ['vim', 'gvim', 'ex', 'exim', 'view', 'gview',
1169 \ 'evim', 'eview', 'rvim', 'rgvim', 'rview', 'rgview',
1170 \ 'vimdiff', 'gvimdiff']
1171
1172 for progname in prognames
Bram Moolenaar240309c2021-03-14 16:20:37 +01001173 let run_with_gui = (progname =~# 'g') || (has('gui') && (progname ==# 'evim' || progname ==# 'eview'))
1174
1175 if empty($DISPLAY) && run_with_gui
1176 " Can't run gvim, gview (etc.) if $DISPLAY is not setup.
1177 continue
Bram Moolenaardf4c9af2021-01-11 19:54:42 +01001178 endif
1179
1180 exe 'silent !ln -s -f ' ..exepath(GetVimProg()) .. ' Xprogname/' .. progname
1181
1182 let stdout_stderr = ''
1183 if progname =~# 'g'
1184 let stdout_stderr = system('Xprogname/'..progname..' -f --clean --not-a-term -S Xprogname_after')
1185 else
1186 exe 'sil !Xprogname/'..progname..' -f --clean --not-a-term -S Xprogname_after'
1187 endif
1188
1189 if progname =~# 'g' && !has('gui')
1190 call assert_equal("E25: GUI cannot be used: Not enabled at compile time\n", stdout_stderr, progname)
1191 else
Bram Moolenaar240309c2021-03-14 16:20:37 +01001192 " GUI motif can output some warnings like this:
1193 " Warning:
1194 " Name: subMenu
1195 " Class: XmCascadeButton
1196 " Illegal mnemonic character; Could not convert X KEYSYM to a keycode
1197 " So don't check that stderr is empty with GUI Motif.
1198 if run_with_gui && !has('gui_motif')
1199 call assert_equal('', stdout_stderr, progname)
1200 endif
Bram Moolenaardf4c9af2021-01-11 19:54:42 +01001201 call assert_equal(expectations[progname], readfile('Xprogname_out'), progname)
1202 endif
1203
1204 call delete('Xprogname/' .. progname)
1205 call delete('Xprogname_out')
1206 endfor
1207
1208 call delete('Xprogname_after')
1209 call delete('Xprogname', 'd')
1210endfunc
1211
Bram Moolenaarcde0ff32020-04-04 14:00:39 +02001212" vim: shiftwidth=2 sts=2 expandtab