changeset 30568:bcd204e28fed v9.0.0619

patch 9.0.0619: too many delete() calls in tests Commit: https://github.com/vim/vim/commit/572a4433c8276d8e8f228a09f43b11afe0c85f6f Author: Bram Moolenaar <Bram@vim.org> Date: Wed Sep 28 21:07:03 2022 +0100 patch 9.0.0619: too many delete() calls in tests Problem: Too many delete() calls in tests. Solution: Use deferred delete where possible.
author Bram Moolenaar <Bram@vim.org>
date Wed, 28 Sep 2022 22:15:05 +0200
parents c3ce2a14a3a2
children c9568bf9c963
files src/testdir/test_gf.vim src/testdir/test_global.vim src/testdir/test_gui.vim src/testdir/test_help.vim src/testdir/test_highlight.vim src/version.c
diffstat 6 files changed, 33 insertions(+), 61 deletions(-) [+]
line wrap: on
line diff
--- a/src/testdir/test_gf.vim
+++ b/src/testdir/test_gf.vim
@@ -88,11 +88,11 @@ endfunc
 func Test_gf()
   set isfname=@,48-57,/,.,-,_,+,,,$,:,~,{,}
 
-  call writefile(["Test for gf command"], "Xtest1")
+  call writefile(["Test for gf command"], "Xtest1", 'D')
   if has("unix")
-    call writefile(["    ${CDIR}/Xtest1"], "Xtestgf")
+    call writefile(["    ${CDIR}/Xtest1"], "Xtestgf", 'D')
   else
-    call writefile(["    $TDIR/Xtest1"], "Xtestgf")
+    call writefile(["    $TDIR/Xtest1"], "Xtestgf", 'D')
   endif
   new Xtestgf
   if has("unix")
@@ -109,14 +109,12 @@ func Test_gf()
 
   normal gf
   call assert_equal('Xtest1', fnamemodify(bufname(''), ":t"))
+
   close!
-
-  call delete('Xtest1')
-  call delete('Xtestgf')
 endfunc
 
 func Test_gf_visual()
-  call writefile(['one', 'two', 'three', 'four'], "Xtest_gf_visual")
+  call writefile(['one', 'two', 'three', 'four'], "Xtest_gf_visual", 'D')
   new
   call setline(1, 'XXXtest_gf_visualXXX')
   set hidden
@@ -139,33 +137,30 @@ func Test_gf_visual()
   call assert_equal(3, getcurpos()[1])
 
   " do not include the NUL at the end
-  call writefile(['x'], 'X')
+  call writefile(['x'], 'Xvisual', 'D')
   let save_enc = &enc
   for enc in ['latin1', 'utf-8']
     exe "set enc=" .. enc
     new
-    call setline(1, 'X')
+    call setline(1, 'Xvisual')
     set nomodified
     exe "normal \<C-V>$gf"
-    call assert_equal('X', bufname())
+    call assert_equal('Xvisual', bufname())
     bwipe!
   endfor
   let &enc = save_enc
-  call delete('X')
 
   " line number in visual area is used for file name
   if has('unix')
     bwipe!
-    call writefile([], "Xtest_gf_visual:3")
+    call writefile([], "Xtest_gf_visual:3", 'D')
     new
     call setline(1, 'XXXtest_gf_visual:3XXX')
     norm! 0ttvtXgF
     call assert_equal('Xtest_gf_visual:3', bufname('%'))
-  call delete('Xtest_gf_visual:3')
   endif
 
   bwipe!
-  call delete('Xtest_gf_visual')
   set hidden&
 endfunc
 
@@ -254,7 +249,7 @@ endfunc
 func Test_gf_subdirs_wildcard()
   let cwd = getcwd()
   let dir = 'Xtestgf_dir'
-  call mkdir(dir)
+  call mkdir(dir, 'R')
   call chdir(dir)
   for i in range(300)
     call mkdir(i)
@@ -269,7 +264,6 @@ func Test_gf_subdirs_wildcard()
   call assert_equal('99', fnamemodify(bufname(''), ":t"))
 
   call chdir(cwd)
-  call delete(dir, 'rf')
   set path&
 endfunc
 
--- a/src/testdir/test_global.vim
+++ b/src/testdir/test_global.vim
@@ -116,7 +116,7 @@ func Test_interrupt_global()
     cnoremap ; <Cmd>sleep 10<CR>
     call setline(1, repeat(['foo'], 5))
   END
-  call writefile(lines, 'Xtest_interrupt_global')
+  call writefile(lines, 'Xtest_interrupt_global', 'D')
   let buf = RunVimInTerminal('-S Xtest_interrupt_global', {'rows': 6})
 
   call term_sendkeys(buf, ":g/foo/norm :\<C-V>;\<CR>")
@@ -133,7 +133,6 @@ func Test_interrupt_global()
   call WaitForAssert({-> assert_match('Interrupted', term_getline(buf, 5))}, 1000)
 
   call StopVimInTerminal(buf)
-  call delete('Xtest_interrupt_global')
 endfunc
 
 " vim: shiftwidth=2 sts=2 expandtab
--- a/src/testdir/test_gui.vim
+++ b/src/testdir/test_gui.vim
@@ -157,12 +157,12 @@ endfunc
 func Test_gui_read_stdin()
   CheckUnix
 
-  call writefile(['some', 'lines'], 'Xstdin')
+  call writefile(['some', 'lines'], 'Xstdin', 'D')
   let script =<< trim END
       call writefile(getline(1, '$'), 'XstdinOK')
       qa!
   END
-  call writefile(script, 'Xscript')
+  call writefile(script, 'Xscript', 'D')
 
   " Cannot use --not-a-term here, the "reading from stdin" message would not be
   " displayed.
@@ -176,9 +176,7 @@ func Test_gui_read_stdin()
   call system('cat Xstdin | ' .. vimcmd .. ' -f -g -S Xscript -')
   call assert_equal(['some', 'lines'], readfile('XstdinOK'))
 
-  call delete('Xstdin')
   call delete('XstdinOK')
-  call delete('Xscript')
 endfunc
 
 func Test_set_background()
@@ -853,33 +851,27 @@ endfunc
 " Test "vim -g" and also the GUIEnter autocommand.
 func Test_gui_dash_g()
   let cmd = GetVimCommand('Xscriptgui')
-  call writefile([""], "Xtestgui")
+  call writefile([""], "Xtestgui", 'D')
   let lines =<< trim END
 	au GUIEnter * call writefile(["insertmode: " . &insertmode], "Xtestgui")
 	au GUIEnter * qall
   END
-  call writefile(lines, 'Xscriptgui')
+  call writefile(lines, 'Xscriptgui', 'D')
   call system(cmd . ' -g')
   call WaitForAssert({-> assert_equal(['insertmode: 0'], readfile('Xtestgui'))})
-
-  call delete('Xscriptgui')
-  call delete('Xtestgui')
 endfunc
 
 " Test "vim -7" and also the GUIEnter autocommand.
 func Test_gui_dash_y()
   let cmd = GetVimCommand('Xscriptgui')
-  call writefile([""], "Xtestgui")
+  call writefile([""], "Xtestgui", 'D')
   let lines =<< trim END
 	au GUIEnter * call writefile(["insertmode: " . &insertmode], "Xtestgui")
 	au GUIEnter * qall
   END
-  call writefile(lines, 'Xscriptgui')
+  call writefile(lines, 'Xscriptgui', 'D')
   call system(cmd . ' -y')
   call WaitForAssert({-> assert_equal(['insertmode: 1'], readfile('Xtestgui'))})
-
-  call delete('Xscriptgui')
-  call delete('Xtestgui')
 endfunc
 
 " Test for "!" option in 'guioptions'. Use a terminal for running external
@@ -1412,7 +1404,7 @@ func Test_gui_drop_files()
   %argdelete
   " pressing shift when dropping files should change directory
   let save_cwd = getcwd()
-  call mkdir('Xdropdir1')
+  call mkdir('Xdropdir1', 'R')
   call writefile([], 'Xdropdir1/Xfile1')
   call writefile([], 'Xdropdir1/Xfile2')
   let d = #{files: ['Xdropdir1/Xfile1', 'Xdropdir1/Xfile2'], row: 1, col: 1,
@@ -1441,7 +1433,6 @@ func Test_gui_drop_files()
   call assert_equal('', @%)
   %bw!
   %argdelete
-  call delete('Xdropdir1', 'rf')
 
   " drop files in the command line. The GUI drop files adds the file names to
   " the low level input buffer. So need to use a cmdline map and feedkeys()
--- a/src/testdir/test_help.vim
+++ b/src/testdir/test_help.vim
@@ -77,7 +77,7 @@ func Test_help_keyword()
 endfunc
 
 func Test_help_local_additions()
-  call mkdir('Xruntime/doc', 'p')
+  call mkdir('Xruntime/doc', 'pR')
   call writefile(['*mydoc.txt* my awesome doc'], 'Xruntime/doc/mydoc.txt')
   call writefile(['*mydoc-ext.txt* my extended awesome doc'], 'Xruntime/doc/mydoc-ext.txt')
   let rtp_save = &rtp
@@ -91,7 +91,7 @@ func Test_help_local_additions()
   call delete('Xruntime/doc/mydoc-ext.txt')
   close
 
-  call mkdir('Xruntime-ja/doc', 'p')
+  call mkdir('Xruntime-ja/doc', 'pR')
   call writefile(["local-additions\thelp.jax\t/*local-additions*"], 'Xruntime-ja/doc/tags-ja')
   call writefile(['*help.txt* This is jax file', '',
   \ 'LOCAL ADDITIONS: *local-additions*', ''], 'Xruntime-ja/doc/help.jax')
@@ -116,8 +116,6 @@ func Test_help_local_additions()
   \ ], lines)
   close
 
-  call delete('Xruntime', 'rf')
-  call delete('Xruntime-ja', 'rf')
   let &rtp = rtp_save
 endfunc
 
@@ -129,7 +127,7 @@ endfunc
 " Test for the :helptags command
 " NOTE: if you run tests as root this will fail.  Don't run tests as root!
 func Test_helptag_cmd()
-  call mkdir('Xtagdir/a/doc', 'p')
+  call mkdir('Xtagdir/a/doc', 'pR')
 
   " No help file to process in the directory
   call assert_fails('helptags Xtagdir', 'E151:')
@@ -151,8 +149,6 @@ func Test_helptag_cmd()
   " Duplicate tags in the help file
   call writefile(['*tag1*', '*tag1*', '*tag2*'], 'Xtagdir/a/doc/sample.txt')
   call assert_fails('helptags Xtagdir', 'E154:')
-
-  call delete('Xtagdir', 'rf')
 endfunc
 
 func Test_helptag_cmd_readonly()
@@ -160,7 +156,7 @@ func Test_helptag_cmd_readonly()
   CheckNotRoot
 
   " Read-only tags file
-  call mkdir('Xrodir/doc', 'p')
+  call mkdir('Xrodir/doc', 'pR')
   call writefile([''], 'Xrodir/doc/tags')
   call writefile([], 'Xrodir/doc/sample.txt')
   call setfperm('Xrodir/doc/tags', 'r-xr--r--')
@@ -178,7 +174,6 @@ func Test_helptag_cmd_readonly()
   call writefile([], 'Xrodir/b/doc/sample.txt')
   call setfperm('Xrodir/b/doc/sample.txt', '-w-------')
   call assert_fails('helptags Xrodir', 'E153:', getfperm('Xrodir/b/doc/sample.txt'))
-  call delete('Xrodir', 'rf')
 endfunc
 
 " Test for setting the 'helpheight' option in the help window
--- a/src/testdir/test_highlight.vim
+++ b/src/testdir/test_highlight.vim
@@ -540,7 +540,7 @@ func Test_cursorline_after_yank()
   call writefile([
 	\ 'set cul rnu',
 	\ 'call setline(1, ["","1","2","3",""])',
-	\ ], 'Xtest_cursorline_yank')
+	\ ], 'Xtest_cursorline_yank', 'D')
   let buf = RunVimInTerminal('-S Xtest_cursorline_yank', {'rows': 8})
   call TermWait(buf)
   call term_sendkeys(buf, "Gy3k")
@@ -551,7 +551,6 @@ func Test_cursorline_after_yank()
 
   " clean up
   call StopVimInTerminal(buf)
-  call delete('Xtest_cursorline_yank')
 endfunc
 
 " test for issue #4862
@@ -580,7 +579,7 @@ func Test_cursorline_with_visualmode()
   call writefile([
 	\ 'set cul',
 	\ 'call setline(1, repeat(["abc"], 50))',
-	\ ], 'Xtest_cursorline_with_visualmode')
+	\ ], 'Xtest_cursorline_with_visualmode', 'D')
   let buf = RunVimInTerminal('-S Xtest_cursorline_with_visualmode', {'rows': 12})
   call TermWait(buf)
   call term_sendkeys(buf, "V\<C-f>kkkjk")
@@ -589,7 +588,6 @@ func Test_cursorline_with_visualmode()
 
   " clean up
   call StopVimInTerminal(buf)
-  call delete('Xtest_cursorline_with_visualmode')
 endfunc
 
 func Test_cursorcolumn_insert_on_tab()
@@ -600,7 +598,7 @@ func Test_cursorcolumn_insert_on_tab()
     set cursorcolumn
     call cursor(2, 2)
   END
-  call writefile(lines, 'Xcuc_insert_on_tab')
+  call writefile(lines, 'Xcuc_insert_on_tab', 'D')
 
   let buf = RunVimInTerminal('-S Xcuc_insert_on_tab', #{rows: 8})
   call TermWait(buf)
@@ -619,7 +617,6 @@ func Test_cursorcolumn_insert_on_tab()
   call VerifyScreenDump(buf, 'Test_cursorcolumn_insert_on_tab_2', {})
 
   call StopVimInTerminal(buf)
-  call delete('Xcuc_insert_on_tab')
 endfunc
 
 func Test_cursorcolumn_callback()
@@ -637,14 +634,13 @@ func Test_cursorcolumn_callback()
 
       call timer_start(300, 'Func')
   END
-  call writefile(lines, 'Xcuc_timer')
+  call writefile(lines, 'Xcuc_timer', 'D')
 
   let buf = RunVimInTerminal('-S Xcuc_timer', #{rows: 8})
   call TermWait(buf, 310)
   call VerifyScreenDump(buf, 'Test_cursorcolumn_callback_1', {})
 
   call StopVimInTerminal(buf)
-  call delete('Xcuc_timer')
 endfunc
 
 func Test_wincolor()
@@ -663,7 +659,7 @@ func Test_wincolor()
 	call prop_add(6, 12, {"type": "foo", "end_col": 15})
 	/here
   END
-  call writefile(lines, 'Xtest_wincolor')
+  call writefile(lines, 'Xtest_wincolor', 'D')
   let buf = RunVimInTerminal('-S Xtest_wincolor', {'rows': 8})
   call TermWait(buf)
   call term_sendkeys(buf, "2G5lvj")
@@ -674,7 +670,6 @@ func Test_wincolor()
   " clean up
   call term_sendkeys(buf, "\<Esc>")
   call StopVimInTerminal(buf)
-  call delete('Xtest_wincolor')
 endfunc
 
 func Test_wincolor_listchars()
@@ -689,7 +684,7 @@ func Test_wincolor_listchars()
 	call matchadd('Conceal', 'text')
 	normal 2G5zl
   END
-  call writefile(lines, 'Xtest_wincolorlcs')
+  call writefile(lines, 'Xtest_wincolorlcs', 'D')
   let buf = RunVimInTerminal('-S Xtest_wincolorlcs', {'rows': 8})
 
   call VerifyScreenDump(buf, 'Test_wincolor_lcs', {})
@@ -697,7 +692,6 @@ func Test_wincolor_listchars()
   " clean up
   call term_sendkeys(buf, "\<Esc>")
   call StopVimInTerminal(buf)
-  call delete('Xtest_wincolorlcs')
 endfunc
 
 func Test_colorcolumn()
@@ -714,14 +708,13 @@ func Test_colorcolumn()
 	wincmd w
 	buf X
   END
-  call writefile(lines, 'Xtest_colorcolumn')
+  call writefile(lines, 'Xtest_colorcolumn', 'D')
   let buf = RunVimInTerminal('-S Xtest_colorcolumn', {'rows': 10})
   call term_sendkeys(buf, ":\<CR>")
   call VerifyScreenDump(buf, 'Test_colorcolumn_1', {})
 
   " clean up
   call StopVimInTerminal(buf)
-  call delete('Xtest_colorcolumn')
 endfunc
 
 func Test_colorcolumn_bri()
@@ -731,14 +724,13 @@ func Test_colorcolumn_bri()
   let lines =<< trim END
 	call setline(1, 'The quick brown fox jumped over the lazy dogs')
   END
-  call writefile(lines, 'Xtest_colorcolumn_bri')
+  call writefile(lines, 'Xtest_colorcolumn_bri', 'D')
   let buf = RunVimInTerminal('-S Xtest_colorcolumn_bri', {'rows': 10,'columns': 40})
   call term_sendkeys(buf, ":set co=40 linebreak bri briopt=shift:2 cc=40,41,43\<CR>")
   call VerifyScreenDump(buf, 'Test_colorcolumn_2', {})
 
   " clean up
   call StopVimInTerminal(buf)
-  call delete('Xtest_colorcolumn_bri')
 endfunc
 
 func Test_colorcolumn_sbr()
@@ -748,14 +740,13 @@ func Test_colorcolumn_sbr()
   let lines =<< trim END
 	call setline(1, 'The quick brown fox jumped over the lazy dogs')
   END
-  call writefile(lines, 'Xtest_colorcolumn_srb')
+  call writefile(lines, 'Xtest_colorcolumn_srb', 'D')
   let buf = RunVimInTerminal('-S Xtest_colorcolumn_srb', {'rows': 10,'columns': 40})
   call term_sendkeys(buf, ":set co=40 showbreak=+++>\\  cc=40,41,43\<CR>")
   call VerifyScreenDump(buf, 'Test_colorcolumn_3', {})
 
   " clean up
   call StopVimInTerminal(buf)
-  call delete('Xtest_colorcolumn_srb')
 endfunc
 
 " This test must come before the Test_cursorline test, as it appears this
--- a/src/version.c
+++ b/src/version.c
@@ -700,6 +700,8 @@ static char *(features[]) =
 static int included_patches[] =
 {   /* Add new patch number below this line */
 /**/
+    619,
+/**/
     618,
 /**/
     617,