neovim

Neovim text editor
git clone https://git.dasho.dev/neovim.git
Log | Files | Refs | README

test_startup.vim (43700B)


      1 " Tests for startup.
      2 
      3 source shared.vim
      4 source screendump.vim
      5 source term_util.vim
      6 source check.vim
      7 
      8 " Check that loading startup.vim works.
      9 func 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
     18 endfunc
     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
     24 func 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')
     76 endfunc
     77 
     78 func 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')
    106 endfunc
    107 
    108 func 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')
    137 endfunc
    138 
    139 func 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')
    162 endfunc
    163 
    164 func 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')
    183 endfunc
    184 
    185 " Test the -o[N] and -O[N] arguments to open N windows split
    186 " horizontally or vertically.
    187 func 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')
    262 endfunc
    263 
    264 " Test the -p[N] argument to open N tabpages.
    265 func 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')
    290 endfunc
    291 
    292 " Test the -V[N] argument to set the 'verbose' option to [N]
    293 func 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)
    306 endfunc
    307 
    308 " Test that an error is shown when the defaults.vim file could not be read
    309 func 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)
    323 endfunc
    324 
    325 " Test the '-q [errorfile]' argument.
    326 func 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')
    385 endfunc
    386 
    387 " Test the -V[N]{filename} argument to set the 'verbose' option to N
    388 " and set 'verbosefile' to filename.
    389 func 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')
    398 endfunc
    399 
    400 " Test the -m, -M and -R arguments:
    401 " -m resets 'write'
    402 " -M resets 'modifiable' and 'write'
    403 " -R sets 'readonly'
    404 func 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')
    428 endfunc
    429 
    430 " Test the -A and -H arguments (Arabic and Hebrew modes).
    431 func 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')
    450 endfunc
    451 
    452 " Test the --echo-wid argument (for GTK GUI only).
    453 func 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')
    464 endfunction
    465 
    466 " Test the -reverse and +reverse arguments (for GUI only).
    467 func 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')
    485 endfunc
    486 
    487 " Test the -background and -foreground arguments (for GUI only).
    488 func 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')
    508 endfunc
    509 
    510 " Test the -font argument (for GUI only).
    511 func 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')
    534 endfunc
    535 
    536 " Test the -geometry argument (for GUI only).
    537 func 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')
    577 endfunc
    578 
    579 " Test the -iconic argument (for GUI only).
    580 func 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?
    588 endfunc
    589 
    590 
    591 func 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')
    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
    685 endfunc
    686 
    687 func 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')
    729 endfunc
    730 
    731 func 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')
    750 endfunc
    751 
    752 func 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')
    764 endfunc
    765 
    766 func 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)
    778 endfunc
    779 
    780 func 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)
    788 endfunc
    789 
    790 func 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
    800 endfunc
    801 
    802 func 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')
    826 endfunc
    827 
    828 func 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)
    835 endfunc
    836 
    837 func 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)
    846 endfunc
    847 
    848 func 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:])
    855 endfunc
    856 
    857 " Test for the "-r" recovery mode option
    858 func 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]\\+", '', ''))
    874 endfunc
    875 
    876 " Test for the '-t' option to jump to a tag
    877 func 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')
    903 endfunc
    904 
    905 " Test the '-T' argument which sets the 'term' option.
    906 func 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')
    922 endfunc
    923 
    924 " Test the '-x' argument to read/write encrypted files.
    925 func 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')
    951 endfunc
    952 
    953 " Test for entering the insert mode on startup
    954 func 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
    967 endfunc
    968 
    969 " Test for enabling the binary mode on startup
    970 func 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
    979 endfunc
    980 
    981 " Test for enabling the lisp mode on startup
    982 func 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
    993 endfunc
    994 
    995 " Test for specifying a non-existing vimrc file using "-u"
    996 func 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')
   1015 endfunc
   1016 
   1017 " Test for using the $VIMINIT environment variable
   1018 func 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')
   1033 endfunc
   1034 
   1035 " Test for using the $EXINIT environment variable
   1036 func 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')
   1051 endfunc
   1052 
   1053 " Test for using the 'exrc' option
   1054 func 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')
   1071 endfunc
   1072 
   1073 " Test for starting Vim with a non-terminal as input/output
   1074 func 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)
   1083 endfunc
   1084 
   1085 " Test for not being a term avoiding escape codes.
   1086 func 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
   1104 endfunc
   1105 
   1106 
   1107 " Test for the "-w scriptout" argument
   1108 func 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')
   1137 endfunc
   1138 
   1139 " Test for the "-s scriptin" argument
   1140 func 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')
   1153 endfunc
   1154 
   1155 " Test for the "-n" (no swap file) argument
   1156 func 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
   1166 endfunc
   1167 
   1168 " Test for the "-h" (help) argument
   1169 func 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])
   1177 endfunc
   1178 
   1179 " Test for the "-F" (farsi) argument
   1180 func 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])
   1186 endfunc
   1187 
   1188 " Test for the "-E" (improved Ex mode) argument
   1189 func Test_E_arg()
   1190  let after =<< trim [CODE]
   1191    call assert_equal('cv', mode(1))
   1192    call writefile(v:errors, 'Xtestout')
   1193    qall
   1194  [CODE]
   1195  if RunVim([], after, '-E')
   1196    call assert_equal([], readfile('Xtestout'))
   1197    call delete('Xtestout')
   1198  endif
   1199 endfunc
   1200 
   1201 " Test for the "-D" (debugger) argument
   1202 func Test_D_arg()
   1203  CheckRunVimInTerminal
   1204 
   1205  let cmd = GetVimCommandCleanTerm() .. ' -D'
   1206  let buf = term_start(cmd, {'term_rows' : 10})
   1207  call WaitForAssert({-> assert_equal("running", term_getstatus(buf))})
   1208 
   1209  call WaitForAssert({-> assert_equal('Entering Debug mode.  Type "cont" to continue.',
   1210  \                  term_getline(buf, 7))})
   1211  call WaitForAssert({-> assert_equal('>', term_getline(buf, 10))})
   1212 
   1213  call StopVimInTerminal(buf)
   1214 endfunc
   1215 
   1216 " Test for too many edit argument errors
   1217 func Test_too_many_edit_args()
   1218  throw 'Skipped: N/A'
   1219  " Can't catch the output of gvim.
   1220  CheckNotGui
   1221  CheckEnglish
   1222  let l = systemlist(GetVimProg() .. ' - -')
   1223  call assert_match('^Too many edit arguments: "-"', l[1])
   1224 endfunc
   1225 
   1226 " Test starting vim with various names: vim, ex, view, evim, etc.
   1227 func Test_progname()
   1228  CheckUnix
   1229 
   1230  call mkdir('Xprogname', 'p')
   1231  call writefile(['silent !date',
   1232  \               'call writefile([mode(1), '
   1233  \               .. '&insertmode, &diff, &readonly, &updatecount, '
   1234  \               .. 'join(split(execute("message"), "\n")[1:])], "Xprogname_out")',
   1235  \               'qall'], 'Xprogname_after')
   1236 
   1237  "  +---------------------------------------------- progname
   1238  "  |            +--------------------------------- mode(1)
   1239  "  |            |     +--------------------------- &insertmode
   1240  "  |            |     |    +---------------------- &diff
   1241  "  |            |     |    |    +----------------- &readonly
   1242  "  |            |     |    |    |        +-------- &updatecount
   1243  "  |            |     |    |    |        |    +--- :messages
   1244  "  |            |     |    |    |        |    |
   1245  " let expectations = {
   1246  " \ 'vim':      ['n',  '0', '0', '0',   '200', ''],
   1247  " \ 'gvim':     ['n',  '0', '0', '0',   '200', ''],
   1248  " \ 'ex':       ['ce', '0', '0', '0',   '200', ''],
   1249  " \ 'exim':     ['cv', '0', '0', '0',   '200', ''],
   1250  " \ 'view':     ['n',  '0', '0', '1', '10000', ''],
   1251  " \ 'gview':    ['n',  '0', '0', '1', '10000', ''],
   1252  " \ 'evim':     ['n',  '1', '0', '0',   '200', ''],
   1253  " \ 'eview':    ['n',  '1', '0', '1', '10000', ''],
   1254  " \ 'rvim':     ['n',  '0', '0', '0',   '200', 'line    1: E145: Shell commands and some functionality not allowed in rvim'],
   1255  " \ 'rgvim':    ['n',  '0', '0', '0',   '200', 'line    1: E145: Shell commands and some functionality not allowed in rvim'],
   1256  " \ 'rview':    ['n',  '0', '0', '1', '10000', 'line    1: E145: Shell commands and some functionality not allowed in rvim'],
   1257  " \ 'rgview':   ['n',  '0', '0', '1', '10000', 'line    1: E145: Shell commands and some functionality not allowed in rvim'],
   1258  " \ 'vimdiff':  ['n',  '0', '1', '0',   '200', ''],
   1259  " \ 'gvimdiff': ['n',  '0', '1', '0',   '200', '']}
   1260  let expectations = {'nvim': ['n',  '0', '0', '0',   '200', '']}
   1261 
   1262  " let prognames = ['vim', 'gvim', 'ex', 'exim', 'view', 'gview',
   1263  " \                'evim', 'eview', 'rvim', 'rgvim', 'rview', 'rgview',
   1264  " \                'vimdiff', 'gvimdiff']
   1265  let prognames = ['nvim']
   1266 
   1267  for progname in prognames
   1268    let run_with_gui = (progname =~# 'g') || (has('gui') && (progname ==# 'evim' || progname ==# 'eview'))
   1269 
   1270    if empty($DISPLAY) && run_with_gui
   1271      " Can't run gvim, gview  (etc.) if $DISPLAY is not setup.
   1272      continue
   1273     endif
   1274 
   1275    exe 'silent !ln -s -f ' ..exepath(GetVimProg()) .. ' Xprogname/' .. progname
   1276 
   1277    let stdout_stderr = ''
   1278    if progname =~# 'g'
   1279      let stdout_stderr = system('Xprogname/'..progname..' -f --clean --not-a-term -S Xprogname_after')
   1280    else
   1281      exe 'sil !Xprogname/'..progname..' -f --clean -S Xprogname_after'
   1282    endif
   1283 
   1284    if progname =~# 'g' && !has('gui')
   1285      call assert_equal("E25: GUI cannot be used: Not enabled at compile time\n", stdout_stderr, progname)
   1286    else
   1287      " GUI motif can output some warnings like this:
   1288      "   Warning:
   1289      "       Name: subMenu
   1290      "       Class: XmCascadeButton
   1291      "       Illegal mnemonic character;  Could not convert X KEYSYM to a keycode
   1292      " So don't check that stderr is empty with GUI Motif.
   1293      if run_with_gui && !has('gui_motif')
   1294        call assert_equal('', stdout_stderr, progname)
   1295      endif
   1296      call assert_equal(expectations[progname], readfile('Xprogname_out'), progname)
   1297    endif
   1298 
   1299    call delete('Xprogname/' .. progname)
   1300    call delete('Xprogname_out')
   1301  endfor
   1302 
   1303  call delete('Xprogname_after')
   1304  call delete('Xprogname', 'd')
   1305 endfunc
   1306 
   1307 " Test for doing a write from .vimrc
   1308 func Test_write_in_vimrc()
   1309  call writefile(['silent! write'], 'Xvimrc')
   1310  let after =<< trim [CODE]
   1311    call assert_match('E32: ', v:errmsg)
   1312    call writefile(v:errors, 'Xtestout')
   1313    qall
   1314  [CODE]
   1315  if RunVim([], after, '-u Xvimrc')
   1316    call assert_equal([], readfile('Xtestout'))
   1317    call delete('Xtestout')
   1318  endif
   1319  call delete('Xvimrc')
   1320 endfunc
   1321 
   1322 func Test_echo_true_in_cmd()
   1323  CheckNotGui
   1324 
   1325  let lines =<< trim END
   1326      echo v:true
   1327      call writefile(['done'], 'Xresult')
   1328      quit
   1329  END
   1330  call writefile(lines, 'Xscript')
   1331  if RunVim([], [], '--cmd "source Xscript"')
   1332    call assert_equal(['done'], readfile('Xresult'))
   1333  endif
   1334  call delete('Xscript')
   1335  call delete('Xresult')
   1336 endfunc
   1337 
   1338 func Test_rename_buffer_on_startup()
   1339  CheckUnix
   1340 
   1341  let lines =<< trim END
   1342      call writefile(['done'], 'Xresult')
   1343      qa!
   1344  END
   1345  call writefile(lines, 'Xscript')
   1346  if RunVim([], [], "--clean -e -s --cmd 'file x|new|file x' --cmd 'so Xscript'")
   1347    call assert_equal(['done'], readfile('Xresult'))
   1348  endif
   1349  call delete('Xscript')
   1350  call delete('Xresult')
   1351 endfunc
   1352 
   1353 " Test that -cq works as expected
   1354 func Test_cq_zero_exmode()
   1355  CheckFeature channel
   1356 
   1357  let logfile = 'Xcq_log.txt'
   1358  let out = system(GetVimCommand() .. ' --clean --log ' .. logfile .. ' -es -X -c "argdelete foobar" -c"7cq"')
   1359  call assert_equal(8, v:shell_error)
   1360  let log = filter(readfile(logfile), {idx, val -> val =~ "E480:"})
   1361  call assert_match('E480: No match: foobar', log[0])
   1362  call delete(logfile)
   1363 
   1364  " wrap-around on Unix
   1365  let out = system(GetVimCommand() .. ' --clean --log ' .. logfile .. ' -es -X -c "argdelete foobar" -c"255cq"')
   1366  if !has('win32')
   1367    call assert_equal(0, v:shell_error)
   1368  else
   1369    call assert_equal(256, v:shell_error)
   1370  endif
   1371  let log = filter(readfile(logfile), {idx, val -> val =~ "E480:"})
   1372  call assert_match('E480: No match: foobar', log[0])
   1373  call delete('Xcq_log.txt')
   1374 endfunc
   1375 
   1376 " vim: shiftwidth=2 sts=2 expandtab