changeset 23092:c713358da074 v8.2.2092

patch 8.2.2092: Vim9: unpredictable errors for script tests Commit: https://github.com/vim/vim/commit/2d870f8d9ebad22d32799d0d0ee30943d0a0e49d Author: Bram Moolenaar <Bram@vim.org> Date: Sat Dec 5 13:41:01 2020 +0100 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.
author Bram Moolenaar <Bram@vim.org>
date Sat, 05 Dec 2020 13:45:04 +0100
parents dd27e20498a3
children 2e6c66937951
files src/testdir/test_quickfix.vim src/testdir/test_vim9_assign.vim src/testdir/test_vim9_func.vim src/testdir/test_vim9_script.vim src/testdir/vim9.vim src/version.c
diffstat 6 files changed, 61 insertions(+), 21 deletions(-) [+]
line wrap: on
line diff
--- a/src/testdir/test_quickfix.vim
+++ b/src/testdir/test_quickfix.vim
@@ -5253,7 +5253,7 @@ func Test_quickfix_window_fails_to_open(
   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)
--- a/src/testdir/test_vim9_assign.vim
+++ b/src/testdir/test_vim9_assign.vim
@@ -953,6 +953,7 @@ def Test_heredoc()
       call Func()
   [END]
   CheckScriptFailure(lines, 'E990:')
+  delfunc! g:Func
 enddef
 
 def Test_let_func_call()
--- a/src/testdir/test_vim9_func.vim
+++ b/src/testdir/test_vim9_func.vim
@@ -199,7 +199,9 @@ def Test_call_default_args()
   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 @@ def Test_global_local_function()
       enddef
       g:Func()->assert_equal('global')
       Func()->assert_equal('local')
+      delfunc g:Func
   END
   CheckScriptSuccess(lines)
 
@@ -605,6 +608,7 @@ def Test_assign_to_argument()
   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 @@ def Test_return_type_wrong()
         '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 @@ def Test_error_reporting()
     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 @@ def Test_error_reporting()
     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 @@ def Test_error_reporting()
   catch /E716:/
     v:throwpoint->assert_match('_Func, line 3$')
   endtry
+  delfunc! g:Func
 
   delete('Xdef')
 enddef
@@ -1766,6 +1781,7 @@ def Test_reset_did_emsg()
       Func()
   END
   CheckScriptFailure(lines, 'E492:', 8)
+  delfunc! g:Func
 enddef
 
 def Test_abort_even_with_silent()
--- a/src/testdir/test_vim9_script.vim
+++ b/src/testdir/test_vim9_script.vim
@@ -1878,6 +1878,7 @@ def Test_for_loop_fails()
   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 @@ def Test_vim9_comment()
       '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 @@ def Test_vim9_comment()
       'command Echo echo',
       'command Echo# comment',
       ], 'E182:')
+  delcommand Echo
 
   CheckScriptSuccess([
       'vim9script',
@@ -2432,6 +2436,7 @@ def Test_vim9_comment()
   CheckScriptSuccess([
       'func Test() " comment',
       'endfunc',
+      'delfunc Test',
       ])
   CheckScriptSuccess([
       'vim9script',
--- 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 @@ endfunc
 " 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 @@ endfunc
 " 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 @@ def CheckDefAndScriptSuccess(lines: list
   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)
--- a/src/version.c
+++ b/src/version.c
@@ -751,6 +751,8 @@ static char *(features[]) =
 static int included_patches[] =
 {   /* Add new patch number below this line */
 /**/
+    2092,
+/**/
     2091,
 /**/
     2090,