Skip to content

Commit b86abad

Browse files
committed
patch 8.2.1340: some tests fail on Cirrus CI and/or with FreeBSD
Problem: Some tests fail on Cirrus CI and/or with FreeBSD. Solution: Make 'backupskip' empty. Do not run tests as root. Check for directory when using viminfo. (Ozaki Kiichi, closes #6596)
1 parent 2caa159 commit b86abad

7 files changed

Lines changed: 57 additions & 45 deletions

File tree

.cirrus.yml

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,9 @@ freebsd_12_task:
1111
- NPROC=$(getconf _NPROCESSORS_ONLN)
1212
- ./configure --with-features=${FEATURES}
1313
- make -j${NPROC}
14-
- src/vim --version
1514
test_script:
16-
- make test
15+
- src/vim --version
16+
# run tests as user "cirrus" instead of root
17+
- pw useradd cirrus -m
18+
- chown -R cirrus:cirrus .
19+
- sudo -u cirrus make test

src/testdir/test_backup.vim

Lines changed: 20 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,22 @@ func Test_backup()
1919
call delete('Xbackup.txt~')
2020
endfunc
2121

22+
func Test_backup_backupskip()
23+
set backup backupdir=. backupskip=*.txt
24+
new
25+
call setline(1, ['line1', 'line2'])
26+
:f Xbackup.txt
27+
:w! Xbackup.txt
28+
" backup file is only created after
29+
" writing a second time (before overwriting)
30+
:w! Xbackup.txt
31+
call assert_false(filereadable('Xbackup.txt~'))
32+
bw!
33+
set backup&vim backupdir&vim backupskip&vim
34+
call delete('Xbackup.txt')
35+
call delete('Xbackup.txt~')
36+
endfunc
37+
2238
func Test_backup2()
2339
set backup backupdir=.// backupskip=
2440
new
@@ -30,7 +46,7 @@ func Test_backup2()
3046
:w! Xbackup.txt
3147
sp *Xbackup.txt~
3248
call assert_equal(['line1', 'line2', 'line3'], getline(1,'$'))
33-
let f=expand('%')
49+
let f = expand('%')
3450
call assert_match('%testdir%Xbackup.txt\~', f)
3551
bw!
3652
bw!
@@ -50,7 +66,7 @@ func Test_backup2_backupcopy()
5066
:w! Xbackup.txt
5167
sp *Xbackup.txt~
5268
call assert_equal(['line1', 'line2', 'line3'], getline(1,'$'))
53-
let f=expand('%')
69+
let f = expand('%')
5470
call assert_match('%testdir%Xbackup.txt\~', f)
5571
bw!
5672
bw!
@@ -61,14 +77,11 @@ endfunc
6177

6278
" Test for using a non-existing directory as a backup directory
6379
func Test_non_existing_backupdir()
64-
CheckNotBSD
65-
let save_backup = &backupdir
66-
set backupdir=./non_existing_dir
80+
set backupdir=./non_existing_dir backupskip=
6781
call writefile(['line1'], 'Xfile')
6882
new Xfile
69-
" TODO: write doesn't fail in Cirrus FreeBSD CI test
7083
call assert_fails('write', 'E510:')
71-
let &backupdir = save_backup
84+
set backupdir&vim backupskip&vim
7285
call delete('Xfile')
7386
endfunc
7487

src/testdir/test_edit.vim

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1682,7 +1682,6 @@ endfunc
16821682
" Test for editing a file without read permission
16831683
func Test_edit_file_no_read_perm()
16841684
CheckUnix
1685-
CheckNotBSD
16861685
call writefile(['one', 'two'], 'Xfile')
16871686
call setfperm('Xfile', '-w-------')
16881687
new

src/testdir/test_viminfo.vim

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -807,7 +807,7 @@ func Test_viminfo_perm()
807807

808808
" Try to write the viminfo to a directory
809809
call mkdir('Xdir')
810-
call assert_fails('wviminfo Xdir', 'E886:')
810+
call assert_fails('wviminfo Xdir', 'E137:')
811811
call delete('Xdir', 'rf')
812812
endfunc
813813

src/testdir/test_writefile.vim

Lines changed: 9 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -136,9 +136,7 @@ func Test_writefile_sync_arg()
136136
endfunc
137137

138138
func Test_writefile_sync_dev_stdout()
139-
if !has('unix')
140-
return
141-
endif
139+
CheckUnix
142140
if filewritable('/dev/stdout')
143141
" Just check that this doesn't cause an error.
144142
call writefile(['one'], '/dev/stdout')
@@ -371,13 +369,10 @@ endfunc
371369

372370
" Test for writing to a readonly file
373371
func Test_write_readonly()
374-
" In Cirrus-CI, the freebsd tests are run under a root account. So this test
375-
" doesn't fail.
376-
CheckNotBSD
377372
call writefile([], 'Xfile')
378373
call setfperm('Xfile', "r--------")
379374
edit Xfile
380-
set noreadonly
375+
set noreadonly backupskip=
381376
call assert_fails('write', 'E505:')
382377
let save_cpo = &cpo
383378
set cpo+=W
@@ -386,37 +381,32 @@ func Test_write_readonly()
386381
call setline(1, ['line1'])
387382
write!
388383
call assert_equal(['line1'], readfile('Xfile'))
384+
set backupskip&
389385
call delete('Xfile')
390386
endfunc
391387

392388
" Test for 'patchmode'
393389
func Test_patchmode()
394-
CheckNotBSD
395390
call writefile(['one'], 'Xfile')
396-
set patchmode=.orig nobackup writebackup
391+
set patchmode=.orig nobackup backupskip= writebackup
397392
new Xfile
398393
call setline(1, 'two')
399394
" first write should create the .orig file
400395
write
401-
" TODO: Xfile.orig is not created in Cirrus FreeBSD CI test
402396
call assert_equal(['one'], readfile('Xfile.orig'))
403397
call setline(1, 'three')
404398
" subsequent writes should not create/modify the .orig file
405399
write
406400
call assert_equal(['one'], readfile('Xfile.orig'))
407-
set patchmode& backup& writebackup&
401+
set patchmode& backup& backupskip& writebackup&
408402
call delete('Xfile')
409403
call delete('Xfile.orig')
410404
endfunc
411405

412406
" Test for writing to a file in a readonly directory
413407
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
408+
" On MS-Windows, modifying files in a read-only directory is allowed.
409+
CheckUnix
420410
call mkdir('Xdir')
421411
call writefile(['one'], 'Xdir/Xfile1')
422412
call setfperm('Xdir', 'r-xr--r--')
@@ -426,12 +416,12 @@ func Test_write_readonly_dir()
426416
call assert_fails('write', 'E212:')
427417
" try to create a backup file in the directory
428418
edit! Xdir/Xfile1
429-
set backupdir=./Xdir
419+
set backupdir=./Xdir backupskip=
430420
set patchmode=.orig
431421
call assert_fails('write', 'E509:')
432422
call setfperm('Xdir', 'rwxr--r--')
433423
call delete('Xdir', 'rf')
434-
set backupdir& patchmode&
424+
set backupdir& backupskip& patchmode&
435425
endfunc
436426

437427
" Test for writing a file using invalid file encoding

src/version.c

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -754,6 +754,8 @@ static char *(features[]) =
754754

755755
static int included_patches[] =
756756
{ /* Add new patch number below this line */
757+
/**/
758+
1340,
757759
/**/
758760
1339,
759761
/**/

src/viminfo.c

Lines changed: 20 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -3007,6 +3007,7 @@ read_viminfo(
30073007
{
30083008
FILE *fp;
30093009
char_u *fname;
3010+
stat_T st; // mch_stat() of existing viminfo file
30103011

30113012
if (no_viminfo())
30123013
return FAIL;
@@ -3031,6 +3032,11 @@ read_viminfo(
30313032
vim_free(fname);
30323033
if (fp == NULL)
30333034
return FAIL;
3035+
if (mch_fstat(fileno(fp), &st) < 0 || S_ISDIR(st.st_mode))
3036+
{
3037+
fclose(fp);
3038+
return FAIL;
3039+
}
30343040

30353041
viminfo_errcnt = 0;
30363042
do_viminfo(fp, NULL, flags);
@@ -3054,12 +3060,12 @@ write_viminfo(char_u *file, int forceit)
30543060
FILE *fp_out = NULL; // output viminfo file
30553061
char_u *tempname = NULL; // name of temp viminfo file
30563062
stat_T st_new; // mch_stat() of potential new file
3063+
stat_T st_old; // mch_stat() of existing viminfo file
30573064
#if defined(UNIX) || defined(VMS)
30583065
mode_t umask_save;
30593066
#endif
30603067
#ifdef UNIX
30613068
int shortname = FALSE; // use 8.3 file name
3062-
stat_T st_old; // mch_stat() of existing viminfo file
30633069
#endif
30643070
#ifdef MSWIN
30653071
int hidden = FALSE;
@@ -3097,20 +3103,20 @@ write_viminfo(char_u *file, int forceit)
30973103
// write the new viminfo into, in the same directory as the
30983104
// existing viminfo file, which will be renamed once all writing is
30993105
// successful.
3106+
if (mch_fstat(fileno(fp_in), &st_old) < 0
3107+
|| S_ISDIR(st_old.st_mode)
31003108
#ifdef UNIX
3101-
// For Unix we check the owner of the file. It's not very nice to
3102-
// overwrite a user's viminfo file after a "su root", with a
3103-
// viminfo file that the user can't read.
3104-
st_old.st_dev = (dev_t)0;
3105-
st_old.st_ino = 0;
3106-
st_old.st_mode = 0600;
3107-
if (mch_stat((char *)fname, &st_old) == 0
3108-
&& getuid() != ROOT_UID
3109-
&& !(st_old.st_uid == getuid()
3110-
? (st_old.st_mode & 0200)
3111-
: (st_old.st_gid == getgid()
3112-
? (st_old.st_mode & 0020)
3113-
: (st_old.st_mode & 0002))))
3109+
// For Unix we check the owner of the file. It's not very nice
3110+
// to overwrite a user's viminfo file after a "su root", with a
3111+
// viminfo file that the user can't read.
3112+
|| (getuid() != ROOT_UID
3113+
&& !(st_old.st_uid == getuid()
3114+
? (st_old.st_mode & 0200)
3115+
: (st_old.st_gid == getgid()
3116+
? (st_old.st_mode & 0020)
3117+
: (st_old.st_mode & 0002))))
3118+
#endif
3119+
)
31143120
{
31153121
int tt = msg_didany;
31163122

@@ -3120,7 +3126,6 @@ write_viminfo(char_u *file, int forceit)
31203126
fclose(fp_in);
31213127
goto end;
31223128
}
3123-
#endif
31243129
#ifdef MSWIN
31253130
// Get the file attributes of the existing viminfo file.
31263131
hidden = mch_ishidden(fname);

0 commit comments

Comments
 (0)