0
0
mirror of https://github.com/vim/vim.git synced 2025-07-26 11:04:33 -04:00

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.
This commit is contained in:
Bram Moolenaar 2020-12-05 13:41:01 +01:00
parent 29d2f45c88
commit 2d870f8d9e
6 changed files with 61 additions and 21 deletions

View File

@ -5253,7 +5253,7 @@ func Test_quickfix_window_fails_to_open()
call delete('XquickfixFails') call delete('XquickfixFails')
endfunc 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. " is changed.
func Xqfbuf_update(cchar) func Xqfbuf_update(cchar)
call s:setup_commands(a:cchar) call s:setup_commands(a:cchar)

View File

@ -953,6 +953,7 @@ def Test_heredoc()
call Func() call Func()
[END] [END]
CheckScriptFailure(lines, 'E990:') CheckScriptFailure(lines, 'E990:')
delfunc! g:Func
enddef enddef
def Test_let_func_call() def Test_let_func_call()

View File

@ -199,7 +199,9 @@ def Test_call_default_args()
MyDefaultSecond('test', false)->assert_equal('none') MyDefaultSecond('test', false)->assert_equal('none')
CheckScriptFailure(['def Func(arg: number = asdf)', 'enddef', 'defcompile'], 'E1001:') 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') CheckScriptFailure(['def Func(arg: number = "text")', 'enddef', 'defcompile'], 'E1013: Argument 1: type mismatch, expected number but got string')
delfunc g:Func
enddef enddef
def Test_nested_function() def Test_nested_function()
@ -326,6 +328,7 @@ def Test_global_local_function()
enddef enddef
g:Func()->assert_equal('global') g:Func()->assert_equal('global')
Func()->assert_equal('local') Func()->assert_equal('local')
delfunc g:Func
END END
CheckScriptSuccess(lines) CheckScriptSuccess(lines)
@ -605,6 +608,7 @@ def Test_assign_to_argument()
l[0]->assert_equal('value') l[0]->assert_equal('value')
CheckScriptFailure(['def Func(arg: number)', 'arg = 3', 'enddef', 'defcompile'], 'E1090:') CheckScriptFailure(['def Func(arg: number)', 'arg = 3', 'enddef', 'defcompile'], 'E1090:')
delfunc! g:Func
enddef enddef
" These argument names are reserved in legacy functions. " These argument names are reserved in legacy functions.
@ -763,33 +767,41 @@ def Test_return_type_wrong()
'return "a"', 'return "a"',
'enddef', 'enddef',
'defcompile'], 'expected number but got string') 'defcompile'], 'expected number but got string')
delfunc! g:Func
CheckScriptFailure([ CheckScriptFailure([
'def Func(): string', 'def Func(): string',
'return 1', 'return 1',
'enddef', 'enddef',
'defcompile'], 'expected string but got number') 'defcompile'], 'expected string but got number')
delfunc! g:Func
CheckScriptFailure([ CheckScriptFailure([
'def Func(): void', 'def Func(): void',
'return "a"', 'return "a"',
'enddef', 'enddef',
'defcompile'], 'defcompile'],
'E1096: Returning a value in a function without a return type') 'E1096: Returning a value in a function without a return type')
delfunc! g:Func
CheckScriptFailure([ CheckScriptFailure([
'def Func()', 'def Func()',
'return "a"', 'return "a"',
'enddef', 'enddef',
'defcompile'], 'defcompile'],
'E1096: Returning a value in a function without a return type') 'E1096: Returning a value in a function without a return type')
delfunc! g:Func
CheckScriptFailure([ CheckScriptFailure([
'def Func(): number', 'def Func(): number',
'return', 'return',
'enddef', 'enddef',
'defcompile'], 'E1003:') 'defcompile'], 'E1003:')
delfunc! g:Func
CheckScriptFailure(['def Func(): list', 'return []', 'enddef'], 'E1008:') CheckScriptFailure(['def Func(): list', 'return []', 'enddef'], 'E1008:')
delfunc! g:Func
CheckScriptFailure(['def Func(): dict', 'return {}', 'enddef'], 'E1008:') CheckScriptFailure(['def Func(): dict', 'return {}', 'enddef'], 'E1008:')
delfunc! g:Func
CheckScriptFailure(['def Func()', 'return 1'], 'E1057:') CheckScriptFailure(['def Func()', 'return 1'], 'E1057:')
delfunc! g:Func
CheckScriptFailure([ CheckScriptFailure([
'vim9script', 'vim9script',
@ -1248,6 +1260,7 @@ def Test_error_reporting()
v:exception->assert_match('Invalid command: invalid') v:exception->assert_match('Invalid command: invalid')
v:throwpoint->assert_match(', line 3$') v:throwpoint->assert_match(', line 3$')
endtry endtry
delfunc! g:Func
# comment lines after the start of the function # comment lines after the start of the function
lines =<< trim END lines =<< trim END
@ -1268,6 +1281,7 @@ def Test_error_reporting()
v:exception->assert_match('Invalid command: invalid') v:exception->assert_match('Invalid command: invalid')
v:throwpoint->assert_match(', line 4$') v:throwpoint->assert_match(', line 4$')
endtry endtry
delfunc! g:Func
lines =<< trim END lines =<< trim END
vim9script vim9script
@ -1286,6 +1300,7 @@ def Test_error_reporting()
catch /E716:/ catch /E716:/
v:throwpoint->assert_match('_Func, line 3$') v:throwpoint->assert_match('_Func, line 3$')
endtry endtry
delfunc! g:Func
delete('Xdef') delete('Xdef')
enddef enddef
@ -1766,6 +1781,7 @@ def Test_reset_did_emsg()
Func() Func()
END END
CheckScriptFailure(lines, 'E492:', 8) CheckScriptFailure(lines, 'E492:', 8)
delfunc! g:Func
enddef enddef
def Test_abort_even_with_silent() def Test_abort_even_with_silent()

View File

@ -1878,6 +1878,7 @@ def Test_for_loop_fails()
CheckDefFailure(['for i In range(5)'], 'E690:') CheckDefFailure(['for i In range(5)'], 'E690:')
CheckDefFailure(['var x = 5', 'for x in range(5)'], 'E1017:') CheckDefFailure(['var x = 5', 'for x in range(5)'], 'E1017:')
CheckScriptFailure(['def Func(arg: any)', 'for arg in range(5)', 'enddef', 'defcompile'], 'E1006:') 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 "text"'], 'E1012:')
CheckDefFailure(['for i in xxx'], 'E1001:') CheckDefFailure(['for i in xxx'], 'E1001:')
CheckDefFailure(['endfor'], 'E588:') CheckDefFailure(['endfor'], 'E588:')
@ -2360,12 +2361,14 @@ def Test_vim9_comment()
'vim9script', 'vim9script',
'command Echo echo # comment', 'command Echo echo # comment',
'command Echo # comment', 'command Echo # comment',
'delcommand Echo',
]) ])
CheckScriptFailure([ CheckScriptFailure([
'vim9script', 'vim9script',
'command Echo echo# comment', 'command Echo echo# comment',
'Echo', 'Echo',
], 'E121:') ], 'E121:')
delcommand Echo
CheckScriptFailure([ CheckScriptFailure([
'vim9script', 'vim9script',
'command Echo# comment', 'command Echo# comment',
@ -2375,6 +2378,7 @@ def Test_vim9_comment()
'command Echo echo', 'command Echo echo',
'command Echo# comment', 'command Echo# comment',
], 'E182:') ], 'E182:')
delcommand Echo
CheckScriptSuccess([ CheckScriptSuccess([
'vim9script', 'vim9script',
@ -2432,6 +2436,7 @@ def Test_vim9_comment()
CheckScriptSuccess([ CheckScriptSuccess([
'func Test() " comment', 'func Test() " comment',
'endfunc', 'endfunc',
'delfunc Test',
]) ])
CheckScriptSuccess([ CheckScriptSuccess([
'vim9script', 'vim9script',

View File

@ -1,11 +1,17 @@
" Utility functions for testing vim9 script " 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) func CheckDefSuccess(lines)
call writefile(['def Func()'] + a:lines + ['enddef', 'defcompile'], 'Xdef') let fname = 'Xdef' .. s:sequence
so Xdef let s:sequence += 1
call writefile(['def Func()'] + a:lines + ['enddef', 'defcompile'], fname)
exe 'so ' .. fname
call Func() call Func()
call delete('Xdef') delfunc! Func
call delete(fname)
endfunc endfunc
" Check that "lines" inside ":def" results in an "error" message. " 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 " Add a line before and after to make it less likely that the line number is
" accidentally correct. " accidentally correct.
func CheckDefFailure(lines, error, lnum = -3) func CheckDefFailure(lines, error, lnum = -3)
call writefile(['def Func()', '# comment'] + a:lines + ['#comment', 'enddef', 'defcompile'], 'Xdef') let fname = 'Xdef' .. s:sequence
call assert_fails('so Xdef', a:error, a:lines, a:lnum + 1) call writefile(['def Func()', '# comment'] + a:lines + ['#comment', 'enddef', 'defcompile'], fname)
call delete('Xdef') call assert_fails('so ' .. fname, a:error, a:lines, a:lnum + 1)
delfunc! Func
call delete(fname)
let s:sequence += 1
endfunc endfunc
" Check that "lines" inside ":def" results in an "error" message when executed. " 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 " Add a line before and after to make it less likely that the line number is
" accidentally correct. " accidentally correct.
func CheckDefExecFailure(lines, error, lnum = -3) func CheckDefExecFailure(lines, error, lnum = -3)
call writefile(['def Func()', '# comment'] + a:lines + ['#comment', 'enddef'], 'Xdef') let fname = 'Xdef' .. s:sequence
so Xdef 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 assert_fails('call Func()', a:error, a:lines, a:lnum + 1)
call delete('Xdef') delfunc! Func
call delete(fname)
endfunc endfunc
def CheckScriptFailure(lines: list<string>, error: string, lnum = -3) def CheckScriptFailure(lines: list<string>, error: string, lnum = -3)
writefile(lines, 'Xdef') var fname = 'Xdef' .. s:sequence
assert_fails('so Xdef', error, lines, lnum) s:sequence += 1
delete('Xdef') writefile(lines, fname)
assert_fails('so ' .. fname, error, lines, lnum)
delete(fname)
enddef enddef
def CheckScriptSuccess(lines: list<string>) def CheckScriptSuccess(lines: list<string>)
writefile(lines, 'Xdef') var fname = 'Xdef' .. s:sequence
so Xdef s:sequence += 1
delete('Xdef') writefile(lines, fname)
exe 'so ' .. fname
delete(fname)
enddef enddef
def CheckDefAndScriptSuccess(lines: list<string>) def CheckDefAndScriptSuccess(lines: list<string>)
@ -46,15 +62,15 @@ def CheckDefAndScriptSuccess(lines: list<string>)
CheckScriptSuccess(['vim9script'] + lines) CheckScriptSuccess(['vim9script'] + lines)
enddef enddef
" Check that a command fails both when used in a :def function and when used " Check that a command fails with the same error when used in a :def function
" in Vim9 script. " and when used in Vim9 script.
def CheckDefAndScriptFailure(lines: list<string>, error: string, lnum = -3) def CheckDefAndScriptFailure(lines: list<string>, error: string, lnum = -3)
CheckDefFailure(lines, error, lnum) CheckDefFailure(lines, error, lnum)
CheckScriptFailure(['vim9script'] + lines, error, lnum + 1) CheckScriptFailure(['vim9script'] + lines, error, lnum + 1)
enddef enddef
" Check that a command fails both when executed in a :def function and when " Check that a command fails with the same error when executed in a :def
" used in Vim9 script. " function and when used in Vim9 script.
def CheckDefExecAndScriptFailure(lines: list<string>, error: string, lnum = -3) def CheckDefExecAndScriptFailure(lines: list<string>, error: string, lnum = -3)
CheckDefExecFailure(lines, error, lnum) CheckDefExecFailure(lines, error, lnum)
CheckScriptFailure(['vim9script'] + lines, error, lnum + 1) CheckScriptFailure(['vim9script'] + lines, error, lnum + 1)

View File

@ -750,6 +750,8 @@ static char *(features[]) =
static int included_patches[] = static int included_patches[] =
{ /* Add new patch number below this line */ { /* Add new patch number below this line */
/**/
2092,
/**/ /**/
2091, 2091,
/**/ /**/