Mercurial > vim
comparison 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 |
comparison
equal
deleted
inserted
replaced
20811:af8f25c089dd | 20812:d8628d75c47a |
---|---|
381 call assert_fails('write', 'E505:') | 381 call assert_fails('write', 'E505:') |
382 let save_cpo = &cpo | 382 let save_cpo = &cpo |
383 set cpo+=W | 383 set cpo+=W |
384 call assert_fails('write!', 'E504:') | 384 call assert_fails('write!', 'E504:') |
385 let &cpo = save_cpo | 385 let &cpo = save_cpo |
386 call delete('Xfile') | 386 call setline(1, ['line1']) |
387 write! | |
388 call assert_equal(['line1'], readfile('Xfile')) | |
389 call delete('Xfile') | |
390 endfunc | |
391 | |
392 " Test for 'patchmode' | |
393 func Test_patchmode() | |
394 CheckNotBSD | |
395 call writefile(['one'], 'Xfile') | |
396 set patchmode=.orig nobackup writebackup | |
397 new Xfile | |
398 call setline(1, 'two') | |
399 " first write should create the .orig file | |
400 write | |
401 " TODO: Xfile.orig is not created in Cirrus FreeBSD CI test | |
402 call assert_equal(['one'], readfile('Xfile.orig')) | |
403 call setline(1, 'three') | |
404 " subsequent writes should not create/modify the .orig file | |
405 write | |
406 call assert_equal(['one'], readfile('Xfile.orig')) | |
407 set patchmode& backup& writebackup& | |
408 call delete('Xfile') | |
409 call delete('Xfile.orig') | |
410 endfunc | |
411 | |
412 " Test for writing to a file in a readonly directory | |
413 func Test_write_readonly_dir() | |
414 if !has('unix') || has('bsd') | |
415 " On MS-Windows, modifying files in a read-only directory is allowed. | |
416 " In Cirrus-CI for Freebsd, tests are run under a root account where | |
417 " modifying files in a read-only directory are allowed. | |
418 return | |
419 endif | |
420 call mkdir('Xdir') | |
421 call writefile(['one'], 'Xdir/Xfile1') | |
422 call setfperm('Xdir', 'r-xr--r--') | |
423 " try to create a new file in the directory | |
424 new Xdir/Xfile2 | |
425 call setline(1, 'two') | |
426 call assert_fails('write', 'E212:') | |
427 " try to create a backup file in the directory | |
428 edit! Xdir/Xfile1 | |
429 set backupdir=./Xdir | |
430 set patchmode=.orig | |
431 call assert_fails('write', 'E509:') | |
432 call setfperm('Xdir', 'rwxr--r--') | |
433 call delete('Xdir', 'rf') | |
434 set backupdir& patchmode& | |
387 endfunc | 435 endfunc |
388 | 436 |
389 " vim: shiftwidth=2 sts=2 expandtab | 437 " vim: shiftwidth=2 sts=2 expandtab |