xref: /vim-8.2.3635/src/testdir/test_startup.vim (revision ceb56ddb)
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  if !has('packages')
25    return
26  endif
27  let before =<< trim [CODE]
28    set nocp viminfo+=nviminfo
29    set guioptions+=M
30    let $HOME = "/does/not/exist"
31    set loadplugins
32    set rtp=Xhere,Xafter,Xanother
33    set packpath=Xhere,Xafter
34    set nomore
35    let g:sequence = ""
36  [CODE]
37
38  let after =<< trim [CODE]
39    redir! > Xtestout
40    scriptnames
41    redir END
42    redir! > Xsequence
43    echo g:sequence
44    redir END
45    quit
46  [CODE]
47
48  call mkdir('Xhere/plugin', 'p')
49  call writefile(['let g:sequence .= "here "'], 'Xhere/plugin/here.vim')
50  call mkdir('Xanother/plugin', 'p')
51  call writefile(['let g:sequence .= "another "'], 'Xanother/plugin/another.vim')
52  call mkdir('Xhere/pack/foo/start/foobar/plugin', 'p')
53  call writefile(['let g:sequence .= "pack "'], 'Xhere/pack/foo/start/foobar/plugin/foo.vim')
54
55  call mkdir('Xafter/plugin', 'p')
56  call writefile(['let g:sequence .= "after "'], 'Xafter/plugin/later.vim')
57
58  if RunVim(before, after, '')
59
60    let lines = readfile('Xtestout')
61    let expected = ['Xbefore.vim', 'here.vim', 'another.vim', 'foo.vim', 'later.vim', 'Xafter.vim']
62    let found = []
63    for line in lines
64      for one in expected
65	if line =~ one
66	  call add(found, one)
67	endif
68      endfor
69    endfor
70    call assert_equal(expected, found)
71  endif
72
73  call assert_equal('here another pack after', substitute(join(readfile('Xsequence', 1), ''), '\s\+$', '', ''))
74
75  call delete('Xtestout')
76  call delete('Xsequence')
77  call delete('Xhere', 'rf')
78  call delete('Xanother', 'rf')
79  call delete('Xafter', 'rf')
80endfunc
81
82func Test_pack_in_rtp_when_plugins_run()
83  if !has('packages')
84    return
85  endif
86  let before =<< trim [CODE]
87    set nocp viminfo+=nviminfo
88    set guioptions+=M
89    let $HOME = "/does/not/exist"
90    set loadplugins
91    set rtp=Xhere
92    set packpath=Xhere
93    set nomore
94  [CODE]
95
96  let after = [
97	\ 'quit',
98	\ ]
99  call mkdir('Xhere/plugin', 'p')
100  call writefile(['redir! > Xtestout', 'silent set runtimepath?', 'silent! call foo#Trigger()', 'redir END'], 'Xhere/plugin/here.vim')
101  call mkdir('Xhere/pack/foo/start/foobar/autoload', 'p')
102  call writefile(['function! foo#Trigger()', 'echo "autoloaded foo"', 'endfunction'], 'Xhere/pack/foo/start/foobar/autoload/foo.vim')
103
104  if RunVim(before, after, '')
105
106    let lines = filter(readfile('Xtestout'), '!empty(v:val)')
107    call assert_match('Xhere[/\\]pack[/\\]foo[/\\]start[/\\]foobar', get(lines, 0))
108    call assert_match('autoloaded foo', get(lines, 1))
109  endif
110
111  call delete('Xtestout')
112  call delete('Xhere', 'rf')
113endfunc
114
115func Test_help_arg()
116  if !has('unix') && has('gui')
117    " this doesn't work with gvim on MS-Windows
118    return
119  endif
120  if RunVim([], [], '--help >Xtestout')
121    let lines = readfile('Xtestout')
122    call assert_true(len(lines) > 20)
123    call assert_match('Vi IMproved', lines[0])
124
125    " check if  couple of lines are there
126    let found = []
127    for line in lines
128      if line =~ '-R.*Readonly mode'
129	call add(found, 'Readonly mode')
130      endif
131      " Watch out for a second --version line in the Gnome version.
132      if line =~ '--version.*Print version information and exit'
133	call add(found, "--version")
134      endif
135    endfor
136    call assert_equal(['Readonly mode', '--version'], found)
137  endif
138  call delete('Xtestout')
139endfunc
140
141func Test_compatible_args()
142  let after =<< trim [CODE]
143    call writefile([string(&compatible)], "Xtestout")
144    set viminfo+=nviminfo
145    quit
146  [CODE]
147
148  if RunVim([], after, '-C')
149    let lines = readfile('Xtestout')
150    call assert_equal('1', lines[0])
151  endif
152
153  if RunVim([], after, '-N')
154    let lines = readfile('Xtestout')
155    call assert_equal('0', lines[0])
156  endif
157
158  call delete('Xtestout')
159endfunc
160
161" Test the -o[N] and -O[N] arguments to open N windows split
162" horizontally or vertically.
163func Test_o_arg()
164  let after =<< trim [CODE]
165    set cpo&vim
166    call writefile([winnr("$"),
167		\ winheight(1), winheight(2), &lines,
168		\ winwidth(1), winwidth(2), &columns,
169		\ bufname(winbufnr(1)), bufname(winbufnr(2))],
170		\ "Xtestout")
171    qall
172  [CODE]
173
174  if RunVim([], after, '-o2')
175    " Open 2 windows split horizontally. Expect:
176    " - 2 windows
177    " - both windows should have the same or almost the same height
178    " - sum of both windows height (+ 3 for both statusline and Ex command)
179    "   should be equal to the number of lines
180    " - both windows should have the same width which should be equal to the
181    "   number of columns
182    " - buffer of both windows should have no name
183    let [wn, wh1, wh2, ln, ww1, ww2, cn, bn1, bn2] = readfile('Xtestout')
184    call assert_equal('2', wn)
185    call assert_inrange(0, 1, wh1 - wh2)
186    call assert_equal(string(wh1 + wh2 + 3), ln)
187    call assert_equal(ww1, ww2)
188    call assert_equal(ww1, cn)
189    call assert_equal('', bn1)
190    call assert_equal('', bn2)
191  endif
192
193  if RunVim([], after, '-o foo bar')
194    " Same expectations as for -o2 but buffer names should be foo and bar
195    let [wn, wh1, wh2, ln, ww1, ww2, cn, bn1, bn2] = readfile('Xtestout')
196    call assert_equal('2', wn)
197    call assert_inrange(0, 1, wh1 - wh2)
198    call assert_equal(string(wh1 + wh2 + 3), ln)
199    call assert_equal(ww1, ww2)
200    call assert_equal(ww1, cn)
201    call assert_equal('foo', bn1)
202    call assert_equal('bar', bn2)
203  endif
204
205  if RunVim([], after, '-O2')
206    " Open 2 windows split vertically. Expect:
207    " - 2 windows
208    " - both windows should have the same or almost the same width
209    " - sum of both windows width (+ 1 for the separator) should be equal to
210    "   the number of columns
211    " - both windows should have the same height
212    " - window height (+ 2 for the statusline and Ex command) should be equal
213    "   to the number of lines
214    " - buffer of both windows should have no name
215    let [wn, wh1, wh2, ln, ww1, ww2, cn, bn1, bn2] = readfile('Xtestout')
216    call assert_equal('2', wn)
217    call assert_inrange(0, 1, ww1 - ww2)
218    call assert_equal(string(ww1 + ww2 + 1), cn)
219    call assert_equal(wh1, wh2)
220    call assert_equal(string(wh1 + 2), ln)
221    call assert_equal('', bn1)
222    call assert_equal('', bn2)
223  endif
224
225  if RunVim([], after, '-O foo bar')
226    " Same expectations as for -O2 but buffer names should be foo and bar
227    let [wn, wh1, wh2, ln, ww1, ww2, cn, bn1, bn2] = readfile('Xtestout')
228    call assert_equal('2', wn)
229    call assert_inrange(0, 1, ww1 - ww2)
230    call assert_equal(string(ww1 + ww2 + 1), cn)
231    call assert_equal(wh1, wh2)
232    call assert_equal(string(wh1 + 2), ln)
233    call assert_equal('foo', bn1)
234    call assert_equal('bar', bn2)
235  endif
236
237  call delete('Xtestout')
238endfunc
239
240" Test the -p[N] argument to open N tabpages.
241func Test_p_arg()
242  let after =<< trim [CODE]
243    call writefile(split(execute("tabs"), "\n"), "Xtestout")
244    qall
245  [CODE]
246
247  if RunVim([], after, '-p2')
248    let lines = readfile('Xtestout')
249    call assert_equal(4, len(lines))
250    call assert_equal('Tab page 1',    lines[0])
251    call assert_equal('>   [No Name]', lines[1])
252    call assert_equal('Tab page 2',    lines[2])
253    call assert_equal('    [No Name]', lines[3])
254  endif
255
256  if RunVim([], after, '-p foo bar')
257    let lines = readfile('Xtestout')
258    call assert_equal(4, len(lines))
259    call assert_equal('Tab page 1', lines[0])
260    call assert_equal('>   foo',    lines[1])
261    call assert_equal('Tab page 2', lines[2])
262    call assert_equal('    bar',    lines[3])
263  endif
264
265  call delete('Xtestout')
266endfunc
267
268" Test the -V[N] argument to set the 'verbose' option to [N]
269func Test_V_arg()
270  " Can't catch the output of gvim.
271  CheckNotGui
272
273  let out = system(GetVimCommand() . ' --clean -es -X -V0 -c "set verbose?" -cq')
274  call assert_equal("  verbose=0\n", out)
275
276  let out = system(GetVimCommand() . ' --clean -es -X -V2 -c "set verbose?" -cq')
277  call assert_match("sourcing \"$VIMRUNTIME[\\/]defaults\.vim\"\r\nline \\d\\+: sourcing \"[^\"]*runtime[\\/]filetype\.vim\".*\n", out)
278  call assert_match("  verbose=2\n", out)
279
280  let out = system(GetVimCommand() . ' --clean -es -X -V15 -c "set verbose?" -cq')
281   call assert_match("sourcing \"$VIMRUNTIME[\\/]defaults\.vim\"\r\nline 1: \" The default vimrc file\..*  verbose=15\n", out)
282endfunc
283
284" Test the '-q [errorfile]' argument.
285func Test_q_arg()
286  CheckFeature quickfix
287
288  let source_file = has('win32') ? '..\memfile.c' : '../memfile.c'
289  let after =<< trim [CODE]
290    call writefile([&errorfile, string(getpos("."))], "Xtestout")
291    copen
292    w >> Xtestout
293    qall
294  [CODE]
295
296  " Test with default argument '-q'.
297  call assert_equal('errors.err', &errorfile)
298  call writefile(["../memfile.c:208:5: error: expected ';' before '}' token"], 'errors.err')
299  if RunVim([], after, '-q')
300    let lines = readfile('Xtestout')
301    call assert_equal(['errors.err',
302	\              '[0, 208, 5, 0]',
303	\              source_file . "|208 col 5| error: expected ';' before '}' token"],
304	\             lines)
305  endif
306  call delete('Xtestout')
307  call delete('errors.err')
308
309  " Test with explicit argument '-q Xerrors' (with space).
310  call writefile(["../memfile.c:208:5: error: expected ';' before '}' token"], 'Xerrors')
311  if RunVim([], after, '-q Xerrors')
312    let lines = readfile('Xtestout')
313    call assert_equal(['Xerrors',
314	\              '[0, 208, 5, 0]',
315	\              source_file . "|208 col 5| error: expected ';' before '}' token"],
316	\             lines)
317  endif
318  call delete('Xtestout')
319
320  " Test with explicit argument '-qXerrors' (without space).
321  if RunVim([], after, '-qXerrors')
322    let lines = readfile('Xtestout')
323    call assert_equal(['Xerrors',
324	\              '[0, 208, 5, 0]',
325	\              source_file . "|208 col 5| error: expected ';' before '}' token"],
326	\             lines)
327  endif
328
329  " Test with a non-existing error file (exits with value 3)
330  let out = system(GetVimCommand() .. ' -q xyz.err')
331  call assert_equal(3, v:shell_error)
332
333  call delete('Xtestout')
334  call delete('Xerrors')
335endfunc
336
337" Test the -V[N]{filename} argument to set the 'verbose' option to N
338" and set 'verbosefile' to filename.
339func Test_V_file_arg()
340  if RunVim([], [], ' --clean -V2Xverbosefile -c "set verbose? verbosefile?" -cq')
341    let out = join(readfile('Xverbosefile'), "\n")
342    call assert_match("sourcing \"$VIMRUNTIME[\\/]defaults\.vim\"\n", out)
343    call assert_match("\n  verbose=2\n", out)
344    call assert_match("\n  verbosefile=Xverbosefile", out)
345  endif
346
347  call delete('Xverbosefile')
348endfunc
349
350" Test the -m, -M and -R arguments:
351" -m resets 'write'
352" -M resets 'modifiable' and 'write'
353" -R sets 'readonly'
354func Test_m_M_R()
355  let after =<< trim [CODE]
356    call writefile([&write, &modifiable, &readonly, &updatecount], "Xtestout")
357    qall
358  [CODE]
359
360  if RunVim([], after, '')
361    let lines = readfile('Xtestout')
362    call assert_equal(['1', '1', '0', '200'], lines)
363  endif
364  if RunVim([], after, '-m')
365    let lines = readfile('Xtestout')
366    call assert_equal(['0', '1', '0', '200'], lines)
367  endif
368  if RunVim([], after, '-M')
369    let lines = readfile('Xtestout')
370    call assert_equal(['0', '0', '0', '200'], lines)
371  endif
372  if RunVim([], after, '-R')
373    let lines = readfile('Xtestout')
374    call assert_equal(['1', '1', '1', '10000'], lines)
375  endif
376
377  call delete('Xtestout')
378endfunc
379
380" Test the -A, -F and -H arguments (Arabic, Farsi and Hebrew modes).
381func Test_A_F_H_arg()
382  let after =<< trim [CODE]
383    call writefile([&rightleft, &arabic, &fkmap, &hkmap], "Xtestout")
384    qall
385  [CODE]
386
387  " Use silent Ex mode to avoid the hit-Enter prompt for the warning that
388  " 'encoding' is not utf-8.
389  if has('arabic') && &encoding == 'utf-8' && RunVim([], after, '-e -s -A')
390    let lines = readfile('Xtestout')
391    call assert_equal(['1', '1', '0', '0'], lines)
392  endif
393
394  if has('farsi') && RunVim([], after, '-F')
395    let lines = readfile('Xtestout')
396    call assert_equal(['1', '0', '1', '0'], lines)
397  endif
398
399  if has('rightleft') && RunVim([], after, '-H')
400    let lines = readfile('Xtestout')
401    call assert_equal(['1', '0', '0', '1'], lines)
402  endif
403
404  call delete('Xtestout')
405endfunc
406
407func Test_invalid_args()
408  " must be able to get the output of Vim.
409  CheckUnix
410  CheckNotGui
411
412  for opt in ['-Y', '--does-not-exist']
413    let out = split(system(GetVimCommand() .. ' ' .. opt), "\n")
414    call assert_equal(1, v:shell_error)
415    call assert_match('^VIM - Vi IMproved .* (.*)$',              out[0])
416    call assert_equal('Unknown option argument: "' .. opt .. '"', out[1])
417    call assert_equal('More info with: "vim -h"',                 out[2])
418  endfor
419
420  for opt in ['-c', '-i', '-s', '-t', '-T', '-u', '-U', '-w', '-W', '--cmd', '--startuptime']
421    let out = split(system(GetVimCommand() .. ' '  .. opt), "\n")
422    call assert_equal(1, v:shell_error)
423    call assert_match('^VIM - Vi IMproved .* (.*)$',             out[0])
424    call assert_equal('Argument missing after: "' .. opt .. '"', out[1])
425    call assert_equal('More info with: "vim -h"',                out[2])
426  endfor
427
428  if has('clientserver')
429    for opt in ['--remote', '--remote-send', '--remote-silent', '--remote-expr',
430          \     '--remote-tab', '--remote-tab-wait',
431          \     '--remote-tab-wait-silent', '--remote-tab-silent',
432          \     '--remote-wait', '--remote-wait-silent',
433          \     '--servername',
434          \    ]
435      let out = split(system(GetVimCommand() .. ' '  .. opt), "\n")
436      call assert_equal(1, v:shell_error)
437      call assert_match('^VIM - Vi IMproved .* (.*)$',             out[0])
438      call assert_equal('Argument missing after: "' .. opt .. '"', out[1])
439      call assert_equal('More info with: "vim -h"',                out[2])
440    endfor
441  endif
442
443  if has('gui_gtk')
444    let out = split(system(GetVimCommand() .. ' --display'), "\n")
445    call assert_equal(1, v:shell_error)
446    call assert_match('^VIM - Vi IMproved .* (.*)$',         out[0])
447    call assert_equal('Argument missing after: "--display"', out[1])
448    call assert_equal('More info with: "vim -h"',            out[2])
449  endif
450
451  if has('xterm_clipboard')
452    let out = split(system(GetVimCommand() .. ' -display'), "\n")
453    call assert_equal(1, v:shell_error)
454    call assert_match('^VIM - Vi IMproved .* (.*)$',         out[0])
455    call assert_equal('Argument missing after: "-display"', out[1])
456    call assert_equal('More info with: "vim -h"',            out[2])
457  endif
458
459  let out = split(system(GetVimCommand() .. ' -ix'), "\n")
460  call assert_equal(1, v:shell_error)
461  call assert_match('^VIM - Vi IMproved .* (.*)$',          out[0])
462  call assert_equal('Garbage after option argument: "-ix"', out[1])
463  call assert_equal('More info with: "vim -h"',             out[2])
464
465  let out = split(system(GetVimCommand() .. ' - xxx'), "\n")
466  call assert_equal(1, v:shell_error)
467  call assert_match('^VIM - Vi IMproved .* (.*)$',    out[0])
468  call assert_equal('Too many edit arguments: "xxx"', out[1])
469  call assert_equal('More info with: "vim -h"',       out[2])
470
471  if has('quickfix')
472    " Detect invalid repeated arguments '-t foo -t foo", '-q foo -q foo'.
473    for opt in ['-t', '-q']
474      let out = split(system(GetVimCommand() .. repeat(' ' .. opt .. ' foo', 2)), "\n")
475      call assert_equal(1, v:shell_error)
476      call assert_match('^VIM - Vi IMproved .* (.*)$',              out[0])
477      call assert_equal('Too many edit arguments: "' .. opt .. '"', out[1])
478      call assert_equal('More info with: "vim -h"',                 out[2])
479    endfor
480  endif
481
482  for opt in [' -cq', ' --cmd q', ' +', ' -S foo']
483    let out = split(system(GetVimCommand() .. repeat(opt, 11)), "\n")
484    call assert_equal(1, v:shell_error)
485    " FIXME: The error message given by Vim is not ideal in case of repeated
486    " -S foo since it does not mention -S.
487    call assert_match('^VIM - Vi IMproved .* (.*)$',                                    out[0])
488    call assert_equal('Too many "+command", "-c command" or "--cmd command" arguments', out[1])
489    call assert_equal('More info with: "vim -h"',                                       out[2])
490  endfor
491
492  if has('gui_gtk')
493    for opt in ['--socketid x', '--socketid 0xg']
494      let out = split(system(GetVimCommand() .. ' ' .. opt), "\n")
495      call assert_equal(1, v:shell_error)
496      call assert_match('^VIM - Vi IMproved .* (.*)$',        out[0])
497      call assert_equal('Invalid argument for: "--socketid"', out[1])
498      call assert_equal('More info with: "vim -h"',           out[2])
499    endfor
500  endif
501endfunc
502
503func Test_file_args()
504  let after =<< trim [CODE]
505    call writefile(argv(), "Xtestout")
506    qall
507  [CODE]
508
509  if RunVim([], after, '')
510    let lines = readfile('Xtestout')
511    call assert_equal(0, len(lines))
512  endif
513
514  if RunVim([], after, 'one')
515    let lines = readfile('Xtestout')
516    call assert_equal(1, len(lines))
517    call assert_equal('one', lines[0])
518  endif
519
520  if RunVim([], after, 'one two three')
521    let lines = readfile('Xtestout')
522    call assert_equal(3, len(lines))
523    call assert_equal('one', lines[0])
524    call assert_equal('two', lines[1])
525    call assert_equal('three', lines[2])
526  endif
527
528  if RunVim([], after, 'one -c echo two')
529    let lines = readfile('Xtestout')
530    call assert_equal(2, len(lines))
531    call assert_equal('one', lines[0])
532    call assert_equal('two', lines[1])
533  endif
534
535  if RunVim([], after, 'one -- -c echo two')
536    let lines = readfile('Xtestout')
537    call assert_equal(4, len(lines))
538    call assert_equal('one', lines[0])
539    call assert_equal('-c', lines[1])
540    call assert_equal('echo', lines[2])
541    call assert_equal('two', lines[3])
542  endif
543
544  call delete('Xtestout')
545endfunc
546
547func Test_startuptime()
548  if !has('startuptime')
549    return
550  endif
551  let after = ['qall']
552  if RunVim([], after, '--startuptime Xtestout one')
553    let lines = readfile('Xtestout')
554    let expected = ['--- VIM STARTING ---', 'parsing arguments',
555	  \ 'shell init', 'inits 3', 'start termcap', 'opening buffers']
556    let found = []
557    for line in lines
558      for exp in expected
559	if line =~ exp
560	  call add(found, exp)
561	endif
562      endfor
563    endfor
564    call assert_equal(expected, found)
565  endif
566  call delete('Xtestout')
567endfunc
568
569func Test_read_stdin()
570  let after =<< trim [CODE]
571    write Xtestout
572    quit!
573  [CODE]
574
575  if RunVimPiped([], after, '-', 'echo something | ')
576    let lines = readfile('Xtestout')
577    " MS-Windows adds a space after the word
578    call assert_equal(['something'], split(lines[0]))
579  endif
580  call delete('Xtestout')
581endfunc
582
583func Test_set_shell()
584  let after =<< trim [CODE]
585    call writefile([&shell], "Xtestout")
586    quit!
587  [CODE]
588
589  if has('win32')
590    let $SHELL = 'C:\with space\cmd.exe'
591    let expected = '"C:\with space\cmd.exe"'
592  else
593    let $SHELL = '/bin/with space/sh'
594    let expected = '/bin/with\ space/sh'
595  endif
596
597  if RunVimPiped([], after, '', '')
598    let lines = readfile('Xtestout')
599    call assert_equal(expected, lines[0])
600  endif
601  call delete('Xtestout')
602endfunc
603
604func Test_progpath()
605  " Tests normally run with "./vim" or "../vim", these must have been expanded
606  " to a full path.
607  if has('unix')
608    call assert_equal('/', v:progpath[0])
609  elseif has('win32')
610    call assert_equal(':', v:progpath[1])
611    call assert_match('[/\\]', v:progpath[2])
612  endif
613
614  " Only expect "vim" to appear in v:progname.
615  call assert_match('vim\c', v:progname)
616endfunc
617
618func Test_silent_ex_mode()
619  " must be able to get the output of Vim.
620  CheckUnix
621  CheckNotGui
622
623  " This caused an ml_get error.
624  let out = system(GetVimCommand() . '-u NONE -es -c''set verbose=1|h|exe "%norm\<c-y>\<c-d>"'' -c cq')
625  call assert_notmatch('E315:', out)
626endfunc
627
628func Test_default_term()
629  " must be able to get the output of Vim.
630  CheckUnix
631  CheckNotGui
632
633  let save_term = $TERM
634  let $TERM = 'unknownxxx'
635  let out = system(GetVimCommand() . ' -c''set term'' -c cq')
636  call assert_match("defaulting to 'ansi'", out)
637  let $TERM = save_term
638endfunc
639
640func Test_zzz_startinsert()
641  " Test :startinsert
642  call writefile(['123456'], 'Xtestout')
643  let after =<< trim [CODE]
644    :startinsert
645    call feedkeys("foobar\<c-o>:wq\<cr>","t")
646  [CODE]
647
648  if RunVim([], after, 'Xtestout')
649    let lines = readfile('Xtestout')
650    call assert_equal(['foobar123456'], lines)
651  endif
652  " Test :startinsert!
653  call writefile(['123456'], 'Xtestout')
654  let after =<< trim [CODE]
655    :startinsert!
656    call feedkeys("foobar\<c-o>:wq\<cr>","t")
657  [CODE]
658
659  if RunVim([], after, 'Xtestout')
660    let lines = readfile('Xtestout')
661    call assert_equal(['123456foobar'], lines)
662  endif
663  call delete('Xtestout')
664endfunc
665
666func Test_issue_3969()
667  " Can't catch the output of gvim.
668  CheckNotGui
669
670  " Check that message is not truncated.
671  let out = system(GetVimCommand() . ' -es -X -V1 -c "echon ''hello''" -cq')
672  call assert_equal('hello', out)
673endfunc
674
675func Test_start_with_tabs()
676  CheckRunVimInTerminal
677
678  let buf = RunVimInTerminal('-p a b c', {})
679  call VerifyScreenDump(buf, 'Test_start_with_tabs', {})
680
681  " clean up
682  call StopVimInTerminal(buf)
683endfunc
684
685func Test_v_argv()
686  " Can't catch the output of gvim.
687  CheckNotGui
688
689  let out = system(GetVimCommand() . ' -es -V1 -X arg1 --cmd "echo v:argv" --cmd q')
690  let list = out->split("', '")
691  call assert_match('vim', list[0])
692  let idx = index(list, 'arg1')
693  call assert_true(idx > 2)
694  call assert_equal(['arg1', '--cmd', 'echo v:argv', '--cmd', 'q'']'], list[idx:])
695endfunc
696
697" Test for the "-r" recovery mode option
698func Test_r_arg()
699  " Can't catch the output of gvim.
700  CheckNotGui
701  CheckUnix
702  CheckEnglish
703  let cmd = GetVimCommand()
704  " There can be swap files anywhere, only check for the headers.
705  let expected =<< trim END
706    Swap files found:.*
707    In current directory:.*
708    In directory \~/tmp:.*
709    In directory /var/tmp:.*
710    In directory /tmp:.*
711  END
712  call assert_match(join(expected, ""), system(cmd .. " -r")->substitute("[\r\n]\\+", '', ''))
713endfunc
714
715" Test for the '-t' option to jump to a tag
716func Test_t_arg()
717  let before =<< trim [CODE]
718    set tags=Xtags
719  [CODE]
720  let after =<< trim [CODE]
721    let s = bufname('') .. ':L' .. line('.') .. 'C' .. col('.')
722    call writefile([s], "Xtestout")
723    qall
724  [CODE]
725
726  call writefile(["!_TAG_FILE_ENCODING\tutf-8\t//",
727        \ "first\tXfile1\t/^    \\zsfirst$/",
728        \ "second\tXfile1\t/^    \\zssecond$/",
729        \ "third\tXfile1\t/^    \\zsthird$/"],
730        \ 'Xtags')
731  call writefile(['    first', '    second', '    third'], 'Xfile1')
732
733  if RunVim(before, after, '-t second')
734    call assert_equal(['Xfile1:L2C5'], readfile('Xtestout'))
735    call delete('Xtestout')
736  endif
737
738  call delete('Xtags')
739  call delete('Xfile1')
740endfunc
741
742" Test for entering the insert mode on startup
743func Test_start_insertmode()
744  let before =<< trim [CODE]
745    set insertmode
746  [CODE]
747  let after =<< trim [CODE]
748    call writefile(['insertmode=' .. &insertmode], 'Xtestout')
749    qall
750  [CODE]
751  if RunVim(before, after, '')
752    call assert_equal(['insertmode=1'], readfile('Xtestout'))
753    call delete('Xtestout')
754  endif
755endfunc
756
757" Test for enabling the binary mode on startup
758func Test_b_arg()
759  let after =<< trim [CODE]
760    call writefile(['binary=' .. &binary], 'Xtestout')
761    qall
762  [CODE]
763  if RunVim([], after, '-b')
764    call assert_equal(['binary=1'], readfile('Xtestout'))
765    call delete('Xtestout')
766  endif
767endfunc
768
769" Test for enabling the lisp mode on startup
770func Test_l_arg()
771  let after =<< trim [CODE]
772    let s = 'lisp=' .. &lisp .. ', showmatch=' .. &showmatch
773    call writefile([s], 'Xtestout')
774    qall
775  [CODE]
776  if RunVim([], after, '-l')
777    call assert_equal(['lisp=1, showmatch=1'], readfile('Xtestout'))
778    call delete('Xtestout')
779  endif
780endfunc
781
782" Test for specifying a non-existing vimrc file using "-u"
783func Test_missing_vimrc()
784  CheckRunVimInTerminal
785  let after =<< trim [CODE]
786    call assert_match('^E282:', v:errmsg)
787    call writefile(v:errors, 'Xtestout')
788  [CODE]
789  call writefile(after, 'Xafter')
790
791  let cmd = GetVimCommandCleanTerm() . ' -u Xvimrc_missing -S Xafter'
792  let buf = term_start(cmd, {'term_rows' : 10})
793  call WaitForAssert({-> assert_equal("running", term_getstatus(buf))})
794  call TermWait(buf)
795  call term_sendkeys(buf, "\n:")
796  call TermWait(buf)
797  call WaitForAssert({-> assert_match(':', term_getline(buf, 10))})
798  call StopVimInTerminal(buf)
799  call assert_equal([], readfile('Xtestout'))
800  call delete('Xafter')
801  call delete('Xtestout')
802endfunc
803
804" Test for using the $VIMINIT environment variable
805func Test_VIMINIT()
806  let after =<< trim [CODE]
807    call assert_equal(1, exists('viminit_found'))
808    call assert_equal('yes', viminit_found)
809    call writefile(v:errors, 'Xtestout')
810    qall
811  [CODE]
812  call writefile(after, 'Xafter')
813  let cmd = GetVimProg() . ' --not-a-term -S Xafter --cmd "set enc=utf8"'
814  call setenv('VIMINIT', 'let viminit_found="yes"')
815  exe "silent !" . cmd
816  call assert_equal([], readfile('Xtestout'))
817  call delete('Xtestout')
818  call delete('Xafter')
819endfunc
820
821" Test for using the $EXINIT environment variable
822func Test_EXINIT()
823  let after =<< trim [CODE]
824    call assert_equal(1, exists('exinit_found'))
825    call assert_equal('yes', exinit_found)
826    call writefile(v:errors, 'Xtestout')
827    qall
828  [CODE]
829  call writefile(after, 'Xafter')
830  let cmd = GetVimProg() . ' --not-a-term -S Xafter --cmd "set enc=utf8"'
831  call setenv('EXINIT', 'let exinit_found="yes"')
832  exe "silent !" . cmd
833  call assert_equal([], readfile('Xtestout'))
834  call delete('Xtestout')
835  call delete('Xafter')
836endfunc
837
838" Test for using the 'exrc' option
839func Test_exrc()
840  let after =<< trim [CODE]
841    call assert_equal(1, &exrc)
842    call assert_equal(1, &secure)
843    call assert_equal(37, exrc_found)
844    call writefile(v:errors, 'Xtestout')
845    qall
846  [CODE]
847  call mkdir('Xdir')
848  call writefile(['let exrc_found=37'], 'Xdir/.exrc')
849  call writefile(after, 'Xdir/Xafter')
850  let cmd = GetVimProg() . ' --not-a-term -S Xafter --cmd "cd Xdir" --cmd "set enc=utf8 exrc secure"'
851  exe "silent !" . cmd
852  call assert_equal([], readfile('Xdir/Xtestout'))
853  call delete('Xdir', 'rf')
854endfunc
855
856" Test for starting Vim with a non-terminal as input/output
857func Test_io_not_a_terminal()
858  " Can't catch the output of gvim.
859  CheckNotGui
860  CheckUnix
861  CheckEnglish
862  let l = systemlist(GetVimProg() .. ' --ttyfail')
863  call assert_equal(['Vim: Warning: Output is not to a terminal',
864        \ 'Vim: Warning: Input is not from a terminal'], l)
865endfunc
866
867" Test for the "-w scriptout" argument
868func Test_w_arg()
869  " Can't catch the output of gvim.
870  CheckNotGui
871  call writefile(["iVim Editor\<Esc>:q!\<CR>"], 'Xscriptin', 'b')
872  if RunVim([], [], '-s Xscriptin -w Xscriptout')
873    call assert_equal(["iVim Editor\e:q!\r"], readfile('Xscriptout'))
874    call delete('Xscriptout')
875  endif
876  call delete('Xscriptin')
877
878  " Test for failing to open the script output file. This test works only when
879  " the language is English.
880  if v:lang == "C" || v:lang =~ '^[Ee]n'
881    call mkdir("Xdir")
882    let m = system(GetVimCommand() .. " -w Xdir")
883    call assert_equal("Cannot open for script output: \"Xdir\"\n", m)
884    call delete("Xdir", 'rf')
885  endif
886endfunc
887
888" Test for the "-s scriptin" argument
889func Test_s_arg()
890  " Can't catch the output of gvim.
891  CheckNotGui
892  CheckEnglish
893  " Test for failing to open the script input file.
894  let m = system(GetVimCommand() .. " -s abcxyz")
895  call assert_equal("Cannot open for reading: \"abcxyz\"\n", m)
896
897  call writefile([], 'Xinput')
898  let m = system(GetVimCommand() .. " -s Xinput -s Xinput")
899  call assert_equal("Attempt to open script file again: \"-s Xinput\"\n", m)
900  call delete('Xinput')
901endfunc
902
903" Test for the "-n" (no swap file) argument
904func Test_n_arg()
905  let after =<< trim [CODE]
906    call assert_equal(0, &updatecount)
907    call writefile(v:errors, 'Xtestout')
908    qall
909  [CODE]
910  if RunVim([], after, '-n')
911    call assert_equal([], readfile('Xtestout'))
912    call delete('Xtestout')
913  endif
914  call delete('Xafter')
915endfunc
916
917" Test for the "-h" (help) argument
918func Test_h_arg()
919  " Can't catch the output of gvim.
920  CheckNotGui
921  let l = systemlist(GetVimProg() .. ' -h')
922  call assert_match('^VIM - Vi IMproved', l[0])
923  let l = systemlist(GetVimProg() .. ' -?')
924  call assert_match('^VIM - Vi IMproved', l[0])
925endfunc
926
927" Test for the "-F" (farsi) argument
928func Test_F_arg()
929  " Can't catch the output of gvim.
930  CheckNotGui
931  let l = systemlist(GetVimProg() .. ' -F')
932  call assert_match('^E27:', l[0])
933endfunc
934
935" Test for the "-E" (improved Ex mode) argument
936func Test_E_arg()
937  let after =<< trim [CODE]
938    call assert_equal('cv', mode(1))
939    call writefile(v:errors, 'Xtestout')
940    qall
941  [CODE]
942  if RunVim([], after, '-E')
943    call assert_equal([], readfile('Xtestout'))
944    call delete('Xtestout')
945  endif
946  call delete('Xafter')
947endfunc
948
949" Test for too many edit argument errors
950func Test_too_many_edit_args()
951  " Can't catch the output of gvim.
952  CheckNotGui
953  CheckEnglish
954  let l = systemlist(GetVimProg() .. ' - -')
955  call assert_match('^Too many edit arguments: "-"', l[1])
956endfunc
957
958" vim: shiftwidth=2 sts=2 expandtab
959