To: vim_dev@googlegroups.com Subject: Patch 8.1.2133 Fcc: outbox From: Bram Moolenaar Mime-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit ------------ Patch 8.1.2133 Problem: Some tests fail when run as root. Solution: Add CheckNotRoot and use it. (James McCoy, closes #5020) Files: 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 *** ../vim-8.1.2132/src/testdir/check.vim 2019-08-09 14:13:54.789278493 +0200 --- src/testdir/check.vim 2019-10-10 16:40:31.739786696 +0200 *************** *** 1,3 **** --- 1,5 ---- + source shared.vim + " Command to check for the presence of a feature. command -nargs=1 CheckFeature call CheckFeature() func CheckFeature(name) *************** *** 102,104 **** --- 104,114 ---- 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 *** ../vim-8.1.2132/src/testdir/shared.vim 2019-09-01 15:26:20.043537901 +0200 --- src/testdir/shared.vim 2019-10-10 16:40:31.739786696 +0200 *************** *** 325,327 **** --- 325,336 ---- endif return 1 endfunc + + func IsRoot() + if !has('unix') + return v:false + elseif $USER == 'root' || system('id -un') =~ '\' + return v:true + endif + return v:false + endfunc *** ../vim-8.1.2132/src/testdir/test_rename.vim 2019-09-04 22:28:53.061026888 +0200 --- src/testdir/test_rename.vim 2019-10-10 16:40:31.739786696 +0200 *************** *** 1,5 **** --- 1,7 ---- " Test rename() + source shared.vim + func Test_rename_file_to_file() call writefile(['foo'], 'Xrename1') *************** *** 81,87 **** call assert_equal(0, rename('Xrenamedir/Xrenamefile', 'Xrenamefile')) ! if !has('win32') " On Windows, the source file is removed despite " its directory being made not writable. call assert_equal(['foo'], readfile('Xrenamedir/Xrenamefile')) --- 83,89 ---- call assert_equal(0, rename('Xrenamedir/Xrenamefile', 'Xrenamefile')) ! 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')) *** ../vim-8.1.2132/src/testdir/test_swap.vim 2019-09-07 19:05:02.341280926 +0200 --- src/testdir/test_swap.vim 2019-10-10 16:40:31.739786696 +0200 *************** *** 1,5 **** --- 1,7 ---- " Tests for the swap feature + source shared.vim + func s:swapname() return trim(execute('swapname')) endfunc *************** *** 196,209 **** 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) " Now set the modified flag, the swap file will not be deleted let swapfile_bytes[28 + 80 + 899] = 0x55 --- 198,214 ---- quit 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 ! " 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 *** ../vim-8.1.2132/src/testdir/test_terminal.vim 2019-09-26 23:08:10.505926873 +0200 --- src/testdir/test_terminal.vim 2019-10-10 16:40:31.739786696 +0200 *************** *** 570,576 **** " Case 3: Directory exists but is not accessible. " Skip this for root, it will be accessible anyway. ! if $USER != 'root' call mkdir('XdirNoAccess', '', '0600') " return early if the directory permissions could not be set properly if getfperm('XdirNoAccess')[2] == 'x' --- 570,576 ---- " Case 3: Directory exists but is not accessible. " Skip this for root, it will be accessible anyway. ! if !IsRoot() call mkdir('XdirNoAccess', '', '0600') " return early if the directory permissions could not be set properly if getfperm('XdirNoAccess')[2] == 'x' *************** *** 1353,1359 **** func Test_terminal_api_call() CheckRunVimInTerminal - call ch_logfile('logfile', 'w') unlet! g:called_bufnum unlet! g:called_arg --- 1353,1358 ---- *** ../vim-8.1.2132/src/testdir/test_viminfo.vim 2019-10-09 22:01:20.599438001 +0200 --- src/testdir/test_viminfo.vim 2019-10-10 16:42:04.819401359 +0200 *************** *** 736,741 **** --- 736,742 ---- " 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:') *** ../vim-8.1.2132/src/version.c 2019-10-10 16:35:57.336930439 +0200 --- src/version.c 2019-10-10 16:43:57.678935373 +0200 *************** *** 755,756 **** --- 755,758 ---- { /* Add new patch number below this line */ + /**/ + 2133, /**/ -- BEDEVERE: Look! It's the old man from scene 24 - what's he Doing here? ARTHUR: He is the keeper of the Bridge. He asks each traveler five questions ... GALAHAD: Three questions. "Monty Python and the Holy Grail" PYTHON (MONTY) PICTURES LTD /// Bram Moolenaar -- Bram@Moolenaar.net -- http://www.Moolenaar.net \\\ /// sponsor Vim, vote for features -- http://www.Vim.org/sponsor/ \\\ \\\ an exciting new programming language -- http://www.Zimbu.org /// \\\ help me help AIDS victims -- http://ICCF-Holland.org ///