patch 9.0.1007: there is no way to get a list of swap file names
Problem: There is no way to get a list of swap file names.
Solution: Add the swapfilelist() function. Use it in the test script to
clean up. Remove deleting individual swap files.
diff --git a/src/testdir/runtest.vim b/src/testdir/runtest.vim
index e1d9999..2eabb1a 100644
--- a/src/testdir/runtest.vim
+++ b/src/testdir/runtest.vim
@@ -160,6 +160,14 @@
let $BASH_SILENCE_DEPRECATION_WARNING = 1
endif
+
+" A previous (failed) test run may have left swap files behind. Delete them
+" before running tests again, they might interfere.
+for name in s:GetSwapFileList()
+ call delete(name)
+endfor
+
+
" Prepare for calling test_garbagecollect_now().
let v:testing = 1
@@ -186,6 +194,22 @@
let g:func_start = reltime()
endif
+" Get the list of swap files in the current directory.
+func s:GetSwapFileList()
+ let save_dir = &directory
+ let &directory = '.'
+ let files = swapfilelist()
+ let &directory = save_dir
+
+ " remove a match with runtest.vim
+ let idx = indexof(files, 'v:val =~ "runtest.vim."')
+ if idx >= 0
+ call remove(files, idx)
+ endif
+
+ return files
+endfunc
+
" Invoked when a test takes too much time.
func TestTimeout(id)
split test.log
@@ -339,6 +363,16 @@
endif
call add(s:messages, message)
let s:done += 1
+
+ " Check if the test has left any swap files behind. Delete them before
+ " running tests again, they might interfere.
+ let swapfiles = s:GetSwapFileList()
+ if len(swapfiles) > 0
+ call add(s:messages, "Found swap files: " .. string(swapfiles))
+ for name in swapfiles
+ call delete(name)
+ endfor
+ endif
endfunc
func AfterTheTest(func_name)
diff --git a/src/testdir/test_suspend.vim b/src/testdir/test_suspend.vim
index c96a1a6..7538c80 100644
--- a/src/testdir/test_suspend.vim
+++ b/src/testdir/test_suspend.vim
@@ -28,9 +28,6 @@
sleep 150m
endif
- " in case a previous failure left a swap file behind
- call delete('.Xfoo.swp')
-
let buf = term_start('/bin/sh')
" Wait for shell prompt.
call WaitForAssert({-> assert_match('[$#] $', term_getline(buf, '.'))})
@@ -69,7 +66,6 @@
exe buf . 'bwipe!'
call delete('Xfoo')
- call delete('.Xfoo.swp')
endfunc
func Test_suspend_autocmd()
@@ -82,9 +78,6 @@
sleep 150m
endif
- " in case a previous failure left a swap file behind
- call delete('.Xfoo.swp')
-
let buf = term_start('/bin/sh', #{term_rows: 6})
" Wait for shell prompt.
call WaitForAssert({-> assert_match('[$#] $', term_getline(buf, '.'))})
@@ -123,7 +116,6 @@
exe buf . 'bwipe!'
call delete('Xfoo')
- call delete('.Xfoo.swp')
endfunc
" vim: shiftwidth=2 sts=2 expandtab
diff --git a/src/testdir/test_swap.vim b/src/testdir/test_swap.vim
index 5237edc..c776ca5 100644
--- a/src/testdir/test_swap.vim
+++ b/src/testdir/test_swap.vim
@@ -110,6 +110,15 @@
w
let fname = s:swapname()
call assert_match('Xswapinfo', fname)
+
+ let nr = 0
+ for name in swapfilelist()
+ if name =~ '[\\/]' .. fname .. '$'
+ let nr += 1
+ endif
+ endfor
+ call assert_equal(1, nr)
+
let info = fname->swapinfo()
let ver = printf('VIM %d.%d', v:version / 100, v:version % 100)
diff --git a/src/testdir/test_tagjump.vim b/src/testdir/test_tagjump.vim
index 2c720a5..5185b20 100644
--- a/src/testdir/test_tagjump.vim
+++ b/src/testdir/test_tagjump.vim
@@ -733,9 +733,6 @@
" Tests for guessing the tag location
func Test_tag_guess()
- " in case a previous failure left a swap file behind
- call delete('.Xfoo.swp')
-
call writefile(["!_TAG_FILE_ENCODING\tutf-8\t//",
\ "func1\tXfoo\t/^int func1(int x)/",
\ "func2\tXfoo\t/^int func2(int y)/",
@@ -772,9 +769,6 @@
" Test for an unsorted tags file
func Test_tag_sort()
- " in case a previous failure left a swap file behind
- call delete('.Xfoo.swp')
-
let l = [
\ "first\tXfoo\t1",
\ "ten\tXfoo\t3",
@@ -802,9 +796,6 @@
" Test for an unsorted tags file
func Test_tag_fold()
- " in case a previous failure left a swap file behind
- call delete('.Xfoo.swp')
-
call writefile([
\ "!_TAG_FILE_ENCODING\tutf-8\t//",
\ "!_TAG_FILE_SORTED\t2\t/0=unsorted, 1=sorted, 2=foldcase/",
@@ -831,9 +822,6 @@
" Test for the :ltag command
func Test_ltag()
- " in case a previous failure left a swap file behind
- call delete('.Xfoo.swp')
-
call writefile([
\ "!_TAG_FILE_ENCODING\tutf-8\t//",
\ "first\tXfoo\t1",
@@ -871,9 +859,6 @@
" Test for setting the last search pattern to the tag search pattern
" when cpoptions has 't'
func Test_tag_last_search_pat()
- " in case a previous failure left a swap file behind
- call delete('.Xfoo.swp')
-
call writefile([
\ "!_TAG_FILE_ENCODING\tutf-8\t//",
\ "first\tXfoo\t/^int first() {}/",
@@ -902,9 +887,6 @@
" Tag stack tests
func Test_tag_stack()
- " in case a previous failure left a swap file behind
- call delete('.Xfoo.swp')
-
let l = []
for i in range(10, 31)
let l += ["var" .. i .. "\tXfoo\t/^int var" .. i .. ";$/"]
@@ -967,9 +949,6 @@
" Test for browsing multiple matching tags
func Test_tag_multimatch()
- " in case a previous failure left a swap file behind
- call delete('.Xfoo.swp')
-
call writefile([
\ "!_TAG_FILE_ENCODING\tutf-8\t//",
\ "first\tXfoo\t1",
@@ -1015,9 +994,6 @@
" Test for previewing multiple matching tags
func Test_preview_tag_multimatch()
- " in case a previous failure left a swap file behind
- call delete('.Xfoo.swp')
-
call writefile([
\ "!_TAG_FILE_ENCODING\tutf-8\t//",
\ "first\tXfoo\t1",
@@ -1066,9 +1042,6 @@
" Test for jumping to multiple matching tags across multiple :tags commands
func Test_tnext_multimatch()
- " in case a previous failure left a swap file behind
- call delete('.Xfoo.swp')
-
call writefile([
\ "!_TAG_FILE_ENCODING\tutf-8\t//",
\ "first\tXfoo1\t1",
@@ -1096,9 +1069,6 @@
" Test for jumping to multiple matching tags in non-existing files
func Test_multimatch_non_existing_files()
- " in case a previous failure left a swap file behind
- call delete('.Xfoo.swp')
-
call writefile([
\ "!_TAG_FILE_ENCODING\tutf-8\t//",
\ "first\tXfoo1\t1",
@@ -1116,9 +1086,6 @@
endfunc
func Test_tselect_listing()
- " in case a previous failure left a swap file behind
- call delete('.Xfoo.swp')
-
call writefile([
\ "!_TAG_FILE_ENCODING\tutf-8\t//",
\ "first\tXfoo\t1" .. ';"' .. "\tv\ttyperef:typename:int\tfile:",
@@ -1500,9 +1467,6 @@
" Test for 'tagbsearch' (binary search)
func Test_tagbsearch()
- " in case a previous failure left a swap file behind
- call delete('.Xfoo.swp')
-
" If a tags file header says the tags are sorted, but the tags are actually
" unsorted, then binary search should fail and linear search should work.
call writefile([
diff --git a/src/testdir/test_tcl.vim b/src/testdir/test_tcl.vim
index 03cae09..4c6537f 100644
--- a/src/testdir/test_tcl.vim
+++ b/src/testdir/test_tcl.vim
@@ -638,9 +638,6 @@
" Test $buf delcmd {cmd} (command executed when buffer is deleted)
func Test_buffer_delcmd()
- " in case a previous failure left a swap file behind
- call delete('.Xfoo.swp')
-
new Xfoo
split
tcl $::vim::current(buffer) delcmd [list set msg "buffer deleted"]
diff --git a/src/testdir/test_termcodes.vim b/src/testdir/test_termcodes.vim
index 2cb20e0..dd5280f 100644
--- a/src/testdir/test_termcodes.vim
+++ b/src/testdir/test_termcodes.vim
@@ -665,9 +665,6 @@
set mouse=a term=xterm
call WaitForResponses()
- " in case a previous failure left a swap file behind
- call delete('.Xfoo.swp')
-
let row = 1
for ttymouse_val in g:Ttymouse_values + g:Ttymouse_dec + g:Ttymouse_netterm
diff --git a/src/testdir/test_window_cmd.vim b/src/testdir/test_window_cmd.vim
index 9a042c3..0a4ae49 100644
--- a/src/testdir/test_window_cmd.vim
+++ b/src/testdir/test_window_cmd.vim
@@ -137,9 +137,6 @@
" Test the ":wincmd ^" and "<C-W>^" commands.
func Test_window_split_edit_alternate()
- " in case a previous failure left a swap file behind
- call delete('.Xfoo.swp')
-
" Test for failure when the alternate buffer/file no longer exists.
edit Xfoo | %bw
call assert_fails(':wincmd ^', 'E23:')
@@ -172,9 +169,6 @@
" Test the ":[count]wincmd ^" and "[count]<C-W>^" commands.
func Test_window_split_edit_bufnr()
- " in case a previous failure left a swap file behind
- call delete('.Xfoo.swp')
-
%bwipeout
let l:nr = bufnr('%') + 1
call assert_fails(':execute "normal! ' . l:nr . '\<C-W>\<C-^>"', 'E92:')