blob: 9d4c6d8fe1a3fe4e358ee0d2dd32ba2d5682fd40 [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')
74 return
75 endif
76 let top2_dir = s:topdir . '/Xdir2'
77 let real_dir = s:topdir . '/Xsym'
Bram Moolenaar24f8f542017-02-11 23:00:36 +010078 exec "silent !ln -s" real_dir top2_dir
Bram Moolenaar2f9e5752017-02-05 16:07:54 +010079 let &rtp = top2_dir . ',' . top2_dir . '/after'
80 let &packpath = &rtp
81
82 let s:plugdir = top2_dir . '/pack/mine/opt/mytest'
83 call mkdir(s:plugdir . '/plugin', 'p')
84
85 exe 'split ' . s:plugdir . '/plugin/test.vim'
86 call setline(1, 'let g:plugin_works = 44')
87 wq
88 let g:plugin_works = 0
89
90 packadd mytest
91
92 " Must have been inserted in the middle, not at the end
93 call assert_true(&rtp =~ '/pack/mine/opt/mytest,')
94 call assert_equal(44, g:plugin_works)
95
96 " No change when doing it again.
97 let rtp_before = &rtp
98 packadd mytest
99 call assert_equal(rtp_before, &rtp)
100
101 set rtp&
102 let rtp = &rtp
Bram Moolenaar24f8f542017-02-11 23:00:36 +0100103 exec "silent !rm" top2_dir
Bram Moolenaar2f9e5752017-02-05 16:07:54 +0100104endfunc
105
Bram Moolenaar35ca0e72016-03-05 17:41:49 +0100106" Check command-line completion for 'packadd'
107func Test_packadd_completion()
108 let optdir1 = &packpath . '/pack/mine/opt'
109 let optdir2 = &packpath . '/pack/candidate/opt'
110
111 call mkdir(optdir1 . '/pluginA', 'p')
112 call mkdir(optdir1 . '/pluginC', 'p')
113 call mkdir(optdir2 . '/pluginB', 'p')
114 call mkdir(optdir2 . '/pluginC', 'p')
115
116 let li = []
117 call feedkeys(":packadd \<Tab>')\<C-B>call add(li, '\<CR>", 't')
118 call feedkeys(":packadd " . repeat("\<Tab>", 2) . "')\<C-B>call add(li, '\<CR>", 't')
119 call feedkeys(":packadd " . repeat("\<Tab>", 3) . "')\<C-B>call add(li, '\<CR>", 't')
120 call feedkeys(":packadd " . repeat("\<Tab>", 4) . "')\<C-B>call add(li, '\<CR>", 'tx')
121 call assert_equal("packadd pluginA", li[0])
122 call assert_equal("packadd pluginB", li[1])
123 call assert_equal("packadd pluginC", li[2])
124 call assert_equal("packadd ", li[3])
125endfunc
Bram Moolenaar2d8f56a2016-03-12 20:34:27 +0100126
127func Test_packloadall()
Bram Moolenaar49b27322016-04-05 21:13:00 +0200128 " plugin foo with an autoload directory
129 let fooplugindir = &packpath . '/pack/mine/start/foo/plugin'
130 call mkdir(fooplugindir, 'p')
131 call writefile(['let g:plugin_foo_number = 1234',
132 \ 'let g:plugin_foo_auto = bbb#value',
133 \ 'let g:plugin_extra_auto = extra#value'], fooplugindir . '/bar.vim')
134 let fooautodir = &packpath . '/pack/mine/start/foo/autoload'
135 call mkdir(fooautodir, 'p')
136 call writefile(['let bar#value = 77'], fooautodir . '/bar.vim')
137
138 " plugin aaa with an autoload directory
139 let aaaplugindir = &packpath . '/pack/mine/start/aaa/plugin'
140 call mkdir(aaaplugindir, 'p')
141 call writefile(['let g:plugin_aaa_number = 333',
142 \ 'let g:plugin_aaa_auto = bar#value'], aaaplugindir . '/bbb.vim')
143 let aaaautodir = &packpath . '/pack/mine/start/aaa/autoload'
144 call mkdir(aaaautodir, 'p')
145 call writefile(['let bbb#value = 55'], aaaautodir . '/bbb.vim')
146
147 " plugin extra with only an autoload directory
148 let extraautodir = &packpath . '/pack/mine/start/extra/autoload'
149 call mkdir(extraautodir, 'p')
150 call writefile(['let extra#value = 99'], extraautodir . '/extra.vim')
151
Bram Moolenaar2d8f56a2016-03-12 20:34:27 +0100152 packloadall
153 call assert_equal(1234, g:plugin_foo_number)
Bram Moolenaar49b27322016-04-05 21:13:00 +0200154 call assert_equal(55, g:plugin_foo_auto)
155 call assert_equal(99, g:plugin_extra_auto)
156 call assert_equal(333, g:plugin_aaa_number)
157 call assert_equal(77, g:plugin_aaa_auto)
Bram Moolenaar2d8f56a2016-03-12 20:34:27 +0100158
159 " only works once
Bram Moolenaar49b27322016-04-05 21:13:00 +0200160 call writefile(['let g:plugin_bar_number = 4321'], fooplugindir . '/bar2.vim')
Bram Moolenaar2d8f56a2016-03-12 20:34:27 +0100161 packloadall
162 call assert_false(exists('g:plugin_bar_number'))
163
164 " works when ! used
165 packloadall!
166 call assert_equal(4321, g:plugin_bar_number)
167endfunc
Bram Moolenaar6bef5302016-03-12 21:28:26 +0100168
169func Test_helptags()
170 let docdir1 = &packpath . '/pack/mine/start/foo/doc'
171 let docdir2 = &packpath . '/pack/mine/start/bar/doc'
172 call mkdir(docdir1, 'p')
173 call mkdir(docdir2, 'p')
174 call writefile(['look here: *look-here*'], docdir1 . '/bar.txt')
175 call writefile(['look away: *look-away*'], docdir2 . '/foo.txt')
176 exe 'set rtp=' . &packpath . '/pack/mine/start/foo,' . &packpath . '/pack/mine/start/bar'
177
178 helptags ALL
179
180 let tags1 = readfile(docdir1 . '/tags')
181 call assert_true(tags1[0] =~ 'look-here')
182 let tags2 = readfile(docdir2 . '/tags')
183 call assert_true(tags2[0] =~ 'look-away')
184endfunc
Bram Moolenaar7f8989d2016-03-12 22:11:39 +0100185
186func Test_colorscheme()
187 let colordirrun = &packpath . '/runtime/colors'
188 let colordirstart = &packpath . '/pack/mine/start/foo/colors'
189 let colordiropt = &packpath . '/pack/mine/opt/bar/colors'
190 call mkdir(colordirrun, 'p')
191 call mkdir(colordirstart, 'p')
192 call mkdir(colordiropt, 'p')
193 call writefile(['let g:found_one = 1'], colordirrun . '/one.vim')
194 call writefile(['let g:found_two = 1'], colordirstart . '/two.vim')
195 call writefile(['let g:found_three = 1'], colordiropt . '/three.vim')
196 exe 'set rtp=' . &packpath . '/runtime'
197
198 colorscheme one
199 call assert_equal(1, g:found_one)
200 colorscheme two
201 call assert_equal(1, g:found_two)
202 colorscheme three
203 call assert_equal(1, g:found_three)
204endfunc
Bram Moolenaar8dcf2592016-03-12 22:47:14 +0100205
Bram Moolenaar52f9c192016-03-13 13:24:45 +0100206func Test_colorscheme_completion()
207 let colordirrun = &packpath . '/runtime/colors'
208 let colordirstart = &packpath . '/pack/mine/start/foo/colors'
209 let colordiropt = &packpath . '/pack/mine/opt/bar/colors'
210 call mkdir(colordirrun, 'p')
211 call mkdir(colordirstart, 'p')
212 call mkdir(colordiropt, 'p')
213 call writefile(['let g:found_one = 1'], colordirrun . '/one.vim')
214 call writefile(['let g:found_two = 1'], colordirstart . '/two.vim')
215 call writefile(['let g:found_three = 1'], colordiropt . '/three.vim')
216 exe 'set rtp=' . &packpath . '/runtime'
217
218 let li=[]
219 call feedkeys(":colorscheme " . repeat("\<Tab>", 1) . "')\<C-B>call add(li, '\<CR>", 't')
220 call feedkeys(":colorscheme " . repeat("\<Tab>", 2) . "')\<C-B>call add(li, '\<CR>", 't')
221 call feedkeys(":colorscheme " . repeat("\<Tab>", 3) . "')\<C-B>call add(li, '\<CR>", 't')
222 call feedkeys(":colorscheme " . repeat("\<Tab>", 4) . "')\<C-B>call add(li, '\<CR>", 'tx')
223 call assert_equal("colorscheme one", li[0])
224 call assert_equal("colorscheme three", li[1])
225 call assert_equal("colorscheme two", li[2])
226 call assert_equal("colorscheme ", li[3])
227endfunc
228
Bram Moolenaar8dcf2592016-03-12 22:47:14 +0100229func Test_runtime()
230 let rundir = &packpath . '/runtime/extra'
231 let startdir = &packpath . '/pack/mine/start/foo/extra'
232 let optdir = &packpath . '/pack/mine/opt/bar/extra'
233 call mkdir(rundir, 'p')
234 call mkdir(startdir, 'p')
235 call mkdir(optdir, 'p')
236 call writefile(['let g:sequence .= "run"'], rundir . '/bar.vim')
237 call writefile(['let g:sequence .= "start"'], startdir . '/bar.vim')
238 call writefile(['let g:sequence .= "foostart"'], startdir . '/foo.vim')
239 call writefile(['let g:sequence .= "opt"'], optdir . '/bar.vim')
240 call writefile(['let g:sequence .= "xxxopt"'], optdir . '/xxx.vim')
241 exe 'set rtp=' . &packpath . '/runtime'
242
243 let g:sequence = ''
244 runtime extra/bar.vim
245 call assert_equal('run', g:sequence)
246 let g:sequence = ''
247 runtime START extra/bar.vim
248 call assert_equal('start', g:sequence)
249 let g:sequence = ''
250 runtime OPT extra/bar.vim
251 call assert_equal('opt', g:sequence)
252 let g:sequence = ''
253 runtime PACK extra/bar.vim
254 call assert_equal('start', g:sequence)
255 let g:sequence = ''
256 runtime! PACK extra/bar.vim
257 call assert_equal('startopt', g:sequence)
258 let g:sequence = ''
259 runtime PACK extra/xxx.vim
260 call assert_equal('xxxopt', g:sequence)
261
262 let g:sequence = ''
263 runtime ALL extra/bar.vim
264 call assert_equal('run', g:sequence)
265 let g:sequence = ''
266 runtime ALL extra/foo.vim
267 call assert_equal('foostart', g:sequence)
268 let g:sequence = ''
269 runtime! ALL extra/xxx.vim
270 call assert_equal('xxxopt', g:sequence)
271 let g:sequence = ''
272 runtime! ALL extra/bar.vim
273 call assert_equal('runstartopt', g:sequence)
274endfunc