From a11849abdf7eeb33423be2ee920c7b504379b39b Mon Sep 17 00:00:00 2001 From: zeertzjq Date: Wed, 19 Apr 2023 07:55:27 +0800 Subject: vim-patch:9.0.1468: recursively calling :defer function if it does :qa Problem: Recursively calling :defer function if it does :qa in a compiled function. Solution: Clear the defer entry before calling the function. (closes vim/vim#12271) https://github.com/vim/vim/commit/a1f2b5ddc63d4e2b6ab047d8c839dd8477b36aba --- test/old/testdir/test_user_func.vim | 55 ++++++++++++++++++++++++++----------- 1 file changed, 39 insertions(+), 16 deletions(-) diff --git a/test/old/testdir/test_user_func.vim b/test/old/testdir/test_user_func.vim index d217ca8c69..d8e36cefe4 100644 --- a/test/old/testdir/test_user_func.vim +++ b/test/old/testdir/test_user_func.vim @@ -609,33 +609,56 @@ func Test_defer_throw() call assert_false(filereadable('XDeleteTwo')) endfunc -func Test_defer_quitall() +func Test_defer_quitall_func() let lines =<< trim END - " vim9script func DeferLevelTwo() - call writefile(['text'], 'XQuitallTwo', 'D') - call writefile(['quit'], 'XQuitallThree', 'a') + call writefile(['text'], 'XQuitallFuncTwo', 'D') + call writefile(['quit'], 'XQuitallFuncThree', 'a') qa! endfunc - " def DeferLevelOne() func DeferLevelOne() - call writefile(['text'], 'XQuitallOne', 'D') - call DeferLevelTwo() - " enddef + call writefile(['text'], 'XQuitalFunclOne', 'D') + defer DeferLevelTwo() endfunc - " DeferLevelOne() call DeferLevelOne() END - call writefile(lines, 'XdeferQuitall', 'D') - let res = system(GetVimCommand() .. ' -X -S XdeferQuitall') + call writefile(lines, 'XdeferQuitallFunc', 'D') + call system(GetVimCommand() .. ' -X -S XdeferQuitallFunc') call assert_equal(0, v:shell_error) - call assert_false(filereadable('XQuitallOne')) - call assert_false(filereadable('XQuitallTwo')) - call assert_equal(['quit'], readfile('XQuitallThree')) + call assert_false(filereadable('XQuitallFuncOne')) + call assert_false(filereadable('XQuitallFuncTwo')) + call assert_equal(['quit'], readfile('XQuitallFuncThree')) - call delete('XQuitallThree') + call delete('XQuitallFuncThree') +endfunc + +func Test_defer_quitall_def() + throw 'Skipped: Vim9 script is N/A' + let lines =<< trim END + vim9script + def DeferLevelTwo() + call writefile(['text'], 'XQuitallDefTwo', 'D') + call writefile(['quit'], 'XQuitallDefThree', 'a') + qa! + enddef + + def DeferLevelOne() + call writefile(['text'], 'XQuitallDefOne', 'D') + defer DeferLevelTwo() + enddef + + DeferLevelOne() + END + call writefile(lines, 'XdeferQuitallDef', 'D') + call system(GetVimCommand() .. ' -X -S XdeferQuitallDef') + call assert_equal(0, v:shell_error) + call assert_false(filereadable('XQuitallDefOne')) + call assert_false(filereadable('XQuitallDefTwo')) + call assert_equal(['quit'], readfile('XQuitallDefThree')) + + call delete('XQuitallDefThree') endfunc func Test_defer_quitall_in_expr_func() @@ -655,7 +678,7 @@ func Test_defer_quitall_in_expr_func() call Test_defer_in_funcref() END call writefile(lines, 'XdeferQuitallExpr', 'D') - let res = system(GetVimCommand() .. ' -X -S XdeferQuitallExpr') + call system(GetVimCommand() .. ' -X -S XdeferQuitallExpr') call assert_equal(0, v:shell_error) call assert_false(filereadable('Xentry0')) call assert_false(filereadable('Xentry1')) -- cgit