aboutsummaryrefslogtreecommitdiff
path: root/src/nvim/testdir
diff options
context:
space:
mode:
authorzeertzjq <zeertzjq@outlook.com>2022-11-17 18:13:13 +0800
committerzeertzjq <zeertzjq@outlook.com>2022-11-17 18:24:21 +0800
commitabe1dd308e1f37bb9b06a85da82e066135b86ff9 (patch)
treeae0ff3691dd597cfd6b0d9f05aa26417ce538e23 /src/nvim/testdir
parent98bcf49d2692af1f2c21f6d10fd056855d4ea238 (diff)
downloadrneovim-abe1dd308e1f37bb9b06a85da82e066135b86ff9.tar.gz
rneovim-abe1dd308e1f37bb9b06a85da82e066135b86ff9.tar.bz2
rneovim-abe1dd308e1f37bb9b06a85da82e066135b86ff9.zip
vim-patch:8.2.1970: it is easy to make mistakes when cleaning up swap files
Problem: It is easy to make mistakes when cleaning up swap files after the system crashed. Solution: Warn for the process still running after recovery. Do not automatically delete a swap file created on another system. (David Fries, closes vim/vim#7273) https://github.com/vim/vim/commit/f883508e36c209d60388b944e04e22a3fcf603cf
Diffstat (limited to 'src/nvim/testdir')
-rw-r--r--src/nvim/testdir/test_swap.vim46
1 files changed, 46 insertions, 0 deletions
diff --git a/src/nvim/testdir/test_swap.vim b/src/nvim/testdir/test_swap.vim
index 34d1d585ce..7941f78ced 100644
--- a/src/nvim/testdir/test_swap.vim
+++ b/src/nvim/testdir/test_swap.vim
@@ -421,6 +421,52 @@ func Test_swap_symlink()
call delete('Xswapdir', 'rf')
endfunc
+func Test_swap_auto_delete()
+ " Create a valid swapfile by editing a file with a special extension.
+ split Xtest.scr
+ call setline(1, ['one', 'two', 'three'])
+ write " file is written, not modified
+ write " write again to make sure the swapfile is created
+ " read the swapfile as a Blob
+ let swapfile_name = swapname('%')
+ let swapfile_bytes = readfile(swapfile_name, 'B')
+
+ " Forget about the file, recreate the swap file, then edit it again. The
+ " swap file should be automatically deleted.
+ bwipe!
+ " change the process ID to avoid the "still running" warning
+ let swapfile_bytes[24] = 0x99
+ call writefile(swapfile_bytes, swapfile_name)
+ edit Xtest.scr
+ " will end up using the same swap file after deleting the existing one
+ call assert_equal(swapfile_name, swapname('%'))
+ bwipe!
+
+ " create the swap file again, but change the host name so that it won't be
+ " deleted
+ autocmd! SwapExists
+ augroup test_swap_recover_ext
+ autocmd!
+ autocmd SwapExists * let v:swapchoice = 'e'
+ augroup END
+
+ " change the host name
+ let swapfile_bytes[28 + 40] = 0x89
+ call writefile(swapfile_bytes, swapfile_name)
+ edit Xtest.scr
+ call assert_equal(1, filereadable(swapfile_name))
+ " will use another same swap file name
+ call assert_notequal(swapfile_name, swapname('%'))
+ bwipe!
+
+ call delete('Xtest.scr')
+ call delete(swapfile_name)
+ augroup test_swap_recover_ext
+ autocmd!
+ augroup END
+ augroup! test_swap_recover_ext
+endfunc
+
func Test_no_swap_file()
call assert_equal("\nNo swap file", execute('swapname'))
endfunc