diff options
author | zeertzjq <zeertzjq@outlook.com> | 2022-11-05 08:22:46 +0800 |
---|---|---|
committer | zeertzjq <zeertzjq@outlook.com> | 2022-11-05 09:25:31 +0800 |
commit | b002499c1978c98cc4dfc3a3f2326997720d571a (patch) | |
tree | 5c8bd2776e3cbac280c359f863ae1d1d59ced0d0 | |
parent | 40ca9b9528e5a4f043f0e6858786bf0c3d992a90 (diff) | |
download | rneovim-b002499c1978c98cc4dfc3a3f2326997720d571a.tar.gz rneovim-b002499c1978c98cc4dfc3a3f2326997720d571a.tar.bz2 rneovim-b002499c1978c98cc4dfc3a3f2326997720d571a.zip |
vim-patch:8.2.0958: not sufficient testing for buffer writing
Problem: Not sufficient testing for buffer writing.
Solution: Add a few tests. (Yegappan Lakshmanan, closes vim/vim#6238)
https://github.com/vim/vim/commit/1de5f7c81d5e78fb4d612134bd2dfa6ee9183fae
-rw-r--r-- | src/nvim/testdir/test_backup.vim | 18 | ||||
-rw-r--r-- | src/nvim/testdir/test_writefile.vim | 48 |
2 files changed, 66 insertions, 0 deletions
diff --git a/src/nvim/testdir/test_backup.vim b/src/nvim/testdir/test_backup.vim index ce2bfe72bc..7eff818732 100644 --- a/src/nvim/testdir/test_backup.vim +++ b/src/nvim/testdir/test_backup.vim @@ -1,5 +1,7 @@ " Tests for the backup function +source check.vim + func Test_backup() set backup backupdir=. backupskip= new @@ -56,3 +58,19 @@ func Test_backup2_backupcopy() call delete(f) set backup&vim backupdir&vim backupcopy&vim backupskip&vim endfunc + +" Test for using a non-existing directory as a backup directory +func Test_non_existing_backupdir() + throw 'Skipped: Nvim auto-creates backup directory' + CheckNotBSD + let save_backup = &backupdir + set backupdir=./non_existing_dir + call writefile(['line1'], 'Xfile') + new Xfile + " TODO: write doesn't fail in Cirrus FreeBSD CI test + call assert_fails('write', 'E510:') + let &backupdir = save_backup + call delete('Xfile') +endfunc + +" vim: shiftwidth=2 sts=2 expandtab diff --git a/src/nvim/testdir/test_writefile.vim b/src/nvim/testdir/test_writefile.vim index 59214d1aab..5ee13ef144 100644 --- a/src/nvim/testdir/test_writefile.vim +++ b/src/nvim/testdir/test_writefile.vim @@ -398,9 +398,57 @@ func Test_write_readonly() set cpo+=W call assert_fails('write!', 'E504:') let &cpo = save_cpo + call setline(1, ['line1']) + write! + call assert_equal(['line1'], readfile('Xfile')) call delete('Xfile') endfunc +" Test for 'patchmode' +func Test_patchmode() + CheckNotBSD + call writefile(['one'], 'Xfile') + set patchmode=.orig nobackup writebackup + new Xfile + call setline(1, 'two') + " first write should create the .orig file + write + " TODO: Xfile.orig is not created in Cirrus FreeBSD CI test + call assert_equal(['one'], readfile('Xfile.orig')) + call setline(1, 'three') + " subsequent writes should not create/modify the .orig file + write + call assert_equal(['one'], readfile('Xfile.orig')) + set patchmode& backup& writebackup& + call delete('Xfile') + call delete('Xfile.orig') +endfunc + +" Test for writing to a file in a readonly directory +func Test_write_readonly_dir() + if !has('unix') || has('bsd') + " On MS-Windows, modifying files in a read-only directory is allowed. + " In Cirrus-CI for Freebsd, tests are run under a root account where + " modifying files in a read-only directory are allowed. + return + endif + call mkdir('Xdir') + call writefile(['one'], 'Xdir/Xfile1') + call setfperm('Xdir', 'r-xr--r--') + " try to create a new file in the directory + new Xdir/Xfile2 + call setline(1, 'two') + call assert_fails('write', 'E212:') + " try to create a backup file in the directory + edit! Xdir/Xfile1 + set backupdir=./Xdir + set patchmode=.orig + call assert_fails('write', 'E509:') + call setfperm('Xdir', 'rwxr--r--') + call delete('Xdir', 'rf') + set backupdir& patchmode& +endfunc + " Test for writing a file using invalid file encoding func Test_write_invalid_encoding() new |