2019-11-18 00:38:27 -07:00
|
|
|
" Tests for the backup function
|
|
|
|
|
2022-11-04 17:22:46 -07:00
|
|
|
source check.vim
|
|
|
|
|
2019-11-18 00:38:27 -07:00
|
|
|
func Test_backup()
|
2020-08-02 08:56:22 -07:00
|
|
|
set backup backupdir=. backupskip=
|
2019-11-18 00:38:27 -07:00
|
|
|
new
|
|
|
|
call setline(1, ['line1', 'line2'])
|
|
|
|
:f Xbackup.txt
|
|
|
|
:w! Xbackup.txt
|
|
|
|
" backup file is only created after
|
|
|
|
" writing a second time (before overwriting)
|
|
|
|
:w! Xbackup.txt
|
|
|
|
let l = readfile('Xbackup.txt~')
|
|
|
|
call assert_equal(['line1', 'line2'], l)
|
|
|
|
bw!
|
2020-08-02 08:56:22 -07:00
|
|
|
set backup&vim backupdir&vim backupskip&vim
|
2019-11-18 00:38:27 -07:00
|
|
|
call delete('Xbackup.txt')
|
|
|
|
call delete('Xbackup.txt~')
|
|
|
|
endfunc
|
|
|
|
|
2022-11-06 07:13:36 -07:00
|
|
|
func Test_backup_backupskip()
|
|
|
|
set backup backupdir=. backupskip=*.txt
|
|
|
|
new
|
|
|
|
call setline(1, ['line1', 'line2'])
|
|
|
|
:f Xbackup.txt
|
|
|
|
:w! Xbackup.txt
|
|
|
|
" backup file is only created after
|
|
|
|
" writing a second time (before overwriting)
|
|
|
|
:w! Xbackup.txt
|
|
|
|
call assert_false(filereadable('Xbackup.txt~'))
|
|
|
|
bw!
|
|
|
|
set backup&vim backupdir&vim backupskip&vim
|
|
|
|
call delete('Xbackup.txt')
|
|
|
|
call delete('Xbackup.txt~')
|
|
|
|
endfunc
|
|
|
|
|
2019-11-18 00:38:27 -07:00
|
|
|
func Test_backup2()
|
2020-08-02 08:56:22 -07:00
|
|
|
set backup backupdir=.// backupskip=
|
2019-11-18 00:38:27 -07:00
|
|
|
new
|
|
|
|
call setline(1, ['line1', 'line2', 'line3'])
|
|
|
|
:f Xbackup.txt
|
|
|
|
:w! Xbackup.txt
|
|
|
|
" backup file is only created after
|
|
|
|
" writing a second time (before overwriting)
|
|
|
|
:w! Xbackup.txt
|
|
|
|
sp *Xbackup.txt~
|
|
|
|
call assert_equal(['line1', 'line2', 'line3'], getline(1,'$'))
|
2022-11-06 07:13:36 -07:00
|
|
|
let f = expand('%')
|
2020-08-01 10:36:43 -07:00
|
|
|
call assert_match('%testdir%Xbackup.txt\~', f)
|
2019-11-18 00:38:27 -07:00
|
|
|
bw!
|
|
|
|
bw!
|
|
|
|
call delete('Xbackup.txt')
|
|
|
|
call delete(f)
|
2020-08-02 08:56:22 -07:00
|
|
|
set backup&vim backupdir&vim backupskip&vim
|
2019-11-18 00:38:27 -07:00
|
|
|
endfunc
|
|
|
|
|
|
|
|
func Test_backup2_backupcopy()
|
2020-08-02 08:56:22 -07:00
|
|
|
set backup backupdir=.// backupcopy=yes backupskip=
|
2019-11-18 00:38:27 -07:00
|
|
|
new
|
|
|
|
call setline(1, ['line1', 'line2', 'line3'])
|
|
|
|
:f Xbackup.txt
|
|
|
|
:w! Xbackup.txt
|
|
|
|
" backup file is only created after
|
|
|
|
" writing a second time (before overwriting)
|
|
|
|
:w! Xbackup.txt
|
|
|
|
sp *Xbackup.txt~
|
|
|
|
call assert_equal(['line1', 'line2', 'line3'], getline(1,'$'))
|
2022-11-06 07:13:36 -07:00
|
|
|
let f = expand('%')
|
2020-08-01 10:36:43 -07:00
|
|
|
call assert_match('%testdir%Xbackup.txt\~', f)
|
2019-11-18 00:38:27 -07:00
|
|
|
bw!
|
|
|
|
bw!
|
|
|
|
call delete('Xbackup.txt')
|
|
|
|
call delete(f)
|
2020-08-02 08:56:22 -07:00
|
|
|
set backup&vim backupdir&vim backupcopy&vim backupskip&vim
|
2019-11-18 00:38:27 -07:00
|
|
|
endfunc
|
2022-11-04 17:22:46 -07:00
|
|
|
|
|
|
|
" Test for using a non-existing directory as a backup directory
|
|
|
|
func Test_non_existing_backupdir()
|
|
|
|
throw 'Skipped: Nvim auto-creates backup directory'
|
2022-11-06 07:13:36 -07:00
|
|
|
set backupdir=./non_existing_dir backupskip=
|
2023-08-21 01:27:14 -07:00
|
|
|
call writefile(['line1'], 'Xbackupdir')
|
|
|
|
new Xbackupdir
|
2022-11-04 17:22:46 -07:00
|
|
|
call assert_fails('write', 'E510:')
|
2022-11-06 07:13:36 -07:00
|
|
|
set backupdir&vim backupskip&vim
|
2023-08-21 01:27:14 -07:00
|
|
|
call delete('Xbackupdir')
|
2022-11-04 17:22:46 -07:00
|
|
|
endfunc
|
|
|
|
|
|
|
|
" vim: shiftwidth=2 sts=2 expandtab
|