blob: 5433c9866dbda15c5b69491f60410555adb0fad6 [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
101endfunc
102
Bram Moolenaar35ca0e72016-03-05 17:41:49 +0100103" Check command-line completion for 'packadd'
104func Test_packadd_completion()
105 let optdir1 = &packpath . '/pack/mine/opt'
106 let optdir2 = &packpath . '/pack/candidate/opt'
107
108 call mkdir(optdir1 . '/pluginA', 'p')
109 call mkdir(optdir1 . '/pluginC', 'p')
110 call mkdir(optdir2 . '/pluginB', 'p')
111 call mkdir(optdir2 . '/pluginC', 'p')
112
113 let li = []
114 call feedkeys(":packadd \<Tab>')\<C-B>call add(li, '\<CR>", 't')
115 call feedkeys(":packadd " . repeat("\<Tab>", 2) . "')\<C-B>call add(li, '\<CR>", 't')
116 call feedkeys(":packadd " . repeat("\<Tab>", 3) . "')\<C-B>call add(li, '\<CR>", 't')
117 call feedkeys(":packadd " . repeat("\<Tab>", 4) . "')\<C-B>call add(li, '\<CR>", 'tx')
118 call assert_equal("packadd pluginA", li[0])
119 call assert_equal("packadd pluginB", li[1])
120 call assert_equal("packadd pluginC", li[2])
121 call assert_equal("packadd ", li[3])
122endfunc
Bram Moolenaar2d8f56a2016-03-12 20:34:27 +0100123
124func Test_packloadall()
Bram Moolenaar49b27322016-04-05 21:13:00 +0200125 " plugin foo with an autoload directory
126 let fooplugindir = &packpath . '/pack/mine/start/foo/plugin'
127 call mkdir(fooplugindir, 'p')
128 call writefile(['let g:plugin_foo_number = 1234',
129 \ 'let g:plugin_foo_auto = bbb#value',
130 \ 'let g:plugin_extra_auto = extra#value'], fooplugindir . '/bar.vim')
131 let fooautodir = &packpath . '/pack/mine/start/foo/autoload'
132 call mkdir(fooautodir, 'p')
133 call writefile(['let bar#value = 77'], fooautodir . '/bar.vim')
134
135 " plugin aaa with an autoload directory
136 let aaaplugindir = &packpath . '/pack/mine/start/aaa/plugin'
137 call mkdir(aaaplugindir, 'p')
138 call writefile(['let g:plugin_aaa_number = 333',
139 \ 'let g:plugin_aaa_auto = bar#value'], aaaplugindir . '/bbb.vim')
140 let aaaautodir = &packpath . '/pack/mine/start/aaa/autoload'
141 call mkdir(aaaautodir, 'p')
142 call writefile(['let bbb#value = 55'], aaaautodir . '/bbb.vim')
143
144 " plugin extra with only an autoload directory
145 let extraautodir = &packpath . '/pack/mine/start/extra/autoload'
146 call mkdir(extraautodir, 'p')
147 call writefile(['let extra#value = 99'], extraautodir . '/extra.vim')
148
Bram Moolenaar2d8f56a2016-03-12 20:34:27 +0100149 packloadall
150 call assert_equal(1234, g:plugin_foo_number)
Bram Moolenaar49b27322016-04-05 21:13:00 +0200151 call assert_equal(55, g:plugin_foo_auto)
152 call assert_equal(99, g:plugin_extra_auto)
153 call assert_equal(333, g:plugin_aaa_number)
154 call assert_equal(77, g:plugin_aaa_auto)
Bram Moolenaar2d8f56a2016-03-12 20:34:27 +0100155
156 " only works once
Bram Moolenaar49b27322016-04-05 21:13:00 +0200157 call writefile(['let g:plugin_bar_number = 4321'], fooplugindir . '/bar2.vim')
Bram Moolenaar2d8f56a2016-03-12 20:34:27 +0100158 packloadall
159 call assert_false(exists('g:plugin_bar_number'))
160
161 " works when ! used
162 packloadall!
163 call assert_equal(4321, g:plugin_bar_number)
164endfunc
Bram Moolenaar6bef5302016-03-12 21:28:26 +0100165
166func Test_helptags()
167 let docdir1 = &packpath . '/pack/mine/start/foo/doc'
168 let docdir2 = &packpath . '/pack/mine/start/bar/doc'
169 call mkdir(docdir1, 'p')
170 call mkdir(docdir2, 'p')
171 call writefile(['look here: *look-here*'], docdir1 . '/bar.txt')
172 call writefile(['look away: *look-away*'], docdir2 . '/foo.txt')
173 exe 'set rtp=' . &packpath . '/pack/mine/start/foo,' . &packpath . '/pack/mine/start/bar'
174
175 helptags ALL
176
177 let tags1 = readfile(docdir1 . '/tags')
178 call assert_true(tags1[0] =~ 'look-here')
179 let tags2 = readfile(docdir2 . '/tags')
180 call assert_true(tags2[0] =~ 'look-away')
181endfunc
Bram Moolenaar7f8989d2016-03-12 22:11:39 +0100182
183func Test_colorscheme()
184 let colordirrun = &packpath . '/runtime/colors'
185 let colordirstart = &packpath . '/pack/mine/start/foo/colors'
186 let colordiropt = &packpath . '/pack/mine/opt/bar/colors'
187 call mkdir(colordirrun, 'p')
188 call mkdir(colordirstart, 'p')
189 call mkdir(colordiropt, 'p')
190 call writefile(['let g:found_one = 1'], colordirrun . '/one.vim')
191 call writefile(['let g:found_two = 1'], colordirstart . '/two.vim')
192 call writefile(['let g:found_three = 1'], colordiropt . '/three.vim')
193 exe 'set rtp=' . &packpath . '/runtime'
194
195 colorscheme one
196 call assert_equal(1, g:found_one)
197 colorscheme two
198 call assert_equal(1, g:found_two)
199 colorscheme three
200 call assert_equal(1, g:found_three)
201endfunc
Bram Moolenaar8dcf2592016-03-12 22:47:14 +0100202
Bram Moolenaar52f9c192016-03-13 13:24:45 +0100203func Test_colorscheme_completion()
204 let colordirrun = &packpath . '/runtime/colors'
205 let colordirstart = &packpath . '/pack/mine/start/foo/colors'
206 let colordiropt = &packpath . '/pack/mine/opt/bar/colors'
207 call mkdir(colordirrun, 'p')
208 call mkdir(colordirstart, 'p')
209 call mkdir(colordiropt, 'p')
210 call writefile(['let g:found_one = 1'], colordirrun . '/one.vim')
211 call writefile(['let g:found_two = 1'], colordirstart . '/two.vim')
212 call writefile(['let g:found_three = 1'], colordiropt . '/three.vim')
213 exe 'set rtp=' . &packpath . '/runtime'
214
215 let li=[]
216 call feedkeys(":colorscheme " . repeat("\<Tab>", 1) . "')\<C-B>call add(li, '\<CR>", 't')
217 call feedkeys(":colorscheme " . repeat("\<Tab>", 2) . "')\<C-B>call add(li, '\<CR>", 't')
218 call feedkeys(":colorscheme " . repeat("\<Tab>", 3) . "')\<C-B>call add(li, '\<CR>", 't')
219 call feedkeys(":colorscheme " . repeat("\<Tab>", 4) . "')\<C-B>call add(li, '\<CR>", 'tx')
220 call assert_equal("colorscheme one", li[0])
221 call assert_equal("colorscheme three", li[1])
222 call assert_equal("colorscheme two", li[2])
223 call assert_equal("colorscheme ", li[3])
224endfunc
225
Bram Moolenaar8dcf2592016-03-12 22:47:14 +0100226func Test_runtime()
227 let rundir = &packpath . '/runtime/extra'
228 let startdir = &packpath . '/pack/mine/start/foo/extra'
229 let optdir = &packpath . '/pack/mine/opt/bar/extra'
230 call mkdir(rundir, 'p')
231 call mkdir(startdir, 'p')
232 call mkdir(optdir, 'p')
233 call writefile(['let g:sequence .= "run"'], rundir . '/bar.vim')
234 call writefile(['let g:sequence .= "start"'], startdir . '/bar.vim')
235 call writefile(['let g:sequence .= "foostart"'], startdir . '/foo.vim')
236 call writefile(['let g:sequence .= "opt"'], optdir . '/bar.vim')
237 call writefile(['let g:sequence .= "xxxopt"'], optdir . '/xxx.vim')
238 exe 'set rtp=' . &packpath . '/runtime'
239
240 let g:sequence = ''
241 runtime extra/bar.vim
242 call assert_equal('run', g:sequence)
243 let g:sequence = ''
244 runtime START extra/bar.vim
245 call assert_equal('start', g:sequence)
246 let g:sequence = ''
247 runtime OPT extra/bar.vim
248 call assert_equal('opt', g:sequence)
249 let g:sequence = ''
250 runtime PACK extra/bar.vim
251 call assert_equal('start', g:sequence)
252 let g:sequence = ''
253 runtime! PACK extra/bar.vim
254 call assert_equal('startopt', g:sequence)
255 let g:sequence = ''
256 runtime PACK extra/xxx.vim
257 call assert_equal('xxxopt', g:sequence)
258
259 let g:sequence = ''
260 runtime ALL extra/bar.vim
261 call assert_equal('run', g:sequence)
262 let g:sequence = ''
263 runtime ALL extra/foo.vim
264 call assert_equal('foostart', g:sequence)
265 let g:sequence = ''
266 runtime! ALL extra/xxx.vim
267 call assert_equal('xxxopt', g:sequence)
268 let g:sequence = ''
269 runtime! ALL extra/bar.vim
270 call assert_equal('runstartopt', g:sequence)
271endfunc