vim-patch:9.0.0391: using separate delete() call instead of writefile() 'D' flag

Problem:    Using separate delete() call instead of writefile() 'D' flag.
Solution:   Use the writefile 'D' flag.

3411265a36

Co-authored-by: Bram Moolenaar <Bram@vim.org>
This commit is contained in:
zeertzjq 2023-08-22 17:44:04 +08:00
parent 50b069a8b9
commit c170708023
4 changed files with 41 additions and 56 deletions

View File

@ -79,11 +79,11 @@ endfunc
func Test_non_existing_backupdir() func Test_non_existing_backupdir()
throw 'Skipped: Nvim auto-creates backup directory' throw 'Skipped: Nvim auto-creates backup directory'
set backupdir=./non_existing_dir backupskip= set backupdir=./non_existing_dir backupskip=
call writefile(['line1'], 'Xbackupdir') call writefile(['line1'], 'Xbackupdir', 'D')
new Xbackupdir new Xbackupdir
call assert_fails('write', 'E510:') call assert_fails('write', 'E510:')
set backupdir&vim backupskip&vim set backupdir&vim backupskip&vim
call delete('Xbackupdir')
endfunc endfunc
" vim: shiftwidth=2 sts=2 expandtab " vim: shiftwidth=2 sts=2 expandtab

View File

@ -942,14 +942,13 @@ func Test_cursor_position_with_showbreak()
repeat('x', &columns - leftcol - 1)->setline(1) repeat('x', &columns - leftcol - 1)->setline(1)
'second line'->setline(2) 'second line'->setline(2)
END END
call writefile(lines, 'XscriptShowbreak') call writefile(lines, 'XscriptShowbreak', 'D')
let buf = RunVimInTerminal('-S XscriptShowbreak', #{rows: 6}) let buf = RunVimInTerminal('-S XscriptShowbreak', #{rows: 6})
call term_sendkeys(buf, "AX") call term_sendkeys(buf, "AX")
call VerifyScreenDump(buf, 'Test_cursor_position_with_showbreak', {}) call VerifyScreenDump(buf, 'Test_cursor_position_with_showbreak', {})
call StopVimInTerminal(buf) call StopVimInTerminal(buf)
call delete('XscriptShowbreak')
endfunc endfunc
func Test_no_spurious_match() func Test_no_spurious_match()

View File

@ -5,64 +5,60 @@ source check.vim
" Test for the :bunload command with an offset " Test for the :bunload command with an offset
func Test_bunload_with_offset() func Test_bunload_with_offset()
%bwipe! %bwipe!
call writefile(['B1'], 'b1') call writefile(['B1'], 'Xb1', 'D')
call writefile(['B2'], 'b2') call writefile(['B2'], 'Xb2', 'D')
call writefile(['B3'], 'b3') call writefile(['B3'], 'Xb3', 'D')
call writefile(['B4'], 'b4') call writefile(['B4'], 'Xb4', 'D')
" Load four buffers. Unload the second and third buffers and then " Load four buffers. Unload the second and third buffers and then
" execute .+3bunload to unload the last buffer. " execute .+3bunload to unload the last buffer.
edit b1 edit Xb1
new b2 new Xb2
new b3 new Xb3
new b4 new Xb4
bunload b2 bunload Xb2
bunload b3 bunload Xb3
exe bufwinnr('b1') . 'wincmd w' exe bufwinnr('Xb1') . 'wincmd w'
.+3bunload .+3bunload
call assert_equal(0, getbufinfo('b4')[0].loaded) call assert_equal(0, getbufinfo('Xb4')[0].loaded)
call assert_equal('b1', call assert_equal('Xb1',
\ fnamemodify(getbufinfo({'bufloaded' : 1})[0].name, ':t')) \ fnamemodify(getbufinfo({'bufloaded' : 1})[0].name, ':t'))
" Load four buffers. Unload the third and fourth buffers. Execute .+3bunload " Load four buffers. Unload the third and fourth buffers. Execute .+3bunload
" and check whether the second buffer is unloaded. " and check whether the second buffer is unloaded.
ball ball
bunload b3 bunload Xb3
bunload b4 bunload Xb4
exe bufwinnr('b1') . 'wincmd w' exe bufwinnr('Xb1') . 'wincmd w'
.+3bunload .+3bunload
call assert_equal(0, getbufinfo('b2')[0].loaded) call assert_equal(0, getbufinfo('Xb2')[0].loaded)
call assert_equal('b1', call assert_equal('Xb1',
\ fnamemodify(getbufinfo({'bufloaded' : 1})[0].name, ':t')) \ fnamemodify(getbufinfo({'bufloaded' : 1})[0].name, ':t'))
" Load four buffers. Unload the second and third buffers and from the last " Load four buffers. Unload the second and third buffers and from the last
" buffer execute .-3bunload to unload the first buffer. " buffer execute .-3bunload to unload the first buffer.
ball ball
bunload b2 bunload Xb2
bunload b3 bunload Xb3
exe bufwinnr('b4') . 'wincmd w' exe bufwinnr('Xb4') . 'wincmd w'
.-3bunload .-3bunload
call assert_equal(0, getbufinfo('b1')[0].loaded) call assert_equal(0, getbufinfo('Xb1')[0].loaded)
call assert_equal('b4', call assert_equal('Xb4',
\ fnamemodify(getbufinfo({'bufloaded' : 1})[0].name, ':t')) \ fnamemodify(getbufinfo({'bufloaded' : 1})[0].name, ':t'))
" Load four buffers. Unload the first and second buffers. Execute .-3bunload " Load four buffers. Unload the first and second buffers. Execute .-3bunload
" from the last buffer and check whether the third buffer is unloaded. " from the last buffer and check whether the third buffer is unloaded.
ball ball
bunload b1 bunload Xb1
bunload b2 bunload Xb2
exe bufwinnr('b4') . 'wincmd w' exe bufwinnr('Xb4') . 'wincmd w'
.-3bunload .-3bunload
call assert_equal(0, getbufinfo('b3')[0].loaded) call assert_equal(0, getbufinfo('Xb3')[0].loaded)
call assert_equal('b4', call assert_equal('Xb4',
\ fnamemodify(getbufinfo({'bufloaded' : 1})[0].name, ':t')) \ fnamemodify(getbufinfo({'bufloaded' : 1})[0].name, ':t'))
%bwipe! %bwipe!
call delete('b1')
call delete('b2')
call delete('b3')
call delete('b4')
call assert_fails('1,4bunload', 'E16:') call assert_fails('1,4bunload', 'E16:')
call assert_fails(',100bunload', 'E16:') call assert_fails(',100bunload', 'E16:')
@ -76,9 +72,9 @@ func Test_buflist_browse()
%bwipe! %bwipe!
call assert_fails('buffer 1000', 'E86:') call assert_fails('buffer 1000', 'E86:')
call writefile(['foo1', 'foo2', 'foo3', 'foo4'], 'Xbrowse1') call writefile(['foo1', 'foo2', 'foo3', 'foo4'], 'Xbrowse1', 'D')
call writefile(['bar1', 'bar2', 'bar3', 'bar4'], 'Xbrowse2') call writefile(['bar1', 'bar2', 'bar3', 'bar4'], 'Xbrowse2', 'D')
call writefile(['baz1', 'baz2', 'baz3', 'baz4'], 'Xbrowse3') call writefile(['baz1', 'baz2', 'baz3', 'baz4'], 'Xbrowse3', 'D')
edit Xbrowse1 edit Xbrowse1
let b1 = bufnr() let b1 = bufnr()
edit Xbrowse2 edit Xbrowse2
@ -127,9 +123,6 @@ func Test_buflist_browse()
call assert_fails('sandbox bnext', 'E48:') call assert_fails('sandbox bnext', 'E48:')
call delete('Xbrowse1')
call delete('Xbrowse2')
call delete('Xbrowse3')
%bwipe! %bwipe!
endfunc endfunc
@ -200,13 +193,13 @@ endfunc
" Test for quitting the 'swapfile exists' dialog with the split buffer " Test for quitting the 'swapfile exists' dialog with the split buffer
" command. " command.
func Test_buffer_sbuf_cleanup() func Test_buffer_sbuf_cleanup()
call writefile([], 'XsplitCleanup') call writefile([], 'XsplitCleanup', 'D')
" first open the file in a buffer " first open the file in a buffer
new XsplitCleanup new XsplitCleanup
let bnr = bufnr() let bnr = bufnr()
close close
" create the swap file " create the swap file
call writefile([], '.XsplitCleanup.swp') call writefile([], '.XsplitCleanup.swp', 'D')
" Remove the catch-all that runtest.vim adds " Remove the catch-all that runtest.vim adds
au! SwapExists au! SwapExists
augroup BufTest augroup BufTest
@ -231,8 +224,6 @@ func Test_buffer_sbuf_cleanup()
call assert_equal(0, getbufinfo('XsplitCleanup')[0].loaded) call assert_equal(0, getbufinfo('XsplitCleanup')[0].loaded)
set shortmess& set shortmess&
call delete('XsplitCleanup')
call delete('.XsplitCleanup.swp')
augroup BufTest augroup BufTest
au! au!
augroup END augroup END
@ -329,8 +320,8 @@ endfunc
" Test for using CTRL-^ to edit the alternative file keeping the cursor " Test for using CTRL-^ to edit the alternative file keeping the cursor
" position with 'nostartofline'. Also test using the 'buf' command. " position with 'nostartofline'. Also test using the 'buf' command.
func Test_buffer_edit_altfile() func Test_buffer_edit_altfile()
call writefile(repeat(['one two'], 50), 'Xaltfile1') call writefile(repeat(['one two'], 50), 'Xaltfile1', 'D')
call writefile(repeat(['five six'], 50), 'Xaltfile2') call writefile(repeat(['five six'], 50), 'Xaltfile2', 'D')
set nosol set nosol
edit Xaltfile1 edit Xaltfile1
call cursor(25, 5) call cursor(25, 5)
@ -345,8 +336,6 @@ func Test_buffer_edit_altfile()
buf Xaltfile2 buf Xaltfile2
call assert_equal([0, 30, 4, 0], getpos('.')) call assert_equal([0, 30, 4, 0], getpos('.'))
set sol& set sol&
call delete('Xaltfile1')
call delete('Xaltfile2')
endfunc endfunc
" Test for running the :sball command with a maximum window count and a " Test for running the :sball command with a maximum window count and a
@ -499,7 +488,7 @@ func Test_buflist_alloc_failure()
call assert_fails('%bw!', 'E342:') call assert_fails('%bw!', 'E342:')
" test for :checktime loading the buffer " test for :checktime loading the buffer
call writefile(['one'], 'XallocFail5') call writefile(['one'], 'XallocFail5', 'D')
if has('unix') if has('unix')
edit XallocFail5 edit XallocFail5
" sleep for some time to make sure the timestamp is different " sleep for some time to make sure the timestamp is different
@ -515,7 +504,6 @@ func Test_buflist_alloc_failure()
" test for :vimgrep loading a dummy buffer " test for :vimgrep loading a dummy buffer
call test_alloc_fail(GetAllocId('newbuf_bvars'), 0, 0) call test_alloc_fail(GetAllocId('newbuf_bvars'), 0, 0)
call assert_fails('vimgrep two XallocFail5', 'E342:') call assert_fails('vimgrep two XallocFail5', 'E342:')
call delete('XallocFail5')
" test for quickfix command loading a buffer " test for quickfix command loading a buffer
call test_alloc_fail(GetAllocId('newbuf_bvars'), 0, 0) call test_alloc_fail(GetAllocId('newbuf_bvars'), 0, 0)

View File

@ -86,11 +86,10 @@ func Test_setline_startup()
if cmd == '' if cmd == ''
return return
endif endif
call writefile(['call setline(1, "Hello")', 'silent w Xtest', 'q!'], 'Xscript') call writefile(['call setline(1, "Hello")', 'silent w Xtest', 'q!'], 'Xscript', 'D')
call system(cmd) call system(cmd)
call assert_equal(['Hello'], readfile('Xtest')) call assert_equal(['Hello'], readfile('Xtest'))
call delete('Xscript')
call delete('Xtest') call delete('Xtest')
endfunc endfunc
@ -215,12 +214,11 @@ func Test_appendbufline_redraw()
call deletebufline(buf, 1, '$') call deletebufline(buf, 1, '$')
call appendbufline(buf, '$', 'Hello Vim world...') call appendbufline(buf, '$', 'Hello Vim world...')
END END
call writefile(lines, 'XscriptMatchCommon') call writefile(lines, 'XscriptMatchCommon', 'D')
let buf = RunVimInTerminal('-S XscriptMatchCommon', #{rows: 10}) let buf = RunVimInTerminal('-S XscriptMatchCommon', #{rows: 10})
call VerifyScreenDump(buf, 'Test_appendbufline_1', {}) call VerifyScreenDump(buf, 'Test_appendbufline_1', {})
call StopVimInTerminal(buf) call StopVimInTerminal(buf)
call delete('XscriptMatchCommon')
endfunc endfunc
func Test_setbufline_select_mode() func Test_setbufline_select_mode()