robin/laufey

git clone https://git.robinwobin.dev/robin/laufey

Justin M. Keyesrefactor(exmode): Ex-mode as cmdwin + Lua #40991359459dec6

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