2018-09-04 18:57:45 -07:00
|
|
|
" Tests for exiting Vim.
|
|
|
|
|
|
|
|
source shared.vim
|
2022-02-24 17:13:25 -07:00
|
|
|
source check.vim
|
2018-09-04 18:57:45 -07:00
|
|
|
|
|
|
|
func Test_exiting()
|
2019-09-23 13:12:02 -07:00
|
|
|
let after =<< trim [CODE]
|
|
|
|
au QuitPre * call writefile(["QuitPre"], "Xtestout")
|
|
|
|
au ExitPre * call writefile(["ExitPre"], "Xtestout", "a")
|
|
|
|
quit
|
|
|
|
[CODE]
|
|
|
|
|
2018-09-04 18:57:45 -07:00
|
|
|
if RunVim([], after, '')
|
|
|
|
call assert_equal(['QuitPre', 'ExitPre'], readfile('Xtestout'))
|
|
|
|
endif
|
|
|
|
call delete('Xtestout')
|
|
|
|
|
2019-09-23 13:12:02 -07:00
|
|
|
let after =<< trim [CODE]
|
|
|
|
au QuitPre * call writefile(["QuitPre"], "Xtestout")
|
|
|
|
au ExitPre * call writefile(["ExitPre"], "Xtestout", "a")
|
|
|
|
help
|
|
|
|
wincmd w
|
|
|
|
quit
|
|
|
|
[CODE]
|
|
|
|
|
2018-09-04 18:57:45 -07:00
|
|
|
if RunVim([], after, '')
|
|
|
|
call assert_equal(['QuitPre', 'ExitPre'], readfile('Xtestout'))
|
|
|
|
endif
|
|
|
|
call delete('Xtestout')
|
|
|
|
|
2019-09-23 13:12:02 -07:00
|
|
|
let after =<< trim [CODE]
|
|
|
|
au QuitPre * call writefile(["QuitPre"], "Xtestout")
|
|
|
|
au ExitPre * call writefile(["ExitPre"], "Xtestout", "a")
|
|
|
|
split
|
|
|
|
new
|
|
|
|
qall
|
|
|
|
[CODE]
|
|
|
|
|
2018-09-04 18:57:45 -07:00
|
|
|
if RunVim([], after, '')
|
|
|
|
call assert_equal(['QuitPre', 'ExitPre'], readfile('Xtestout'))
|
|
|
|
endif
|
|
|
|
call delete('Xtestout')
|
|
|
|
|
2019-10-20 17:12:08 -07:00
|
|
|
" ExitPre autocommand splits the window, so that it's no longer the last one.
|
2019-09-23 13:12:02 -07:00
|
|
|
let after =<< trim [CODE]
|
|
|
|
au QuitPre * call writefile(["QuitPre"], "Xtestout", "a")
|
|
|
|
au ExitPre * call writefile(["ExitPre"], "Xtestout", "a")
|
|
|
|
augroup nasty
|
|
|
|
au ExitPre * split
|
|
|
|
augroup END
|
|
|
|
quit
|
|
|
|
augroup nasty
|
|
|
|
au! ExitPre
|
|
|
|
augroup END
|
|
|
|
quit
|
|
|
|
[CODE]
|
|
|
|
|
2018-09-04 18:57:45 -07:00
|
|
|
if RunVim([], after, '')
|
|
|
|
call assert_equal(['QuitPre', 'ExitPre', 'QuitPre', 'ExitPre'],
|
|
|
|
\ readfile('Xtestout'))
|
|
|
|
endif
|
|
|
|
call delete('Xtestout')
|
2019-10-20 17:12:08 -07:00
|
|
|
|
|
|
|
" ExitPre autocommand splits and closes the window, so that there is still
|
|
|
|
" one window but it's a different one.
|
|
|
|
let after =<< trim [CODE]
|
|
|
|
au QuitPre * call writefile(["QuitPre"], "Xtestout", "a")
|
|
|
|
au ExitPre * call writefile(["ExitPre"], "Xtestout", "a")
|
|
|
|
augroup nasty
|
|
|
|
au ExitPre * split | only
|
|
|
|
augroup END
|
|
|
|
quit
|
|
|
|
augroup nasty
|
|
|
|
au! ExitPre
|
|
|
|
augroup END
|
|
|
|
quit
|
|
|
|
[CODE]
|
|
|
|
|
|
|
|
if RunVim([], after, '')
|
|
|
|
call assert_equal(['QuitPre', 'ExitPre', 'QuitPre', 'ExitPre'],
|
|
|
|
\ readfile('Xtestout'))
|
|
|
|
endif
|
|
|
|
call delete('Xtestout')
|
2018-09-04 18:57:45 -07:00
|
|
|
endfunc
|
2021-02-20 21:45:14 -07:00
|
|
|
|
|
|
|
" Test for getting the Vim exit code from v:exiting
|
|
|
|
func Test_exit_code()
|
|
|
|
call assert_equal(v:null, v:exiting)
|
|
|
|
|
|
|
|
let before =<< trim [CODE]
|
|
|
|
au QuitPre * call writefile(['qp = ' .. v:exiting], 'Xtestout', 'a')
|
|
|
|
au ExitPre * call writefile(['ep = ' .. v:exiting], 'Xtestout', 'a')
|
|
|
|
au VimLeavePre * call writefile(['lp = ' .. v:exiting], 'Xtestout', 'a')
|
|
|
|
au VimLeave * call writefile(['l = ' .. v:exiting], 'Xtestout', 'a')
|
|
|
|
[CODE]
|
|
|
|
|
|
|
|
if RunVim(before, ['quit'], '')
|
2022-08-13 06:31:00 -07:00
|
|
|
call assert_equal(['qp = v:null', 'ep = v:null', 'lp = 0', 'l = 0'], readfile('Xtestout'))
|
2021-02-20 21:45:14 -07:00
|
|
|
endif
|
|
|
|
call delete('Xtestout')
|
|
|
|
|
|
|
|
if RunVim(before, ['cquit'], '')
|
|
|
|
call assert_equal(['lp = 1', 'l = 1'], readfile('Xtestout'))
|
|
|
|
endif
|
|
|
|
call delete('Xtestout')
|
|
|
|
|
|
|
|
if RunVim(before, ['cquit 4'], '')
|
|
|
|
call assert_equal(['lp = 4', 'l = 4'], readfile('Xtestout'))
|
|
|
|
endif
|
|
|
|
call delete('Xtestout')
|
|
|
|
endfunc
|
|
|
|
|
2022-02-24 17:13:25 -07:00
|
|
|
func Test_exit_error_reading_input()
|
|
|
|
throw 'Skipped: Nvim does not exit after stdin is read'
|
|
|
|
|
|
|
|
CheckNotGui
|
2022-02-24 17:22:54 -07:00
|
|
|
CheckNotMSWindows
|
2022-02-24 17:20:35 -07:00
|
|
|
" The early exit causes memory not to be freed somehow
|
|
|
|
CheckNotAsan
|
2022-02-24 17:13:25 -07:00
|
|
|
|
2022-02-24 17:20:35 -07:00
|
|
|
call writefile([":au VimLeave * call writefile(['l = ' .. v:exiting], 'Xtestout')", ":tabnew", "q:"], 'Xscript', 'b')
|
2022-02-24 17:13:25 -07:00
|
|
|
|
|
|
|
" Nvim requires "-s -" to read stdin as Normal mode input
|
2022-02-24 17:20:35 -07:00
|
|
|
" if RunVim([], [], '<Xscript')
|
|
|
|
if RunVim([], [], '-s - <Xscript')
|
2022-02-24 17:17:17 -07:00
|
|
|
call assert_equal(1, v:shell_error)
|
2022-02-24 17:13:25 -07:00
|
|
|
call assert_equal(['l = 1'], readfile('Xtestout'))
|
|
|
|
endif
|
|
|
|
call delete('Xscript')
|
|
|
|
call delete('Xtestout')
|
|
|
|
endfun
|
|
|
|
|
|
|
|
|
2021-02-20 21:45:14 -07:00
|
|
|
" vim: shiftwidth=2 sts=2 expandtab
|