patch 8.2.2092: Vim9: unpredictable errors for script tests

Problem:    Vim9: unpredictable errors for script tests.
Solution:   Use a different script file name for each run.
diff --git a/src/testdir/test_quickfix.vim b/src/testdir/test_quickfix.vim
index 78fd6c9..d89508f 100644
--- a/src/testdir/test_quickfix.vim
+++ b/src/testdir/test_quickfix.vim
@@ -5253,7 +5253,7 @@
   call delete('XquickfixFails')
 endfunc
 
-" Test for updating the quickfix buffer whenever the assocaited quickfix list
+" Test for updating the quickfix buffer whenever the associated quickfix list
 " is changed.
 func Xqfbuf_update(cchar)
   call s:setup_commands(a:cchar)
diff --git a/src/testdir/test_vim9_assign.vim b/src/testdir/test_vim9_assign.vim
index 635b4be..2f4c0d1 100644
--- a/src/testdir/test_vim9_assign.vim
+++ b/src/testdir/test_vim9_assign.vim
@@ -953,6 +953,7 @@
       call Func()
   [END]
   CheckScriptFailure(lines, 'E990:')
+  delfunc! g:Func
 enddef
 
 def Test_let_func_call()
diff --git a/src/testdir/test_vim9_func.vim b/src/testdir/test_vim9_func.vim
index 86b57f3..18aefe0 100644
--- a/src/testdir/test_vim9_func.vim
+++ b/src/testdir/test_vim9_func.vim
@@ -199,7 +199,9 @@
   MyDefaultSecond('test', false)->assert_equal('none')
 
   CheckScriptFailure(['def Func(arg: number = asdf)', 'enddef', 'defcompile'], 'E1001:')
+  delfunc g:Func
   CheckScriptFailure(['def Func(arg: number = "text")', 'enddef', 'defcompile'], 'E1013: Argument 1: type mismatch, expected number but got string')
+  delfunc g:Func
 enddef
 
 def Test_nested_function()
@@ -326,6 +328,7 @@
       enddef
       g:Func()->assert_equal('global')
       Func()->assert_equal('local')
+      delfunc g:Func
   END
   CheckScriptSuccess(lines)
 
@@ -605,6 +608,7 @@
   l[0]->assert_equal('value')
 
   CheckScriptFailure(['def Func(arg: number)', 'arg = 3', 'enddef', 'defcompile'], 'E1090:')
+  delfunc! g:Func
 enddef
 
 " These argument names are reserved in legacy functions.
@@ -763,33 +767,41 @@
         'return "a"',
         'enddef',
         'defcompile'], 'expected number but got string')
+  delfunc! g:Func
   CheckScriptFailure([
         'def Func(): string',
         'return 1',
         'enddef',
         'defcompile'], 'expected string but got number')
+  delfunc! g:Func
   CheckScriptFailure([
         'def Func(): void',
         'return "a"',
         'enddef',
         'defcompile'],
         'E1096: Returning a value in a function without a return type')
+  delfunc! g:Func
   CheckScriptFailure([
         'def Func()',
         'return "a"',
         'enddef',
         'defcompile'],
         'E1096: Returning a value in a function without a return type')
+  delfunc! g:Func
 
   CheckScriptFailure([
         'def Func(): number',
         'return',
         'enddef',
         'defcompile'], 'E1003:')
+  delfunc! g:Func
 
   CheckScriptFailure(['def Func(): list', 'return []', 'enddef'], 'E1008:')
+  delfunc! g:Func
   CheckScriptFailure(['def Func(): dict', 'return {}', 'enddef'], 'E1008:')
+  delfunc! g:Func
   CheckScriptFailure(['def Func()', 'return 1'], 'E1057:')
+  delfunc! g:Func
 
   CheckScriptFailure([
         'vim9script',
@@ -1248,6 +1260,7 @@
     v:exception->assert_match('Invalid command: invalid')
     v:throwpoint->assert_match(', line 3$')
   endtry
+  delfunc! g:Func
 
   # comment lines after the start of the function
   lines =<< trim END
@@ -1268,6 +1281,7 @@
     v:exception->assert_match('Invalid command: invalid')
     v:throwpoint->assert_match(', line 4$')
   endtry
+  delfunc! g:Func
 
   lines =<< trim END
     vim9script
@@ -1286,6 +1300,7 @@
   catch /E716:/
     v:throwpoint->assert_match('_Func, line 3$')
   endtry
+  delfunc! g:Func
 
   delete('Xdef')
 enddef
@@ -1766,6 +1781,7 @@
       Func()
   END
   CheckScriptFailure(lines, 'E492:', 8)
+  delfunc! g:Func
 enddef
 
 def Test_abort_even_with_silent()
diff --git a/src/testdir/test_vim9_script.vim b/src/testdir/test_vim9_script.vim
index 794a36e..532ad83 100644
--- a/src/testdir/test_vim9_script.vim
+++ b/src/testdir/test_vim9_script.vim
@@ -1878,6 +1878,7 @@
   CheckDefFailure(['for i In range(5)'], 'E690:')
   CheckDefFailure(['var x = 5', 'for x in range(5)'], 'E1017:')
   CheckScriptFailure(['def Func(arg: any)', 'for arg in range(5)', 'enddef', 'defcompile'], 'E1006:')
+  delfunc! g:Func
   CheckDefFailure(['for i in "text"'], 'E1012:')
   CheckDefFailure(['for i in xxx'], 'E1001:')
   CheckDefFailure(['endfor'], 'E588:')
@@ -2360,12 +2361,14 @@
       'vim9script',
       'command Echo echo # comment',
       'command Echo # comment',
+      'delcommand Echo',
       ])
   CheckScriptFailure([
       'vim9script',
       'command Echo echo# comment',
       'Echo',
       ], 'E121:')
+  delcommand Echo
   CheckScriptFailure([
       'vim9script',
       'command Echo# comment',
@@ -2375,6 +2378,7 @@
       'command Echo echo',
       'command Echo# comment',
       ], 'E182:')
+  delcommand Echo
 
   CheckScriptSuccess([
       'vim9script',
@@ -2432,6 +2436,7 @@
   CheckScriptSuccess([
       'func Test() " comment',
       'endfunc',
+      'delfunc Test',
       ])
   CheckScriptSuccess([
       'vim9script',
diff --git a/src/testdir/vim9.vim b/src/testdir/vim9.vim
index aeeb5a3..e700732 100644
--- a/src/testdir/vim9.vim
+++ b/src/testdir/vim9.vim
@@ -1,11 +1,17 @@
 " Utility functions for testing vim9 script
 
-" Check that "lines" inside ":def" has no error.
+" Use a different file name for each run.
+let s:sequence = 1
+
+" Check that "lines" inside a ":def" function has no error.
 func CheckDefSuccess(lines)
-  call writefile(['def Func()'] + a:lines + ['enddef', 'defcompile'], 'Xdef')
-  so Xdef
+  let fname = 'Xdef' .. s:sequence
+  let s:sequence += 1
+  call writefile(['def Func()'] + a:lines + ['enddef', 'defcompile'], fname)
+  exe 'so ' .. fname
   call Func()
-  call delete('Xdef')
+  delfunc! Func
+  call delete(fname)
 endfunc
 
 " Check that "lines" inside ":def" results in an "error" message.
@@ -13,9 +19,12 @@
 " Add a line before and after to make it less likely that the line number is
 " accidentally correct.
 func CheckDefFailure(lines, error, lnum = -3)
-  call writefile(['def Func()', '# comment'] + a:lines + ['#comment', 'enddef', 'defcompile'], 'Xdef')
-  call assert_fails('so Xdef', a:error, a:lines, a:lnum + 1)
-  call delete('Xdef')
+  let fname = 'Xdef' .. s:sequence
+  call writefile(['def Func()', '# comment'] + a:lines + ['#comment', 'enddef', 'defcompile'], fname)
+  call assert_fails('so ' .. fname, a:error, a:lines, a:lnum + 1)
+  delfunc! Func
+  call delete(fname)
+  let s:sequence += 1
 endfunc
 
 " Check that "lines" inside ":def" results in an "error" message when executed.
@@ -23,22 +32,29 @@
 " Add a line before and after to make it less likely that the line number is
 " accidentally correct.
 func CheckDefExecFailure(lines, error, lnum = -3)
-  call writefile(['def Func()', '# comment'] + a:lines + ['#comment', 'enddef'], 'Xdef')
-  so Xdef
+  let fname = 'Xdef' .. s:sequence
+  let s:sequence += 1
+  call writefile(['def Func()', '# comment'] + a:lines + ['#comment', 'enddef'], fname)
+  exe 'so ' .. fname
   call assert_fails('call Func()', a:error, a:lines, a:lnum + 1)
-  call delete('Xdef')
+  delfunc! Func
+  call delete(fname)
 endfunc
 
 def CheckScriptFailure(lines: list<string>, error: string, lnum = -3)
-  writefile(lines, 'Xdef')
-  assert_fails('so Xdef', error, lines, lnum)
-  delete('Xdef')
+  var fname = 'Xdef' .. s:sequence
+  s:sequence += 1
+  writefile(lines, fname)
+  assert_fails('so ' .. fname, error, lines, lnum)
+  delete(fname)
 enddef
 
 def CheckScriptSuccess(lines: list<string>)
-  writefile(lines, 'Xdef')
-  so Xdef
-  delete('Xdef')
+  var fname = 'Xdef' .. s:sequence
+  s:sequence += 1
+  writefile(lines, fname)
+  exe 'so ' .. fname
+  delete(fname)
 enddef
 
 def CheckDefAndScriptSuccess(lines: list<string>)
@@ -46,15 +62,15 @@
   CheckScriptSuccess(['vim9script'] + lines)
 enddef
 
-" Check that a command fails both when used in a :def function and when used
-" in Vim9 script.
+" Check that a command fails with the same error when used in a :def function
+" and when used in Vim9 script.
 def CheckDefAndScriptFailure(lines: list<string>, error: string, lnum = -3)
   CheckDefFailure(lines, error, lnum)
   CheckScriptFailure(['vim9script'] + lines, error, lnum + 1)
 enddef
 
-" Check that a command fails both when executed in a :def function and when
-" used in Vim9 script.
+" Check that a command fails with the same error  when executed in a :def
+" function and when used in Vim9 script.
 def CheckDefExecAndScriptFailure(lines: list<string>, error: string, lnum = -3)
   CheckDefExecFailure(lines, error, lnum)
   CheckScriptFailure(['vim9script'] + lines, error, lnum + 1)
diff --git a/src/version.c b/src/version.c
index 0002ef8..6f242ff 100644
--- a/src/version.c
+++ b/src/version.c
@@ -751,6 +751,8 @@
 static int included_patches[] =
 {   /* Add new patch number below this line */
 /**/
+    2092,
+/**/
     2091,
 /**/
     2090,