166459b7cSBram Moolenaar" Tests for startup. 2b9a46fecSBram Moolenaar 366459b7cSBram Moolenaarsource shared.vim 4c75e8126SBram Moolenaarsource screendump.vim 5cde0ff39SBram Moolenaarsource term_util.vim 68c5a278fSBram Moolenaarsource check.vim 766459b7cSBram Moolenaar 866459b7cSBram Moolenaar" Check that loading startup.vim works. 9b9a46fecSBram Moolenaarfunc Test_startup_script() 10b9a46fecSBram Moolenaar set compatible 11b9a46fecSBram Moolenaar source $VIMRUNTIME/defaults.vim 12b9a46fecSBram Moolenaar 13b9a46fecSBram Moolenaar call assert_equal(0, &compatible) 14cde0ff39SBram Moolenaar " Restore some options, so that the following tests doesn't break 15cde0ff39SBram Moolenaar set nomore 16cde0ff39SBram Moolenaar set noshowmode 17b9a46fecSBram Moolenaarendfunc 1866459b7cSBram Moolenaar 1966459b7cSBram Moolenaar" Verify the order in which plugins are loaded: 2066459b7cSBram Moolenaar" 1. plugins in non-after directories 2166459b7cSBram Moolenaar" 2. packages 2266459b7cSBram Moolenaar" 3. plugins in after directories 2366459b7cSBram Moolenaarfunc Test_after_comes_later() 246d91bcb4SBram Moolenaar CheckFeature packages 25c79745a8SBram Moolenaar let before =<< trim [CODE] 26c79745a8SBram Moolenaar set nocp viminfo+=nviminfo 27c79745a8SBram Moolenaar set guioptions+=M 28c79745a8SBram Moolenaar let $HOME = "/does/not/exist" 29c79745a8SBram Moolenaar set loadplugins 30c79745a8SBram Moolenaar set rtp=Xhere,Xafter,Xanother 31c79745a8SBram Moolenaar set packpath=Xhere,Xafter 32c79745a8SBram Moolenaar set nomore 33c79745a8SBram Moolenaar let g:sequence = "" 34c79745a8SBram Moolenaar [CODE] 35c79745a8SBram Moolenaar 36c79745a8SBram Moolenaar let after =<< trim [CODE] 37c79745a8SBram Moolenaar redir! > Xtestout 38c79745a8SBram Moolenaar scriptnames 39c79745a8SBram Moolenaar redir END 40c79745a8SBram Moolenaar redir! > Xsequence 41c79745a8SBram Moolenaar echo g:sequence 42c79745a8SBram Moolenaar redir END 43c79745a8SBram Moolenaar quit 44c79745a8SBram Moolenaar [CODE] 45c79745a8SBram Moolenaar 4666459b7cSBram Moolenaar call mkdir('Xhere/plugin', 'p') 4707ecfa64SBram Moolenaar call writefile(['let g:sequence .= "here "'], 'Xhere/plugin/here.vim') 4807ecfa64SBram Moolenaar call mkdir('Xanother/plugin', 'p') 4907ecfa64SBram Moolenaar call writefile(['let g:sequence .= "another "'], 'Xanother/plugin/another.vim') 5066459b7cSBram Moolenaar call mkdir('Xhere/pack/foo/start/foobar/plugin', 'p') 5107ecfa64SBram Moolenaar call writefile(['let g:sequence .= "pack "'], 'Xhere/pack/foo/start/foobar/plugin/foo.vim') 5266459b7cSBram Moolenaar 5366459b7cSBram Moolenaar call mkdir('Xafter/plugin', 'p') 5407ecfa64SBram Moolenaar call writefile(['let g:sequence .= "after "'], 'Xafter/plugin/later.vim') 5566459b7cSBram Moolenaar 56472a0a88SBram Moolenaar if RunVim(before, after, '') 5766459b7cSBram Moolenaar 5866459b7cSBram Moolenaar let lines = readfile('Xtestout') 5907ecfa64SBram Moolenaar let expected = ['Xbefore.vim', 'here.vim', 'another.vim', 'foo.vim', 'later.vim', 'Xafter.vim'] 6066459b7cSBram Moolenaar let found = [] 6166459b7cSBram Moolenaar for line in lines 6266459b7cSBram Moolenaar for one in expected 6366459b7cSBram Moolenaar if line =~ one 6466459b7cSBram Moolenaar call add(found, one) 6566459b7cSBram Moolenaar endif 6666459b7cSBram Moolenaar endfor 6766459b7cSBram Moolenaar endfor 6866459b7cSBram Moolenaar call assert_equal(expected, found) 6983b3c3d8SBram Moolenaar endif 7066459b7cSBram Moolenaar 7107ecfa64SBram Moolenaar call assert_equal('here another pack after', substitute(join(readfile('Xsequence', 1), ''), '\s\+$', '', '')) 7207ecfa64SBram Moolenaar 7366459b7cSBram Moolenaar call delete('Xtestout') 7407ecfa64SBram Moolenaar call delete('Xsequence') 7566459b7cSBram Moolenaar call delete('Xhere', 'rf') 7607ecfa64SBram Moolenaar call delete('Xanother', 'rf') 7766459b7cSBram Moolenaar call delete('Xafter', 'rf') 7866459b7cSBram Moolenaarendfunc 79472a0a88SBram Moolenaar 80ce876aaaSBram Moolenaarfunc Test_pack_in_rtp_when_plugins_run() 816d91bcb4SBram Moolenaar CheckFeature packages 82c79745a8SBram Moolenaar let before =<< trim [CODE] 83c79745a8SBram Moolenaar set nocp viminfo+=nviminfo 84c79745a8SBram Moolenaar set guioptions+=M 85c79745a8SBram Moolenaar let $HOME = "/does/not/exist" 86c79745a8SBram Moolenaar set loadplugins 87c79745a8SBram Moolenaar set rtp=Xhere 88c79745a8SBram Moolenaar set packpath=Xhere 89c79745a8SBram Moolenaar set nomore 90c79745a8SBram Moolenaar [CODE] 91c79745a8SBram Moolenaar 92ce876aaaSBram Moolenaar let after = [ 93ce876aaaSBram Moolenaar \ 'quit', 94ce876aaaSBram Moolenaar \ ] 95ce876aaaSBram Moolenaar call mkdir('Xhere/plugin', 'p') 96ce876aaaSBram Moolenaar call writefile(['redir! > Xtestout', 'silent set runtimepath?', 'silent! call foo#Trigger()', 'redir END'], 'Xhere/plugin/here.vim') 97ce876aaaSBram Moolenaar call mkdir('Xhere/pack/foo/start/foobar/autoload', 'p') 98ce876aaaSBram Moolenaar call writefile(['function! foo#Trigger()', 'echo "autoloaded foo"', 'endfunction'], 'Xhere/pack/foo/start/foobar/autoload/foo.vim') 99ce876aaaSBram Moolenaar 100ce876aaaSBram Moolenaar if RunVim(before, after, '') 101ce876aaaSBram Moolenaar 102ce876aaaSBram Moolenaar let lines = filter(readfile('Xtestout'), '!empty(v:val)') 103ce876aaaSBram Moolenaar call assert_match('Xhere[/\\]pack[/\\]foo[/\\]start[/\\]foobar', get(lines, 0)) 104ce876aaaSBram Moolenaar call assert_match('autoloaded foo', get(lines, 1)) 105ce876aaaSBram Moolenaar endif 106ce876aaaSBram Moolenaar 107ce876aaaSBram Moolenaar call delete('Xtestout') 108ce876aaaSBram Moolenaar call delete('Xhere', 'rf') 109ce876aaaSBram Moolenaarendfunc 110ce876aaaSBram Moolenaar 111472a0a88SBram Moolenaarfunc Test_help_arg() 112f8c52e8dSBram Moolenaar " This does not work with a GUI-only binary, such as on MS-Windows. 113f8c52e8dSBram Moolenaar CheckAnyOf Unix NotGui 114240309c9SBram Moolenaar 115472a0a88SBram Moolenaar if RunVim([], [], '--help >Xtestout') 116472a0a88SBram Moolenaar let lines = readfile('Xtestout') 117472a0a88SBram Moolenaar call assert_true(len(lines) > 20) 118ba98bef1SBram Moolenaar call assert_match('Vi IMproved', lines[0]) 119472a0a88SBram Moolenaar 120472a0a88SBram Moolenaar " check if couple of lines are there 12150fa8dd0SBram Moolenaar let found = [] 122472a0a88SBram Moolenaar for line in lines 123472a0a88SBram Moolenaar if line =~ '-R.*Readonly mode' 12450fa8dd0SBram Moolenaar call add(found, 'Readonly mode') 125472a0a88SBram Moolenaar endif 12650fa8dd0SBram Moolenaar " Watch out for a second --version line in the Gnome version. 12750fa8dd0SBram Moolenaar if line =~ '--version.*Print version information and exit' 12850fa8dd0SBram Moolenaar call add(found, "--version") 129472a0a88SBram Moolenaar endif 130472a0a88SBram Moolenaar endfor 13150fa8dd0SBram Moolenaar call assert_equal(['Readonly mode', '--version'], found) 132472a0a88SBram Moolenaar endif 133472a0a88SBram Moolenaar call delete('Xtestout') 134472a0a88SBram Moolenaarendfunc 135ba98bef1SBram Moolenaar 136ba98bef1SBram Moolenaarfunc Test_compatible_args() 137c79745a8SBram Moolenaar let after =<< trim [CODE] 138c79745a8SBram Moolenaar call writefile([string(&compatible)], "Xtestout") 139c79745a8SBram Moolenaar set viminfo+=nviminfo 140c79745a8SBram Moolenaar quit 141c79745a8SBram Moolenaar [CODE] 142c79745a8SBram Moolenaar 143ba98bef1SBram Moolenaar if RunVim([], after, '-C') 144ba98bef1SBram Moolenaar let lines = readfile('Xtestout') 145ba98bef1SBram Moolenaar call assert_equal('1', lines[0]) 146ba98bef1SBram Moolenaar endif 147ba98bef1SBram Moolenaar 148ba98bef1SBram Moolenaar if RunVim([], after, '-N') 149ba98bef1SBram Moolenaar let lines = readfile('Xtestout') 150ba98bef1SBram Moolenaar call assert_equal('0', lines[0]) 151ba98bef1SBram Moolenaar endif 152ba98bef1SBram Moolenaar 153ba98bef1SBram Moolenaar call delete('Xtestout') 154ba98bef1SBram Moolenaarendfunc 155ba98bef1SBram Moolenaar 1568f4499b8SBram Moolenaar" Test the -o[N] and -O[N] arguments to open N windows split 1578f4499b8SBram Moolenaar" horizontally or vertically. 1588f4499b8SBram Moolenaarfunc Test_o_arg() 159c79745a8SBram Moolenaar let after =<< trim [CODE] 160e96a2498SBram Moolenaar set cpo&vim 161c79745a8SBram Moolenaar call writefile([winnr("$"), 1628f4499b8SBram Moolenaar \ winheight(1), winheight(2), &lines, 1638f4499b8SBram Moolenaar \ winwidth(1), winwidth(2), &columns, 1648f4499b8SBram Moolenaar \ bufname(winbufnr(1)), bufname(winbufnr(2))], 165c79745a8SBram Moolenaar \ "Xtestout") 166c79745a8SBram Moolenaar qall 167c79745a8SBram Moolenaar [CODE] 168c79745a8SBram Moolenaar 1698f4499b8SBram Moolenaar if RunVim([], after, '-o2') 1708f4499b8SBram Moolenaar " Open 2 windows split horizontally. Expect: 1718f4499b8SBram Moolenaar " - 2 windows 1728f4499b8SBram Moolenaar " - both windows should have the same or almost the same height 1738f4499b8SBram Moolenaar " - sum of both windows height (+ 3 for both statusline and Ex command) 1748f4499b8SBram Moolenaar " should be equal to the number of lines 1758f4499b8SBram Moolenaar " - both windows should have the same width which should be equal to the 1768f4499b8SBram Moolenaar " number of columns 1778f4499b8SBram Moolenaar " - buffer of both windows should have no name 1788f4499b8SBram Moolenaar let [wn, wh1, wh2, ln, ww1, ww2, cn, bn1, bn2] = readfile('Xtestout') 1798f4499b8SBram Moolenaar call assert_equal('2', wn) 1808f4499b8SBram Moolenaar call assert_inrange(0, 1, wh1 - wh2) 1818f4499b8SBram Moolenaar call assert_equal(string(wh1 + wh2 + 3), ln) 1828f4499b8SBram Moolenaar call assert_equal(ww1, ww2) 1838f4499b8SBram Moolenaar call assert_equal(ww1, cn) 1848f4499b8SBram Moolenaar call assert_equal('', bn1) 1858f4499b8SBram Moolenaar call assert_equal('', bn2) 1868f4499b8SBram Moolenaar endif 1878f4499b8SBram Moolenaar 1888f4499b8SBram Moolenaar if RunVim([], after, '-o foo bar') 1898f4499b8SBram Moolenaar " Same expectations as for -o2 but buffer names should be foo and bar 1908f4499b8SBram Moolenaar let [wn, wh1, wh2, ln, ww1, ww2, cn, bn1, bn2] = readfile('Xtestout') 1918f4499b8SBram Moolenaar call assert_equal('2', wn) 1928f4499b8SBram Moolenaar call assert_inrange(0, 1, wh1 - wh2) 1938f4499b8SBram Moolenaar call assert_equal(string(wh1 + wh2 + 3), ln) 1948f4499b8SBram Moolenaar call assert_equal(ww1, ww2) 1958f4499b8SBram Moolenaar call assert_equal(ww1, cn) 1968f4499b8SBram Moolenaar call assert_equal('foo', bn1) 1978f4499b8SBram Moolenaar call assert_equal('bar', bn2) 1988f4499b8SBram Moolenaar endif 1998f4499b8SBram Moolenaar 2008f4499b8SBram Moolenaar if RunVim([], after, '-O2') 2018f4499b8SBram Moolenaar " Open 2 windows split vertically. Expect: 2028f4499b8SBram Moolenaar " - 2 windows 2038f4499b8SBram Moolenaar " - both windows should have the same or almost the same width 204036b09caSBram Moolenaar " - sum of both windows width (+ 1 for the separator) should be equal to 205036b09caSBram Moolenaar " the number of columns 2068f4499b8SBram Moolenaar " - both windows should have the same height 2078f4499b8SBram Moolenaar " - window height (+ 2 for the statusline and Ex command) should be equal 2088f4499b8SBram Moolenaar " to the number of lines 2099e81db97SBram Moolenaar " - buffer of both windows should have no name 2108f4499b8SBram Moolenaar let [wn, wh1, wh2, ln, ww1, ww2, cn, bn1, bn2] = readfile('Xtestout') 2118f4499b8SBram Moolenaar call assert_equal('2', wn) 2128f4499b8SBram Moolenaar call assert_inrange(0, 1, ww1 - ww2) 2138f4499b8SBram Moolenaar call assert_equal(string(ww1 + ww2 + 1), cn) 2148f4499b8SBram Moolenaar call assert_equal(wh1, wh2) 2158f4499b8SBram Moolenaar call assert_equal(string(wh1 + 2), ln) 2168f4499b8SBram Moolenaar call assert_equal('', bn1) 2178f4499b8SBram Moolenaar call assert_equal('', bn2) 2188f4499b8SBram Moolenaar endif 2198f4499b8SBram Moolenaar 2208f4499b8SBram Moolenaar if RunVim([], after, '-O foo bar') 2218f4499b8SBram Moolenaar " Same expectations as for -O2 but buffer names should be foo and bar 2228f4499b8SBram Moolenaar let [wn, wh1, wh2, ln, ww1, ww2, cn, bn1, bn2] = readfile('Xtestout') 2238f4499b8SBram Moolenaar call assert_equal('2', wn) 2248f4499b8SBram Moolenaar call assert_inrange(0, 1, ww1 - ww2) 2258f4499b8SBram Moolenaar call assert_equal(string(ww1 + ww2 + 1), cn) 2268f4499b8SBram Moolenaar call assert_equal(wh1, wh2) 2278f4499b8SBram Moolenaar call assert_equal(string(wh1 + 2), ln) 2288f4499b8SBram Moolenaar call assert_equal('foo', bn1) 2298f4499b8SBram Moolenaar call assert_equal('bar', bn2) 2308f4499b8SBram Moolenaar endif 2318f4499b8SBram Moolenaar 2328f4499b8SBram Moolenaar call delete('Xtestout') 2338f4499b8SBram Moolenaarendfunc 2348f4499b8SBram Moolenaar 2359e81db97SBram Moolenaar" Test the -p[N] argument to open N tabpages. 2369e81db97SBram Moolenaarfunc Test_p_arg() 237c79745a8SBram Moolenaar let after =<< trim [CODE] 238c79745a8SBram Moolenaar call writefile(split(execute("tabs"), "\n"), "Xtestout") 239c79745a8SBram Moolenaar qall 240c79745a8SBram Moolenaar [CODE] 241c79745a8SBram Moolenaar 2429e81db97SBram Moolenaar if RunVim([], after, '-p2') 2439e81db97SBram Moolenaar let lines = readfile('Xtestout') 2449e81db97SBram Moolenaar call assert_equal(4, len(lines)) 2459e81db97SBram Moolenaar call assert_equal('Tab page 1', lines[0]) 2469e81db97SBram Moolenaar call assert_equal('> [No Name]', lines[1]) 2479e81db97SBram Moolenaar call assert_equal('Tab page 2', lines[2]) 2489e81db97SBram Moolenaar call assert_equal(' [No Name]', lines[3]) 2499e81db97SBram Moolenaar endif 2509e81db97SBram Moolenaar 2519e81db97SBram Moolenaar if RunVim([], after, '-p foo bar') 2529e81db97SBram Moolenaar let lines = readfile('Xtestout') 2539e81db97SBram Moolenaar call assert_equal(4, len(lines)) 2549e81db97SBram Moolenaar call assert_equal('Tab page 1', lines[0]) 2559e81db97SBram Moolenaar call assert_equal('> foo', lines[1]) 2569e81db97SBram Moolenaar call assert_equal('Tab page 2', lines[2]) 2579e81db97SBram Moolenaar call assert_equal(' bar', lines[3]) 2589e81db97SBram Moolenaar endif 2599e81db97SBram Moolenaar 2609e81db97SBram Moolenaar call delete('Xtestout') 2619e81db97SBram Moolenaarendfunc 2629e81db97SBram Moolenaar 2634b1c9a91SBram Moolenaar" Test the -V[N] argument to set the 'verbose' option to [N] 2649e81db97SBram Moolenaarfunc Test_V_arg() 2654b1c9a91SBram Moolenaar " Can't catch the output of gvim. 2668c5a278fSBram Moolenaar CheckNotGui 2678c5a278fSBram Moolenaar 2689e81db97SBram Moolenaar let out = system(GetVimCommand() . ' --clean -es -X -V0 -c "set verbose?" -cq') 2699e81db97SBram Moolenaar call assert_equal(" verbose=0\n", out) 2709e81db97SBram Moolenaar 2719e81db97SBram Moolenaar let out = system(GetVimCommand() . ' --clean -es -X -V2 -c "set verbose?" -cq') 2724515bcdeSBram Moolenaar call assert_match("sourcing \"$VIMRUNTIME[\\/]defaults\.vim\"\r\nline \\d\\+: sourcing \"[^\"]*runtime[\\/]filetype\.vim\".*\n", out) 2734b1c9a91SBram Moolenaar call assert_match(" verbose=2\n", out) 2749e81db97SBram Moolenaar 2759e81db97SBram Moolenaar let out = system(GetVimCommand() . ' --clean -es -X -V15 -c "set verbose?" -cq') 2764b1c9a91SBram Moolenaar call assert_match("sourcing \"$VIMRUNTIME[\\/]defaults\.vim\"\r\nline 1: \" The default vimrc file\..* verbose=15\n", out) 2779e81db97SBram Moolenaarendfunc 2789e81db97SBram Moolenaar 2791d3a14ecSChristian Brabandt" Test that an error is shown when the defaults.vim file could not be read 280a83d0602SBram Moolenaarfunc Test_defaults_error() 281a83d0602SBram Moolenaar " Can't catch the output of gvim. 282a83d0602SBram Moolenaar CheckNotGui 283a83d0602SBram Moolenaar CheckNotMSWindows 284a83d0602SBram Moolenaar " For unknown reasons freeing all memory does not work here, even though 285a83d0602SBram Moolenaar " EXITFREE is defined. 286a83d0602SBram Moolenaar CheckNotAsan 287a83d0602SBram Moolenaar 288a83d0602SBram Moolenaar let out = system('VIMRUNTIME=/tmp ' .. GetVimCommand() .. ' --clean -cq') 289a83d0602SBram Moolenaar call assert_match("E1187: Failed to source defaults.vim", out) 290a83d0602SBram Moolenaar 291a83d0602SBram Moolenaar let out = system('VIMRUNTIME=/tmp ' .. GetVimCommand() .. ' -u DEFAULTS -cq') 292a83d0602SBram Moolenaar call assert_match("E1187: Failed to source defaults.vim", out) 293a83d0602SBram Moolenaarendfunc 2941d3a14ecSChristian Brabandt 29554948183SBram Moolenaar" Test the '-q [errorfile]' argument. 29654948183SBram Moolenaarfunc Test_q_arg() 2975a4c3082SBram Moolenaar CheckFeature quickfix 2985a4c3082SBram Moolenaar 2991e1f612bSBram Moolenaar let lines =<< trim END 3001e1f612bSBram Moolenaar /* some file with an error */ 3011e1f612bSBram Moolenaar main() { 3021e1f612bSBram Moolenaar functionCall(arg; arg, arg); 3031e1f612bSBram Moolenaar return 666 3041e1f612bSBram Moolenaar } 3051e1f612bSBram Moolenaar END 3061e1f612bSBram Moolenaar call writefile(lines, 'Xbadfile.c') 3071e1f612bSBram Moolenaar 308c79745a8SBram Moolenaar let after =<< trim [CODE] 309c79745a8SBram Moolenaar call writefile([&errorfile, string(getpos("."))], "Xtestout") 310c79745a8SBram Moolenaar copen 311c79745a8SBram Moolenaar w >> Xtestout 312c79745a8SBram Moolenaar qall 313c79745a8SBram Moolenaar [CODE] 31454948183SBram Moolenaar 31554948183SBram Moolenaar " Test with default argument '-q'. 31654948183SBram Moolenaar call assert_equal('errors.err', &errorfile) 3171e1f612bSBram Moolenaar call writefile(["Xbadfile.c:4:12: error: expected ';' before '}' token"], 'errors.err') 31854948183SBram Moolenaar if RunVim([], after, '-q') 31954948183SBram Moolenaar let lines = readfile('Xtestout') 32054948183SBram Moolenaar call assert_equal(['errors.err', 3211e1f612bSBram Moolenaar \ '[0, 4, 12, 0]', 3221e1f612bSBram Moolenaar \ "Xbadfile.c|4 col 12| error: expected ';' before '}' token"], 32354948183SBram Moolenaar \ lines) 32454948183SBram Moolenaar endif 32554948183SBram Moolenaar call delete('Xtestout') 32654948183SBram Moolenaar call delete('errors.err') 32754948183SBram Moolenaar 32854948183SBram Moolenaar " Test with explicit argument '-q Xerrors' (with space). 3291e1f612bSBram Moolenaar call writefile(["Xbadfile.c:4:12: error: expected ';' before '}' token"], 'Xerrors') 33054948183SBram Moolenaar if RunVim([], after, '-q Xerrors') 33154948183SBram Moolenaar let lines = readfile('Xtestout') 33254948183SBram Moolenaar call assert_equal(['Xerrors', 3331e1f612bSBram Moolenaar \ '[0, 4, 12, 0]', 3341e1f612bSBram Moolenaar \ "Xbadfile.c|4 col 12| error: expected ';' before '}' token"], 33554948183SBram Moolenaar \ lines) 33654948183SBram Moolenaar endif 33754948183SBram Moolenaar call delete('Xtestout') 33854948183SBram Moolenaar 33954948183SBram Moolenaar " Test with explicit argument '-qXerrors' (without space). 34054948183SBram Moolenaar if RunVim([], after, '-qXerrors') 34154948183SBram Moolenaar let lines = readfile('Xtestout') 34254948183SBram Moolenaar call assert_equal(['Xerrors', 3431e1f612bSBram Moolenaar \ '[0, 4, 12, 0]', 3441e1f612bSBram Moolenaar \ "Xbadfile.c|4 col 12| error: expected ';' before '}' token"], 34554948183SBram Moolenaar \ lines) 34654948183SBram Moolenaar endif 34754948183SBram Moolenaar 348cde0ff39SBram Moolenaar " Test with a non-existing error file (exits with value 3) 349cde0ff39SBram Moolenaar let out = system(GetVimCommand() .. ' -q xyz.err') 350cde0ff39SBram Moolenaar call assert_equal(3, v:shell_error) 351cde0ff39SBram Moolenaar 3521e1f612bSBram Moolenaar call delete('Xbadfile.c') 35354948183SBram Moolenaar call delete('Xtestout') 35454948183SBram Moolenaar call delete('Xerrors') 35554948183SBram Moolenaarendfunc 35654948183SBram Moolenaar 357036b09caSBram Moolenaar" Test the -V[N]{filename} argument to set the 'verbose' option to N 358036b09caSBram Moolenaar" and set 'verbosefile' to filename. 359036b09caSBram Moolenaarfunc Test_V_file_arg() 3604841a7ccSBram Moolenaar if RunVim([], [], ' --clean -V2Xverbosefile -c "set verbose? verbosefile?" -cq') 361036b09caSBram Moolenaar let out = join(readfile('Xverbosefile'), "\n") 362036b09caSBram Moolenaar call assert_match("sourcing \"$VIMRUNTIME[\\/]defaults\.vim\"\n", out) 363036b09caSBram Moolenaar call assert_match("\n verbose=2\n", out) 364036b09caSBram Moolenaar call assert_match("\n verbosefile=Xverbosefile", out) 365036b09caSBram Moolenaar endif 366036b09caSBram Moolenaar 367036b09caSBram Moolenaar call delete('Xverbosefile') 368036b09caSBram Moolenaarendfunc 369036b09caSBram Moolenaar 370036b09caSBram Moolenaar" Test the -m, -M and -R arguments: 371036b09caSBram Moolenaar" -m resets 'write' 372036b09caSBram Moolenaar" -M resets 'modifiable' and 'write' 373036b09caSBram Moolenaar" -R sets 'readonly' 374036b09caSBram Moolenaarfunc Test_m_M_R() 375c79745a8SBram Moolenaar let after =<< trim [CODE] 376c79745a8SBram Moolenaar call writefile([&write, &modifiable, &readonly, &updatecount], "Xtestout") 377c79745a8SBram Moolenaar qall 378c79745a8SBram Moolenaar [CODE] 379c79745a8SBram Moolenaar 380036b09caSBram Moolenaar if RunVim([], after, '') 381036b09caSBram Moolenaar let lines = readfile('Xtestout') 382036b09caSBram Moolenaar call assert_equal(['1', '1', '0', '200'], lines) 383036b09caSBram Moolenaar endif 384036b09caSBram Moolenaar if RunVim([], after, '-m') 385036b09caSBram Moolenaar let lines = readfile('Xtestout') 386036b09caSBram Moolenaar call assert_equal(['0', '1', '0', '200'], lines) 387036b09caSBram Moolenaar endif 388036b09caSBram Moolenaar if RunVim([], after, '-M') 389036b09caSBram Moolenaar let lines = readfile('Xtestout') 390036b09caSBram Moolenaar call assert_equal(['0', '0', '0', '200'], lines) 391036b09caSBram Moolenaar endif 392036b09caSBram Moolenaar if RunVim([], after, '-R') 393036b09caSBram Moolenaar let lines = readfile('Xtestout') 394036b09caSBram Moolenaar call assert_equal(['1', '1', '1', '10000'], lines) 395036b09caSBram Moolenaar endif 396036b09caSBram Moolenaar 397036b09caSBram Moolenaar call delete('Xtestout') 398036b09caSBram Moolenaarendfunc 399036b09caSBram Moolenaar 4009e81db97SBram Moolenaar" Test the -A, -F and -H arguments (Arabic, Farsi and Hebrew modes). 4019e81db97SBram Moolenaarfunc Test_A_F_H_arg() 402c79745a8SBram Moolenaar let after =<< trim [CODE] 403c79745a8SBram Moolenaar call writefile([&rightleft, &arabic, &fkmap, &hkmap], "Xtestout") 404c79745a8SBram Moolenaar qall 405c79745a8SBram Moolenaar [CODE] 406c79745a8SBram Moolenaar 4074b1c9a91SBram Moolenaar " Use silent Ex mode to avoid the hit-Enter prompt for the warning that 4084b1c9a91SBram Moolenaar " 'encoding' is not utf-8. 4094b1c9a91SBram Moolenaar if has('arabic') && &encoding == 'utf-8' && RunVim([], after, '-e -s -A') 4109e81db97SBram Moolenaar let lines = readfile('Xtestout') 4119e81db97SBram Moolenaar call assert_equal(['1', '1', '0', '0'], lines) 4129e81db97SBram Moolenaar endif 4139e81db97SBram Moolenaar 4149e81db97SBram Moolenaar if has('farsi') && RunVim([], after, '-F') 4159e81db97SBram Moolenaar let lines = readfile('Xtestout') 4169e81db97SBram Moolenaar call assert_equal(['1', '0', '1', '0'], lines) 4179e81db97SBram Moolenaar endif 4189e81db97SBram Moolenaar 4199e81db97SBram Moolenaar if has('rightleft') && RunVim([], after, '-H') 4209e81db97SBram Moolenaar let lines = readfile('Xtestout') 4219e81db97SBram Moolenaar call assert_equal(['1', '0', '0', '1'], lines) 4229e81db97SBram Moolenaar endif 4239e81db97SBram Moolenaar 4249e81db97SBram Moolenaar call delete('Xtestout') 4259e81db97SBram Moolenaarendfunc 4269e81db97SBram Moolenaar 427240309c9SBram Moolenaar" Test the --echo-wid argument (for GTK GUI only). 428240309c9SBram Moolenaarfunc Test_echo_wid() 429240309c9SBram Moolenaar CheckCanRunGui 430240309c9SBram Moolenaar CheckFeature gui_gtk 431240309c9SBram Moolenaar 432240309c9SBram Moolenaar if RunVim([], [], '-g --echo-wid -cq >Xtest_echo_wid') 433240309c9SBram Moolenaar let lines = readfile('Xtest_echo_wid') 434240309c9SBram Moolenaar call assert_equal(1, len(lines)) 435240309c9SBram Moolenaar call assert_match('^WID: \d\+$', lines[0]) 436240309c9SBram Moolenaar endif 437240309c9SBram Moolenaar 438240309c9SBram Moolenaar call delete('Xtest_echo_wid') 439240309c9SBram Moolenaarendfunction 440240309c9SBram Moolenaar 441240309c9SBram Moolenaar" Test the -reverse and +reverse arguments (for GUI only). 442240309c9SBram Moolenaarfunc Test_reverse() 443240309c9SBram Moolenaar CheckCanRunGui 444f8c52e8dSBram Moolenaar CheckAnyOf Feature:gui_gtk Feature:gui_motif Feature:gui_athena 445240309c9SBram Moolenaar 446240309c9SBram Moolenaar let after =<< trim [CODE] 447240309c9SBram Moolenaar call writefile([&background], "Xtest_reverse") 448240309c9SBram Moolenaar qall 449240309c9SBram Moolenaar [CODE] 450240309c9SBram Moolenaar if RunVim([], after, '-f -g -reverse') 451240309c9SBram Moolenaar let lines = readfile('Xtest_reverse') 452240309c9SBram Moolenaar call assert_equal(['dark'], lines) 453240309c9SBram Moolenaar endif 454240309c9SBram Moolenaar if RunVim([], after, '-f -g +reverse') 455240309c9SBram Moolenaar let lines = readfile('Xtest_reverse') 456240309c9SBram Moolenaar call assert_equal(['light'], lines) 457240309c9SBram Moolenaar endif 458240309c9SBram Moolenaar 459240309c9SBram Moolenaar call delete('Xtest_reverse') 460240309c9SBram Moolenaarendfunc 461240309c9SBram Moolenaar 462240309c9SBram Moolenaar" Test the -background and -foreground arguments (for GUI only). 463240309c9SBram Moolenaarfunc Test_background_foreground() 464240309c9SBram Moolenaar CheckCanRunGui 465f8c52e8dSBram Moolenaar CheckAnyOf Feature:gui_gtk Feature:gui_motif Feature:gui_athena 466240309c9SBram Moolenaar 467240309c9SBram Moolenaar " Is there a better way to check the effect of -background & -foreground 468240309c9SBram Moolenaar " other than merely looking at &background (dark or light)? 469240309c9SBram Moolenaar let after =<< trim [CODE] 470240309c9SBram Moolenaar call writefile([&background], "Xtest_fg_bg") 471240309c9SBram Moolenaar qall 472240309c9SBram Moolenaar [CODE] 473240309c9SBram Moolenaar if RunVim([], after, '-f -g -background darkred -foreground yellow') 474240309c9SBram Moolenaar let lines = readfile('Xtest_fg_bg') 475240309c9SBram Moolenaar call assert_equal(['dark'], lines) 476240309c9SBram Moolenaar endif 477240309c9SBram Moolenaar if RunVim([], after, '-f -g -background ivory -foreground darkgreen') 478240309c9SBram Moolenaar let lines = readfile('Xtest_fg_bg') 479240309c9SBram Moolenaar call assert_equal(['light'], lines) 480240309c9SBram Moolenaar endif 481240309c9SBram Moolenaar 482240309c9SBram Moolenaar call delete('Xtest_fg_bg') 483240309c9SBram Moolenaarendfunc 484240309c9SBram Moolenaar 485240309c9SBram Moolenaar" Test the -font argument (for GUI only). 486240309c9SBram Moolenaarfunc Test_font() 487240309c9SBram Moolenaar CheckCanRunGui 488240309c9SBram Moolenaar CheckNotMSWindows 489240309c9SBram Moolenaar 490240309c9SBram Moolenaar if has('gui_gtk') 491240309c9SBram Moolenaar let font = 'Courier 14' 492240309c9SBram Moolenaar elseif has('gui_motif') || has('gui_athena') 493240309c9SBram Moolenaar let font = '-misc-fixed-bold-*' 494240309c9SBram Moolenaar else 495240309c9SBram Moolenaar throw 'Skipped: test does not set a valid font for this GUI' 496240309c9SBram Moolenaar endif 497240309c9SBram Moolenaar 498240309c9SBram Moolenaar let after =<< trim [CODE] 499240309c9SBram Moolenaar call writefile([&guifont], "Xtest_font") 500240309c9SBram Moolenaar qall 501240309c9SBram Moolenaar [CODE] 502240309c9SBram Moolenaar 503240309c9SBram Moolenaar if RunVim([], after, '--nofork -g -font "' .. font .. '"') 504240309c9SBram Moolenaar let lines = readfile('Xtest_font') 505240309c9SBram Moolenaar call assert_equal([font], lines) 506240309c9SBram Moolenaar endif 507240309c9SBram Moolenaar 508240309c9SBram Moolenaar call delete('Xtest_font') 509240309c9SBram Moolenaarendfunc 510240309c9SBram Moolenaar 511240309c9SBram Moolenaar" Test the -geometry argument (for GUI only). 512240309c9SBram Moolenaarfunc Test_geometry() 513240309c9SBram Moolenaar CheckCanRunGui 514f8c52e8dSBram Moolenaar CheckAnyOf Feature:gui_gtk Feature:gui_motif Feature:gui_athena 515240309c9SBram Moolenaar 516240309c9SBram Moolenaar if has('gui_motif') || has('gui_athena') 517240309c9SBram Moolenaar " FIXME: With GUI Athena or Motif, the value of getwinposx(), 518240309c9SBram Moolenaar " getwinposy() and getwinpos() do not match exactly the 519240309c9SBram Moolenaar " value given in -geometry. Why? 520240309c9SBram Moolenaar " So only check &columns and &lines for those GUIs. 521240309c9SBram Moolenaar let after =<< trim [CODE] 522240309c9SBram Moolenaar call writefile([&columns, &lines], "Xtest_geometry") 523240309c9SBram Moolenaar qall 524240309c9SBram Moolenaar [CODE] 525240309c9SBram Moolenaar if RunVim([], after, '-f -g -geometry 31x13+41+43') 526240309c9SBram Moolenaar let lines = readfile('Xtest_geometry') 527240309c9SBram Moolenaar call assert_equal(['31', '13'], lines) 528240309c9SBram Moolenaar endif 529240309c9SBram Moolenaar else 530240309c9SBram Moolenaar let after =<< trim [CODE] 531240309c9SBram Moolenaar call writefile([&columns, &lines, getwinposx(), getwinposy(), string(getwinpos())], "Xtest_geometry") 532240309c9SBram Moolenaar qall 533240309c9SBram Moolenaar [CODE] 534240309c9SBram Moolenaar if RunVim([], after, '-f -g -geometry 31x13+41+43') 535240309c9SBram Moolenaar let lines = readfile('Xtest_geometry') 536b376aa2dSBram Moolenaar " Depending on the GUI library and the windowing system the final size 537b376aa2dSBram Moolenaar " might be a bit different, allow for some tolerance. Tuned based on 538b376aa2dSBram Moolenaar " actual failures. 539*3d031a0aSBram Moolenaar call assert_inrange(31, 35, str2nr(lines[0])) 540*3d031a0aSBram Moolenaar call assert_equal('13', lines[1]) 541*3d031a0aSBram Moolenaar call assert_equal('41', lines[2]) 542*3d031a0aSBram Moolenaar call assert_equal('43', lines[3]) 543*3d031a0aSBram Moolenaar call assert_equal('[41, 43]', lines[4]) 544240309c9SBram Moolenaar endif 545240309c9SBram Moolenaar endif 546240309c9SBram Moolenaar 547240309c9SBram Moolenaar call delete('Xtest_geometry') 548240309c9SBram Moolenaarendfunc 549240309c9SBram Moolenaar 550240309c9SBram Moolenaar" Test the -iconic argument (for GUI only). 551240309c9SBram Moolenaarfunc Test_iconic() 552240309c9SBram Moolenaar CheckCanRunGui 553f8c52e8dSBram Moolenaar CheckAnyOf Feature:gui_gtk Feature:gui_motif Feature:gui_athena 554240309c9SBram Moolenaar 555240309c9SBram Moolenaar call RunVim([], [], '-f -g -iconic -cq') 556240309c9SBram Moolenaar 557240309c9SBram Moolenaar " TODO: currently only start vim iconified, but does not 558240309c9SBram Moolenaar " check that vim is iconified. How could this be checked? 559240309c9SBram Moolenaarendfunc 560240309c9SBram Moolenaar 561240309c9SBram Moolenaar 562ba9ea91bSBram Moolenaarfunc Test_invalid_args() 5638c5a278fSBram Moolenaar " must be able to get the output of Vim. 5648c5a278fSBram Moolenaar CheckUnix 5658c5a278fSBram Moolenaar CheckNotGui 566ba9ea91bSBram Moolenaar 567ba9ea91bSBram Moolenaar for opt in ['-Y', '--does-not-exist'] 568ba9ea91bSBram Moolenaar let out = split(system(GetVimCommand() .. ' ' .. opt), "\n") 569ba9ea91bSBram Moolenaar call assert_equal(1, v:shell_error) 570ba9ea91bSBram Moolenaar call assert_match('^VIM - Vi IMproved .* (.*)$', out[0]) 571ba9ea91bSBram Moolenaar call assert_equal('Unknown option argument: "' .. opt .. '"', out[1]) 572ba9ea91bSBram Moolenaar call assert_equal('More info with: "vim -h"', out[2]) 573ba9ea91bSBram Moolenaar endfor 574ba9ea91bSBram Moolenaar 575ba9ea91bSBram Moolenaar for opt in ['-c', '-i', '-s', '-t', '-T', '-u', '-U', '-w', '-W', '--cmd', '--startuptime'] 576ba9ea91bSBram Moolenaar let out = split(system(GetVimCommand() .. ' ' .. opt), "\n") 577ba9ea91bSBram Moolenaar call assert_equal(1, v:shell_error) 578ba9ea91bSBram Moolenaar call assert_match('^VIM - Vi IMproved .* (.*)$', out[0]) 579ba9ea91bSBram Moolenaar call assert_equal('Argument missing after: "' .. opt .. '"', out[1]) 580ba9ea91bSBram Moolenaar call assert_equal('More info with: "vim -h"', out[2]) 581ba9ea91bSBram Moolenaar endfor 582ba9ea91bSBram Moolenaar 583ba9ea91bSBram Moolenaar if has('clientserver') 584ba9ea91bSBram Moolenaar for opt in ['--remote', '--remote-send', '--remote-silent', '--remote-expr', 585ba9ea91bSBram Moolenaar \ '--remote-tab', '--remote-tab-wait', 586ba9ea91bSBram Moolenaar \ '--remote-tab-wait-silent', '--remote-tab-silent', 587ba9ea91bSBram Moolenaar \ '--remote-wait', '--remote-wait-silent', 58827821260SBram Moolenaar \ '--servername', 589ba9ea91bSBram Moolenaar \ ] 590ba9ea91bSBram Moolenaar let out = split(system(GetVimCommand() .. ' ' .. opt), "\n") 591ba9ea91bSBram Moolenaar call assert_equal(1, v:shell_error) 592ba9ea91bSBram Moolenaar call assert_match('^VIM - Vi IMproved .* (.*)$', out[0]) 593ba9ea91bSBram Moolenaar call assert_equal('Argument missing after: "' .. opt .. '"', out[1]) 594ba9ea91bSBram Moolenaar call assert_equal('More info with: "vim -h"', out[2]) 595ba9ea91bSBram Moolenaar endfor 596ba9ea91bSBram Moolenaar endif 597ba9ea91bSBram Moolenaar 598240f7abaSBram Moolenaar if has('gui_gtk') 59927821260SBram Moolenaar let out = split(system(GetVimCommand() .. ' --display'), "\n") 60027821260SBram Moolenaar call assert_equal(1, v:shell_error) 60127821260SBram Moolenaar call assert_match('^VIM - Vi IMproved .* (.*)$', out[0]) 60227821260SBram Moolenaar call assert_equal('Argument missing after: "--display"', out[1]) 60327821260SBram Moolenaar call assert_equal('More info with: "vim -h"', out[2]) 60427821260SBram Moolenaar endif 605ba9ea91bSBram Moolenaar 6065416b750SBram Moolenaar if has('xterm_clipboard') 607240f7abaSBram Moolenaar let out = split(system(GetVimCommand() .. ' -display'), "\n") 608240f7abaSBram Moolenaar call assert_equal(1, v:shell_error) 609240f7abaSBram Moolenaar call assert_match('^VIM - Vi IMproved .* (.*)$', out[0]) 610240f7abaSBram Moolenaar call assert_equal('Argument missing after: "-display"', out[1]) 611240f7abaSBram Moolenaar call assert_equal('More info with: "vim -h"', out[2]) 612240f7abaSBram Moolenaar endif 613240f7abaSBram Moolenaar 614ba9ea91bSBram Moolenaar let out = split(system(GetVimCommand() .. ' -ix'), "\n") 615ba9ea91bSBram Moolenaar call assert_equal(1, v:shell_error) 616ba9ea91bSBram Moolenaar call assert_match('^VIM - Vi IMproved .* (.*)$', out[0]) 617ba9ea91bSBram Moolenaar call assert_equal('Garbage after option argument: "-ix"', out[1]) 618ba9ea91bSBram Moolenaar call assert_equal('More info with: "vim -h"', out[2]) 619ba9ea91bSBram Moolenaar 620ba9ea91bSBram Moolenaar let out = split(system(GetVimCommand() .. ' - xxx'), "\n") 621ba9ea91bSBram Moolenaar call assert_equal(1, v:shell_error) 622ba9ea91bSBram Moolenaar call assert_match('^VIM - Vi IMproved .* (.*)$', out[0]) 623ba9ea91bSBram Moolenaar call assert_equal('Too many edit arguments: "xxx"', out[1]) 624ba9ea91bSBram Moolenaar call assert_equal('More info with: "vim -h"', out[2]) 625ba9ea91bSBram Moolenaar 6265a4c3082SBram Moolenaar if has('quickfix') 627d176ca3dSDominique Pelle " Detect invalid repeated arguments '-t foo -t foo', '-q foo -q foo'. 628ba9ea91bSBram Moolenaar for opt in ['-t', '-q'] 629ba9ea91bSBram Moolenaar let out = split(system(GetVimCommand() .. repeat(' ' .. opt .. ' foo', 2)), "\n") 630ba9ea91bSBram Moolenaar call assert_equal(1, v:shell_error) 631ba9ea91bSBram Moolenaar call assert_match('^VIM - Vi IMproved .* (.*)$', out[0]) 632ba9ea91bSBram Moolenaar call assert_equal('Too many edit arguments: "' .. opt .. '"', out[1]) 633ba9ea91bSBram Moolenaar call assert_equal('More info with: "vim -h"', out[2]) 634ba9ea91bSBram Moolenaar endfor 6355a4c3082SBram Moolenaar endif 636ba9ea91bSBram Moolenaar 637ba9ea91bSBram Moolenaar for opt in [' -cq', ' --cmd q', ' +', ' -S foo'] 638ba9ea91bSBram Moolenaar let out = split(system(GetVimCommand() .. repeat(opt, 11)), "\n") 639ba9ea91bSBram Moolenaar call assert_equal(1, v:shell_error) 640ba9ea91bSBram Moolenaar " FIXME: The error message given by Vim is not ideal in case of repeated 641ba9ea91bSBram Moolenaar " -S foo since it does not mention -S. 642ba9ea91bSBram Moolenaar call assert_match('^VIM - Vi IMproved .* (.*)$', out[0]) 643ba9ea91bSBram Moolenaar call assert_equal('Too many "+command", "-c command" or "--cmd command" arguments', out[1]) 644ba9ea91bSBram Moolenaar call assert_equal('More info with: "vim -h"', out[2]) 645ba9ea91bSBram Moolenaar endfor 646ba9ea91bSBram Moolenaar 64727821260SBram Moolenaar if has('gui_gtk') 6486d37e8e3SDominique Pelle let out = split(system(GetVimCommand() .. ' --socketid'), "\n") 6496d37e8e3SDominique Pelle call assert_equal(1, v:shell_error) 6506d37e8e3SDominique Pelle call assert_match('^VIM - Vi IMproved .* (.*)$', out[0]) 6516d37e8e3SDominique Pelle call assert_equal('Argument missing after: "--socketid"', out[1]) 6526d37e8e3SDominique Pelle call assert_equal('More info with: "vim -h"', out[2]) 6536d37e8e3SDominique Pelle 65427821260SBram Moolenaar for opt in ['--socketid x', '--socketid 0xg'] 65527821260SBram Moolenaar let out = split(system(GetVimCommand() .. ' ' .. opt), "\n") 65627821260SBram Moolenaar call assert_equal(1, v:shell_error) 65727821260SBram Moolenaar call assert_match('^VIM - Vi IMproved .* (.*)$', out[0]) 65827821260SBram Moolenaar call assert_equal('Invalid argument for: "--socketid"', out[1]) 65927821260SBram Moolenaar call assert_equal('More info with: "vim -h"', out[2]) 66027821260SBram Moolenaar endfor 6616d37e8e3SDominique Pelle 66227821260SBram Moolenaar endif 663ba9ea91bSBram Moolenaarendfunc 664ba9ea91bSBram Moolenaar 665ba98bef1SBram Moolenaarfunc Test_file_args() 666c79745a8SBram Moolenaar let after =<< trim [CODE] 667c79745a8SBram Moolenaar call writefile(argv(), "Xtestout") 668c79745a8SBram Moolenaar qall 669c79745a8SBram Moolenaar [CODE] 670c79745a8SBram Moolenaar 671ba98bef1SBram Moolenaar if RunVim([], after, '') 672ba98bef1SBram Moolenaar let lines = readfile('Xtestout') 673ba98bef1SBram Moolenaar call assert_equal(0, len(lines)) 674ba98bef1SBram Moolenaar endif 675ba98bef1SBram Moolenaar 676ba98bef1SBram Moolenaar if RunVim([], after, 'one') 677ba98bef1SBram Moolenaar let lines = readfile('Xtestout') 678ba98bef1SBram Moolenaar call assert_equal(1, len(lines)) 679ba98bef1SBram Moolenaar call assert_equal('one', lines[0]) 680ba98bef1SBram Moolenaar endif 681ba98bef1SBram Moolenaar 682ba98bef1SBram Moolenaar if RunVim([], after, 'one two three') 683ba98bef1SBram Moolenaar let lines = readfile('Xtestout') 684ba98bef1SBram Moolenaar call assert_equal(3, len(lines)) 685ba98bef1SBram Moolenaar call assert_equal('one', lines[0]) 686ba98bef1SBram Moolenaar call assert_equal('two', lines[1]) 687ba98bef1SBram Moolenaar call assert_equal('three', lines[2]) 688ba98bef1SBram Moolenaar endif 689ba98bef1SBram Moolenaar 690ba98bef1SBram Moolenaar if RunVim([], after, 'one -c echo two') 691ba98bef1SBram Moolenaar let lines = readfile('Xtestout') 692ba98bef1SBram Moolenaar call assert_equal(2, len(lines)) 693ba98bef1SBram Moolenaar call assert_equal('one', lines[0]) 694ba98bef1SBram Moolenaar call assert_equal('two', lines[1]) 695ba98bef1SBram Moolenaar endif 696ba98bef1SBram Moolenaar 697ba98bef1SBram Moolenaar if RunVim([], after, 'one -- -c echo two') 698ba98bef1SBram Moolenaar let lines = readfile('Xtestout') 699ba98bef1SBram Moolenaar call assert_equal(4, len(lines)) 700ba98bef1SBram Moolenaar call assert_equal('one', lines[0]) 701ba98bef1SBram Moolenaar call assert_equal('-c', lines[1]) 702ba98bef1SBram Moolenaar call assert_equal('echo', lines[2]) 703ba98bef1SBram Moolenaar call assert_equal('two', lines[3]) 704ba98bef1SBram Moolenaar endif 705ba98bef1SBram Moolenaar 706ba98bef1SBram Moolenaar call delete('Xtestout') 707ba98bef1SBram Moolenaarendfunc 708ba98bef1SBram Moolenaar 709ba98bef1SBram Moolenaarfunc Test_startuptime() 7106d91bcb4SBram Moolenaar CheckFeature startuptime 711ba98bef1SBram Moolenaar let after = ['qall'] 712ba98bef1SBram Moolenaar if RunVim([], after, '--startuptime Xtestout one') 713ba98bef1SBram Moolenaar let lines = readfile('Xtestout') 714ba98bef1SBram Moolenaar let expected = ['--- VIM STARTING ---', 'parsing arguments', 715ba98bef1SBram Moolenaar \ 'shell init', 'inits 3', 'start termcap', 'opening buffers'] 716ba98bef1SBram Moolenaar let found = [] 717ba98bef1SBram Moolenaar for line in lines 718ba98bef1SBram Moolenaar for exp in expected 719ba98bef1SBram Moolenaar if line =~ exp 720ba98bef1SBram Moolenaar call add(found, exp) 721ba98bef1SBram Moolenaar endif 722ba98bef1SBram Moolenaar endfor 723ba98bef1SBram Moolenaar endfor 724ba98bef1SBram Moolenaar call assert_equal(expected, found) 725ba98bef1SBram Moolenaar endif 726ba98bef1SBram Moolenaar call delete('Xtestout') 727ba98bef1SBram Moolenaarendfunc 7283a938383SBram Moolenaar 7293a938383SBram Moolenaarfunc Test_read_stdin() 730c79745a8SBram Moolenaar let after =<< trim [CODE] 731c79745a8SBram Moolenaar write Xtestout 732c79745a8SBram Moolenaar quit! 733c79745a8SBram Moolenaar [CODE] 734c79745a8SBram Moolenaar 7353a938383SBram Moolenaar if RunVimPiped([], after, '-', 'echo something | ') 7363a938383SBram Moolenaar let lines = readfile('Xtestout') 737e4a76ad0SBram Moolenaar " MS-Windows adds a space after the word 738e4a76ad0SBram Moolenaar call assert_equal(['something'], split(lines[0])) 7393a938383SBram Moolenaar endif 7403a938383SBram Moolenaar call delete('Xtestout') 7413a938383SBram Moolenaarendfunc 74208cab960SBram Moolenaar 74308cab960SBram Moolenaarfunc Test_progpath() 74408cab960SBram Moolenaar " Tests normally run with "./vim" or "../vim", these must have been expanded 74508cab960SBram Moolenaar " to a full path. 74608cab960SBram Moolenaar if has('unix') 74708cab960SBram Moolenaar call assert_equal('/', v:progpath[0]) 74808cab960SBram Moolenaar elseif has('win32') 74908cab960SBram Moolenaar call assert_equal(':', v:progpath[1]) 75008cab960SBram Moolenaar call assert_match('[/\\]', v:progpath[2]) 75108cab960SBram Moolenaar endif 75208cab960SBram Moolenaar 75308cab960SBram Moolenaar " Only expect "vim" to appear in v:progname. 75408cab960SBram Moolenaar call assert_match('vim\c', v:progname) 75508cab960SBram Moolenaarendfunc 756d5d37537SBram Moolenaar 757d5d37537SBram Moolenaarfunc Test_silent_ex_mode() 7588c5a278fSBram Moolenaar " must be able to get the output of Vim. 7598c5a278fSBram Moolenaar CheckUnix 7608c5a278fSBram Moolenaar CheckNotGui 761d5d37537SBram Moolenaar 762d5d37537SBram Moolenaar " This caused an ml_get error. 763d5d37537SBram Moolenaar let out = system(GetVimCommand() . '-u NONE -es -c''set verbose=1|h|exe "%norm\<c-y>\<c-d>"'' -c cq') 764d5d37537SBram Moolenaar call assert_notmatch('E315:', out) 765d5d37537SBram Moolenaarendfunc 76685045a73SBram Moolenaar 76785045a73SBram Moolenaarfunc Test_default_term() 7688c5a278fSBram Moolenaar " must be able to get the output of Vim. 7698c5a278fSBram Moolenaar CheckUnix 7708c5a278fSBram Moolenaar CheckNotGui 77185045a73SBram Moolenaar 77285045a73SBram Moolenaar let save_term = $TERM 77308f88b13SBram Moolenaar let $TERM = 'unknownxxx' 77485045a73SBram Moolenaar let out = system(GetVimCommand() . ' -c''set term'' -c cq') 77585045a73SBram Moolenaar call assert_match("defaulting to 'ansi'", out) 77685045a73SBram Moolenaar let $TERM = save_term 77785045a73SBram Moolenaarendfunc 77809ca932fSBram Moolenaar 77909ca932fSBram Moolenaarfunc Test_zzz_startinsert() 78009ca932fSBram Moolenaar " Test :startinsert 78109ca932fSBram Moolenaar call writefile(['123456'], 'Xtestout') 782c79745a8SBram Moolenaar let after =<< trim [CODE] 783c79745a8SBram Moolenaar :startinsert 784c79745a8SBram Moolenaar call feedkeys("foobar\<c-o>:wq\<cr>","t") 785c79745a8SBram Moolenaar [CODE] 786c79745a8SBram Moolenaar 78709ca932fSBram Moolenaar if RunVim([], after, 'Xtestout') 78809ca932fSBram Moolenaar let lines = readfile('Xtestout') 78909ca932fSBram Moolenaar call assert_equal(['foobar123456'], lines) 79009ca932fSBram Moolenaar endif 79109ca932fSBram Moolenaar " Test :startinsert! 79209ca932fSBram Moolenaar call writefile(['123456'], 'Xtestout') 793c79745a8SBram Moolenaar let after =<< trim [CODE] 794c79745a8SBram Moolenaar :startinsert! 795c79745a8SBram Moolenaar call feedkeys("foobar\<c-o>:wq\<cr>","t") 796c79745a8SBram Moolenaar [CODE] 797c79745a8SBram Moolenaar 79809ca932fSBram Moolenaar if RunVim([], after, 'Xtestout') 79909ca932fSBram Moolenaar let lines = readfile('Xtestout') 80009ca932fSBram Moolenaar call assert_equal(['123456foobar'], lines) 80109ca932fSBram Moolenaar endif 80209ca932fSBram Moolenaar call delete('Xtestout') 80309ca932fSBram Moolenaarendfunc 80497c2c05eSBram Moolenaar 80597c2c05eSBram Moolenaarfunc Test_issue_3969() 80697c2c05eSBram Moolenaar " Can't catch the output of gvim. 8078c5a278fSBram Moolenaar CheckNotGui 8088c5a278fSBram Moolenaar 80997c2c05eSBram Moolenaar " Check that message is not truncated. 81097c2c05eSBram Moolenaar let out = system(GetVimCommand() . ' -es -X -V1 -c "echon ''hello''" -cq') 81197c2c05eSBram Moolenaar call assert_equal('hello', out) 81297c2c05eSBram Moolenaarendfunc 813c75e8126SBram Moolenaar 814c75e8126SBram Moolenaarfunc Test_start_with_tabs() 815494e9069SBram Moolenaar CheckRunVimInTerminal 816c75e8126SBram Moolenaar 817c75e8126SBram Moolenaar let buf = RunVimInTerminal('-p a b c', {}) 818c75e8126SBram Moolenaar call VerifyScreenDump(buf, 'Test_start_with_tabs', {}) 819c75e8126SBram Moolenaar 820c75e8126SBram Moolenaar " clean up 821c75e8126SBram Moolenaar call StopVimInTerminal(buf) 822c75e8126SBram Moolenaarendfunc 82369bf6348SBram Moolenaar 82469bf6348SBram Moolenaarfunc Test_v_argv() 82569bf6348SBram Moolenaar " Can't catch the output of gvim. 82669bf6348SBram Moolenaar CheckNotGui 82769bf6348SBram Moolenaar 82869bf6348SBram Moolenaar let out = system(GetVimCommand() . ' -es -V1 -X arg1 --cmd "echo v:argv" --cmd q') 82969bf6348SBram Moolenaar let list = out->split("', '") 83069bf6348SBram Moolenaar call assert_match('vim', list[0]) 83169bf6348SBram Moolenaar let idx = index(list, 'arg1') 83269bf6348SBram Moolenaar call assert_true(idx > 2) 83369bf6348SBram Moolenaar call assert_equal(['arg1', '--cmd', 'echo v:argv', '--cmd', 'q'']'], list[idx:]) 83469bf6348SBram Moolenaarendfunc 835cde0ff39SBram Moolenaar 836cde0ff39SBram Moolenaar" Test for the "-r" recovery mode option 837cde0ff39SBram Moolenaarfunc Test_r_arg() 838cde0ff39SBram Moolenaar " Can't catch the output of gvim. 839cde0ff39SBram Moolenaar CheckNotGui 840cde0ff39SBram Moolenaar CheckUnix 841cde0ff39SBram Moolenaar CheckEnglish 842cde0ff39SBram Moolenaar let cmd = GetVimCommand() 843cde0ff39SBram Moolenaar " There can be swap files anywhere, only check for the headers. 844cde0ff39SBram Moolenaar let expected =<< trim END 845cde0ff39SBram Moolenaar Swap files found:.* 846cde0ff39SBram Moolenaar In current directory:.* 847cde0ff39SBram Moolenaar In directory \~/tmp:.* 848cde0ff39SBram Moolenaar In directory /var/tmp:.* 849cde0ff39SBram Moolenaar In directory /tmp:.* 850cde0ff39SBram Moolenaar END 851cde0ff39SBram Moolenaar call assert_match(join(expected, ""), system(cmd .. " -r")->substitute("[\r\n]\\+", '', '')) 852cde0ff39SBram Moolenaarendfunc 853cde0ff39SBram Moolenaar 854cde0ff39SBram Moolenaar" Test for the '-t' option to jump to a tag 855cde0ff39SBram Moolenaarfunc Test_t_arg() 856cde0ff39SBram Moolenaar let before =<< trim [CODE] 857cde0ff39SBram Moolenaar set tags=Xtags 858cde0ff39SBram Moolenaar [CODE] 859cde0ff39SBram Moolenaar let after =<< trim [CODE] 860cde0ff39SBram Moolenaar let s = bufname('') .. ':L' .. line('.') .. 'C' .. col('.') 861cde0ff39SBram Moolenaar call writefile([s], "Xtestout") 862cde0ff39SBram Moolenaar qall 863cde0ff39SBram Moolenaar [CODE] 864cde0ff39SBram Moolenaar 865cde0ff39SBram Moolenaar call writefile(["!_TAG_FILE_ENCODING\tutf-8\t//", 866cde0ff39SBram Moolenaar \ "first\tXfile1\t/^ \\zsfirst$/", 867cde0ff39SBram Moolenaar \ "second\tXfile1\t/^ \\zssecond$/", 868cde0ff39SBram Moolenaar \ "third\tXfile1\t/^ \\zsthird$/"], 869cde0ff39SBram Moolenaar \ 'Xtags') 870cde0ff39SBram Moolenaar call writefile([' first', ' second', ' third'], 'Xfile1') 871cde0ff39SBram Moolenaar 872a2b3e7dcSBram Moolenaar for t_arg in ['-t second', '-tsecond'] 873d176ca3dSDominique Pelle if RunVim(before, after, t_arg) 874a2b3e7dcSBram Moolenaar call assert_equal(['Xfile1:L2C5'], readfile('Xtestout'), t_arg) 875cde0ff39SBram Moolenaar call delete('Xtestout') 876cde0ff39SBram Moolenaar endif 877a2b3e7dcSBram Moolenaar endfor 878cde0ff39SBram Moolenaar 879cde0ff39SBram Moolenaar call delete('Xtags') 880cde0ff39SBram Moolenaar call delete('Xfile1') 881cde0ff39SBram Moolenaarendfunc 882cde0ff39SBram Moolenaar 8831f33e0a7SBram Moolenaar" Test the '-T' argument which sets the 'term' option. 8841f33e0a7SBram Moolenaarfunc Test_T_arg() 8851f33e0a7SBram Moolenaar CheckNotGui 8861f33e0a7SBram Moolenaar let after =<< trim [CODE] 8871f33e0a7SBram Moolenaar call writefile([&term], "Xtest_T_arg") 8881f33e0a7SBram Moolenaar qall 8891f33e0a7SBram Moolenaar [CODE] 8901f33e0a7SBram Moolenaar 8911f33e0a7SBram Moolenaar for t in ['builtin_dumb', 'builtin_ansi'] 8921f33e0a7SBram Moolenaar if RunVim([], after, '-T ' .. t) 8931f33e0a7SBram Moolenaar let lines = readfile('Xtest_T_arg') 8941f33e0a7SBram Moolenaar call assert_equal([t], lines) 8951f33e0a7SBram Moolenaar endif 8961f33e0a7SBram Moolenaar endfor 8971f33e0a7SBram Moolenaar 8981f33e0a7SBram Moolenaar call delete('Xtest_T_arg') 8991f33e0a7SBram Moolenaarendfunc 9001f33e0a7SBram Moolenaar 9011f33e0a7SBram Moolenaar" Test the '-x' argument to read/write encrypted files. 9021f33e0a7SBram Moolenaarfunc Test_x_arg() 9031f33e0a7SBram Moolenaar CheckRunVimInTerminal 9041f33e0a7SBram Moolenaar CheckFeature cryptv 9051f33e0a7SBram Moolenaar 9061f33e0a7SBram Moolenaar " Create an encrypted file Xtest_x_arg. 9071f33e0a7SBram Moolenaar let buf = RunVimInTerminal('-n -x Xtest_x_arg', #{rows: 10, wait_for_ruler: 0}) 9081f33e0a7SBram Moolenaar call WaitForAssert({-> assert_match('^Enter encryption key: ', term_getline(buf, 10))}) 9091f33e0a7SBram Moolenaar call term_sendkeys(buf, "foo\n") 9101f33e0a7SBram Moolenaar call WaitForAssert({-> assert_match('^Enter same key again: ', term_getline(buf, 10))}) 9111f33e0a7SBram Moolenaar call term_sendkeys(buf, "foo\n") 9121f33e0a7SBram Moolenaar call WaitForAssert({-> assert_match(' All$', term_getline(buf, 10))}) 9131f33e0a7SBram Moolenaar call term_sendkeys(buf, "itest\<Esc>:w\<Enter>") 9141f33e0a7SBram Moolenaar call WaitForAssert({-> assert_match('"Xtest_x_arg" \[New\]\[blowfish2\] 1L, 5B written', 9151f33e0a7SBram Moolenaar \ term_getline(buf, 10))}) 9161f33e0a7SBram Moolenaar call StopVimInTerminal(buf) 9171f33e0a7SBram Moolenaar 9181f33e0a7SBram Moolenaar " Read the encrypted file and check that it contains the expected content "test" 9191f33e0a7SBram Moolenaar let buf = RunVimInTerminal('-n -x Xtest_x_arg', #{rows: 10, wait_for_ruler: 0}) 9201f33e0a7SBram Moolenaar call WaitForAssert({-> assert_match('^Enter encryption key: ', term_getline(buf, 10))}) 9211f33e0a7SBram Moolenaar call term_sendkeys(buf, "foo\n") 9221f33e0a7SBram Moolenaar call WaitForAssert({-> assert_match('^Enter same key again: ', term_getline(buf, 10))}) 9231f33e0a7SBram Moolenaar call term_sendkeys(buf, "foo\n") 9241f33e0a7SBram Moolenaar call WaitForAssert({-> assert_match('^test', term_getline(buf, 1))}) 9251f33e0a7SBram Moolenaar call StopVimInTerminal(buf) 9261f33e0a7SBram Moolenaar 9271f33e0a7SBram Moolenaar call delete('Xtest_x_arg') 9281f33e0a7SBram Moolenaarendfunc 9291f33e0a7SBram Moolenaar 930cde0ff39SBram Moolenaar" Test for entering the insert mode on startup 931cde0ff39SBram Moolenaarfunc Test_start_insertmode() 932cde0ff39SBram Moolenaar let before =<< trim [CODE] 933cde0ff39SBram Moolenaar set insertmode 934cde0ff39SBram Moolenaar [CODE] 935cde0ff39SBram Moolenaar let after =<< trim [CODE] 936cde0ff39SBram Moolenaar call writefile(['insertmode=' .. &insertmode], 'Xtestout') 937cde0ff39SBram Moolenaar qall 938cde0ff39SBram Moolenaar [CODE] 939cde0ff39SBram Moolenaar if RunVim(before, after, '') 940cde0ff39SBram Moolenaar call assert_equal(['insertmode=1'], readfile('Xtestout')) 941cde0ff39SBram Moolenaar call delete('Xtestout') 942cde0ff39SBram Moolenaar endif 943cde0ff39SBram Moolenaarendfunc 944cde0ff39SBram Moolenaar 945cde0ff39SBram Moolenaar" Test for enabling the binary mode on startup 946cde0ff39SBram Moolenaarfunc Test_b_arg() 947cde0ff39SBram Moolenaar let after =<< trim [CODE] 948cde0ff39SBram Moolenaar call writefile(['binary=' .. &binary], 'Xtestout') 949cde0ff39SBram Moolenaar qall 950cde0ff39SBram Moolenaar [CODE] 951cde0ff39SBram Moolenaar if RunVim([], after, '-b') 952cde0ff39SBram Moolenaar call assert_equal(['binary=1'], readfile('Xtestout')) 953cde0ff39SBram Moolenaar call delete('Xtestout') 954cde0ff39SBram Moolenaar endif 955cde0ff39SBram Moolenaarendfunc 956cde0ff39SBram Moolenaar 957cde0ff39SBram Moolenaar" Test for enabling the lisp mode on startup 958cde0ff39SBram Moolenaarfunc Test_l_arg() 959cde0ff39SBram Moolenaar let after =<< trim [CODE] 960cde0ff39SBram Moolenaar let s = 'lisp=' .. &lisp .. ', showmatch=' .. &showmatch 961cde0ff39SBram Moolenaar call writefile([s], 'Xtestout') 962cde0ff39SBram Moolenaar qall 963cde0ff39SBram Moolenaar [CODE] 964cde0ff39SBram Moolenaar if RunVim([], after, '-l') 965cde0ff39SBram Moolenaar call assert_equal(['lisp=1, showmatch=1'], readfile('Xtestout')) 966cde0ff39SBram Moolenaar call delete('Xtestout') 967cde0ff39SBram Moolenaar endif 968cde0ff39SBram Moolenaarendfunc 969cde0ff39SBram Moolenaar 970cde0ff39SBram Moolenaar" Test for specifying a non-existing vimrc file using "-u" 971cde0ff39SBram Moolenaarfunc Test_missing_vimrc() 972494e9069SBram Moolenaar CheckRunVimInTerminal 973cde0ff39SBram Moolenaar let after =<< trim [CODE] 974cde0ff39SBram Moolenaar call assert_match('^E282:', v:errmsg) 975cde0ff39SBram Moolenaar call writefile(v:errors, 'Xtestout') 976cde0ff39SBram Moolenaar [CODE] 977cde0ff39SBram Moolenaar call writefile(after, 'Xafter') 978cde0ff39SBram Moolenaar 979cde0ff39SBram Moolenaar let cmd = GetVimCommandCleanTerm() . ' -u Xvimrc_missing -S Xafter' 980cde0ff39SBram Moolenaar let buf = term_start(cmd, {'term_rows' : 10}) 981cde0ff39SBram Moolenaar call WaitForAssert({-> assert_equal("running", term_getstatus(buf))}) 9826a2c5a7dSBram Moolenaar call TermWait(buf) 983cde0ff39SBram Moolenaar call term_sendkeys(buf, "\n:") 9846a2c5a7dSBram Moolenaar call TermWait(buf) 985cde0ff39SBram Moolenaar call WaitForAssert({-> assert_match(':', term_getline(buf, 10))}) 986cde0ff39SBram Moolenaar call StopVimInTerminal(buf) 987cde0ff39SBram Moolenaar call assert_equal([], readfile('Xtestout')) 988cde0ff39SBram Moolenaar call delete('Xafter') 989cde0ff39SBram Moolenaar call delete('Xtestout') 990cde0ff39SBram Moolenaarendfunc 991cde0ff39SBram Moolenaar 992cde0ff39SBram Moolenaar" Test for using the $VIMINIT environment variable 993cde0ff39SBram Moolenaarfunc Test_VIMINIT() 994cde0ff39SBram Moolenaar let after =<< trim [CODE] 995cde0ff39SBram Moolenaar call assert_equal(1, exists('viminit_found')) 996cde0ff39SBram Moolenaar call assert_equal('yes', viminit_found) 997cde0ff39SBram Moolenaar call writefile(v:errors, 'Xtestout') 998cde0ff39SBram Moolenaar qall 999cde0ff39SBram Moolenaar [CODE] 1000cde0ff39SBram Moolenaar call writefile(after, 'Xafter') 1001cde0ff39SBram Moolenaar let cmd = GetVimProg() . ' --not-a-term -S Xafter --cmd "set enc=utf8"' 1002cde0ff39SBram Moolenaar call setenv('VIMINIT', 'let viminit_found="yes"') 1003cde0ff39SBram Moolenaar exe "silent !" . cmd 1004cde0ff39SBram Moolenaar call assert_equal([], readfile('Xtestout')) 1005cde0ff39SBram Moolenaar call delete('Xtestout') 1006cde0ff39SBram Moolenaar call delete('Xafter') 1007cde0ff39SBram Moolenaarendfunc 1008cde0ff39SBram Moolenaar 1009cde0ff39SBram Moolenaar" Test for using the $EXINIT environment variable 1010cde0ff39SBram Moolenaarfunc Test_EXINIT() 1011cde0ff39SBram Moolenaar let after =<< trim [CODE] 1012cde0ff39SBram Moolenaar call assert_equal(1, exists('exinit_found')) 1013cde0ff39SBram Moolenaar call assert_equal('yes', exinit_found) 1014cde0ff39SBram Moolenaar call writefile(v:errors, 'Xtestout') 1015cde0ff39SBram Moolenaar qall 1016cde0ff39SBram Moolenaar [CODE] 1017cde0ff39SBram Moolenaar call writefile(after, 'Xafter') 1018cde0ff39SBram Moolenaar let cmd = GetVimProg() . ' --not-a-term -S Xafter --cmd "set enc=utf8"' 1019cde0ff39SBram Moolenaar call setenv('EXINIT', 'let exinit_found="yes"') 1020cde0ff39SBram Moolenaar exe "silent !" . cmd 1021cde0ff39SBram Moolenaar call assert_equal([], readfile('Xtestout')) 1022cde0ff39SBram Moolenaar call delete('Xtestout') 1023cde0ff39SBram Moolenaar call delete('Xafter') 1024cde0ff39SBram Moolenaarendfunc 1025cde0ff39SBram Moolenaar 1026cde0ff39SBram Moolenaar" Test for using the 'exrc' option 1027cde0ff39SBram Moolenaarfunc Test_exrc() 1028cde0ff39SBram Moolenaar let after =<< trim [CODE] 1029cde0ff39SBram Moolenaar call assert_equal(1, &exrc) 1030cde0ff39SBram Moolenaar call assert_equal(1, &secure) 1031cde0ff39SBram Moolenaar call assert_equal(37, exrc_found) 1032cde0ff39SBram Moolenaar call writefile(v:errors, 'Xtestout') 1033cde0ff39SBram Moolenaar qall 1034cde0ff39SBram Moolenaar [CODE] 1035cde0ff39SBram Moolenaar call mkdir('Xdir') 1036cde0ff39SBram Moolenaar call writefile(['let exrc_found=37'], 'Xdir/.exrc') 1037cde0ff39SBram Moolenaar call writefile(after, 'Xdir/Xafter') 1038cde0ff39SBram Moolenaar let cmd = GetVimProg() . ' --not-a-term -S Xafter --cmd "cd Xdir" --cmd "set enc=utf8 exrc secure"' 1039cde0ff39SBram Moolenaar exe "silent !" . cmd 1040cde0ff39SBram Moolenaar call assert_equal([], readfile('Xdir/Xtestout')) 1041cde0ff39SBram Moolenaar call delete('Xdir', 'rf') 1042cde0ff39SBram Moolenaarendfunc 1043cde0ff39SBram Moolenaar 1044cde0ff39SBram Moolenaar" Test for starting Vim with a non-terminal as input/output 1045cde0ff39SBram Moolenaarfunc Test_io_not_a_terminal() 1046cde0ff39SBram Moolenaar " Can't catch the output of gvim. 1047cde0ff39SBram Moolenaar CheckNotGui 1048cde0ff39SBram Moolenaar CheckUnix 1049cde0ff39SBram Moolenaar CheckEnglish 1050cde0ff39SBram Moolenaar let l = systemlist(GetVimProg() .. ' --ttyfail') 1051cde0ff39SBram Moolenaar call assert_equal(['Vim: Warning: Output is not to a terminal', 1052cde0ff39SBram Moolenaar \ 'Vim: Warning: Input is not from a terminal'], l) 1053cde0ff39SBram Moolenaarendfunc 1054cde0ff39SBram Moolenaar 10557007e31bSBram Moolenaar" Test for --not-a-term avoiding escape codes. 10567007e31bSBram Moolenaarfunc Test_not_a_term() 10577007e31bSBram Moolenaar CheckUnix 10587007e31bSBram Moolenaar CheckNotGui 10597007e31bSBram Moolenaar 10607007e31bSBram Moolenaar if &shellredir =~ '%s' 10617007e31bSBram Moolenaar let redir = printf(&shellredir, 'Xvimout') 10627007e31bSBram Moolenaar else 10637007e31bSBram Moolenaar let redir = &shellredir .. ' Xvimout' 10647007e31bSBram Moolenaar endif 10657007e31bSBram Moolenaar 10667007e31bSBram Moolenaar " Without --not-a-term there are a few escape sequences. 10677007e31bSBram Moolenaar " This will take 2 seconds because of the missing --not-a-term 10687007e31bSBram Moolenaar let cmd = GetVimProg() .. ' --cmd quit ' .. redir 10697007e31bSBram Moolenaar exe "silent !" . cmd 10707007e31bSBram Moolenaar call assert_match("\<Esc>", readfile('Xvimout')->join()) 10717007e31bSBram Moolenaar call delete('Xvimout') 10727007e31bSBram Moolenaar 10737007e31bSBram Moolenaar " With --not-a-term there are no escape sequences. 10747007e31bSBram Moolenaar let cmd = GetVimProg() .. ' --not-a-term --cmd quit ' .. redir 10757007e31bSBram Moolenaar exe "silent !" . cmd 10767007e31bSBram Moolenaar call assert_notmatch("\<Esc>", readfile('Xvimout')->join()) 10777007e31bSBram Moolenaar call delete('Xvimout') 10787007e31bSBram Moolenaarendfunc 10797007e31bSBram Moolenaar 10807007e31bSBram Moolenaar 1081cde0ff39SBram Moolenaar" Test for the "-w scriptout" argument 1082cde0ff39SBram Moolenaarfunc Test_w_arg() 1083cde0ff39SBram Moolenaar " Can't catch the output of gvim. 1084cde0ff39SBram Moolenaar CheckNotGui 10850a1a6a1aSBram Moolenaar 1086cde0ff39SBram Moolenaar call writefile(["iVim Editor\<Esc>:q!\<CR>"], 'Xscriptin', 'b') 1087cde0ff39SBram Moolenaar if RunVim([], [], '-s Xscriptin -w Xscriptout') 1088cde0ff39SBram Moolenaar call assert_equal(["iVim Editor\e:q!\r"], readfile('Xscriptout')) 1089cde0ff39SBram Moolenaar call delete('Xscriptout') 1090cde0ff39SBram Moolenaar endif 1091cde0ff39SBram Moolenaar call delete('Xscriptin') 1092cde0ff39SBram Moolenaar 1093cde0ff39SBram Moolenaar " Test for failing to open the script output file. This test works only when 1094cde0ff39SBram Moolenaar " the language is English. 1095cde0ff39SBram Moolenaar if v:lang == "C" || v:lang =~ '^[Ee]n' 1096cde0ff39SBram Moolenaar call mkdir("Xdir") 1097cde0ff39SBram Moolenaar let m = system(GetVimCommand() .. " -w Xdir") 1098cde0ff39SBram Moolenaar call assert_equal("Cannot open for script output: \"Xdir\"\n", m) 1099cde0ff39SBram Moolenaar call delete("Xdir", 'rf') 1100cde0ff39SBram Moolenaar endif 11010a1a6a1aSBram Moolenaar 11020a1a6a1aSBram Moolenaar " A number argument sets the 'window' option 11030a1a6a1aSBram Moolenaar call writefile(["iwindow \<C-R>=&window\<CR>\<Esc>:wq! Xresult\<CR>"], 'Xscriptin', 'b') 1104a2b3e7dcSBram Moolenaar for w_arg in ['-w 17', '-w17'] 1105a2b3e7dcSBram Moolenaar if RunVim([], [], '-s Xscriptin ' .. w_arg) 1106a2b3e7dcSBram Moolenaar call assert_equal(["window 17"], readfile('Xresult'), w_arg) 11070a1a6a1aSBram Moolenaar call delete('Xresult') 11080a1a6a1aSBram Moolenaar endif 1109a2b3e7dcSBram Moolenaar endfor 11100a1a6a1aSBram Moolenaar call delete('Xscriptin') 1111cde0ff39SBram Moolenaarendfunc 1112cde0ff39SBram Moolenaar 1113cde0ff39SBram Moolenaar" Test for the "-s scriptin" argument 1114cde0ff39SBram Moolenaarfunc Test_s_arg() 1115cde0ff39SBram Moolenaar " Can't catch the output of gvim. 1116cde0ff39SBram Moolenaar CheckNotGui 1117cde0ff39SBram Moolenaar CheckEnglish 1118cde0ff39SBram Moolenaar " Test for failing to open the script input file. 1119cde0ff39SBram Moolenaar let m = system(GetVimCommand() .. " -s abcxyz") 1120cde0ff39SBram Moolenaar call assert_equal("Cannot open for reading: \"abcxyz\"\n", m) 1121cde0ff39SBram Moolenaar 1122cde0ff39SBram Moolenaar call writefile([], 'Xinput') 1123cde0ff39SBram Moolenaar let m = system(GetVimCommand() .. " -s Xinput -s Xinput") 1124cde0ff39SBram Moolenaar call assert_equal("Attempt to open script file again: \"-s Xinput\"\n", m) 1125cde0ff39SBram Moolenaar call delete('Xinput') 1126cde0ff39SBram Moolenaarendfunc 1127cde0ff39SBram Moolenaar 1128cde0ff39SBram Moolenaar" Test for the "-n" (no swap file) argument 1129cde0ff39SBram Moolenaarfunc Test_n_arg() 1130cde0ff39SBram Moolenaar let after =<< trim [CODE] 1131cde0ff39SBram Moolenaar call assert_equal(0, &updatecount) 1132cde0ff39SBram Moolenaar call writefile(v:errors, 'Xtestout') 1133cde0ff39SBram Moolenaar qall 1134cde0ff39SBram Moolenaar [CODE] 1135cde0ff39SBram Moolenaar if RunVim([], after, '-n') 1136cde0ff39SBram Moolenaar call assert_equal([], readfile('Xtestout')) 1137cde0ff39SBram Moolenaar call delete('Xtestout') 1138cde0ff39SBram Moolenaar endif 1139cde0ff39SBram Moolenaarendfunc 1140cde0ff39SBram Moolenaar 1141cde0ff39SBram Moolenaar" Test for the "-h" (help) argument 1142cde0ff39SBram Moolenaarfunc Test_h_arg() 1143cde0ff39SBram Moolenaar " Can't catch the output of gvim. 1144cde0ff39SBram Moolenaar CheckNotGui 1145cde0ff39SBram Moolenaar let l = systemlist(GetVimProg() .. ' -h') 1146cde0ff39SBram Moolenaar call assert_match('^VIM - Vi IMproved', l[0]) 1147cde0ff39SBram Moolenaar let l = systemlist(GetVimProg() .. ' -?') 1148cde0ff39SBram Moolenaar call assert_match('^VIM - Vi IMproved', l[0]) 1149cde0ff39SBram Moolenaarendfunc 1150cde0ff39SBram Moolenaar 1151cde0ff39SBram Moolenaar" Test for the "-F" (farsi) argument 1152cde0ff39SBram Moolenaarfunc Test_F_arg() 1153cde0ff39SBram Moolenaar " Can't catch the output of gvim. 1154cde0ff39SBram Moolenaar CheckNotGui 1155cde0ff39SBram Moolenaar let l = systemlist(GetVimProg() .. ' -F') 1156cde0ff39SBram Moolenaar call assert_match('^E27:', l[0]) 1157cde0ff39SBram Moolenaarendfunc 1158cde0ff39SBram Moolenaar 1159cde0ff39SBram Moolenaar" Test for the "-E" (improved Ex mode) argument 1160cde0ff39SBram Moolenaarfunc Test_E_arg() 1161cde0ff39SBram Moolenaar let after =<< trim [CODE] 1162cde0ff39SBram Moolenaar call assert_equal('cv', mode(1)) 1163cde0ff39SBram Moolenaar call writefile(v:errors, 'Xtestout') 1164cde0ff39SBram Moolenaar qall 1165cde0ff39SBram Moolenaar [CODE] 1166cde0ff39SBram Moolenaar if RunVim([], after, '-E') 1167cde0ff39SBram Moolenaar call assert_equal([], readfile('Xtestout')) 1168cde0ff39SBram Moolenaar call delete('Xtestout') 1169cde0ff39SBram Moolenaar endif 1170cde0ff39SBram Moolenaarendfunc 1171cde0ff39SBram Moolenaar 1172c5cf369eSBram Moolenaar" Test for the "-D" (debugger) argument 1173c5cf369eSBram Moolenaarfunc Test_D_arg() 1174c5cf369eSBram Moolenaar CheckRunVimInTerminal 1175c5cf369eSBram Moolenaar 1176c5cf369eSBram Moolenaar let cmd = GetVimCommandCleanTerm() .. ' -D' 1177c5cf369eSBram Moolenaar let buf = term_start(cmd, {'term_rows' : 10}) 1178c5cf369eSBram Moolenaar call WaitForAssert({-> assert_equal("running", term_getstatus(buf))}) 1179c5cf369eSBram Moolenaar 1180c5cf369eSBram Moolenaar call WaitForAssert({-> assert_equal('Entering Debug mode. Type "cont" to continue.', 1181c5cf369eSBram Moolenaar \ term_getline(buf, 7))}) 1182c5cf369eSBram Moolenaar call WaitForAssert({-> assert_equal('>', term_getline(buf, 10))}) 1183c5cf369eSBram Moolenaar 1184c5cf369eSBram Moolenaar call StopVimInTerminal(buf) 1185c5cf369eSBram Moolenaarendfunc 1186c5cf369eSBram Moolenaar 1187cde0ff39SBram Moolenaar" Test for too many edit argument errors 1188cde0ff39SBram Moolenaarfunc Test_too_many_edit_args() 1189cde0ff39SBram Moolenaar " Can't catch the output of gvim. 1190cde0ff39SBram Moolenaar CheckNotGui 1191cde0ff39SBram Moolenaar CheckEnglish 1192cde0ff39SBram Moolenaar let l = systemlist(GetVimProg() .. ' - -') 1193cde0ff39SBram Moolenaar call assert_match('^Too many edit arguments: "-"', l[1]) 1194cde0ff39SBram Moolenaarendfunc 1195cde0ff39SBram Moolenaar 1196df4c9af7SBram Moolenaar" Test starting vim with various names: vim, ex, view, evim, etc. 1197df4c9af7SBram Moolenaarfunc Test_progname() 1198df4c9af7SBram Moolenaar CheckUnix 1199df4c9af7SBram Moolenaar 1200df4c9af7SBram Moolenaar call mkdir('Xprogname', 'p') 1201df4c9af7SBram Moolenaar call writefile(['silent !date', 1202df4c9af7SBram Moolenaar \ 'call writefile([mode(1), ' 1203df4c9af7SBram Moolenaar \ .. '&insertmode, &diff, &readonly, &updatecount, ' 1204df4c9af7SBram Moolenaar \ .. 'join(split(execute("message"), "\n")[1:])], "Xprogname_out")', 1205df4c9af7SBram Moolenaar \ 'qall'], 'Xprogname_after') 1206df4c9af7SBram Moolenaar 1207df4c9af7SBram Moolenaar " +---------------------------------------------- progname 1208df4c9af7SBram Moolenaar " | +--------------------------------- mode(1) 1209df4c9af7SBram Moolenaar " | | +--------------------------- &insertmode 1210df4c9af7SBram Moolenaar " | | | +---------------------- &diff 1211df4c9af7SBram Moolenaar " | | | | +----------------- &readonly 1212df4c9af7SBram Moolenaar " | | | | | +-------- &updatecount 1213df4c9af7SBram Moolenaar " | | | | | | +--- :messages 1214df4c9af7SBram Moolenaar " | | | | | | | 1215df4c9af7SBram Moolenaar let expectations = { 1216df4c9af7SBram Moolenaar \ 'vim': ['n', '0', '0', '0', '200', ''], 1217df4c9af7SBram Moolenaar \ 'gvim': ['n', '0', '0', '0', '200', ''], 1218df4c9af7SBram Moolenaar \ 'ex': ['ce', '0', '0', '0', '200', ''], 1219df4c9af7SBram Moolenaar \ 'exim': ['cv', '0', '0', '0', '200', ''], 1220df4c9af7SBram Moolenaar \ 'view': ['n', '0', '0', '1', '10000', ''], 1221df4c9af7SBram Moolenaar \ 'gview': ['n', '0', '0', '1', '10000', ''], 1222df4c9af7SBram Moolenaar \ 'evim': ['n', '1', '0', '0', '200', ''], 1223df4c9af7SBram Moolenaar \ 'eview': ['n', '1', '0', '1', '10000', ''], 1224df4c9af7SBram Moolenaar \ 'rvim': ['n', '0', '0', '0', '200', 'line 1: E145: Shell commands and some functionality not allowed in rvim'], 1225df4c9af7SBram Moolenaar \ 'rgvim': ['n', '0', '0', '0', '200', 'line 1: E145: Shell commands and some functionality not allowed in rvim'], 1226df4c9af7SBram Moolenaar \ 'rview': ['n', '0', '0', '1', '10000', 'line 1: E145: Shell commands and some functionality not allowed in rvim'], 1227df4c9af7SBram Moolenaar \ 'rgview': ['n', '0', '0', '1', '10000', 'line 1: E145: Shell commands and some functionality not allowed in rvim'], 1228df4c9af7SBram Moolenaar \ 'vimdiff': ['n', '0', '1', '0', '200', ''], 1229df4c9af7SBram Moolenaar \ 'gvimdiff': ['n', '0', '1', '0', '200', '']} 1230df4c9af7SBram Moolenaar 1231df4c9af7SBram Moolenaar let prognames = ['vim', 'gvim', 'ex', 'exim', 'view', 'gview', 1232df4c9af7SBram Moolenaar \ 'evim', 'eview', 'rvim', 'rgvim', 'rview', 'rgview', 1233df4c9af7SBram Moolenaar \ 'vimdiff', 'gvimdiff'] 1234df4c9af7SBram Moolenaar 1235df4c9af7SBram Moolenaar for progname in prognames 1236240309c9SBram Moolenaar let run_with_gui = (progname =~# 'g') || (has('gui') && (progname ==# 'evim' || progname ==# 'eview')) 1237240309c9SBram Moolenaar 1238240309c9SBram Moolenaar if empty($DISPLAY) && run_with_gui 1239df4c9af7SBram Moolenaar " Can't run gvim, gview (etc.) if $DISPLAY is not setup. 1240df4c9af7SBram Moolenaar continue 1241df4c9af7SBram Moolenaar endif 1242df4c9af7SBram Moolenaar 1243df4c9af7SBram Moolenaar exe 'silent !ln -s -f ' ..exepath(GetVimProg()) .. ' Xprogname/' .. progname 1244df4c9af7SBram Moolenaar 1245df4c9af7SBram Moolenaar let stdout_stderr = '' 1246df4c9af7SBram Moolenaar if progname =~# 'g' 1247df4c9af7SBram Moolenaar let stdout_stderr = system('Xprogname/'..progname..' -f --clean --not-a-term -S Xprogname_after') 1248df4c9af7SBram Moolenaar else 1249df4c9af7SBram Moolenaar exe 'sil !Xprogname/'..progname..' -f --clean --not-a-term -S Xprogname_after' 1250df4c9af7SBram Moolenaar endif 1251df4c9af7SBram Moolenaar 1252df4c9af7SBram Moolenaar if progname =~# 'g' && !has('gui') 1253df4c9af7SBram Moolenaar call assert_equal("E25: GUI cannot be used: Not enabled at compile time\n", stdout_stderr, progname) 1254df4c9af7SBram Moolenaar else 1255240309c9SBram Moolenaar " GUI motif can output some warnings like this: 1256240309c9SBram Moolenaar " Warning: 1257240309c9SBram Moolenaar " Name: subMenu 1258240309c9SBram Moolenaar " Class: XmCascadeButton 1259240309c9SBram Moolenaar " Illegal mnemonic character; Could not convert X KEYSYM to a keycode 1260240309c9SBram Moolenaar " So don't check that stderr is empty with GUI Motif. 1261240309c9SBram Moolenaar if run_with_gui && !has('gui_motif') 1262df4c9af7SBram Moolenaar call assert_equal('', stdout_stderr, progname) 1263240309c9SBram Moolenaar endif 1264df4c9af7SBram Moolenaar call assert_equal(expectations[progname], readfile('Xprogname_out'), progname) 1265df4c9af7SBram Moolenaar endif 1266df4c9af7SBram Moolenaar 1267df4c9af7SBram Moolenaar call delete('Xprogname/' .. progname) 1268df4c9af7SBram Moolenaar call delete('Xprogname_out') 1269df4c9af7SBram Moolenaar endfor 1270df4c9af7SBram Moolenaar 1271df4c9af7SBram Moolenaar call delete('Xprogname_after') 1272df4c9af7SBram Moolenaar call delete('Xprogname', 'd') 1273df4c9af7SBram Moolenaarendfunc 1274df4c9af7SBram Moolenaar 127536f96a51SYegappan Lakshmanan" Test for doing a write from .vimrc 127636f96a51SYegappan Lakshmananfunc Test_write_in_vimrc() 127736f96a51SYegappan Lakshmanan call writefile(['silent! write'], 'Xvimrc') 127836f96a51SYegappan Lakshmanan let after =<< trim [CODE] 127936f96a51SYegappan Lakshmanan call assert_match('E32: ', v:errmsg) 128036f96a51SYegappan Lakshmanan call writefile(v:errors, 'Xtestout') 128136f96a51SYegappan Lakshmanan qall 128236f96a51SYegappan Lakshmanan [CODE] 128336f96a51SYegappan Lakshmanan if RunVim([], after, '-u Xvimrc') 128436f96a51SYegappan Lakshmanan call assert_equal([], readfile('Xtestout')) 128536f96a51SYegappan Lakshmanan call delete('Xtestout') 128636f96a51SYegappan Lakshmanan endif 128736f96a51SYegappan Lakshmanan call delete('Xvimrc') 128836f96a51SYegappan Lakshmananendfunc 128936f96a51SYegappan Lakshmanan 1290a97c3631SBram Moolenaarfunc Test_echo_true_in_cmd() 1291b90ac5e9SBram Moolenaar CheckNotGui 1292b90ac5e9SBram Moolenaar 1293a97c3631SBram Moolenaar let lines =<< trim END 1294a97c3631SBram Moolenaar echo v:true 1295a97c3631SBram Moolenaar call writefile(['done'], 'Xresult') 129655b6b60bSBram Moolenaar quit 1297a97c3631SBram Moolenaar END 1298a97c3631SBram Moolenaar call writefile(lines, 'Xscript') 129955b6b60bSBram Moolenaar if RunVim([], [], '--cmd "source Xscript"') 1300a97c3631SBram Moolenaar call assert_equal(['done'], readfile('Xresult')) 1301a97c3631SBram Moolenaar endif 1302a97c3631SBram Moolenaar call delete('Xscript') 1303a97c3631SBram Moolenaar call delete('Xresult') 1304a97c3631SBram Moolenaarendfunc 1305a97c3631SBram Moolenaar 1306d3710cf0SBram Moolenaarfunc Test_rename_buffer_on_startup() 13076d197987SBram Moolenaar CheckUnix 13086d197987SBram Moolenaar 1309d3710cf0SBram Moolenaar let lines =<< trim END 1310d3710cf0SBram Moolenaar call writefile(['done'], 'Xresult') 1311d3710cf0SBram Moolenaar qa! 1312d3710cf0SBram Moolenaar END 1313d3710cf0SBram Moolenaar call writefile(lines, 'Xscript') 1314d3710cf0SBram Moolenaar if RunVim([], [], "--clean -e -s --cmd 'file x|new|file x' --cmd 'so Xscript'") 1315d3710cf0SBram Moolenaar call assert_equal(['done'], readfile('Xresult')) 1316d3710cf0SBram Moolenaar endif 1317d3710cf0SBram Moolenaar call delete('Xscript') 1318d3710cf0SBram Moolenaar call delete('Xresult') 1319d3710cf0SBram Moolenaarendfunc 1320d3710cf0SBram Moolenaar 1321d3710cf0SBram Moolenaar 1322cde0ff39SBram Moolenaar" vim: shiftwidth=2 sts=2 expandtab 1323