changeset 30863:b4b51e01dd36 v9.0.0766

patch 9.0.0766: too many delete() calls in tests Commit: https://github.com/vim/vim/commit/0e9bdad545e8e75b23c40e44cc6ec51330f5b465 Author: Bram Moolenaar <Bram@vim.org> Date: Sat Oct 15 20:06:33 2022 +0100 patch 9.0.0766: 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 Sat, 15 Oct 2022 21:15:03 +0200
parents 2040ac6761ba
children 51906709cb7a
files src/testdir/test_vim9_assign.vim src/testdir/test_vim9_builtin.vim src/testdir/test_vim9_cmd.vim src/testdir/test_vim9_disassemble.vim src/testdir/test_vim9_expr.vim src/testdir/test_vim9_import.vim src/version.c
diffstat 7 files changed, 158 insertions(+), 289 deletions(-) [+]
line wrap: on
line diff
--- a/src/testdir/test_vim9_assign.vim
+++ b/src/testdir/test_vim9_assign.vim
@@ -921,9 +921,8 @@ def Test_vim9_single_char_vars()
       assert_equal(333, v)
       assert_equal(444, w)
   END
-  writefile(lines, 'Xsinglechar')
+  writefile(lines, 'Xsinglechar', 'D')
   source Xsinglechar
-  delete('Xsinglechar')
 enddef
 
 def Test_assignment_list()
@@ -1940,13 +1939,12 @@ def Test_var_func_call()
     # env var is always a string
     var env = $TERM
   END
-  writefile(lines, 'Xfinished')
+  writefile(lines, 'Xfinished', 'D')
   source Xfinished
   # GetValue() is not called during discovery phase
   assert_equal(1, g:count)
 
   unlet g:count
-  delete('Xfinished')
 enddef
 
 def Test_var_missing_type()
@@ -2532,7 +2530,7 @@ def Test_unlet()
    'DelChangedtick(b:)',
    ], 'E795:')
 
-  writefile(['vim9script', 'export var svar = 1234'], 'XunletExport.vim')
+  writefile(['vim9script', 'export var svar = 1234'], 'XunletExport.vim', 'D')
   var lines =<< trim END
     vim9script
     import './XunletExport.vim' as exp
@@ -2542,7 +2540,6 @@ def Test_unlet()
     defcompile
   END
   v9.CheckScriptFailure(lines, 'E1260:', 1)
-  delete('XunletExport.vim')
 
   $ENVVAR = 'foobar'
   assert_equal('foobar', $ENVVAR)
@@ -2701,11 +2698,9 @@ def Test_abort_after_error()
       var x: string
       x = strpart(1, 2)
   END
-  writefile(lines, 'Xtestscript')
+  writefile(lines, 'Xtestscript', 'D')
   var expected = 'E1174: String required for argument 1'
   assert_fails('so Xtestscript', [expected, expected], 3)
-
-  delete('Xtestscript')
 enddef
 
 def Test_using_s_var_in_function()
--- a/src/testdir/test_vim9_builtin.vim
+++ b/src/testdir/test_vim9_builtin.vim
@@ -12,7 +12,7 @@ func Test_internalfunc_arg_error()
     enddef
     defcompile
   END
-  call writefile(l, 'Xinvalidarg')
+  call writefile(l, 'Xinvalidarg', 'D')
   call assert_fails('so Xinvalidarg', 'E118:', '', 1, 'FArgErr')
   let l =<< trim END
     def! FArgErr(): float
@@ -22,7 +22,6 @@ func Test_internalfunc_arg_error()
   END
   call writefile(l, 'Xinvalidarg')
   call assert_fails('so Xinvalidarg', 'E119:', '', 1, 'FArgErr')
-  call delete('Xinvalidarg')
 endfunc
 
 " Test for builtin functions returning different types
@@ -52,7 +51,7 @@ func Test_InternalFuncRetType()
       return environ()
     enddef
   END
-  call writefile(lines, 'Xscript')
+  call writefile(lines, 'Xscript', 'D')
   source Xscript
 
   call RetFloat()->assert_equal(2.0)
@@ -61,7 +60,6 @@ func Test_InternalFuncRetType()
   call RetListDictAny()->assert_notequal([])
   call RetDictNumber()->assert_notequal({})
   call RetDictString()->assert_notequal({})
-  call delete('Xscript')
 endfunc
 
 def Test_abs()
@@ -1984,7 +1982,7 @@ def Test_getscriptinfo()
     def g:Xscript_def_func2()
     enddef
   END
-  writefile(lines1, 'X22script92')
+  writefile(lines1, 'X22script92', 'D')
 
   var lines2 =<< trim END
     source X22script92
@@ -2006,7 +2004,6 @@ def Test_getscriptinfo()
     endfor
   END
   v9.CheckDefAndScriptSuccess(lines2)
-  delete('X22script92')
 enddef
 
 def Test_gettabinfo()
@@ -3238,7 +3235,7 @@ enddef
 
 def Test_readblob()
   var blob = 0z12341234
-  writefile(blob, 'Xreadblob')
+  writefile(blob, 'Xreadblob', 'D')
   var read: blob = readblob('Xreadblob')
   assert_equal(blob, read)
 
@@ -3247,12 +3244,11 @@ def Test_readblob()
   END
   v9.CheckDefAndScriptFailure(lines, 'E1012: Type mismatch; expected list<string> but got blob', 1)
   v9.CheckDefExecAndScriptFailure(['readblob("")'], 'E484: Can''t open file <empty>')
-  delete('Xreadblob')
 enddef
 
 def Test_readfile()
   var text = ['aaa', 'bbb', 'ccc']
-  writefile(text, 'Xreadfile')
+  writefile(text, 'Xreadfile', 'D')
   var read: list<string> = readfile('Xreadfile')
   assert_equal(text, read)
   assert_equal([7, 7, 7], readfile('Xreadfile')->map((_, _) => 7))
@@ -3261,7 +3257,6 @@ def Test_readfile()
       var read: dict<string> = readfile('Xreadfile')
   END
   v9.CheckDefAndScriptFailure(lines, 'E1012: Type mismatch; expected dict<string> but got list<string>', 1)
-  delete('Xreadfile')
 
   v9.CheckDefAndScriptFailure(['readfile("a", 0z10)'], ['E1013: Argument 2: type mismatch, expected string but got blob', 'E1174: String required for argument 2'])
   v9.CheckDefAndScriptFailure(['readfile("a", "b", "c")'], ['E1013: Argument 3: type mismatch, expected number but got string', 'E1210: Number required for argument 3'])
@@ -4131,9 +4126,8 @@ def Test_sort_compare_func_fails()
     vim9script
     echo ['a', 'b', 'c']->sort((a: number, b: number) => 0)
   END
-  writefile(lines, 'Xbadsort')
+  writefile(lines, 'Xbadsort', 'D')
   assert_fails('source Xbadsort', ['E1013:', 'E702:'])
-  delete('Xbadsort')
 
   lines =<< trim END
       var l = [1, 2, 3]
@@ -4822,7 +4816,7 @@ func Test_win_gotoid_in_mapping()
 	  call feedkeys("\<F3>\<LeftMouse>\<LeftRelease>", "xt")
         endfunc
     END
-    call writefile(lines, 'Xgotoscript')
+    call writefile(lines, 'Xgotoscript', 'D')
     let buf = RunVimInTerminal('-S Xgotoscript', #{rows: 15, wait_for_ruler: 0})
     " wait longer here, since we didn't wait for the ruler
     call VerifyScreenDump(buf, 'Test_win_gotoid_1', #{wait: 3000})
@@ -4833,7 +4827,6 @@ func Test_win_gotoid_in_mapping()
     call VerifyScreenDump(buf, 'Test_win_gotoid_3', {})
 
     call StopVimInTerminal(buf)
-    call delete('Xgotoscript')
   endif
 endfunc
 
--- a/src/testdir/test_vim9_cmd.vim
+++ b/src/testdir/test_vim9_cmd.vim
@@ -120,12 +120,11 @@ def Test_cmdmod_execute()
       vim9script
       export var exported = 'x'
   END
-  writefile(lines, 'Xvim9import.vim')
+  writefile(lines, 'Xvim9import.vim', 'D')
   lines =<< trim END
       legacy exe "import './Xvim9import.vim'"
   END
   v9.CheckScriptSuccess(lines)
-  delete('Xvim9import.vim')
 
   # "legacy" does not aply to a called function
   lines =<< trim END
@@ -331,7 +330,7 @@ def Test_hardcopy_wildcards()
 enddef
 
 def Test_syn_include_wildcards()
-  writefile(['syn keyword Found found'], 'Xthemine.vim')
+  writefile(['syn keyword Found found'], 'Xthemine.vim', 'D')
   var save_rtp = &rtp
   &rtp = '.'
 
@@ -340,7 +339,6 @@ def Test_syn_include_wildcards()
   assert_match('Found.* contained found', execute('syn list Found'))
 
   &rtp = save_rtp
-  delete('Xthemine.vim')
 enddef
 
 def Test_echo_linebreak()
@@ -932,7 +930,7 @@ func Test_command_modifier_confirm()
       confirm write Xcmodfile
     enddef
   END
-  call writefile(lines, 'Xconfirmscript')
+  call writefile(lines, 'Xconfirmscript', 'D')
   call writefile(['empty'], 'Xcmodfile')
   let buf = RunVimInTerminal('-S Xconfirmscript', {'rows': 8})
   call term_sendkeys(buf, ":call Getout()\n")
@@ -946,7 +944,6 @@ func Test_command_modifier_confirm()
   call assert_equal(['changed'], readfile('Xcmodfile'))
   call delete('Xcmodfile')
   call delete('.Xcmodfile.swp')  " in case Vim was killed
-  call delete('Xconfirmscript')
 endfunc
 
 def Test_command_modifiers_keep()
--- a/src/testdir/test_vim9_disassemble.vim
+++ b/src/testdir/test_vim9_disassemble.vim
@@ -313,7 +313,7 @@ def s:ScriptFuncPush()
 enddef
 
 def Test_disassemble_push()
-  mkdir('Xdisdir/autoload', 'p')
+  mkdir('Xdisdir/autoload', 'pR')
   var save_rtp = &rtp
   exe 'set rtp^=' .. getcwd() .. '/Xdisdir'
 
@@ -340,12 +340,11 @@ def Test_disassemble_push()
   END
   v9.CheckScriptSuccess(lines)
 
-  delete('Xdisdir', 'rf')
   &rtp = save_rtp
 enddef
 
 def Test_disassemble_import_autoload()
-  writefile(['vim9script'], 'XimportAL.vim')
+  writefile(['vim9script'], 'XimportAL.vim', 'D')
 
   var lines =<< trim END
       vim9script
@@ -380,8 +379,6 @@ def Test_disassemble_import_autoload()
             res)
   END
   v9.CheckScriptSuccess(lines)
-
-  delete('XimportAL.vim')
 enddef
 
 def s:ScriptFuncStore()
@@ -2440,7 +2437,7 @@ def Test_vim9script_forward_func()
     enddef
     g:res_FuncOne = execute('disass FuncOne')
   END
-  writefile(lines, 'Xdisassemble')
+  writefile(lines, 'Xdisassemble', 'D')
   source Xdisassemble
 
   # check that the first function calls the second with DCALL
@@ -2450,7 +2447,6 @@ def Test_vim9script_forward_func()
         '\d RETURN',
         g:res_FuncOne)
 
-  delete('Xdisassemble')
   unlet g:res_FuncOne
 enddef
 
@@ -2901,51 +2897,50 @@ def Test_disassemble_nextcmd()
 enddef
 
 def Test_disassemble_after_reload()
-    var lines =<< trim END
-        vim9script
-        if exists('g:ThisFunc')
-          finish
-        endif
-        var name: any
-        def g:ThisFunc(): number
-          g:name = name
-          return 0
-        enddef
-        def g:ThatFunc(): number
-          name = g:name
-          return 0
-        enddef
-    END
-    lines->writefile('Xreload.vim')
+  var lines =<< trim END
+      vim9script
+      if exists('g:ThisFunc')
+        finish
+      endif
+      var name: any
+      def g:ThisFunc(): number
+        g:name = name
+        return 0
+      enddef
+      def g:ThatFunc(): number
+        name = g:name
+        return 0
+      enddef
+  END
+  lines->writefile('Xreload.vim', 'D')
 
-    source Xreload.vim
-    g:ThisFunc()
-    g:ThatFunc()
+  source Xreload.vim
+  g:ThisFunc()
+  g:ThatFunc()
 
-    source Xreload.vim
-    var res = execute('disass g:ThisFunc')
-    assert_match('ThisFunc\_s*' ..
-          'g:name = name\_s*' ..
-          '\d LOADSCRIPT \[deleted\] from .*/Xreload.vim\_s*' ..
-          '\d STOREG g:name\_s*' ..
-          'return 0\_s*' ..
-          '\d PUSHNR 0\_s*' ..
-          '\d RETURN\_s*',
-          res)
+  source Xreload.vim
+  var res = execute('disass g:ThisFunc')
+  assert_match('ThisFunc\_s*' ..
+        'g:name = name\_s*' ..
+        '\d LOADSCRIPT \[deleted\] from .*/Xreload.vim\_s*' ..
+        '\d STOREG g:name\_s*' ..
+        'return 0\_s*' ..
+        '\d PUSHNR 0\_s*' ..
+        '\d RETURN\_s*',
+        res)
 
-    res = execute('disass g:ThatFunc')
-    assert_match('ThatFunc\_s*' ..
-          'name = g:name\_s*' ..
-          '\d LOADG g:name\_s*' ..
-          '\d STORESCRIPT \[deleted\] in .*/Xreload.vim\_s*' ..
-          'return 0\_s*' ..
-          '\d PUSHNR 0\_s*' ..
-          '\d RETURN\_s*',
-          res)
+  res = execute('disass g:ThatFunc')
+  assert_match('ThatFunc\_s*' ..
+        'name = g:name\_s*' ..
+        '\d LOADG g:name\_s*' ..
+        '\d STORESCRIPT \[deleted\] in .*/Xreload.vim\_s*' ..
+        'return 0\_s*' ..
+        '\d PUSHNR 0\_s*' ..
+        '\d RETURN\_s*',
+        res)
 
-    delete('Xreload.vim')
-    delfunc g:ThisFunc
-    delfunc g:ThatFunc
+  delfunc g:ThisFunc
+  delfunc g:ThatFunc
 enddef
 
 def s:MakeString(x: number): string
--- a/src/testdir/test_vim9_expr.vim
+++ b/src/testdir/test_vim9_expr.vim
@@ -3490,7 +3490,7 @@ def Test_expr9_autoload_var()
   var auto_lines =<< trim END
       let autofile#var = 'found'
   END
-  mkdir('Xruntime/autoload', 'p')
+  mkdir('Xruntime/autoload', 'pR')
   writefile(auto_lines, 'Xruntime/autoload/autofile.vim')
   var save_rtp = &rtp
   &rtp = getcwd() .. '/Xruntime,' .. &rtp
@@ -3506,7 +3506,6 @@ def Test_expr9_autoload_var()
   v9.CheckDefExecAndScriptFailure(lines, 'E121: Undefined variable: autofile#other')
 
   &rtp = save_rtp
-  delete('Xruntime', 'rf')
 enddef
 
 def Test_expr9_call_autoload()
@@ -3515,7 +3514,7 @@ def Test_expr9_call_autoload()
 	return 'found'
       enddef
   END
-  mkdir('Xruntime/autoload', 'p')
+  mkdir('Xruntime/autoload', 'pR')
   writefile(auto_lines, 'Xruntime/autoload/some.vim')
   var save_rtp = &rtp
   &rtp = getcwd() .. '/Xruntime,' .. &rtp
@@ -3523,7 +3522,6 @@ def Test_expr9_call_autoload()
   assert_equal('found', some#func())
 
   &rtp = save_rtp
-  delete('Xruntime', 'rf')
 enddef
 
 def Test_expr9_method_call()
@@ -3640,7 +3638,7 @@ def Test_expr9_method_call_import()
           return map(items, (_, i) => i * i)
       enddef
   END
-  call writefile(lines, 'Xsquare.vim')
+  call writefile(lines, 'Xsquare.vim', 'D')
 
   lines =<< trim END
       vim9script
@@ -3663,8 +3661,6 @@ def Test_expr9_method_call_import()
       echo range(5)->Xsquare.NoSuchFunc()
   END
   v9.CheckScriptFailure(lines, 'E1048: Item not found in script: NoSuchFunc')
-
-  delete('Xsquare.vim')
 enddef
 
 
--- a/src/testdir/test_vim9_import.vim
+++ b/src/testdir/test_vim9_import.vim
@@ -39,7 +39,7 @@ def s:Undo_export_script_lines()
 enddef
 
 def Test_vim9_import_export()
-  writefile(s:export_script_lines, 'Xexport.vim')
+  writefile(s:export_script_lines, 'Xexport.vim', 'D')
   var import_script_lines =<< trim END
     vim9script
     var dir = './'
@@ -84,7 +84,7 @@ def Test_vim9_import_export()
     assert_equal('andthensome', 'andthen'->expo.AddSome())
     assert_equal('awesome', 'awe'->expo.AddRef())
   END
-  writefile(import_script_lines, 'Ximport.vim')
+  writefile(import_script_lines, 'Ximport.vim', 'D')
   source Ximport.vim
 
   assert_equal('bobbie', g:result)
@@ -380,9 +380,6 @@ def Test_vim9_import_export()
   writefile(import_assign_const_lines, 'Ximport.vim')
   assert_fails('source Ximport.vim', 'E46: Cannot change read-only variable "CONST"', '', 3)
 
-  delete('Ximport.vim')
-  delete('Xexport.vim')
-
   # Check that in a Vim9 script 'cpo' is set to the Vim default.
   # Flags added or removed are also applied to the restored value.
   set cpo=abcd
@@ -393,7 +390,7 @@ def Test_vim9_import_export()
     set cpo-=c
     g:cpo_after_vim9script = &cpo
   END
-  writefile(lines, 'Xvim9_script')
+  writefile(lines, 'Xvim9_script', 'D')
   source Xvim9_script
   assert_equal('fabd', &cpo)
   set cpo&vim
@@ -410,7 +407,7 @@ def Test_import_very_long_name()
 
       export var verylongnameverylongnameverylongnameverylongnameverylongnameverylongnameverylongnameverylongnameverylongnameverylongnameverylongnameverylongnameverylongnameverylongnameverylongnameverylongname = 'asdf'
   END
-  writefile(lines, 'Xverylong.vim')
+  writefile(lines, 'Xverylong.vim', 'D')
 
   lines =<< trim END
       vim9script
@@ -421,7 +418,6 @@ def Test_import_very_long_name()
   v9.CheckScriptSuccess(lines)
   assert_equal('asdf', g:result)
 
-  delete('Xverylong.vim')
   unlet g:result
 enddef
 
@@ -433,7 +429,7 @@ def Test_import_funcref()
       enddef
       export const G = F
   END
-  writefile(lines, 'Xlib.vim')
+  writefile(lines, 'Xlib.vim', 'D')
 
   lines =<< trim END
       vim9script
@@ -448,8 +444,6 @@ def Test_import_funcref()
       DoTest()
   END
   v9.CheckScriptSuccess(lines)
-
-  delete('Xlib.vim')
 enddef
 
 def Test_export_closure()
@@ -485,7 +479,7 @@ def Test_import_duplicate_function()
 
       NewLspServer()
   END
-  writefile(lines, 'Xserver.vim')
+  writefile(lines, 'Xserver.vim', 'D')
 
   lines =<< trim END
       vim9script
@@ -502,13 +496,11 @@ def Test_import_duplicate_function()
       AddServer()
   END
   v9.CheckScriptSuccess(lines)
-
-  delete('Xserver.vim')
 enddef
 
 
 def Test_import_fails()
-  writefile([], 'Xfoo.vim')
+  writefile([], 'Xfoo.vim', 'D')
   var lines =<< trim END
       import './Xfoo.vim' as foo
       foo = 'bar'
@@ -588,11 +580,10 @@ def Test_import_fails()
       export var item = 'hello'
       import './Xyourself.vim'
   END
-  writefile(lines, 'Xyourself.vim')
+  writefile(lines, 'Xyourself.vim', 'D')
   assert_fails('source Xyourself.vim', 'E1088:')
-  delete('Xyourself.vim')
-
-  mkdir('Ximport')
+
+  mkdir('Ximport', 'R')
 
   writefile(['vim9script'], 'Ximport/.vim')
   lines =<< trim END
@@ -635,9 +626,6 @@ def Test_import_fails()
   call writefile(['vim9script', "import './Xfoo.vim' as abc | foobar"], 'Xbar.vim')
   assert_fails('source Xbar.vim', 'E492: Not an editor command:  foobar')
   call delete('Xbar.vim')
-
-  delete('Ximport', 'rf')
-  delete('Xfoo.vim')
 enddef
 
 func g:Trigger()
@@ -653,26 +641,24 @@ def Test_import_export_expr_map()
       return 'yes'
     enddef
   END
-  writefile(export_lines, 'Xexport_that.vim')
+  writefile(export_lines, 'Xexport_that.vim', 'D')
 
   var import_lines =<< trim END
     vim9script
     import './Xexport_that.vim' as that
     assert_equal('yes', that.That())
   END
-  writefile(import_lines, 'Ximport.vim')
+  writefile(import_lines, 'Ximport.vim', 'D')
 
   nnoremap <expr> trigger g:Trigger()
   feedkeys('trigger', "xt")
 
-  delete('Xexport_that.vim')
-  delete('Ximport.vim')
   nunmap trigger
 enddef
 
 def Test_import_in_filetype()
   # check that :import works when the buffer is locked
-  mkdir('ftplugin', 'p')
+  mkdir('ftplugin', 'pR')
   var export_lines =<< trim END
     vim9script
     export var That = 'yes'
@@ -695,8 +681,6 @@ def Test_import_in_filetype()
   assert_equal(1, g:did_load_mytpe)
 
   quit!
-  delete('Xexport_ft.vim')
-  delete('ftplugin', 'rf')
   &rtp = save_rtp
 enddef
 
@@ -707,7 +691,7 @@ def Test_use_import_in_mapping()
         g:result = nr
       enddef
   END
-  writefile(lines, 'XsomeExport.vim')
+  writefile(lines, 'XsomeExport.vim', 'D')
   lines =<< trim END
       vim9script
       import './XsomeExport.vim' as some
@@ -715,7 +699,7 @@ def Test_use_import_in_mapping()
       nnoremap <F3> :call <sid>Funcy(42)<cr>
       nnoremap <F4> :call <sid>some.Funcx(44)<cr>
   END
-  writefile(lines, 'Xmapscript.vim')
+  writefile(lines, 'Xmapscript.vim', 'D')
 
   source Xmapscript.vim
   feedkeys("\<F3>", "xt")
@@ -724,8 +708,6 @@ def Test_use_import_in_mapping()
   assert_equal(44, g:result)
 
   unlet g:result
-  delete('XsomeExport.vim')
-  delete('Xmapscript.vim')
   nunmap <F3>
   nunmap <F4>
 enddef
@@ -737,13 +719,13 @@ def Test_use_relative_autoload_import_in
         g:result = 42
       enddef
   END
-  writefile(lines, 'XrelautoloadExport.vim')
+  writefile(lines, 'XrelautoloadExport.vim', 'D')
   lines =<< trim END
       vim9script
       import autoload './XrelautoloadExport.vim' as some
       nnoremap <F3> :call <SID>some.Func()<CR>
   END
-  writefile(lines, 'Xmapscript.vim')
+  writefile(lines, 'Xmapscript.vim', 'D')
 
   source Xmapscript.vim
   assert_match('\d\+ A: .*XrelautoloadExport.vim', execute('scriptnames')->split("\n")[-1])
@@ -759,8 +741,6 @@ def Test_use_relative_autoload_import_in
   assert_equal(999999, l[0].version)
 
   unlet g:result
-  delete('XrelautoloadExport.vim')
-  delete('Xmapscript.vim')
   nunmap <F3>
 enddef
 
@@ -781,7 +761,7 @@ def Test_use_autoload_import_in_mapping(
         g:result = 49
       enddef
   END
-  mkdir('Ximpdir/autoload', 'p')
+  mkdir('Ximpdir/autoload', 'pR')
   writefile(lines, 'Ximpdir/autoload/XautoloadExport.vim')
   var save_rtp = &rtp
   exe 'set rtp^=' .. getcwd() .. '/Ximpdir'
@@ -791,7 +771,7 @@ def Test_use_autoload_import_in_mapping(
       import autoload 'XautoloadExport.vim' as some
       nnoremap <F3> :call <SID>some.Func()<CR>
   END
-  writefile(lines, 'Xmapscript.vim')
+  writefile(lines, 'Xmapscript.vim', 'D')
 
   source Xmapscript.vim
   assert_match('\d\+ A: .*autoload/XautoloadExport.vim', execute('scriptnames')->split("\n")[-1])
@@ -799,9 +779,7 @@ def Test_use_autoload_import_in_mapping(
   assert_equal(49, g:result)
 
   unlet g:result
-  delete('Xmapscript.vim')
   nunmap <F3>
-  delete('Ximpdir', 'rf')
   &rtp = save_rtp
 enddef
 
@@ -812,7 +790,7 @@ def Test_use_import_in_command_completio
         return ['abcd']
       enddef
   END
-  writefile(lines, 'Xscript.vim')
+  writefile(lines, 'Xscript.vim', 'D')
 
   lines =<< trim END
       vim9script
@@ -825,7 +803,6 @@ def Test_use_import_in_command_completio
   v9.CheckScriptSuccess(lines)
 
   delcommand Cmd
-  delete('Xscript.vim')
 enddef
 
 def Test_use_import_with_funcref_in_command_completion()
@@ -835,7 +812,7 @@ def Test_use_import_with_funcref_in_comm
         return ['abcd']
       enddef
   END
-  writefile(lines, 'Xscript.vim')
+  writefile(lines, 'Xscript.vim', 'D')
 
   lines =<< trim END
       vim9script
@@ -849,11 +826,10 @@ def Test_use_import_with_funcref_in_comm
   v9.CheckScriptSuccess(lines)
 
   delcommand Cmd
-  delete('Xscript.vim')
 enddef
 
 def Test_use_autoload_import_in_insert_completion()
-  mkdir('Xinsdir/autoload', 'p')
+  mkdir('Xinsdir/autoload', 'pR')
   var save_rtp = &rtp
   exe 'set rtp^=' .. getcwd() .. '/Xinsdir'
 
@@ -889,12 +865,11 @@ def Test_use_autoload_import_in_insert_c
 
   set thesaurusfunc=
   bwipe!
-  delete('Xinsdir', 'rf')
   &rtp = save_rtp
 enddef
 
 def Test_use_autoload_import_partial_in_opfunc()
-  mkdir('Xpartdir/autoload', 'p')
+  mkdir('Xpartdir/autoload', 'pR')
   var save_rtp = &rtp
   exe 'set rtp^=' .. getcwd() .. '/Xpartdir'
 
@@ -922,13 +897,12 @@ def Test_use_autoload_import_partial_in_
 
   set opfunc=
   bwipe!
-  delete('Xpartdir', 'rf')
   nunmap <F3>
   &rtp = save_rtp
 enddef
 
 def Test_set_opfunc_to_autoload_func_directly()
-  mkdir('Xdirdir/autoload', 'p')
+  mkdir('Xdirdir/autoload', 'pR')
   var save_rtp = &rtp
   exe 'set rtp^=' .. getcwd() .. '/Xdirdir'
 
@@ -956,13 +930,12 @@ def Test_set_opfunc_to_autoload_func_dir
 
   set opfunc=
   bwipe!
-  delete('Xdirdir', 'rf')
   nunmap <F3>
   &rtp = save_rtp
 enddef
 
 def Test_use_autoload_import_in_fold_expression()
-  mkdir('Xfolddir/autoload', 'p')
+  mkdir('Xfolddir/autoload', 'pR')
   var save_rtp = &rtp
   exe 'set rtp^=' .. getcwd() .. '/Xfolddir'
 
@@ -1000,7 +973,6 @@ def Test_use_autoload_import_in_fold_exp
 
   set foldexpr= foldtext& foldmethod& debug=
   bwipe!
-  delete('Xfolddir', 'rf')
   &rtp = save_rtp
 enddef
 
@@ -1019,11 +991,11 @@ def Test_autoload_import_relative()
       export var someText = 'some text'
       var notexp = 'bad'
   END
-  writefile(lines, 'XimportRel.vim')
-  writefile(lines, 'XimportRel2.vim')
-  writefile(lines, 'XimportRel3.vim')
-  writefile(lines, 'XimportRel4.vim')
-  writefile(lines, 'XimportRel5.vim')
+  writefile(lines, 'XimportRel.vim', 'D')
+  writefile(lines, 'XimportRel2.vim', 'D')
+  writefile(lines, 'XimportRel3.vim', 'D')
+  writefile(lines, 'XimportRel4.vim', 'D')
+  writefile(lines, 'XimportRel5.vim', 'D')
 
   lines =<< trim END
       vim9script
@@ -1166,16 +1138,10 @@ def Test_autoload_import_relative()
       DoIt()
   END
   v9.CheckScriptFailure(lines, 'E484:')
-
-  delete('XimportRel.vim')
-  delete('XimportRel2.vim')
-  delete('XimportRel3.vim')
-  delete('XimportRel4.vim')
-  delete('XimportRel5.vim')
 enddef
 
 def Test_autoload_import_relative_autoload_dir()
-  mkdir('autoload', 'p')
+  mkdir('autoload', 'pR')
   var lines =<< trim END
       vim9script
       export def Bar()
@@ -1196,7 +1162,6 @@ def Test_autoload_import_relative_autolo
   v9.CheckScriptSuccess(lines)
 
   unlet g:called_bar
-  delete('autoload', 'rf')
 enddef
 
 def Test_autoload_import_deleted()
@@ -1204,7 +1169,7 @@ def Test_autoload_import_deleted()
       vim9script
       export const FOO = 1
   END
-  writefile(lines, 'Xa.vim')
+  writefile(lines, 'Xa.vim', 'D')
 
   lines =<< trim END
       vim9script
@@ -1214,8 +1179,6 @@ def Test_autoload_import_deleted()
       var x = Xa.FOO
   END
   v9.CheckScriptFailure(lines, 'E484:')
-
-  delete('Xa.vim')
 enddef
 
 def Test_autoload_import_using_const()
@@ -1255,7 +1218,7 @@ def Run_Test_import_in_diffexpr()
                             .. v:fname_new .. '>>' .. v:fname_out
       enddef
   END
-  writefile(lines, 'Xdiffexpr')
+  writefile(lines, 'Xdiffexpr', 'D')
 
   lines =<< trim END
       vim9script
@@ -1281,7 +1244,6 @@ def Run_Test_import_in_diffexpr()
   set diffopt&
   bwipe!
   bwipe!
-  delete('Xdiffexpr')
 enddef
 
 def Test_import_in_patchexpr()
@@ -1291,7 +1253,7 @@ def Test_import_in_patchexpr()
       call writefile(['output file'], v:fname_out)
     enddef
   END
-  writefile(lines, 'Xpatchexpr')
+  writefile(lines, 'Xpatchexpr', 'D')
 
   lines =<< trim END
       vim9script
@@ -1300,16 +1262,13 @@ def Test_import_in_patchexpr()
   END
   v9.CheckScriptSuccess(lines)
 
-  call writefile(['input file'], 'Xinput')
-  call writefile(['diff file'], 'Xdiff')
+  call writefile(['input file'], 'Xinput', 'D')
+  call writefile(['diff file'], 'Xdiff', 'D')
   :%bwipe!
   edit Xinput
   diffpatch Xdiff
   call assert_equal('output file', getline(1))
 
-  call delete('Xinput')
-  call delete('Xdiff')
-  call delete('Xpatchexpr')
   set patchexpr&
   :%bwipe!
 enddef
@@ -1322,7 +1281,7 @@ def Test_import_in_formatexpr()
         return 0
       enddef
   END
-  writefile(lines, 'Xformatter')
+  writefile(lines, 'Xformatter', 'D')
 
   lines =<< trim END
       vim9script
@@ -1337,13 +1296,12 @@ def Test_import_in_formatexpr()
   assert_equal('yes', g:did_format)
 
   bwipe!
-  delete('Xformatter')
   unlet g:did_format
   set formatexpr=
 enddef
 
 def Test_import_in_includeexpr()
-  writefile(['found it'], 'Xthisfile')
+  writefile(['found it'], 'Xthisfile', 'D')
   new
 
   var lines =<< trim END
@@ -1352,7 +1310,7 @@ def Test_import_in_includeexpr()
         return substitute(v:fname, 'that', 'this', '')
       enddef
   END
-  writefile(lines, 'Xinclude.vim')
+  writefile(lines, 'Xinclude.vim', 'D')
 
   lines =<< trim END
     vim9script
@@ -1368,8 +1326,6 @@ def Test_import_in_includeexpr()
   bwipe!
   bwipe!
   set includeexpr=
-  delete('Xinclude.vim')
-  delete('Xthisfile')
 enddef
 
 def Test_import_in_indentexpr()
@@ -1379,7 +1335,7 @@ def Test_import_in_indentexpr()
         return 5
       enddef
   END
-  writefile(lines, 'Xindenter')
+  writefile(lines, 'Xindenter', 'D')
 
   lines =<< trim END
       vim9script
@@ -1396,7 +1352,6 @@ def Test_import_in_indentexpr()
 
   bwipe!
   set indentexpr= debug=
-  delete('Xindenter')
 enddef
 
 func Test_import_in_printexpr()
@@ -1413,7 +1368,7 @@ def Run_Test_import_in_printexpr()
         return false
       enddef
   END
-  writefile(lines, 'Xprint.vim')
+  writefile(lines, 'Xprint.vim', 'D')
 
   lines =<< trim END
       vim9script
@@ -1426,7 +1381,6 @@ def Run_Test_import_in_printexpr()
   hardcopy dummy args
   assert_equal('yes', g:printed)
 
-  delete('Xprint.vim')
   set printexpr=
 enddef
 
@@ -1440,7 +1394,7 @@ def Test_import_in_charconvert()
         return false  # success
       enddef
   END
-  writefile(lines, 'Xconvert.vim')
+  writefile(lines, 'Xconvert.vim', 'D')
 
   lines =<< trim END
       vim9script
@@ -1449,14 +1403,12 @@ def Test_import_in_charconvert()
   END
   v9.CheckScriptSuccess(lines)
 
-  writefile(['one', 'two'], 'Xiicfile')
+  writefile(['one', 'two'], 'Xiicfile', 'D')
   new Xiicfile
   write ++enc=ucase Xiicfile1
   assert_equal(['ONE', 'TWO'], readfile('Xiicfile1'))
 
-  delete('Xiicfile')
   delete('Xiicfile1')
-  delete('Xconvert.vim')
   bwipe!
   set charconvert&
 enddef
@@ -1473,7 +1425,7 @@ def Run_Test_import_in_spellsuggest_expr
         return [['Fox', 8], ['Fop', 9]]
       enddef
   END
-  writefile(lines, 'Xsuggest.vim')
+  writefile(lines, 'Xsuggest.vim', 'D')
 
   lines =<< trim END
       vim9script
@@ -1485,7 +1437,6 @@ def Run_Test_import_in_spellsuggest_expr
   set verbose=1  # report errors
   call assert_equal(['Fox', 'Fop'], spellsuggest('Fo', 2))
 
-  delete('Xsuggest.vim')
   set nospell spellsuggest& verbose=0
 enddef
 
@@ -1496,7 +1447,7 @@ def Test_import_in_lambda_method()
         return e
       enddef
   END
-  writefile(lines, 'XexportRetarg.vim')
+  writefile(lines, 'XexportRetarg.vim', 'D')
   lines =<< trim END
       vim9script
       import './XexportRetarg.vim'
@@ -1507,12 +1458,10 @@ def Test_import_in_lambda_method()
       assert_equal('arg', Lambda())
   END
   v9.CheckScriptSuccess(lines)
-
-  delete('XexportRetarg.vim')
 enddef
 
 def Test_export_shadows_global_function()
-  mkdir('Xglobdir/autoload', 'p')
+  mkdir('Xglobdir/autoload', 'pR')
   var save_rtp = &rtp
   exe 'set rtp^=' .. getcwd() .. '/Xglobdir'
 
@@ -1538,7 +1487,6 @@ def Test_export_shadows_global_function(
 
   delfunc g:Shadow
   bwipe!
-  delete('Xglobdir', 'rf')
   &rtp = save_rtp
 enddef
 
@@ -1565,13 +1513,12 @@ def Run_Test_import_fails_on_command_lin
         return 0
     enddef
   END
-  writefile(export, 'XexportCmd.vim')
+  writefile(export, 'XexportCmd.vim', 'D')
 
   var buf = g:RunVimInTerminal('-c "import Foo from ''./XexportCmd.vim''"', {
                 rows: 6, wait_for_ruler: 0})
   g:WaitForAssert(() => assert_match('^E1094:', term_getline(buf, 5)))
 
-  delete('XexportCmd.vim')
   g:StopVimInTerminal(buf)
 enddef
 
@@ -1583,7 +1530,7 @@ def Test_vim9_reload_noclear()
     export def TheFunc(x = 0)
     enddef
   END
-  writefile(lines, 'XExportReload')
+  writefile(lines, 'XExportReload', 'D')
   lines =<< trim END
     vim9script noclear
     g:loadCount += 1
@@ -1609,7 +1556,7 @@ def Test_vim9_reload_noclear()
       return 'once'
     enddef
   END
-  writefile(lines, 'XReloaded')
+  writefile(lines, 'XReloaded', 'D')
   g:loadCount = 0
   source XReloaded
   assert_equal(1, g:loadCount)
@@ -1621,8 +1568,6 @@ def Test_vim9_reload_noclear()
   assert_equal(3, g:loadCount)
   assert_equal(['init', 'yes', 'again', 'once', 'thexport'], g:Values())
 
-  delete('XReloaded')
-  delete('XExportReload')
   delfunc g:Values
   unlet g:loadCount
 
@@ -1631,7 +1576,7 @@ def Test_vim9_reload_noclear()
       def Inner()
       enddef
   END
-  lines->writefile('XreloadScript.vim')
+  lines->writefile('XreloadScript.vim', 'D')
   source XreloadScript.vim
 
   lines =<< trim END
@@ -1644,8 +1589,6 @@ def Test_vim9_reload_noclear()
   END
   lines->writefile('XreloadScript.vim')
   source XreloadScript.vim
-
-  delete('XreloadScript.vim')
 enddef
 
 def Test_vim_reload_noclear_arg_count()
@@ -1668,7 +1611,7 @@ def Test_vim_reload_noclear_arg_count()
       Call()
       g:didload = 1
   END
-  lines->writefile('XreloadScript_1.vim')
+  lines->writefile('XreloadScript_1.vim', 'D')
   source XreloadScript_1.vim
   assert_fails('source XreloadScript_1.vim', 'E1106: One argument too many')
   unlet g:didload
@@ -1692,7 +1635,7 @@ def Test_vim_reload_noclear_arg_count()
       Call()
       g:didload = 1
   END
-  lines->writefile('XreloadScript_2.vim')
+  lines->writefile('XreloadScript_2.vim', 'D')
   source XreloadScript_2.vim
   assert_fails('source XreloadScript_2.vim', 'E1106: 2 arguments too many')
   unlet g:didload
@@ -1716,7 +1659,7 @@ def Test_vim_reload_noclear_arg_count()
       Call()
       g:didload = 1
   END
-  lines->writefile('XreloadScript_3.vim')
+  lines->writefile('XreloadScript_3.vim', 'D')
   source XreloadScript_3.vim
   assert_fails('source XreloadScript_3.vim', 'E1190: One argument too few')
   unlet g:didload
@@ -1740,15 +1683,10 @@ def Test_vim_reload_noclear_arg_count()
       Call()
       g:didload = 1
   END
-  lines->writefile('XreloadScript_4.vim')
+  lines->writefile('XreloadScript_4.vim', 'D')
   source XreloadScript_4.vim
   assert_fails('source XreloadScript_4.vim', 'E1190: 2 arguments too few')
   unlet g:didload
-
-  delete('XreloadScript_1.vim')
-  delete('XreloadScript_2.vim')
-  delete('XreloadScript_3.vim')
-  delete('XreloadScript_4.vim')
 enddef
 
 def Test_vim9_reload_noclear_error()
@@ -1771,12 +1709,11 @@ def Test_vim9_reload_noclear_error()
       Call()
       g:didload = 1
   END
-  lines->writefile('XreloadScriptErr.vim')
+  lines->writefile('XreloadScriptErr.vim', 'D')
   source XreloadScriptErr.vim
   assert_fails('source XreloadScriptErr.vim', 'E1001: Variable not found: ax')
 
   unlet g:didload
-  delete('XreloadScriptErr.vim')
 enddef
 
 def Test_vim9_reload_import()
@@ -1794,7 +1731,7 @@ def Test_vim9_reload_import()
       return valtwo
     enddef
   END
-  writefile(lines + morelines, 'Xreload.vim')
+  writefile(lines + morelines, 'Xreload.vim', 'D')
   source Xreload.vim
   source Xreload.vim
   source Xreload.vim
@@ -1808,7 +1745,6 @@ def Test_vim9_reload_import()
   writefile(lines, 'Xreload.vim')
   assert_fails('source Xreload.vim', 'E1041:', '', 3, 'Xreload.vim')
 
-  delete('Xreload.vim')
   delete('Ximport.vim')
 enddef
 
@@ -1822,7 +1758,7 @@ def Test_script_reload_change_type()
       return str .. 'xxx'
     enddef
   END
-  writefile(lines, 'Xreload.vim')
+  writefile(lines, 'Xreload.vim', 'D')
   source Xreload.vim
   echo g:GetStr()
 
@@ -1835,7 +1771,6 @@ def Test_script_reload_change_type()
   assert_fails('echo g:GetStr()', 'E1150:')
 
   delfunc g:GetStr
-  delete('Xreload.vim')
 enddef
 
 " Define CallFunc so that the test can be compiled
@@ -1856,12 +1791,11 @@ def Test_script_reload_from_function()
         g:didTheFunc = 1
       enddef
   END
-  writefile(lines, 'XreloadFunc.vim')
+  writefile(lines, 'XreloadFunc.vim', 'D')
   source XreloadFunc.vim
   CallFunc
   assert_equal(1, g:didTheFunc)
 
-  delete('XreloadFunc.vim')
   delcommand CallFunc
   unlet g:loadedThis
   unlet g:didTheFunc
@@ -1888,7 +1822,7 @@ def Test_vim9_funcref()
         return arg
       enddef
   END
-  writefile(sortlines, 'Xsort.vim')
+  writefile(sortlines, 'Xsort.vim', 'D')
 
   var lines =<< trim END
     vim9script
@@ -1898,7 +1832,7 @@ def Test_vim9_funcref()
     enddef
     Test()
   END
-  writefile(lines, 'Xscript.vim')
+  writefile(lines, 'Xscript.vim', 'D')
   source Xscript.vim
   assert_equal([4, 3, 2, 1, 0], g:result)
   unlet g:result
@@ -1921,9 +1855,6 @@ def Test_vim9_funcref()
   END
   writefile(lines, 'Xscript.vim')
 
-  delete('Xsort.vim')
-  delete('Xscript.vim')
-
   var Funcref = function('s:RetSome')
   assert_equal('some', Funcref())
 enddef
@@ -1944,7 +1875,7 @@ def Test_vim9_funcref_other_script()
       return range(10)->filter(FilterFunc)
     enddef
   END
-  writefile(filterLines, 'Xfilter.vim')
+  writefile(filterLines, 'Xfilter.vim', 'D')
 
   var lines =<< trim END
     vim9script
@@ -1959,7 +1890,6 @@ def Test_vim9_funcref_other_script()
     TestDirect()
   END
   v9.CheckScriptSuccess(lines)
-  delete('Xfilter.vim')
 enddef
 
 def Test_import_absolute()
@@ -1974,8 +1904,8 @@ def Test_import_absolute()
         'UseExported()',
         'g:import_disassembled = execute("disass UseExported")',
         ]
-  writefile(import_lines, 'Ximport_abs.vim')
-  writefile(s:export_script_lines, 'Xexport_abs.vim')
+  writefile(import_lines, 'Ximport_abs.vim', 'D')
+  writefile(s:export_script_lines, 'Xexport_abs.vim', 'D')
 
   source Ximport_abs.vim
 
@@ -1996,9 +1926,6 @@ def Test_import_absolute()
   Undo_export_script_lines()
   unlet g:imported_abs
   unlet g:import_disassembled
-
-  delete('Ximport_abs.vim')
-  delete('Xexport_abs.vim')
 enddef
 
 def Test_import_rtp()
@@ -2007,8 +1934,8 @@ def Test_import_rtp()
         'import "Xexport_rtp.vim" as rtp',
         'g:imported_rtp = rtp.exported',
         ]
-  writefile(import_lines, 'Ximport_rtp.vim')
-  mkdir('import', 'p')
+  writefile(import_lines, 'Ximport_rtp.vim', 'D')
+  mkdir('import', 'pR')
   writefile(s:export_script_lines, 'import/Xexport_rtp.vim')
 
   var save_rtp = &rtp
@@ -2020,8 +1947,6 @@ def Test_import_rtp()
 
   Undo_export_script_lines()
   unlet g:imported_rtp
-  delete('Ximport_rtp.vim')
-  delete('import', 'rf')
 enddef
 
 def Test_import_compile_error()
@@ -2031,7 +1956,7 @@ def Test_import_compile_error()
         '  return notDefined',
         'enddef',
         ]
-  writefile(export_lines, 'Xexported.vim')
+  writefile(export_lines, 'Xexported.vim', 'D')
 
   var import_lines = [
         'vim9script',
@@ -2041,7 +1966,7 @@ def Test_import_compile_error()
         'enddef',
         'defcompile',
         ]
-  writefile(import_lines, 'Ximport.vim')
+  writefile(import_lines, 'Ximport.vim', 'D')
 
   try
     source Ximport.vim
@@ -2050,9 +1975,6 @@ def Test_import_compile_error()
     assert_match('E1001: Variable not found: notDefined', v:exception)
     assert_match('function <SNR>\d\+_ImpFunc\[1\]..<SNR>\d\+_ExpFunc, line 1', v:throwpoint)
   endtry
-
-  delete('Xexported.vim')
-  delete('Ximport.vim')
 enddef
 
 def Test_func_overrules_import_fails()
@@ -2062,7 +1984,7 @@ def Test_func_overrules_import_fails()
         echo 'imported'
       enddef
   END
-  writefile(export_lines, 'XexportedFunc.vim')
+  writefile(export_lines, 'XexportedFunc.vim', 'D')
 
   var lines =<< trim END
     vim9script
@@ -2084,8 +2006,6 @@ def Test_func_overrules_import_fails()
     defcompile
   END
   v9.CheckScriptFailure(lines, 'E1236:')
-
-  delete('XexportedFunc.vim')
 enddef
 
 def Test_source_vim9_from_legacy()
@@ -2098,7 +2018,7 @@ def Test_source_vim9_from_legacy()
        return 'text'
     enddef
   END
-  writefile(vim9_lines, 'Xvim9_script.vim')
+  writefile(vim9_lines, 'Xvim9_script.vim', 'D')
 
   var legacy_lines =<< trim END
     source Xvim9_script.vim
@@ -2109,14 +2029,11 @@ def Test_source_vim9_from_legacy()
     call assert_equal('global', global)
     call assert_equal('global', g:global)
   END
-  writefile(legacy_lines, 'Xlegacy_script.vim')
+  writefile(legacy_lines, 'Xlegacy_script.vim', 'D')
 
   source Xlegacy_script.vim
   assert_equal('global', g:global)
   unlet g:global
-
-  delete('Xlegacy_script.vim')
-  delete('Xvim9_script.vim')
 enddef
 
 def Test_import_vim9_from_legacy()
@@ -2129,7 +2046,7 @@ def Test_import_vim9_from_legacy()
        return 'text'
     enddef
   END
-  writefile(vim9_lines, 'Xvim9_export.vim')
+  writefile(vim9_lines, 'Xvim9_export.vim', 'D')
 
   var legacy_lines =<< trim END
     import './Xvim9_export.vim' as vim9
@@ -2147,20 +2064,17 @@ def Test_import_vim9_from_legacy()
     call assert_equal('exported', s:vim9.exported)
     call assert_equal('text', s:vim9.GetText())
   END
-  writefile(legacy_lines, 'Xlegacy_script.vim')
+  writefile(legacy_lines, 'Xlegacy_script.vim', 'D')
 
   source Xlegacy_script.vim
   assert_equal('global', g:global)
   unlet g:global
-
-  delete('Xlegacy_script.vim')
-  delete('Xvim9_export.vim')
 enddef
 
 def Test_cmdline_win()
   # if the Vim syntax highlighting uses Vim9 constructs they can be used from
   # the command line window.
-  mkdir('rtp/syntax', 'p')
+  mkdir('rtp/syntax', 'pR')
   var export_lines =<< trim END
     vim9script
     export var That = 'yes'
@@ -2186,7 +2100,6 @@ def Test_cmdline_win()
     au!
   augroup END
   &rtp = save_rtp
-  delete('rtp', 'rf')
 enddef
 
 def Test_import_gone_when_sourced_twice()
@@ -2198,7 +2111,7 @@ def Test_import_gone_when_sourced_twice(
       g:guard = 1
       export var name = 'someName'
   END
-  writefile(exportlines, 'XexportScript.vim')
+  writefile(exportlines, 'XexportScript.vim', 'D')
 
   var lines =<< trim END
       vim9script
@@ -2207,7 +2120,7 @@ def Test_import_gone_when_sourced_twice(
         return expo.name
       enddef
   END
-  writefile(lines, 'XscriptImport.vim')
+  writefile(lines, 'XscriptImport.vim', 'D')
   so XscriptImport.vim
   assert_equal('someName', g:GetName())
 
@@ -2215,8 +2128,6 @@ def Test_import_gone_when_sourced_twice(
   assert_fails('call g:GetName()', 'E1149:')
 
   delfunc g:GetName
-  delete('XexportScript.vim')
-  delete('XscriptImport.vim')
   unlet g:guard
 enddef
 
@@ -2235,7 +2146,7 @@ def Test_vim9_autoload_full_name()
      enddef
   END
 
-  mkdir('Xfulldir/autoload', 'p')
+  mkdir('Xfulldir/autoload', 'pR')
   writefile(lines, 'Xfulldir/autoload/some.vim')
   var save_rtp = &rtp
   exe 'set rtp^=' .. getcwd() .. '/Xfulldir'
@@ -2258,12 +2169,11 @@ def Test_vim9_autoload_full_name()
   writefile(lines, 'Xfulldir/autoload/Other.vim')
   assert_equal('other', g:Other#GetOther())
 
-  delete('Xfulldir', 'rf')
   &rtp = save_rtp
 enddef
 
 def Test_vim9script_autoload()
-  mkdir('Xaldir/autoload', 'p')
+  mkdir('Xaldir/autoload', 'pR')
   var save_rtp = &rtp
   exe 'set rtp^=' .. getcwd() .. '/Xaldir'
 
@@ -2323,12 +2233,11 @@ def Test_vim9script_autoload()
 
   unlet g:prefixed_loaded
   unlet g:expected_loaded
-  delete('Xaldir', 'rf')
   &rtp = save_rtp
 enddef
 
 def Test_import_autoload_not_exported()
-  mkdir('Xnimdir/autoload', 'p')
+  mkdir('Xnimdir/autoload', 'pR')
   var save_rtp = &rtp
   exe 'set rtp^=' .. getcwd() .. '/Xnimdir'
 
@@ -2453,12 +2362,11 @@ def Test_import_autoload_not_exported()
   END
   v9.CheckScriptFailure(lines, 'E117: Unknown function: notExport7#NotExport')
 
-  delete('Xnimdir', 'rf')
   &rtp = save_rtp
 enddef
 
 def Test_vim9script_autoload_call()
-  mkdir('Xcalldir/autoload', 'p')
+  mkdir('Xcalldir/autoload', 'pR')
   var save_rtp = &rtp
   exe 'set rtp^=' .. getcwd() .. '/Xcalldir'
 
@@ -2497,12 +2405,11 @@ def Test_vim9script_autoload_call()
   v9.CheckScriptSuccess(lines)
 
   unlet g:result
-  delete('Xcalldir', 'rf')
   &rtp = save_rtp
 enddef
 
 def Test_vim9script_noclear_autoload()
-  mkdir('Xnocdir/autoload', 'p')
+  mkdir('Xnocdir/autoload', 'pR')
   var save_rtp = &rtp
   exe 'set rtp^=' .. getcwd() .. '/Xnocdir'
 
@@ -2526,7 +2433,7 @@ def Test_vim9script_noclear_autoload()
       nnoremap <F3> <ScriptCmd>g:result = double.Func()<CR>
   END
   g:double_loaded = 'no'
-  writefile(lines, 'Xloaddouble')
+  writefile(lines, 'Xloaddouble', 'D')
   source Xloaddouble
   assert_equal('no', g:double_loaded)
   assert_equal(true, g:script_loaded)
@@ -2535,16 +2442,14 @@ def Test_vim9script_noclear_autoload()
   assert_equal('called', g:result)
   assert_equal('yes', g:double_loaded)
 
-  delete('Xloaddouble')
   unlet g:double_loaded
   unlet g:script_loaded
   unlet g:result
-  delete('Xnocdir', 'rf')
   &rtp = save_rtp
 enddef
 
 def Test_vim9script_autoload_duplicate()
-  mkdir('Xdupdir/autoload', 'p')
+  mkdir('Xdupdir/autoload', 'pR')
 
   var lines =<< trim END
      vim9script
@@ -2613,12 +2518,10 @@ def Test_vim9script_autoload_duplicate()
   END
   writefile(lines, 'Xdupdir/autoload/dup6func.vim')
   assert_fails('source Xdupdir/autoload/dup6func.vim', 'E1041: Redefining script item: "Func"')
-
-  delete('Xdupdir', 'rf')
 enddef
 
 def Test_autoload_missing_function_name()
-  mkdir('Xmisdir/autoload', 'p')
+  mkdir('Xmisdir/autoload', 'pR')
 
   var lines =<< trim END
      vim9script
@@ -2628,8 +2531,6 @@ def Test_autoload_missing_function_name(
   END
   writefile(lines, 'Xmisdir/autoload/loadme.vim')
   assert_fails('source Xmisdir/autoload/loadme.vim', 'E129:')
-
-  delete('Xmisdir', 'rf')
 enddef
 
 def Test_autoload_name_wrong()
@@ -2637,11 +2538,10 @@ def Test_autoload_name_wrong()
      def Xscriptname#Func()
      enddef
   END
-  writefile(lines, 'Xscriptname.vim')
+  writefile(lines, 'Xscriptname.vim', 'D')
   v9.CheckScriptFailure(lines, 'E746:')
-  delete('Xscriptname.vim')
-
-  mkdir('Xwrodir/autoload', 'p')
+
+  mkdir('Xwrodir/autoload', 'pR')
   lines =<< trim END
      vim9script
      def somescript#Func()
@@ -2654,7 +2554,7 @@ def Test_autoload_name_wrong()
 enddef
 
 def Test_import_autoload_postponed()
-  mkdir('Xpostdir/autoload', 'p')
+  mkdir('Xpostdir/autoload', 'pR')
   var save_rtp = &rtp
   exe 'set rtp^=' .. getcwd() .. '/Xpostdir'
 
@@ -2685,12 +2585,11 @@ def Test_import_autoload_postponed()
   assert_equal('true', g:loaded_postponed)
 
   unlet g:loaded_postponed
-  delete('Xpostdir', 'rf')
   &rtp = save_rtp
 enddef
 
 def Test_import_autoload_override()
-  mkdir('Xoverdir/autoload', 'p')
+  mkdir('Xoverdir/autoload', 'pR')
   var save_rtp = &rtp
   exe 'set rtp^=' .. getcwd() .. '/Xoverdir'
   test_override('autoload', 1)
@@ -2721,12 +2620,11 @@ def Test_import_autoload_override()
 
   test_override('autoload', 0)
   unlet g:loaded_override
-  delete('Xoverdir', 'rf')
   &rtp = save_rtp
 enddef
 
 def Test_autoload_mapping()
-  mkdir('Xmapdir/autoload', 'p')
+  mkdir('Xmapdir/autoload', 'pR')
   var save_rtp = &rtp
   exe 'set rtp^=' .. getcwd() .. '/Xmapdir'
 
@@ -2773,7 +2671,6 @@ def Test_autoload_mapping()
   nunmap yy
   unlet g:toggle_loaded
   unlet g:toggle_called
-  delete('Xmapdir', 'rf')
   &rtp = save_rtp
 enddef
 
@@ -2831,7 +2728,7 @@ enddef
 
 " test disassembling an auto-loaded function starting with "debug"
 def Test_vim9_autoload_disass()
-  mkdir('Xdasdir/autoload', 'p')
+  mkdir('Xdasdir/autoload', 'pR')
   var save_rtp = &rtp
   exe 'set rtp^=' .. getcwd() .. '/Xdasdir'
 
@@ -2860,7 +2757,6 @@ def Test_vim9_autoload_disass()
   END
   v9.CheckScriptSuccess(lines)
 
-  delete('Xdasdir', 'rf')
   &rtp = save_rtp
 enddef
 
@@ -2873,7 +2769,7 @@ def Test_vim9_aucmd_autoload()
      enddef
   END
 
-  mkdir('Xauldir/autoload', 'p')
+  mkdir('Xauldir/autoload', 'pR')
   writefile(lines, 'Xauldir/autoload/foo.vim')
   var save_rtp = &rtp
   exe 'set rtp^=' .. getcwd() .. '/Xauldir'
@@ -2886,7 +2782,6 @@ def Test_vim9_aucmd_autoload()
   augroup test
     autocmd!
   augroup END
-  delete('Xauldir', 'rf')
   &rtp = save_rtp
 enddef
 
@@ -2899,7 +2794,7 @@ def Test_vim9_autoload_case_sensitive()
      enddef
   END
 
-  mkdir('Xcasedir/autoload', 'p')
+  mkdir('Xcasedir/autoload', 'pR')
   writefile(lines, 'Xcasedir/autoload/CaseSensitive.vim')
   var save_rtp = &rtp
   exe 'set rtp^=' .. getcwd() .. '/Xcasedir'
@@ -2920,7 +2815,6 @@ def Test_vim9_autoload_case_sensitive()
     v9.CheckScriptFailure(lines, 'E1262:')
   endif
 
-  delete('Xcasedir', 'rf')
   &rtp = save_rtp
 enddef
 
@@ -2944,7 +2838,7 @@ def Test_vim9_autoload_error()
       catch /wontmatch/
       endtry
   END
-  call mkdir('Xruntime/autoload', 'p')
+  call mkdir('Xruntime/autoload', 'pR')
   call writefile(lines, 'Xruntime/autoload/crash.vim')
 
   # run in a separate Vim to avoid the side effects of assert_fails()
@@ -2954,13 +2848,11 @@ def Test_vim9_autoload_error()
     call writefile(['ok'], 'Xdidit')
     qall!
   END
-  writefile(lines, 'Xscript')
+  writefile(lines, 'Xscript', 'D')
   g:RunVim([], [], '-S Xscript')
   assert_equal(['ok'], readfile('Xdidit'))
 
   delete('Xdidit')
-  delete('Xscript')
-  delete('Xruntime', 'rf')
 
   lines =<< trim END
     vim9script
@@ -2973,7 +2865,7 @@ def Test_vim9_import_symlink()
   if !has('unix')
     CheckUnix
   else
-    mkdir('Xto/plugin', 'p')
+    mkdir('Xto/plugin', 'pR')
     var lines =<< trim END
         vim9script
         import autoload 'bar.vim'
@@ -2982,7 +2874,7 @@ def Test_vim9_import_symlink()
     END
     writefile(lines, 'Xto/plugin/foo.vim')
 
-    mkdir('Xto/autoload', 'p')
+    mkdir('Xto/autoload', 'pR')
     lines =<< trim END
         vim9script
         export def Func(): string
@@ -3014,7 +2906,6 @@ def Test_vim9_import_symlink()
     unlet g:resultFunc
     unlet g:resultValue
     &rtp = save_rtp
-    delete('Xto', 'rf')
     delete('Xfrom', 'rf')
   endif
 enddef
--- 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 */
 /**/
+    766,
+/**/
     765,
 /**/
     764,