blob: 889d77f4145deda2605cfb612d5fb819eeb47e23 [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
43 " Check exception
44 call assert_fails("packadd directorynotfound", 'E919:')
45 call assert_fails("packadd", 'E471:')
Bram Moolenaar91715872016-03-03 17:13:03 +010046endfunc
47
Bram Moolenaar9e1d3992017-12-17 14:26:46 +010048func Test_packadd_start()
49 let plugdir = s:topdir . '/pack/mine/start/other'
50 call mkdir(plugdir . '/plugin', 'p')
51 set rtp&
52 let rtp = &rtp
53 filetype on
54
55 exe 'split ' . plugdir . '/plugin/test.vim'
56 call setline(1, 'let g:plugin_works = 24')
57 wq
58
59 packadd other
60
61 call assert_equal(24, g:plugin_works)
62 call assert_true(len(&rtp) > len(rtp))
Bram Moolenaar2374faa2018-02-04 17:47:42 +010063 call assert_match('/testdir/Xdir/pack/mine/start/other\($\|,\)', &rtp)
Bram Moolenaar9e1d3992017-12-17 14:26:46 +010064endfunc
65
Bram Moolenaarf3654822016-03-04 22:12:23 +010066func Test_packadd_noload()
67 call mkdir(s:plugdir . '/plugin', 'p')
Bram Moolenaar91715872016-03-03 17:13:03 +010068 call mkdir(s:plugdir . '/syntax', 'p')
69 set rtp&
70 let rtp = &rtp
Bram Moolenaarf3654822016-03-04 22:12:23 +010071
72 exe 'split ' . s:plugdir . '/plugin/test.vim'
73 call setline(1, 'let g:plugin_works = 42')
74 wq
75 let g:plugin_works = 0
76
77 packadd! mytest
78
Bram Moolenaar91715872016-03-03 17:13:03 +010079 call assert_true(len(&rtp) > len(rtp))
Bram Moolenaar2374faa2018-02-04 17:47:42 +010080 call assert_match('testdir/Xdir/pack/mine/opt/mytest\($\|,\)', &rtp)
Bram Moolenaarf3654822016-03-04 22:12:23 +010081 call assert_equal(0, g:plugin_works)
Bram Moolenaar91715872016-03-03 17:13:03 +010082
83 " check the path is not added twice
84 let new_rtp = &rtp
Bram Moolenaarf3654822016-03-04 22:12:23 +010085 packadd! mytest
Bram Moolenaar91715872016-03-03 17:13:03 +010086 call assert_equal(new_rtp, &rtp)
Bram Moolenaar863c1a92016-03-03 15:47:06 +010087endfunc
Bram Moolenaar35ca0e72016-03-05 17:41:49 +010088
Bram Moolenaar2f9e5752017-02-05 16:07:54 +010089func Test_packadd_symlink_dir()
90 if !has('unix')
Bram Moolenaar644df412017-03-09 13:58:02 +010091 return
Bram Moolenaar2f9e5752017-02-05 16:07:54 +010092 endif
93 let top2_dir = s:topdir . '/Xdir2'
94 let real_dir = s:topdir . '/Xsym'
Bram Moolenaar644df412017-03-09 13:58:02 +010095 call mkdir(real_dir, 'p')
96 exec "silent !ln -s Xsym" top2_dir
Bram Moolenaar2f9e5752017-02-05 16:07:54 +010097 let &rtp = top2_dir . ',' . top2_dir . '/after'
98 let &packpath = &rtp
99
100 let s:plugdir = top2_dir . '/pack/mine/opt/mytest'
101 call mkdir(s:plugdir . '/plugin', 'p')
102
103 exe 'split ' . s:plugdir . '/plugin/test.vim'
104 call setline(1, 'let g:plugin_works = 44')
105 wq
106 let g:plugin_works = 0
107
108 packadd mytest
109
110 " Must have been inserted in the middle, not at the end
Bram Moolenaar2374faa2018-02-04 17:47:42 +0100111 call assert_match('/pack/mine/opt/mytest,', &rtp)
Bram Moolenaar2f9e5752017-02-05 16:07:54 +0100112 call assert_equal(44, g:plugin_works)
113
114 " No change when doing it again.
115 let rtp_before = &rtp
116 packadd mytest
117 call assert_equal(rtp_before, &rtp)
118
119 set rtp&
120 let rtp = &rtp
Bram Moolenaar24f8f542017-02-11 23:00:36 +0100121 exec "silent !rm" top2_dir
Bram Moolenaar2f9e5752017-02-05 16:07:54 +0100122endfunc
123
Bram Moolenaar2374faa2018-02-04 17:47:42 +0100124func Test_packadd_symlink_dir2()
125 if !has('unix')
126 return
127 endif
128 let top2_dir = s:topdir . '/Xdir2'
129 let real_dir = s:topdir . '/Xsym/pack'
130 call mkdir(top2_dir, 'p')
131 call mkdir(real_dir, 'p')
132 let &rtp = top2_dir . ',' . top2_dir . '/after'
133 let &packpath = &rtp
134
135 exec "silent !ln -s ../Xsym/pack" top2_dir . '/pack'
136 let s:plugdir = top2_dir . '/pack/mine/opt/mytest'
137 call mkdir(s:plugdir . '/plugin', 'p')
138
139 exe 'split ' . s:plugdir . '/plugin/test.vim'
140 call setline(1, 'let g:plugin_works = 48')
141 wq
142 let g:plugin_works = 0
143
144 packadd mytest
145
146 " Must have been inserted in the middle, not at the end
147 call assert_match('/Xdir2/pack/mine/opt/mytest,', &rtp)
148 call assert_equal(48, g:plugin_works)
149
150 " No change when doing it again.
151 let rtp_before = &rtp
152 packadd mytest
153 call assert_equal(rtp_before, &rtp)
154
155 set rtp&
156 let rtp = &rtp
157 exec "silent !rm" top2_dir . '/pack'
158 exec "silent !rmdir" top2_dir
159endfunc
160
Bram Moolenaar35ca0e72016-03-05 17:41:49 +0100161" Check command-line completion for 'packadd'
162func Test_packadd_completion()
163 let optdir1 = &packpath . '/pack/mine/opt'
164 let optdir2 = &packpath . '/pack/candidate/opt'
165
166 call mkdir(optdir1 . '/pluginA', 'p')
167 call mkdir(optdir1 . '/pluginC', 'p')
168 call mkdir(optdir2 . '/pluginB', 'p')
169 call mkdir(optdir2 . '/pluginC', 'p')
170
171 let li = []
172 call feedkeys(":packadd \<Tab>')\<C-B>call add(li, '\<CR>", 't')
173 call feedkeys(":packadd " . repeat("\<Tab>", 2) . "')\<C-B>call add(li, '\<CR>", 't')
174 call feedkeys(":packadd " . repeat("\<Tab>", 3) . "')\<C-B>call add(li, '\<CR>", 't')
175 call feedkeys(":packadd " . repeat("\<Tab>", 4) . "')\<C-B>call add(li, '\<CR>", 'tx')
176 call assert_equal("packadd pluginA", li[0])
177 call assert_equal("packadd pluginB", li[1])
178 call assert_equal("packadd pluginC", li[2])
179 call assert_equal("packadd ", li[3])
180endfunc
Bram Moolenaar2d8f56a2016-03-12 20:34:27 +0100181
182func Test_packloadall()
Bram Moolenaar49b27322016-04-05 21:13:00 +0200183 " plugin foo with an autoload directory
184 let fooplugindir = &packpath . '/pack/mine/start/foo/plugin'
185 call mkdir(fooplugindir, 'p')
186 call writefile(['let g:plugin_foo_number = 1234',
187 \ 'let g:plugin_foo_auto = bbb#value',
188 \ 'let g:plugin_extra_auto = extra#value'], fooplugindir . '/bar.vim')
189 let fooautodir = &packpath . '/pack/mine/start/foo/autoload'
190 call mkdir(fooautodir, 'p')
191 call writefile(['let bar#value = 77'], fooautodir . '/bar.vim')
192
193 " plugin aaa with an autoload directory
194 let aaaplugindir = &packpath . '/pack/mine/start/aaa/plugin'
195 call mkdir(aaaplugindir, 'p')
196 call writefile(['let g:plugin_aaa_number = 333',
197 \ 'let g:plugin_aaa_auto = bar#value'], aaaplugindir . '/bbb.vim')
198 let aaaautodir = &packpath . '/pack/mine/start/aaa/autoload'
199 call mkdir(aaaautodir, 'p')
200 call writefile(['let bbb#value = 55'], aaaautodir . '/bbb.vim')
201
202 " plugin extra with only an autoload directory
203 let extraautodir = &packpath . '/pack/mine/start/extra/autoload'
204 call mkdir(extraautodir, 'p')
205 call writefile(['let extra#value = 99'], extraautodir . '/extra.vim')
206
Bram Moolenaar2d8f56a2016-03-12 20:34:27 +0100207 packloadall
208 call assert_equal(1234, g:plugin_foo_number)
Bram Moolenaar49b27322016-04-05 21:13:00 +0200209 call assert_equal(55, g:plugin_foo_auto)
210 call assert_equal(99, g:plugin_extra_auto)
211 call assert_equal(333, g:plugin_aaa_number)
212 call assert_equal(77, g:plugin_aaa_auto)
Bram Moolenaar2d8f56a2016-03-12 20:34:27 +0100213
214 " only works once
Bram Moolenaar49b27322016-04-05 21:13:00 +0200215 call writefile(['let g:plugin_bar_number = 4321'], fooplugindir . '/bar2.vim')
Bram Moolenaar2d8f56a2016-03-12 20:34:27 +0100216 packloadall
217 call assert_false(exists('g:plugin_bar_number'))
218
219 " works when ! used
220 packloadall!
221 call assert_equal(4321, g:plugin_bar_number)
222endfunc
Bram Moolenaar6bef5302016-03-12 21:28:26 +0100223
224func Test_helptags()
225 let docdir1 = &packpath . '/pack/mine/start/foo/doc'
226 let docdir2 = &packpath . '/pack/mine/start/bar/doc'
227 call mkdir(docdir1, 'p')
228 call mkdir(docdir2, 'p')
229 call writefile(['look here: *look-here*'], docdir1 . '/bar.txt')
230 call writefile(['look away: *look-away*'], docdir2 . '/foo.txt')
231 exe 'set rtp=' . &packpath . '/pack/mine/start/foo,' . &packpath . '/pack/mine/start/bar'
232
233 helptags ALL
234
235 let tags1 = readfile(docdir1 . '/tags')
Bram Moolenaar2374faa2018-02-04 17:47:42 +0100236 call assert_match('look-here', tags1[0])
Bram Moolenaar6bef5302016-03-12 21:28:26 +0100237 let tags2 = readfile(docdir2 . '/tags')
Bram Moolenaar2374faa2018-02-04 17:47:42 +0100238 call assert_match('look-away', tags2[0])
Bram Moolenaar6bef5302016-03-12 21:28:26 +0100239endfunc
Bram Moolenaar7f8989d2016-03-12 22:11:39 +0100240
241func Test_colorscheme()
242 let colordirrun = &packpath . '/runtime/colors'
243 let colordirstart = &packpath . '/pack/mine/start/foo/colors'
244 let colordiropt = &packpath . '/pack/mine/opt/bar/colors'
245 call mkdir(colordirrun, 'p')
246 call mkdir(colordirstart, 'p')
247 call mkdir(colordiropt, 'p')
248 call writefile(['let g:found_one = 1'], colordirrun . '/one.vim')
249 call writefile(['let g:found_two = 1'], colordirstart . '/two.vim')
250 call writefile(['let g:found_three = 1'], colordiropt . '/three.vim')
251 exe 'set rtp=' . &packpath . '/runtime'
252
253 colorscheme one
254 call assert_equal(1, g:found_one)
255 colorscheme two
256 call assert_equal(1, g:found_two)
257 colorscheme three
258 call assert_equal(1, g:found_three)
259endfunc
Bram Moolenaar8dcf2592016-03-12 22:47:14 +0100260
Bram Moolenaar52f9c192016-03-13 13:24:45 +0100261func Test_colorscheme_completion()
262 let colordirrun = &packpath . '/runtime/colors'
263 let colordirstart = &packpath . '/pack/mine/start/foo/colors'
264 let colordiropt = &packpath . '/pack/mine/opt/bar/colors'
265 call mkdir(colordirrun, 'p')
266 call mkdir(colordirstart, 'p')
267 call mkdir(colordiropt, 'p')
268 call writefile(['let g:found_one = 1'], colordirrun . '/one.vim')
269 call writefile(['let g:found_two = 1'], colordirstart . '/two.vim')
270 call writefile(['let g:found_three = 1'], colordiropt . '/three.vim')
271 exe 'set rtp=' . &packpath . '/runtime'
272
273 let li=[]
274 call feedkeys(":colorscheme " . repeat("\<Tab>", 1) . "')\<C-B>call add(li, '\<CR>", 't')
275 call feedkeys(":colorscheme " . repeat("\<Tab>", 2) . "')\<C-B>call add(li, '\<CR>", 't')
276 call feedkeys(":colorscheme " . repeat("\<Tab>", 3) . "')\<C-B>call add(li, '\<CR>", 't')
277 call feedkeys(":colorscheme " . repeat("\<Tab>", 4) . "')\<C-B>call add(li, '\<CR>", 'tx')
278 call assert_equal("colorscheme one", li[0])
279 call assert_equal("colorscheme three", li[1])
280 call assert_equal("colorscheme two", li[2])
281 call assert_equal("colorscheme ", li[3])
282endfunc
283
Bram Moolenaar8dcf2592016-03-12 22:47:14 +0100284func Test_runtime()
285 let rundir = &packpath . '/runtime/extra'
286 let startdir = &packpath . '/pack/mine/start/foo/extra'
287 let optdir = &packpath . '/pack/mine/opt/bar/extra'
288 call mkdir(rundir, 'p')
289 call mkdir(startdir, 'p')
290 call mkdir(optdir, 'p')
291 call writefile(['let g:sequence .= "run"'], rundir . '/bar.vim')
292 call writefile(['let g:sequence .= "start"'], startdir . '/bar.vim')
293 call writefile(['let g:sequence .= "foostart"'], startdir . '/foo.vim')
294 call writefile(['let g:sequence .= "opt"'], optdir . '/bar.vim')
295 call writefile(['let g:sequence .= "xxxopt"'], optdir . '/xxx.vim')
296 exe 'set rtp=' . &packpath . '/runtime'
297
298 let g:sequence = ''
299 runtime extra/bar.vim
300 call assert_equal('run', g:sequence)
301 let g:sequence = ''
302 runtime START extra/bar.vim
303 call assert_equal('start', g:sequence)
304 let g:sequence = ''
305 runtime OPT extra/bar.vim
306 call assert_equal('opt', g:sequence)
307 let g:sequence = ''
308 runtime PACK extra/bar.vim
309 call assert_equal('start', g:sequence)
310 let g:sequence = ''
311 runtime! PACK extra/bar.vim
312 call assert_equal('startopt', g:sequence)
313 let g:sequence = ''
314 runtime PACK extra/xxx.vim
315 call assert_equal('xxxopt', g:sequence)
316
317 let g:sequence = ''
318 runtime ALL extra/bar.vim
319 call assert_equal('run', g:sequence)
320 let g:sequence = ''
321 runtime ALL extra/foo.vim
322 call assert_equal('foostart', g:sequence)
323 let g:sequence = ''
324 runtime! ALL extra/xxx.vim
325 call assert_equal('xxxopt', g:sequence)
326 let g:sequence = ''
327 runtime! ALL extra/bar.vim
328 call assert_equal('runstartopt', g:sequence)
329endfunc