Problem: Too many delete() calls in tests.
Solution: Use deferred delete where possible.
" try several sizes
for size in range(20, 500, 33)
- call writefile(contents[0:size], 'Xundofile')
+ call writefile(contents[0:size], 'Xundofile', 'D')
call assert_fails('rundo Xundofile', 'E825:')
endfor
bwipe!
- call delete('Xundofile')
endfunc
func Test_rundo_errors()
call assert_fails('rundo XfileDoesNotExist', 'E822:')
- call writefile(['abc'], 'Xundofile')
+ call writefile(['abc'], 'Xundofile', 'D')
call assert_fails('rundo Xundofile', 'E823:')
-
- call delete('Xundofile')
endfunc
func Test_undofile_next()
qall!
[CODE]
- call writefile(lines, 'Xtest.vim')
+ call writefile(lines, 'Xtest.vim', 'D')
let res = system(GetVimCommandClean() .. ' -es -X -S Xtest.vim')
call assert_equal(0, v:shell_error)
let m = matchstr(res, 'function F6()[^[:print:]]*[[:print:]]*')
call assert_match(' line 23$', m)
-
- call delete('Xtest.vim')
endfunc
" Test for defining a function reference in the global scope
:qall
[CODE]
- call writefile(lines, 'Xscript')
+ call writefile(lines, 'Xscript', 'D')
if RunVim([], [], '-s Xscript')
call assert_equal([], readfile('Xresult'))
endif
call delete('Xresult')
- call delete('Xscript')
endfunc
" Test for errors in defining new functions
call assert_fails('call feedkeys(":func d.F1()\<CR>", "xt")', 'E717:')
" Define an autoload function with an incorrect file name
- call writefile(['func foo#Bar()', 'return 1', 'endfunc'], 'Xscript')
+ call writefile(['func foo#Bar()', 'return 1', 'endfunc'], 'Xscript', 'D')
call assert_fails('source Xscript', 'E746:')
- call delete('Xscript')
" Try to list functions using an invalid search pattern
call assert_fails('function /\%(/', 'E53:')
" Test for calling return outside of a function
func Test_return_outside_func()
- call writefile(['return 10'], 'Xscript')
+ call writefile(['return 10'], 'Xscript', 'D')
call assert_fails('source Xscript', 'E133:')
- call delete('Xscript')
endfunc
" Test for errors in calling a function
endfunc
func Test_redefine_on_reload()
- call writefile(['command ExistingCommand echo "yes"'], 'Xcommandexists')
+ call writefile(['command ExistingCommand echo "yes"'], 'Xcommandexists', 'D')
call assert_equal(0, exists(':ExistingCommand'))
source Xcommandexists
call assert_equal(2, exists(':ExistingCommand'))
call assert_equal(2, exists(':ExistingCommand'))
" But redefining in another script is not OK.
- call writefile(['command ExistingCommand echo "yes"'], 'Xcommandexists2')
+ call writefile(['command ExistingCommand echo "yes"'], 'Xcommandexists2', 'D')
call assert_fails('source Xcommandexists2', 'E174:')
- call delete('Xcommandexists2')
" And defining twice in one script is not OK.
delcommand ExistingCommand
call assert_fails('source Xcommandexists', 'E174:')
call assert_equal(2, exists(':ExistingCommand'))
- call delete('Xcommandexists')
delcommand ExistingCommand
endfunc
@a = save
}
END
- call writefile(lines, 'Xlegacy')
+ call writefile(lines, 'Xlegacy', 'D')
source Xlegacy
let lines =<< trim END
call assert_equal('something', g:someExpr)
call assert_equal('also', @a)
END
- call writefile(lines, 'Xother')
+ call writefile(lines, 'Xother', 'D')
source Xother
unlet g:someExpr
- call delete('Xlegacy')
- call delete('Xother')
delcommand Rename
endfunc
\ '|copied as-is',
\ '|and one more',
\ ]
- call writefile(lines, 'Xviminfo')
+ call writefile(lines, 'Xviminfo', 'D')
rviminfo Xviminfo
call assert_equal('asdf', @/)
endif
endfor
call assert_equal(3, done)
-
- call delete('Xviminfo')
endfunc
func Test_global_vars()
\ "!GLOB_BLOB_3\tBLO\t0z1x",
\ "!GLOB_BLOB_4\tBLO\t0z12 ab",
\ "!GLOB_LIST_1\tLIS\t1 2",
- \ "!GLOB_DICT_1\tDIC\t1 2"], 'Xviminfo')
+ \ "!GLOB_DICT_1\tDIC\t1 2"], 'Xviminfo', 'D')
call assert_fails('rv! Xviminfo', 'E488:')
call assert_equal('123', g:GLOB_BLOB_1)
call assert_equal(1, type(g:GLOB_BLOB_1))
call assert_equal('1 2', g:GLOB_DICT_1)
call assert_equal(1, type(g:GLOB_DICT_1))
- call delete('Xviminfo')
set viminfo-=!
endfunc
call add(lines, '|1,"x\') " trailing backslash
call add(lines, '|1,,,,') "trailing comma
call add(lines, '|1,>234') " trailing continuation line
- call writefile(lines, 'Xviminfo')
+ call writefile(lines, 'Xviminfo', 'D')
rviminfo Xviminfo
call delete('Xviminfo')
call add(lines, '|4,20,1,1,1,"x"') " invalid value for file name
call add(lines, '|4,49,0,1,1,"x"') " invalid value for line number
- call writefile(lines, 'Xviminfo')
+ call writefile(lines, 'Xviminfo', 'D')
rviminfo Xviminfo
- call delete('Xviminfo')
endfunc
func Test_viminfo_file_marks()
\ '|4,66,1,0,0,"/tmp/nothing"',
\ "",
\ ]
- call writefile(lines, 'Xviminfo')
+ call writefile(lines, 'Xviminfo', 'D')
delmark B
rviminfo Xviminfo
- call delete('Xviminfo')
call assert_equal(1, line("'B"))
delmark B
endfunc
func Test_viminfo_file_mark_unloaded_buf()
let save_viminfo = &viminfo
set viminfo&vim
- call writefile(repeat(['vim'], 10), 'Xfile1')
+ call writefile(repeat(['vim'], 10), 'Xfile1', 'D')
%bwipe
edit! Xfile1
call setpos("'u", [0, 3, 1, 0])
call assert_equal([0, 3, 1, 0], getpos("'u"))
call assert_equal([0, 5, 1, 0], getpos("'v"))
%bwipe
- call delete('Xfile1')
call delete('Xviminfo')
let &viminfo = save_viminfo
endfunc
\ "\t\"\t11\t0",
\ "",
\ ]
- call writefile(lines, 'Xviminfo')
+ call writefile(lines, 'Xviminfo', 'D')
delmark E
edit /tmp/file_two.txt
rviminfo! Xviminfo
- call delete('Xviminfo')
call assert_equal('h viminfo', histget(':'))
call assert_equal('session', histget('/'))
call assert_fails('rviminfo xyz', 'E195:')
" Illegal starting character
- call writefile(["a 123"], 'Xviminfo')
+ call writefile(["a 123"], 'Xviminfo', 'D')
call assert_fails('rv Xviminfo', 'E575:')
" Illegal register name in the viminfo file
call writefile(repeat(['"@'], 15), 'Xviminfo')
call assert_fails('rv Xviminfo', 'E577:')
-
- call delete('Xviminfo')
endfunc
" Test for saving and restoring last substitute string in viminfo
\ " :echo 'Hello'\<CR>",
\ "",
\ ]
- call writefile(lines, 'Xviminfo')
+ call writefile(lines, 'Xviminfo', 'D')
let @a = 'one'
let @b = 'two'
let @m = 'three'
call assert_equal(":echo 'Hello'\<CR>", getreg('m'))
call assert_equal('Vim', getreg('"'))
call assert_equal("\nHello", execute('normal @@'))
- call delete('Xviminfo')
+
let @" = ''
endfunc
set viminfo+=<200
let lines = ['"r CHAR 0']
call extend(lines, repeat(["\tsun is rising"], 200))
- call writefile(lines, 'Xviminfo')
+ call writefile(lines, 'Xviminfo', 'D')
let @r = ''
rviminfo! Xviminfo
call assert_equal(join(repeat(["sun is rising"], 200), "\n"), @r)
- call delete('Xviminfo')
+
let @r = ''
let &viminfo = save_viminfo
endfunc
set viminfofile=NONE
wviminfo Xviminfo
call assert_false(filereadable('Xviminfo'))
- call writefile([''], 'Xviminfo')
+ call writefile([''], 'Xviminfo', 'D')
call assert_fails('rviminfo Xviminfo', 'E195:')
- call delete('Xviminfo')
+
let &viminfofile = save_vif
endfunc
func Test_viminfo_perm()
CheckUnix
CheckNotRoot
- call writefile([''], 'Xviminfo')
+ call writefile([''], 'Xviminfo', 'D')
call setfperm('Xviminfo', 'r-x------')
call assert_fails('wviminfo Xviminfo', 'E137:')
call setfperm('Xviminfo', '--x------')
call assert_fails('rviminfo Xviminfo', 'E195:')
- call delete('Xviminfo')
" Try to write the viminfo to a directory
- call mkdir('Xvifdir')
+ call mkdir('Xvifdir', 'R')
call assert_fails('wviminfo Xvifdir', 'E137:')
call assert_fails('rviminfo Xvifdir', 'E195:')
- call delete('Xvifdir', 'rf')
endfunc
" Test for writing to an existing viminfo file merges the file marks
%argdelete
%bwipe
- call writefile(repeat(['editor'], 10), 'Xbufa')
- call writefile(repeat(['Vim'], 10), 'Xbufb')
+ call writefile(repeat(['editor'], 10), 'Xbufa', 'D')
+ call writefile(repeat(['Vim'], 10), 'Xbufb', 'D')
" set marks in buffers
call test_settime(10)
" cleanup
%bwipe
call delete('Xviminfo')
- call delete('Xbufa')
- call delete('Xbufb')
call test_settime(0)
let &viminfo=save_viminfo
endfunc
w! Xnew-file.txt
qall
[CODE]
- call writefile(commands, 'Xviminfotest')
+ call writefile(commands, 'Xviminfotest', 'D')
let buf = RunVimInTerminal('-S Xviminfotest', #{wait_for_ruler: 0})
call WaitForAssert({-> assert_equal("finished", term_getstatus(buf))})
rviminfo! Xviminfofile
call assert_match('Xnew-file.txt$', v:oldfiles[0])
call assert_equal(1, len(v:oldfiles))
+
call delete('Xviminfofile')
- call delete('Xviminfotest')
call delete('Xnew-file.txt')
let v:oldfiles = test_null_list()
call add(lines, '|1,4')
call add(lines, '> ' .. fnamemodify('a.txt', ':p:~'))
call add(lines, "\tb\t7\t0\n")
- call writefile(lines, 'Xviminfo')
+ call writefile(lines, 'Xviminfo', 'D')
edit b.txt
call setline(1, range(1, 20))
12mark b
edit b.txt
rviminfo! Xviminfo
call assert_equal(12, line("'b"))
- call delete('Xviminfo')
endfunc
" Test for merging the jump list from a old viminfo file
call add(lines, "-' 20 1 " .. fnamemodify('a.txt', ':p:~'))
call add(lines, "-' 30 1 " .. fnamemodify('b.txt', ':p:~'))
call add(lines, "-' 40 1 " .. fnamemodify('b.txt', ':p:~'))
- call writefile(lines, 'Xviminfo')
+ call writefile(lines, 'Xviminfo', 'D')
clearjumps
rviminfo! Xviminfo
let l = getjumplist()[0]
call assert_equal([40, 30, 20, 10], [l[0].lnum, l[1].lnum, l[2].lnum,
\ l[3].lnum])
bw!
- call delete('Xviminfo')
endfunc
" vim: shiftwidth=2 sts=2 expandtab
call writefile(v:errors, 'Xtest.out')
qall
END
- call writefile(init, 'Xtest.vim')
+ call writefile(init, 'Xtest.vim', 'D')
call writefile(a:test, 'Xtest.vim', 'a')
- call writefile(a:verify, 'Xverify.vim')
+ call writefile(a:verify, 'Xverify.vim', 'D')
call writefile(cleanup, 'Xverify.vim', 'a')
call RunVim([], [], "-S Xtest.vim -S Xverify.vim")
call assert_equal([], readfile('Xtest.out'))
call delete('Xtest.out')
- call delete('Xtest.vim')
- call delete('Xverify.vim')
endfunc
"-------------------------------------------------------------------------------
let code =<< trim END
endif
END
- call writefile(code, 'Xtest')
+ call writefile(code, 'Xtest', 'D')
call AssertException(['source Xtest'], 'Vim(endif):E580: :endif without :if')
" :endif without :if
END
call writefile(code, 'Xtest')
call AssertException(['source Xtest'], 'Vim(elseif):E584: :elseif after :else')
-
- call delete('Xtest')
endfunc
"-------------------------------------------------------------------------------
endwhile
endif
END
- call writefile(code, 'Xtest')
+ call writefile(code, 'Xtest', 'D')
call AssertException(['source Xtest'], 'Vim(endwhile):E588: :endwhile without :while')
" Missing :endif
END
call writefile(code, 'Xtest')
call AssertException(['source Xtest'], 'Vim(endwhile):E588: :endwhile without :while')
-
- call delete('Xtest')
endfunc
"-------------------------------------------------------------------------------
let code =<< trim END
continue
END
- call writefile(code, 'Xtest')
+ call writefile(code, 'Xtest', 'D')
call AssertException(['source Xtest'], 'Vim(continue):E586: :continue without :while or :for')
" :continue without :while
END
call writefile(code, 'Xtest')
call AssertException(['source Xtest'], 'Vim(break):E587: :break without :while or :for')
-
- call delete('Xtest')
endfunc
"-------------------------------------------------------------------------------
let code =<< trim END
endtry
END
- call writefile(code, 'Xtest')
+ call writefile(code, 'Xtest', 'D')
call AssertException(['source Xtest'], 'Vim(endtry):E602: :endtry without :try')
" :endtry without :try
END
call writefile(code, 'Xtest')
call AssertException(['source Xtest'], 'Vim(endtry):E170: Missing :endwhile')
-
- call delete('Xtest')
endfunc
"-------------------------------------------------------------------------------
endtry
call assert_report('should not get here')
[CODE]
- call writefile(lines, 'Xscript')
+ call writefile(lines, 'Xscript', 'D')
breakadd file 7 Xscript
try
call assert_equal(1, caught_intr)
call assert_equal('ab', g:Xpath)
breakdel *
- call delete('Xscript')
endfunc
"-------------------------------------------------------------------------------
endtry
call assert_report('should not get here')
[CODE]
- call writefile(lines, 'Xscript')
+ call writefile(lines, 'Xscript', 'D')
breakadd file 6 Xscript
try
call assert_equal(1, caught_intr)
call assert_equal('a', g:Xpath)
breakdel *
- call delete('Xscript')
endfunc
" interrupt right before a catch is invoked inside a function.
endtry
call assert_report('should not get here')
[CODE]
- call writefile(lines, 'Xscript')
+ call writefile(lines, 'Xscript', 'D')
breakadd file 7 Xscript
try
call assert_equal(1, caught_intr)
call assert_equal('abc', g:Xpath)
breakdel *
- call delete('Xscript')
endfunc
"-------------------------------------------------------------------------------
endfunc
let g:result = s:snr()
END
- call writefile(lines, 'Xexpand')
+ call writefile(lines, 'Xexpand', 'D')
source Xexpand
call assert_match('<SNR>\d\+_snr', g:result)
source Xexpand
call assert_match('<SNR>\d\+_snr', g:result)
- call delete('Xexpand')
unlet g:result
endfunc
" Test for missing :endif, :endfor, :endwhile and :endtry {{{1
func Test_missing_end()
- call writefile(['if 2 > 1', 'echo ">"'], 'Xscript')
+ call writefile(['if 2 > 1', 'echo ">"'], 'Xscript', 'D')
call assert_fails('source Xscript', 'E171:')
call writefile(['for i in range(5)', 'echo i'], 'Xscript')
call assert_fails('source Xscript', 'E170:')
call assert_fails('source Xscript', 'E170:')
call writefile(['try', 'echo "."'], 'Xscript')
call assert_fails('source Xscript', 'E600:')
- call delete('Xscript')
" Using endfor with :while
let caught_e732 = 0
let @a = ''
endfunc
[SCRIPT]
- call writefile(lines, 'Xscript')
+ call writefile(lines, 'Xscript', 'D')
let buf = RunVimInTerminal('-S Xscript', {'rows': 6})
"call assert_report(l)
call StopVimInTerminal(buf)
- call delete('Xscript')
endfunc
" Test for errors in converting to float from various types {{{1
call assert_equal(1, exists('Bar'))
call assert_equal(1, exists('*Bar'))
END
- call writefile(lines, 'Xscript')
+ call writefile(lines, 'Xscript', 'D')
source Xscript
- call delete('Xscript')
endfunc
" substring and variable name {{{1
so
0
END
- call writefile(["vim9 silent! @0 \n/"] + lines, 'Xnested.vim')
+ call writefile(["vim9 silent! @0 \n/"] + lines, 'Xnested.vim', 'D')
" this must not crash
let cmd = GetVimCommand() .. " -e -s -S Xnested.vim -c qa!"
call system(cmd)
-
- call delete('Xnested.vim')
endfunc
"-------------------------------------------------------------------------------
set virtualedit=block
normal G
END
- call writefile(lines, 'XTest_block')
+ call writefile(lines, 'XTest_block', 'D')
let buf = RunVimInTerminal('-S XTest_block', {'rows': 8, 'cols': 50})
call term_sendkeys(buf, "\<C-V>gg$")
" clean up
call term_sendkeys(buf, "\<Esc>")
call StopVimInTerminal(buf)
- call delete('XTest_block')
endfunc
func Test_visual_block_ctrl_w_f()
:
END
- call writefile(lines, 'XvisualReselect')
+ call writefile(lines, 'XvisualReselect', 'D')
source XvisualReselect
bwipe!
- call delete('XvisualReselect')
endfunc
func Test_visual_block_insert_round_off()
static int included_patches[] =
{ /* Add new patch number below this line */
+/**/
+ 768,
/**/
767,
/**/