]> granicus.if.org Git - vim/commitdiff
patch 8.1.2133: some tests fail when run as root v8.1.2133
authorBram Moolenaar <Bram@vim.org>
Thu, 10 Oct 2019 14:46:17 +0000 (16:46 +0200)
committerBram Moolenaar <Bram@vim.org>
Thu, 10 Oct 2019 14:46:17 +0000 (16:46 +0200)
Problem:    Some tests fail when run as root.
Solution:   Add CheckNotRoot and use it. (James McCoy, closes #5020)

src/testdir/check.vim
src/testdir/shared.vim
src/testdir/test_rename.vim
src/testdir/test_swap.vim
src/testdir/test_terminal.vim
src/testdir/test_viminfo.vim
src/version.c

index f176f833298151538d89ac12481283d2e7b8ce5c..6c3b1be4ff1608ede13dfad8c061dfcfff72ce7f 100644 (file)
@@ -1,3 +1,5 @@
+source shared.vim
+
 " Command to check for the presence of a feature.
 command -nargs=1 CheckFeature call CheckFeature(<f-args>)
 func CheckFeature(name)
@@ -102,3 +104,11 @@ func CheckNotGui()
     throw 'Skipped: only works in the terminal'
   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
index cf15a4cc4150024d1ebf189ba466f60b16842745..78f204c10e83cf8ee3f442736c896f61e79c5590 100644 (file)
@@ -325,3 +325,12 @@ func RunVimPiped(before, after, arguments, pipecmd)
   endif
   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
index 3887fcfabfb355a5f494bafaf90fe3fbdee088ed..5359b84923cf4a1e64fdb5239d47ebac306efd05 100644 (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'))
index 6e01ad00dae915dc5a4057d3a3bf6e53507c157e..aa67b430e6fb02e0f32aaaabc29d4602388fe608 100644 (file)
@@ -1,5 +1,7 @@
 " Tests for the swap feature
 
+source shared.vim
+
 func s:swapname()
   return trim(execute('swapname'))
 endfunc
@@ -196,14 +198,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
index 0041965f30c4546854ed24480d0b1379c45bc31f..7e8ef763b4eb8e51b58139f0561ce0f2e17a82fc 100644 (file)
@@ -570,7 +570,7 @@ func Test_terminal_cwd_failure()
 
   " Case 3: Directory exists but is not accessible.
   " Skip this for root, it will be accessible anyway.
-  if $USER != 'root'
+  if !IsRoot()
     call mkdir('XdirNoAccess', '', '0600')
     " return early if the directory permissions could not be set properly
     if getfperm('XdirNoAccess')[2] == 'x'
@@ -1353,7 +1353,6 @@ endfunc
 func Test_terminal_api_call()
   CheckRunVimInTerminal
 
-call ch_logfile('logfile', 'w')
   unlet! g:called_bufnum
   unlet! g:called_arg
 
index 7ea9f78da49424e78cac932f9e0e55ea6dc7973f..a9dc8fd31a33a48669b00f318b498aa7c07b92a3 100644 (file)
@@ -736,6 +736,7 @@ endfunc
 " Test for an unwritable and unreadble 'viminfo' file
 func Test_viminfo_perm()
   CheckUnix
+  CheckNotRoot
   call writefile([''], 'Xviminfo')
   call setfperm('Xviminfo', 'r-x------')
   call assert_fails('wviminfo Xviminfo', 'E137:')
index 4e0af78a45cb6314dcbad7daa9f73b129dbfa9d4..acbcc2d258f0cf2710c3108ff97a88dc3a0341df 100644 (file)
@@ -753,6 +753,8 @@ static char *(features[]) =
 
 static int included_patches[] =
 {   /* Add new patch number below this line */
+/**/
+    2133,
 /**/
     2132,
 /**/