blob: bf00fa26c89a5746b8856670e181956c6c4ba2f5 [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 Moolenaar91715872016-03-03 17:13:03 +01003func SetUp()
4 let s:topdir = expand('%:h') . '/Xdir'
5 exe 'set packpath=' . s:topdir
6 let s:plugdir = s:topdir . '/pack/mine/opt/mytest'
7endfunc
8
9func TearDown()
10 call delete(s:topdir, 'rf')
11endfunc
12
Bram Moolenaarf3654822016-03-04 22:12:23 +010013func Test_packadd()
Bram Moolenaar71fb0c12016-04-02 22:44:16 +020014 call mkdir(s:plugdir . '/plugin/also', 'p')
Bram Moolenaar91715872016-03-03 17:13:03 +010015 call mkdir(s:plugdir . '/ftdetect', 'p')
Bram Moolenaara5702442016-05-24 19:37:29 +020016 call mkdir(s:plugdir . '/after', 'p')
Bram Moolenaar91715872016-03-03 17:13:03 +010017 set rtp&
18 let rtp = &rtp
Bram Moolenaar863c1a92016-03-03 15:47:06 +010019 filetype on
Bram Moolenaar863c1a92016-03-03 15:47:06 +010020
Bram Moolenaar91715872016-03-03 17:13:03 +010021 exe 'split ' . s:plugdir . '/plugin/test.vim'
22 call setline(1, 'let g:plugin_works = 42')
23 wq
Bram Moolenaar863c1a92016-03-03 15:47:06 +010024
Bram Moolenaar71fb0c12016-04-02 22:44:16 +020025 exe 'split ' . s:plugdir . '/plugin/also/loaded.vim'
26 call setline(1, 'let g:plugin_also_works = 77')
27 wq
28
Bram Moolenaar91715872016-03-03 17:13:03 +010029 exe 'split ' . s:plugdir . '/ftdetect/test.vim'
30 call setline(1, 'let g:ftdetect_works = 17')
31 wq
32
Bram Moolenaarf3654822016-03-04 22:12:23 +010033 packadd mytest
Bram Moolenaar91715872016-03-03 17:13:03 +010034
35 call assert_equal(42, g:plugin_works)
Bram Moolenaar71fb0c12016-04-02 22:44:16 +020036 call assert_equal(77, g:plugin_also_works)
Bram Moolenaar91715872016-03-03 17:13:03 +010037 call assert_equal(17, g:ftdetect_works)
38 call assert_true(len(&rtp) > len(rtp))
Bram Moolenaara5702442016-05-24 19:37:29 +020039 call assert_true(&rtp =~ '/testdir/Xdir/pack/mine/opt/mytest\($\|,\)')
40 call assert_true(&rtp =~ '/testdir/Xdir/pack/mine/opt/mytest/after$')
Bram Moolenaarbe82c252016-03-06 14:44:08 +010041
42 " Check exception
43 call assert_fails("packadd directorynotfound", 'E919:')
44 call assert_fails("packadd", 'E471:')
Bram Moolenaar91715872016-03-03 17:13:03 +010045endfunc
46
Bram Moolenaarf3654822016-03-04 22:12:23 +010047func Test_packadd_noload()
48 call mkdir(s:plugdir . '/plugin', 'p')
Bram Moolenaar91715872016-03-03 17:13:03 +010049 call mkdir(s:plugdir . '/syntax', 'p')
50 set rtp&
51 let rtp = &rtp
Bram Moolenaarf3654822016-03-04 22:12:23 +010052
53 exe 'split ' . s:plugdir . '/plugin/test.vim'
54 call setline(1, 'let g:plugin_works = 42')
55 wq
56 let g:plugin_works = 0
57
58 packadd! mytest
59
Bram Moolenaar91715872016-03-03 17:13:03 +010060 call assert_true(len(&rtp) > len(rtp))
61 call assert_true(&rtp =~ 'testdir/Xdir/pack/mine/opt/mytest\($\|,\)')
Bram Moolenaarf3654822016-03-04 22:12:23 +010062 call assert_equal(0, g:plugin_works)
Bram Moolenaar91715872016-03-03 17:13:03 +010063
64 " check the path is not added twice
65 let new_rtp = &rtp
Bram Moolenaarf3654822016-03-04 22:12:23 +010066 packadd! mytest
Bram Moolenaar91715872016-03-03 17:13:03 +010067 call assert_equal(new_rtp, &rtp)
Bram Moolenaar863c1a92016-03-03 15:47:06 +010068endfunc
Bram Moolenaar35ca0e72016-03-05 17:41:49 +010069
Bram Moolenaar2f9e5752017-02-05 16:07:54 +010070func Test_packadd_symlink_dir()
71 if !has('unix')
72 return
73 endif
74 let top2_dir = s:topdir . '/Xdir2'
75 let real_dir = s:topdir . '/Xsym'
76 silent !ln -s real_dir top2_dir
77 let &rtp = top2_dir . ',' . top2_dir . '/after'
78 let &packpath = &rtp
79
80 let s:plugdir = top2_dir . '/pack/mine/opt/mytest'
81 call mkdir(s:plugdir . '/plugin', 'p')
82
83 exe 'split ' . s:plugdir . '/plugin/test.vim'
84 call setline(1, 'let g:plugin_works = 44')
85 wq
86 let g:plugin_works = 0
87
88 packadd mytest
89
90 " Must have been inserted in the middle, not at the end
91 call assert_true(&rtp =~ '/pack/mine/opt/mytest,')
92 call assert_equal(44, g:plugin_works)
93
94 " No change when doing it again.
95 let rtp_before = &rtp
96 packadd mytest
97 call assert_equal(rtp_before, &rtp)
98
99 set rtp&
100 let rtp = &rtp
Bram Moolenaar913727e2017-02-11 11:34:58 +0100101 silent !rm top2_dir
Bram Moolenaar2f9e5752017-02-05 16:07:54 +0100102endfunc
103
Bram Moolenaar35ca0e72016-03-05 17:41:49 +0100104" Check command-line completion for 'packadd'
105func Test_packadd_completion()
106 let optdir1 = &packpath . '/pack/mine/opt'
107 let optdir2 = &packpath . '/pack/candidate/opt'
108
109 call mkdir(optdir1 . '/pluginA', 'p')
110 call mkdir(optdir1 . '/pluginC', 'p')
111 call mkdir(optdir2 . '/pluginB', 'p')
112 call mkdir(optdir2 . '/pluginC', 'p')
113
114 let li = []
115 call feedkeys(":packadd \<Tab>')\<C-B>call add(li, '\<CR>", 't')
116 call feedkeys(":packadd " . repeat("\<Tab>", 2) . "')\<C-B>call add(li, '\<CR>", 't')
117 call feedkeys(":packadd " . repeat("\<Tab>", 3) . "')\<C-B>call add(li, '\<CR>", 't')
118 call feedkeys(":packadd " . repeat("\<Tab>", 4) . "')\<C-B>call add(li, '\<CR>", 'tx')
119 call assert_equal("packadd pluginA", li[0])
120 call assert_equal("packadd pluginB", li[1])
121 call assert_equal("packadd pluginC", li[2])
122 call assert_equal("packadd ", li[3])
123endfunc
Bram Moolenaar2d8f56a2016-03-12 20:34:27 +0100124
125func Test_packloadall()
Bram Moolenaar49b27322016-04-05 21:13:00 +0200126 " plugin foo with an autoload directory
127 let fooplugindir = &packpath . '/pack/mine/start/foo/plugin'
128 call mkdir(fooplugindir, 'p')
129 call writefile(['let g:plugin_foo_number = 1234',
130 \ 'let g:plugin_foo_auto = bbb#value',
131 \ 'let g:plugin_extra_auto = extra#value'], fooplugindir . '/bar.vim')
132 let fooautodir = &packpath . '/pack/mine/start/foo/autoload'
133 call mkdir(fooautodir, 'p')
134 call writefile(['let bar#value = 77'], fooautodir . '/bar.vim')
135
136 " plugin aaa with an autoload directory
137 let aaaplugindir = &packpath . '/pack/mine/start/aaa/plugin'
138 call mkdir(aaaplugindir, 'p')
139 call writefile(['let g:plugin_aaa_number = 333',
140 \ 'let g:plugin_aaa_auto = bar#value'], aaaplugindir . '/bbb.vim')
141 let aaaautodir = &packpath . '/pack/mine/start/aaa/autoload'
142 call mkdir(aaaautodir, 'p')
143 call writefile(['let bbb#value = 55'], aaaautodir . '/bbb.vim')
144
145 " plugin extra with only an autoload directory
146 let extraautodir = &packpath . '/pack/mine/start/extra/autoload'
147 call mkdir(extraautodir, 'p')
148 call writefile(['let extra#value = 99'], extraautodir . '/extra.vim')
149
Bram Moolenaar2d8f56a2016-03-12 20:34:27 +0100150 packloadall
151 call assert_equal(1234, g:plugin_foo_number)
Bram Moolenaar49b27322016-04-05 21:13:00 +0200152 call assert_equal(55, g:plugin_foo_auto)
153 call assert_equal(99, g:plugin_extra_auto)
154 call assert_equal(333, g:plugin_aaa_number)
155 call assert_equal(77, g:plugin_aaa_auto)
Bram Moolenaar2d8f56a2016-03-12 20:34:27 +0100156
157 " only works once
Bram Moolenaar49b27322016-04-05 21:13:00 +0200158 call writefile(['let g:plugin_bar_number = 4321'], fooplugindir . '/bar2.vim')
Bram Moolenaar2d8f56a2016-03-12 20:34:27 +0100159 packloadall
160 call assert_false(exists('g:plugin_bar_number'))
161
162 " works when ! used
163 packloadall!
164 call assert_equal(4321, g:plugin_bar_number)
165endfunc
Bram Moolenaar6bef5302016-03-12 21:28:26 +0100166
167func Test_helptags()
168 let docdir1 = &packpath . '/pack/mine/start/foo/doc'
169 let docdir2 = &packpath . '/pack/mine/start/bar/doc'
170 call mkdir(docdir1, 'p')
171 call mkdir(docdir2, 'p')
172 call writefile(['look here: *look-here*'], docdir1 . '/bar.txt')
173 call writefile(['look away: *look-away*'], docdir2 . '/foo.txt')
174 exe 'set rtp=' . &packpath . '/pack/mine/start/foo,' . &packpath . '/pack/mine/start/bar'
175
176 helptags ALL
177
178 let tags1 = readfile(docdir1 . '/tags')
179 call assert_true(tags1[0] =~ 'look-here')
180 let tags2 = readfile(docdir2 . '/tags')
181 call assert_true(tags2[0] =~ 'look-away')
182endfunc
Bram Moolenaar7f8989d2016-03-12 22:11:39 +0100183
184func Test_colorscheme()
185 let colordirrun = &packpath . '/runtime/colors'
186 let colordirstart = &packpath . '/pack/mine/start/foo/colors'
187 let colordiropt = &packpath . '/pack/mine/opt/bar/colors'
188 call mkdir(colordirrun, 'p')
189 call mkdir(colordirstart, 'p')
190 call mkdir(colordiropt, 'p')
191 call writefile(['let g:found_one = 1'], colordirrun . '/one.vim')
192 call writefile(['let g:found_two = 1'], colordirstart . '/two.vim')
193 call writefile(['let g:found_three = 1'], colordiropt . '/three.vim')
194 exe 'set rtp=' . &packpath . '/runtime'
195
196 colorscheme one
197 call assert_equal(1, g:found_one)
198 colorscheme two
199 call assert_equal(1, g:found_two)
200 colorscheme three
201 call assert_equal(1, g:found_three)
202endfunc
Bram Moolenaar8dcf2592016-03-12 22:47:14 +0100203
Bram Moolenaar52f9c192016-03-13 13:24:45 +0100204func Test_colorscheme_completion()
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 let li=[]
217 call feedkeys(":colorscheme " . repeat("\<Tab>", 1) . "')\<C-B>call add(li, '\<CR>", 't')
218 call feedkeys(":colorscheme " . repeat("\<Tab>", 2) . "')\<C-B>call add(li, '\<CR>", 't')
219 call feedkeys(":colorscheme " . repeat("\<Tab>", 3) . "')\<C-B>call add(li, '\<CR>", 't')
220 call feedkeys(":colorscheme " . repeat("\<Tab>", 4) . "')\<C-B>call add(li, '\<CR>", 'tx')
221 call assert_equal("colorscheme one", li[0])
222 call assert_equal("colorscheme three", li[1])
223 call assert_equal("colorscheme two", li[2])
224 call assert_equal("colorscheme ", li[3])
225endfunc
226
Bram Moolenaar8dcf2592016-03-12 22:47:14 +0100227func Test_runtime()
228 let rundir = &packpath . '/runtime/extra'
229 let startdir = &packpath . '/pack/mine/start/foo/extra'
230 let optdir = &packpath . '/pack/mine/opt/bar/extra'
231 call mkdir(rundir, 'p')
232 call mkdir(startdir, 'p')
233 call mkdir(optdir, 'p')
234 call writefile(['let g:sequence .= "run"'], rundir . '/bar.vim')
235 call writefile(['let g:sequence .= "start"'], startdir . '/bar.vim')
236 call writefile(['let g:sequence .= "foostart"'], startdir . '/foo.vim')
237 call writefile(['let g:sequence .= "opt"'], optdir . '/bar.vim')
238 call writefile(['let g:sequence .= "xxxopt"'], optdir . '/xxx.vim')
239 exe 'set rtp=' . &packpath . '/runtime'
240
241 let g:sequence = ''
242 runtime extra/bar.vim
243 call assert_equal('run', g:sequence)
244 let g:sequence = ''
245 runtime START extra/bar.vim
246 call assert_equal('start', g:sequence)
247 let g:sequence = ''
248 runtime OPT extra/bar.vim
249 call assert_equal('opt', g:sequence)
250 let g:sequence = ''
251 runtime PACK extra/bar.vim
252 call assert_equal('start', g:sequence)
253 let g:sequence = ''
254 runtime! PACK extra/bar.vim
255 call assert_equal('startopt', g:sequence)
256 let g:sequence = ''
257 runtime PACK extra/xxx.vim
258 call assert_equal('xxxopt', g:sequence)
259
260 let g:sequence = ''
261 runtime ALL extra/bar.vim
262 call assert_equal('run', g:sequence)
263 let g:sequence = ''
264 runtime ALL extra/foo.vim
265 call assert_equal('foostart', g:sequence)
266 let g:sequence = ''
267 runtime! ALL extra/xxx.vim
268 call assert_equal('xxxopt', g:sequence)
269 let g:sequence = ''
270 runtime! ALL extra/bar.vim
271 call assert_equal('runstartopt', g:sequence)
272endfunc