From 56564964e6d0956c29687e8a10cb94fe42f5c097 Mon Sep 17 00:00:00 2001 From: Bram Moolenaar Date: Mon, 10 Oct 2022 22:39:42 +0100 Subject: patch 9.0.0719: too many delete() calls in tests Problem: Too many delete() calls in tests. Solution: Use deferred delete where possible. --- src/testdir/test_startup.vim | 71 ++++++++++++++++---------------------------- 1 file changed, 26 insertions(+), 45 deletions(-) (limited to 'src/testdir/test_startup.vim') diff --git a/src/testdir/test_startup.vim b/src/testdir/test_startup.vim index 7995cd2e5b..6c2fbbd15d 100644 --- a/src/testdir/test_startup.vim +++ b/src/testdir/test_startup.vim @@ -43,14 +43,14 @@ func Test_after_comes_later() quit [CODE] - call mkdir('Xhere/plugin', 'p') + call mkdir('Xhere/plugin', 'pR') call writefile(['let g:sequence .= "here "'], 'Xhere/plugin/here.vim') - call mkdir('Xanother/plugin', 'p') + call mkdir('Xanother/plugin', 'pR') call writefile(['let g:sequence .= "another "'], 'Xanother/plugin/another.vim') call mkdir('Xhere/pack/foo/start/foobar/plugin', 'p') call writefile(['let g:sequence .= "pack "'], 'Xhere/pack/foo/start/foobar/plugin/foo.vim') - call mkdir('Xafter/plugin', 'p') + call mkdir('Xafter/plugin', 'pR') call writefile(['let g:sequence .= "after "'], 'Xafter/plugin/later.vim') if RunVim(before, after, '') @@ -72,9 +72,6 @@ func Test_after_comes_later() call delete('Xtestout') call delete('Xsequence') - call delete('Xhere', 'rf') - call delete('Xanother', 'rf') - call delete('Xafter', 'rf') endfunc func Test_pack_in_rtp_when_plugins_run() @@ -92,7 +89,7 @@ func Test_pack_in_rtp_when_plugins_run() let after = [ \ 'quit', \ ] - call mkdir('Xhere/plugin', 'p') + call mkdir('Xhere/plugin', 'pR') call writefile(['redir! > Xtestout', 'silent set runtimepath?', 'silent! call foo#Trigger()', 'redir END'], 'Xhere/plugin/here.vim') call mkdir('Xhere/pack/foo/start/foobar/autoload', 'p') call writefile(['function! foo#Trigger()', 'echo "autoloaded foo"', 'endfunction'], 'Xhere/pack/foo/start/foobar/autoload/foo.vim') @@ -105,7 +102,6 @@ func Test_pack_in_rtp_when_plugins_run() endif call delete('Xtestout') - call delete('Xhere', 'rf') endfunc func Test_help_arg() @@ -228,7 +224,6 @@ func Test_o_arg() call assert_equal('foo', bn1) call assert_equal('bar', bn2) endif - call delete('Xtestout') endfunc @@ -303,7 +298,7 @@ func Test_q_arg() return 666 } END - call writefile(lines, 'Xbadfile.c') + call writefile(lines, 'Xbadfile.c', 'D') let after =<< trim [CODE] call writefile([&errorfile, string(getpos("."))], "XtestoutQarg") @@ -314,7 +309,7 @@ func Test_q_arg() " Test with default argument '-q'. call assert_equal('errors.err', &errorfile) - call writefile(["Xbadfile.c:4:12: error: expected ';' before '}' token"], 'errors.err') + call writefile(["Xbadfile.c:4:12: error: expected ';' before '}' token"], 'errors.err', 'D') if RunVim([], after, '-q') let lines = readfile('XtestoutQarg') call assert_equal(['errors.err', @@ -323,10 +318,9 @@ func Test_q_arg() \ lines) endif call delete('XtestoutQarg') - call delete('errors.err') " Test with explicit argument '-q XerrorsQarg' (with space). - call writefile(["Xbadfile.c:4:12: error: expected ';' before '}' token"], 'XerrorsQarg') + call writefile(["Xbadfile.c:4:12: error: expected ';' before '}' token"], 'XerrorsQarg', 'D') if RunVim([], after, '-q XerrorsQarg') let lines = readfile('XtestoutQarg') call assert_equal(['XerrorsQarg', @@ -349,9 +343,7 @@ func Test_q_arg() let out = system(GetVimCommand() .. ' -q xyz.err') call assert_equal(3, v:shell_error) - call delete('Xbadfile.c') call delete('XtestoutQarg') - call delete('XerrorsQarg') endfunc " Test the -V[N]{filename} argument to set the 'verbose' option to N @@ -400,7 +392,7 @@ endfunc " Test the -A, -F and -H arguments (Arabic, Farsi and Hebrew modes). func Test_A_F_H_arg() let after =<< trim [CODE] - call writefile([&rightleft, &arabic, &fkmap, &hkmap], "Xtestout") + call writefile([&rightleft, &arabic, &fkmap, &hkmap], "Xtestout", 'D') qall [CODE] @@ -420,8 +412,6 @@ func Test_A_F_H_arg() let lines = readfile('Xtestout') call assert_equal(['1', '0', '0', '1'], lines) endif - - call delete('Xtestout') endfunc " Test the --echo-wid argument (for GTK GUI only). @@ -799,7 +789,7 @@ endfunc func Test_zzz_startinsert() " Test :startinsert - call writefile(['123456'], 'Xtestout') + call writefile(['123456'], 'Xtestout', 'D') let after =<< trim [CODE] :startinsert call feedkeys("foobar\:wq\","t") @@ -820,7 +810,6 @@ func Test_zzz_startinsert() let lines = readfile('Xtestout') call assert_equal(['123456foobar'], lines) endif - call delete('Xtestout') endfunc func Test_issue_3969() @@ -898,8 +887,8 @@ func Test_t_arg() \ "first\tXfile1\t/^ \\zsfirst$/", \ "second\tXfile1\t/^ \\zssecond$/", \ "third\tXfile1\t/^ \\zsthird$/"], - \ 'Xtags') - call writefile([' first', ' second', ' third'], 'Xfile1') + \ 'Xtags', 'D') + call writefile([' first', ' second', ' third'], 'Xfile1', 'D') for t_arg in ['-t second', '-tsecond'] if RunVim(before, after, t_arg) @@ -907,9 +896,6 @@ func Test_t_arg() call delete('Xtestout') endif endfor - - call delete('Xtags') - call delete('Xfile1') endfunc " Test the '-T' argument which sets the 'term' option. @@ -1006,7 +992,7 @@ func Test_missing_vimrc() call assert_match('^E282:', v:errmsg) call writefile(v:errors, 'Xtestout') [CODE] - call writefile(after, 'Xafter') + call writefile(after, 'Xafter', 'D') let cmd = GetVimCommandCleanTerm() . ' -u Xvimrc_missing -S Xafter' let buf = term_start(cmd, {'term_rows' : 10}) @@ -1017,7 +1003,7 @@ func Test_missing_vimrc() call WaitForAssert({-> assert_match(':', term_getline(buf, 10))}) call StopVimInTerminal(buf) call assert_equal([], readfile('Xtestout')) - call delete('Xafter') + call delete('Xtestout') endfunc @@ -1029,13 +1015,13 @@ func Test_VIMINIT() call writefile(v:errors, 'Xtestout') qall [CODE] - call writefile(after, 'Xafter') + call writefile(after, 'Xafter', 'D') let cmd = GetVimProg() . ' --not-a-term -S Xafter --cmd "set enc=utf8"' call setenv('VIMINIT', 'let viminit_found="yes"') exe "silent !" . cmd call assert_equal([], readfile('Xtestout')) + call delete('Xtestout') - call delete('Xafter') endfunc " Test for using the $EXINIT environment variable @@ -1046,13 +1032,13 @@ func Test_EXINIT() call writefile(v:errors, 'Xtestout') qall [CODE] - call writefile(after, 'Xafter') + call writefile(after, 'Xafter', 'D') let cmd = GetVimProg() . ' --not-a-term -S Xafter --cmd "set enc=utf8"' call setenv('EXINIT', 'let exinit_found="yes"') exe "silent !" . cmd call assert_equal([], readfile('Xtestout')) + call delete('Xtestout') - call delete('Xafter') endfunc " Test for using the 'exrc' option @@ -1064,13 +1050,12 @@ func Test_exrc() call writefile(v:errors, 'Xtestout') qall [CODE] - call mkdir('Xrcdir') + call mkdir('Xrcdir', 'R') call writefile(['let exrc_found=37'], 'Xrcdir/.exrc') call writefile(after, 'Xrcdir/Xafter') let cmd = GetVimProg() . ' --not-a-term -S Xafter --cmd "cd Xrcdir" --cmd "set enc=utf8 exrc secure"' exe "silent !" . cmd call assert_equal([], readfile('Xrcdir/Xtestout')) - call delete('Xrcdir', 'rf') endfunc " Test for starting Vim with a non-terminal as input/output @@ -1138,7 +1123,7 @@ func Test_w_arg() " Can't catch the output of gvim. CheckNotGui - call writefile(["iVim Editor\:q!\"], 'Xscriptin', 'b') + call writefile(["iVim Editor\:q!\"], 'Xscriptin', 'bD') if RunVim([], [], '-s Xscriptin -w Xscriptout') call assert_equal(["iVim Editor\e:q!\r"], readfile('Xscriptout')) call delete('Xscriptout') @@ -1162,7 +1147,6 @@ func Test_w_arg() call delete('Xresult') endif endfor - call delete('Xscriptin') endfunc " Test for the "-s scriptin" argument @@ -1174,10 +1158,9 @@ func Test_s_arg() let m = system(GetVimCommand() .. " -s abcxyz") call assert_equal("Cannot open for reading: \"abcxyz\"\n", m) - call writefile([], 'Xinput') + call writefile([], 'Xinput', 'D') let m = system(GetVimCommand() .. " -s Xinput -s Xinput") call assert_equal("Attempt to open script file again: \"-s Xinput\"\n", m) - call delete('Xinput') endfunc " Test for the "-n" (no swap file) argument @@ -1252,7 +1235,7 @@ endfunc func Test_progname() CheckUnix - call mkdir('Xprogname', 'p') + call mkdir('Xprogname', 'pD') call writefile(['silent !date', \ 'call writefile([mode(1), ' \ .. '&insertmode, &diff, &readonly, &updatecount, ' @@ -1324,12 +1307,11 @@ func Test_progname() endfor call delete('Xprogname_after') - call delete('Xprogname', 'd') endfunc " Test for doing a write from .vimrc func Test_write_in_vimrc() - call writefile(['silent! write'], 'Xvimrc') + call writefile(['silent! write'], 'Xvimrc', 'D') let after =<< trim [CODE] call assert_match('E32: ', v:errmsg) call writefile(v:errors, 'Xtestout') @@ -1339,7 +1321,6 @@ func Test_write_in_vimrc() call assert_equal([], readfile('Xtestout')) call delete('Xtestout') endif - call delete('Xvimrc') endfunc func Test_echo_true_in_cmd() @@ -1350,11 +1331,11 @@ func Test_echo_true_in_cmd() call writefile(['done'], 'Xresult') quit END - call writefile(lines, 'Xscript') + call writefile(lines, 'Xscript', 'D') if RunVim([], [], '--cmd "source Xscript"') call assert_equal(['done'], readfile('Xresult')) endif - call delete('Xscript') + call delete('Xresult') endfunc @@ -1365,11 +1346,11 @@ func Test_rename_buffer_on_startup() call writefile(['done'], 'Xresult') qa! END - call writefile(lines, 'Xscript') + call writefile(lines, 'Xscript', 'D') if RunVim([], [], "--clean -e -s --cmd 'file x|new|file x' --cmd 'so Xscript'") call assert_equal(['done'], readfile('Xresult')) endif - call delete('Xscript') + call delete('Xresult') endfunc -- cgit v1.2.3