@@ -345,3 +345,66 @@ func Test_BufEnter()
345345 call delete (' Xdir' , ' d' )
346346 au ! BufEnter
347347endfunc
348+
349+ " Closing a window might cause an endless loop
350+ " E814 for older Vims
351+ function Test_autocmd_bufwipe_in_SessLoadPost ()
352+ tabnew
353+ set noswapfile
354+ let g: bufnr= bufnr (' %' )
355+ mksession !
356+
357+ let content= [' set nocp noswapfile' ,
358+ \ ' let v:swapchoice="e"' ,
359+ \ ' augroup test_autocmd_sessionload' ,
360+ \ ' autocmd!' ,
361+ \ ' autocmd SessionLoadPost * 4bw!' ,
362+ \ ' augroup END'
363+ \ ]
364+ call writefile (content, ' Xvimrc' )
365+ let a = system (v: progpath . ' -u Xvimrc --noplugins -S Session.vim' )
366+ call assert_match (' E814' , a )
367+
368+ unlet ! g: bufnr
369+ set swapfile
370+ for file in [' Session.vim' , ' Xvimrc' ]
371+ call delete (file )
372+ endfor
373+ endfunc
374+
375+ " SEGV occurs in older versions.
376+ function Test_autocmd_bufwipe_in_SessLoadPost2 ()
377+ tabnew
378+ set noswapfile
379+ let g: bufnr= bufnr (' %' )
380+ mksession !
381+
382+ let content = [' set nocp noswapfile' ,
383+ \ ' function! DeleteInactiveBufs()' ,
384+ \ ' tabfirst' ,
385+ \ ' let tabblist = []' ,
386+ \ ' for i in range(1, tabpagenr('' $'' ))' ,
387+ \ ' call extend(tabblist, tabpagebuflist(i))' ,
388+ \ ' endfor' ,
389+ \ ' for b in range(1, bufnr('' $'' ))' ,
390+ \ ' if bufexists(b) && buflisted(b) && (index(tabblist, b) == -1 || bufname(b) =~# '' ^$'' )' ,
391+ \ ' exec '' bwipeout '' . b' ,
392+ \ ' endif' ,
393+ \ ' endfor' ,
394+ \ ' call append("1", "SessionLoadPost DONE")' ,
395+ \ ' endfunction' ,
396+ \ ' au SessionLoadPost * call DeleteInactiveBufs()' ]
397+ call writefile (content, ' Xvimrc' )
398+ let a = system (v: progpath . ' -u Xvimrc --noplugins -S Session.vim' )
399+ " this probably only matches on unix
400+ if has (" unix" )
401+ call assert_notmatch (' Caught deadly signal SEGV' , a )
402+ endif
403+ call assert_match (' SessionLoadPost DONE' , a )
404+
405+ unlet ! g: bufnr
406+ set swapfile
407+ for file in [' Session.vim' , ' Xvimrc' ]
408+ call delete (file )
409+ endfor
410+ endfunc
0 commit comments