1" Tests for exiting Vim. 2 3source shared.vim 4 5func Test_exiting() 6 let after =<< trim [CODE] 7 au QuitPre * call writefile(["QuitPre"], "Xtestout") 8 au ExitPre * call writefile(["ExitPre"], "Xtestout", "a") 9 quit 10 [CODE] 11 12 if RunVim([], after, '') 13 call assert_equal(['QuitPre', 'ExitPre'], readfile('Xtestout')) 14 endif 15 call delete('Xtestout') 16 17 let after =<< trim [CODE] 18 au QuitPre * call writefile(["QuitPre"], "Xtestout") 19 au ExitPre * call writefile(["ExitPre"], "Xtestout", "a") 20 help 21 wincmd w 22 quit 23 [CODE] 24 25 if RunVim([], after, '') 26 call assert_equal(['QuitPre', 'ExitPre'], readfile('Xtestout')) 27 endif 28 call delete('Xtestout') 29 30 let after =<< trim [CODE] 31 au QuitPre * call writefile(["QuitPre"], "Xtestout") 32 au ExitPre * call writefile(["ExitPre"], "Xtestout", "a") 33 split 34 new 35 qall 36 [CODE] 37 38 if RunVim([], after, '') 39 call assert_equal(['QuitPre', 'ExitPre'], readfile('Xtestout')) 40 endif 41 call delete('Xtestout') 42 43 " ExitPre autocommand splits the window, so that it's no longer the last one. 44 let after =<< trim [CODE] 45 au QuitPre * call writefile(["QuitPre"], "Xtestout", "a") 46 au ExitPre * call writefile(["ExitPre"], "Xtestout", "a") 47 augroup nasty 48 au ExitPre * split 49 augroup END 50 quit 51 augroup nasty 52 au! ExitPre 53 augroup END 54 quit 55 [CODE] 56 57 if RunVim([], after, '') 58 call assert_equal(['QuitPre', 'ExitPre', 'QuitPre', 'ExitPre'], 59 \ readfile('Xtestout')) 60 endif 61 call delete('Xtestout') 62 63 " ExitPre autocommand splits and closes the window, so that there is still 64 " one window but it's a different one. 65 let after =<< trim [CODE] 66 au QuitPre * call writefile(["QuitPre"], "Xtestout", "a") 67 au ExitPre * call writefile(["ExitPre"], "Xtestout", "a") 68 augroup nasty 69 au ExitPre * split | only 70 augroup END 71 quit 72 augroup nasty 73 au! ExitPre 74 augroup END 75 quit 76 [CODE] 77 78 if RunVim([], after, '') 79 call assert_equal(['QuitPre', 'ExitPre', 'QuitPre', 'ExitPre'], 80 \ readfile('Xtestout')) 81 endif 82 call delete('Xtestout') 83endfunc 84 85" Test for getting the Vim exit code from v:exiting 86func Test_exit_code() 87 call assert_equal(v:null, v:exiting) 88 89 let before =<< trim [CODE] 90 au QuitPre * call writefile(['qp = ' .. v:exiting], 'Xtestout', 'a') 91 au ExitPre * call writefile(['ep = ' .. v:exiting], 'Xtestout', 'a') 92 au VimLeavePre * call writefile(['lp = ' .. v:exiting], 'Xtestout', 'a') 93 au VimLeave * call writefile(['l = ' .. v:exiting], 'Xtestout', 'a') 94 [CODE] 95 96 if RunVim(before, ['quit'], '') 97 call assert_equal(['qp = v:null', 'ep = v:null', 'lp = 0', 'l = 0'], readfile('Xtestout')) 98 endif 99 call delete('Xtestout') 100 101 if RunVim(before, ['cquit'], '') 102 call assert_equal(['lp = 1', 'l = 1'], readfile('Xtestout')) 103 endif 104 call delete('Xtestout') 105 106 if RunVim(before, ['cquit 4'], '') 107 call assert_equal(['lp = 4', 'l = 4'], readfile('Xtestout')) 108 endif 109 call delete('Xtestout') 110endfunc 111 112" vim: shiftwidth=2 sts=2 expandtab 113