forked from aniani/vim
patch 8.1.2133: some tests fail when run as root
Problem: Some tests fail when run as root. Solution: Add CheckNotRoot and use it. (James McCoy, closes #5020)
This commit is contained in:
@@ -1,3 +1,5 @@
|
|||||||
|
source shared.vim
|
||||||
|
|
||||||
" Command to check for the presence of a feature.
|
" Command to check for the presence of a feature.
|
||||||
command -nargs=1 CheckFeature call CheckFeature(<f-args>)
|
command -nargs=1 CheckFeature call CheckFeature(<f-args>)
|
||||||
func CheckFeature(name)
|
func CheckFeature(name)
|
||||||
@@ -102,3 +104,11 @@ func CheckNotGui()
|
|||||||
throw 'Skipped: only works in the terminal'
|
throw 'Skipped: only works in the terminal'
|
||||||
endif
|
endif
|
||||||
endfunc
|
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
|
||||||
|
@@ -325,3 +325,12 @@ func RunVimPiped(before, after, arguments, pipecmd)
|
|||||||
endif
|
endif
|
||||||
return 1
|
return 1
|
||||||
endfunc
|
endfunc
|
||||||
|
|
||||||
|
func IsRoot()
|
||||||
|
if !has('unix')
|
||||||
|
return v:false
|
||||||
|
elseif $USER == 'root' || system('id -un') =~ '\<root\>'
|
||||||
|
return v:true
|
||||||
|
endif
|
||||||
|
return v:false
|
||||||
|
endfunc
|
||||||
|
@@ -1,5 +1,7 @@
|
|||||||
" Test rename()
|
" Test rename()
|
||||||
|
|
||||||
|
source shared.vim
|
||||||
|
|
||||||
func Test_rename_file_to_file()
|
func Test_rename_file_to_file()
|
||||||
call writefile(['foo'], 'Xrename1')
|
call writefile(['foo'], 'Xrename1')
|
||||||
|
|
||||||
@@ -81,7 +83,7 @@ func Test_rename_copy()
|
|||||||
|
|
||||||
call assert_equal(0, rename('Xrenamedir/Xrenamefile', 'Xrenamefile'))
|
call assert_equal(0, rename('Xrenamedir/Xrenamefile', 'Xrenamefile'))
|
||||||
|
|
||||||
if !has('win32')
|
if !has('win32') && !IsRoot()
|
||||||
" On Windows, the source file is removed despite
|
" On Windows, the source file is removed despite
|
||||||
" its directory being made not writable.
|
" its directory being made not writable.
|
||||||
call assert_equal(['foo'], readfile('Xrenamedir/Xrenamefile'))
|
call assert_equal(['foo'], readfile('Xrenamedir/Xrenamefile'))
|
||||||
|
@@ -1,5 +1,7 @@
|
|||||||
" Tests for the swap feature
|
" Tests for the swap feature
|
||||||
|
|
||||||
|
source shared.vim
|
||||||
|
|
||||||
func s:swapname()
|
func s:swapname()
|
||||||
return trim(execute('swapname'))
|
return trim(execute('swapname'))
|
||||||
endfunc
|
endfunc
|
||||||
@@ -196,6 +198,8 @@ func Test_swapfile_delete()
|
|||||||
quit
|
quit
|
||||||
call assert_equal(fnamemodify(swapfile_name, ':t'), fnamemodify(s:swapname, ':t'))
|
call assert_equal(fnamemodify(swapfile_name, ':t'), fnamemodify(s:swapname, ':t'))
|
||||||
|
|
||||||
|
" 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
|
" Write the swapfile with a modified PID, now it will be automatically
|
||||||
" deleted. Process one should never be Vim.
|
" deleted. Process one should never be Vim.
|
||||||
let swapfile_bytes[24:27] = 0z01000000
|
let swapfile_bytes[24:27] = 0z01000000
|
||||||
@@ -204,6 +208,7 @@ func Test_swapfile_delete()
|
|||||||
split XswapfileText
|
split XswapfileText
|
||||||
quit
|
quit
|
||||||
call assert_equal('', s:swapname)
|
call assert_equal('', s:swapname)
|
||||||
|
endif
|
||||||
|
|
||||||
" Now set the modified flag, the swap file will not be deleted
|
" Now set the modified flag, the swap file will not be deleted
|
||||||
let swapfile_bytes[28 + 80 + 899] = 0x55
|
let swapfile_bytes[28 + 80 + 899] = 0x55
|
||||||
|
@@ -570,7 +570,7 @@ func Test_terminal_cwd_failure()
|
|||||||
|
|
||||||
" Case 3: Directory exists but is not accessible.
|
" Case 3: Directory exists but is not accessible.
|
||||||
" Skip this for root, it will be accessible anyway.
|
" Skip this for root, it will be accessible anyway.
|
||||||
if $USER != 'root'
|
if !IsRoot()
|
||||||
call mkdir('XdirNoAccess', '', '0600')
|
call mkdir('XdirNoAccess', '', '0600')
|
||||||
" return early if the directory permissions could not be set properly
|
" return early if the directory permissions could not be set properly
|
||||||
if getfperm('XdirNoAccess')[2] == 'x'
|
if getfperm('XdirNoAccess')[2] == 'x'
|
||||||
@@ -1353,7 +1353,6 @@ endfunc
|
|||||||
func Test_terminal_api_call()
|
func Test_terminal_api_call()
|
||||||
CheckRunVimInTerminal
|
CheckRunVimInTerminal
|
||||||
|
|
||||||
call ch_logfile('logfile', 'w')
|
|
||||||
unlet! g:called_bufnum
|
unlet! g:called_bufnum
|
||||||
unlet! g:called_arg
|
unlet! g:called_arg
|
||||||
|
|
||||||
|
@@ -736,6 +736,7 @@ endfunc
|
|||||||
" Test for an unwritable and unreadble 'viminfo' file
|
" Test for an unwritable and unreadble 'viminfo' file
|
||||||
func Test_viminfo_perm()
|
func Test_viminfo_perm()
|
||||||
CheckUnix
|
CheckUnix
|
||||||
|
CheckNotRoot
|
||||||
call writefile([''], 'Xviminfo')
|
call writefile([''], 'Xviminfo')
|
||||||
call setfperm('Xviminfo', 'r-x------')
|
call setfperm('Xviminfo', 'r-x------')
|
||||||
call assert_fails('wviminfo Xviminfo', 'E137:')
|
call assert_fails('wviminfo Xviminfo', 'E137:')
|
||||||
|
@@ -753,6 +753,8 @@ static char *(features[]) =
|
|||||||
|
|
||||||
static int included_patches[] =
|
static int included_patches[] =
|
||||||
{ /* Add new patch number below this line */
|
{ /* Add new patch number below this line */
|
||||||
|
/**/
|
||||||
|
2133,
|
||||||
/**/
|
/**/
|
||||||
2132,
|
2132,
|
||||||
/**/
|
/**/
|
||||||
|
Reference in New Issue
Block a user