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