mirror of
https://github.com/neovim/neovim.git
synced 2025-02-25 18:55:25 -06:00
Merge pull request #25703 from zeertzjq/vim-9.0.2044
vim-patch:9.0.{2044,2045}
This commit is contained in:
commit
c49cfd89fd
@ -3296,8 +3296,23 @@ static void handle_defer_one(funccall_T *funccal)
|
|||||||
char *name = dr->dr_name;
|
char *name = dr->dr_name;
|
||||||
dr->dr_name = NULL;
|
dr->dr_name = NULL;
|
||||||
|
|
||||||
|
// If the deferred function is called after an exception, then only the
|
||||||
|
// first statement in the function will be executed. Save and restore
|
||||||
|
// the try/catch/throw exception state.
|
||||||
|
const int save_trylevel = trylevel;
|
||||||
|
const bool save_did_throw = did_throw;
|
||||||
|
const bool save_need_rethrow = need_rethrow;
|
||||||
|
|
||||||
|
trylevel = 0;
|
||||||
|
did_throw = false;
|
||||||
|
need_rethrow = false;
|
||||||
|
|
||||||
call_func(name, -1, &rettv, dr->dr_argcount, dr->dr_argvars, &funcexe);
|
call_func(name, -1, &rettv, dr->dr_argcount, dr->dr_argvars, &funcexe);
|
||||||
|
|
||||||
|
trylevel = save_trylevel;
|
||||||
|
did_throw = save_did_throw;
|
||||||
|
need_rethrow = save_need_rethrow;
|
||||||
|
|
||||||
tv_clear(&rettv);
|
tv_clear(&rettv);
|
||||||
xfree(name);
|
xfree(name);
|
||||||
for (int i = dr->dr_argcount - 1; i >= 0; i--) {
|
for (int i = dr->dr_argcount - 1; i >= 0; i--) {
|
||||||
|
@ -231,6 +231,8 @@ func RunTheTest(test)
|
|||||||
endtry
|
endtry
|
||||||
endif
|
endif
|
||||||
|
|
||||||
|
let skipped = v:false
|
||||||
|
|
||||||
au VimLeavePre * call EarlyExit(g:testfunc)
|
au VimLeavePre * call EarlyExit(g:testfunc)
|
||||||
if a:test =~ 'Test_nocatch_'
|
if a:test =~ 'Test_nocatch_'
|
||||||
" Function handles errors itself. This avoids skipping commands after the
|
" Function handles errors itself. This avoids skipping commands after the
|
||||||
@ -240,6 +242,7 @@ func RunTheTest(test)
|
|||||||
if g:skipped_reason != ''
|
if g:skipped_reason != ''
|
||||||
call add(s:messages, ' Skipped')
|
call add(s:messages, ' Skipped')
|
||||||
call add(s:skipped, 'SKIPPED ' . a:test . ': ' . g:skipped_reason)
|
call add(s:skipped, 'SKIPPED ' . a:test . ': ' . g:skipped_reason)
|
||||||
|
let skipped = v:true
|
||||||
endif
|
endif
|
||||||
else
|
else
|
||||||
try
|
try
|
||||||
@ -247,6 +250,7 @@ func RunTheTest(test)
|
|||||||
catch /^\cskipped/
|
catch /^\cskipped/
|
||||||
call add(s:messages, ' Skipped')
|
call add(s:messages, ' Skipped')
|
||||||
call add(s:skipped, 'SKIPPED ' . a:test . ': ' . substitute(v:exception, '^\S*\s\+', '', ''))
|
call add(s:skipped, 'SKIPPED ' . a:test . ': ' . substitute(v:exception, '^\S*\s\+', '', ''))
|
||||||
|
let skipped = v:true
|
||||||
catch
|
catch
|
||||||
call add(v:errors, 'Caught exception in ' . a:test . ': ' . v:exception . ' @ ' . v:throwpoint)
|
call add(v:errors, 'Caught exception in ' . a:test . ': ' . v:exception . ' @ ' . v:throwpoint)
|
||||||
endtry
|
endtry
|
||||||
@ -342,14 +346,16 @@ func RunTheTest(test)
|
|||||||
endif
|
endif
|
||||||
endwhile
|
endwhile
|
||||||
|
|
||||||
" Check if the test has left any swap files behind. Delete them before
|
if !skipped
|
||||||
" running tests again, they might interfere.
|
" Check if the test has left any swap files behind. Delete them before
|
||||||
let swapfiles = s:GetSwapFileList()
|
" running tests again, they might interfere.
|
||||||
if len(swapfiles) > 0
|
let swapfiles = s:GetSwapFileList()
|
||||||
call add(s:messages, "Found swap files: " .. string(swapfiles))
|
if len(swapfiles) > 0
|
||||||
for name in swapfiles
|
call add(s:messages, "Found swap files: " .. string(swapfiles))
|
||||||
call delete(name)
|
for name in swapfiles
|
||||||
endfor
|
call delete(name)
|
||||||
|
endfor
|
||||||
|
endif
|
||||||
endif
|
endif
|
||||||
endfunc
|
endfunc
|
||||||
|
|
||||||
|
@ -793,5 +793,31 @@ func Test_defer_wrong_arguments()
|
|||||||
call v9.CheckScriptFailure(lines, 'E1013: Argument 1: type mismatch, expected string but got number')
|
call v9.CheckScriptFailure(lines, 'E1013: Argument 1: type mismatch, expected string but got number')
|
||||||
endfunc
|
endfunc
|
||||||
|
|
||||||
|
" Test for calling a deferred function after an exception
|
||||||
|
func Test_defer_after_exception()
|
||||||
|
let g:callTrace = []
|
||||||
|
func Defer()
|
||||||
|
let g:callTrace += ['a']
|
||||||
|
let g:callTrace += ['b']
|
||||||
|
let g:callTrace += ['c']
|
||||||
|
let g:callTrace += ['d']
|
||||||
|
endfunc
|
||||||
|
|
||||||
|
func Foo()
|
||||||
|
defer Defer()
|
||||||
|
throw "TestException"
|
||||||
|
endfunc
|
||||||
|
|
||||||
|
try
|
||||||
|
call Foo()
|
||||||
|
catch /TestException/
|
||||||
|
let g:callTrace += ['e']
|
||||||
|
endtry
|
||||||
|
call assert_equal(['a', 'b', 'c', 'd', 'e'], g:callTrace)
|
||||||
|
|
||||||
|
delfunc Defer
|
||||||
|
delfunc Foo
|
||||||
|
unlet g:callTrace
|
||||||
|
endfunc
|
||||||
|
|
||||||
" vim: shiftwidth=2 sts=2 expandtab
|
" vim: shiftwidth=2 sts=2 expandtab
|
||||||
|
Loading…
Reference in New Issue
Block a user