blob: 09b9b82f5511c682cc0a81092c7ba30f68db4188 [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 Moolenaara5702442016-05-24 19:37:29 +020040 call assert_true(&rtp =~ '/testdir/Xdir/pack/mine/opt/mytest\($\|,\)')
41 call assert_true(&rtp =~ '/testdir/Xdir/pack/mine/opt/mytest/after$')
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))
63 call assert_true(&rtp =~ '/testdir/Xdir/pack/mine/start/other\($\|,\)')
64endfunc
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))
80 call assert_true(&rtp =~ 'testdir/Xdir/pack/mine/opt/mytest\($\|,\)')
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
111 call assert_true(&rtp =~ '/pack/mine/opt/mytest,')
112 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 Moolenaar35ca0e72016-03-05 17:41:49 +0100124" Check command-line completion for 'packadd'
125func Test_packadd_completion()
126 let optdir1 = &packpath . '/pack/mine/opt'
127 let optdir2 = &packpath . '/pack/candidate/opt'
128
129 call mkdir(optdir1 . '/pluginA', 'p')
130 call mkdir(optdir1 . '/pluginC', 'p')
131 call mkdir(optdir2 . '/pluginB', 'p')
132 call mkdir(optdir2 . '/pluginC', 'p')
133
134 let li = []
135 call feedkeys(":packadd \<Tab>')\<C-B>call add(li, '\<CR>", 't')
136 call feedkeys(":packadd " . repeat("\<Tab>", 2) . "')\<C-B>call add(li, '\<CR>", 't')
137 call feedkeys(":packadd " . repeat("\<Tab>", 3) . "')\<C-B>call add(li, '\<CR>", 't')
138 call feedkeys(":packadd " . repeat("\<Tab>", 4) . "')\<C-B>call add(li, '\<CR>", 'tx')
139 call assert_equal("packadd pluginA", li[0])
140 call assert_equal("packadd pluginB", li[1])
141 call assert_equal("packadd pluginC", li[2])
142 call assert_equal("packadd ", li[3])
143endfunc
Bram Moolenaar2d8f56a2016-03-12 20:34:27 +0100144
145func Test_packloadall()
Bram Moolenaar49b27322016-04-05 21:13:00 +0200146 " plugin foo with an autoload directory
147 let fooplugindir = &packpath . '/pack/mine/start/foo/plugin'
148 call mkdir(fooplugindir, 'p')
149 call writefile(['let g:plugin_foo_number = 1234',
150 \ 'let g:plugin_foo_auto = bbb#value',
151 \ 'let g:plugin_extra_auto = extra#value'], fooplugindir . '/bar.vim')
152 let fooautodir = &packpath . '/pack/mine/start/foo/autoload'
153 call mkdir(fooautodir, 'p')
154 call writefile(['let bar#value = 77'], fooautodir . '/bar.vim')
155
156 " plugin aaa with an autoload directory
157 let aaaplugindir = &packpath . '/pack/mine/start/aaa/plugin'
158 call mkdir(aaaplugindir, 'p')
159 call writefile(['let g:plugin_aaa_number = 333',
160 \ 'let g:plugin_aaa_auto = bar#value'], aaaplugindir . '/bbb.vim')
161 let aaaautodir = &packpath . '/pack/mine/start/aaa/autoload'
162 call mkdir(aaaautodir, 'p')
163 call writefile(['let bbb#value = 55'], aaaautodir . '/bbb.vim')
164
165 " plugin extra with only an autoload directory
166 let extraautodir = &packpath . '/pack/mine/start/extra/autoload'
167 call mkdir(extraautodir, 'p')
168 call writefile(['let extra#value = 99'], extraautodir . '/extra.vim')
169
Bram Moolenaar2d8f56a2016-03-12 20:34:27 +0100170 packloadall
171 call assert_equal(1234, g:plugin_foo_number)
Bram Moolenaar49b27322016-04-05 21:13:00 +0200172 call assert_equal(55, g:plugin_foo_auto)
173 call assert_equal(99, g:plugin_extra_auto)
174 call assert_equal(333, g:plugin_aaa_number)
175 call assert_equal(77, g:plugin_aaa_auto)
Bram Moolenaar2d8f56a2016-03-12 20:34:27 +0100176
177 " only works once
Bram Moolenaar49b27322016-04-05 21:13:00 +0200178 call writefile(['let g:plugin_bar_number = 4321'], fooplugindir . '/bar2.vim')
Bram Moolenaar2d8f56a2016-03-12 20:34:27 +0100179 packloadall
180 call assert_false(exists('g:plugin_bar_number'))
181
182 " works when ! used
183 packloadall!
184 call assert_equal(4321, g:plugin_bar_number)
185endfunc
Bram Moolenaar6bef5302016-03-12 21:28:26 +0100186
187func Test_helptags()
188 let docdir1 = &packpath . '/pack/mine/start/foo/doc'
189 let docdir2 = &packpath . '/pack/mine/start/bar/doc'
190 call mkdir(docdir1, 'p')
191 call mkdir(docdir2, 'p')
192 call writefile(['look here: *look-here*'], docdir1 . '/bar.txt')
193 call writefile(['look away: *look-away*'], docdir2 . '/foo.txt')
194 exe 'set rtp=' . &packpath . '/pack/mine/start/foo,' . &packpath . '/pack/mine/start/bar'
195
196 helptags ALL
197
198 let tags1 = readfile(docdir1 . '/tags')
199 call assert_true(tags1[0] =~ 'look-here')
200 let tags2 = readfile(docdir2 . '/tags')
201 call assert_true(tags2[0] =~ 'look-away')
202endfunc
Bram Moolenaar7f8989d2016-03-12 22:11:39 +0100203
204func Test_colorscheme()
205 let colordirrun = &packpath . '/runtime/colors'
206 let colordirstart = &packpath . '/pack/mine/start/foo/colors'
207 let colordiropt = &packpath . '/pack/mine/opt/bar/colors'
208 call mkdir(colordirrun, 'p')
209 call mkdir(colordirstart, 'p')
210 call mkdir(colordiropt, 'p')
211 call writefile(['let g:found_one = 1'], colordirrun . '/one.vim')
212 call writefile(['let g:found_two = 1'], colordirstart . '/two.vim')
213 call writefile(['let g:found_three = 1'], colordiropt . '/three.vim')
214 exe 'set rtp=' . &packpath . '/runtime'
215
216 colorscheme one
217 call assert_equal(1, g:found_one)
218 colorscheme two
219 call assert_equal(1, g:found_two)
220 colorscheme three
221 call assert_equal(1, g:found_three)
222endfunc
Bram Moolenaar8dcf2592016-03-12 22:47:14 +0100223
Bram Moolenaar52f9c192016-03-13 13:24:45 +0100224func Test_colorscheme_completion()
225 let colordirrun = &packpath . '/runtime/colors'
226 let colordirstart = &packpath . '/pack/mine/start/foo/colors'
227 let colordiropt = &packpath . '/pack/mine/opt/bar/colors'
228 call mkdir(colordirrun, 'p')
229 call mkdir(colordirstart, 'p')
230 call mkdir(colordiropt, 'p')
231 call writefile(['let g:found_one = 1'], colordirrun . '/one.vim')
232 call writefile(['let g:found_two = 1'], colordirstart . '/two.vim')
233 call writefile(['let g:found_three = 1'], colordiropt . '/three.vim')
234 exe 'set rtp=' . &packpath . '/runtime'
235
236 let li=[]
237 call feedkeys(":colorscheme " . repeat("\<Tab>", 1) . "')\<C-B>call add(li, '\<CR>", 't')
238 call feedkeys(":colorscheme " . repeat("\<Tab>", 2) . "')\<C-B>call add(li, '\<CR>", 't')
239 call feedkeys(":colorscheme " . repeat("\<Tab>", 3) . "')\<C-B>call add(li, '\<CR>", 't')
240 call feedkeys(":colorscheme " . repeat("\<Tab>", 4) . "')\<C-B>call add(li, '\<CR>", 'tx')
241 call assert_equal("colorscheme one", li[0])
242 call assert_equal("colorscheme three", li[1])
243 call assert_equal("colorscheme two", li[2])
244 call assert_equal("colorscheme ", li[3])
245endfunc
246
Bram Moolenaar8dcf2592016-03-12 22:47:14 +0100247func Test_runtime()
248 let rundir = &packpath . '/runtime/extra'
249 let startdir = &packpath . '/pack/mine/start/foo/extra'
250 let optdir = &packpath . '/pack/mine/opt/bar/extra'
251 call mkdir(rundir, 'p')
252 call mkdir(startdir, 'p')
253 call mkdir(optdir, 'p')
254 call writefile(['let g:sequence .= "run"'], rundir . '/bar.vim')
255 call writefile(['let g:sequence .= "start"'], startdir . '/bar.vim')
256 call writefile(['let g:sequence .= "foostart"'], startdir . '/foo.vim')
257 call writefile(['let g:sequence .= "opt"'], optdir . '/bar.vim')
258 call writefile(['let g:sequence .= "xxxopt"'], optdir . '/xxx.vim')
259 exe 'set rtp=' . &packpath . '/runtime'
260
261 let g:sequence = ''
262 runtime extra/bar.vim
263 call assert_equal('run', g:sequence)
264 let g:sequence = ''
265 runtime START extra/bar.vim
266 call assert_equal('start', g:sequence)
267 let g:sequence = ''
268 runtime OPT extra/bar.vim
269 call assert_equal('opt', g:sequence)
270 let g:sequence = ''
271 runtime PACK extra/bar.vim
272 call assert_equal('start', g:sequence)
273 let g:sequence = ''
274 runtime! PACK extra/bar.vim
275 call assert_equal('startopt', g:sequence)
276 let g:sequence = ''
277 runtime PACK extra/xxx.vim
278 call assert_equal('xxxopt', g:sequence)
279
280 let g:sequence = ''
281 runtime ALL extra/bar.vim
282 call assert_equal('run', g:sequence)
283 let g:sequence = ''
284 runtime ALL extra/foo.vim
285 call assert_equal('foostart', g:sequence)
286 let g:sequence = ''
287 runtime! ALL extra/xxx.vim
288 call assert_equal('xxxopt', g:sequence)
289 let g:sequence = ''
290 runtime! ALL extra/bar.vim
291 call assert_equal('runstartopt', g:sequence)
292endfunc