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_vimscript.vim b/src/testdir/test_vimscript.vim
index 6292f6d..1d71450 100644
--- a/src/testdir/test_vimscript.vim
+++ b/src/testdir/test_vimscript.vim
@@ -33,15 +33,13 @@
     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 @@
   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 @@
   END
   call writefile(code, 'Xtest')
   call AssertException(['source Xtest'], 'Vim(elseif):E584: :elseif after :else')
-
-  call delete('Xtest')
 endfunc
 
 "-------------------------------------------------------------------------------
@@ -3118,7 +3114,7 @@
       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 @@
   END
   call writefile(code, 'Xtest')
   call AssertException(['source Xtest'], 'Vim(endwhile):E588: :endwhile without :while')
-
-  call delete('Xtest')
 endfunc
 
 "-------------------------------------------------------------------------------
@@ -3236,7 +3230,7 @@
   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 @@
   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 @@
   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 @@
   END
   call writefile(code, 'Xtest')
   call AssertException(['source Xtest'], 'Vim(endtry):E170: Missing :endwhile')
-
-  call delete('Xtest')
 endfunc
 
 "-------------------------------------------------------------------------------
@@ -5891,7 +5881,7 @@
     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 @@
   call assert_equal(1, caught_intr)
   call assert_equal('ab', g:Xpath)
   breakdel *
-  call delete('Xscript')
 endfunc
 
 "-------------------------------------------------------------------------------
@@ -5996,7 +5985,7 @@
     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 @@
   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 @@
     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 @@
   call assert_equal(1, caught_intr)
   call assert_equal('abc', g:Xpath)
   breakdel *
-  call delete('Xscript')
 endfunc
 
 "-------------------------------------------------------------------------------
@@ -6963,13 +6950,12 @@
     endfunc
     let g:result = s:snr()
   END
-  call writefile(lines, 'Xexpand')
+  call writefile(lines, 'Xexpand', 'D')
   source Xexpand
   call assert_match('<SNR>\d\+_snr', g:result)
   source Xexpand
   call assert_match('<SNR>\d\+_snr', g:result)
 
-  call delete('Xexpand')
   unlet g:result
 endfunc
 
@@ -7230,7 +7216,7 @@
 
 " 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 @@
   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 @@
       let @a = ''
     endfunc
   [SCRIPT]
-  call writefile(lines, 'Xscript')
+  call writefile(lines, 'Xscript', 'D')
 
   let buf = RunVimInTerminal('-S Xscript', {'rows': 6})
 
@@ -7358,7 +7343,6 @@
   "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 @@
     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 @@
       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
 
 "-------------------------------------------------------------------------------