1
0
forked from aniani/vim

patch 9.0.0766: too many delete() calls in tests

Problem:    Too many delete() calls in tests.
Solution:   Use deferred delete where possible.
This commit is contained in:
Bram Moolenaar 2022-10-15 20:06:33 +01:00
parent 36343ae0fb
commit 0e9bdad545
7 changed files with 156 additions and 287 deletions

View File

@ -921,9 +921,8 @@ def Test_vim9_single_char_vars()
assert_equal(333, v)
assert_equal(444, w)
END
writefile(lines, 'Xsinglechar')
writefile(lines, 'Xsinglechar', 'D')
source Xsinglechar
delete('Xsinglechar')
enddef
def Test_assignment_list()
@ -1940,13 +1939,12 @@ def Test_var_func_call()
# env var is always a string
var env = $TERM
END
writefile(lines, 'Xfinished')
writefile(lines, 'Xfinished', 'D')
source Xfinished
# GetValue() is not called during discovery phase
assert_equal(1, g:count)
unlet g:count
delete('Xfinished')
enddef
def Test_var_missing_type()
@ -2532,7 +2530,7 @@ def Test_unlet()
'DelChangedtick(b:)',
], 'E795:')
writefile(['vim9script', 'export var svar = 1234'], 'XunletExport.vim')
writefile(['vim9script', 'export var svar = 1234'], 'XunletExport.vim', 'D')
var lines =<< trim END
vim9script
import './XunletExport.vim' as exp
@ -2542,7 +2540,6 @@ def Test_unlet()
defcompile
END
v9.CheckScriptFailure(lines, 'E1260:', 1)
delete('XunletExport.vim')
$ENVVAR = 'foobar'
assert_equal('foobar', $ENVVAR)
@ -2701,11 +2698,9 @@ def Test_abort_after_error()
var x: string
x = strpart(1, 2)
END
writefile(lines, 'Xtestscript')
writefile(lines, 'Xtestscript', 'D')
var expected = 'E1174: String required for argument 1'
assert_fails('so Xtestscript', [expected, expected], 3)
delete('Xtestscript')
enddef
def Test_using_s_var_in_function()

View File

@ -12,7 +12,7 @@ func Test_internalfunc_arg_error()
enddef
defcompile
END
call writefile(l, 'Xinvalidarg')
call writefile(l, 'Xinvalidarg', 'D')
call assert_fails('so Xinvalidarg', 'E118:', '', 1, 'FArgErr')
let l =<< trim END
def! FArgErr(): float
@ -22,7 +22,6 @@ func Test_internalfunc_arg_error()
END
call writefile(l, 'Xinvalidarg')
call assert_fails('so Xinvalidarg', 'E119:', '', 1, 'FArgErr')
call delete('Xinvalidarg')
endfunc
" Test for builtin functions returning different types
@ -52,7 +51,7 @@ func Test_InternalFuncRetType()
return environ()
enddef
END
call writefile(lines, 'Xscript')
call writefile(lines, 'Xscript', 'D')
source Xscript
call RetFloat()->assert_equal(2.0)
@ -61,7 +60,6 @@ func Test_InternalFuncRetType()
call RetListDictAny()->assert_notequal([])
call RetDictNumber()->assert_notequal({})
call RetDictString()->assert_notequal({})
call delete('Xscript')
endfunc
def Test_abs()
@ -1984,7 +1982,7 @@ def Test_getscriptinfo()
def g:Xscript_def_func2()
enddef
END
writefile(lines1, 'X22script92')
writefile(lines1, 'X22script92', 'D')
var lines2 =<< trim END
source X22script92
@ -2006,7 +2004,6 @@ def Test_getscriptinfo()
endfor
END
v9.CheckDefAndScriptSuccess(lines2)
delete('X22script92')
enddef
def Test_gettabinfo()
@ -3238,7 +3235,7 @@ enddef
def Test_readblob()
var blob = 0z12341234
writefile(blob, 'Xreadblob')
writefile(blob, 'Xreadblob', 'D')
var read: blob = readblob('Xreadblob')
assert_equal(blob, read)
@ -3247,12 +3244,11 @@ def Test_readblob()
END
v9.CheckDefAndScriptFailure(lines, 'E1012: Type mismatch; expected list<string> but got blob', 1)
v9.CheckDefExecAndScriptFailure(['readblob("")'], 'E484: Can''t open file <empty>')
delete('Xreadblob')
enddef
def Test_readfile()
var text = ['aaa', 'bbb', 'ccc']
writefile(text, 'Xreadfile')
writefile(text, 'Xreadfile', 'D')
var read: list<string> = readfile('Xreadfile')
assert_equal(text, read)
assert_equal([7, 7, 7], readfile('Xreadfile')->map((_, _) => 7))
@ -3261,7 +3257,6 @@ def Test_readfile()
var read: dict<string> = readfile('Xreadfile')
END
v9.CheckDefAndScriptFailure(lines, 'E1012: Type mismatch; expected dict<string> but got list<string>', 1)
delete('Xreadfile')
v9.CheckDefAndScriptFailure(['readfile("a", 0z10)'], ['E1013: Argument 2: type mismatch, expected string but got blob', 'E1174: String required for argument 2'])
v9.CheckDefAndScriptFailure(['readfile("a", "b", "c")'], ['E1013: Argument 3: type mismatch, expected number but got string', 'E1210: Number required for argument 3'])
@ -4131,9 +4126,8 @@ def Test_sort_compare_func_fails()
vim9script
echo ['a', 'b', 'c']->sort((a: number, b: number) => 0)
END
writefile(lines, 'Xbadsort')
writefile(lines, 'Xbadsort', 'D')
assert_fails('source Xbadsort', ['E1013:', 'E702:'])
delete('Xbadsort')
lines =<< trim END
var l = [1, 2, 3]
@ -4822,7 +4816,7 @@ func Test_win_gotoid_in_mapping()
call feedkeys("\<F3>\<LeftMouse>\<LeftRelease>", "xt")
endfunc
END
call writefile(lines, 'Xgotoscript')
call writefile(lines, 'Xgotoscript', 'D')
let buf = RunVimInTerminal('-S Xgotoscript', #{rows: 15, wait_for_ruler: 0})
" wait longer here, since we didn't wait for the ruler
call VerifyScreenDump(buf, 'Test_win_gotoid_1', #{wait: 3000})
@ -4833,7 +4827,6 @@ func Test_win_gotoid_in_mapping()
call VerifyScreenDump(buf, 'Test_win_gotoid_3', {})
call StopVimInTerminal(buf)
call delete('Xgotoscript')
endif
endfunc

View File

@ -120,12 +120,11 @@ def Test_cmdmod_execute()
vim9script
export var exported = 'x'
END
writefile(lines, 'Xvim9import.vim')
writefile(lines, 'Xvim9import.vim', 'D')
lines =<< trim END
legacy exe "import './Xvim9import.vim'"
END
v9.CheckScriptSuccess(lines)
delete('Xvim9import.vim')
# "legacy" does not aply to a called function
lines =<< trim END
@ -331,7 +330,7 @@ def Test_hardcopy_wildcards()
enddef
def Test_syn_include_wildcards()
writefile(['syn keyword Found found'], 'Xthemine.vim')
writefile(['syn keyword Found found'], 'Xthemine.vim', 'D')
var save_rtp = &rtp
&rtp = '.'
@ -340,7 +339,6 @@ def Test_syn_include_wildcards()
assert_match('Found.* contained found', execute('syn list Found'))
&rtp = save_rtp
delete('Xthemine.vim')
enddef
def Test_echo_linebreak()
@ -932,7 +930,7 @@ func Test_command_modifier_confirm()
confirm write Xcmodfile
enddef
END
call writefile(lines, 'Xconfirmscript')
call writefile(lines, 'Xconfirmscript', 'D')
call writefile(['empty'], 'Xcmodfile')
let buf = RunVimInTerminal('-S Xconfirmscript', {'rows': 8})
call term_sendkeys(buf, ":call Getout()\n")
@ -946,7 +944,6 @@ func Test_command_modifier_confirm()
call assert_equal(['changed'], readfile('Xcmodfile'))
call delete('Xcmodfile')
call delete('.Xcmodfile.swp') " in case Vim was killed
call delete('Xconfirmscript')
endfunc
def Test_command_modifiers_keep()

View File

@ -313,7 +313,7 @@ def s:ScriptFuncPush()
enddef
def Test_disassemble_push()
mkdir('Xdisdir/autoload', 'p')
mkdir('Xdisdir/autoload', 'pR')
var save_rtp = &rtp
exe 'set rtp^=' .. getcwd() .. '/Xdisdir'
@ -340,12 +340,11 @@ def Test_disassemble_push()
END
v9.CheckScriptSuccess(lines)
delete('Xdisdir', 'rf')
&rtp = save_rtp
enddef
def Test_disassemble_import_autoload()
writefile(['vim9script'], 'XimportAL.vim')
writefile(['vim9script'], 'XimportAL.vim', 'D')
var lines =<< trim END
vim9script
@ -380,8 +379,6 @@ def Test_disassemble_import_autoload()
res)
END
v9.CheckScriptSuccess(lines)
delete('XimportAL.vim')
enddef
def s:ScriptFuncStore()
@ -2440,7 +2437,7 @@ def Test_vim9script_forward_func()
enddef
g:res_FuncOne = execute('disass FuncOne')
END
writefile(lines, 'Xdisassemble')
writefile(lines, 'Xdisassemble', 'D')
source Xdisassemble
# check that the first function calls the second with DCALL
@ -2450,7 +2447,6 @@ def Test_vim9script_forward_func()
'\d RETURN',
g:res_FuncOne)
delete('Xdisassemble')
unlet g:res_FuncOne
enddef
@ -2901,51 +2897,50 @@ def Test_disassemble_nextcmd()
enddef
def Test_disassemble_after_reload()
var lines =<< trim END
vim9script
if exists('g:ThisFunc')
finish
endif
var name: any
def g:ThisFunc(): number
g:name = name
return 0
enddef
def g:ThatFunc(): number
name = g:name
return 0
enddef
END
lines->writefile('Xreload.vim')
var lines =<< trim END
vim9script
if exists('g:ThisFunc')
finish
endif
var name: any
def g:ThisFunc(): number
g:name = name
return 0
enddef
def g:ThatFunc(): number
name = g:name
return 0
enddef
END
lines->writefile('Xreload.vim', 'D')
source Xreload.vim
g:ThisFunc()
g:ThatFunc()
source Xreload.vim
g:ThisFunc()
g:ThatFunc()
source Xreload.vim
var res = execute('disass g:ThisFunc')
assert_match('ThisFunc\_s*' ..
'g:name = name\_s*' ..
'\d LOADSCRIPT \[deleted\] from .*/Xreload.vim\_s*' ..
'\d STOREG g:name\_s*' ..
'return 0\_s*' ..
'\d PUSHNR 0\_s*' ..
'\d RETURN\_s*',
res)
source Xreload.vim
var res = execute('disass g:ThisFunc')
assert_match('ThisFunc\_s*' ..
'g:name = name\_s*' ..
'\d LOADSCRIPT \[deleted\] from .*/Xreload.vim\_s*' ..
'\d STOREG g:name\_s*' ..
'return 0\_s*' ..
'\d PUSHNR 0\_s*' ..
'\d RETURN\_s*',
res)
res = execute('disass g:ThatFunc')
assert_match('ThatFunc\_s*' ..
'name = g:name\_s*' ..
'\d LOADG g:name\_s*' ..
'\d STORESCRIPT \[deleted\] in .*/Xreload.vim\_s*' ..
'return 0\_s*' ..
'\d PUSHNR 0\_s*' ..
'\d RETURN\_s*',
res)
res = execute('disass g:ThatFunc')
assert_match('ThatFunc\_s*' ..
'name = g:name\_s*' ..
'\d LOADG g:name\_s*' ..
'\d STORESCRIPT \[deleted\] in .*/Xreload.vim\_s*' ..
'return 0\_s*' ..
'\d PUSHNR 0\_s*' ..
'\d RETURN\_s*',
res)
delete('Xreload.vim')
delfunc g:ThisFunc
delfunc g:ThatFunc
delfunc g:ThisFunc
delfunc g:ThatFunc
enddef
def s:MakeString(x: number): string

View File

@ -3490,7 +3490,7 @@ def Test_expr9_autoload_var()
var auto_lines =<< trim END
let autofile#var = 'found'
END
mkdir('Xruntime/autoload', 'p')
mkdir('Xruntime/autoload', 'pR')
writefile(auto_lines, 'Xruntime/autoload/autofile.vim')
var save_rtp = &rtp
&rtp = getcwd() .. '/Xruntime,' .. &rtp
@ -3506,7 +3506,6 @@ def Test_expr9_autoload_var()
v9.CheckDefExecAndScriptFailure(lines, 'E121: Undefined variable: autofile#other')
&rtp = save_rtp
delete('Xruntime', 'rf')
enddef
def Test_expr9_call_autoload()
@ -3515,7 +3514,7 @@ def Test_expr9_call_autoload()
return 'found'
enddef
END
mkdir('Xruntime/autoload', 'p')
mkdir('Xruntime/autoload', 'pR')
writefile(auto_lines, 'Xruntime/autoload/some.vim')
var save_rtp = &rtp
&rtp = getcwd() .. '/Xruntime,' .. &rtp
@ -3523,7 +3522,6 @@ def Test_expr9_call_autoload()
assert_equal('found', some#func())
&rtp = save_rtp
delete('Xruntime', 'rf')
enddef
def Test_expr9_method_call()
@ -3640,7 +3638,7 @@ def Test_expr9_method_call_import()
return map(items, (_, i) => i * i)
enddef
END
call writefile(lines, 'Xsquare.vim')
call writefile(lines, 'Xsquare.vim', 'D')
lines =<< trim END
vim9script
@ -3663,8 +3661,6 @@ def Test_expr9_method_call_import()
echo range(5)->Xsquare.NoSuchFunc()
END
v9.CheckScriptFailure(lines, 'E1048: Item not found in script: NoSuchFunc')
delete('Xsquare.vim')
enddef

File diff suppressed because it is too large Load Diff

View File

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