diff options
author | Bram Moolenaar <Bram@vim.org> | 2022-09-15 22:26:18 +0100 |
---|---|---|
committer | Bram Moolenaar <Bram@vim.org> | 2022-09-15 22:26:18 +0100 |
commit | dd674774bbe3774ff41b817bee0e32060ebcfdad (patch) | |
tree | 63b3a5688d6fd2cbb30058a5dc18b96870fd8ca6 /src/testdir | |
parent | dd44b58f64a173ffc976cc96ccdd00cd5493b273 (diff) |
patch 9.0.0475: not using deferred delete in testsv9.0.0475
Problem: Not using deferred delete in tests.
Solution: Use deferred delete more often.
Diffstat (limited to 'src/testdir')
-rw-r--r-- | src/testdir/test_vim9_script.vim | 102 |
1 files changed, 40 insertions, 62 deletions
diff --git a/src/testdir/test_vim9_script.vim b/src/testdir/test_vim9_script.vim index 0f462e3243..8f9ffad2f6 100644 --- a/src/testdir/test_vim9_script.vim +++ b/src/testdir/test_vim9_script.vim @@ -400,11 +400,10 @@ def Test_block_local_vars() # need to execute this with a separate Vim instance to avoid the current # context gets garbage collected. - writefile(lines, 'Xscript') + writefile(lines, 'Xscript', 'D') g:RunVim([], [], '-S Xscript') assert_equal(['ok'], readfile('Xdidit')) - delete('Xscript') delete('Xdidit') enddef @@ -991,13 +990,12 @@ def Test_cnext_works_in_catch() writefile([getqflist({idx: 0}).idx], 'Xcncresult') qall END - writefile(lines, 'XCatchCnext') + writefile(lines, 'XCatchCnext', 'D') g:RunVim([], [], '--clean -S XCatchCnext') assert_equal(['1'], readfile('Xcncresult')) delete('Xcncfile1') delete('Xcncfile2') - delete('XCatchCnext') delete('Xcncresult') enddef @@ -1015,9 +1013,8 @@ def Test_nocatch_throw_silenced() enddef silent! Func() END - writefile(lines, 'XthrowSilenced') + writefile(lines, 'XthrowSilenced', 'D') source XthrowSilenced - delete('XthrowSilenced') enddef def DeletedFunc(): list<any> @@ -1473,7 +1470,7 @@ def Test_vim9script_reload_delfunc() END # FuncNo() is defined - writefile(first_lines + withno_lines, 'Xreloaded.vim') + writefile(first_lines + withno_lines, 'Xreloaded.vim', 'D') source Xreloaded.vim g:DoCheck(true) @@ -1486,8 +1483,6 @@ def Test_vim9script_reload_delfunc() writefile(first_lines + withno_lines, 'Xreloaded.vim') source Xreloaded.vim g:DoCheck(false) - - delete('Xreloaded.vim') enddef def Test_vim9script_reload_delvar() @@ -1496,7 +1491,7 @@ def Test_vim9script_reload_delvar() vim9script var name = 'string' END - writefile(lines, 'XreloadVar.vim') + writefile(lines, 'XreloadVar.vim', 'D') source XreloadVar.vim # now write the script using the same variable locally - works @@ -1508,8 +1503,6 @@ def Test_vim9script_reload_delvar() END writefile(lines, 'XreloadVar.vim') source XreloadVar.vim - - delete('XreloadVar.vim') enddef def Test_func_redefine_error() @@ -1520,7 +1513,7 @@ def Test_func_redefine_error() 'enddef', 'Func()', ] - writefile(lines, 'Xtestscript.vim') + writefile(lines, 'Xtestscript.vim', 'D') for count in range(3) try @@ -1531,8 +1524,6 @@ def Test_func_redefine_error() assert_match('function <SNR>\d\+_Func, line 1', v:throwpoint) endtry endfor - - delete('Xtestscript.vim') enddef def Test_func_redefine_fails() @@ -2035,9 +2026,8 @@ def Test_for_outside_of_function() endfor assert_equal(' loop 1 loop 2 loop 3', result) END - writefile(lines, 'Xvim9for.vim') + writefile(lines, 'Xvim9for.vim', 'D') source Xvim9for.vim - delete('Xvim9for.vim') enddef def Test_for_skipped_block() @@ -2271,6 +2261,18 @@ def Test_for_loop_with_closure() END v9.CheckDefAndScriptSuccess(lines) + # also works when the loop variable is used only once halfway the loops + lines =<< trim END + var Clo: func + for i in range(5) + if i == 3 + Clo = () => i + endif + endfor + assert_equal(4, Clo()) + END + v9.CheckDefAndScriptSuccess(lines) + # using a local variable set to the loop variable in a closure results in the # value at that moment lines =<< trim END @@ -3330,12 +3332,11 @@ def Test_finish() finish g:res = 'three' END - writefile(lines, 'Xfinished') + writefile(lines, 'Xfinished', 'D') source Xfinished assert_equal('two', g:res) unlet g:res - delete('Xfinished') enddef def Test_forward_declaration() @@ -3349,14 +3350,13 @@ def Test_forward_declaration() theVal = 'else' g:laterVal = GetValue() END - writefile(lines, 'Xforward') + writefile(lines, 'Xforward', 'D') source Xforward assert_equal('something', g:initVal) assert_equal('else', g:laterVal) unlet g:initVal unlet g:laterVal - delete('Xforward') enddef def Test_declare_script_var_in_func() @@ -3408,7 +3408,7 @@ func Test_vim9script_not_global() echo 'local' enddef END - call writefile(vim9lines, 'Xvim9script.vim') + call writefile(vim9lines, 'Xvim9script.vim', 'D') source Xvim9script.vim try echo g:var @@ -3428,8 +3428,6 @@ func Test_vim9script_not_global() catch /E117:/ " caught endtry - - call delete('Xvim9script.vim') endfunc def Test_vim9_copen() @@ -3459,7 +3457,7 @@ def Test_error_in_autoload_script() var save_rtp = &rtp var dir = getcwd() .. '/Xruntime' &rtp = dir - mkdir(dir .. '/autoload', 'p') + mkdir(dir .. '/autoload', 'pR') var lines =<< trim END vim9script noclear @@ -3492,12 +3490,11 @@ def Test_error_in_autoload_script() v9.CheckScriptSuccess(lines) &rtp = save_rtp - delete(dir, 'rf') enddef def Test_error_in_autoload_script_foldexpr() var save_rtp = &rtp - mkdir('Xvim/autoload', 'p') + mkdir('Xvim/autoload', 'pR') &runtimepath = 'Xvim' var lines =<< trim END @@ -3515,8 +3512,6 @@ def Test_error_in_autoload_script_foldexpr() redraw END v9.CheckScriptFailure(lines, 'E684: List index out of range: 0') - - delete('Xvim', 'rf') enddef def Test_invalid_sid() @@ -3529,16 +3524,14 @@ def Test_invalid_sid() enddef def Test_restoring_cpo() - writefile(['vim9script', 'set nocp'], 'Xsourced') - writefile(['call writefile(["done"], "Xdone")', 'quit!'], 'Xclose') + writefile(['vim9script', 'set nocp'], 'Xsourced', 'D') + writefile(['call writefile(["done"], "Xdone")', 'quit!'], 'Xclose', 'D') if g:RunVim([], [], '-u NONE +"set cpo+=a" -S Xsourced -S Xclose') assert_equal(['done'], readfile('Xdone')) endif - delete('Xsourced') - delete('Xclose') delete('Xdone') - writefile(['vim9script', 'g:cpoval = &cpo'], 'XanotherScript') + writefile(['vim9script', 'g:cpoval = &cpo'], 'XanotherScript', 'D') set cpo=aABceFsMny> edit XanotherScript so % @@ -3551,7 +3544,6 @@ def Test_restoring_cpo() assert_equal('aABceFsMny>', &cpo) assert_equal('aABceFsMny>', g:cpoval) - delete('XanotherScript') set cpo&vim unlet g:cpoval @@ -3559,7 +3551,7 @@ def Test_restoring_cpo() # 'cpo' is not restored in main vimrc var save_HOME = $HOME $HOME = getcwd() .. '/Xhome' - mkdir('Xhome') + mkdir('Xhome', 'R') var lines =<< trim END vim9script writefile(['before: ' .. &cpo], 'Xrporesult') @@ -3571,14 +3563,14 @@ def Test_restoring_cpo() lines =<< trim END call writefile(['later: ' .. &cpo], 'Xrporesult', 'a') END - writefile(lines, 'Xlegacy') + writefile(lines, 'Xlegacy', 'D') lines =<< trim END vim9script call writefile(['vim9: ' .. &cpo], 'Xrporesult', 'a') qa END - writefile(lines, 'Xvim9') + writefile(lines, 'Xvim9', 'D') var cmd = g:GetVimCommand() .. " -S Xlegacy -S Xvim9" cmd = substitute(cmd, '-u NONE', '', '') @@ -3591,9 +3583,6 @@ def Test_restoring_cpo() 'vim9: aABceFs'], readfile('Xrporesult')) $HOME = save_HOME - delete('Xhome', 'rf') - delete('Xlegacy') - delete('Xvim9') delete('Xrporesult') endif enddef @@ -3611,7 +3600,7 @@ def Run_test_no_redraw_when_restoring_cpo() export def Func() enddef END - mkdir('Xnordir/autoload', 'p') + mkdir('Xnordir/autoload', 'pR') writefile(lines, 'Xnordir/autoload/script.vim') lines =<< trim END @@ -3621,7 +3610,7 @@ def Run_test_no_redraw_when_restoring_cpo() au CmdlineEnter : ++once timer_start(0, (_) => script#Func()) setline(1, 'some text') END - writefile(lines, 'XTest_redraw_cpo') + writefile(lines, 'XTest_redraw_cpo', 'D') var buf = g:RunVimInTerminal('-S XTest_redraw_cpo', {'rows': 6}) term_sendkeys(buf, "V:") g:VerifyScreenDump(buf, 'Test_vim9_no_redraw', {}) @@ -3629,8 +3618,6 @@ def Run_test_no_redraw_when_restoring_cpo() # clean up term_sendkeys(buf, "\<Esc>u") g:StopVimInTerminal(buf) - delete('XTest_redraw_cpo') - delete('Xnordir', 'rf') enddef func Test_reject_declaration() @@ -3731,8 +3718,8 @@ def Run_Test_define_func_at_command_line() call writefile(['errors: ' .. string(v:errors)], 'Xdidcmd') endfunc END - writefile([''], 'Xdidcmd') - writefile(lines, 'XcallFunc') + writefile([''], 'Xdidcmd', 'D') + writefile(lines, 'XcallFunc', 'D') var buf = g:RunVimInTerminal('-S XcallFunc', {rows: 6}) # define Afunc() on the command line term_sendkeys(buf, ":def Afunc()\<CR>Bfunc()\<CR>enddef\<CR>") @@ -3740,8 +3727,6 @@ def Run_Test_define_func_at_command_line() g:WaitForAssert(() => assert_equal(['errors: []'], readfile('Xdidcmd'))) call g:StopVimInTerminal(buf) - delete('XcallFunc') - delete('Xdidcmd') enddef def Test_script_var_scope() @@ -3869,9 +3854,8 @@ def Test_no_unknown_error_after_error() sleep 10m endfor END - writefile(lines, 'Xdef') + writefile(lines, 'Xdef', 'D') assert_fails('so Xdef', ['E684:', 'E1012:']) - delete('Xdef') enddef def InvokeNormal() @@ -3914,7 +3898,7 @@ def Test_script_var_gone_when_sourced_twice() name = arg enddef END - writefile(lines, 'XscriptTwice.vim') + writefile(lines, 'XscriptTwice.vim', 'D') so XscriptTwice.vim assert_equal('thename', g:GetName()) g:SetName('newname') @@ -3925,7 +3909,6 @@ def Test_script_var_gone_when_sourced_twice() delfunc g:GetName delfunc g:SetName - delete('XscriptTwice.vim') unlet g:guard enddef @@ -4102,7 +4085,7 @@ def Run_Test_debug_with_lambda() breakadd func Func Func() END - writefile(lines, 'XdebugFunc') + writefile(lines, 'XdebugFunc', 'D') var buf = g:RunVimInTerminal('-S XdebugFunc', {rows: 6, wait_for_ruler: 0}) g:WaitForAssert(() => assert_match('^>', term_getline(buf, 6))) @@ -4110,7 +4093,6 @@ def Run_Test_debug_with_lambda() g:WaitForAssert(() => assert_match('\[0\]', term_getline(buf, 5))) g:StopVimInTerminal(buf) - delete('XdebugFunc') enddef func Test_debug_running_out_of_lines() @@ -4138,7 +4120,7 @@ def Run_Test_debug_running_out_of_lines() breakadd func Crash Crash() END - writefile(lines, 'XdebugFunc') + writefile(lines, 'XdebugFunc', 'D') var buf = g:RunVimInTerminal('-S XdebugFunc', {rows: 6, wait_for_ruler: 0}) g:WaitForAssert(() => assert_match('^>', term_getline(buf, 6))) @@ -4150,7 +4132,6 @@ def Run_Test_debug_running_out_of_lines() g:TermWait(buf) g:StopVimInTerminal(buf) - delete('XdebugFunc') enddef def Test_ambigous_command_error() @@ -4239,7 +4220,7 @@ def Test_profile_with_lambda() writefile([result], 'Xdidprofile') endtry END - writefile(lines, 'Xprofile.vim') + writefile(lines, 'Xprofile.vim', 'D') call system(g:GetVimCommand() .. ' --clean' .. ' -c "so Xprofile.vim"' @@ -4250,7 +4231,6 @@ def Test_profile_with_lambda() assert_true(filereadable('Xprofile.log')) delete('Xdidprofile') delete('Xprofile.log') - delete('Xprofile.vim') enddef func Test_misplaced_type() @@ -4323,10 +4303,8 @@ def Test_substitute_cmd() assert_equal('otherthing', getline(1)) bwipe! END - writefile(lines, 'Xvim9lines') + writefile(lines, 'Xvim9lines', 'D') source Xvim9lines - - delete('Xvim9lines') enddef " vim: ts=8 sw=2 sts=2 expandtab tw=80 fdm=marker |