Merge pull request #17287 from zeertzjq/vim-8.1.2133

vim-patch:8.1.2133: some tests fail when run as root
This commit is contained in:
zeertzjq 2022-02-04 22:24:38 +08:00 committed by GitHub
commit c50cea3de4
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
4 changed files with 32 additions and 9 deletions

View File

@ -113,6 +113,14 @@ func CheckNotGui()
endif
endfunc
" Command to check that test is not running as root
command CheckNotRoot call CheckNotRoot()
func CheckNotRoot()
if IsRoot()
throw 'Skipped: cannot run test as root'
endif
endfunc
" Command to check that the current language is English
command CheckEnglish call CheckEnglish()
func CheckEnglish()

View File

@ -343,6 +343,15 @@ func RunVimPiped(before, after, arguments, pipecmd)
return 1
endfunc
func IsRoot()
if !has('unix')
return v:false
elseif $USER == 'root' || system('id -un') =~ '\<root\>'
return v:true
endif
return v:false
endfunc
" Get all messages but drop the maintainer entry.
func GetMessages()
redir => result

View File

@ -1,5 +1,7 @@
" Test rename()
source shared.vim
func Test_rename_file_to_file()
call writefile(['foo'], 'Xrename1')
@ -81,7 +83,7 @@ func Test_rename_copy()
call assert_equal(0, rename('Xrenamedir/Xrenamefile', 'Xrenamefile'))
if !has('win32')
if !has('win32') && !IsRoot()
" On Windows, the source file is removed despite
" its directory being made not writable.
call assert_equal(['foo'], readfile('Xrenamedir/Xrenamefile'))

View File

@ -1,6 +1,7 @@
" Tests for the swap feature
source check.vim
source shared.vim
func s:swapname()
return trim(execute('swapname'))
@ -198,14 +199,17 @@ func Test_swapfile_delete()
quit
call assert_equal(fnamemodify(swapfile_name, ':t'), fnamemodify(s:swapname, ':t'))
" Write the swapfile with a modified PID, now it will be automatically
" deleted. Process one should never be Vim.
let swapfile_bytes[24:27] = 0z01000000
call writefile(swapfile_bytes, swapfile_name)
let s:swapname = ''
split XswapfileText
quit
call assert_equal('', s:swapname)
" This test won't work as root because root can successfully run kill(1, 0)
if !IsRoot()
" Write the swapfile with a modified PID, now it will be automatically
" deleted. Process one should never be Vim.
let swapfile_bytes[24:27] = 0z01000000
call writefile(swapfile_bytes, swapfile_name)
let s:swapname = ''
split XswapfileText
quit
call assert_equal('', s:swapname)
endif
" Now set the modified flag, the swap file will not be deleted
let swapfile_bytes[28 + 80 + 899] = 0x55