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