blob: 7dcaa60622976830591b9f1fc521069f74637ec9 [file] [log] [blame]
Bram Moolenaarf3654822016-03-04 22:12:23 +01001" Tests for 'packpath' and :packadd
Bram Moolenaar863c1a92016-03-03 15:47:06 +01002
Bram Moolenaarc3c766e2017-03-08 22:55:19 +01003set belloff=all
4
Bram Moolenaar91715872016-03-03 17:13:03 +01005func SetUp()
6 let s:topdir = expand('%:h') . '/Xdir'
7 exe 'set packpath=' . s:topdir
8 let s:plugdir = s:topdir . '/pack/mine/opt/mytest'
9endfunc
10
11func TearDown()
12 call delete(s:topdir, 'rf')
13endfunc
14
Bram Moolenaarf3654822016-03-04 22:12:23 +010015func Test_packadd()
Bram Moolenaar71fb0c12016-04-02 22:44:16 +020016 call mkdir(s:plugdir . '/plugin/also', 'p')
Bram Moolenaar91715872016-03-03 17:13:03 +010017 call mkdir(s:plugdir . '/ftdetect', 'p')
Bram Moolenaara5702442016-05-24 19:37:29 +020018 call mkdir(s:plugdir . '/after', 'p')
Bram Moolenaar91715872016-03-03 17:13:03 +010019 set rtp&
20 let rtp = &rtp
Bram Moolenaar863c1a92016-03-03 15:47:06 +010021 filetype on
Bram Moolenaar863c1a92016-03-03 15:47:06 +010022
Bram Moolenaar91715872016-03-03 17:13:03 +010023 exe 'split ' . s:plugdir . '/plugin/test.vim'
24 call setline(1, 'let g:plugin_works = 42')
25 wq
Bram Moolenaar863c1a92016-03-03 15:47:06 +010026
Bram Moolenaar71fb0c12016-04-02 22:44:16 +020027 exe 'split ' . s:plugdir . '/plugin/also/loaded.vim'
28 call setline(1, 'let g:plugin_also_works = 77')
29 wq
30
Bram Moolenaar91715872016-03-03 17:13:03 +010031 exe 'split ' . s:plugdir . '/ftdetect/test.vim'
32 call setline(1, 'let g:ftdetect_works = 17')
33 wq
34
Bram Moolenaarf3654822016-03-04 22:12:23 +010035 packadd mytest
Bram Moolenaar91715872016-03-03 17:13:03 +010036
37 call assert_equal(42, g:plugin_works)
Bram Moolenaar71fb0c12016-04-02 22:44:16 +020038 call assert_equal(77, g:plugin_also_works)
Bram Moolenaar91715872016-03-03 17:13:03 +010039 call assert_equal(17, g:ftdetect_works)
40 call assert_true(len(&rtp) > len(rtp))
Bram Moolenaara5702442016-05-24 19:37:29 +020041 call assert_true(&rtp =~ '/testdir/Xdir/pack/mine/opt/mytest\($\|,\)')
42 call assert_true(&rtp =~ '/testdir/Xdir/pack/mine/opt/mytest/after$')
Bram Moolenaarbe82c252016-03-06 14:44:08 +010043
44 " Check exception
45 call assert_fails("packadd directorynotfound", 'E919:')
46 call assert_fails("packadd", 'E471:')
Bram Moolenaar91715872016-03-03 17:13:03 +010047endfunc
48
Bram Moolenaarf3654822016-03-04 22:12:23 +010049func Test_packadd_noload()
50 call mkdir(s:plugdir . '/plugin', 'p')
Bram Moolenaar91715872016-03-03 17:13:03 +010051 call mkdir(s:plugdir . '/syntax', 'p')
52 set rtp&
53 let rtp = &rtp
Bram Moolenaarf3654822016-03-04 22:12:23 +010054
55 exe 'split ' . s:plugdir . '/plugin/test.vim'
56 call setline(1, 'let g:plugin_works = 42')
57 wq
58 let g:plugin_works = 0
59
60 packadd! mytest
61
Bram Moolenaar91715872016-03-03 17:13:03 +010062 call assert_true(len(&rtp) > len(rtp))
63 call assert_true(&rtp =~ 'testdir/Xdir/pack/mine/opt/mytest\($\|,\)')
Bram Moolenaarf3654822016-03-04 22:12:23 +010064 call assert_equal(0, g:plugin_works)
Bram Moolenaar91715872016-03-03 17:13:03 +010065
66 " check the path is not added twice
67 let new_rtp = &rtp
Bram Moolenaarf3654822016-03-04 22:12:23 +010068 packadd! mytest
Bram Moolenaar91715872016-03-03 17:13:03 +010069 call assert_equal(new_rtp, &rtp)
Bram Moolenaar863c1a92016-03-03 15:47:06 +010070endfunc
Bram Moolenaar35ca0e72016-03-05 17:41:49 +010071
Bram Moolenaar2f9e5752017-02-05 16:07:54 +010072func Test_packadd_symlink_dir()
73 if !has('unix')
Bram Moolenaar644df412017-03-09 13:58:02 +010074 return
Bram Moolenaar2f9e5752017-02-05 16:07:54 +010075 endif
76 let top2_dir = s:topdir . '/Xdir2'
77 let real_dir = s:topdir . '/Xsym'
Bram Moolenaar644df412017-03-09 13:58:02 +010078 call mkdir(real_dir, 'p')
79 exec "silent !ln -s Xsym" top2_dir
Bram Moolenaar2f9e5752017-02-05 16:07:54 +010080 let &rtp = top2_dir . ',' . top2_dir . '/after'
81 let &packpath = &rtp
82
83 let s:plugdir = top2_dir . '/pack/mine/opt/mytest'
84 call mkdir(s:plugdir . '/plugin', 'p')
85
86 exe 'split ' . s:plugdir . '/plugin/test.vim'
87 call setline(1, 'let g:plugin_works = 44')
88 wq
89 let g:plugin_works = 0
90
91 packadd mytest
92
93 " Must have been inserted in the middle, not at the end
94 call assert_true(&rtp =~ '/pack/mine/opt/mytest,')
95 call assert_equal(44, g:plugin_works)
96
97 " No change when doing it again.
98 let rtp_before = &rtp
99 packadd mytest
100 call assert_equal(rtp_before, &rtp)
101
102 set rtp&
103 let rtp = &rtp
Bram Moolenaar24f8f542017-02-11 23:00:36 +0100104 exec "silent !rm" top2_dir
Bram Moolenaar2f9e5752017-02-05 16:07:54 +0100105endfunc
106
Bram Moolenaar35ca0e72016-03-05 17:41:49 +0100107" Check command-line completion for 'packadd'
108func Test_packadd_completion()
109 let optdir1 = &packpath . '/pack/mine/opt'
110 let optdir2 = &packpath . '/pack/candidate/opt'
111
112 call mkdir(optdir1 . '/pluginA', 'p')
113 call mkdir(optdir1 . '/pluginC', 'p')
114 call mkdir(optdir2 . '/pluginB', 'p')
115 call mkdir(optdir2 . '/pluginC', 'p')
116
117 let li = []
118 call feedkeys(":packadd \<Tab>')\<C-B>call add(li, '\<CR>", 't')
119 call feedkeys(":packadd " . repeat("\<Tab>", 2) . "')\<C-B>call add(li, '\<CR>", 't')
120 call feedkeys(":packadd " . repeat("\<Tab>", 3) . "')\<C-B>call add(li, '\<CR>", 't')
121 call feedkeys(":packadd " . repeat("\<Tab>", 4) . "')\<C-B>call add(li, '\<CR>", 'tx')
122 call assert_equal("packadd pluginA", li[0])
123 call assert_equal("packadd pluginB", li[1])
124 call assert_equal("packadd pluginC", li[2])
125 call assert_equal("packadd ", li[3])
126endfunc
Bram Moolenaar2d8f56a2016-03-12 20:34:27 +0100127
128func Test_packloadall()
Bram Moolenaar49b27322016-04-05 21:13:00 +0200129 " plugin foo with an autoload directory
130 let fooplugindir = &packpath . '/pack/mine/start/foo/plugin'
131 call mkdir(fooplugindir, 'p')
132 call writefile(['let g:plugin_foo_number = 1234',
133 \ 'let g:plugin_foo_auto = bbb#value',
134 \ 'let g:plugin_extra_auto = extra#value'], fooplugindir . '/bar.vim')
135 let fooautodir = &packpath . '/pack/mine/start/foo/autoload'
136 call mkdir(fooautodir, 'p')
137 call writefile(['let bar#value = 77'], fooautodir . '/bar.vim')
138
139 " plugin aaa with an autoload directory
140 let aaaplugindir = &packpath . '/pack/mine/start/aaa/plugin'
141 call mkdir(aaaplugindir, 'p')
142 call writefile(['let g:plugin_aaa_number = 333',
143 \ 'let g:plugin_aaa_auto = bar#value'], aaaplugindir . '/bbb.vim')
144 let aaaautodir = &packpath . '/pack/mine/start/aaa/autoload'
145 call mkdir(aaaautodir, 'p')
146 call writefile(['let bbb#value = 55'], aaaautodir . '/bbb.vim')
147
148 " plugin extra with only an autoload directory
149 let extraautodir = &packpath . '/pack/mine/start/extra/autoload'
150 call mkdir(extraautodir, 'p')
151 call writefile(['let extra#value = 99'], extraautodir . '/extra.vim')
152
Bram Moolenaar2d8f56a2016-03-12 20:34:27 +0100153 packloadall
154 call assert_equal(1234, g:plugin_foo_number)
Bram Moolenaar49b27322016-04-05 21:13:00 +0200155 call assert_equal(55, g:plugin_foo_auto)
156 call assert_equal(99, g:plugin_extra_auto)
157 call assert_equal(333, g:plugin_aaa_number)
158 call assert_equal(77, g:plugin_aaa_auto)
Bram Moolenaar2d8f56a2016-03-12 20:34:27 +0100159
160 " only works once
Bram Moolenaar49b27322016-04-05 21:13:00 +0200161 call writefile(['let g:plugin_bar_number = 4321'], fooplugindir . '/bar2.vim')
Bram Moolenaar2d8f56a2016-03-12 20:34:27 +0100162 packloadall
163 call assert_false(exists('g:plugin_bar_number'))
164
165 " works when ! used
166 packloadall!
167 call assert_equal(4321, g:plugin_bar_number)
168endfunc
Bram Moolenaar6bef5302016-03-12 21:28:26 +0100169
170func Test_helptags()
171 let docdir1 = &packpath . '/pack/mine/start/foo/doc'
172 let docdir2 = &packpath . '/pack/mine/start/bar/doc'
173 call mkdir(docdir1, 'p')
174 call mkdir(docdir2, 'p')
175 call writefile(['look here: *look-here*'], docdir1 . '/bar.txt')
176 call writefile(['look away: *look-away*'], docdir2 . '/foo.txt')
177 exe 'set rtp=' . &packpath . '/pack/mine/start/foo,' . &packpath . '/pack/mine/start/bar'
178
179 helptags ALL
180
181 let tags1 = readfile(docdir1 . '/tags')
182 call assert_true(tags1[0] =~ 'look-here')
183 let tags2 = readfile(docdir2 . '/tags')
184 call assert_true(tags2[0] =~ 'look-away')
185endfunc
Bram Moolenaar7f8989d2016-03-12 22:11:39 +0100186
187func Test_colorscheme()
188 let colordirrun = &packpath . '/runtime/colors'
189 let colordirstart = &packpath . '/pack/mine/start/foo/colors'
190 let colordiropt = &packpath . '/pack/mine/opt/bar/colors'
191 call mkdir(colordirrun, 'p')
192 call mkdir(colordirstart, 'p')
193 call mkdir(colordiropt, 'p')
194 call writefile(['let g:found_one = 1'], colordirrun . '/one.vim')
195 call writefile(['let g:found_two = 1'], colordirstart . '/two.vim')
196 call writefile(['let g:found_three = 1'], colordiropt . '/three.vim')
197 exe 'set rtp=' . &packpath . '/runtime'
198
199 colorscheme one
200 call assert_equal(1, g:found_one)
201 colorscheme two
202 call assert_equal(1, g:found_two)
203 colorscheme three
204 call assert_equal(1, g:found_three)
205endfunc
Bram Moolenaar8dcf2592016-03-12 22:47:14 +0100206
Bram Moolenaar52f9c192016-03-13 13:24:45 +0100207func Test_colorscheme_completion()
208 let colordirrun = &packpath . '/runtime/colors'
209 let colordirstart = &packpath . '/pack/mine/start/foo/colors'
210 let colordiropt = &packpath . '/pack/mine/opt/bar/colors'
211 call mkdir(colordirrun, 'p')
212 call mkdir(colordirstart, 'p')
213 call mkdir(colordiropt, 'p')
214 call writefile(['let g:found_one = 1'], colordirrun . '/one.vim')
215 call writefile(['let g:found_two = 1'], colordirstart . '/two.vim')
216 call writefile(['let g:found_three = 1'], colordiropt . '/three.vim')
217 exe 'set rtp=' . &packpath . '/runtime'
218
219 let li=[]
220 call feedkeys(":colorscheme " . repeat("\<Tab>", 1) . "')\<C-B>call add(li, '\<CR>", 't')
221 call feedkeys(":colorscheme " . repeat("\<Tab>", 2) . "')\<C-B>call add(li, '\<CR>", 't')
222 call feedkeys(":colorscheme " . repeat("\<Tab>", 3) . "')\<C-B>call add(li, '\<CR>", 't')
223 call feedkeys(":colorscheme " . repeat("\<Tab>", 4) . "')\<C-B>call add(li, '\<CR>", 'tx')
224 call assert_equal("colorscheme one", li[0])
225 call assert_equal("colorscheme three", li[1])
226 call assert_equal("colorscheme two", li[2])
227 call assert_equal("colorscheme ", li[3])
228endfunc
229
Bram Moolenaar8dcf2592016-03-12 22:47:14 +0100230func Test_runtime()
231 let rundir = &packpath . '/runtime/extra'
232 let startdir = &packpath . '/pack/mine/start/foo/extra'
233 let optdir = &packpath . '/pack/mine/opt/bar/extra'
234 call mkdir(rundir, 'p')
235 call mkdir(startdir, 'p')
236 call mkdir(optdir, 'p')
237 call writefile(['let g:sequence .= "run"'], rundir . '/bar.vim')
238 call writefile(['let g:sequence .= "start"'], startdir . '/bar.vim')
239 call writefile(['let g:sequence .= "foostart"'], startdir . '/foo.vim')
240 call writefile(['let g:sequence .= "opt"'], optdir . '/bar.vim')
241 call writefile(['let g:sequence .= "xxxopt"'], optdir . '/xxx.vim')
242 exe 'set rtp=' . &packpath . '/runtime'
243
244 let g:sequence = ''
245 runtime extra/bar.vim
246 call assert_equal('run', g:sequence)
247 let g:sequence = ''
248 runtime START extra/bar.vim
249 call assert_equal('start', g:sequence)
250 let g:sequence = ''
251 runtime OPT extra/bar.vim
252 call assert_equal('opt', g:sequence)
253 let g:sequence = ''
254 runtime PACK extra/bar.vim
255 call assert_equal('start', g:sequence)
256 let g:sequence = ''
257 runtime! PACK extra/bar.vim
258 call assert_equal('startopt', g:sequence)
259 let g:sequence = ''
260 runtime PACK extra/xxx.vim
261 call assert_equal('xxxopt', g:sequence)
262
263 let g:sequence = ''
264 runtime ALL extra/bar.vim
265 call assert_equal('run', g:sequence)
266 let g:sequence = ''
267 runtime ALL extra/foo.vim
268 call assert_equal('foostart', g:sequence)
269 let g:sequence = ''
270 runtime! ALL extra/xxx.vim
271 call assert_equal('xxxopt', g:sequence)
272 let g:sequence = ''
273 runtime! ALL extra/bar.vim
274 call assert_equal('runstartopt', g:sequence)
275endfunc