112a96de4SBram Moolenaar" Tests for exiting Vim. 212a96de4SBram Moolenaar 312a96de4SBram Moolenaarsource shared.vim 412a96de4SBram Moolenaar 512a96de4SBram Moolenaarfunc Test_exiting() 6c79745a8SBram Moolenaar let after =<< trim [CODE] 7c79745a8SBram Moolenaar au QuitPre * call writefile(["QuitPre"], "Xtestout") 8c79745a8SBram Moolenaar au ExitPre * call writefile(["ExitPre"], "Xtestout", "a") 9c79745a8SBram Moolenaar quit 10c79745a8SBram Moolenaar [CODE] 11c79745a8SBram Moolenaar 1212a96de4SBram Moolenaar if RunVim([], after, '') 1312a96de4SBram Moolenaar call assert_equal(['QuitPre', 'ExitPre'], readfile('Xtestout')) 1412a96de4SBram Moolenaar endif 1512a96de4SBram Moolenaar call delete('Xtestout') 1612a96de4SBram Moolenaar 17c79745a8SBram Moolenaar let after =<< trim [CODE] 18c79745a8SBram Moolenaar au QuitPre * call writefile(["QuitPre"], "Xtestout") 19c79745a8SBram Moolenaar au ExitPre * call writefile(["ExitPre"], "Xtestout", "a") 20c79745a8SBram Moolenaar help 21c79745a8SBram Moolenaar wincmd w 22c79745a8SBram Moolenaar quit 23c79745a8SBram Moolenaar [CODE] 24c79745a8SBram Moolenaar 2512a96de4SBram Moolenaar if RunVim([], after, '') 2612a96de4SBram Moolenaar call assert_equal(['QuitPre', 'ExitPre'], readfile('Xtestout')) 2712a96de4SBram Moolenaar endif 2812a96de4SBram Moolenaar call delete('Xtestout') 2912a96de4SBram Moolenaar 30c79745a8SBram Moolenaar let after =<< trim [CODE] 31c79745a8SBram Moolenaar au QuitPre * call writefile(["QuitPre"], "Xtestout") 32c79745a8SBram Moolenaar au ExitPre * call writefile(["ExitPre"], "Xtestout", "a") 33c79745a8SBram Moolenaar split 34c79745a8SBram Moolenaar new 35c79745a8SBram Moolenaar qall 36c79745a8SBram Moolenaar [CODE] 37c79745a8SBram Moolenaar 3812a96de4SBram Moolenaar if RunVim([], after, '') 3912a96de4SBram Moolenaar call assert_equal(['QuitPre', 'ExitPre'], readfile('Xtestout')) 4012a96de4SBram Moolenaar endif 4112a96de4SBram Moolenaar call delete('Xtestout') 4212a96de4SBram Moolenaar 4334ba06b6SBram Moolenaar " ExitPre autocommand splits the window, so that it's no longer the last one. 44c79745a8SBram Moolenaar let after =<< trim [CODE] 45c79745a8SBram Moolenaar au QuitPre * call writefile(["QuitPre"], "Xtestout", "a") 46c79745a8SBram Moolenaar au ExitPre * call writefile(["ExitPre"], "Xtestout", "a") 47c79745a8SBram Moolenaar augroup nasty 48c79745a8SBram Moolenaar au ExitPre * split 49c79745a8SBram Moolenaar augroup END 50c79745a8SBram Moolenaar quit 51c79745a8SBram Moolenaar augroup nasty 52c79745a8SBram Moolenaar au! ExitPre 53c79745a8SBram Moolenaar augroup END 54c79745a8SBram Moolenaar quit 55c79745a8SBram Moolenaar [CODE] 56c79745a8SBram Moolenaar 5712a96de4SBram Moolenaar if RunVim([], after, '') 5812a96de4SBram Moolenaar call assert_equal(['QuitPre', 'ExitPre', 'QuitPre', 'ExitPre'], 5912a96de4SBram Moolenaar \ readfile('Xtestout')) 6012a96de4SBram Moolenaar endif 6112a96de4SBram Moolenaar call delete('Xtestout') 6234ba06b6SBram Moolenaar 6334ba06b6SBram Moolenaar " ExitPre autocommand splits and closes the window, so that there is still 6434ba06b6SBram Moolenaar " one window but it's a different one. 6534ba06b6SBram Moolenaar let after =<< trim [CODE] 6634ba06b6SBram Moolenaar au QuitPre * call writefile(["QuitPre"], "Xtestout", "a") 6734ba06b6SBram Moolenaar au ExitPre * call writefile(["ExitPre"], "Xtestout", "a") 6834ba06b6SBram Moolenaar augroup nasty 6934ba06b6SBram Moolenaar au ExitPre * split | only 7034ba06b6SBram Moolenaar augroup END 7134ba06b6SBram Moolenaar quit 7234ba06b6SBram Moolenaar augroup nasty 7334ba06b6SBram Moolenaar au! ExitPre 7434ba06b6SBram Moolenaar augroup END 7534ba06b6SBram Moolenaar quit 7634ba06b6SBram Moolenaar [CODE] 7734ba06b6SBram Moolenaar 7834ba06b6SBram Moolenaar if RunVim([], after, '') 7934ba06b6SBram Moolenaar call assert_equal(['QuitPre', 'ExitPre', 'QuitPre', 'ExitPre'], 8034ba06b6SBram Moolenaar \ readfile('Xtestout')) 8134ba06b6SBram Moolenaar endif 8234ba06b6SBram Moolenaar call delete('Xtestout') 8312a96de4SBram Moolenaarendfunc 846d91bcb4SBram Moolenaar 85*f0068c51SBram Moolenaar" Test for getting the Vim exit code from v:exiting 86*f0068c51SBram Moolenaarfunc Test_exit_code() 87*f0068c51SBram Moolenaar call assert_equal(v:null, v:exiting) 88*f0068c51SBram Moolenaar 89*f0068c51SBram Moolenaar let before =<< trim [CODE] 90*f0068c51SBram Moolenaar au QuitPre * call writefile(['qp = ' .. v:exiting], 'Xtestout', 'a') 91*f0068c51SBram Moolenaar au ExitPre * call writefile(['ep = ' .. v:exiting], 'Xtestout', 'a') 92*f0068c51SBram Moolenaar au VimLeavePre * call writefile(['lp = ' .. v:exiting], 'Xtestout', 'a') 93*f0068c51SBram Moolenaar au VimLeave * call writefile(['l = ' .. v:exiting], 'Xtestout', 'a') 94*f0068c51SBram Moolenaar [CODE] 95*f0068c51SBram Moolenaar 96*f0068c51SBram Moolenaar if RunVim(before, ['quit'], '') 97*f0068c51SBram Moolenaar call assert_equal(['qp = v:null', 'ep = v:null', 'lp = 0', 'l = 0'], readfile('Xtestout')) 98*f0068c51SBram Moolenaar endif 99*f0068c51SBram Moolenaar call delete('Xtestout') 100*f0068c51SBram Moolenaar 101*f0068c51SBram Moolenaar if RunVim(before, ['cquit'], '') 102*f0068c51SBram Moolenaar call assert_equal(['lp = 1', 'l = 1'], readfile('Xtestout')) 103*f0068c51SBram Moolenaar endif 104*f0068c51SBram Moolenaar call delete('Xtestout') 105*f0068c51SBram Moolenaar 106*f0068c51SBram Moolenaar if RunVim(before, ['cquit 4'], '') 107*f0068c51SBram Moolenaar call assert_equal(['lp = 4', 'l = 4'], readfile('Xtestout')) 108*f0068c51SBram Moolenaar endif 109*f0068c51SBram Moolenaar call delete('Xtestout') 110*f0068c51SBram Moolenaarendfunc 111*f0068c51SBram Moolenaar 1126d91bcb4SBram Moolenaar" vim: shiftwidth=2 sts=2 expandtab 113