xref: /vim-8.2.3635/src/testdir/test_startup.vim (revision f89be8de)
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 the '-q [errorfile]' argument.
280func Test_q_arg()
281  CheckFeature quickfix
282
283  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
292  let after =<< trim [CODE]
293    call writefile([&errorfile, string(getpos("."))], "Xtestout")
294    copen
295    w >> Xtestout
296    qall
297  [CODE]
298
299  " Test with default argument '-q'.
300  call assert_equal('errors.err', &errorfile)
301  call writefile(["Xbadfile.c:4:12: error: expected ';' before '}' token"], 'errors.err')
302  if RunVim([], after, '-q')
303    let lines = readfile('Xtestout')
304    call assert_equal(['errors.err',
305	\              '[0, 4, 12, 0]',
306	\              "Xbadfile.c|4 col 12| error: expected ';' before '}' token"],
307	\             lines)
308  endif
309  call delete('Xtestout')
310  call delete('errors.err')
311
312  " Test with explicit argument '-q Xerrors' (with space).
313  call writefile(["Xbadfile.c:4:12: error: expected ';' before '}' token"], 'Xerrors')
314  if RunVim([], after, '-q Xerrors')
315    let lines = readfile('Xtestout')
316    call assert_equal(['Xerrors',
317	\              '[0, 4, 12, 0]',
318	\              "Xbadfile.c|4 col 12| error: expected ';' before '}' token"],
319	\             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',
327	\              '[0, 4, 12, 0]',
328	\              "Xbadfile.c|4 col 12| error: expected ';' before '}' token"],
329	\             lines)
330  endif
331
332  " 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
336  call delete('Xbadfile.c')
337  call delete('Xtestout')
338  call delete('Xerrors')
339endfunc
340
341" Test the -V[N]{filename} argument to set the 'verbose' option to N
342" and set 'verbosefile' to filename.
343func Test_V_file_arg()
344  if RunVim([], [], ' --clean -V2Xverbosefile -c "set verbose? verbosefile?" -cq')
345    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()
359  let after =<< trim [CODE]
360    call writefile([&write, &modifiable, &readonly, &updatecount], "Xtestout")
361    qall
362  [CODE]
363
364  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
384" Test the -A, -F and -H arguments (Arabic, Farsi and Hebrew modes).
385func Test_A_F_H_arg()
386  let after =<< trim [CODE]
387    call writefile([&rightleft, &arabic, &fkmap, &hkmap], "Xtestout")
388    qall
389  [CODE]
390
391  " 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')
394    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
411" 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
428  CheckAnyOf Feature:gui_gtk Feature:gui_motif Feature:gui_athena
429
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
449  CheckAnyOf Feature:gui_gtk Feature:gui_motif Feature:gui_athena
450
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
498  CheckAnyOf Feature:gui_gtk Feature:gui_motif Feature:gui_athena
499
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
530  CheckAnyOf Feature:gui_gtk Feature:gui_motif Feature:gui_athena
531
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
539func Test_invalid_args()
540  " must be able to get the output of Vim.
541  CheckUnix
542  CheckNotGui
543
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')
561    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',
565          \     '--servername',
566          \    ]
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
575  if has('gui_gtk')
576    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
582
583  if has('xterm_clipboard')
584    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
591  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
603  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
613
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
624  if has('gui_gtk')
625    let out = split(system(GetVimCommand() .. ' --socketid'), "\n")
626    call assert_equal(1, v:shell_error)
627    call assert_match('^VIM - Vi IMproved .* (.*)$',          out[0])
628    call assert_equal('Argument missing after: "--socketid"', out[1])
629    call assert_equal('More info with: "vim -h"',             out[2])
630
631    for opt in ['--socketid x', '--socketid 0xg']
632      let out = split(system(GetVimCommand() .. ' ' .. opt), "\n")
633      call assert_equal(1, v:shell_error)
634      call assert_match('^VIM - Vi IMproved .* (.*)$',        out[0])
635      call assert_equal('Invalid argument for: "--socketid"', out[1])
636      call assert_equal('More info with: "vim -h"',           out[2])
637    endfor
638
639  endif
640endfunc
641
642func Test_file_args()
643  let after =<< trim [CODE]
644    call writefile(argv(), "Xtestout")
645    qall
646  [CODE]
647
648  if RunVim([], after, '')
649    let lines = readfile('Xtestout')
650    call assert_equal(0, len(lines))
651  endif
652
653  if RunVim([], after, 'one')
654    let lines = readfile('Xtestout')
655    call assert_equal(1, len(lines))
656    call assert_equal('one', lines[0])
657  endif
658
659  if RunVim([], after, 'one two three')
660    let lines = readfile('Xtestout')
661    call assert_equal(3, len(lines))
662    call assert_equal('one', lines[0])
663    call assert_equal('two', lines[1])
664    call assert_equal('three', lines[2])
665  endif
666
667  if RunVim([], after, 'one -c echo two')
668    let lines = readfile('Xtestout')
669    call assert_equal(2, len(lines))
670    call assert_equal('one', lines[0])
671    call assert_equal('two', lines[1])
672  endif
673
674  if RunVim([], after, 'one -- -c echo two')
675    let lines = readfile('Xtestout')
676    call assert_equal(4, len(lines))
677    call assert_equal('one', lines[0])
678    call assert_equal('-c', lines[1])
679    call assert_equal('echo', lines[2])
680    call assert_equal('two', lines[3])
681  endif
682
683  call delete('Xtestout')
684endfunc
685
686func Test_startuptime()
687  CheckFeature startuptime
688  let after = ['qall']
689  if RunVim([], after, '--startuptime Xtestout one')
690    let lines = readfile('Xtestout')
691    let expected = ['--- VIM STARTING ---', 'parsing arguments',
692	  \ 'shell init', 'inits 3', 'start termcap', 'opening buffers']
693    let found = []
694    for line in lines
695      for exp in expected
696	if line =~ exp
697	  call add(found, exp)
698	endif
699      endfor
700    endfor
701    call assert_equal(expected, found)
702  endif
703  call delete('Xtestout')
704endfunc
705
706func Test_read_stdin()
707  let after =<< trim [CODE]
708    write Xtestout
709    quit!
710  [CODE]
711
712  if RunVimPiped([], after, '-', 'echo something | ')
713    let lines = readfile('Xtestout')
714    " MS-Windows adds a space after the word
715    call assert_equal(['something'], split(lines[0]))
716  endif
717  call delete('Xtestout')
718endfunc
719
720func Test_set_shell()
721  let after =<< trim [CODE]
722    call writefile([&shell], "Xtestout")
723    quit!
724  [CODE]
725
726  if has('win32')
727    let $SHELL = 'C:\with space\cmd.exe'
728    let expected = '"C:\with space\cmd.exe"'
729  else
730    let $SHELL = '/bin/with space/sh'
731    let expected = '/bin/with\ space/sh'
732  endif
733
734  if RunVimPiped([], after, '', '')
735    let lines = readfile('Xtestout')
736    call assert_equal(expected, lines[0])
737  endif
738  call delete('Xtestout')
739endfunc
740
741func Test_progpath()
742  " Tests normally run with "./vim" or "../vim", these must have been expanded
743  " to a full path.
744  if has('unix')
745    call assert_equal('/', v:progpath[0])
746  elseif has('win32')
747    call assert_equal(':', v:progpath[1])
748    call assert_match('[/\\]', v:progpath[2])
749  endif
750
751  " Only expect "vim" to appear in v:progname.
752  call assert_match('vim\c', v:progname)
753endfunc
754
755func Test_silent_ex_mode()
756  " must be able to get the output of Vim.
757  CheckUnix
758  CheckNotGui
759
760  " This caused an ml_get error.
761  let out = system(GetVimCommand() . '-u NONE -es -c''set verbose=1|h|exe "%norm\<c-y>\<c-d>"'' -c cq')
762  call assert_notmatch('E315:', out)
763endfunc
764
765func Test_default_term()
766  " must be able to get the output of Vim.
767  CheckUnix
768  CheckNotGui
769
770  let save_term = $TERM
771  let $TERM = 'unknownxxx'
772  let out = system(GetVimCommand() . ' -c''set term'' -c cq')
773  call assert_match("defaulting to 'ansi'", out)
774  let $TERM = save_term
775endfunc
776
777func Test_zzz_startinsert()
778  " Test :startinsert
779  call writefile(['123456'], 'Xtestout')
780  let after =<< trim [CODE]
781    :startinsert
782    call feedkeys("foobar\<c-o>:wq\<cr>","t")
783  [CODE]
784
785  if RunVim([], after, 'Xtestout')
786    let lines = readfile('Xtestout')
787    call assert_equal(['foobar123456'], lines)
788  endif
789  " Test :startinsert!
790  call writefile(['123456'], 'Xtestout')
791  let after =<< trim [CODE]
792    :startinsert!
793    call feedkeys("foobar\<c-o>:wq\<cr>","t")
794  [CODE]
795
796  if RunVim([], after, 'Xtestout')
797    let lines = readfile('Xtestout')
798    call assert_equal(['123456foobar'], lines)
799  endif
800  call delete('Xtestout')
801endfunc
802
803func Test_issue_3969()
804  " Can't catch the output of gvim.
805  CheckNotGui
806
807  " Check that message is not truncated.
808  let out = system(GetVimCommand() . ' -es -X -V1 -c "echon ''hello''" -cq')
809  call assert_equal('hello', out)
810endfunc
811
812func Test_start_with_tabs()
813  CheckRunVimInTerminal
814
815  let buf = RunVimInTerminal('-p a b c', {})
816  call VerifyScreenDump(buf, 'Test_start_with_tabs', {})
817
818  " clean up
819  call StopVimInTerminal(buf)
820endfunc
821
822func Test_v_argv()
823  " Can't catch the output of gvim.
824  CheckNotGui
825
826  let out = system(GetVimCommand() . ' -es -V1 -X arg1 --cmd "echo v:argv" --cmd q')
827  let list = out->split("', '")
828  call assert_match('vim', list[0])
829  let idx = index(list, 'arg1')
830  call assert_true(idx > 2)
831  call assert_equal(['arg1', '--cmd', 'echo v:argv', '--cmd', 'q'']'], list[idx:])
832endfunc
833
834" Test for the "-r" recovery mode option
835func Test_r_arg()
836  " Can't catch the output of gvim.
837  CheckNotGui
838  CheckUnix
839  CheckEnglish
840  let cmd = GetVimCommand()
841  " There can be swap files anywhere, only check for the headers.
842  let expected =<< trim END
843    Swap files found:.*
844    In current directory:.*
845    In directory \~/tmp:.*
846    In directory /var/tmp:.*
847    In directory /tmp:.*
848  END
849  call assert_match(join(expected, ""), system(cmd .. " -r")->substitute("[\r\n]\\+", '', ''))
850endfunc
851
852" Test for the '-t' option to jump to a tag
853func Test_t_arg()
854  let before =<< trim [CODE]
855    set tags=Xtags
856  [CODE]
857  let after =<< trim [CODE]
858    let s = bufname('') .. ':L' .. line('.') .. 'C' .. col('.')
859    call writefile([s], "Xtestout")
860    qall
861  [CODE]
862
863  call writefile(["!_TAG_FILE_ENCODING\tutf-8\t//",
864        \ "first\tXfile1\t/^    \\zsfirst$/",
865        \ "second\tXfile1\t/^    \\zssecond$/",
866        \ "third\tXfile1\t/^    \\zsthird$/"],
867        \ 'Xtags')
868  call writefile(['    first', '    second', '    third'], 'Xfile1')
869
870  for t_arg in ['-t second', '-tsecond']
871    if RunVim(before, after, '-t second')
872      call assert_equal(['Xfile1:L2C5'], readfile('Xtestout'), t_arg)
873      call delete('Xtestout')
874    endif
875  endfor
876
877  call delete('Xtags')
878  call delete('Xfile1')
879endfunc
880
881" Test the '-T' argument which sets the 'term' option.
882func Test_T_arg()
883  CheckNotGui
884  let after =<< trim [CODE]
885    call writefile([&term], "Xtest_T_arg")
886    qall
887  [CODE]
888
889  for t in ['builtin_dumb', 'builtin_ansi']
890    if RunVim([], after, '-T ' .. t)
891      let lines = readfile('Xtest_T_arg')
892      call assert_equal([t], lines)
893    endif
894  endfor
895
896  call delete('Xtest_T_arg')
897endfunc
898
899" Test the '-x' argument to read/write encrypted files.
900func Test_x_arg()
901  CheckRunVimInTerminal
902  CheckFeature cryptv
903
904  " Create an encrypted file Xtest_x_arg.
905  let buf = RunVimInTerminal('-n -x Xtest_x_arg', #{rows: 10, wait_for_ruler: 0})
906  call WaitForAssert({-> assert_match('^Enter encryption key: ', term_getline(buf, 10))})
907  call term_sendkeys(buf, "foo\n")
908  call WaitForAssert({-> assert_match('^Enter same key again: ', term_getline(buf, 10))})
909  call term_sendkeys(buf, "foo\n")
910  call WaitForAssert({-> assert_match(' All$', term_getline(buf, 10))})
911  call term_sendkeys(buf, "itest\<Esc>:w\<Enter>")
912  call WaitForAssert({-> assert_match('"Xtest_x_arg" \[New\]\[blowfish2\] 1L, 5B written',
913        \            term_getline(buf, 10))})
914  call StopVimInTerminal(buf)
915
916  " Read the encrypted file and check that it contains the expected content "test"
917  let buf = RunVimInTerminal('-n -x Xtest_x_arg', #{rows: 10, wait_for_ruler: 0})
918  call WaitForAssert({-> assert_match('^Enter encryption key: ', term_getline(buf, 10))})
919  call term_sendkeys(buf, "foo\n")
920  call WaitForAssert({-> assert_match('^Enter same key again: ', term_getline(buf, 10))})
921  call term_sendkeys(buf, "foo\n")
922  call WaitForAssert({-> assert_match('^test', term_getline(buf, 1))})
923  call StopVimInTerminal(buf)
924
925  call delete('Xtest_x_arg')
926endfunc
927
928" Test for entering the insert mode on startup
929func Test_start_insertmode()
930  let before =<< trim [CODE]
931    set insertmode
932  [CODE]
933  let after =<< trim [CODE]
934    call writefile(['insertmode=' .. &insertmode], 'Xtestout')
935    qall
936  [CODE]
937  if RunVim(before, after, '')
938    call assert_equal(['insertmode=1'], readfile('Xtestout'))
939    call delete('Xtestout')
940  endif
941endfunc
942
943" Test for enabling the binary mode on startup
944func Test_b_arg()
945  let after =<< trim [CODE]
946    call writefile(['binary=' .. &binary], 'Xtestout')
947    qall
948  [CODE]
949  if RunVim([], after, '-b')
950    call assert_equal(['binary=1'], readfile('Xtestout'))
951    call delete('Xtestout')
952  endif
953endfunc
954
955" Test for enabling the lisp mode on startup
956func Test_l_arg()
957  let after =<< trim [CODE]
958    let s = 'lisp=' .. &lisp .. ', showmatch=' .. &showmatch
959    call writefile([s], 'Xtestout')
960    qall
961  [CODE]
962  if RunVim([], after, '-l')
963    call assert_equal(['lisp=1, showmatch=1'], readfile('Xtestout'))
964    call delete('Xtestout')
965  endif
966endfunc
967
968" Test for specifying a non-existing vimrc file using "-u"
969func Test_missing_vimrc()
970  CheckRunVimInTerminal
971  let after =<< trim [CODE]
972    call assert_match('^E282:', v:errmsg)
973    call writefile(v:errors, 'Xtestout')
974  [CODE]
975  call writefile(after, 'Xafter')
976
977  let cmd = GetVimCommandCleanTerm() . ' -u Xvimrc_missing -S Xafter'
978  let buf = term_start(cmd, {'term_rows' : 10})
979  call WaitForAssert({-> assert_equal("running", term_getstatus(buf))})
980  call TermWait(buf)
981  call term_sendkeys(buf, "\n:")
982  call TermWait(buf)
983  call WaitForAssert({-> assert_match(':', term_getline(buf, 10))})
984  call StopVimInTerminal(buf)
985  call assert_equal([], readfile('Xtestout'))
986  call delete('Xafter')
987  call delete('Xtestout')
988endfunc
989
990" Test for using the $VIMINIT environment variable
991func Test_VIMINIT()
992  let after =<< trim [CODE]
993    call assert_equal(1, exists('viminit_found'))
994    call assert_equal('yes', viminit_found)
995    call writefile(v:errors, 'Xtestout')
996    qall
997  [CODE]
998  call writefile(after, 'Xafter')
999  let cmd = GetVimProg() . ' --not-a-term -S Xafter --cmd "set enc=utf8"'
1000  call setenv('VIMINIT', 'let viminit_found="yes"')
1001  exe "silent !" . cmd
1002  call assert_equal([], readfile('Xtestout'))
1003  call delete('Xtestout')
1004  call delete('Xafter')
1005endfunc
1006
1007" Test for using the $EXINIT environment variable
1008func Test_EXINIT()
1009  let after =<< trim [CODE]
1010    call assert_equal(1, exists('exinit_found'))
1011    call assert_equal('yes', exinit_found)
1012    call writefile(v:errors, 'Xtestout')
1013    qall
1014  [CODE]
1015  call writefile(after, 'Xafter')
1016  let cmd = GetVimProg() . ' --not-a-term -S Xafter --cmd "set enc=utf8"'
1017  call setenv('EXINIT', 'let exinit_found="yes"')
1018  exe "silent !" . cmd
1019  call assert_equal([], readfile('Xtestout'))
1020  call delete('Xtestout')
1021  call delete('Xafter')
1022endfunc
1023
1024" Test for using the 'exrc' option
1025func Test_exrc()
1026  let after =<< trim [CODE]
1027    call assert_equal(1, &exrc)
1028    call assert_equal(1, &secure)
1029    call assert_equal(37, exrc_found)
1030    call writefile(v:errors, 'Xtestout')
1031    qall
1032  [CODE]
1033  call mkdir('Xdir')
1034  call writefile(['let exrc_found=37'], 'Xdir/.exrc')
1035  call writefile(after, 'Xdir/Xafter')
1036  let cmd = GetVimProg() . ' --not-a-term -S Xafter --cmd "cd Xdir" --cmd "set enc=utf8 exrc secure"'
1037  exe "silent !" . cmd
1038  call assert_equal([], readfile('Xdir/Xtestout'))
1039  call delete('Xdir', 'rf')
1040endfunc
1041
1042" Test for starting Vim with a non-terminal as input/output
1043func Test_io_not_a_terminal()
1044  " Can't catch the output of gvim.
1045  CheckNotGui
1046  CheckUnix
1047  CheckEnglish
1048  let l = systemlist(GetVimProg() .. ' --ttyfail')
1049  call assert_equal(['Vim: Warning: Output is not to a terminal',
1050        \ 'Vim: Warning: Input is not from a terminal'], l)
1051endfunc
1052
1053" Test for --not-a-term avoiding escape codes.
1054func Test_not_a_term()
1055  CheckUnix
1056  CheckNotGui
1057
1058  if &shellredir =~ '%s'
1059    let redir = printf(&shellredir,  'Xvimout')
1060  else
1061    let redir = &shellredir .. ' Xvimout'
1062  endif
1063
1064  " Without --not-a-term there are a few escape sequences.
1065  " This will take 2 seconds because of the missing --not-a-term
1066  let cmd = GetVimProg() .. ' --cmd quit ' .. redir
1067  exe "silent !" . cmd
1068  call assert_match("\<Esc>", readfile('Xvimout')->join())
1069  call delete('Xvimout')
1070
1071  " With --not-a-term there are no escape sequences.
1072  let cmd = GetVimProg() .. ' --not-a-term --cmd quit ' .. redir
1073  exe "silent !" . cmd
1074  call assert_notmatch("\<Esc>", readfile('Xvimout')->join())
1075  call delete('Xvimout')
1076endfunc
1077
1078
1079" Test for the "-w scriptout" argument
1080func Test_w_arg()
1081  " Can't catch the output of gvim.
1082  CheckNotGui
1083
1084  call writefile(["iVim Editor\<Esc>:q!\<CR>"], 'Xscriptin', 'b')
1085  if RunVim([], [], '-s Xscriptin -w Xscriptout')
1086    call assert_equal(["iVim Editor\e:q!\r"], readfile('Xscriptout'))
1087    call delete('Xscriptout')
1088  endif
1089  call delete('Xscriptin')
1090
1091  " Test for failing to open the script output file. This test works only when
1092  " the language is English.
1093  if v:lang == "C" || v:lang =~ '^[Ee]n'
1094    call mkdir("Xdir")
1095    let m = system(GetVimCommand() .. " -w Xdir")
1096    call assert_equal("Cannot open for script output: \"Xdir\"\n", m)
1097    call delete("Xdir", 'rf')
1098  endif
1099
1100  " A number argument sets the 'window' option
1101  call writefile(["iwindow \<C-R>=&window\<CR>\<Esc>:wq! Xresult\<CR>"], 'Xscriptin', 'b')
1102  for w_arg in ['-w 17', '-w17']
1103    if RunVim([], [], '-s Xscriptin ' .. w_arg)
1104      call assert_equal(["window 17"], readfile('Xresult'), w_arg)
1105      call delete('Xresult')
1106    endif
1107  endfor
1108  call delete('Xscriptin')
1109endfunc
1110
1111" Test for the "-s scriptin" argument
1112func Test_s_arg()
1113  " Can't catch the output of gvim.
1114  CheckNotGui
1115  CheckEnglish
1116  " Test for failing to open the script input file.
1117  let m = system(GetVimCommand() .. " -s abcxyz")
1118  call assert_equal("Cannot open for reading: \"abcxyz\"\n", m)
1119
1120  call writefile([], 'Xinput')
1121  let m = system(GetVimCommand() .. " -s Xinput -s Xinput")
1122  call assert_equal("Attempt to open script file again: \"-s Xinput\"\n", m)
1123  call delete('Xinput')
1124endfunc
1125
1126" Test for the "-n" (no swap file) argument
1127func Test_n_arg()
1128  let after =<< trim [CODE]
1129    call assert_equal(0, &updatecount)
1130    call writefile(v:errors, 'Xtestout')
1131    qall
1132  [CODE]
1133  if RunVim([], after, '-n')
1134    call assert_equal([], readfile('Xtestout'))
1135    call delete('Xtestout')
1136  endif
1137endfunc
1138
1139" Test for the "-h" (help) argument
1140func Test_h_arg()
1141  " Can't catch the output of gvim.
1142  CheckNotGui
1143  let l = systemlist(GetVimProg() .. ' -h')
1144  call assert_match('^VIM - Vi IMproved', l[0])
1145  let l = systemlist(GetVimProg() .. ' -?')
1146  call assert_match('^VIM - Vi IMproved', l[0])
1147endfunc
1148
1149" Test for the "-F" (farsi) argument
1150func Test_F_arg()
1151  " Can't catch the output of gvim.
1152  CheckNotGui
1153  let l = systemlist(GetVimProg() .. ' -F')
1154  call assert_match('^E27:', l[0])
1155endfunc
1156
1157" Test for the "-E" (improved Ex mode) argument
1158func Test_E_arg()
1159  let after =<< trim [CODE]
1160    call assert_equal('cv', mode(1))
1161    call writefile(v:errors, 'Xtestout')
1162    qall
1163  [CODE]
1164  if RunVim([], after, '-E')
1165    call assert_equal([], readfile('Xtestout'))
1166    call delete('Xtestout')
1167  endif
1168endfunc
1169
1170" Test for the "-D" (debugger) argument
1171func Test_D_arg()
1172  CheckRunVimInTerminal
1173
1174  let cmd = GetVimCommandCleanTerm() .. ' -D'
1175  let buf = term_start(cmd, {'term_rows' : 10})
1176  call WaitForAssert({-> assert_equal("running", term_getstatus(buf))})
1177
1178  call WaitForAssert({-> assert_equal('Entering Debug mode.  Type "cont" to continue.',
1179  \                  term_getline(buf, 7))})
1180  call WaitForAssert({-> assert_equal('>', term_getline(buf, 10))})
1181
1182  call StopVimInTerminal(buf)
1183endfunc
1184
1185" Test for too many edit argument errors
1186func Test_too_many_edit_args()
1187  " Can't catch the output of gvim.
1188  CheckNotGui
1189  CheckEnglish
1190  let l = systemlist(GetVimProg() .. ' - -')
1191  call assert_match('^Too many edit arguments: "-"', l[1])
1192endfunc
1193
1194" Test starting vim with various names: vim, ex, view, evim, etc.
1195func Test_progname()
1196  CheckUnix
1197
1198  call mkdir('Xprogname', 'p')
1199  call writefile(['silent !date',
1200  \               'call writefile([mode(1), '
1201  \               .. '&insertmode, &diff, &readonly, &updatecount, '
1202  \               .. 'join(split(execute("message"), "\n")[1:])], "Xprogname_out")',
1203  \               'qall'], 'Xprogname_after')
1204
1205  "  +---------------------------------------------- progname
1206  "  |            +--------------------------------- mode(1)
1207  "  |            |     +--------------------------- &insertmode
1208  "  |            |     |    +---------------------- &diff
1209  "  |            |     |    |    +----------------- &readonly
1210  "  |            |     |    |    |        +-------- &updatecount
1211  "  |            |     |    |    |        |    +--- :messages
1212  "  |            |     |    |    |        |    |
1213  let expectations = {
1214  \ 'vim':      ['n',  '0', '0', '0',   '200', ''],
1215  \ 'gvim':     ['n',  '0', '0', '0',   '200', ''],
1216  \ 'ex':       ['ce', '0', '0', '0',   '200', ''],
1217  \ 'exim':     ['cv', '0', '0', '0',   '200', ''],
1218  \ 'view':     ['n',  '0', '0', '1', '10000', ''],
1219  \ 'gview':    ['n',  '0', '0', '1', '10000', ''],
1220  \ 'evim':     ['n',  '1', '0', '0',   '200', ''],
1221  \ 'eview':    ['n',  '1', '0', '1', '10000', ''],
1222  \ 'rvim':     ['n',  '0', '0', '0',   '200', 'line    1: E145: Shell commands and some functionality not allowed in rvim'],
1223  \ 'rgvim':    ['n',  '0', '0', '0',   '200', 'line    1: E145: Shell commands and some functionality not allowed in rvim'],
1224  \ 'rview':    ['n',  '0', '0', '1', '10000', 'line    1: E145: Shell commands and some functionality not allowed in rvim'],
1225  \ 'rgview':   ['n',  '0', '0', '1', '10000', 'line    1: E145: Shell commands and some functionality not allowed in rvim'],
1226  \ 'vimdiff':  ['n',  '0', '1', '0',   '200', ''],
1227  \ 'gvimdiff': ['n',  '0', '1', '0',   '200', '']}
1228
1229  let prognames = ['vim', 'gvim', 'ex', 'exim', 'view', 'gview',
1230  \                'evim', 'eview', 'rvim', 'rgvim', 'rview', 'rgview',
1231  \                'vimdiff', 'gvimdiff']
1232
1233  for progname in prognames
1234    let run_with_gui = (progname =~# 'g') || (has('gui') && (progname ==# 'evim' || progname ==# 'eview'))
1235
1236    if empty($DISPLAY) && run_with_gui
1237      " Can't run gvim, gview  (etc.) if $DISPLAY is not setup.
1238      continue
1239    endif
1240
1241    exe 'silent !ln -s -f ' ..exepath(GetVimProg()) .. ' Xprogname/' .. progname
1242
1243    let stdout_stderr = ''
1244    if progname =~# 'g'
1245      let stdout_stderr = system('Xprogname/'..progname..' -f --clean --not-a-term -S Xprogname_after')
1246    else
1247      exe 'sil !Xprogname/'..progname..' -f --clean --not-a-term -S Xprogname_after'
1248    endif
1249
1250    if progname =~# 'g' && !has('gui')
1251      call assert_equal("E25: GUI cannot be used: Not enabled at compile time\n", stdout_stderr, progname)
1252    else
1253      " GUI motif can output some warnings like this:
1254      "   Warning:
1255      "       Name: subMenu
1256      "       Class: XmCascadeButton
1257      "       Illegal mnemonic character;  Could not convert X KEYSYM to a keycode
1258      " So don't check that stderr is empty with GUI Motif.
1259      if run_with_gui && !has('gui_motif')
1260        call assert_equal('', stdout_stderr, progname)
1261      endif
1262      call assert_equal(expectations[progname], readfile('Xprogname_out'), progname)
1263    endif
1264
1265    call delete('Xprogname/' .. progname)
1266    call delete('Xprogname_out')
1267  endfor
1268
1269  call delete('Xprogname_after')
1270  call delete('Xprogname', 'd')
1271endfunc
1272
1273" Test for doing a write from .vimrc
1274func Test_write_in_vimrc()
1275  call writefile(['silent! write'], 'Xvimrc')
1276  let after =<< trim [CODE]
1277    call assert_match('E32: ', v:errmsg)
1278    call writefile(v:errors, 'Xtestout')
1279    qall
1280  [CODE]
1281  if RunVim([], after, '-u Xvimrc')
1282    call assert_equal([], readfile('Xtestout'))
1283    call delete('Xtestout')
1284  endif
1285  call delete('Xvimrc')
1286endfunc
1287
1288" vim: shiftwidth=2 sts=2 expandtab
1289