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