# HG changeset patch # User Bram Moolenaar # Date 1665866702 -7200 # Node ID 0913cd44fdfab2d1ffefbafd71b01e1e3f3c96bd # Parent bd117a0611924a50bc8607058f65a1b38c44a8a8 patch 9.0.0768: too many delete() calls in tests Commit: https://github.com/vim/vim/commit/5b148ef2628251b2d79f78c65a614f8aca404329 Author: Bram Moolenaar Date: Sat Oct 15 21:35:56 2022 +0100 patch 9.0.0768: too many delete() calls in tests Problem: Too many delete() calls in tests. Solution: Use deferred delete where possible. diff --git a/src/testdir/test_undo.vim b/src/testdir/test_undo.vim --- a/src/testdir/test_undo.vim +++ b/src/testdir/test_undo.vim @@ -384,21 +384,18 @@ func Test_undofile_truncated() " try several sizes for size in range(20, 500, 33) - call writefile(contents[0:size], 'Xundofile') + call writefile(contents[0:size], 'Xundofile', 'D') call assert_fails('rundo Xundofile', 'E825:') endfor bwipe! - call delete('Xundofile') endfunc func Test_rundo_errors() call assert_fails('rundo XfileDoesNotExist', 'E822:') - call writefile(['abc'], 'Xundofile') + call writefile(['abc'], 'Xundofile', 'D') call assert_fails('rundo Xundofile', 'E823:') - - call delete('Xundofile') endfunc func Test_undofile_next() diff --git a/src/testdir/test_user_func.vim b/src/testdir/test_user_func.vim --- a/src/testdir/test_user_func.vim +++ b/src/testdir/test_user_func.vim @@ -303,7 +303,7 @@ func Test_function_defined_line() qall! [CODE] - call writefile(lines, 'Xtest.vim') + call writefile(lines, 'Xtest.vim', 'D') let res = system(GetVimCommandClean() .. ' -es -X -S Xtest.vim') call assert_equal(0, v:shell_error) @@ -324,8 +324,6 @@ func Test_function_defined_line() let m = matchstr(res, 'function F6()[^[:print:]]*[[:print:]]*') call assert_match(' line 23$', m) - - call delete('Xtest.vim') endfunc " Test for defining a function reference in the global scope @@ -380,12 +378,11 @@ func Test_script_local_func() :qall [CODE] - call writefile(lines, 'Xscript') + call writefile(lines, 'Xscript', 'D') if RunVim([], [], '-s Xscript') call assert_equal([], readfile('Xresult')) endif call delete('Xresult') - call delete('Xscript') endfunc " Test for errors in defining new functions @@ -417,9 +414,8 @@ func Test_func_def_error() call assert_fails('call feedkeys(":func d.F1()\", "xt")', 'E717:') " Define an autoload function with an incorrect file name - call writefile(['func foo#Bar()', 'return 1', 'endfunc'], 'Xscript') + call writefile(['func foo#Bar()', 'return 1', 'endfunc'], 'Xscript', 'D') call assert_fails('source Xscript', 'E746:') - call delete('Xscript') " Try to list functions using an invalid search pattern call assert_fails('function /\%(/', 'E53:') @@ -444,9 +440,8 @@ endfunc " Test for calling return outside of a function func Test_return_outside_func() - call writefile(['return 10'], 'Xscript') + call writefile(['return 10'], 'Xscript', 'D') call assert_fails('source Xscript', 'E133:') - call delete('Xscript') endfunc " Test for errors in calling a function diff --git a/src/testdir/test_usercommands.vim b/src/testdir/test_usercommands.vim --- a/src/testdir/test_usercommands.vim +++ b/src/testdir/test_usercommands.vim @@ -239,7 +239,7 @@ func Test_Ambiguous() endfunc func Test_redefine_on_reload() - call writefile(['command ExistingCommand echo "yes"'], 'Xcommandexists') + call writefile(['command ExistingCommand echo "yes"'], 'Xcommandexists', 'D') call assert_equal(0, exists(':ExistingCommand')) source Xcommandexists call assert_equal(2, exists(':ExistingCommand')) @@ -248,9 +248,8 @@ func Test_redefine_on_reload() call assert_equal(2, exists(':ExistingCommand')) " But redefining in another script is not OK. - call writefile(['command ExistingCommand echo "yes"'], 'Xcommandexists2') + call writefile(['command ExistingCommand echo "yes"'], 'Xcommandexists2', 'D') call assert_fails('source Xcommandexists2', 'E174:') - call delete('Xcommandexists2') " And defining twice in one script is not OK. delcommand ExistingCommand @@ -262,7 +261,6 @@ func Test_redefine_on_reload() call assert_fails('source Xcommandexists', 'E174:') call assert_equal(2, exists(':ExistingCommand')) - call delete('Xcommandexists') delcommand ExistingCommand endfunc @@ -849,7 +847,7 @@ func Test_block_declaration_legacy_scrip @a = save } END - call writefile(lines, 'Xlegacy') + call writefile(lines, 'Xlegacy', 'D') source Xlegacy let lines =<< trim END @@ -864,12 +862,10 @@ func Test_block_declaration_legacy_scrip call assert_equal('something', g:someExpr) call assert_equal('also', @a) END - call writefile(lines, 'Xother') + call writefile(lines, 'Xother', 'D') source Xother unlet g:someExpr - call delete('Xlegacy') - call delete('Xother') delcommand Rename endfunc diff --git a/src/testdir/test_viminfo.vim b/src/testdir/test_viminfo.vim --- a/src/testdir/test_viminfo.vim +++ b/src/testdir/test_viminfo.vim @@ -20,7 +20,7 @@ func Test_viminfo_read_and_write() \ '|copied as-is', \ '|and one more', \ ] - call writefile(lines, 'Xviminfo') + call writefile(lines, 'Xviminfo', 'D') rviminfo Xviminfo call assert_equal('asdf', @/) @@ -40,8 +40,6 @@ func Test_viminfo_read_and_write() endif endfor call assert_equal(3, done) - - call delete('Xviminfo') endfunc func Test_global_vars() @@ -130,7 +128,7 @@ func Test_global_vars() \ "!GLOB_BLOB_3\tBLO\t0z1x", \ "!GLOB_BLOB_4\tBLO\t0z12 ab", \ "!GLOB_LIST_1\tLIS\t1 2", - \ "!GLOB_DICT_1\tDIC\t1 2"], 'Xviminfo') + \ "!GLOB_DICT_1\tDIC\t1 2"], 'Xviminfo', 'D') call assert_fails('rv! Xviminfo', 'E488:') call assert_equal('123', g:GLOB_BLOB_1) call assert_equal(1, type(g:GLOB_BLOB_1)) @@ -145,7 +143,6 @@ func Test_global_vars() call assert_equal('1 2', g:GLOB_DICT_1) call assert_equal(1, type(g:GLOB_DICT_1)) - call delete('Xviminfo') set viminfo-=! endfunc @@ -583,7 +580,7 @@ func Test_viminfo_bad_syntax() call add(lines, '|1,"x\') " trailing backslash call add(lines, '|1,,,,') "trailing comma call add(lines, '|1,>234') " trailing continuation line - call writefile(lines, 'Xviminfo') + call writefile(lines, 'Xviminfo', 'D') rviminfo Xviminfo call delete('Xviminfo') @@ -613,9 +610,8 @@ func Test_viminfo_bad_syntax2() call add(lines, '|4,20,1,1,1,"x"') " invalid value for file name call add(lines, '|4,49,0,1,1,"x"') " invalid value for line number - call writefile(lines, 'Xviminfo') + call writefile(lines, 'Xviminfo', 'D') rviminfo Xviminfo - call delete('Xviminfo') endfunc func Test_viminfo_file_marks() @@ -691,10 +687,9 @@ func Test_viminfo_file_mark_zero_time() \ '|4,66,1,0,0,"/tmp/nothing"', \ "", \ ] - call writefile(lines, 'Xviminfo') + call writefile(lines, 'Xviminfo', 'D') delmark B rviminfo Xviminfo - call delete('Xviminfo') call assert_equal(1, line("'B")) delmark B endfunc @@ -703,7 +698,7 @@ endfunc func Test_viminfo_file_mark_unloaded_buf() let save_viminfo = &viminfo set viminfo&vim - call writefile(repeat(['vim'], 10), 'Xfile1') + call writefile(repeat(['vim'], 10), 'Xfile1', 'D') %bwipe edit! Xfile1 call setpos("'u", [0, 3, 1, 0]) @@ -716,7 +711,6 @@ func Test_viminfo_file_mark_unloaded_buf call assert_equal([0, 3, 1, 0], getpos("'u")) call assert_equal([0, 5, 1, 0], getpos("'v")) %bwipe - call delete('Xfile1') call delete('Xviminfo') let &viminfo = save_viminfo endfunc @@ -745,11 +739,10 @@ func Test_viminfo_oldfiles() \ "\t\"\t11\t0", \ "", \ ] - call writefile(lines, 'Xviminfo') + call writefile(lines, 'Xviminfo', 'D') delmark E edit /tmp/file_two.txt rviminfo! Xviminfo - call delete('Xviminfo') call assert_equal('h viminfo', histget(':')) call assert_equal('session', histget('/')) @@ -839,7 +832,7 @@ func Test_viminfo_error() call assert_fails('rviminfo xyz', 'E195:') " Illegal starting character - call writefile(["a 123"], 'Xviminfo') + call writefile(["a 123"], 'Xviminfo', 'D') call assert_fails('rv Xviminfo', 'E575:') " Illegal register name in the viminfo file @@ -859,8 +852,6 @@ func Test_viminfo_error() call writefile(repeat(['"@'], 15), 'Xviminfo') call assert_fails('rv Xviminfo', 'E577:') - - call delete('Xviminfo') endfunc " Test for saving and restoring last substitute string in viminfo @@ -901,7 +892,7 @@ func Test_viminfo_registers_old() \ " :echo 'Hello'\", \ "", \ ] - call writefile(lines, 'Xviminfo') + call writefile(lines, 'Xviminfo', 'D') let @a = 'one' let @b = 'two' let @m = 'three' @@ -919,7 +910,7 @@ func Test_viminfo_registers_old() call assert_equal(":echo 'Hello'\", getreg('m')) call assert_equal('Vim', getreg('"')) call assert_equal("\nHello", execute('normal @@')) - call delete('Xviminfo') + let @" = '' endfunc @@ -931,11 +922,11 @@ func Test_viminfo_large_register() set viminfo+=<200 let lines = ['"r CHAR 0'] call extend(lines, repeat(["\tsun is rising"], 200)) - call writefile(lines, 'Xviminfo') + call writefile(lines, 'Xviminfo', 'D') let @r = '' rviminfo! Xviminfo call assert_equal(join(repeat(["sun is rising"], 200), "\n"), @r) - call delete('Xviminfo') + let @r = '' let &viminfo = save_viminfo endfunc @@ -946,9 +937,9 @@ func Test_viminfofile_none() set viminfofile=NONE wviminfo Xviminfo call assert_false(filereadable('Xviminfo')) - call writefile([''], 'Xviminfo') + call writefile([''], 'Xviminfo', 'D') call assert_fails('rviminfo Xviminfo', 'E195:') - call delete('Xviminfo') + let &viminfofile = save_vif endfunc @@ -956,18 +947,16 @@ endfunc func Test_viminfo_perm() CheckUnix CheckNotRoot - call writefile([''], 'Xviminfo') + call writefile([''], 'Xviminfo', 'D') call setfperm('Xviminfo', 'r-x------') call assert_fails('wviminfo Xviminfo', 'E137:') call setfperm('Xviminfo', '--x------') call assert_fails('rviminfo Xviminfo', 'E195:') - call delete('Xviminfo') " Try to write the viminfo to a directory - call mkdir('Xvifdir') + call mkdir('Xvifdir', 'R') call assert_fails('wviminfo Xvifdir', 'E137:') call assert_fails('rviminfo Xvifdir', 'E195:') - call delete('Xvifdir', 'rf') endfunc " Test for writing to an existing viminfo file merges the file marks @@ -979,8 +968,8 @@ func XTest_viminfo_marks_merge() %argdelete %bwipe - call writefile(repeat(['editor'], 10), 'Xbufa') - call writefile(repeat(['Vim'], 10), 'Xbufb') + call writefile(repeat(['editor'], 10), 'Xbufa', 'D') + call writefile(repeat(['Vim'], 10), 'Xbufb', 'D') " set marks in buffers call test_settime(10) @@ -1013,8 +1002,6 @@ func XTest_viminfo_marks_merge() " cleanup %bwipe call delete('Xviminfo') - call delete('Xbufa') - call delete('Xbufb') call test_settime(0) let &viminfo=save_viminfo endfunc @@ -1051,7 +1038,7 @@ func Test_viminfo_oldfiles_newfile() w! Xnew-file.txt qall [CODE] - call writefile(commands, 'Xviminfotest') + call writefile(commands, 'Xviminfotest', 'D') let buf = RunVimInTerminal('-S Xviminfotest', #{wait_for_ruler: 0}) call WaitForAssert({-> assert_equal("finished", term_getstatus(buf))}) @@ -1059,8 +1046,8 @@ func Test_viminfo_oldfiles_newfile() rviminfo! Xviminfofile call assert_match('Xnew-file.txt$', v:oldfiles[0]) call assert_equal(1, len(v:oldfiles)) + call delete('Xviminfofile') - call delete('Xviminfotest') call delete('Xnew-file.txt') let v:oldfiles = test_null_list() @@ -1262,7 +1249,7 @@ func Test_viminfo_merge_old_filemarks() call add(lines, '|1,4') call add(lines, '> ' .. fnamemodify('a.txt', ':p:~')) call add(lines, "\tb\t7\t0\n") - call writefile(lines, 'Xviminfo') + call writefile(lines, 'Xviminfo', 'D') edit b.txt call setline(1, range(1, 20)) 12mark b @@ -1274,7 +1261,6 @@ func Test_viminfo_merge_old_filemarks() edit b.txt rviminfo! Xviminfo call assert_equal(12, line("'b")) - call delete('Xviminfo') endfunc " Test for merging the jump list from a old viminfo file @@ -1284,14 +1270,13 @@ func Test_viminfo_merge_old_jumplist() call add(lines, "-' 20 1 " .. fnamemodify('a.txt', ':p:~')) call add(lines, "-' 30 1 " .. fnamemodify('b.txt', ':p:~')) call add(lines, "-' 40 1 " .. fnamemodify('b.txt', ':p:~')) - call writefile(lines, 'Xviminfo') + call writefile(lines, 'Xviminfo', 'D') clearjumps rviminfo! Xviminfo let l = getjumplist()[0] call assert_equal([40, 30, 20, 10], [l[0].lnum, l[1].lnum, l[2].lnum, \ l[3].lnum]) bw! - call delete('Xviminfo') endfunc " vim: shiftwidth=2 sts=2 expandtab diff --git a/src/testdir/test_vimscript.vim b/src/testdir/test_vimscript.vim --- a/src/testdir/test_vimscript.vim +++ b/src/testdir/test_vimscript.vim @@ -33,15 +33,13 @@ func RunInNewVim(test, verify) call writefile(v:errors, 'Xtest.out') qall END - call writefile(init, 'Xtest.vim') + call writefile(init, 'Xtest.vim', 'D') call writefile(a:test, 'Xtest.vim', 'a') - call writefile(a:verify, 'Xverify.vim') + call writefile(a:verify, 'Xverify.vim', 'D') call writefile(cleanup, 'Xverify.vim', 'a') call RunVim([], [], "-S Xtest.vim -S Xverify.vim") call assert_equal([], readfile('Xtest.out')) call delete('Xtest.out') - call delete('Xtest.vim') - call delete('Xverify.vim') endfunc "------------------------------------------------------------------------------- @@ -2935,7 +2933,7 @@ func Test_nested_if_else_errors() let code =<< trim END endif END - call writefile(code, 'Xtest') + call writefile(code, 'Xtest', 'D') call AssertException(['source Xtest'], 'Vim(endif):E580: :endif without :if') " :endif without :if @@ -3088,8 +3086,6 @@ func Test_nested_if_else_errors() END call writefile(code, 'Xtest') call AssertException(['source Xtest'], 'Vim(elseif):E584: :elseif after :else') - - call delete('Xtest') endfunc "------------------------------------------------------------------------------- @@ -3118,7 +3114,7 @@ func Test_nested_while_error() endwhile endif END - call writefile(code, 'Xtest') + call writefile(code, 'Xtest', 'D') call AssertException(['source Xtest'], 'Vim(endwhile):E588: :endwhile without :while') " Missing :endif @@ -3215,8 +3211,6 @@ func Test_nested_while_error() END call writefile(code, 'Xtest') call AssertException(['source Xtest'], 'Vim(endwhile):E588: :endwhile without :while') - - call delete('Xtest') endfunc "------------------------------------------------------------------------------- @@ -3236,7 +3230,7 @@ func Test_nested_cont_break_error() let code =<< trim END continue END - call writefile(code, 'Xtest') + call writefile(code, 'Xtest', 'D') call AssertException(['source Xtest'], 'Vim(continue):E586: :continue without :while or :for') " :continue without :while @@ -3323,8 +3317,6 @@ func Test_nested_cont_break_error() END call writefile(code, 'Xtest') call AssertException(['source Xtest'], 'Vim(break):E587: :break without :while or :for') - - call delete('Xtest') endfunc "------------------------------------------------------------------------------- @@ -3344,7 +3336,7 @@ func Test_nested_endtry_error() let code =<< trim END endtry END - call writefile(code, 'Xtest') + call writefile(code, 'Xtest', 'D') call AssertException(['source Xtest'], 'Vim(endtry):E602: :endtry without :try') " :endtry without :try @@ -3424,8 +3416,6 @@ func Test_nested_endtry_error() END call writefile(code, 'Xtest') call AssertException(['source Xtest'], 'Vim(endtry):E170: Missing :endwhile') - - call delete('Xtest') endfunc "------------------------------------------------------------------------------- @@ -5891,7 +5881,7 @@ func Test_discard_exception_after_error_ endtry call assert_report('should not get here') [CODE] - call writefile(lines, 'Xscript') + call writefile(lines, 'Xscript', 'D') breakadd file 7 Xscript try @@ -5906,7 +5896,6 @@ func Test_discard_exception_after_error_ call assert_equal(1, caught_intr) call assert_equal('ab', g:Xpath) breakdel * - call delete('Xscript') endfunc "------------------------------------------------------------------------------- @@ -5996,7 +5985,7 @@ func Test_ignore_catch_after_intr_1() endtry call assert_report('should not get here') [CODE] - call writefile(lines, 'Xscript') + call writefile(lines, 'Xscript', 'D') breakadd file 6 Xscript try @@ -6011,7 +6000,6 @@ func Test_ignore_catch_after_intr_1() call assert_equal(1, caught_intr) call assert_equal('a', g:Xpath) breakdel * - call delete('Xscript') endfunc " interrupt right before a catch is invoked inside a function. @@ -6104,7 +6092,7 @@ func Test_finally_after_intr() endtry call assert_report('should not get here') [CODE] - call writefile(lines, 'Xscript') + call writefile(lines, 'Xscript', 'D') breakadd file 7 Xscript try @@ -6119,7 +6107,6 @@ func Test_finally_after_intr() call assert_equal(1, caught_intr) call assert_equal('abc', g:Xpath) breakdel * - call delete('Xscript') endfunc "------------------------------------------------------------------------------- @@ -6963,13 +6950,12 @@ func Test_script_expand_sfile() endfunc let g:result = s:snr() END - call writefile(lines, 'Xexpand') + call writefile(lines, 'Xexpand', 'D') source Xexpand call assert_match('\d\+_snr', g:result) source Xexpand call assert_match('\d\+_snr', g:result) - call delete('Xexpand') unlet g:result endfunc @@ -7230,7 +7216,7 @@ endfunc " Test for missing :endif, :endfor, :endwhile and :endtry {{{1 func Test_missing_end() - call writefile(['if 2 > 1', 'echo ">"'], 'Xscript') + call writefile(['if 2 > 1', 'echo ">"'], 'Xscript', 'D') call assert_fails('source Xscript', 'E171:') call writefile(['for i in range(5)', 'echo i'], 'Xscript') call assert_fails('source Xscript', 'E170:') @@ -7238,7 +7224,6 @@ func Test_missing_end() call assert_fails('source Xscript', 'E170:') call writefile(['try', 'echo "."'], 'Xscript') call assert_fails('source Xscript', 'E600:') - call delete('Xscript') " Using endfor with :while let caught_e732 = 0 @@ -7320,7 +7305,7 @@ func Test_deep_nest() let @a = '' endfunc [SCRIPT] - call writefile(lines, 'Xscript') + call writefile(lines, 'Xscript', 'D') let buf = RunVimInTerminal('-S Xscript', {'rows': 6}) @@ -7358,7 +7343,6 @@ func Test_deep_nest() "call assert_report(l) call StopVimInTerminal(buf) - call delete('Xscript') endfunc " Test for errors in converting to float from various types {{{1 @@ -7429,9 +7413,8 @@ func Test_invalid_function_names() call assert_equal(1, exists('Bar')) call assert_equal(1, exists('*Bar')) END - call writefile(lines, 'Xscript') + call writefile(lines, 'Xscript', 'D') source Xscript - call delete('Xscript') endfunc " substring and variable name {{{1 @@ -7522,13 +7505,11 @@ func Test_deeply_nested_source() so 0 END - call writefile(["vim9 silent! @0 \n/"] + lines, 'Xnested.vim') + call writefile(["vim9 silent! @0 \n/"] + lines, 'Xnested.vim', 'D') " this must not crash let cmd = GetVimCommand() .. " -e -s -S Xnested.vim -c qa!" call system(cmd) - - call delete('Xnested.vim') endfunc "------------------------------------------------------------------------------- diff --git a/src/testdir/test_visual.vim b/src/testdir/test_visual.vim --- a/src/testdir/test_visual.vim +++ b/src/testdir/test_visual.vim @@ -1274,7 +1274,7 @@ func Test_visual_block_with_virtualedit( set virtualedit=block normal G END - call writefile(lines, 'XTest_block') + call writefile(lines, 'XTest_block', 'D') let buf = RunVimInTerminal('-S XTest_block', {'rows': 8, 'cols': 50}) call term_sendkeys(buf, "\gg$") @@ -1286,7 +1286,6 @@ func Test_visual_block_with_virtualedit( " clean up call term_sendkeys(buf, "\") call StopVimInTerminal(buf) - call delete('XTest_block') endfunc func Test_visual_block_ctrl_w_f() @@ -1331,11 +1330,10 @@ func Test_visual_reselect_with_count() : END - call writefile(lines, 'XvisualReselect') + call writefile(lines, 'XvisualReselect', 'D') source XvisualReselect bwipe! - call delete('XvisualReselect') endfunc func Test_visual_block_insert_round_off() diff --git a/src/version.c b/src/version.c --- a/src/version.c +++ b/src/version.c @@ -696,6 +696,8 @@ static char *(features[]) = static int included_patches[] = { /* Add new patch number below this line */ /**/ + 768, +/**/ 767, /**/ 766,