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)