diff src/testdir/test_writefile.vim @ 20812:d8628d75c47a v8.2.0958

patch 8.2.0958: not sufficient testing for buffer writing Commit: https://github.com/vim/vim/commit/1de5f7c81d5e78fb4d612134bd2dfa6ee9183fae Author: Bram Moolenaar <Bram@vim.org> Date: Thu Jun 11 19:22:43 2020 +0200 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 https://github.com/vim/vim/issues/6238)
author Bram Moolenaar <Bram@vim.org>
date Thu, 11 Jun 2020 19:30:04 +0200
parents 116c7bd5e980
children 1725bb56178a
line wrap: on
line diff
--- a/src/testdir/test_writefile.vim
+++ b/src/testdir/test_writefile.vim
@@ -383,7 +383,55 @@ 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
+
 " vim: shiftwidth=2 sts=2 expandtab