robin/laufey
git clone https://git.robinwobin.dev/robin/laufey
b4e602dde5
master
1" Tests for exiting Vim. 2 3source shared.vim 4source check.vim 5 6func Test_exiting () 7let after =<< trim [CODE] 8au QuitPre * call writefile(["QuitPre"], "Xtestout") 9au ExitPre * call writefile(["ExitPre"], "Xtestout", "a") 10quit 11[CODE] 12 13if RunVim ([], after , '' ) 14call assert_equal ([ 'QuitPre' , 'ExitPre' ], readfile ( 'Xtestout' )) 15endif 16call delete ( 'Xtestout' ) 17 18let after =<< trim [CODE] 19au QuitPre * call writefile(["QuitPre"], "Xtestout") 20au ExitPre * call writefile(["ExitPre"], "Xtestout", "a") 21help 22wincmd w 23quit 24[CODE] 25 26if RunVim ([], after , '' ) 27call assert_equal ([ 'QuitPre' , 'ExitPre' ], readfile ( 'Xtestout' )) 28endif 29call delete ( 'Xtestout' ) 30 31let after =<< trim [CODE] 32au QuitPre * call writefile(["QuitPre"], "Xtestout") 33au ExitPre * call writefile(["ExitPre"], "Xtestout", "a") 34split 35new 36qall 37[CODE] 38 39if RunVim ([], after , '' ) 40call assert_equal ([ 'QuitPre' , 'ExitPre' ], readfile ( 'Xtestout' )) 41endif 42call delete ( 'Xtestout' ) 43 44" ExitPre autocommand splits the window, so that it's no longer the last one. 45let after =<< trim [CODE] 46au QuitPre * call writefile(["QuitPre"], "Xtestout", "a") 47au ExitPre * call writefile(["ExitPre"], "Xtestout", "a") 48augroup nasty 49au ExitPre * split 50augroup END 51quit 52augroup nasty 53au! ExitPre 54augroup END 55quit 56[CODE] 57 58if RunVim ([], after , '' ) 59call assert_equal ([ 'QuitPre' , 'ExitPre' , 'QuitPre' , 'ExitPre' ], 60 \readfile ( 'Xtestout' )) 61endif 62call delete ( 'Xtestout' ) 63 64" ExitPre autocommand splits and closes the window, so that there is still 65" one window but it's a different one. 66let after =<< trim [CODE] 67au QuitPre * call writefile(["QuitPre"], "Xtestout", "a") 68au ExitPre * call writefile(["ExitPre"], "Xtestout", "a") 69augroup nasty 70au ExitPre * split | only 71augroup END 72quit 73augroup nasty 74au! ExitPre 75augroup END 76quit 77[CODE] 78 79if RunVim ([], after , '' ) 80call assert_equal ([ 'QuitPre' , 'ExitPre' , 'QuitPre' , 'ExitPre' ], 81 \readfile ( 'Xtestout' )) 82endif 83call delete ( 'Xtestout' ) 84 85" ExitPre autocommand also executed on :wqall 86let after =<< trim [CODE] 87au QuitPre * call writefile(["QuitPre"], "Xtestout", "a") 88au ExitPre * call writefile(["ExitPre"], "Xtestout", "a") 89wqall 90[CODE] 91 92if RunVim ([], after , '' ) 93call assert_equal ([ 'QuitPre' , 'ExitPre' ], readfile ( 'Xtestout' )) 94endif 95call delete ( 'Xtestout' ) 96 97" Test using :quit in BufWritePost during :wqall 98let after =<< trim [CODE] 99botright new Xwritebuf 100call setline(1, 'SHOULD BE WRITTEN') 101autocmd BufWritePost Xwritebuf 1quit 102wqall 103call setline(1, 'NOT REACHED') | write | qall 104[CODE] 105 106if RunVim ([], after , '' ) 107call assert_equal ([ 'SHOULD BE WRITTEN' ], readfile ( 'Xwritebuf' )) 108endif 109call delete ( 'Xwritebuf' ) 110endfunc 111 112" Test for getting the Vim exit code from v:exiting 113func Test_exit_code () 114call assert_equal ( v: null , v: exiting ) 115 116let before =<< trim [CODE] 117au QuitPre * call writefile(['qp = ' .. v:exiting], 'Xtestout', 'a') 118au ExitPre * call writefile(['ep = ' .. v:exiting], 'Xtestout', 'a') 119au VimLeavePre * call writefile(['lp = ' .. v:exiting], 'Xtestout', 'a') 120au VimLeave * call writefile(['l = ' .. v:exiting], 'Xtestout', 'a') 121[CODE] 122 123if RunVim ( before , [ 'quit' ], '' ) 124call assert_equal ([ 'qp = v:null' , 'ep = v:null' , 'lp = 0' , 'l = 0' ], readfile ( 'Xtestout' )) 125endif 126call delete ( 'Xtestout' ) 127 128if RunVim ( before , [ 'cquit' ], '' ) 129call assert_equal ([ 'lp = 1' , 'l = 1' ], readfile ( 'Xtestout' )) 130endif 131call delete ( 'Xtestout' ) 132 133if RunVim ( before , [ 'cquit 4' ], '' ) 134call assert_equal ([ 'lp = 4' , 'l = 4' ], readfile ( 'Xtestout' )) 135endif 136call delete ( 'Xtestout' ) 137endfunc 138 139func Test_exit_error_reading_input () 140throw 'Skipped: Nvim does not exit after stdin is read' 141 142CheckNotGui 143CheckNotMSWindows 144" The early exit causes memory not to be freed somehow 145CheckNotAsan 146CheckNotValgrind 147 148call writefile ([ ":au VimLeave * call writefile(['l = ' .. v:exiting], 'Xtestout')" , ":tabnew" , "q:" ], 'Xscript' , 'b' ) 149 150" Nvim requires "-s -" to read stdin as Normal mode input 151" if RunVim([], [], '<Xscript') 152if RunVim ([], [], '-s - <Xscript' ) 153call assert_equal ( 1 , v: shell_error ) 154call assert_equal ([ 'l = 1' ], readfile ( 'Xtestout' )) 155endif 156call delete ( 'Xscript' ) 157call delete ( 'Xtestout' ) 158endfun 159 160 161" vim: shiftwidth=2 sts=2 expandtab