changeset 30669:de319bf98a39 v9.0.0669

patch 9.0.0669: too many delete() calls in tests Commit: https://github.com/vim/vim/commit/db77cb3c08784e6038dd029271b2080c1b2d9acb Author: Bram Moolenaar <Bram@vim.org> Date: Wed Oct 5 21:45:30 2022 +0100 patch 9.0.0669: too many delete() calls in tests Problem: Too many delete() calls in tests. Solution: Use deferred delete where possible.
author Bram Moolenaar <Bram@vim.org>
date Wed, 05 Oct 2022 23:00:04 +0200
parents fc3a551afc3e
children 069c5155439b
files src/testdir/test_quickfix.vim src/testdir/test_recover.vim src/testdir/test_regexp_utf8.vim src/testdir/test_rename.vim src/testdir/test_restricted.vim src/version.c
diffstat 6 files changed, 80 insertions(+), 165 deletions(-) [+]
line wrap: on
line diff
--- a/src/testdir/test_quickfix.vim
+++ b/src/testdir/test_quickfix.vim
@@ -396,7 +396,7 @@ func XfileTests(cchar)
     Xtestfile1:700:10:Line 700
     Xtestfile2:800:15:Line 800
   END
-  call writefile(lines, 'Xqftestfile1')
+  call writefile(lines, 'Xqftestfile1', 'D')
 
   enew!
   Xfile Xqftestfile1
@@ -439,8 +439,6 @@ func XfileTests(cchar)
   call writefile([t], 'Xqftestfile1', 'b')
   silent! Xfile Xqftestfile1
   call assert_equal(text, g:Xgetlist()[0].text)
-
-  call delete('Xqftestfile1')
 endfunc
 
 func Test_cfile()
@@ -795,10 +793,9 @@ func Xnomem_tests(cchar)
   call assert_fails('Xbuffer', 'E342:')
   %bw!
 
-  call writefile([repeat('a', 8192)], 'Xtest')
+  call writefile([repeat('a', 8192)], 'Xtest', 'D')
   call test_alloc_fail(GetAllocId('qf_linebuf'), 0, 0)
   call assert_fails('Xfile Xtest', 'E342:')
-  call delete('Xtest')
 endfunc
 
 func Test_nomem()
@@ -899,7 +896,7 @@ def Test_helpgrep_vim9_restore_cpo()
   var rtp_save = &rtp
   var dir = 'Xruntime/after'
   &rtp ..= ',' .. dir
-  mkdir(dir .. '/ftplugin', 'p')
+  mkdir(dir .. '/ftplugin', 'pR')
   writefile(['vim9script'], dir .. '/ftplugin/qf.vim')
   filetype plugin on
   silent helpgrep grail
@@ -907,7 +904,6 @@ def Test_helpgrep_vim9_restore_cpo()
   silent helpgrep grail
 
   assert_equal('aABceFs', &cpo)
-  delete('Xruntime', 'rf')
   &rtp = rtp_save
   cclose
   helpclose
@@ -1180,8 +1176,8 @@ func Test_locationlist_curwin_was_closed
 endfunc
 
 func Test_locationlist_cross_tab_jump()
-  call writefile(['loclistfoo'], 'loclistfoo')
-  call writefile(['loclistbar'], 'loclistbar')
+  call writefile(['loclistfoo'], 'loclistfoo', 'D')
+  call writefile(['loclistbar'], 'loclistbar', 'D')
   set switchbuf=usetab
 
   edit loclistfoo
@@ -1191,8 +1187,6 @@ func Test_locationlist_cross_tab_jump()
 
   enew | only | tabonly
   set switchbuf&vim
-  call delete('loclistfoo')
-  call delete('loclistbar')
 endfunc
 
 " More tests for 'errorformat'
@@ -1237,8 +1231,9 @@ func Test_efm1()
     "Xtestfile", line 22 col 9: What is the title of the quickfix window?
   [DATA]
 
-  call writefile(l, 'Xerrorfile1')
-  call writefile(l[:-2], 'Xerrorfile2')
+  call writefile(l, 'Xerrorfile1', 'D')
+  call delete('loclistbar')
+  call writefile(l[:-2], 'Xerrorfile2', 'D')
 
   let m =<< [DATA]
 	xxxxxxxxxxxxxxxxxxxxxxxxxxxxxx    line  2
@@ -1263,7 +1258,7 @@ func Test_efm1()
 	xxxxxxxxxxxxxxxxxxxxxxxxxxxxxx    line 21
 	xxxxxxxxxxxxxxxxxxxxxxxxxxxxxx    line 22
 [DATA]
-  call writefile(m, 'Xtestfile')
+  call writefile(m, 'Xtestfile', 'D')
 
   let save_efm = &efm
   set efm+==%f=\\,\ line\ %l%*\\D%v%*[^\ ]\ %m
@@ -1309,9 +1304,6 @@ func Test_efm1()
   wincmd p
 
   let &efm = save_efm
-  call delete('Xerrorfile1')
-  call delete('Xerrorfile2')
-  call delete('Xtestfile')
 endfunc
 
 " Test for quickfix directory stack support
@@ -1363,11 +1355,11 @@ endfunc
 " Tests for %D and %X errorformat options
 func Test_efm_dirstack()
   " Create the directory stack and files
-  call mkdir('dir1')
+  call mkdir('dir1', 'R')
   call mkdir('dir1/a')
   call mkdir('dir1/a/b')
   call mkdir('dir1/c')
-  call mkdir('dir2')
+  call mkdir('dir2', 'R')
 
   let lines =<< trim END
     Nine Healthy Habits
@@ -1382,7 +1374,7 @@ func Test_efm_dirstack()
     8 Hours of sleep (at least)
     9 PM end of the day and off to bed
   END
-  call writefile(lines, 'habits1.txt')
+  call writefile(lines, 'habits1.txt', 'D')
   call writefile(lines, 'dir1/a/habits2.txt')
   call writefile(lines, 'dir1/a/b/habits3.txt')
   call writefile(lines, 'dir1/c/habits4.txt')
@@ -1390,10 +1382,6 @@ func Test_efm_dirstack()
 
   call s:dir_stack_tests('c')
   call s:dir_stack_tests('l')
-
-  call delete('dir1', 'rf')
-  call delete('dir2', 'rf')
-  call delete('habits1.txt')
 endfunc
 
 " Test for resync after continuing an ignored message
@@ -1518,9 +1506,9 @@ func Test_efm2()
   set efm=%+P[%f]%r,(%l\\,%c)%*[\ ]%t%*[^:]:\ %m,%+Q--%r
   " To exercise the push/pop file functionality in quickfix, the test files
   " need to be created.
-  call writefile(['Line1'], 'Xtestfile1')
-  call writefile(['Line2'], 'Xtestfile2')
-  call writefile(['Line3'], 'Xtestfile3')
+  call writefile(['Line1'], 'Xtestfile1', 'D')
+  call writefile(['Line2'], 'Xtestfile2', 'D')
+  call writefile(['Line3'], 'Xtestfile3', 'D')
   cexpr ""
   for l in lines
       caddexpr l
@@ -1531,9 +1519,6 @@ func Test_efm2()
   call assert_equal(2, l[2].col)
   call assert_equal('w', l[2].type)
   call assert_equal('e', l[3].type)
-  call delete('Xtestfile1')
-  call delete('Xtestfile2')
-  call delete('Xtestfile3')
 
   " Test for %P, %Q with non-existing files
   cexpr lines
@@ -1602,7 +1587,7 @@ func Test_efm2()
   " Test for %o
   set efm=%f(%o):%l\ %m
   cgetexpr ['Xotestfile(Language.PureScript.Types):20 Error']
-  call writefile(['Line1'], 'Xotestfile')
+  call writefile(['Line1'], 'Xotestfile', 'D')
   let l = getqflist()
   call assert_equal(1, len(l), string(l))
   call assert_equal('Language.PureScript.Types', l[0].module)
@@ -1612,7 +1597,6 @@ func Test_efm2()
   call assert_equal('Xotestfile', expand('%:t'))
   cclose
   bd
-  call delete("Xotestfile")
 
   " Test for a long module name
   cexpr 'Xtest(' . repeat('m', 1026) . '):15 message'
@@ -1776,7 +1760,7 @@ func Test_quickfix_was_changed_by_autocm
 endfunc
 
 func Test_setloclist_in_autocommand()
-  call writefile(['test1', 'test2'], 'Xfile')
+  call writefile(['test1', 'test2'], 'Xfile', 'D')
   edit Xfile
   let s:bufnr = bufnr()
   call setloclist(1,
@@ -1796,7 +1780,6 @@ func Test_setloclist_in_autocommand()
   augroup Test_LocList
     au!
   augroup END
-  call delete('Xfile')
 endfunc
 
 func Test_caddbuffer_to_empty()
@@ -2129,11 +2112,10 @@ func Test_cgetfile_on_long_lines()
       /tmp/file4:1:1:ccc
     END
     let lines[1] = substitute(lines[1], '%s', repeat('x', len), '')
-    call writefile(lines, 'Xcqetfile.txt')
+    call writefile(lines, 'Xcqetfile.txt', 'D')
     cgetfile Xcqetfile.txt
     call assert_equal(4, getqflist(#{size: v:true}).size, 'with length ' .. len)
   endfor
-  call delete('Xcqetfile.txt')
 endfunc
 
 func s:create_test_file(filename)
@@ -2274,7 +2256,7 @@ func Test_switchbuf()
   " If opening a file changes 'switchbuf', then the new value should be
   " retained.
   set modeline&vim
-  call writefile(["vim: switchbuf=split"], 'Xqftestfile1')
+  call writefile(["vim: switchbuf=split"], 'Xqftestfile1', 'D')
   enew | only
   set switchbuf&vim
   cexpr "Xqftestfile1:1:10"
@@ -2290,7 +2272,6 @@ func Test_switchbuf()
   cexpr "Xqftestfile1:1:10"
   call assert_equal('', &switchbuf)
 
-  call delete('Xqftestfile1')
   call delete('Xqftestfile2')
   call delete('Xqftestfile3')
   set switchbuf&vim
@@ -2385,8 +2366,8 @@ func Test_two_windows()
   " Use one 'errorformat' for two windows.  Add an expression to each of them,
   " make sure they each keep their own state.
   set efm=%DEntering\ dir\ '%f',%f:%l:%m,%XLeaving\ dir\ '%f'
-  call mkdir('Xone/a', 'p')
-  call mkdir('Xtwo/a', 'p')
+  call mkdir('Xone/a', 'pR')
+  call mkdir('Xtwo/a', 'pR')
   let lines = ['1', '2', 'one one one', '4', 'two two two', '6', '7']
   call writefile(lines, 'Xone/a/one.txt')
   call writefile(lines, 'Xtwo/a/two.txt')
@@ -2418,8 +2399,6 @@ func Test_two_windows()
   bwipe!
   call win_gotoid(two_id)
   bwipe!
-  call delete('Xone', 'rf')
-  call delete('Xtwo', 'rf')
 endfunc
 
 func XbottomTests(cchar)
@@ -2503,12 +2482,10 @@ func Test_duplicate_buf()
   let last_buffer = bufnr("$")
 
   " make sure only one buffer is created
-  call writefile(['this one', 'that one'], 'Xgrepthis')
+  call writefile(['this one', 'that one'], 'Xgrepthis', 'D')
   vimgrep one Xgrepthis
   vimgrep one Xgrepthis
   call assert_equal(last_buffer + 1, bufnr("$"))
-
-  call delete('Xgrepthis')
 endfunc
 
 " Quickfix/Location list set/get properties tests
@@ -2876,8 +2853,8 @@ func Test_Autocmd()
   END
   call assert_equal(l, g:acmds)
 
-  call writefile(['Xtest:1:Line1'], 'Xtest')
-  call writefile([], 'Xempty')
+  call writefile(['Xtest:1:Line1'], 'Xtest', 'D')
+  call writefile([], 'Xempty', 'D')
   let g:acmds = []
   cfile Xtest
   caddfile Xtest
@@ -2976,8 +2953,6 @@ func Test_Autocmd()
     call assert_equal(l, g:acmds)
   endif
 
-  call delete('Xtest')
-  call delete('Xempty')
   au! QuickFixCmdPre
   au! QuickFixCmdPost
 endfunc
@@ -3137,7 +3112,7 @@ func Test_cwindow_highlight()
     redraw
     cwindow 4
   END
-  call writefile(lines, 'XtestCwindow')
+  call writefile(lines, 'XtestCwindow', 'D')
   let buf = RunVimInTerminal('-S XtestCwindow', #{rows: 12})
   call VerifyScreenDump(buf, 'Test_quickfix_cwindow_1', {})
 
@@ -3152,7 +3127,6 @@ func Test_cwindow_highlight()
 
   " clean up
   call StopVimInTerminal(buf)
-  call delete('XtestCwindow')
   call delete('XCwindow')
 endfunc
 
@@ -3164,8 +3138,8 @@ func XvimgrepTests(cchar)
     Editor:Emacs EmAcS
     Editor:Notepad NOTEPAD
   END
-  call writefile(lines, 'Xtestfile1')
-  call writefile(['Linux', 'macOS', 'MS-Windows'], 'Xtestfile2')
+  call writefile(lines, 'Xtestfile1', 'D')
+  call writefile(['Linux', 'macOS', 'MS-Windows'], 'Xtestfile2', 'D')
 
   " Error cases
   call assert_fails('Xvimgrep /abc *', 'E682:')
@@ -3221,9 +3195,6 @@ func XvimgrepTests(cchar)
   augroup QF_Test
     au!
   augroup END
-
-  call delete('Xtestfile1')
-  call delete('Xtestfile2')
 endfunc
 
 " Tests for the :vimgrep command
@@ -3261,11 +3232,10 @@ func Test_vimgrep_with_no_last_search_pa
     call writefile(v:errors, 'Xresult')
     qall!
   [SCRIPT]
-  call writefile(lines, 'Xscript')
+  call writefile(lines, 'Xscript', 'D')
   if RunVim([], [], '--clean -S Xscript')
     call assert_equal([], readfile('Xresult'))
   endif
-  call delete('Xscript')
   call delete('Xresult')
 endfunc
 
@@ -3276,17 +3246,16 @@ func Test_vimgrep_without_swap_file()
     call writefile(['done'], 'Xresult')
     qall!
   [SCRIPT]
-  call writefile(lines, 'Xscript')
+  call writefile(lines, 'Xscript', 'D')
   if RunVim([], [], '--clean -n -S Xscript Xscript')
     call assert_equal(['done'], readfile('Xresult'))
   endif
-  call delete('Xscript')
   call delete('Xresult')
 endfunc
 
 func Test_vimgrep_existing_swapfile()
-  call writefile(['match apple with apple'], 'Xapple')
-  call writefile(['swapfile'], '.Xapple.swp')
+  call writefile(['match apple with apple'], 'Xapple', 'D')
+  call writefile(['swapfile'], '.Xapple.swp', 'D')
   let g:foundSwap = 0
   let g:ignoreSwapExists = 1
   augroup grep
@@ -3296,8 +3265,6 @@ func Test_vimgrep_existing_swapfile()
   call assert_equal(1, g:foundSwap)
   call assert_match('.Xapple.swo', swapname(''))
 
-  call delete('Xapple')
-  call delete('.Xapple.swp')
   augroup grep
     au! SwapExists
   augroup END
@@ -3638,8 +3605,8 @@ func Xmultidirstack_tests(cchar)
 endfunc
 
 func Test_multidirstack()
-  call mkdir('Xone/a', 'p')
-  call mkdir('Xtwo/a', 'p')
+  call mkdir('Xone/a', 'pR')
+  call mkdir('Xtwo/a', 'pR')
   let lines = ['1', '2', 'one one one', '4', 'two two two', '6', '7']
   call writefile(lines, 'Xone/a/one.txt')
   call writefile(lines, 'Xtwo/a/two.txt')
@@ -3650,8 +3617,6 @@ func Test_multidirstack()
   call Xmultidirstack_tests('l')
 
   let &efm = save_efm
-  call delete('Xone', 'rf')
-  call delete('Xtwo', 'rf')
 endfunc
 
 " Tests for per quickfix/location list file stack
@@ -3700,8 +3665,8 @@ endfunc
 
 func Test_multifilestack()
   let lines = ['1', '2', 'one one one', '4', 'two two two', '6', '7']
-  call writefile(lines, 'one.txt')
-  call writefile(lines, 'two.txt')
+  call writefile(lines, 'one.txt', 'D')
+  call writefile(lines, 'two.txt', 'D')
   let save_efm = &efm
   set efm=%+P[%f],(%l\\,%c)\ %m,%-Q
 
@@ -3709,14 +3674,12 @@ func Test_multifilestack()
   call Xmultifilestack_tests('l')
 
   let &efm = save_efm
-  call delete('one.txt')
-  call delete('two.txt')
 endfunc
 
 " Tests for per buffer 'efm' setting
 func Test_perbuf_efm()
-  call writefile(["File1-10-Line10"], 'one.txt')
-  call writefile(["File2#20#Line20"], 'two.txt')
+  call writefile(["File1-10-Line10"], 'one.txt', 'D')
+  call writefile(["File2#20#Line20"], 'two.txt', 'D')
   set efm=%f#%l#%m
   new | only
   new
@@ -3731,8 +3694,6 @@ func Test_perbuf_efm()
 
   set efm&
   new | only
-  call delete('one.txt')
-  call delete('two.txt')
 endfunc
 
 " Open multiple help windows using ":lhelpgrep
@@ -3908,9 +3869,9 @@ endfunc
 func Xqfjump_tests(cchar)
   call s:setup_commands(a:cchar)
 
-  call writefile(["Line1\tFoo", "Line2"], 'F1')
-  call writefile(["Line1\tBar", "Line2"], 'F2')
-  call writefile(["Line1\tBaz", "Line2"], 'F3')
+  call writefile(["Line1\tFoo", "Line2"], 'F1', 'D')
+  call writefile(["Line1\tBar", "Line2"], 'F2', 'D')
+  call writefile(["Line1\tBaz", "Line2"], 'F3', 'D')
 
   call g:Xsetlist([], 'f')
 
@@ -3999,10 +3960,6 @@ func Xqfjump_tests(cchar)
   " Cleanup
   enew!
   new | only
-
-  call delete('F1')
-  call delete('F2')
-  call delete('F3')
 endfunc
 
 func Test_qfjump()
@@ -4118,9 +4075,8 @@ func Test_empty_list_quickfixtextfunc()
       let &quickfixtextfunc = 's:Func'
       cgetfile [ex
   END
-  call writefile(lines, 'Xquickfixtextfunc')
+  call writefile(lines, 'Xquickfixtextfunc', 'D')
   call RunVim([], [], '-e -s -S Xquickfixtextfunc -c qa')
-  call delete('Xquickfixtextfunc')
 endfunc
 
 func Test_getqflist()
@@ -4173,7 +4129,7 @@ func Xqftick_tests(cchar)
 	      \ {'filename' : 'F7', 'lnum' : 11, 'text' : 'L11'}], 'r')
   call assert_equal(2, g:Xgetlist({'changedtick' : 0}).changedtick)
 
-  call writefile(["F8:80:L80", "F8:81:L81"], "Xone")
+  call writefile(["F8:80:L80", "F8:81:L81"], "Xone", 'D')
   Xfile Xone
   call assert_equal(1, g:Xgetlist({'changedtick' : 0}).changedtick)
   Xaddfile Xone
@@ -4186,8 +4142,6 @@ func Xqftick_tests(cchar)
   call g:Xsetlist([], 'a', {'nr' : 1, "lines" : ["F10:10:L10"]})
   call assert_equal(1, g:Xgetlist({'changedtick' : 0}).changedtick)
   call assert_equal(2, g:Xgetlist({'nr' : 1, 'changedtick' : 0}).changedtick)
-
-  call delete("Xone")
 endfunc
 
 func Test_qf_tick()
@@ -4341,8 +4295,8 @@ endfunc
 " :vimgrep/:lvimgrep commands are running.
 func Test_vimgrep_autocmd()
   call setqflist([], 'f')
-  call writefile(['stars'], 'Xtest1.txt')
-  call writefile(['stars'], 'Xtest2.txt')
+  call writefile(['stars'], 'Xtest1.txt', 'D')
+  call writefile(['stars'], 'Xtest2.txt', 'D')
 
   " Test 1:
   " When searching for a pattern using :vimgrep, if the quickfix list is
@@ -4373,8 +4327,6 @@ func Test_vimgrep_autocmd()
   call assert_fails('lvimgrep stars Xtest*.txt', 'E926:')
   au! BufRead Xtest2.txt
 
-  call delete('Xtest1.txt')
-  call delete('Xtest2.txt')
   call setqflist([], 'f')
 endfunc
 
@@ -4403,14 +4355,13 @@ func Xvimgrep_autocmd_cd(cchar)
 endfunc
 
 func Test_vimgrep_autocmd_cd()
-  call mkdir('Xgrepdir/a', 'p')
-  call mkdir('Xgrepdir/b', 'p')
+  call mkdir('Xgrepdir/a', 'pR')
+  call mkdir('Xgrepdir/b', 'pR')
   call writefile(['a_L1_vim', 'a_L2_vim'], 'Xgrepdir/a/f1.txt')
   call writefile(['b_L1_vim', 'b_L2_vim'], 'Xgrepdir/b/f2.txt')
   call Xvimgrep_autocmd_cd('c')
   call Xvimgrep_autocmd_cd('l')
   %bwipe
-  call delete('Xgrepdir', 'rf')
 endfunc
 
 " The following test used to crash Vim
@@ -4539,7 +4490,7 @@ endfunc
 " Otherwise due to indentation, the title is set with spaces at the beginning
 " of the command.
 func Test_qftitle()
-  call writefile(["F1:1:Line1"], 'Xerr')
+  call writefile(["F1:1:Line1"], 'Xerr', 'D')
 
   " :cexpr
   exe "cexpr readfile('Xerr')"
@@ -4617,7 +4568,6 @@ func Test_qftitle()
   call assert_equal(':setqflist()', getqflist({'title' : 1}).title)
 
   close
-  call delete('Xerr')
 
   call setqflist([], ' ', {'title' : 'Errors'})
   copen
@@ -4700,7 +4650,7 @@ func Xjumpto_first_error_test(cchar)
 
   " Test for cfile/lfile
   enew
-  call writefile(l, 'Xerr')
+  call writefile(l, 'Xerr', 'D')
   Xfile Xerr
   call assert_equal('Xtestfile1', @%)
   call assert_equal(2, line('.'))
@@ -4711,7 +4661,6 @@ func Xjumpto_first_error_test(cchar)
   call assert_equal('Xtestfile1', @%)
   call assert_equal(2, line('.'))
 
-  call delete('Xerr')
   call delete('Xtestfile1')
   call delete('Xtestfile2')
 endfunc
@@ -4731,7 +4680,7 @@ func Xautocmd_changelist(cchar)
   call s:create_test_file('Xtestfile2')
   Xexpr 'Xtestfile1:2:Line2'
   autocmd QuickFixCmdPost * Xolder
-  call writefile(['Xtestfile2:4:Line4'], 'Xerr')
+  call writefile(['Xtestfile2:4:Line4'], 'Xerr', 'D')
   Xfile Xerr
   call assert_equal('Xtestfile2', @%)
   call assert_equal(4, line('.'))
@@ -4802,7 +4751,6 @@ func Xautocmd_changelist(cchar)
   call assert_fails('silent Xvimgrep Line5 Xtestfile2', 'E480:')
   autocmd! QuickFixCmdPost
 
-  call delete('Xerr')
   call delete('Xtestfile1')
   call delete('Xtestfile2')
 endfunc
@@ -4919,7 +4867,7 @@ endfunc
 " Test for parsing entries using visual screen column
 func Test_viscol()
   enew
-  call writefile(["Col1\tCol2\tCol3"], 'Xfile1')
+  call writefile(["Col1\tCol2\tCol3"], 'Xfile1', 'D')
   edit Xfile1
 
   " Use byte offset for column number
@@ -4984,7 +4932,6 @@ func Test_viscol()
 
   enew | only
   set efm&
-  call delete('Xfile1')
 endfunc
 
 " Test for the quickfix window buffer
@@ -5101,14 +5048,13 @@ endfunc
 " a normal buffer.
 func Test_empty_qfbuf()
   enew | only
-  call writefile(["Test"], 'Xfile1')
+  call writefile(["Test"], 'Xfile1', 'D')
   call setqflist([], 'f')
   copen | only
   let qfbuf = bufnr('')
   edit Xfile1
   call assert_notequal(qfbuf, bufnr(''))
   enew
-  call delete('Xfile1')
 endfunc
 
 " Test for the :cbelow, :cabove, :lbelow and :labove commands.
@@ -5341,7 +5287,7 @@ func Xtest_qfcmd_abort(cchar)
   call assert_equal(0, g:Xgetlist({'nr' : '$'}).nr)
 
   " cfile/lfile
-  call writefile(["F1:10:Line10", "F2:20:Line20"], 'Xfile1')
+  call writefile(["F1:10:Line10", "F2:20:Line20"], 'Xfile1', 'D')
   let e = ''
   try
     Xfile Xfile1
@@ -5350,7 +5296,6 @@ func Xtest_qfcmd_abort(cchar)
   endtry
   call assert_equal('AbortCmd', e)
   call assert_equal(0, g:Xgetlist({'nr' : '$'}).nr)
-  call delete('Xfile1')
 
   " cgetbuffer/lgetbuffer
   enew!
@@ -5414,7 +5359,7 @@ endfunc
 
 " Test for using a file in one of the parent directories.
 func Test_search_in_dirstack()
-  call mkdir('Xtestdir/a/b/c', 'p')
+  call mkdir('Xtestdir/a/b/c', 'pR')
   let save_cwd = getcwd()
   call writefile(["X1_L1", "X1_L2"], 'Xtestdir/Xfile1')
   call writefile(["X2_L1", "X2_L2"], 'Xtestdir/a/Xfile2')
@@ -5451,7 +5396,6 @@ func Test_search_in_dirstack()
 
   set efm&
   exe 'cd ' . save_cwd
-  call delete('Xtestdir', 'rf')
 endfunc
 
 " Test for :cquit
@@ -5895,7 +5839,7 @@ endfunc
 " Running :lhelpgrep command more than once in a help window, doesn't jump to
 " the help topic
 func Test_lhelpgrep_from_help_window()
-  call mkdir('Xtestdir/doc', 'p')
+  call mkdir('Xtestdir/doc', 'pR')
   call writefile(['window'], 'Xtestdir/doc/a.txt')
   call writefile(['buffer'], 'Xtestdir/doc/b.txt')
   let save_rtp = &rtp
@@ -5906,7 +5850,6 @@ func Test_lhelpgrep_from_help_window()
   lhelpgrep window
   call assert_equal('a.txt', fnamemodify(@%, ":p:t"))
   let &rtp = save_rtp
-  call delete('Xtestdir', 'rf')
   new | only!
 endfunc
 
@@ -5993,7 +5936,7 @@ func Test_quickfix_window_fails_to_open(
         anything
       endtry
   END
-  call writefile(lines, 'XquickfixFails')
+  call writefile(lines, 'XquickfixFails', 'D')
 
   let lines =<< trim END
       split XquickfixFails
@@ -6004,7 +5947,7 @@ func Test_quickfix_window_fails_to_open(
       " is aborted but the window was already split.
       silent! cwindow
   END
-  call writefile(lines, 'XtestWinFails')
+  call writefile(lines, 'XtestWinFails', 'D')
   let buf = RunVimInTerminal('-S XtestWinFails', #{rows: 13})
   call VerifyScreenDump(buf, 'Test_quickfix_window_fails', {})
 
@@ -6012,8 +5955,6 @@ func Test_quickfix_window_fails_to_open(
   call term_sendkeys(buf, ":bwipe!\<CR>")
   call term_wait(buf)
   call StopVimInTerminal(buf)
-  call delete('XtestWinFails')
-  call delete('XquickfixFails')
 endfunc
 
 " Test for updating the quickfix buffer whenever the associated quickfix list
@@ -6076,11 +6017,10 @@ endfunc
 
 func Test_vimgrep_noswapfile()
   set noswapfile
-  call writefile(['one', 'two', 'three'], 'Xgreppie')
+  call writefile(['one', 'two', 'three'], 'Xgreppie', 'D')
   vimgrep two Xgreppie
   call assert_equal('two', getline('.'))
 
-  call delete('Xgreppie')
   set swapfile
 endfunc
 
@@ -6122,12 +6062,10 @@ func Xvimgrep_fuzzy_match(cchar)
 endfunc
 
 func Test_vimgrep_fuzzy_match()
-  call writefile(['one two three', 'aaaaaa'], 'Xfile1')
-  call writefile(['one', 'three one two', 'two', 'aaathreeaaa'], 'Xfile2')
+  call writefile(['one two three', 'aaaaaa'], 'Xfile1', 'D')
+  call writefile(['one', 'three one two', 'two', 'aaathreeaaa'], 'Xfile2', 'D')
   call Xvimgrep_fuzzy_match('c')
   call Xvimgrep_fuzzy_match('l')
-  call delete('Xfile1')
-  call delete('Xfile2')
 endfunc
 
 func Test_locationlist_open_in_newtab()
@@ -6265,12 +6203,11 @@ func Test_lopen_bwipe_all()
     call writefile(['done'], 'Xresult')
     qall!
   END
-  call writefile(lines, 'Xscript')
+  call writefile(lines, 'Xscript', 'D')
   if RunVim([], [], '-u NONE -n -X -Z -e -m -s -S Xscript')
     call assert_equal(['done'], readfile('Xresult'))
   endif
 
-  call delete('Xscript')
   call delete('Xresult')
 endfunc
 
--- a/src/testdir/test_recover.vim
+++ b/src/testdir/test_recover.vim
@@ -140,9 +140,9 @@ func Test_recover_multiple_swap_files()
   call setline(1, ['a', 'b', 'c'])
   preserve
   let b = readblob(swapname(''))
-  call writefile(b, '.Xfile1.swm')
-  call writefile(b, '.Xfile1.swn')
-  call writefile(b, '.Xfile1.swo')
+  call writefile(b, '.Xfile1.swm', 'D')
+  call writefile(b, '.Xfile1.swn', 'D')
+  call writefile(b, '.Xfile1.swo', 'D')
   %bw!
   call feedkeys(":recover Xfile1\<CR>3\<CR>q", 'xt')
   call assert_equal(['a', 'b', 'c'], getline(1, '$'))
@@ -156,16 +156,12 @@ func Test_recover_multiple_swap_files()
   call assert_equal('Xfile1', @%)
   call assert_equal([''], getline(1, '$'))
   bw!
-
-  call delete('.Xfile1.swm')
-  call delete('.Xfile1.swn')
-  call delete('.Xfile1.swo')
 endfunc
 
 " Test for :recover using an empty swap file
 func Test_recover_empty_swap_file()
   CheckUnix
-  call writefile([], '.Xfile1.swp')
+  call writefile([], '.Xfile1.swp', 'D')
   let msg = execute('recover Xfile1')
   call assert_match('Unable to read block 0 from .Xfile1.swp', msg)
   call assert_equal('Xfile1', @%)
@@ -178,7 +174,6 @@ func Test_recover_empty_swap_file()
 
   " :recover from an empty buffer
   call assert_fails('recover', 'E305:')
-  call delete('.Xfile1.swp')
 endfunc
 
 " Test for :recover using a corrupted swap file
@@ -366,11 +361,10 @@ func Test_recover_unreadable_swap_file()
   CheckNotRoot
   new Xfile1
   let b = readblob('.Xfile1.swp')
-  call writefile(b, '.Xfile1.swm')
+  call writefile(b, '.Xfile1.swm', 'D')
   bw!
   call setfperm('.Xfile1.swm', '-w-------')
   call assert_fails('recover Xfile1', 'E306:')
-  call delete('.Xfile1.swm')
 endfunc
 
 " Test for using :recover when the original file and the swap file have the
@@ -382,20 +376,19 @@ func Test_recover_unmodified_file()
   preserve
   let b = readblob('.Xfile1.swp')
   %bw!
-  call writefile(b, '.Xfile1.swz')
+  call writefile(b, '.Xfile1.swz', 'D')
   let msg = execute('recover Xfile1')
   call assert_equal(['aaa', 'bbb', 'ccc'], getline(1, '$'))
   call assert_false(&modified)
   call assert_match('Buffer contents equals file contents', msg)
   bw!
   call delete('Xfile1')
-  call delete('.Xfile1.swz')
 endfunc
 
 " Test for recovering a file when editing a symbolically linked file
 func Test_recover_symbolic_link()
   CheckUnix
-  call writefile(['aaa', 'bbb', 'ccc'], 'Xfile1')
+  call writefile(['aaa', 'bbb', 'ccc'], 'Xfile1', 'D')
   silent !ln -s Xfile1 Xfile2
   edit Xfile2
   call assert_equal('.Xfile1.swp', fnamemodify(swapname(''), ':t'))
@@ -410,7 +403,6 @@ func Test_recover_symbolic_link()
   update
   %bw!
   call assert_equal(['aaa', 'bbb', 'ccc'], readfile('Xfile1'))
-  call delete('Xfile1')
   call delete('Xfile2')
   call delete('.Xfile1.swp')
 endfunc
@@ -419,7 +411,7 @@ endfunc
 " line. This used to result in an internal error (E315) which is fixed
 " by 8.2.2966.
 func Test_recover_invalid_cursor_pos()
-  call writefile([], 'Xfile1')
+  call writefile([], 'Xfile1', 'D')
   edit Xfile1
   preserve
   let b = readblob('.Xfile1.swp')
@@ -429,7 +421,7 @@ func Test_recover_invalid_cursor_pos()
     au BufReadPost Xfile1 normal! 3G
   augroup END
   call writefile(range(1, 3), 'Xfile1')
-  call writefile(b, '.Xfile1.swp')
+  call writefile(b, '.Xfile1.swp', 'D')
   try
     recover Xfile1
   catch /E308:/
@@ -441,8 +433,6 @@ func Test_recover_invalid_cursor_pos()
     au!
   augroup END
   augroup! Test
-  call delete('Xfile1')
-  call delete('.Xfile1.swp')
 endfunc
 
 " Test for recovering a buffer without a name
@@ -453,10 +443,9 @@ func Test_noname_buffer()
   let sn = swapname('')
   let b = readblob(sn)
   bw!
-  call writefile(b, sn)
+  call writefile(b, sn, 'D')
   exe "recover " .. sn
   call assert_equal(['one', 'two'], getline(1, '$'))
-  call delete(sn)
 endfunc
 
 " vim: shiftwidth=2 sts=2 expandtab
--- a/src/testdir/test_regexp_utf8.vim
+++ b/src/testdir/test_regexp_utf8.vim
@@ -555,20 +555,17 @@ func Test_match_char_class_upper()
 endfunc
 
 func Test_match_invalid_byte()
-  call writefile(0z630a.765d30aa0a.2e0a.790a.4030, 'Xinvalid')
+  call writefile(0z630a.765d30aa0a.2e0a.790a.4030, 'Xinvalid', 'D')
   new
   source Xinvalid
   bwipe!
-  call delete('Xinvalid')
 endfunc
 
 func Test_match_illegal_byte()
   " Text has illegal bytes which need to be set explicitly
   let lines = ["norm :set no\x01\<CR>", "silent n\xff", "silent norm :b\xff\<CR>"]
-  call writefile(lines, 'Xregexp')
+  call writefile(lines, 'Xregexp', 'D')
   call system(GetVimCommand() .. ' -X -Z -e -s -S Xregexp -c qa!')
-
-  call delete('Xregexp')
 endfunc
 
 func Test_match_too_complicated()
--- a/src/testdir/test_rename.vim
+++ b/src/testdir/test_rename.vim
@@ -12,7 +12,7 @@ func Test_rename_file_to_file()
 
   " When the destination file already exists, it should be overwritten.
   call writefile(['foo'], 'Xrename1')
-  call writefile(['bar'], 'Xrename2')
+  call writefile(['bar'], 'Xrename2', 'D')
 
   call assert_equal(0, rename('Xrename1', 'Xrename2'))
   call assert_equal('', glob('Xrename1'))
@@ -36,7 +36,7 @@ func Test_rename_file_ignore_case()
 endfunc
 
 func Test_rename_same_file()
-  call writefile(['foo'], 'Xrename')
+  call writefile(['foo'], 'Xrename', 'D')
 
   " When the source and destination are the same file, nothing
   " should be done. The source file should not be deleted.
@@ -45,8 +45,6 @@ func Test_rename_same_file()
 
   call assert_equal(0, rename('./Xrename', 'Xrename'))
   call assert_equal(['foo'], readfile('Xrename'))
-
-  call delete('Xrename')
 endfunc
 
 func Test_rename_dir_to_dir()
@@ -63,21 +61,18 @@ func Test_rename_dir_to_dir()
 endfunc
 
 func Test_rename_same_dir()
-  call mkdir('Xrenamedir')
+  call mkdir('Xrenamedir', 'R')
   call writefile(['foo'], 'Xrenamedir/Xrenamefile')
 
   call assert_equal(0, rename('Xrenamedir', 'Xrenamedir'))
 
   call assert_equal(['foo'], readfile('Xrenamedir/Xrenamefile'))
-
-  call delete('Xrenamedir/Xrenamefile')
-  call delete('Xrenamedir', 'd')
 endfunc
 
 func Test_rename_copy()
   " Check that when original file can't be deleted, rename()
   " still succeeds but copies the file.
-  call mkdir('Xrenamedir')
+  call mkdir('Xrenamedir', 'R')
   call writefile(['foo'], 'Xrenamedir/Xrenamefile')
   call setfperm('Xrenamedir', 'r-xr-xr-x')
 
@@ -91,13 +86,11 @@ func Test_rename_copy()
   call assert_equal(['foo'], readfile('Xrenamefile'))
 
   call setfperm('Xrenamedir', 'rwxrwxrwx')
-  call delete('Xrenamedir/Xrenamefile')
-  call delete('Xrenamedir', 'd')
   call delete('Xrenamefile')
 endfunc
 
 func Test_rename_fails()
-  call writefile(['foo'], 'Xrenamefile')
+  call writefile(['foo'], 'Xrenamefile', 'D')
 
   " Can't rename into a non-existing directory.
   call assert_notequal(0, rename('Xrenamefile', 'Xdoesnotexist/Xrenamefile'))
@@ -115,8 +108,6 @@ func Test_rename_fails()
 
   call assert_fails('call rename("Xrenamefile", [])', 'E730:')
   call assert_fails('call rename(0z, "Xrenamefile")', 'E976:')
-
-  call delete('Xrenamefile')
 endfunc
 
 " vim: shiftwidth=2 sts=2 expandtab
--- a/src/testdir/test_restricted.vim
+++ b/src/testdir/test_restricted.vim
@@ -101,7 +101,7 @@ func Test_restricted_mode()
     call writefile(v:errors, 'Xresult')
     qa!
   END
-  call writefile(lines, 'Xrestricted')
+  call writefile(lines, 'Xrestricted', 'D')
   if RunVim([], [], '-Z --clean -S Xrestricted')
     call assert_equal([], readfile('Xresult'))
   endif
@@ -114,7 +114,6 @@ func Test_restricted_mode()
     call assert_equal([], readfile('Xresult'))
   endif
 
-  call delete('Xrestricted')
   call delete('Xresult')
 endfunc
 
--- a/src/version.c
+++ b/src/version.c
@@ -700,6 +700,8 @@ static char *(features[]) =
 static int included_patches[] =
 {   /* Add new patch number below this line */
 /**/
+    669,
+/**/
     668,
 /**/
     667,