blob: 64bd8d2b23e608898dd64aaee4c69e96dda4b481 [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 +01003
Bram Moolenaar91715872016-03-03 17:13:03 +01004func SetUp()
Bram Moolenaarcf1ba352017-10-27 00:55:04 +02005 let s:topdir = getcwd() . '/Xdir'
Bram Moolenaar91715872016-03-03 17:13:03 +01006 exe 'set packpath=' . s:topdir
7 let s:plugdir = s:topdir . '/pack/mine/opt/mytest'
8endfunc
9
10func TearDown()
11 call delete(s:topdir, 'rf')
12endfunc
13
Bram Moolenaarf3654822016-03-04 22:12:23 +010014func Test_packadd()
Bram Moolenaar71fb0c12016-04-02 22:44:16 +020015 call mkdir(s:plugdir . '/plugin/also', 'p')
Bram Moolenaar91715872016-03-03 17:13:03 +010016 call mkdir(s:plugdir . '/ftdetect', 'p')
Bram Moolenaara5702442016-05-24 19:37:29 +020017 call mkdir(s:plugdir . '/after', 'p')
Bram Moolenaar91715872016-03-03 17:13:03 +010018 set rtp&
19 let rtp = &rtp
Bram Moolenaar863c1a92016-03-03 15:47:06 +010020 filetype on
Bram Moolenaar863c1a92016-03-03 15:47:06 +010021
Bram Moolenaar91715872016-03-03 17:13:03 +010022 exe 'split ' . s:plugdir . '/plugin/test.vim'
23 call setline(1, 'let g:plugin_works = 42')
24 wq
Bram Moolenaar863c1a92016-03-03 15:47:06 +010025
Bram Moolenaar71fb0c12016-04-02 22:44:16 +020026 exe 'split ' . s:plugdir . '/plugin/also/loaded.vim'
27 call setline(1, 'let g:plugin_also_works = 77')
28 wq
29
Bram Moolenaar91715872016-03-03 17:13:03 +010030 exe 'split ' . s:plugdir . '/ftdetect/test.vim'
31 call setline(1, 'let g:ftdetect_works = 17')
32 wq
33
Bram Moolenaarf3654822016-03-04 22:12:23 +010034 packadd mytest
Bram Moolenaar91715872016-03-03 17:13:03 +010035
36 call assert_equal(42, g:plugin_works)
Bram Moolenaar71fb0c12016-04-02 22:44:16 +020037 call assert_equal(77, g:plugin_also_works)
Bram Moolenaar91715872016-03-03 17:13:03 +010038 call assert_equal(17, g:ftdetect_works)
39 call assert_true(len(&rtp) > len(rtp))
Bram Moolenaar2374faa2018-02-04 17:47:42 +010040 call assert_match('/testdir/Xdir/pack/mine/opt/mytest\($\|,\)', &rtp)
41 call assert_match('/testdir/Xdir/pack/mine/opt/mytest/after$', &rtp)
Bram Moolenaarbe82c252016-03-06 14:44:08 +010042
Bram Moolenaarf98a39c2018-04-18 22:18:23 +020043 " NOTE: '/.../opt/myte' forwardly matches with '/.../opt/mytest'
44 call mkdir(fnamemodify(s:plugdir, ':h') . '/myte', 'p')
45 let rtp = &rtp
46 packadd myte
47
48 " Check the path of 'myte' is added
49 call assert_true(len(&rtp) > len(rtp))
50 call assert_match('/testdir/Xdir/pack/mine/opt/myte\($\|,\)', &rtp)
51
Bram Moolenaarbe82c252016-03-06 14:44:08 +010052 " Check exception
53 call assert_fails("packadd directorynotfound", 'E919:')
54 call assert_fails("packadd", 'E471:')
Bram Moolenaar91715872016-03-03 17:13:03 +010055endfunc
56
Bram Moolenaar9e1d3992017-12-17 14:26:46 +010057func Test_packadd_start()
58 let plugdir = s:topdir . '/pack/mine/start/other'
59 call mkdir(plugdir . '/plugin', 'p')
60 set rtp&
61 let rtp = &rtp
62 filetype on
63
64 exe 'split ' . plugdir . '/plugin/test.vim'
65 call setline(1, 'let g:plugin_works = 24')
66 wq
67
68 packadd other
69
70 call assert_equal(24, g:plugin_works)
71 call assert_true(len(&rtp) > len(rtp))
Bram Moolenaar2374faa2018-02-04 17:47:42 +010072 call assert_match('/testdir/Xdir/pack/mine/start/other\($\|,\)', &rtp)
Bram Moolenaar9e1d3992017-12-17 14:26:46 +010073endfunc
74
Bram Moolenaarf3654822016-03-04 22:12:23 +010075func Test_packadd_noload()
76 call mkdir(s:plugdir . '/plugin', 'p')
Bram Moolenaar91715872016-03-03 17:13:03 +010077 call mkdir(s:plugdir . '/syntax', 'p')
78 set rtp&
79 let rtp = &rtp
Bram Moolenaarf3654822016-03-04 22:12:23 +010080
81 exe 'split ' . s:plugdir . '/plugin/test.vim'
82 call setline(1, 'let g:plugin_works = 42')
83 wq
84 let g:plugin_works = 0
85
86 packadd! mytest
87
Bram Moolenaar91715872016-03-03 17:13:03 +010088 call assert_true(len(&rtp) > len(rtp))
Bram Moolenaar2374faa2018-02-04 17:47:42 +010089 call assert_match('testdir/Xdir/pack/mine/opt/mytest\($\|,\)', &rtp)
Bram Moolenaarf3654822016-03-04 22:12:23 +010090 call assert_equal(0, g:plugin_works)
Bram Moolenaar91715872016-03-03 17:13:03 +010091
92 " check the path is not added twice
93 let new_rtp = &rtp
Bram Moolenaarf3654822016-03-04 22:12:23 +010094 packadd! mytest
Bram Moolenaar91715872016-03-03 17:13:03 +010095 call assert_equal(new_rtp, &rtp)
Bram Moolenaar863c1a92016-03-03 15:47:06 +010096endfunc
Bram Moolenaar35ca0e72016-03-05 17:41:49 +010097
Bram Moolenaar2f9e5752017-02-05 16:07:54 +010098func Test_packadd_symlink_dir()
99 if !has('unix')
Bram Moolenaar644df412017-03-09 13:58:02 +0100100 return
Bram Moolenaar2f9e5752017-02-05 16:07:54 +0100101 endif
102 let top2_dir = s:topdir . '/Xdir2'
103 let real_dir = s:topdir . '/Xsym'
Bram Moolenaar644df412017-03-09 13:58:02 +0100104 call mkdir(real_dir, 'p')
105 exec "silent !ln -s Xsym" top2_dir
Bram Moolenaar2f9e5752017-02-05 16:07:54 +0100106 let &rtp = top2_dir . ',' . top2_dir . '/after'
107 let &packpath = &rtp
108
109 let s:plugdir = top2_dir . '/pack/mine/opt/mytest'
110 call mkdir(s:plugdir . '/plugin', 'p')
111
112 exe 'split ' . s:plugdir . '/plugin/test.vim'
113 call setline(1, 'let g:plugin_works = 44')
114 wq
115 let g:plugin_works = 0
116
117 packadd mytest
118
119 " Must have been inserted in the middle, not at the end
Bram Moolenaar2374faa2018-02-04 17:47:42 +0100120 call assert_match('/pack/mine/opt/mytest,', &rtp)
Bram Moolenaar2f9e5752017-02-05 16:07:54 +0100121 call assert_equal(44, g:plugin_works)
122
123 " No change when doing it again.
124 let rtp_before = &rtp
125 packadd mytest
126 call assert_equal(rtp_before, &rtp)
127
128 set rtp&
129 let rtp = &rtp
Bram Moolenaar24f8f542017-02-11 23:00:36 +0100130 exec "silent !rm" top2_dir
Bram Moolenaar2f9e5752017-02-05 16:07:54 +0100131endfunc
132
Bram Moolenaar2374faa2018-02-04 17:47:42 +0100133func Test_packadd_symlink_dir2()
134 if !has('unix')
135 return
136 endif
137 let top2_dir = s:topdir . '/Xdir2'
138 let real_dir = s:topdir . '/Xsym/pack'
139 call mkdir(top2_dir, 'p')
140 call mkdir(real_dir, 'p')
141 let &rtp = top2_dir . ',' . top2_dir . '/after'
142 let &packpath = &rtp
143
144 exec "silent !ln -s ../Xsym/pack" top2_dir . '/pack'
145 let s:plugdir = top2_dir . '/pack/mine/opt/mytest'
146 call mkdir(s:plugdir . '/plugin', 'p')
147
148 exe 'split ' . s:plugdir . '/plugin/test.vim'
149 call setline(1, 'let g:plugin_works = 48')
150 wq
151 let g:plugin_works = 0
152
153 packadd mytest
154
155 " Must have been inserted in the middle, not at the end
156 call assert_match('/Xdir2/pack/mine/opt/mytest,', &rtp)
157 call assert_equal(48, g:plugin_works)
158
159 " No change when doing it again.
160 let rtp_before = &rtp
161 packadd mytest
162 call assert_equal(rtp_before, &rtp)
163
164 set rtp&
165 let rtp = &rtp
166 exec "silent !rm" top2_dir . '/pack'
167 exec "silent !rmdir" top2_dir
168endfunc
169
Bram Moolenaar35ca0e72016-03-05 17:41:49 +0100170" Check command-line completion for 'packadd'
171func Test_packadd_completion()
172 let optdir1 = &packpath . '/pack/mine/opt'
173 let optdir2 = &packpath . '/pack/candidate/opt'
174
175 call mkdir(optdir1 . '/pluginA', 'p')
176 call mkdir(optdir1 . '/pluginC', 'p')
177 call mkdir(optdir2 . '/pluginB', 'p')
178 call mkdir(optdir2 . '/pluginC', 'p')
179
180 let li = []
181 call feedkeys(":packadd \<Tab>')\<C-B>call add(li, '\<CR>", 't')
182 call feedkeys(":packadd " . repeat("\<Tab>", 2) . "')\<C-B>call add(li, '\<CR>", 't')
183 call feedkeys(":packadd " . repeat("\<Tab>", 3) . "')\<C-B>call add(li, '\<CR>", 't')
184 call feedkeys(":packadd " . repeat("\<Tab>", 4) . "')\<C-B>call add(li, '\<CR>", 'tx')
185 call assert_equal("packadd pluginA", li[0])
186 call assert_equal("packadd pluginB", li[1])
187 call assert_equal("packadd pluginC", li[2])
188 call assert_equal("packadd ", li[3])
189endfunc
Bram Moolenaar2d8f56a2016-03-12 20:34:27 +0100190
191func Test_packloadall()
Bram Moolenaar49b27322016-04-05 21:13:00 +0200192 " plugin foo with an autoload directory
193 let fooplugindir = &packpath . '/pack/mine/start/foo/plugin'
194 call mkdir(fooplugindir, 'p')
195 call writefile(['let g:plugin_foo_number = 1234',
196 \ 'let g:plugin_foo_auto = bbb#value',
197 \ 'let g:plugin_extra_auto = extra#value'], fooplugindir . '/bar.vim')
198 let fooautodir = &packpath . '/pack/mine/start/foo/autoload'
199 call mkdir(fooautodir, 'p')
200 call writefile(['let bar#value = 77'], fooautodir . '/bar.vim')
201
202 " plugin aaa with an autoload directory
203 let aaaplugindir = &packpath . '/pack/mine/start/aaa/plugin'
204 call mkdir(aaaplugindir, 'p')
205 call writefile(['let g:plugin_aaa_number = 333',
206 \ 'let g:plugin_aaa_auto = bar#value'], aaaplugindir . '/bbb.vim')
207 let aaaautodir = &packpath . '/pack/mine/start/aaa/autoload'
208 call mkdir(aaaautodir, 'p')
209 call writefile(['let bbb#value = 55'], aaaautodir . '/bbb.vim')
210
211 " plugin extra with only an autoload directory
212 let extraautodir = &packpath . '/pack/mine/start/extra/autoload'
213 call mkdir(extraautodir, 'p')
214 call writefile(['let extra#value = 99'], extraautodir . '/extra.vim')
215
Bram Moolenaar2d8f56a2016-03-12 20:34:27 +0100216 packloadall
217 call assert_equal(1234, g:plugin_foo_number)
Bram Moolenaar49b27322016-04-05 21:13:00 +0200218 call assert_equal(55, g:plugin_foo_auto)
219 call assert_equal(99, g:plugin_extra_auto)
220 call assert_equal(333, g:plugin_aaa_number)
221 call assert_equal(77, g:plugin_aaa_auto)
Bram Moolenaar2d8f56a2016-03-12 20:34:27 +0100222
223 " only works once
Bram Moolenaar49b27322016-04-05 21:13:00 +0200224 call writefile(['let g:plugin_bar_number = 4321'], fooplugindir . '/bar2.vim')
Bram Moolenaar2d8f56a2016-03-12 20:34:27 +0100225 packloadall
226 call assert_false(exists('g:plugin_bar_number'))
227
228 " works when ! used
229 packloadall!
230 call assert_equal(4321, g:plugin_bar_number)
231endfunc
Bram Moolenaar6bef5302016-03-12 21:28:26 +0100232
233func Test_helptags()
234 let docdir1 = &packpath . '/pack/mine/start/foo/doc'
235 let docdir2 = &packpath . '/pack/mine/start/bar/doc'
236 call mkdir(docdir1, 'p')
237 call mkdir(docdir2, 'p')
238 call writefile(['look here: *look-here*'], docdir1 . '/bar.txt')
239 call writefile(['look away: *look-away*'], docdir2 . '/foo.txt')
240 exe 'set rtp=' . &packpath . '/pack/mine/start/foo,' . &packpath . '/pack/mine/start/bar'
241
242 helptags ALL
243
244 let tags1 = readfile(docdir1 . '/tags')
Bram Moolenaar2374faa2018-02-04 17:47:42 +0100245 call assert_match('look-here', tags1[0])
Bram Moolenaar6bef5302016-03-12 21:28:26 +0100246 let tags2 = readfile(docdir2 . '/tags')
Bram Moolenaar2374faa2018-02-04 17:47:42 +0100247 call assert_match('look-away', tags2[0])
Bram Moolenaar6bef5302016-03-12 21:28:26 +0100248endfunc
Bram Moolenaar7f8989d2016-03-12 22:11:39 +0100249
250func Test_colorscheme()
251 let colordirrun = &packpath . '/runtime/colors'
252 let colordirstart = &packpath . '/pack/mine/start/foo/colors'
253 let colordiropt = &packpath . '/pack/mine/opt/bar/colors'
254 call mkdir(colordirrun, 'p')
255 call mkdir(colordirstart, 'p')
256 call mkdir(colordiropt, 'p')
257 call writefile(['let g:found_one = 1'], colordirrun . '/one.vim')
258 call writefile(['let g:found_two = 1'], colordirstart . '/two.vim')
259 call writefile(['let g:found_three = 1'], colordiropt . '/three.vim')
260 exe 'set rtp=' . &packpath . '/runtime'
261
262 colorscheme one
263 call assert_equal(1, g:found_one)
264 colorscheme two
265 call assert_equal(1, g:found_two)
266 colorscheme three
267 call assert_equal(1, g:found_three)
268endfunc
Bram Moolenaar8dcf2592016-03-12 22:47:14 +0100269
Bram Moolenaar52f9c192016-03-13 13:24:45 +0100270func Test_colorscheme_completion()
271 let colordirrun = &packpath . '/runtime/colors'
272 let colordirstart = &packpath . '/pack/mine/start/foo/colors'
273 let colordiropt = &packpath . '/pack/mine/opt/bar/colors'
274 call mkdir(colordirrun, 'p')
275 call mkdir(colordirstart, 'p')
276 call mkdir(colordiropt, 'p')
277 call writefile(['let g:found_one = 1'], colordirrun . '/one.vim')
278 call writefile(['let g:found_two = 1'], colordirstart . '/two.vim')
279 call writefile(['let g:found_three = 1'], colordiropt . '/three.vim')
280 exe 'set rtp=' . &packpath . '/runtime'
281
282 let li=[]
283 call feedkeys(":colorscheme " . repeat("\<Tab>", 1) . "')\<C-B>call add(li, '\<CR>", 't')
284 call feedkeys(":colorscheme " . repeat("\<Tab>", 2) . "')\<C-B>call add(li, '\<CR>", 't')
285 call feedkeys(":colorscheme " . repeat("\<Tab>", 3) . "')\<C-B>call add(li, '\<CR>", 't')
286 call feedkeys(":colorscheme " . repeat("\<Tab>", 4) . "')\<C-B>call add(li, '\<CR>", 'tx')
287 call assert_equal("colorscheme one", li[0])
288 call assert_equal("colorscheme three", li[1])
289 call assert_equal("colorscheme two", li[2])
290 call assert_equal("colorscheme ", li[3])
291endfunc
292
Bram Moolenaar8dcf2592016-03-12 22:47:14 +0100293func Test_runtime()
294 let rundir = &packpath . '/runtime/extra'
295 let startdir = &packpath . '/pack/mine/start/foo/extra'
296 let optdir = &packpath . '/pack/mine/opt/bar/extra'
297 call mkdir(rundir, 'p')
298 call mkdir(startdir, 'p')
299 call mkdir(optdir, 'p')
300 call writefile(['let g:sequence .= "run"'], rundir . '/bar.vim')
301 call writefile(['let g:sequence .= "start"'], startdir . '/bar.vim')
302 call writefile(['let g:sequence .= "foostart"'], startdir . '/foo.vim')
303 call writefile(['let g:sequence .= "opt"'], optdir . '/bar.vim')
304 call writefile(['let g:sequence .= "xxxopt"'], optdir . '/xxx.vim')
305 exe 'set rtp=' . &packpath . '/runtime'
306
307 let g:sequence = ''
308 runtime extra/bar.vim
309 call assert_equal('run', g:sequence)
310 let g:sequence = ''
311 runtime START extra/bar.vim
312 call assert_equal('start', g:sequence)
313 let g:sequence = ''
314 runtime OPT extra/bar.vim
315 call assert_equal('opt', g:sequence)
316 let g:sequence = ''
317 runtime PACK extra/bar.vim
318 call assert_equal('start', g:sequence)
319 let g:sequence = ''
320 runtime! PACK extra/bar.vim
321 call assert_equal('startopt', g:sequence)
322 let g:sequence = ''
323 runtime PACK extra/xxx.vim
324 call assert_equal('xxxopt', g:sequence)
325
326 let g:sequence = ''
327 runtime ALL extra/bar.vim
328 call assert_equal('run', g:sequence)
329 let g:sequence = ''
330 runtime ALL extra/foo.vim
331 call assert_equal('foostart', g:sequence)
332 let g:sequence = ''
333 runtime! ALL extra/xxx.vim
334 call assert_equal('xxxopt', g:sequence)
335 let g:sequence = ''
336 runtime! ALL extra/bar.vim
337 call assert_equal('runstartopt', g:sequence)
338endfunc