Mercurial > vim
comparison src/testdir/test_xdg.vim @ 34940:2d7721a4d213 v9.1.0327
patch 9.1.0327: No support for using $XDG_CONFIG_HOME
Commit: https://github.com/vim/vim/commit/c9df1fb35a1866901c32df37dd39c8b39dbdb64a
Author: Luca Saccarola <github.e41mv@aleeas.com>
Date: Sun Apr 14 22:53:22 2024 +0200
patch 9.1.0327: No support for using $XDG_CONFIG_HOME
Problem: No support for using $XDG_CONFIG_HOME
Solution: optionally source $XDG_CONFIG_HOME/vim/vimrc
(Luca Saccarola)
fixes: #2034
closes: #14182
Signed-off-by: Luca Saccarola <github.e41mv@aleeas.com>
Signed-off-by: Christian Brabandt <cb@256bit.org>
author | Christian Brabandt <cb@256bit.org> |
---|---|
date | Sun, 14 Apr 2024 23:00:03 +0200 |
parents | |
children | 1319fa412b0c |
comparison
equal
deleted
inserted
replaced
34939:2418c55e3ba6 | 34940:2d7721a4d213 |
---|---|
1 " Tests for the XDG feature | |
2 | |
3 source check.vim | |
4 CheckFeature terminal | |
5 | |
6 source shared.vim | |
7 source screendump.vim | |
8 source mouse.vim | |
9 source term_util.vim | |
10 | |
11 func s:get_rcs() | |
12 let rcs = { | |
13 \ 'file1': { 'path': '~/.vimrc' }, | |
14 \ 'file2': { 'path': '~/.vim/vimrc' }, | |
15 \ 'xdg': { 'path': exists('$XDG_CONFIG_HOME') ? '$XDG_CONFIG_HOME' : "~/.config" }, | |
16 \} | |
17 for v in values(rcs) | |
18 let v.exists = filereadable(expand(v.path)) | |
19 endfor | |
20 return rcs | |
21 endfunc | |
22 | |
23 func Test_xdg_rc_detection() | |
24 CheckUnix | |
25 let rc = s:get_rcs() | |
26 let before =<< trim CODE | |
27 call writefile([expand('$MYVIMRC')], "XMY_VIMRC") | |
28 quit! | |
29 CODE | |
30 call RunVim(before, [], "") | |
31 let my_rc = readfile("XMY_VIMRC") | |
32 if rc.file1.exists | |
33 call assert_equal(rc.file1.path, my_rc) | |
34 elseif !rc.file1.exists && rc.file2.exists | |
35 call assert_equal(rc.file2.path, my_rc) | |
36 elseif !rc.file1.exists && !rc.file2.exists && rc.xdg.exists | |
37 call assert_equal(rc.xdg.path, my_rc) | |
38 endif | |
39 call delete("XMY_VIMRC") | |
40 endfunc | |
41 | |
42 func Test_xdg_runtime_files() | |
43 " This tests, that the initialization file from | |
44 " ~/.vimrc, ~/.vim/vimrc and ~/.config/vim/vimrc (or | |
45 " $XDG_HOMECONFIG/vim/vimrc) are sourced in that order | |
46 CheckUnix | |
47 call mkdir(expand('~/.vim/'), 'pD') | |
48 call mkdir(expand('~/.config/vim/'), 'pD') | |
49 call mkdir(expand('~/xdg/vim/'), 'pD') | |
50 | |
51 let rc1=expand('~/.vimrc') | |
52 let rc2=expand('~/.vim/vimrc') | |
53 let rc3=expand('~/.config/vim/vimrc') | |
54 let rc4=expand('~/xdg/vim/vimrc') | |
55 | |
56 " g:rc_one|two|three|four is to verify, that the other | |
57 " init files are not source | |
58 " g:rc is to verify which rc file has been loaded. | |
59 let file1 =<< trim CODE | |
60 let g:rc_one = 'one' | |
61 let g:rc = '.vimrc' | |
62 CODE | |
63 let file2 =<< trim CODE | |
64 let g:rc_two = 'two' | |
65 let g:rc = '.vim/vimrc' | |
66 CODE | |
67 let file3 =<< trim CODE | |
68 let g:rc_three = 'three' | |
69 let g:rc = '.config/vim/vimrc' | |
70 CODE | |
71 let file4 =<< trim CODE | |
72 let g:rc_four = 'four' | |
73 let g:rc = 'xdg/vim/vimrc' | |
74 CODE | |
75 call writefile(file1, rc1) | |
76 call writefile(file2, rc2) | |
77 call writefile(file3, rc3) | |
78 call writefile(file4, rc4) | |
79 | |
80 let rows = 20 | |
81 let buf = RunVimInTerminal('', #{rows: rows, no_clean: 1}) | |
82 call TermWait(buf) | |
83 call term_sendkeys(buf, ":echo \$MYVIMRC\<cr>") | |
84 call WaitForAssert({-> assert_match('XfakeHOME/\.vimrc', term_getline(buf, rows))}) | |
85 call term_sendkeys(buf, ":call filter(g:, {idx, _ -> idx =~ '^rc'})\<cr>") | |
86 call TermWait(buf) | |
87 call term_sendkeys(buf, ":redraw!\<cr>") | |
88 call TermWait(buf) | |
89 call term_sendkeys(buf, ":let g:\<cr>") | |
90 call VerifyScreenDump(buf, 'Test_xdg_1', {}) | |
91 call StopVimInTerminal(buf) | |
92 call delete(rc1) | |
93 bw | |
94 | |
95 let buf = RunVimInTerminal('', #{rows: rows, no_clean: 1}) | |
96 call TermWait(buf) | |
97 call term_sendkeys(buf, ":echo \$MYVIMRC\<cr>") | |
98 call WaitForAssert({-> assert_match('XfakeHOME/\.vim/vimrc', term_getline(buf, rows))}) | |
99 call term_sendkeys(buf, ":call filter(g:, {idx, _ -> idx =~ '^rc'})\<cr>") | |
100 call TermWait(buf) | |
101 call term_sendkeys(buf, ":redraw!\<cr>") | |
102 call TermWait(buf) | |
103 call term_sendkeys(buf, ":let g:\<cr>") | |
104 call VerifyScreenDump(buf, 'Test_xdg_2', {}) | |
105 call StopVimInTerminal(buf) | |
106 call delete(rc2) | |
107 bw | |
108 | |
109 let buf = RunVimInTerminal('', #{rows: rows, no_clean: 1}) | |
110 call TermWait(buf) | |
111 call term_sendkeys(buf, ":echo \$MYVIMRC\<cr>") | |
112 call WaitForAssert({-> assert_match('XfakeHOME/\.config/vim/vimrc', term_getline(buf, rows))}) | |
113 call term_sendkeys(buf, ":call filter(g:, {idx, _ -> idx =~ '^rc'})\<cr>") | |
114 call TermWait(buf) | |
115 call term_sendkeys(buf, ":redraw!\<cr>") | |
116 call TermWait(buf) | |
117 call term_sendkeys(buf, ":let g:\<cr>") | |
118 call VerifyScreenDump(buf, 'Test_xdg_3', {}) | |
119 call StopVimInTerminal(buf) | |
120 call delete(rc3) | |
121 bw | |
122 | |
123 let $XDG_CONFIG_HOME=expand('~/xdg/') | |
124 let buf = RunVimInTerminal('', #{rows: rows, no_clean: 1}) | |
125 call TermWait(buf) | |
126 call term_sendkeys(buf, ":redraw!\<cr>") | |
127 call TermWait(buf) | |
128 call term_sendkeys(buf, ":echo \$MYVIMRC\<cr>") | |
129 call WaitForAssert({-> assert_match('xdg/vim/vimrc', term_getline(buf, rows))}) | |
130 call term_sendkeys(buf, ":call filter(g:, {idx, _ -> idx =~ '^rc'})\<cr>") | |
131 call TermWait(buf) | |
132 call term_sendkeys(buf, ":let g:\<cr>") | |
133 call VerifyScreenDump(buf, 'Test_xdg_4', {}) | |
134 call StopVimInTerminal(buf) | |
135 call delete(rc4) | |
136 bw | |
137 unlet $XDG_CONFIG_HOME | |
138 endfunc | |
139 | |
140 " vim: shiftwidth=2 sts=2 expandtab |