11" Tests for autocommands
22
3+ set belloff = all
4+
35function ! s: cleanup_buffers () abort
46 for bnr in range (1 , bufnr (' $' ))
57 if bufloaded (bnr) && bufnr (' %' ) != bnr
@@ -318,6 +320,8 @@ func Test_three_windows()
318320 call assert_equal (' Xanother' , expand (' %' ))
319321
320322 au !
323+ enew
324+ bwipe! Xtestje1
321325 call delete (' Xtestje1' )
322326 call delete (' Xtestje2' )
323327 call delete (' Xtestje3' )
@@ -341,3 +345,72 @@ func Test_BufEnter()
341345 call delete (' Xdir' , ' d' )
342346 au ! BufEnter
343347endfunc
348+
349+ " Closing a window might cause an endless loop
350+ " E814 for older Vims
351+ function Test_autocmd_bufwipe_in_SessLoadPost ()
352+ if has (' win32' )
353+ throw ' Skipped: test hangs on MS-Windows'
354+ endif
355+ tabnew
356+ set noswapfile
357+ let g: bufnr= bufnr (' %' )
358+ mksession !
359+
360+ let content= [' set nocp noswapfile' ,
361+ \ ' let v:swapchoice="e"' ,
362+ \ ' augroup test_autocmd_sessionload' ,
363+ \ ' autocmd!' ,
364+ \ ' autocmd SessionLoadPost * 4bw!' ,
365+ \ ' augroup END'
366+ \ ]
367+ call writefile (content, ' Xvimrc' )
368+ let a = system (v: progpath . ' -u Xvimrc --noplugins -S Session.vim' )
369+ call assert_match (' E814' , a )
370+
371+ unlet ! g: bufnr
372+ set swapfile
373+ for file in [' Session.vim' , ' Xvimrc' ]
374+ call delete (file )
375+ endfor
376+ endfunc
377+
378+ " SEGV occurs in older versions.
379+ function Test_autocmd_bufwipe_in_SessLoadPost2 ()
380+ if has (' win32' )
381+ throw ' Skipped: test hangs on MS-Windows'
382+ endif
383+ tabnew
384+ set noswapfile
385+ let g: bufnr= bufnr (' %' )
386+ mksession !
387+
388+ let content = [' set nocp noswapfile' ,
389+ \ ' function! DeleteInactiveBufs()' ,
390+ \ ' tabfirst' ,
391+ \ ' let tabblist = []' ,
392+ \ ' for i in range(1, tabpagenr('' $'' ))' ,
393+ \ ' call extend(tabblist, tabpagebuflist(i))' ,
394+ \ ' endfor' ,
395+ \ ' for b in range(1, bufnr('' $'' ))' ,
396+ \ ' if bufexists(b) && buflisted(b) && (index(tabblist, b) == -1 || bufname(b) =~# '' ^$'' )' ,
397+ \ ' exec '' bwipeout '' . b' ,
398+ \ ' endif' ,
399+ \ ' endfor' ,
400+ \ ' call append("1", "SessionLoadPost DONE")' ,
401+ \ ' endfunction' ,
402+ \ ' au SessionLoadPost * call DeleteInactiveBufs()' ]
403+ call writefile (content, ' Xvimrc' )
404+ let a = system (v: progpath . ' -u Xvimrc --noplugins -S Session.vim' )
405+ " this probably only matches on unix
406+ if has (" unix" )
407+ call assert_notmatch (' Caught deadly signal SEGV' , a )
408+ endif
409+ call assert_match (' SessionLoadPost DONE' , a )
410+
411+ unlet ! g: bufnr
412+ set swapfile
413+ for file in [' Session.vim' , ' Xvimrc' ]
414+ call delete (file )
415+ endfor
416+ endfunc
0 commit comments