xref: /vim-8.2.3635/src/testdir/test_startup.vim (revision d2ea7cf1)
1" Tests for startup.
2
3source shared.vim
4source screendump.vim
5source term_util.vim
6source check.vim
7
8" Check that loading startup.vim works.
9func Test_startup_script()
10  set compatible
11  source $VIMRUNTIME/defaults.vim
12
13  call assert_equal(0, &compatible)
14  " Restore some options, so that the following tests doesn't break
15  set nomore
16  set noshowmode
17endfunc
18
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()
24  CheckFeature packages
25  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
46  call mkdir('Xhere/plugin', 'p')
47  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')
50  call mkdir('Xhere/pack/foo/start/foobar/plugin', 'p')
51  call writefile(['let g:sequence .= "pack "'], 'Xhere/pack/foo/start/foobar/plugin/foo.vim')
52
53  call mkdir('Xafter/plugin', 'p')
54  call writefile(['let g:sequence .= "after "'], 'Xafter/plugin/later.vim')
55
56  if RunVim(before, after, '')
57
58    let lines = readfile('Xtestout')
59    let expected = ['Xbefore.vim', 'here.vim', 'another.vim', 'foo.vim', 'later.vim', 'Xafter.vim']
60    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
67    endfor
68    call assert_equal(expected, found)
69  endif
70
71  call assert_equal('here another pack after', substitute(join(readfile('Xsequence', 1), ''), '\s\+$', '', ''))
72
73  call delete('Xtestout')
74  call delete('Xsequence')
75  call delete('Xhere', 'rf')
76  call delete('Xanother', 'rf')
77  call delete('Xafter', 'rf')
78endfunc
79
80func Test_pack_in_rtp_when_plugins_run()
81  CheckFeature packages
82  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
92  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
111func Test_help_arg()
112  " This does not work with a GUI-only binary, such as on MS-Windows.
113  CheckAnyOf Unix NotGui
114
115  if RunVim([], [], '--help >Xtestout')
116    let lines = readfile('Xtestout')
117    call assert_true(len(lines) > 20)
118    call assert_match('Vi IMproved', lines[0])
119
120    " check if  couple of lines are there
121    let found = []
122    for line in lines
123      if line =~ '-R.*Readonly mode'
124	call add(found, 'Readonly mode')
125      endif
126      " 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")
129      endif
130    endfor
131    call assert_equal(['Readonly mode', '--version'], found)
132  endif
133  call delete('Xtestout')
134endfunc
135
136func Test_compatible_args()
137  let after =<< trim [CODE]
138    call writefile([string(&compatible)], "Xtestout")
139    set viminfo+=nviminfo
140    quit
141  [CODE]
142
143  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
156" Test the -o[N] and -O[N] arguments to open N windows split
157" horizontally or vertically.
158func Test_o_arg()
159  let after =<< trim [CODE]
160    set cpo&vim
161    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
169  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
204    " - sum of both windows width (+ 1 for the separator) should be equal to
205    "   the number of columns
206    " - 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
209    " - buffer of both windows should have no name
210    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
235" Test the -p[N] argument to open N tabpages.
236func Test_p_arg()
237  let after =<< trim [CODE]
238    call writefile(split(execute("tabs"), "\n"), "Xtestout")
239    qall
240  [CODE]
241
242  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
263" Test the -V[N] argument to set the 'verbose' option to [N]
264func Test_V_arg()
265  " Can't catch the output of gvim.
266  CheckNotGui
267
268  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')
272  call assert_match("sourcing \"$VIMRUNTIME[\\/]defaults\.vim\"\r\nline \\d\\+: sourcing \"[^\"]*runtime[\\/]filetype\.vim\".*\n", out)
273  call assert_match("  verbose=2\n", out)
274
275  let out = system(GetVimCommand() . ' --clean -es -X -V15 -c "set verbose?" -cq')
276   call assert_match("sourcing \"$VIMRUNTIME[\\/]defaults\.vim\"\r\nline 1: \" The default vimrc file\..*  verbose=15\n", out)
277endfunc
278
279" Test that an error is shown when the defaults.vim file could not be read
280" TODO: disabled - this causes ASAN errors for unknown reasons
281"func Test_defaults_error()
282"  " Can't catch the output of gvim.
283"  CheckNotGui
284"  CheckNotMSWindows
285"
286"  let out = system('VIMRUNTIME=/tmp ' .. GetVimCommand() .. ' --clean -cq')
287"  call assert_match("E1187: Failed to source defaults.vim", out)
288"
289"  let out = system('VIMRUNTIME=/tmp ' .. GetVimCommand() .. ' -u DEFAULTS -cq')
290"  call assert_match("E1187: Failed to source defaults.vim", out)
291"endfunc
292
293" Test the '-q [errorfile]' argument.
294func Test_q_arg()
295  CheckFeature quickfix
296
297  let lines =<< trim END
298    /* some file with an error */
299    main() {
300      functionCall(arg; arg, arg);
301      return 666
302    }
303  END
304  call writefile(lines, 'Xbadfile.c')
305
306  let after =<< trim [CODE]
307    call writefile([&errorfile, string(getpos("."))], "Xtestout")
308    copen
309    w >> Xtestout
310    qall
311  [CODE]
312
313  " Test with default argument '-q'.
314  call assert_equal('errors.err', &errorfile)
315  call writefile(["Xbadfile.c:4:12: error: expected ';' before '}' token"], 'errors.err')
316  if RunVim([], after, '-q')
317    let lines = readfile('Xtestout')
318    call assert_equal(['errors.err',
319	\              '[0, 4, 12, 0]',
320	\              "Xbadfile.c|4 col 12| error: expected ';' before '}' token"],
321	\             lines)
322  endif
323  call delete('Xtestout')
324  call delete('errors.err')
325
326  " Test with explicit argument '-q Xerrors' (with space).
327  call writefile(["Xbadfile.c:4:12: error: expected ';' before '}' token"], 'Xerrors')
328  if RunVim([], after, '-q Xerrors')
329    let lines = readfile('Xtestout')
330    call assert_equal(['Xerrors',
331	\              '[0, 4, 12, 0]',
332	\              "Xbadfile.c|4 col 12| error: expected ';' before '}' token"],
333	\             lines)
334  endif
335  call delete('Xtestout')
336
337  " Test with explicit argument '-qXerrors' (without space).
338  if RunVim([], after, '-qXerrors')
339    let lines = readfile('Xtestout')
340    call assert_equal(['Xerrors',
341	\              '[0, 4, 12, 0]',
342	\              "Xbadfile.c|4 col 12| error: expected ';' before '}' token"],
343	\             lines)
344  endif
345
346  " Test with a non-existing error file (exits with value 3)
347  let out = system(GetVimCommand() .. ' -q xyz.err')
348  call assert_equal(3, v:shell_error)
349
350  call delete('Xbadfile.c')
351  call delete('Xtestout')
352  call delete('Xerrors')
353endfunc
354
355" Test the -V[N]{filename} argument to set the 'verbose' option to N
356" and set 'verbosefile' to filename.
357func Test_V_file_arg()
358  if RunVim([], [], ' --clean -V2Xverbosefile -c "set verbose? verbosefile?" -cq')
359    let out = join(readfile('Xverbosefile'), "\n")
360    call assert_match("sourcing \"$VIMRUNTIME[\\/]defaults\.vim\"\n", out)
361    call assert_match("\n  verbose=2\n", out)
362    call assert_match("\n  verbosefile=Xverbosefile", out)
363  endif
364
365  call delete('Xverbosefile')
366endfunc
367
368" Test the -m, -M and -R arguments:
369" -m resets 'write'
370" -M resets 'modifiable' and 'write'
371" -R sets 'readonly'
372func Test_m_M_R()
373  let after =<< trim [CODE]
374    call writefile([&write, &modifiable, &readonly, &updatecount], "Xtestout")
375    qall
376  [CODE]
377
378  if RunVim([], after, '')
379    let lines = readfile('Xtestout')
380    call assert_equal(['1', '1', '0', '200'], lines)
381  endif
382  if RunVim([], after, '-m')
383    let lines = readfile('Xtestout')
384    call assert_equal(['0', '1', '0', '200'], lines)
385  endif
386  if RunVim([], after, '-M')
387    let lines = readfile('Xtestout')
388    call assert_equal(['0', '0', '0', '200'], lines)
389  endif
390  if RunVim([], after, '-R')
391    let lines = readfile('Xtestout')
392    call assert_equal(['1', '1', '1', '10000'], lines)
393  endif
394
395  call delete('Xtestout')
396endfunc
397
398" Test the -A, -F and -H arguments (Arabic, Farsi and Hebrew modes).
399func Test_A_F_H_arg()
400  let after =<< trim [CODE]
401    call writefile([&rightleft, &arabic, &fkmap, &hkmap], "Xtestout")
402    qall
403  [CODE]
404
405  " Use silent Ex mode to avoid the hit-Enter prompt for the warning that
406  " 'encoding' is not utf-8.
407  if has('arabic') && &encoding == 'utf-8' && RunVim([], after, '-e -s -A')
408    let lines = readfile('Xtestout')
409    call assert_equal(['1', '1', '0', '0'], lines)
410  endif
411
412  if has('farsi') && RunVim([], after, '-F')
413    let lines = readfile('Xtestout')
414    call assert_equal(['1', '0', '1', '0'], lines)
415  endif
416
417  if has('rightleft') && RunVim([], after, '-H')
418    let lines = readfile('Xtestout')
419    call assert_equal(['1', '0', '0', '1'], lines)
420  endif
421
422  call delete('Xtestout')
423endfunc
424
425" Test the --echo-wid argument (for GTK GUI only).
426func Test_echo_wid()
427  CheckCanRunGui
428  CheckFeature gui_gtk
429
430  if RunVim([], [], '-g --echo-wid -cq >Xtest_echo_wid')
431    let lines = readfile('Xtest_echo_wid')
432    call assert_equal(1, len(lines))
433    call assert_match('^WID: \d\+$', lines[0])
434  endif
435
436  call delete('Xtest_echo_wid')
437endfunction
438
439" Test the -reverse and +reverse arguments (for GUI only).
440func Test_reverse()
441  CheckCanRunGui
442  CheckAnyOf Feature:gui_gtk Feature:gui_motif Feature:gui_athena
443
444  let after =<< trim [CODE]
445    call writefile([&background], "Xtest_reverse")
446    qall
447  [CODE]
448  if RunVim([], after, '-f -g -reverse')
449    let lines = readfile('Xtest_reverse')
450    call assert_equal(['dark'], lines)
451  endif
452  if RunVim([], after, '-f -g +reverse')
453    let lines = readfile('Xtest_reverse')
454    call assert_equal(['light'], lines)
455  endif
456
457  call delete('Xtest_reverse')
458endfunc
459
460" Test the -background and -foreground arguments (for GUI only).
461func Test_background_foreground()
462  CheckCanRunGui
463  CheckAnyOf Feature:gui_gtk Feature:gui_motif Feature:gui_athena
464
465  " Is there a better way to check the effect of -background & -foreground
466  " other than merely looking at &background (dark or light)?
467  let after =<< trim [CODE]
468    call writefile([&background], "Xtest_fg_bg")
469    qall
470  [CODE]
471  if RunVim([], after, '-f -g -background darkred -foreground yellow')
472    let lines = readfile('Xtest_fg_bg')
473    call assert_equal(['dark'], lines)
474  endif
475  if RunVim([], after, '-f -g -background ivory -foreground darkgreen')
476    let lines = readfile('Xtest_fg_bg')
477    call assert_equal(['light'], lines)
478  endif
479
480  call delete('Xtest_fg_bg')
481endfunc
482
483" Test the -font argument (for GUI only).
484func Test_font()
485  CheckCanRunGui
486  CheckNotMSWindows
487
488  if has('gui_gtk')
489    let font = 'Courier 14'
490  elseif has('gui_motif') || has('gui_athena')
491    let font = '-misc-fixed-bold-*'
492  else
493    throw 'Skipped: test does not set a valid font for this GUI'
494  endif
495
496  let after =<< trim [CODE]
497    call writefile([&guifont], "Xtest_font")
498    qall
499  [CODE]
500
501  if RunVim([], after, '--nofork -g -font "' .. font .. '"')
502    let lines = readfile('Xtest_font')
503    call assert_equal([font], lines)
504  endif
505
506  call delete('Xtest_font')
507endfunc
508
509" Test the -geometry argument (for GUI only).
510func Test_geometry()
511  CheckCanRunGui
512  CheckAnyOf Feature:gui_gtk Feature:gui_motif Feature:gui_athena
513
514  if has('gui_motif') || has('gui_athena')
515    " FIXME: With GUI Athena or Motif, the value of getwinposx(),
516    "        getwinposy() and getwinpos() do not match exactly the
517    "        value given in -geometry. Why?
518    "        So only check &columns and &lines for those GUIs.
519    let after =<< trim [CODE]
520      call writefile([&columns, &lines], "Xtest_geometry")
521      qall
522    [CODE]
523    if RunVim([], after, '-f -g -geometry 31x13+41+43')
524      let lines = readfile('Xtest_geometry')
525      call assert_equal(['31', '13'], lines)
526    endif
527  else
528    let after =<< trim [CODE]
529      call writefile([&columns, &lines, getwinposx(), getwinposy(), string(getwinpos())], "Xtest_geometry")
530      qall
531    [CODE]
532    if RunVim([], after, '-f -g -geometry 31x13+41+43')
533      let lines = readfile('Xtest_geometry')
534      call assert_equal(['31', '13', '41', '43', '[41, 43]'], lines)
535    endif
536  endif
537
538  call delete('Xtest_geometry')
539endfunc
540
541" Test the -iconic argument (for GUI only).
542func Test_iconic()
543  CheckCanRunGui
544  CheckAnyOf Feature:gui_gtk Feature:gui_motif Feature:gui_athena
545
546  call RunVim([], [], '-f -g -iconic -cq')
547
548  " TODO: currently only start vim iconified, but does not
549  "       check that vim is iconified. How could this be checked?
550endfunc
551
552
553func Test_invalid_args()
554  " must be able to get the output of Vim.
555  CheckUnix
556  CheckNotGui
557
558  for opt in ['-Y', '--does-not-exist']
559    let out = split(system(GetVimCommand() .. ' ' .. opt), "\n")
560    call assert_equal(1, v:shell_error)
561    call assert_match('^VIM - Vi IMproved .* (.*)$',              out[0])
562    call assert_equal('Unknown option argument: "' .. opt .. '"', out[1])
563    call assert_equal('More info with: "vim -h"',                 out[2])
564  endfor
565
566  for opt in ['-c', '-i', '-s', '-t', '-T', '-u', '-U', '-w', '-W', '--cmd', '--startuptime']
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
574  if has('clientserver')
575    for opt in ['--remote', '--remote-send', '--remote-silent', '--remote-expr',
576          \     '--remote-tab', '--remote-tab-wait',
577          \     '--remote-tab-wait-silent', '--remote-tab-silent',
578          \     '--remote-wait', '--remote-wait-silent',
579          \     '--servername',
580          \    ]
581      let out = split(system(GetVimCommand() .. ' '  .. opt), "\n")
582      call assert_equal(1, v:shell_error)
583      call assert_match('^VIM - Vi IMproved .* (.*)$',             out[0])
584      call assert_equal('Argument missing after: "' .. opt .. '"', out[1])
585      call assert_equal('More info with: "vim -h"',                out[2])
586    endfor
587  endif
588
589  if has('gui_gtk')
590    let out = split(system(GetVimCommand() .. ' --display'), "\n")
591    call assert_equal(1, v:shell_error)
592    call assert_match('^VIM - Vi IMproved .* (.*)$',         out[0])
593    call assert_equal('Argument missing after: "--display"', out[1])
594    call assert_equal('More info with: "vim -h"',            out[2])
595  endif
596
597  if has('xterm_clipboard')
598    let out = split(system(GetVimCommand() .. ' -display'), "\n")
599    call assert_equal(1, v:shell_error)
600    call assert_match('^VIM - Vi IMproved .* (.*)$',         out[0])
601    call assert_equal('Argument missing after: "-display"', out[1])
602    call assert_equal('More info with: "vim -h"',            out[2])
603  endif
604
605  let out = split(system(GetVimCommand() .. ' -ix'), "\n")
606  call assert_equal(1, v:shell_error)
607  call assert_match('^VIM - Vi IMproved .* (.*)$',          out[0])
608  call assert_equal('Garbage after option argument: "-ix"', out[1])
609  call assert_equal('More info with: "vim -h"',             out[2])
610
611  let out = split(system(GetVimCommand() .. ' - xxx'), "\n")
612  call assert_equal(1, v:shell_error)
613  call assert_match('^VIM - Vi IMproved .* (.*)$',    out[0])
614  call assert_equal('Too many edit arguments: "xxx"', out[1])
615  call assert_equal('More info with: "vim -h"',       out[2])
616
617  if has('quickfix')
618    " Detect invalid repeated arguments '-t foo -t foo", '-q foo -q foo'.
619    for opt in ['-t', '-q']
620      let out = split(system(GetVimCommand() .. repeat(' ' .. opt .. ' foo', 2)), "\n")
621      call assert_equal(1, v:shell_error)
622      call assert_match('^VIM - Vi IMproved .* (.*)$',              out[0])
623      call assert_equal('Too many edit arguments: "' .. opt .. '"', out[1])
624      call assert_equal('More info with: "vim -h"',                 out[2])
625    endfor
626  endif
627
628  for opt in [' -cq', ' --cmd q', ' +', ' -S foo']
629    let out = split(system(GetVimCommand() .. repeat(opt, 11)), "\n")
630    call assert_equal(1, v:shell_error)
631    " FIXME: The error message given by Vim is not ideal in case of repeated
632    " -S foo since it does not mention -S.
633    call assert_match('^VIM - Vi IMproved .* (.*)$',                                    out[0])
634    call assert_equal('Too many "+command", "-c command" or "--cmd command" arguments', out[1])
635    call assert_equal('More info with: "vim -h"',                                       out[2])
636  endfor
637
638  if has('gui_gtk')
639    let out = split(system(GetVimCommand() .. ' --socketid'), "\n")
640    call assert_equal(1, v:shell_error)
641    call assert_match('^VIM - Vi IMproved .* (.*)$',          out[0])
642    call assert_equal('Argument missing after: "--socketid"', out[1])
643    call assert_equal('More info with: "vim -h"',             out[2])
644
645    for opt in ['--socketid x', '--socketid 0xg']
646      let out = split(system(GetVimCommand() .. ' ' .. opt), "\n")
647      call assert_equal(1, v:shell_error)
648      call assert_match('^VIM - Vi IMproved .* (.*)$',        out[0])
649      call assert_equal('Invalid argument for: "--socketid"', out[1])
650      call assert_equal('More info with: "vim -h"',           out[2])
651    endfor
652
653  endif
654endfunc
655
656func Test_file_args()
657  let after =<< trim [CODE]
658    call writefile(argv(), "Xtestout")
659    qall
660  [CODE]
661
662  if RunVim([], after, '')
663    let lines = readfile('Xtestout')
664    call assert_equal(0, len(lines))
665  endif
666
667  if RunVim([], after, 'one')
668    let lines = readfile('Xtestout')
669    call assert_equal(1, len(lines))
670    call assert_equal('one', lines[0])
671  endif
672
673  if RunVim([], after, 'one two three')
674    let lines = readfile('Xtestout')
675    call assert_equal(3, len(lines))
676    call assert_equal('one', lines[0])
677    call assert_equal('two', lines[1])
678    call assert_equal('three', lines[2])
679  endif
680
681  if RunVim([], after, 'one -c echo two')
682    let lines = readfile('Xtestout')
683    call assert_equal(2, len(lines))
684    call assert_equal('one', lines[0])
685    call assert_equal('two', lines[1])
686  endif
687
688  if RunVim([], after, 'one -- -c echo two')
689    let lines = readfile('Xtestout')
690    call assert_equal(4, len(lines))
691    call assert_equal('one', lines[0])
692    call assert_equal('-c', lines[1])
693    call assert_equal('echo', lines[2])
694    call assert_equal('two', lines[3])
695  endif
696
697  call delete('Xtestout')
698endfunc
699
700func Test_startuptime()
701  CheckFeature startuptime
702  let after = ['qall']
703  if RunVim([], after, '--startuptime Xtestout one')
704    let lines = readfile('Xtestout')
705    let expected = ['--- VIM STARTING ---', 'parsing arguments',
706	  \ 'shell init', 'inits 3', 'start termcap', 'opening buffers']
707    let found = []
708    for line in lines
709      for exp in expected
710	if line =~ exp
711	  call add(found, exp)
712	endif
713      endfor
714    endfor
715    call assert_equal(expected, found)
716  endif
717  call delete('Xtestout')
718endfunc
719
720func Test_read_stdin()
721  let after =<< trim [CODE]
722    write Xtestout
723    quit!
724  [CODE]
725
726  if RunVimPiped([], after, '-', 'echo something | ')
727    let lines = readfile('Xtestout')
728    " MS-Windows adds a space after the word
729    call assert_equal(['something'], split(lines[0]))
730  endif
731  call delete('Xtestout')
732endfunc
733
734func Test_set_shell()
735  let after =<< trim [CODE]
736    call writefile([&shell], "Xtestout")
737    quit!
738  [CODE]
739
740  if has('win32')
741    let $SHELL = 'C:\with space\cmd.exe'
742    let expected = '"C:\with space\cmd.exe"'
743  else
744    let $SHELL = '/bin/with space/sh'
745    let expected = '/bin/with\ space/sh'
746  endif
747
748  if RunVimPiped([], after, '', '')
749    let lines = readfile('Xtestout')
750    call assert_equal(expected, lines[0])
751  endif
752  call delete('Xtestout')
753endfunc
754
755func Test_progpath()
756  " Tests normally run with "./vim" or "../vim", these must have been expanded
757  " to a full path.
758  if has('unix')
759    call assert_equal('/', v:progpath[0])
760  elseif has('win32')
761    call assert_equal(':', v:progpath[1])
762    call assert_match('[/\\]', v:progpath[2])
763  endif
764
765  " Only expect "vim" to appear in v:progname.
766  call assert_match('vim\c', v:progname)
767endfunc
768
769func Test_silent_ex_mode()
770  " must be able to get the output of Vim.
771  CheckUnix
772  CheckNotGui
773
774  " This caused an ml_get error.
775  let out = system(GetVimCommand() . '-u NONE -es -c''set verbose=1|h|exe "%norm\<c-y>\<c-d>"'' -c cq')
776  call assert_notmatch('E315:', out)
777endfunc
778
779func Test_default_term()
780  " must be able to get the output of Vim.
781  CheckUnix
782  CheckNotGui
783
784  let save_term = $TERM
785  let $TERM = 'unknownxxx'
786  let out = system(GetVimCommand() . ' -c''set term'' -c cq')
787  call assert_match("defaulting to 'ansi'", out)
788  let $TERM = save_term
789endfunc
790
791func Test_zzz_startinsert()
792  " Test :startinsert
793  call writefile(['123456'], 'Xtestout')
794  let after =<< trim [CODE]
795    :startinsert
796    call feedkeys("foobar\<c-o>:wq\<cr>","t")
797  [CODE]
798
799  if RunVim([], after, 'Xtestout')
800    let lines = readfile('Xtestout')
801    call assert_equal(['foobar123456'], lines)
802  endif
803  " Test :startinsert!
804  call writefile(['123456'], 'Xtestout')
805  let after =<< trim [CODE]
806    :startinsert!
807    call feedkeys("foobar\<c-o>:wq\<cr>","t")
808  [CODE]
809
810  if RunVim([], after, 'Xtestout')
811    let lines = readfile('Xtestout')
812    call assert_equal(['123456foobar'], lines)
813  endif
814  call delete('Xtestout')
815endfunc
816
817func Test_issue_3969()
818  " Can't catch the output of gvim.
819  CheckNotGui
820
821  " Check that message is not truncated.
822  let out = system(GetVimCommand() . ' -es -X -V1 -c "echon ''hello''" -cq')
823  call assert_equal('hello', out)
824endfunc
825
826func Test_start_with_tabs()
827  CheckRunVimInTerminal
828
829  let buf = RunVimInTerminal('-p a b c', {})
830  call VerifyScreenDump(buf, 'Test_start_with_tabs', {})
831
832  " clean up
833  call StopVimInTerminal(buf)
834endfunc
835
836func Test_v_argv()
837  " Can't catch the output of gvim.
838  CheckNotGui
839
840  let out = system(GetVimCommand() . ' -es -V1 -X arg1 --cmd "echo v:argv" --cmd q')
841  let list = out->split("', '")
842  call assert_match('vim', list[0])
843  let idx = index(list, 'arg1')
844  call assert_true(idx > 2)
845  call assert_equal(['arg1', '--cmd', 'echo v:argv', '--cmd', 'q'']'], list[idx:])
846endfunc
847
848" Test for the "-r" recovery mode option
849func Test_r_arg()
850  " Can't catch the output of gvim.
851  CheckNotGui
852  CheckUnix
853  CheckEnglish
854  let cmd = GetVimCommand()
855  " There can be swap files anywhere, only check for the headers.
856  let expected =<< trim END
857    Swap files found:.*
858    In current directory:.*
859    In directory \~/tmp:.*
860    In directory /var/tmp:.*
861    In directory /tmp:.*
862  END
863  call assert_match(join(expected, ""), system(cmd .. " -r")->substitute("[\r\n]\\+", '', ''))
864endfunc
865
866" Test for the '-t' option to jump to a tag
867func Test_t_arg()
868  let before =<< trim [CODE]
869    set tags=Xtags
870  [CODE]
871  let after =<< trim [CODE]
872    let s = bufname('') .. ':L' .. line('.') .. 'C' .. col('.')
873    call writefile([s], "Xtestout")
874    qall
875  [CODE]
876
877  call writefile(["!_TAG_FILE_ENCODING\tutf-8\t//",
878        \ "first\tXfile1\t/^    \\zsfirst$/",
879        \ "second\tXfile1\t/^    \\zssecond$/",
880        \ "third\tXfile1\t/^    \\zsthird$/"],
881        \ 'Xtags')
882  call writefile(['    first', '    second', '    third'], 'Xfile1')
883
884  for t_arg in ['-t second', '-tsecond']
885    if RunVim(before, after, '-t second')
886      call assert_equal(['Xfile1:L2C5'], readfile('Xtestout'), t_arg)
887      call delete('Xtestout')
888    endif
889  endfor
890
891  call delete('Xtags')
892  call delete('Xfile1')
893endfunc
894
895" Test the '-T' argument which sets the 'term' option.
896func Test_T_arg()
897  CheckNotGui
898  let after =<< trim [CODE]
899    call writefile([&term], "Xtest_T_arg")
900    qall
901  [CODE]
902
903  for t in ['builtin_dumb', 'builtin_ansi']
904    if RunVim([], after, '-T ' .. t)
905      let lines = readfile('Xtest_T_arg')
906      call assert_equal([t], lines)
907    endif
908  endfor
909
910  call delete('Xtest_T_arg')
911endfunc
912
913" Test the '-x' argument to read/write encrypted files.
914func Test_x_arg()
915  CheckRunVimInTerminal
916  CheckFeature cryptv
917
918  " Create an encrypted file Xtest_x_arg.
919  let buf = RunVimInTerminal('-n -x Xtest_x_arg', #{rows: 10, wait_for_ruler: 0})
920  call WaitForAssert({-> assert_match('^Enter encryption key: ', term_getline(buf, 10))})
921  call term_sendkeys(buf, "foo\n")
922  call WaitForAssert({-> assert_match('^Enter same key again: ', term_getline(buf, 10))})
923  call term_sendkeys(buf, "foo\n")
924  call WaitForAssert({-> assert_match(' All$', term_getline(buf, 10))})
925  call term_sendkeys(buf, "itest\<Esc>:w\<Enter>")
926  call WaitForAssert({-> assert_match('"Xtest_x_arg" \[New\]\[blowfish2\] 1L, 5B written',
927        \            term_getline(buf, 10))})
928  call StopVimInTerminal(buf)
929
930  " Read the encrypted file and check that it contains the expected content "test"
931  let buf = RunVimInTerminal('-n -x Xtest_x_arg', #{rows: 10, wait_for_ruler: 0})
932  call WaitForAssert({-> assert_match('^Enter encryption key: ', term_getline(buf, 10))})
933  call term_sendkeys(buf, "foo\n")
934  call WaitForAssert({-> assert_match('^Enter same key again: ', term_getline(buf, 10))})
935  call term_sendkeys(buf, "foo\n")
936  call WaitForAssert({-> assert_match('^test', term_getline(buf, 1))})
937  call StopVimInTerminal(buf)
938
939  call delete('Xtest_x_arg')
940endfunc
941
942" Test for entering the insert mode on startup
943func Test_start_insertmode()
944  let before =<< trim [CODE]
945    set insertmode
946  [CODE]
947  let after =<< trim [CODE]
948    call writefile(['insertmode=' .. &insertmode], 'Xtestout')
949    qall
950  [CODE]
951  if RunVim(before, after, '')
952    call assert_equal(['insertmode=1'], readfile('Xtestout'))
953    call delete('Xtestout')
954  endif
955endfunc
956
957" Test for enabling the binary mode on startup
958func Test_b_arg()
959  let after =<< trim [CODE]
960    call writefile(['binary=' .. &binary], 'Xtestout')
961    qall
962  [CODE]
963  if RunVim([], after, '-b')
964    call assert_equal(['binary=1'], readfile('Xtestout'))
965    call delete('Xtestout')
966  endif
967endfunc
968
969" Test for enabling the lisp mode on startup
970func Test_l_arg()
971  let after =<< trim [CODE]
972    let s = 'lisp=' .. &lisp .. ', showmatch=' .. &showmatch
973    call writefile([s], 'Xtestout')
974    qall
975  [CODE]
976  if RunVim([], after, '-l')
977    call assert_equal(['lisp=1, showmatch=1'], readfile('Xtestout'))
978    call delete('Xtestout')
979  endif
980endfunc
981
982" Test for specifying a non-existing vimrc file using "-u"
983func Test_missing_vimrc()
984  CheckRunVimInTerminal
985  let after =<< trim [CODE]
986    call assert_match('^E282:', v:errmsg)
987    call writefile(v:errors, 'Xtestout')
988  [CODE]
989  call writefile(after, 'Xafter')
990
991  let cmd = GetVimCommandCleanTerm() . ' -u Xvimrc_missing -S Xafter'
992  let buf = term_start(cmd, {'term_rows' : 10})
993  call WaitForAssert({-> assert_equal("running", term_getstatus(buf))})
994  call TermWait(buf)
995  call term_sendkeys(buf, "\n:")
996  call TermWait(buf)
997  call WaitForAssert({-> assert_match(':', term_getline(buf, 10))})
998  call StopVimInTerminal(buf)
999  call assert_equal([], readfile('Xtestout'))
1000  call delete('Xafter')
1001  call delete('Xtestout')
1002endfunc
1003
1004" Test for using the $VIMINIT environment variable
1005func Test_VIMINIT()
1006  let after =<< trim [CODE]
1007    call assert_equal(1, exists('viminit_found'))
1008    call assert_equal('yes', viminit_found)
1009    call writefile(v:errors, 'Xtestout')
1010    qall
1011  [CODE]
1012  call writefile(after, 'Xafter')
1013  let cmd = GetVimProg() . ' --not-a-term -S Xafter --cmd "set enc=utf8"'
1014  call setenv('VIMINIT', 'let viminit_found="yes"')
1015  exe "silent !" . cmd
1016  call assert_equal([], readfile('Xtestout'))
1017  call delete('Xtestout')
1018  call delete('Xafter')
1019endfunc
1020
1021" Test for using the $EXINIT environment variable
1022func Test_EXINIT()
1023  let after =<< trim [CODE]
1024    call assert_equal(1, exists('exinit_found'))
1025    call assert_equal('yes', exinit_found)
1026    call writefile(v:errors, 'Xtestout')
1027    qall
1028  [CODE]
1029  call writefile(after, 'Xafter')
1030  let cmd = GetVimProg() . ' --not-a-term -S Xafter --cmd "set enc=utf8"'
1031  call setenv('EXINIT', 'let exinit_found="yes"')
1032  exe "silent !" . cmd
1033  call assert_equal([], readfile('Xtestout'))
1034  call delete('Xtestout')
1035  call delete('Xafter')
1036endfunc
1037
1038" Test for using the 'exrc' option
1039func Test_exrc()
1040  let after =<< trim [CODE]
1041    call assert_equal(1, &exrc)
1042    call assert_equal(1, &secure)
1043    call assert_equal(37, exrc_found)
1044    call writefile(v:errors, 'Xtestout')
1045    qall
1046  [CODE]
1047  call mkdir('Xdir')
1048  call writefile(['let exrc_found=37'], 'Xdir/.exrc')
1049  call writefile(after, 'Xdir/Xafter')
1050  let cmd = GetVimProg() . ' --not-a-term -S Xafter --cmd "cd Xdir" --cmd "set enc=utf8 exrc secure"'
1051  exe "silent !" . cmd
1052  call assert_equal([], readfile('Xdir/Xtestout'))
1053  call delete('Xdir', 'rf')
1054endfunc
1055
1056" Test for starting Vim with a non-terminal as input/output
1057func Test_io_not_a_terminal()
1058  " Can't catch the output of gvim.
1059  CheckNotGui
1060  CheckUnix
1061  CheckEnglish
1062  let l = systemlist(GetVimProg() .. ' --ttyfail')
1063  call assert_equal(['Vim: Warning: Output is not to a terminal',
1064        \ 'Vim: Warning: Input is not from a terminal'], l)
1065endfunc
1066
1067" Test for --not-a-term avoiding escape codes.
1068func Test_not_a_term()
1069  CheckUnix
1070  CheckNotGui
1071
1072  if &shellredir =~ '%s'
1073    let redir = printf(&shellredir,  'Xvimout')
1074  else
1075    let redir = &shellredir .. ' Xvimout'
1076  endif
1077
1078  " Without --not-a-term there are a few escape sequences.
1079  " This will take 2 seconds because of the missing --not-a-term
1080  let cmd = GetVimProg() .. ' --cmd quit ' .. redir
1081  exe "silent !" . cmd
1082  call assert_match("\<Esc>", readfile('Xvimout')->join())
1083  call delete('Xvimout')
1084
1085  " With --not-a-term there are no escape sequences.
1086  let cmd = GetVimProg() .. ' --not-a-term --cmd quit ' .. redir
1087  exe "silent !" . cmd
1088  call assert_notmatch("\<Esc>", readfile('Xvimout')->join())
1089  call delete('Xvimout')
1090endfunc
1091
1092
1093" Test for the "-w scriptout" argument
1094func Test_w_arg()
1095  " Can't catch the output of gvim.
1096  CheckNotGui
1097
1098  call writefile(["iVim Editor\<Esc>:q!\<CR>"], 'Xscriptin', 'b')
1099  if RunVim([], [], '-s Xscriptin -w Xscriptout')
1100    call assert_equal(["iVim Editor\e:q!\r"], readfile('Xscriptout'))
1101    call delete('Xscriptout')
1102  endif
1103  call delete('Xscriptin')
1104
1105  " Test for failing to open the script output file. This test works only when
1106  " the language is English.
1107  if v:lang == "C" || v:lang =~ '^[Ee]n'
1108    call mkdir("Xdir")
1109    let m = system(GetVimCommand() .. " -w Xdir")
1110    call assert_equal("Cannot open for script output: \"Xdir\"\n", m)
1111    call delete("Xdir", 'rf')
1112  endif
1113
1114  " A number argument sets the 'window' option
1115  call writefile(["iwindow \<C-R>=&window\<CR>\<Esc>:wq! Xresult\<CR>"], 'Xscriptin', 'b')
1116  for w_arg in ['-w 17', '-w17']
1117    if RunVim([], [], '-s Xscriptin ' .. w_arg)
1118      call assert_equal(["window 17"], readfile('Xresult'), w_arg)
1119      call delete('Xresult')
1120    endif
1121  endfor
1122  call delete('Xscriptin')
1123endfunc
1124
1125" Test for the "-s scriptin" argument
1126func Test_s_arg()
1127  " Can't catch the output of gvim.
1128  CheckNotGui
1129  CheckEnglish
1130  " Test for failing to open the script input file.
1131  let m = system(GetVimCommand() .. " -s abcxyz")
1132  call assert_equal("Cannot open for reading: \"abcxyz\"\n", m)
1133
1134  call writefile([], 'Xinput')
1135  let m = system(GetVimCommand() .. " -s Xinput -s Xinput")
1136  call assert_equal("Attempt to open script file again: \"-s Xinput\"\n", m)
1137  call delete('Xinput')
1138endfunc
1139
1140" Test for the "-n" (no swap file) argument
1141func Test_n_arg()
1142  let after =<< trim [CODE]
1143    call assert_equal(0, &updatecount)
1144    call writefile(v:errors, 'Xtestout')
1145    qall
1146  [CODE]
1147  if RunVim([], after, '-n')
1148    call assert_equal([], readfile('Xtestout'))
1149    call delete('Xtestout')
1150  endif
1151endfunc
1152
1153" Test for the "-h" (help) argument
1154func Test_h_arg()
1155  " Can't catch the output of gvim.
1156  CheckNotGui
1157  let l = systemlist(GetVimProg() .. ' -h')
1158  call assert_match('^VIM - Vi IMproved', l[0])
1159  let l = systemlist(GetVimProg() .. ' -?')
1160  call assert_match('^VIM - Vi IMproved', l[0])
1161endfunc
1162
1163" Test for the "-F" (farsi) argument
1164func Test_F_arg()
1165  " Can't catch the output of gvim.
1166  CheckNotGui
1167  let l = systemlist(GetVimProg() .. ' -F')
1168  call assert_match('^E27:', l[0])
1169endfunc
1170
1171" Test for the "-E" (improved Ex mode) argument
1172func Test_E_arg()
1173  let after =<< trim [CODE]
1174    call assert_equal('cv', mode(1))
1175    call writefile(v:errors, 'Xtestout')
1176    qall
1177  [CODE]
1178  if RunVim([], after, '-E')
1179    call assert_equal([], readfile('Xtestout'))
1180    call delete('Xtestout')
1181  endif
1182endfunc
1183
1184" Test for the "-D" (debugger) argument
1185func Test_D_arg()
1186  CheckRunVimInTerminal
1187
1188  let cmd = GetVimCommandCleanTerm() .. ' -D'
1189  let buf = term_start(cmd, {'term_rows' : 10})
1190  call WaitForAssert({-> assert_equal("running", term_getstatus(buf))})
1191
1192  call WaitForAssert({-> assert_equal('Entering Debug mode.  Type "cont" to continue.',
1193  \                  term_getline(buf, 7))})
1194  call WaitForAssert({-> assert_equal('>', term_getline(buf, 10))})
1195
1196  call StopVimInTerminal(buf)
1197endfunc
1198
1199" Test for too many edit argument errors
1200func Test_too_many_edit_args()
1201  " Can't catch the output of gvim.
1202  CheckNotGui
1203  CheckEnglish
1204  let l = systemlist(GetVimProg() .. ' - -')
1205  call assert_match('^Too many edit arguments: "-"', l[1])
1206endfunc
1207
1208" Test starting vim with various names: vim, ex, view, evim, etc.
1209func Test_progname()
1210  CheckUnix
1211
1212  call mkdir('Xprogname', 'p')
1213  call writefile(['silent !date',
1214  \               'call writefile([mode(1), '
1215  \               .. '&insertmode, &diff, &readonly, &updatecount, '
1216  \               .. 'join(split(execute("message"), "\n")[1:])], "Xprogname_out")',
1217  \               'qall'], 'Xprogname_after')
1218
1219  "  +---------------------------------------------- progname
1220  "  |            +--------------------------------- mode(1)
1221  "  |            |     +--------------------------- &insertmode
1222  "  |            |     |    +---------------------- &diff
1223  "  |            |     |    |    +----------------- &readonly
1224  "  |            |     |    |    |        +-------- &updatecount
1225  "  |            |     |    |    |        |    +--- :messages
1226  "  |            |     |    |    |        |    |
1227  let expectations = {
1228  \ 'vim':      ['n',  '0', '0', '0',   '200', ''],
1229  \ 'gvim':     ['n',  '0', '0', '0',   '200', ''],
1230  \ 'ex':       ['ce', '0', '0', '0',   '200', ''],
1231  \ 'exim':     ['cv', '0', '0', '0',   '200', ''],
1232  \ 'view':     ['n',  '0', '0', '1', '10000', ''],
1233  \ 'gview':    ['n',  '0', '0', '1', '10000', ''],
1234  \ 'evim':     ['n',  '1', '0', '0',   '200', ''],
1235  \ 'eview':    ['n',  '1', '0', '1', '10000', ''],
1236  \ 'rvim':     ['n',  '0', '0', '0',   '200', 'line    1: E145: Shell commands and some functionality not allowed in rvim'],
1237  \ 'rgvim':    ['n',  '0', '0', '0',   '200', 'line    1: E145: Shell commands and some functionality not allowed in rvim'],
1238  \ 'rview':    ['n',  '0', '0', '1', '10000', 'line    1: E145: Shell commands and some functionality not allowed in rvim'],
1239  \ 'rgview':   ['n',  '0', '0', '1', '10000', 'line    1: E145: Shell commands and some functionality not allowed in rvim'],
1240  \ 'vimdiff':  ['n',  '0', '1', '0',   '200', ''],
1241  \ 'gvimdiff': ['n',  '0', '1', '0',   '200', '']}
1242
1243  let prognames = ['vim', 'gvim', 'ex', 'exim', 'view', 'gview',
1244  \                'evim', 'eview', 'rvim', 'rgvim', 'rview', 'rgview',
1245  \                'vimdiff', 'gvimdiff']
1246
1247  for progname in prognames
1248    let run_with_gui = (progname =~# 'g') || (has('gui') && (progname ==# 'evim' || progname ==# 'eview'))
1249
1250    if empty($DISPLAY) && run_with_gui
1251      " Can't run gvim, gview  (etc.) if $DISPLAY is not setup.
1252      continue
1253    endif
1254
1255    exe 'silent !ln -s -f ' ..exepath(GetVimProg()) .. ' Xprogname/' .. progname
1256
1257    let stdout_stderr = ''
1258    if progname =~# 'g'
1259      let stdout_stderr = system('Xprogname/'..progname..' -f --clean --not-a-term -S Xprogname_after')
1260    else
1261      exe 'sil !Xprogname/'..progname..' -f --clean --not-a-term -S Xprogname_after'
1262    endif
1263
1264    if progname =~# 'g' && !has('gui')
1265      call assert_equal("E25: GUI cannot be used: Not enabled at compile time\n", stdout_stderr, progname)
1266    else
1267      " GUI motif can output some warnings like this:
1268      "   Warning:
1269      "       Name: subMenu
1270      "       Class: XmCascadeButton
1271      "       Illegal mnemonic character;  Could not convert X KEYSYM to a keycode
1272      " So don't check that stderr is empty with GUI Motif.
1273      if run_with_gui && !has('gui_motif')
1274        call assert_equal('', stdout_stderr, progname)
1275      endif
1276      call assert_equal(expectations[progname], readfile('Xprogname_out'), progname)
1277    endif
1278
1279    call delete('Xprogname/' .. progname)
1280    call delete('Xprogname_out')
1281  endfor
1282
1283  call delete('Xprogname_after')
1284  call delete('Xprogname', 'd')
1285endfunc
1286
1287" Test for doing a write from .vimrc
1288func Test_write_in_vimrc()
1289  call writefile(['silent! write'], 'Xvimrc')
1290  let after =<< trim [CODE]
1291    call assert_match('E32: ', v:errmsg)
1292    call writefile(v:errors, 'Xtestout')
1293    qall
1294  [CODE]
1295  if RunVim([], after, '-u Xvimrc')
1296    call assert_equal([], readfile('Xtestout'))
1297    call delete('Xtestout')
1298  endif
1299  call delete('Xvimrc')
1300endfunc
1301
1302" vim: shiftwidth=2 sts=2 expandtab
1303