Skip to content

Commit 2d870f8

Browse files
committed
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.
1 parent 29d2f45 commit 2d870f8

6 files changed

Lines changed: 61 additions & 21 deletions

File tree

src/testdir/test_quickfix.vim

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5253,7 +5253,7 @@ func Test_quickfix_window_fails_to_open()
52535253
call delete('XquickfixFails')
52545254
endfunc
52555255

5256-
" Test for updating the quickfix buffer whenever the assocaited quickfix list
5256+
" Test for updating the quickfix buffer whenever the associated quickfix list
52575257
" is changed.
52585258
func Xqfbuf_update(cchar)
52595259
call s:setup_commands(a:cchar)

src/testdir/test_vim9_assign.vim

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -953,6 +953,7 @@ def Test_heredoc()
953953
call Func()
954954
[END]
955955
CheckScriptFailure(lines, 'E990:')
956+
delfunc! g:Func
956957
enddef
957958

958959
def Test_let_func_call()

src/testdir/test_vim9_func.vim

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -199,7 +199,9 @@ def Test_call_default_args()
199199
MyDefaultSecond('test', false)->assert_equal('none')
200200

201201
CheckScriptFailure(['def Func(arg: number = asdf)', 'enddef', 'defcompile'], 'E1001:')
202+
delfunc g:Func
202203
CheckScriptFailure(['def Func(arg: number = "text")', 'enddef', 'defcompile'], 'E1013: Argument 1: type mismatch, expected number but got string')
204+
delfunc g:Func
203205
enddef
204206

205207
def Test_nested_function()
@@ -326,6 +328,7 @@ def Test_global_local_function()
326328
enddef
327329
g:Func()->assert_equal('global')
328330
Func()->assert_equal('local')
331+
delfunc g:Func
329332
END
330333
CheckScriptSuccess(lines)
331334

@@ -605,6 +608,7 @@ def Test_assign_to_argument()
605608
l[0]->assert_equal('value')
606609

607610
CheckScriptFailure(['def Func(arg: number)', 'arg = 3', 'enddef', 'defcompile'], 'E1090:')
611+
delfunc! g:Func
608612
enddef
609613

610614
" These argument names are reserved in legacy functions.
@@ -763,33 +767,41 @@ def Test_return_type_wrong()
763767
'return "a"',
764768
'enddef',
765769
'defcompile'], 'expected number but got string')
770+
delfunc! g:Func
766771
CheckScriptFailure([
767772
'def Func(): string',
768773
'return 1',
769774
'enddef',
770775
'defcompile'], 'expected string but got number')
776+
delfunc! g:Func
771777
CheckScriptFailure([
772778
'def Func(): void',
773779
'return "a"',
774780
'enddef',
775781
'defcompile'],
776782
'E1096: Returning a value in a function without a return type')
783+
delfunc! g:Func
777784
CheckScriptFailure([
778785
'def Func()',
779786
'return "a"',
780787
'enddef',
781788
'defcompile'],
782789
'E1096: Returning a value in a function without a return type')
790+
delfunc! g:Func
783791

784792
CheckScriptFailure([
785793
'def Func(): number',
786794
'return',
787795
'enddef',
788796
'defcompile'], 'E1003:')
797+
delfunc! g:Func
789798

790799
CheckScriptFailure(['def Func(): list', 'return []', 'enddef'], 'E1008:')
800+
delfunc! g:Func
791801
CheckScriptFailure(['def Func(): dict', 'return {}', 'enddef'], 'E1008:')
802+
delfunc! g:Func
792803
CheckScriptFailure(['def Func()', 'return 1'], 'E1057:')
804+
delfunc! g:Func
793805

794806
CheckScriptFailure([
795807
'vim9script',
@@ -1248,6 +1260,7 @@ def Test_error_reporting()
12481260
v:exception->assert_match('Invalid command: invalid')
12491261
v:throwpoint->assert_match(', line 3$')
12501262
endtry
1263+
delfunc! g:Func
12511264

12521265
# comment lines after the start of the function
12531266
lines =<< trim END
@@ -1268,6 +1281,7 @@ def Test_error_reporting()
12681281
v:exception->assert_match('Invalid command: invalid')
12691282
v:throwpoint->assert_match(', line 4$')
12701283
endtry
1284+
delfunc! g:Func
12711285

12721286
lines =<< trim END
12731287
vim9script
@@ -1286,6 +1300,7 @@ def Test_error_reporting()
12861300
catch /E716:/
12871301
v:throwpoint->assert_match('_Func, line 3$')
12881302
endtry
1303+
delfunc! g:Func
12891304

12901305
delete('Xdef')
12911306
enddef
@@ -1766,6 +1781,7 @@ def Test_reset_did_emsg()
17661781
Func()
17671782
END
17681783
CheckScriptFailure(lines, 'E492:', 8)
1784+
delfunc! g:Func
17691785
enddef
17701786

17711787
def Test_abort_even_with_silent()

src/testdir/test_vim9_script.vim

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1878,6 +1878,7 @@ def Test_for_loop_fails()
18781878
CheckDefFailure(['for i In range(5)'], 'E690:')
18791879
CheckDefFailure(['var x = 5', 'for x in range(5)'], 'E1017:')
18801880
CheckScriptFailure(['def Func(arg: any)', 'for arg in range(5)', 'enddef', 'defcompile'], 'E1006:')
1881+
delfunc! g:Func
18811882
CheckDefFailure(['for i in "text"'], 'E1012:')
18821883
CheckDefFailure(['for i in xxx'], 'E1001:')
18831884
CheckDefFailure(['endfor'], 'E588:')
@@ -2360,12 +2361,14 @@ def Test_vim9_comment()
23602361
'vim9script',
23612362
'command Echo echo # comment',
23622363
'command Echo # comment',
2364+
'delcommand Echo',
23632365
])
23642366
CheckScriptFailure([
23652367
'vim9script',
23662368
'command Echo echo# comment',
23672369
'Echo',
23682370
], 'E121:')
2371+
delcommand Echo
23692372
CheckScriptFailure([
23702373
'vim9script',
23712374
'command Echo# comment',
@@ -2375,6 +2378,7 @@ def Test_vim9_comment()
23752378
'command Echo echo',
23762379
'command Echo# comment',
23772380
], 'E182:')
2381+
delcommand Echo
23782382

23792383
CheckScriptSuccess([
23802384
'vim9script',
@@ -2432,6 +2436,7 @@ def Test_vim9_comment()
24322436
CheckScriptSuccess([
24332437
'func Test() " comment',
24342438
'endfunc',
2439+
'delfunc Test',
24352440
])
24362441
CheckScriptSuccess([
24372442
'vim9script',

src/testdir/vim9.vim

Lines changed: 36 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -1,60 +1,76 @@
11
" Utility functions for testing vim9 script
22

3-
" Check that "lines" inside ":def" has no error.
3+
" Use a different file name for each run.
4+
let s:sequence = 1
5+
6+
" Check that "lines" inside a ":def" function has no error.
47
func CheckDefSuccess(lines)
5-
call writefile(['def Func()'] + a:lines + ['enddef', 'defcompile'], 'Xdef')
6-
so Xdef
8+
let fname = 'Xdef' .. s:sequence
9+
let s:sequence += 1
10+
call writefile(['def Func()'] + a:lines + ['enddef', 'defcompile'], fname)
11+
exe 'so ' .. fname
712
call Func()
8-
call delete('Xdef')
13+
delfunc! Func
14+
call delete(fname)
915
endfunc
1016

1117
" Check that "lines" inside ":def" results in an "error" message.
1218
" If "lnum" is given check that the error is reported for this line.
1319
" Add a line before and after to make it less likely that the line number is
1420
" accidentally correct.
1521
func CheckDefFailure(lines, error, lnum = -3)
16-
call writefile(['def Func()', '# comment'] + a:lines + ['#comment', 'enddef', 'defcompile'], 'Xdef')
17-
call assert_fails('so Xdef', a:error, a:lines, a:lnum + 1)
18-
call delete('Xdef')
22+
let fname = 'Xdef' .. s:sequence
23+
call writefile(['def Func()', '# comment'] + a:lines + ['#comment', 'enddef', 'defcompile'], fname)
24+
call assert_fails('so ' .. fname, a:error, a:lines, a:lnum + 1)
25+
delfunc! Func
26+
call delete(fname)
27+
let s:sequence += 1
1928
endfunc
2029

2130
" Check that "lines" inside ":def" results in an "error" message when executed.
2231
" If "lnum" is given check that the error is reported for this line.
2332
" Add a line before and after to make it less likely that the line number is
2433
" accidentally correct.
2534
func CheckDefExecFailure(lines, error, lnum = -3)
26-
call writefile(['def Func()', '# comment'] + a:lines + ['#comment', 'enddef'], 'Xdef')
27-
so Xdef
35+
let fname = 'Xdef' .. s:sequence
36+
let s:sequence += 1
37+
call writefile(['def Func()', '# comment'] + a:lines + ['#comment', 'enddef'], fname)
38+
exe 'so ' .. fname
2839
call assert_fails('call Func()', a:error, a:lines, a:lnum + 1)
29-
call delete('Xdef')
40+
delfunc! Func
41+
call delete(fname)
3042
endfunc
3143

3244
def CheckScriptFailure(lines: list<string>, error: string, lnum = -3)
33-
writefile(lines, 'Xdef')
34-
assert_fails('so Xdef', error, lines, lnum)
35-
delete('Xdef')
45+
var fname = 'Xdef' .. s:sequence
46+
s:sequence += 1
47+
writefile(lines, fname)
48+
assert_fails('so ' .. fname, error, lines, lnum)
49+
delete(fname)
3650
enddef
3751

3852
def CheckScriptSuccess(lines: list<string>)
39-
writefile(lines, 'Xdef')
40-
so Xdef
41-
delete('Xdef')
53+
var fname = 'Xdef' .. s:sequence
54+
s:sequence += 1
55+
writefile(lines, fname)
56+
exe 'so ' .. fname
57+
delete(fname)
4258
enddef
4359

4460
def CheckDefAndScriptSuccess(lines: list<string>)
4561
CheckDefSuccess(lines)
4662
CheckScriptSuccess(['vim9script'] + lines)
4763
enddef
4864

49-
" Check that a command fails both when used in a :def function and when used
50-
" in Vim9 script.
65+
" Check that a command fails with the same error when used in a :def function
66+
" and when used in Vim9 script.
5167
def CheckDefAndScriptFailure(lines: list<string>, error: string, lnum = -3)
5268
CheckDefFailure(lines, error, lnum)
5369
CheckScriptFailure(['vim9script'] + lines, error, lnum + 1)
5470
enddef
5571

56-
" Check that a command fails both when executed in a :def function and when
57-
" used in Vim9 script.
72+
" Check that a command fails with the same error when executed in a :def
73+
" function and when used in Vim9 script.
5874
def CheckDefExecAndScriptFailure(lines: list<string>, error: string, lnum = -3)
5975
CheckDefExecFailure(lines, error, lnum)
6076
CheckScriptFailure(['vim9script'] + lines, error, lnum + 1)

src/version.c

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -750,6 +750,8 @@ static char *(features[]) =
750750

751751
static int included_patches[] =
752752
{ /* Add new patch number below this line */
753+
/**/
754+
2092,
753755
/**/
754756
2091,
755757
/**/

0 commit comments

Comments
 (0)