1
0
forked from aniani/vim

patch 9.0.0397: :defer not tested with exceptions and ":qa!"

Problem:    :defer not tested with exceptions and ":qa!".
Solution:   Test :defer works when exceptions are thrown and when ":qa!" is
            used.  Invoke the deferred calls on exit.
This commit is contained in:
Bram Moolenaar
2022-09-06 18:31:14 +01:00
parent 2834ebdee4
commit 58779858fb
9 changed files with 123 additions and 19 deletions

View File

@@ -581,5 +581,49 @@ func Test_defer()
call assert_fails('defer Part("arg2")', 'E1300:')
endfunc
func DeferLevelTwo()
call writefile(['text'], 'XDeleteTwo', 'D')
throw 'someerror'
endfunc
def DeferLevelOne()
call writefile(['text'], 'XDeleteOne', 'D')
call g:DeferLevelTwo()
enddef
func Test_defer_throw()
let caught = 'no'
try
call DeferLevelOne()
catch /someerror/
let caught = 'yes'
endtry
call assert_equal('yes', caught)
call assert_false(filereadable('XDeleteOne'))
call assert_false(filereadable('XDeleteTwo'))
endfunc
func Test_defer_quitall()
let lines =<< trim END
vim9script
func DeferLevelTwo()
call writefile(['text'], 'XQuitallTwo', 'D')
qa!
endfunc
def DeferLevelOne()
call writefile(['text'], 'XQuitallOne', 'D')
call DeferLevelTwo()
enddef
DeferLevelOne()
END
call writefile(lines, 'XdeferQuitall', 'D')
let res = system(GetVimCommandClean() .. ' -X -S XdeferQuitall')
call assert_equal(0, v:shell_error)
call assert_false(filereadable('XQuitallOne'))
call assert_false(filereadable('XQuitallTwo'))
endfunc
" vim: shiftwidth=2 sts=2 expandtab