1
0
forked from aniani/vim

patch 9.0.0538: manually deleting test temp files

Problem:    Manually deleting test temp files.
Solution:   Add the 'D' flag to writefile().
This commit is contained in:
Bram Moolenaar
2022-09-21 22:00:03 +01:00
parent 4740394f23
commit 5c645a25bb
9 changed files with 38 additions and 73 deletions

View File

@@ -25,7 +25,7 @@ func Test_nocatch_restore_silent_emsg()
endfunc endfunc
func Test_mkdir_p() func Test_mkdir_p()
call mkdir('Xmkdir/nested', 'p') call mkdir('Xmkdir/nested', 'pR')
call assert_true(isdirectory('Xmkdir/nested')) call assert_true(isdirectory('Xmkdir/nested'))
try try
" Trying to make existing directories doesn't error " Trying to make existing directories doesn't error
@@ -35,10 +35,9 @@ func Test_mkdir_p()
call assert_report('mkdir(..., "p") failed for an existing directory') call assert_report('mkdir(..., "p") failed for an existing directory')
endtry endtry
" 'p' doesn't suppress real errors " 'p' doesn't suppress real errors
call writefile([], 'Xmkdirfile') call writefile([], 'Xmkdirfile', 'D')
call assert_fails('call mkdir("Xmkdirfile", "p")', 'E739:') call assert_fails('call mkdir("Xmkdirfile", "p")', 'E739:')
call delete('Xmkdirfile')
call delete('Xmkdir', 'rf')
call assert_equal(0, mkdir(test_null_string())) call assert_equal(0, mkdir(test_null_string()))
call assert_fails('call mkdir([])', 'E730:') call assert_fails('call mkdir([])', 'E730:')
call assert_fails('call mkdir("abc", [], [])', 'E745:') call assert_fails('call mkdir("abc", [], [])', 'E745:')
@@ -160,11 +159,9 @@ func Test_for_invalid_line_count()
111111111111111111111111 for line in ['one'] 111111111111111111111111 for line in ['one']
endfor endfor
END END
call writefile(lines, 'XinvalidFor') call writefile(lines, 'XinvalidFor', 'D')
" only test that this doesn't crash " only test that this doesn't crash
call RunVim([], [], '-u NONE -e -s -S XinvalidFor -c qa') call RunVim([], [], '-u NONE -e -s -S XinvalidFor -c qa')
call delete('XinvalidFor')
endfunc endfunc
func Test_readfile_binary() func Test_readfile_binary()
@@ -186,10 +183,9 @@ func Test_readfile_binary()
endfunc endfunc
func Test_readfile_binary_empty() func Test_readfile_binary_empty()
call writefile([], 'Xempty-file') call writefile([], 'Xempty-file', 'D')
" This used to compare uninitialized memory in Vim <= 8.2.4065 " This used to compare uninitialized memory in Vim <= 8.2.4065
call assert_equal([''], readfile('Xempty-file', 'b')) call assert_equal([''], readfile('Xempty-file', 'b'))
call delete('Xempty-file')
endfunc endfunc
func Test_readfile_bom() func Test_readfile_bom()
@@ -199,10 +195,9 @@ func Test_readfile_bom()
endfunc endfunc
func Test_readfile_max() func Test_readfile_max()
call writefile(range(1, 4), 'XReadfile_max') call writefile(range(1, 4), 'XReadfile_max', 'D')
call assert_equal(['1', '2'], readfile('XReadfile_max', '', 2)) call assert_equal(['1', '2'], readfile('XReadfile_max', '', 2))
call assert_equal(['3', '4'], readfile('XReadfile_max', '', -2)) call assert_equal(['3', '4'], readfile('XReadfile_max', '', -2))
call delete('XReadfile_max')
endfunc endfunc
func Test_let_errmsg() func Test_let_errmsg()
@@ -336,9 +331,8 @@ func Test_vvar_scriptversion1()
endfunc endfunc
func Test_scriptversion_fail() func Test_scriptversion_fail()
call writefile(['scriptversion 9'], 'Xversionscript') call writefile(['scriptversion 9'], 'Xversionscript', 'D')
call assert_fails('source Xversionscript', 'E999:') call assert_fails('source Xversionscript', 'E999:')
call delete('Xversionscript')
endfunc endfunc
func Test_execute_cmd_with_null() func Test_execute_cmd_with_null()

View File

@@ -237,13 +237,12 @@ func Test_ex_mode_with_global()
call writefile(['done'], 'Xdidexmode') call writefile(['done'], 'Xdidexmode')
qall! qall!
END END
call writefile(lines, 'Xexmodescript') call writefile(lines, 'Xexmodescript', 'D')
call assert_equal(1, RunVim([], [], '-e -s -S Xexmodescript')) call assert_equal(1, RunVim([], [], '-e -s -S Xexmodescript'))
call assert_equal(['done'], readfile('Xdidexmode')) call assert_equal(['done'], readfile('Xdidexmode'))
call delete('logfile') call delete('logfile')
call delete('Xdidexmode') call delete('Xdidexmode')
call delete('Xexmodescript')
endfunc endfunc
func Test_ex_mode_count_overflow() func Test_ex_mode_count_overflow()
@@ -257,12 +256,11 @@ func Test_ex_mode_count_overflow()
call writefile(['done'], 'Xdidexmode') call writefile(['done'], 'Xdidexmode')
qall! qall!
END END
call writefile(lines, 'Xexmodescript') call writefile(lines, 'Xexmodescript', 'D')
call assert_equal(1, RunVim([], [], '-e -s -S Xexmodescript -c qa')) call assert_equal(1, RunVim([], [], '-e -s -S Xexmodescript -c qa'))
call assert_equal(['done'], readfile('Xdidexmode')) call assert_equal(['done'], readfile('Xdidexmode'))
call delete('Xdidexmode') call delete('Xdidexmode')
call delete('Xexmodescript')
endfunc endfunc
func Test_ex_mode_large_indent() func Test_ex_mode_large_indent()
@@ -281,11 +279,9 @@ func Test_empty_command_visual_mode()
0norm0V: 0norm0V:
:qall! :qall!
END END
call writefile(lines, 'Xexmodescript') call writefile(lines, 'Xexmodescript', 'D')
call assert_equal(1, RunVim([], [], '-u NONE -e -s -S Xexmodescript')) call assert_equal(1, RunVim([], [], '-u NONE -e -s -S Xexmodescript'))
call delete('Xexmodescript')
" This may cause a dialog to be displayed for an empty command, ignore it. " This may cause a dialog to be displayed for an empty command, ignore it.
call delete('guidialogfile') call delete('guidialogfile')
endfunc endfunc

View File

@@ -83,7 +83,7 @@ endfunc
" Test for the :drop command " Test for the :drop command
func Test_drop_cmd() func Test_drop_cmd()
call writefile(['L1', 'L2'], 'Xdropfile') call writefile(['L1', 'L2'], 'Xdropfile', 'D')
enew | only enew | only
drop Xdropfile drop Xdropfile
call assert_equal('L2', getline(2)) call assert_equal('L2', getline(2))
@@ -99,7 +99,6 @@ func Test_drop_cmd()
" Check for setting the argument list " Check for setting the argument list
call assert_equal(['Xdropfile'], argv()) call assert_equal(['Xdropfile'], argv())
enew | only! enew | only!
call delete('Xdropfile')
endfunc endfunc
" Test for the :append command " Test for the :append command
@@ -141,14 +140,13 @@ func Test_append_cmd_empty_buf()
endfunc endfunc
call timer_start(10, 'Timer') call timer_start(10, 'Timer')
END END
call writefile(lines, 'Xtest_append_cmd_empty_buf') call writefile(lines, 'Xtest_append_cmd_empty_buf', 'D')
let buf = RunVimInTerminal('-S Xtest_append_cmd_empty_buf', {'rows': 6}) let buf = RunVimInTerminal('-S Xtest_append_cmd_empty_buf', {'rows': 6})
call WaitForAssert({-> assert_equal('bbbbb', term_getline(buf, 2))}) call WaitForAssert({-> assert_equal('bbbbb', term_getline(buf, 2))})
call WaitForAssert({-> assert_equal('aaaaa', term_getline(buf, 1))}) call WaitForAssert({-> assert_equal('aaaaa', term_getline(buf, 1))})
" clean up " clean up
call StopVimInTerminal(buf) call StopVimInTerminal(buf)
call delete('Xtest_append_cmd_empty_buf')
endfunc endfunc
" Test for the :insert command " Test for the :insert command
@@ -190,14 +188,13 @@ func Test_insert_cmd_empty_buf()
endfunc endfunc
call timer_start(10, 'Timer') call timer_start(10, 'Timer')
END END
call writefile(lines, 'Xtest_insert_cmd_empty_buf') call writefile(lines, 'Xtest_insert_cmd_empty_buf', 'D')
let buf = RunVimInTerminal('-S Xtest_insert_cmd_empty_buf', {'rows': 6}) let buf = RunVimInTerminal('-S Xtest_insert_cmd_empty_buf', {'rows': 6})
call WaitForAssert({-> assert_equal('bbbbb', term_getline(buf, 2))}) call WaitForAssert({-> assert_equal('bbbbb', term_getline(buf, 2))})
call WaitForAssert({-> assert_equal('aaaaa', term_getline(buf, 1))}) call WaitForAssert({-> assert_equal('aaaaa', term_getline(buf, 1))})
" clean up " clean up
call StopVimInTerminal(buf) call StopVimInTerminal(buf)
call delete('Xtest_insert_cmd_empty_buf')
endfunc endfunc
" Test for the :change command " Test for the :change command
@@ -241,8 +238,8 @@ func Test_confirm_cmd()
CheckNotGui CheckNotGui
CheckRunVimInTerminal CheckRunVimInTerminal
call writefile(['foo1'], 'Xfoo') call writefile(['foo1'], 'Xfoo', 'D')
call writefile(['bar1'], 'Xbar') call writefile(['bar1'], 'Xbar', 'D')
" Test for saving all the modified buffers " Test for saving all the modified buffers
let lines =<< trim END let lines =<< trim END
@@ -253,7 +250,7 @@ func Test_confirm_cmd()
call setline(1, 'bar2') call setline(1, 'bar2')
wincmd b wincmd b
END END
call writefile(lines, 'Xscript') call writefile(lines, 'Xscript', 'D')
let buf = RunVimInTerminal('-S Xscript', {'rows': 20}) let buf = RunVimInTerminal('-S Xscript', {'rows': 20})
call term_sendkeys(buf, ":confirm qall\n") call term_sendkeys(buf, ":confirm qall\n")
call WaitForAssert({-> assert_match('\[Y\]es, (N)o, Save (A)ll, (D)iscard All, (C)ancel: ', term_getline(buf, 20))}, 1000) call WaitForAssert({-> assert_match('\[Y\]es, (N)o, Save (A)ll, (D)iscard All, (C)ancel: ', term_getline(buf, 20))}, 1000)
@@ -302,10 +299,6 @@ func Test_confirm_cmd()
call assert_equal(['foo4'], readfile('Xfoo')) call assert_equal(['foo4'], readfile('Xfoo'))
call assert_equal(['bar2'], readfile('Xbar')) call assert_equal(['bar2'], readfile('Xbar'))
call delete('Xscript')
call delete('Xfoo')
call delete('Xbar')
endfunc endfunc
func Test_confirm_cmd_cancel() func Test_confirm_cmd_cancel()
@@ -318,7 +311,7 @@ func Test_confirm_cmd_cancel()
new new
call setline(1, 'abc') call setline(1, 'abc')
END END
call writefile(lines, 'Xscript') call writefile(lines, 'Xscript', 'D')
let buf = RunVimInTerminal('-S Xscript', {'rows': 20}) let buf = RunVimInTerminal('-S Xscript', {'rows': 20})
call term_sendkeys(buf, ":confirm close\n") call term_sendkeys(buf, ":confirm close\n")
call WaitForAssert({-> assert_match('^\[Y\]es, (N)o, (C)ancel: *$', call WaitForAssert({-> assert_match('^\[Y\]es, (N)o, (C)ancel: *$',
@@ -332,7 +325,6 @@ func Test_confirm_cmd_cancel()
call WaitForAssert({-> assert_match('^ *0,0-1 All$', call WaitForAssert({-> assert_match('^ *0,0-1 All$',
\ term_getline(buf, 20))}, 1000) \ term_getline(buf, 20))}, 1000)
call StopVimInTerminal(buf) call StopVimInTerminal(buf)
call delete('Xscript')
endfunc endfunc
" The ":confirm" prompt was sometimes used with the terminal in cooked mode. " The ":confirm" prompt was sometimes used with the terminal in cooked mode.
@@ -342,14 +334,14 @@ func Test_confirm_q_wq()
CheckNotGui CheckNotGui
CheckRunVimInTerminal CheckRunVimInTerminal
call writefile(['foo'], 'Xfoo') call writefile(['foo'], 'Xfoo', 'D')
let lines =<< trim END let lines =<< trim END
set hidden nomore set hidden nomore
call setline(1, 'abc') call setline(1, 'abc')
edit Xfoo edit Xfoo
END END
call writefile(lines, 'Xscript') call writefile(lines, 'Xscript', 'D')
let buf = RunVimInTerminal('-S Xscript', {'rows': 20}) let buf = RunVimInTerminal('-S Xscript', {'rows': 20})
call term_sendkeys(buf, ":confirm q\n") call term_sendkeys(buf, ":confirm q\n")
call WaitForAssert({-> assert_match('^\[Y\]es, (N)o, (C)ancel: *$', call WaitForAssert({-> assert_match('^\[Y\]es, (N)o, (C)ancel: *$',
@@ -365,23 +357,21 @@ func Test_confirm_q_wq()
call term_sendkeys(buf, 'C') call term_sendkeys(buf, 'C')
call WaitForAssert({-> assert_notmatch('^\[Y\]es, (N)o, (C)ancel: C*$', call WaitForAssert({-> assert_notmatch('^\[Y\]es, (N)o, (C)ancel: C*$',
\ term_getline(buf, 20))}, 1000) \ term_getline(buf, 20))}, 1000)
call StopVimInTerminal(buf)
call delete('Xscript') call StopVimInTerminal(buf)
call delete('Xfoo')
endfunc endfunc
func Test_confirm_write_ro() func Test_confirm_write_ro()
CheckNotGui CheckNotGui
CheckRunVimInTerminal CheckRunVimInTerminal
call writefile(['foo'], 'Xconfirm_write_ro') call writefile(['foo'], 'Xconfirm_write_ro', 'D')
let lines =<< trim END let lines =<< trim END
set nobackup ff=unix cmdheight=2 set nobackup ff=unix cmdheight=2
edit Xconfirm_write_ro edit Xconfirm_write_ro
norm Abar norm Abar
END END
call writefile(lines, 'Xscript') call writefile(lines, 'Xscript', 'D')
let buf = RunVimInTerminal('-S Xscript', {'rows': 20}) let buf = RunVimInTerminal('-S Xscript', {'rows': 20})
" Try to write with 'ro' option. " Try to write with 'ro' option.
@@ -422,17 +412,15 @@ func Test_confirm_write_ro()
call assert_equal(['foo'], readfile('Xconfirm_write_ro')) call assert_equal(['foo'], readfile('Xconfirm_write_ro'))
call StopVimInTerminal(buf) call StopVimInTerminal(buf)
call delete('Xscript')
call delete('Xconfirm_write_ro')
endfunc endfunc
func Test_confirm_write_partial_file() func Test_confirm_write_partial_file()
CheckNotGui CheckNotGui
CheckRunVimInTerminal CheckRunVimInTerminal
call writefile(['a', 'b', 'c', 'd'], 'Xwrite_partial') call writefile(['a', 'b', 'c', 'd'], 'Xwrite_partial', 'D')
call writefile(['set nobackup ff=unix cmdheight=2', call writefile(['set nobackup ff=unix cmdheight=2',
\ 'edit Xwrite_partial'], 'Xscript') \ 'edit Xwrite_partial'], 'Xscript', 'D')
let buf = RunVimInTerminal('-S Xscript', {'rows': 20}) let buf = RunVimInTerminal('-S Xscript', {'rows': 20})
call term_sendkeys(buf, ":confirm 2,3w\n") call term_sendkeys(buf, ":confirm 2,3w\n")
@@ -458,8 +446,6 @@ func Test_confirm_write_partial_file()
call assert_equal(['b', 'c'], readfile('Xwrite_partial')) call assert_equal(['b', 'c'], readfile('Xwrite_partial'))
call StopVimInTerminal(buf) call StopVimInTerminal(buf)
call delete('Xwrite_partial')
call delete('Xscript')
endfunc endfunc
" Test for the :print command " Test for the :print command
@@ -509,10 +495,9 @@ func Test_redir_cmd_readonly()
CheckNotRoot CheckNotRoot
" Redirecting to a read-only file " Redirecting to a read-only file
call writefile([], 'Xredirfile') call writefile([], 'Xredirfile', 'D')
call setfperm('Xredirfile', 'r--r--r--') call setfperm('Xredirfile', 'r--r--r--')
call assert_fails('redir! > Xredirfile', 'E190:') call assert_fails('redir! > Xredirfile', 'E190:')
call delete('Xredirfile')
endfunc endfunc
" Test for the :filetype command " Test for the :filetype command
@@ -532,7 +517,7 @@ endfunc
" Test for the :read command " Test for the :read command
func Test_read_cmd() func Test_read_cmd()
call writefile(['one'], 'Xcmdfile') call writefile(['one'], 'Xcmdfile', 'D')
new new
call assert_fails('read', 'E32:') call assert_fails('read', 'E32:')
edit Xcmdfile edit Xcmdfile
@@ -546,7 +531,6 @@ func Test_read_cmd()
call feedkeys("Qr Xcmdfile\<CR>visual\<CR>", 'xt') call feedkeys("Qr Xcmdfile\<CR>visual\<CR>", 'xt')
call assert_equal(['one'], getline(1, '$')) call assert_equal(['one'], getline(1, '$'))
close! close!
call delete('Xcmdfile')
endfunc endfunc
" Test for running Ex commands when text is locked. " Test for running Ex commands when text is locked.
@@ -727,7 +711,7 @@ endfunc
" Test :write after changing name with :file and loading it with :edit " Test :write after changing name with :file and loading it with :edit
func Test_write_after_rename() func Test_write_after_rename()
call writefile(['text'], 'Xafterfile') call writefile(['text'], 'Xafterfile', 'D')
enew enew
file Xafterfile file Xafterfile
@@ -737,7 +721,6 @@ func Test_write_after_rename()
edit edit
write write
call delete('Xafterfile')
bwipe! bwipe!
endfunc endfunc

View File

@@ -183,13 +183,12 @@ func Test_win_execute_on_startup()
silent tabedit Xfile3 silent tabedit Xfile3
autocmd VimEnter * win_execute(id, 'close') autocmd VimEnter * win_execute(id, 'close')
END END
call writefile(lines, 'XwinExecute') call writefile(lines, 'XwinExecute', 'D')
let buf = RunVimInTerminal('-p Xfile1 -Nu XwinExecute', {}) let buf = RunVimInTerminal('-p Xfile1 -Nu XwinExecute', {})
" this was crashing on exit with EXITFREE defined " this was crashing on exit with EXITFREE defined
call StopVimInTerminal(buf) call StopVimInTerminal(buf)
call delete('XwinExecute')
call delete('Xfile1') call delete('Xfile1')
endfunc endfunc

View File

@@ -117,13 +117,12 @@ func Test_exit_error_reading_input()
CheckNotAsan CheckNotAsan
CheckNotValgrind CheckNotValgrind
call writefile([":au VimLeave * call writefile(['l = ' .. v:exiting], 'Xtestout')", ":tabnew", "q:"], 'Xscript', 'b') call writefile([":au VimLeave * call writefile(['l = ' .. v:exiting], 'Xtestout')", ":tabnew", "q:"], 'Xscript', 'bD')
if RunVim([], [], '<Xscript') if RunVim([], [], '<Xscript')
call assert_equal(1, v:shell_error) call assert_equal(1, v:shell_error)
call assert_equal(['l = 1'], readfile('Xtestout')) call assert_equal(['l = 1'], readfile('Xtestout'))
endif endif
call delete('Xscript')
call delete('Xtestout') call delete('Xtestout')
endfun endfun

View File

@@ -137,14 +137,13 @@ func Test_source_sfile()
:call writefile(v:errors, 'Xresult') :call writefile(v:errors, 'Xresult')
:qall! :qall!
[SCRIPT] [SCRIPT]
call writefile(lines, 'Xscript') call writefile(lines, 'Xscript', 'D')
if RunVim([], [], '--clean -s Xscript') if RunVim([], [], '--clean -s Xscript')
call assert_equal([ call assert_equal([
\ 'E1274: No script file name to substitute for "<script>"', \ 'E1274: No script file name to substitute for "<script>"',
\ 'E498: No :source file name to substitute for "<sfile>"'], \ 'E498: No :source file name to substitute for "<sfile>"'],
\ readfile('Xresult')) \ readfile('Xresult'))
endif endif
call delete('Xscript')
call delete('Xresult') call delete('Xresult')
endfunc endfunc
@@ -197,9 +196,9 @@ func Test_expand_script_source()
au User * call extend(g:au_level, [expand('<script>:t')]) au User * call extend(g:au_level, [expand('<script>:t')])
[SCRIPT] [SCRIPT]
call writefile(lines0, 'Xscript0') call writefile(lines0, 'Xscript0', 'D')
call writefile(lines1, 'Xscript1') call writefile(lines1, 'Xscript1', 'D')
call writefile(lines2, 'Xscript2') call writefile(lines2, 'Xscript2', 'D')
" Check the expansion of <script> at different levels. " Check the expansion of <script> at different levels.
let g:script_level = [] let g:script_level = []
@@ -220,10 +219,6 @@ func Test_expand_script_source()
delfunc F0 delfunc F0
delfunc F1 delfunc F1
delfunc F2 delfunc F2
call delete('Xscript0')
call delete('Xscript1')
call delete('Xscript2')
endfunc endfunc
" vim: shiftwidth=2 sts=2 expandtab " vim: shiftwidth=2 sts=2 expandtab

View File

@@ -56,14 +56,13 @@ func Test_expand_sfile_and_stack()
" comment here " comment here
let g:stack_value = expand('<stack>') let g:stack_value = expand('<stack>')
END END
call writefile(lines, 'Xstack') call writefile(lines, 'Xstack', 'D')
source Xstack source Xstack
call assert_match('\<Xstack\[2\]$', g:stack_value) call assert_match('\<Xstack\[2\]$', g:stack_value)
unlet g:stack_value unlet g:stack_value
call delete('Xstack')
if exists('+shellslash') if exists('+shellslash')
call mkdir('Xshellslash') call mkdir('Xshellslash', 'R')
let lines =<< trim END let lines =<< trim END
let g:stack1 = expand('<stack>') let g:stack1 = expand('<stack>')
set noshellslash set noshellslash
@@ -83,7 +82,6 @@ func Test_expand_sfile_and_stack()
unlet g:stack2 unlet g:stack2
unlet g:stack3 unlet g:stack3
endfor endfor
call delete('Xshellslash', 'rf')
endif endif
endfunc endfunc

View File

@@ -706,13 +706,12 @@ func Test_function_outside_script()
call writefile([execute('messages')], 'Xtest.out') call writefile([execute('messages')], 'Xtest.out')
qall qall
END END
call writefile(cleanup, 'Xverify.vim') call writefile(cleanup, 'Xverify.vim', 'D')
call RunVim([], [], "-c \"echo function('s:abc')\" -S Xverify.vim") call RunVim([], [], "-c \"echo function('s:abc')\" -S Xverify.vim")
call assert_match('E81: Using <SID> not in a', readfile('Xtest.out')[0]) call assert_match('E81: Using <SID> not in a', readfile('Xtest.out')[0])
call RunVim([], [], "-c \"echo funcref('s:abc')\" -S Xverify.vim") call RunVim([], [], "-c \"echo funcref('s:abc')\" -S Xverify.vim")
call assert_match('E81: Using <SID> not in a', readfile('Xtest.out')[0]) call assert_match('E81: Using <SID> not in a', readfile('Xtest.out')[0])
call delete('Xtest.out') call delete('Xtest.out')
call delete('Xverify.vim')
endfunc endfunc
func Test_setmatches() func Test_setmatches()

View File

@@ -699,6 +699,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 */
/**/
538,
/**/ /**/
537, 537,
/**/ /**/