Luca Saccarola | c9df1fb | 2024-04-14 22:53:22 +0200 | [diff] [blame] | 1 | " Tests for the XDG feature |
| 2 | |
Luca Saccarola | c9df1fb | 2024-04-14 22:53:22 +0200 | [diff] [blame] | 3 | func s:get_rcs() |
| 4 | let rcs = { |
Christian Brabandt | 4e7249a | 2024-09-05 17:46:19 +0200 | [diff] [blame] | 5 | \ 'file1': { 'path': '~/.vimrc', 'dir': expand('~/.vim/') }, |
| 6 | \ 'file2': { 'path': '~/.vim/vimrc', 'dir': expand('~/.vim/') }, |
| 7 | \ 'xdg': { 'path': exists('$XDG_CONFIG_HOME') ? '$XDG_CONFIG_HOME' : "~/.config", |
| 8 | \ 'dir': exists('$XDG_CONFIG_HOME') ? expand("$XDG_CONFIG_HOME/vim") : '~/.config/vim/'}, |
Luca Saccarola | c9df1fb | 2024-04-14 22:53:22 +0200 | [diff] [blame] | 9 | \} |
| 10 | for v in values(rcs) |
| 11 | let v.exists = filereadable(expand(v.path)) |
| 12 | endfor |
| 13 | return rcs |
| 14 | endfunc |
| 15 | |
| 16 | func Test_xdg_rc_detection() |
| 17 | CheckUnix |
| 18 | let rc = s:get_rcs() |
| 19 | let before =<< trim CODE |
| 20 | call writefile([expand('$MYVIMRC')], "XMY_VIMRC") |
Christian Brabandt | 1a741d3 | 2025-03-01 16:30:33 +0100 | [diff] [blame] | 21 | call writefile([expand('$MYVIMDIR')], "XMY_VIMDIR") |
Luca Saccarola | c9df1fb | 2024-04-14 22:53:22 +0200 | [diff] [blame] | 22 | quit! |
| 23 | CODE |
| 24 | call RunVim(before, [], "") |
| 25 | let my_rc = readfile("XMY_VIMRC") |
Christian Brabandt | 4e7249a | 2024-09-05 17:46:19 +0200 | [diff] [blame] | 26 | let my_rcdir = readfile("XMY_VIMDIR") |
Luca Saccarola | c9df1fb | 2024-04-14 22:53:22 +0200 | [diff] [blame] | 27 | if rc.file1.exists |
| 28 | call assert_equal(rc.file1.path, my_rc) |
Christian Brabandt | 4e7249a | 2024-09-05 17:46:19 +0200 | [diff] [blame] | 29 | call assert_equal(rc.file1.dir, my_rcdir) |
Luca Saccarola | c9df1fb | 2024-04-14 22:53:22 +0200 | [diff] [blame] | 30 | elseif !rc.file1.exists && rc.file2.exists |
| 31 | call assert_equal(rc.file2.path, my_rc) |
Christian Brabandt | 4e7249a | 2024-09-05 17:46:19 +0200 | [diff] [blame] | 32 | call assert_equal(rc.file2.dir, my_rcdir) |
Luca Saccarola | c9df1fb | 2024-04-14 22:53:22 +0200 | [diff] [blame] | 33 | elseif !rc.file1.exists && !rc.file2.exists && rc.xdg.exists |
| 34 | call assert_equal(rc.xdg.path, my_rc) |
Christian Brabandt | 4e7249a | 2024-09-05 17:46:19 +0200 | [diff] [blame] | 35 | call assert_equal(rc.xdg.dir, my_rcdir) |
Luca Saccarola | c9df1fb | 2024-04-14 22:53:22 +0200 | [diff] [blame] | 36 | endif |
| 37 | call delete("XMY_VIMRC") |
Christian Brabandt | 4e7249a | 2024-09-05 17:46:19 +0200 | [diff] [blame] | 38 | call delete("XMY_VIMDIR") |
Luca Saccarola | c9df1fb | 2024-04-14 22:53:22 +0200 | [diff] [blame] | 39 | endfunc |
| 40 | |
| 41 | func Test_xdg_runtime_files() |
| 42 | " This tests, that the initialization file from |
| 43 | " ~/.vimrc, ~/.vim/vimrc and ~/.config/vim/vimrc (or |
Diego Viola | 133ed2a | 2024-04-18 20:54:06 +0200 | [diff] [blame] | 44 | " $XDG_CONFIG_HOME/vim/vimrc) are sourced in that order |
Luca Saccarola | c9df1fb | 2024-04-14 22:53:22 +0200 | [diff] [blame] | 45 | CheckUnix |
| 46 | call mkdir(expand('~/.vim/'), 'pD') |
| 47 | call mkdir(expand('~/.config/vim/'), 'pD') |
| 48 | call mkdir(expand('~/xdg/vim/'), 'pD') |
Maxim Kim | a34ba82 | 2024-04-17 22:29:06 +0200 | [diff] [blame] | 49 | |
Luca Saccarola | c9df1fb | 2024-04-14 22:53:22 +0200 | [diff] [blame] | 50 | let rc1=expand('~/.vimrc') |
| 51 | let rc2=expand('~/.vim/vimrc') |
| 52 | let rc3=expand('~/.config/vim/vimrc') |
| 53 | let rc4=expand('~/xdg/vim/vimrc') |
| 54 | |
| 55 | " g:rc_one|two|three|four is to verify, that the other |
Diego Viola | 2da68c8 | 2024-04-15 20:08:38 +0200 | [diff] [blame] | 56 | " init files are not sourced |
Luca Saccarola | c9df1fb | 2024-04-14 22:53:22 +0200 | [diff] [blame] | 57 | " g:rc is to verify which rc file has been loaded. |
Christian Brabandt | 1a741d3 | 2025-03-01 16:30:33 +0100 | [diff] [blame] | 58 | " g:rc_vimdir is to verify $MYVIMDIR is set and valid |
Luca Saccarola | c9df1fb | 2024-04-14 22:53:22 +0200 | [diff] [blame] | 59 | let file1 =<< trim CODE |
| 60 | let g:rc_one = 'one' |
| 61 | let g:rc = '.vimrc' |
Christian Brabandt | 1a741d3 | 2025-03-01 16:30:33 +0100 | [diff] [blame] | 62 | let g:rc_vimdir = expand('~/.vim/') |
| 63 | call assert_equal(g:rc_vimdir, $MYVIMDIR) |
Luca Saccarola | c9df1fb | 2024-04-14 22:53:22 +0200 | [diff] [blame] | 64 | CODE |
| 65 | let file2 =<< trim CODE |
| 66 | let g:rc_two = 'two' |
| 67 | let g:rc = '.vim/vimrc' |
Christian Brabandt | 1a741d3 | 2025-03-01 16:30:33 +0100 | [diff] [blame] | 68 | let g:rc_vimdir = expand('~/.vim/') |
| 69 | call assert_equal(g:rc_vimdir, $MYVIMDIR) |
Luca Saccarola | c9df1fb | 2024-04-14 22:53:22 +0200 | [diff] [blame] | 70 | CODE |
| 71 | let file3 =<< trim CODE |
| 72 | let g:rc_three = 'three' |
| 73 | let g:rc = '.config/vim/vimrc' |
Christian Brabandt | 1a741d3 | 2025-03-01 16:30:33 +0100 | [diff] [blame] | 74 | let g:rc_vimdir = expand('~/.config/vim/') |
| 75 | call assert_equal(g:rc_vimdir, $MYVIMDIR) |
Luca Saccarola | c9df1fb | 2024-04-14 22:53:22 +0200 | [diff] [blame] | 76 | CODE |
| 77 | let file4 =<< trim CODE |
| 78 | let g:rc_four = 'four' |
| 79 | let g:rc = 'xdg/vim/vimrc' |
Christian Brabandt | 1a741d3 | 2025-03-01 16:30:33 +0100 | [diff] [blame] | 80 | let g:rc_vimdir = expand('~/xdg/vim/') |
| 81 | call assert_equal(g:rc_vimdir, $MYVIMDIR) |
Luca Saccarola | c9df1fb | 2024-04-14 22:53:22 +0200 | [diff] [blame] | 82 | CODE |
| 83 | call writefile(file1, rc1) |
| 84 | call writefile(file2, rc2) |
| 85 | call writefile(file3, rc3) |
| 86 | call writefile(file4, rc4) |
| 87 | |
Yegappan Lakshmanan | 8560e6c | 2024-04-16 22:18:15 +0200 | [diff] [blame] | 88 | " Get the Vim command to run without the '-u NONE' argument |
| 89 | let vimcmd = substitute(GetVimCommand(), '-u NONE', '', '') |
| 90 | |
| 91 | " Test for ~/.vimrc |
| 92 | let lines =<< trim END |
| 93 | call assert_match('XfakeHOME/\.vimrc', $MYVIMRC) |
Christian Brabandt | 4e7249a | 2024-09-05 17:46:19 +0200 | [diff] [blame] | 94 | call assert_match('XfakeHOME/.vim/', $MYVIMDIR) |
Yegappan Lakshmanan | 8560e6c | 2024-04-16 22:18:15 +0200 | [diff] [blame] | 95 | call filter(g:, {idx, _ -> idx =~ '^rc'}) |
Christian Brabandt | 1a741d3 | 2025-03-01 16:30:33 +0100 | [diff] [blame] | 96 | call assert_equal(#{rc_one: 'one', rc: '.vimrc', rc_vimdir: $MYVIMDIR}, g:) |
Christian Brabandt | c3e6e39 | 2024-05-04 09:48:15 +0200 | [diff] [blame] | 97 | call assert_match('XfakeHOME/\.vim/view', &viewdir) |
Yegappan Lakshmanan | 8560e6c | 2024-04-16 22:18:15 +0200 | [diff] [blame] | 98 | call writefile(v:errors, 'Xresult') |
| 99 | quit |
| 100 | END |
| 101 | call writefile(lines, 'Xscript', 'D') |
| 102 | call system($'{vimcmd} -S Xscript') |
| 103 | call assert_equal([], readfile('Xresult')) |
| 104 | |
Luca Saccarola | c9df1fb | 2024-04-14 22:53:22 +0200 | [diff] [blame] | 105 | call delete(rc1) |
Luca Saccarola | c9df1fb | 2024-04-14 22:53:22 +0200 | [diff] [blame] | 106 | |
Yegappan Lakshmanan | 8560e6c | 2024-04-16 22:18:15 +0200 | [diff] [blame] | 107 | " Test for ~/.vim/vimrc |
| 108 | let lines =<< trim END |
| 109 | call assert_match('XfakeHOME/\.vim/vimrc', $MYVIMRC) |
Christian Brabandt | 4e7249a | 2024-09-05 17:46:19 +0200 | [diff] [blame] | 110 | call assert_match('XfakeHOME/\.vim/', $MYVIMDIR) |
Yegappan Lakshmanan | 8560e6c | 2024-04-16 22:18:15 +0200 | [diff] [blame] | 111 | call filter(g:, {idx, _ -> idx =~ '^rc'}) |
Christian Brabandt | 1a741d3 | 2025-03-01 16:30:33 +0100 | [diff] [blame] | 112 | call assert_equal(#{rc_two: 'two', rc: '.vim/vimrc', rc_vimdir: $MYVIMDIR}, g:) |
Christian Brabandt | c3e6e39 | 2024-05-04 09:48:15 +0200 | [diff] [blame] | 113 | call assert_match('XfakeHOME/\.vim/view', &viewdir) |
Yegappan Lakshmanan | 8560e6c | 2024-04-16 22:18:15 +0200 | [diff] [blame] | 114 | call writefile(v:errors, 'Xresult') |
| 115 | quit |
| 116 | END |
| 117 | call writefile(lines, 'Xscript', 'D') |
| 118 | call system($'{vimcmd} -S Xscript') |
| 119 | call assert_equal([], readfile('Xresult')) |
| 120 | |
Luca Saccarola | c9df1fb | 2024-04-14 22:53:22 +0200 | [diff] [blame] | 121 | call delete(rc2) |
Luca Saccarola | c9df1fb | 2024-04-14 22:53:22 +0200 | [diff] [blame] | 122 | |
Yegappan Lakshmanan | 8560e6c | 2024-04-16 22:18:15 +0200 | [diff] [blame] | 123 | " XDG_CONFIG_HOME is set in Github CI runners |
| 124 | unlet $XDG_CONFIG_HOME |
| 125 | |
| 126 | " Test for ~/.config/vim/vimrc |
| 127 | let lines =<< trim END |
| 128 | let msg = $'HOME="{$HOME}", ~="{expand("~")}"' |
| 129 | call assert_match('XfakeHOME/\.config/vim/vimrc', $MYVIMRC, msg) |
Christian Brabandt | 4e7249a | 2024-09-05 17:46:19 +0200 | [diff] [blame] | 130 | call assert_match('XfakeHOME/\.config/vim/', $MYVIMDIR, msg) |
Yegappan Lakshmanan | 8560e6c | 2024-04-16 22:18:15 +0200 | [diff] [blame] | 131 | call filter(g:, {idx, _ -> idx =~ '^rc'}) |
Christian Brabandt | 1a741d3 | 2025-03-01 16:30:33 +0100 | [diff] [blame] | 132 | call assert_equal(#{rc_three: 'three', rc: '.config/vim/vimrc', rc_vimdir: $MYVIMDIR}, g:) |
Christian Brabandt | c3e6e39 | 2024-05-04 09:48:15 +0200 | [diff] [blame] | 133 | call assert_match('XfakeHOME/\.config/vim/view', &viewdir) |
Yegappan Lakshmanan | 8560e6c | 2024-04-16 22:18:15 +0200 | [diff] [blame] | 134 | call writefile(v:errors, 'Xresult') |
| 135 | quit |
| 136 | END |
| 137 | call writefile(lines, 'Xscript', 'D') |
| 138 | call system($'{vimcmd} -S Xscript') |
| 139 | call assert_equal([], readfile('Xresult')) |
| 140 | |
Luca Saccarola | c9df1fb | 2024-04-14 22:53:22 +0200 | [diff] [blame] | 141 | call delete(rc3) |
Luca Saccarola | c9df1fb | 2024-04-14 22:53:22 +0200 | [diff] [blame] | 142 | |
Yegappan Lakshmanan | 8560e6c | 2024-04-16 22:18:15 +0200 | [diff] [blame] | 143 | " Test for ~/xdg/vim/vimrc |
Luca Saccarola | c9df1fb | 2024-04-14 22:53:22 +0200 | [diff] [blame] | 144 | let $XDG_CONFIG_HOME=expand('~/xdg/') |
Yegappan Lakshmanan | 8560e6c | 2024-04-16 22:18:15 +0200 | [diff] [blame] | 145 | let lines =<< trim END |
| 146 | let msg = $'HOME="{$HOME}", XDG_CONFIG_HOME="{$XDG_CONFIG_HOME}"' |
| 147 | call assert_match('XfakeHOME/xdg/vim/vimrc', $MYVIMRC, msg) |
Christian Brabandt | 4e7249a | 2024-09-05 17:46:19 +0200 | [diff] [blame] | 148 | call assert_match('XfakeHOME/xdg/vim/', $MYVIMDIR, msg) |
Yegappan Lakshmanan | 8560e6c | 2024-04-16 22:18:15 +0200 | [diff] [blame] | 149 | call filter(g:, {idx, _ -> idx =~ '^rc'}) |
Christian Brabandt | 1a741d3 | 2025-03-01 16:30:33 +0100 | [diff] [blame] | 150 | call assert_equal(#{rc_four: 'four', rc: 'xdg/vim/vimrc', rc_vimdir: $MYVIMDIR}, g:) |
Christian Brabandt | c3e6e39 | 2024-05-04 09:48:15 +0200 | [diff] [blame] | 151 | call assert_match('XfakeHOME/xdg/vim/view, &viewdir) |
Yegappan Lakshmanan | 8560e6c | 2024-04-16 22:18:15 +0200 | [diff] [blame] | 152 | call writefile(v:errors, 'Xresult') |
| 153 | quit |
| 154 | END |
| 155 | call writefile(lines, 'Xscript', 'D') |
| 156 | call system($'{vimcmd} -S Xscript') |
| 157 | call assert_equal([], readfile('Xresult')) |
| 158 | |
Christian Brabandt | 3e2affc | 2025-02-28 17:34:46 +0100 | [diff] [blame] | 159 | " Test for $MYVIMDIR changes when updating runtimepath |
| 160 | let lines =<< trim END |
| 161 | let msg = $'HOME="{$HOME}", XDG_CONFIG_HOME="{$XDG_CONFIG_HOME}" rtp-prepend' |
| 162 | set rtp^=/non-existing |
| 163 | call assert_match('XfakeHOME/xdg/vim/vimrc', $MYVIMRC, msg) |
| 164 | call assert_match('/non-existing', $MYVIMDIR, msg) |
| 165 | call writefile(v:errors, 'Xresult') |
| 166 | quit |
| 167 | END |
| 168 | call writefile(lines, 'Xscript', 'D') |
| 169 | call system($'{vimcmd} -S Xscript') |
| 170 | call assert_equal([], readfile('Xresult')) |
| 171 | |
Luca Saccarola | c9df1fb | 2024-04-14 22:53:22 +0200 | [diff] [blame] | 172 | call delete(rc4) |
Luca Saccarola | c9df1fb | 2024-04-14 22:53:22 +0200 | [diff] [blame] | 173 | unlet $XDG_CONFIG_HOME |
| 174 | endfunc |
| 175 | |
Diego Viola | d1068a2 | 2024-04-16 20:58:45 +0200 | [diff] [blame] | 176 | func Test_xdg_version() |
| 177 | CheckUnix |
| 178 | let $HOME = getcwd() .. '/XfakeHOME' |
| 179 | unlet $XDG_CONFIG_HOME |
| 180 | let a = execute(':version')->split('\n') |
| 181 | let a = filter(a, { _, val -> val =~ '\.config\|XDG_CONFIG_HOME' }) |
Maxim Kim | a34ba82 | 2024-04-17 22:29:06 +0200 | [diff] [blame] | 182 | " There should be 1 entry for gvimrc and 1 entry for vimrc, |
| 183 | " but only if Vim was compiled with gui support |
| 184 | call assert_equal(1 + has("gui"), len(a)) |
| 185 | call assert_match('\~/\.config/vim/vimrc', a[0]) |
| 186 | if has("gui") |
| 187 | call assert_match('\~/\.config/vim/gvimrc', a[1]) |
| 188 | endif |
Diego Viola | d1068a2 | 2024-04-16 20:58:45 +0200 | [diff] [blame] | 189 | |
| 190 | let $XDG_CONFIG_HOME = expand('~/.xdg') |
| 191 | let a = execute(':version')->split('\n') |
| 192 | let a = filter(a, { _, val -> val =~ '\.config\|XDG_CONFIG_HOME' }) |
Maxim Kim | a34ba82 | 2024-04-17 22:29:06 +0200 | [diff] [blame] | 193 | call assert_equal(1 + has("gui"), len(a)) |
Diego Viola | d1068a2 | 2024-04-16 20:58:45 +0200 | [diff] [blame] | 194 | call assert_match('XDG_CONFIG_HOME/vim/vimrc', a[0]) |
Maxim Kim | a34ba82 | 2024-04-17 22:29:06 +0200 | [diff] [blame] | 195 | if has("gui") |
| 196 | call assert_match('XDG_CONFIG_HOME/vim/gvimrc', a[1]) |
| 197 | endif |
Diego Viola | d1068a2 | 2024-04-16 20:58:45 +0200 | [diff] [blame] | 198 | unlet $XDG_CONFIG_HOME |
| 199 | endfunc |
| 200 | |
Maxim Kim | a34ba82 | 2024-04-17 22:29:06 +0200 | [diff] [blame] | 201 | " Test for gvimrc, must be last, since it starts the GUI |
| 202 | " and sources a few extra test files |
| 203 | func Test_zzz_xdg_runtime_files() |
| 204 | CheckCanRunGui |
| 205 | CheckUnix |
| 206 | |
| 207 | " Is setup in Github Runner |
| 208 | unlet $XDG_CONFIG_HOME |
Christian Brabandt | eb380b9 | 2025-07-07 20:53:55 +0200 | [diff] [blame] | 209 | source util/setup_gui.vim |
Maxim Kim | a34ba82 | 2024-04-17 22:29:06 +0200 | [diff] [blame] | 210 | call GUISetUpCommon() |
| 211 | |
Diego Viola | 133ed2a | 2024-04-18 20:54:06 +0200 | [diff] [blame] | 212 | " This tests, that the GUI initialization file from |
| 213 | " ~/.gvimrc, ~/.vim/gvimrc, ~/.config/vim/gvimrc |
| 214 | " and ~/XDG_CONFIG_HOME/vim/gvimrc is sourced |
| 215 | " when starting GUI mode |
Maxim Kim | a34ba82 | 2024-04-17 22:29:06 +0200 | [diff] [blame] | 216 | call mkdir(expand('~/.vim/'), 'pD') |
| 217 | call mkdir(expand('~/.config/vim/'), 'pD') |
| 218 | call mkdir(expand('~/xdg/vim/'), 'pD') |
| 219 | |
| 220 | let rc1=expand('~/.gvimrc') |
| 221 | let rc2=expand('~/.vim/gvimrc') |
| 222 | let rc3=expand('~/.config/vim/gvimrc') |
| 223 | let rc4=expand('~/xdg/vim/gvimrc') |
| 224 | |
| 225 | " g:rc_one|two|three|four is to verify, that the other |
| 226 | " init files are not sourced |
| 227 | " g:rc is to verify which rc file has been loaded. |
| 228 | let file1 =<< trim CODE |
| 229 | let g:rc_one = 'one' |
| 230 | let g:rc = '.gvimrc' |
| 231 | CODE |
| 232 | let file2 =<< trim CODE |
| 233 | let g:rc_two = 'two' |
| 234 | let g:rc = '.vim/gvimrc' |
| 235 | CODE |
| 236 | let file3 =<< trim CODE |
| 237 | let g:rc_three = 'three' |
| 238 | let g:rc = '.config/vim/gvimrc' |
| 239 | CODE |
| 240 | let file4 =<< trim CODE |
| 241 | let g:rc_four = 'four' |
| 242 | let g:rc = 'xdg/vim/gvimrc' |
| 243 | CODE |
| 244 | call writefile(file1, rc1) |
| 245 | call writefile(file2, rc2) |
| 246 | call writefile(file3, rc3) |
| 247 | call writefile(file4, rc4) |
| 248 | |
| 249 | " Get the Vim command to run without the '-u NONE' argument |
| 250 | let vimcmd = substitute(GetVimCommand(), '-u NONE', '', '') |
| 251 | |
| 252 | " Test for ~/.gvimrc |
| 253 | let lines =<< trim END |
| 254 | " Ignore the "failed to create input context" error. |
| 255 | call test_ignore_error('E285') |
| 256 | gui -f |
| 257 | call assert_match('Xhome/\.gvimrc', $MYGVIMRC) |
Christian Brabandt | 4e7249a | 2024-09-05 17:46:19 +0200 | [diff] [blame] | 258 | call assert_match('Xhome/\.vim/', $MYVIMDIR) |
Maxim Kim | a34ba82 | 2024-04-17 22:29:06 +0200 | [diff] [blame] | 259 | call filter(g:, {idx, _ -> idx =~ '^rc'}) |
| 260 | call assert_equal(#{rc_one: 'one', rc: '.gvimrc'}, g:) |
| 261 | call writefile(v:errors, 'Xresult') |
| 262 | quit |
| 263 | END |
| 264 | call writefile(lines, 'Xscript', 'D') |
| 265 | call system($'{vimcmd} -S Xscript') |
| 266 | call assert_equal([], readfile('Xresult')) |
| 267 | |
| 268 | call delete(rc1) |
| 269 | |
| 270 | " Test for ~/.vim/gvimrc |
| 271 | let lines =<< trim END |
| 272 | " Ignore the "failed to create input context" error. |
| 273 | call test_ignore_error('E285') |
| 274 | gui -f |
| 275 | call assert_match('Xhome/\.vim/gvimrc', $MYGVIMRC) |
Christian Brabandt | 4e7249a | 2024-09-05 17:46:19 +0200 | [diff] [blame] | 276 | call assert_match('Xhome/\.vim/', $MYVIMDIR) |
Maxim Kim | a34ba82 | 2024-04-17 22:29:06 +0200 | [diff] [blame] | 277 | call filter(g:, {idx, _ -> idx =~ '^rc'}) |
| 278 | call assert_equal(#{rc_two: 'two', rc: '.vim/gvimrc'}, g:) |
| 279 | call writefile(v:errors, 'Xresult') |
| 280 | quit |
| 281 | END |
| 282 | call writefile(lines, 'Xscript', 'D') |
| 283 | call system($'{vimcmd} -S Xscript') |
| 284 | call assert_equal([], readfile('Xresult')) |
| 285 | |
| 286 | call delete(rc2) |
| 287 | |
Maxim Kim | a34ba82 | 2024-04-17 22:29:06 +0200 | [diff] [blame] | 288 | " Test for ~/.config/vim/gvimrc |
Christian Brabandt | 3e2affc | 2025-02-28 17:34:46 +0100 | [diff] [blame] | 289 | " MYVIMDIR is only set to ~/config/.vim if ~/.config/vim/vimrc exists! |
Maxim Kim | a34ba82 | 2024-04-17 22:29:06 +0200 | [diff] [blame] | 290 | let lines =<< trim END |
| 291 | " Ignore the "failed to create input context" error. |
| 292 | call test_ignore_error('E285') |
| 293 | gui -f |
| 294 | let msg = $'HOME="{$HOME}", ~="{expand("~")}"' |
| 295 | call assert_match('Xhome/\.config/vim/gvimrc', $MYGVIMRC, msg) |
Christian Brabandt | 3e2affc | 2025-02-28 17:34:46 +0100 | [diff] [blame] | 296 | call assert_match('Xhome/\.vim/', $MYVIMDIR, msg) |
Maxim Kim | a34ba82 | 2024-04-17 22:29:06 +0200 | [diff] [blame] | 297 | call filter(g:, {idx, _ -> idx =~ '^rc'}) |
| 298 | call assert_equal(#{rc_three: 'three', rc: '.config/vim/gvimrc'}, g:) |
| 299 | call writefile(v:errors, 'Xresult') |
| 300 | quit |
| 301 | END |
| 302 | call writefile(lines, 'Xscript', 'D') |
| 303 | call system($'{vimcmd} -S Xscript') |
| 304 | call assert_equal([], readfile('Xresult')) |
| 305 | |
| 306 | call delete(rc3) |
| 307 | |
| 308 | " Test for ~/xdg/vim/gvimrc |
Christian Brabandt | 3e2affc | 2025-02-28 17:34:46 +0100 | [diff] [blame] | 309 | " MYVIMDIR is only set to ~/xdg/vim if ~/xdg/vim/vimrc exists! |
Maxim Kim | a34ba82 | 2024-04-17 22:29:06 +0200 | [diff] [blame] | 310 | let $XDG_CONFIG_HOME=expand('~/xdg/') |
| 311 | let lines =<< trim END |
| 312 | " Ignore the "failed to create input context" error. |
| 313 | call test_ignore_error('E285') |
| 314 | gui -f |
| 315 | let msg = $'HOME="{$HOME}", XDG_CONFIG_HOME="{$XDG_CONFIG_HOME}"' |
| 316 | call assert_match('Xhome/xdg/vim/gvimrc', $MYGVIMRC, msg) |
Christian Brabandt | 3e2affc | 2025-02-28 17:34:46 +0100 | [diff] [blame] | 317 | call assert_match('Xhome/\.vim/', $MYVIMDIR, msg) |
Maxim Kim | a34ba82 | 2024-04-17 22:29:06 +0200 | [diff] [blame] | 318 | call filter(g:, {idx, _ -> idx =~ '^rc'}) |
| 319 | call assert_equal(#{rc_four: 'four', rc: 'xdg/vim/gvimrc'}, g:) |
| 320 | call writefile(v:errors, 'Xresult') |
| 321 | quit |
| 322 | END |
| 323 | call writefile(lines, 'Xscript', 'D') |
| 324 | call system($'{vimcmd} -S Xscript') |
| 325 | call assert_equal([], readfile('Xresult')) |
| 326 | |
| 327 | call delete(rc4) |
| 328 | |
| 329 | " Clean up |
| 330 | unlet $XDG_CONFIG_HOME |
| 331 | call GUITearDownCommon() |
| 332 | call delete('Xhome', 'rf') |
| 333 | endfunc |
| 334 | |
Luca Saccarola | c9df1fb | 2024-04-14 22:53:22 +0200 | [diff] [blame] | 335 | " vim: shiftwidth=2 sts=2 expandtab |