From a34ba821076476a68e0e579723d68e896f771ba6 Mon Sep 17 00:00:00 2001 From: Maxim Kim Date: Wed, 17 Apr 2024 22:29:06 +0200 Subject: patch 9.1.0345: Problem: gvimrc not sourced from XDG_CONFIG_HOME Problem: gvimrc not sourced from XDG_CONFIG_HOME (after v9.1.0327) Solution: Also try to source from ~/.config/vim/gvimrc and $XDG_CONFIG_HOME/vim/gvimrc (Maxim Kim) fixes: #14567 closes: #14568 Signed-off-by: Maxim Kim Signed-off-by: Christian Brabandt --- src/testdir/test_xdg.vim | 147 +++++++++++++++++++++++++++++++++++++++++++++-- 1 file changed, 142 insertions(+), 5 deletions(-) (limited to 'src/testdir') diff --git a/src/testdir/test_xdg.vim b/src/testdir/test_xdg.vim index 557864e257..7c0c8ef619 100644 --- a/src/testdir/test_xdg.vim +++ b/src/testdir/test_xdg.vim @@ -3,7 +3,6 @@ source check.vim source shared.vim -source mouse.vim func s:get_rcs() let rcs = { @@ -44,7 +43,7 @@ func Test_xdg_runtime_files() call mkdir(expand('~/.vim/'), 'pD') call mkdir(expand('~/.config/vim/'), 'pD') call mkdir(expand('~/xdg/vim/'), 'pD') - + let rc1=expand('~/.vimrc') let rc2=expand('~/.vim/vimrc') let rc3=expand('~/.config/vim/vimrc') @@ -147,15 +146,153 @@ func Test_xdg_version() unlet $XDG_CONFIG_HOME let a = execute(':version')->split('\n') let a = filter(a, { _, val -> val =~ '\.config\|XDG_CONFIG_HOME' }) - call assert_equal(1, len(a)) - call assert_match('\~/.config/vim/vimrc', a[0]) + " There should be 1 entry for gvimrc and 1 entry for vimrc, + " but only if Vim was compiled with gui support + call assert_equal(1 + has("gui"), len(a)) + call assert_match('\~/\.config/vim/vimrc', a[0]) + if has("gui") + call assert_match('\~/\.config/vim/gvimrc', a[1]) + endif let $XDG_CONFIG_HOME = expand('~/.xdg') let a = execute(':version')->split('\n') let a = filter(a, { _, val -> val =~ '\.config\|XDG_CONFIG_HOME' }) - call assert_equal(1, len(a)) + call assert_equal(1 + has("gui"), len(a)) call assert_match('XDG_CONFIG_HOME/vim/vimrc', a[0]) + if has("gui") + call assert_match('XDG_CONFIG_HOME/vim/gvimrc', a[1]) + endif + unlet $XDG_CONFIG_HOME +endfunc + +" Test for gvimrc, must be last, since it starts the GUI +" and sources a few extra test files +func Test_zzz_xdg_runtime_files() + CheckCanRunGui + CheckUnix + + " Is setup in Github Runner + unlet $XDG_CONFIG_HOME + source setup_gui.vim + call GUISetUpCommon() + + " This tests, that the initialization file from + " ~/.vimrc, ~/.vim/vimrc and ~/.config/vim/vimrc (or + " $XDG_HOMECONFIG/vim/vimrc) are sourced in that order + call mkdir(expand('~/.vim/'), 'pD') + call mkdir(expand('~/.config/vim/'), 'pD') + call mkdir(expand('~/xdg/vim/'), 'pD') + + let rc1=expand('~/.gvimrc') + let rc2=expand('~/.vim/gvimrc') + let rc3=expand('~/.config/vim/gvimrc') + let rc4=expand('~/xdg/vim/gvimrc') + + " g:rc_one|two|three|four is to verify, that the other + " init files are not sourced + " g:rc is to verify which rc file has been loaded. + let file1 =<< trim CODE + let g:rc_one = 'one' + let g:rc = '.gvimrc' + CODE + let file2 =<< trim CODE + let g:rc_two = 'two' + let g:rc = '.vim/gvimrc' + CODE + let file3 =<< trim CODE + let g:rc_three = 'three' + let g:rc = '.config/vim/gvimrc' + CODE + let file4 =<< trim CODE + let g:rc_four = 'four' + let g:rc = 'xdg/vim/gvimrc' + CODE + call writefile(file1, rc1) + call writefile(file2, rc2) + call writefile(file3, rc3) + call writefile(file4, rc4) + + " Get the Vim command to run without the '-u NONE' argument + let vimcmd = substitute(GetVimCommand(), '-u NONE', '', '') + + " Test for ~/.gvimrc + let lines =<< trim END + " Ignore the "failed to create input context" error. + call test_ignore_error('E285') + gui -f + call assert_match('Xhome/\.gvimrc', $MYGVIMRC) + call filter(g:, {idx, _ -> idx =~ '^rc'}) + call assert_equal(#{rc_one: 'one', rc: '.gvimrc'}, g:) + call writefile(v:errors, 'Xresult') + quit + END + call writefile(lines, 'Xscript', 'D') + call system($'{vimcmd} -S Xscript') + call assert_equal([], readfile('Xresult')) + + call delete(rc1) + + " Test for ~/.vim/gvimrc + let lines =<< trim END + " Ignore the "failed to create input context" error. + call test_ignore_error('E285') + gui -f + call assert_match('Xhome/\.vim/gvimrc', $MYGVIMRC) + call filter(g:, {idx, _ -> idx =~ '^rc'}) + call assert_equal(#{rc_two: 'two', rc: '.vim/gvimrc'}, g:) + call writefile(v:errors, 'Xresult') + quit + END + call writefile(lines, 'Xscript', 'D') + call system($'{vimcmd} -S Xscript') + call assert_equal([], readfile('Xresult')) + + call delete(rc2) + + " XDG_CONFIG_HOME is set in Github CI runners + unlet $XDG_CONFIG_HOME + + " Test for ~/.config/vim/gvimrc + let lines =<< trim END + " Ignore the "failed to create input context" error. + call test_ignore_error('E285') + gui -f + let msg = $'HOME="{$HOME}", ~="{expand("~")}"' + call assert_match('Xhome/\.config/vim/gvimrc', $MYGVIMRC, msg) + call filter(g:, {idx, _ -> idx =~ '^rc'}) + call assert_equal(#{rc_three: 'three', rc: '.config/vim/gvimrc'}, g:) + call writefile(v:errors, 'Xresult') + quit + END + call writefile(lines, 'Xscript', 'D') + call system($'{vimcmd} -S Xscript') + call assert_equal([], readfile('Xresult')) + + call delete(rc3) + + " Test for ~/xdg/vim/gvimrc + let $XDG_CONFIG_HOME=expand('~/xdg/') + let lines =<< trim END + " Ignore the "failed to create input context" error. + call test_ignore_error('E285') + gui -f + let msg = $'HOME="{$HOME}", XDG_CONFIG_HOME="{$XDG_CONFIG_HOME}"' + call assert_match('Xhome/xdg/vim/gvimrc', $MYGVIMRC, msg) + call filter(g:, {idx, _ -> idx =~ '^rc'}) + call assert_equal(#{rc_four: 'four', rc: 'xdg/vim/gvimrc'}, g:) + call writefile(v:errors, 'Xresult') + quit + END + call writefile(lines, 'Xscript', 'D') + call system($'{vimcmd} -S Xscript') + call assert_equal([], readfile('Xresult')) + + call delete(rc4) + + " Clean up unlet $XDG_CONFIG_HOME + call GUITearDownCommon() + call delete('Xhome', 'rf') endfunc " vim: shiftwidth=2 sts=2 expandtab -- cgit v1.2.3