blob: eca1560f7718897907799c3ce707fa6efd002b10 [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
70" Check command-line completion for 'packadd'
71func Test_packadd_completion()
72 let optdir1 = &packpath . '/pack/mine/opt'
73 let optdir2 = &packpath . '/pack/candidate/opt'
74
75 call mkdir(optdir1 . '/pluginA', 'p')
76 call mkdir(optdir1 . '/pluginC', 'p')
77 call mkdir(optdir2 . '/pluginB', 'p')
78 call mkdir(optdir2 . '/pluginC', 'p')
79
80 let li = []
81 call feedkeys(":packadd \<Tab>')\<C-B>call add(li, '\<CR>", 't')
82 call feedkeys(":packadd " . repeat("\<Tab>", 2) . "')\<C-B>call add(li, '\<CR>", 't')
83 call feedkeys(":packadd " . repeat("\<Tab>", 3) . "')\<C-B>call add(li, '\<CR>", 't')
84 call feedkeys(":packadd " . repeat("\<Tab>", 4) . "')\<C-B>call add(li, '\<CR>", 'tx')
85 call assert_equal("packadd pluginA", li[0])
86 call assert_equal("packadd pluginB", li[1])
87 call assert_equal("packadd pluginC", li[2])
88 call assert_equal("packadd ", li[3])
89endfunc
Bram Moolenaar2d8f56a2016-03-12 20:34:27 +010090
91func Test_packloadall()
Bram Moolenaar49b27322016-04-05 21:13:00 +020092 " plugin foo with an autoload directory
93 let fooplugindir = &packpath . '/pack/mine/start/foo/plugin'
94 call mkdir(fooplugindir, 'p')
95 call writefile(['let g:plugin_foo_number = 1234',
96 \ 'let g:plugin_foo_auto = bbb#value',
97 \ 'let g:plugin_extra_auto = extra#value'], fooplugindir . '/bar.vim')
98 let fooautodir = &packpath . '/pack/mine/start/foo/autoload'
99 call mkdir(fooautodir, 'p')
100 call writefile(['let bar#value = 77'], fooautodir . '/bar.vim')
101
102 " plugin aaa with an autoload directory
103 let aaaplugindir = &packpath . '/pack/mine/start/aaa/plugin'
104 call mkdir(aaaplugindir, 'p')
105 call writefile(['let g:plugin_aaa_number = 333',
106 \ 'let g:plugin_aaa_auto = bar#value'], aaaplugindir . '/bbb.vim')
107 let aaaautodir = &packpath . '/pack/mine/start/aaa/autoload'
108 call mkdir(aaaautodir, 'p')
109 call writefile(['let bbb#value = 55'], aaaautodir . '/bbb.vim')
110
111 " plugin extra with only an autoload directory
112 let extraautodir = &packpath . '/pack/mine/start/extra/autoload'
113 call mkdir(extraautodir, 'p')
114 call writefile(['let extra#value = 99'], extraautodir . '/extra.vim')
115
Bram Moolenaar2d8f56a2016-03-12 20:34:27 +0100116 packloadall
117 call assert_equal(1234, g:plugin_foo_number)
Bram Moolenaar49b27322016-04-05 21:13:00 +0200118 call assert_equal(55, g:plugin_foo_auto)
119 call assert_equal(99, g:plugin_extra_auto)
120 call assert_equal(333, g:plugin_aaa_number)
121 call assert_equal(77, g:plugin_aaa_auto)
Bram Moolenaar2d8f56a2016-03-12 20:34:27 +0100122
123 " only works once
Bram Moolenaar49b27322016-04-05 21:13:00 +0200124 call writefile(['let g:plugin_bar_number = 4321'], fooplugindir . '/bar2.vim')
Bram Moolenaar2d8f56a2016-03-12 20:34:27 +0100125 packloadall
126 call assert_false(exists('g:plugin_bar_number'))
127
128 " works when ! used
129 packloadall!
130 call assert_equal(4321, g:plugin_bar_number)
131endfunc
Bram Moolenaar6bef5302016-03-12 21:28:26 +0100132
133func Test_helptags()
134 let docdir1 = &packpath . '/pack/mine/start/foo/doc'
135 let docdir2 = &packpath . '/pack/mine/start/bar/doc'
136 call mkdir(docdir1, 'p')
137 call mkdir(docdir2, 'p')
138 call writefile(['look here: *look-here*'], docdir1 . '/bar.txt')
139 call writefile(['look away: *look-away*'], docdir2 . '/foo.txt')
140 exe 'set rtp=' . &packpath . '/pack/mine/start/foo,' . &packpath . '/pack/mine/start/bar'
141
142 helptags ALL
143
144 let tags1 = readfile(docdir1 . '/tags')
145 call assert_true(tags1[0] =~ 'look-here')
146 let tags2 = readfile(docdir2 . '/tags')
147 call assert_true(tags2[0] =~ 'look-away')
148endfunc
Bram Moolenaar7f8989d2016-03-12 22:11:39 +0100149
150func Test_colorscheme()
151 let colordirrun = &packpath . '/runtime/colors'
152 let colordirstart = &packpath . '/pack/mine/start/foo/colors'
153 let colordiropt = &packpath . '/pack/mine/opt/bar/colors'
154 call mkdir(colordirrun, 'p')
155 call mkdir(colordirstart, 'p')
156 call mkdir(colordiropt, 'p')
157 call writefile(['let g:found_one = 1'], colordirrun . '/one.vim')
158 call writefile(['let g:found_two = 1'], colordirstart . '/two.vim')
159 call writefile(['let g:found_three = 1'], colordiropt . '/three.vim')
160 exe 'set rtp=' . &packpath . '/runtime'
161
162 colorscheme one
163 call assert_equal(1, g:found_one)
164 colorscheme two
165 call assert_equal(1, g:found_two)
166 colorscheme three
167 call assert_equal(1, g:found_three)
168endfunc
Bram Moolenaar8dcf2592016-03-12 22:47:14 +0100169
Bram Moolenaar52f9c192016-03-13 13:24:45 +0100170func Test_colorscheme_completion()
171 let colordirrun = &packpath . '/runtime/colors'
172 let colordirstart = &packpath . '/pack/mine/start/foo/colors'
173 let colordiropt = &packpath . '/pack/mine/opt/bar/colors'
174 call mkdir(colordirrun, 'p')
175 call mkdir(colordirstart, 'p')
176 call mkdir(colordiropt, 'p')
177 call writefile(['let g:found_one = 1'], colordirrun . '/one.vim')
178 call writefile(['let g:found_two = 1'], colordirstart . '/two.vim')
179 call writefile(['let g:found_three = 1'], colordiropt . '/three.vim')
180 exe 'set rtp=' . &packpath . '/runtime'
181
182 let li=[]
183 call feedkeys(":colorscheme " . repeat("\<Tab>", 1) . "')\<C-B>call add(li, '\<CR>", 't')
184 call feedkeys(":colorscheme " . repeat("\<Tab>", 2) . "')\<C-B>call add(li, '\<CR>", 't')
185 call feedkeys(":colorscheme " . repeat("\<Tab>", 3) . "')\<C-B>call add(li, '\<CR>", 't')
186 call feedkeys(":colorscheme " . repeat("\<Tab>", 4) . "')\<C-B>call add(li, '\<CR>", 'tx')
187 call assert_equal("colorscheme one", li[0])
188 call assert_equal("colorscheme three", li[1])
189 call assert_equal("colorscheme two", li[2])
190 call assert_equal("colorscheme ", li[3])
191endfunc
192
Bram Moolenaar8dcf2592016-03-12 22:47:14 +0100193func Test_runtime()
194 let rundir = &packpath . '/runtime/extra'
195 let startdir = &packpath . '/pack/mine/start/foo/extra'
196 let optdir = &packpath . '/pack/mine/opt/bar/extra'
197 call mkdir(rundir, 'p')
198 call mkdir(startdir, 'p')
199 call mkdir(optdir, 'p')
200 call writefile(['let g:sequence .= "run"'], rundir . '/bar.vim')
201 call writefile(['let g:sequence .= "start"'], startdir . '/bar.vim')
202 call writefile(['let g:sequence .= "foostart"'], startdir . '/foo.vim')
203 call writefile(['let g:sequence .= "opt"'], optdir . '/bar.vim')
204 call writefile(['let g:sequence .= "xxxopt"'], optdir . '/xxx.vim')
205 exe 'set rtp=' . &packpath . '/runtime'
206
207 let g:sequence = ''
208 runtime extra/bar.vim
209 call assert_equal('run', g:sequence)
210 let g:sequence = ''
211 runtime START extra/bar.vim
212 call assert_equal('start', g:sequence)
213 let g:sequence = ''
214 runtime OPT extra/bar.vim
215 call assert_equal('opt', g:sequence)
216 let g:sequence = ''
217 runtime PACK extra/bar.vim
218 call assert_equal('start', g:sequence)
219 let g:sequence = ''
220 runtime! PACK extra/bar.vim
221 call assert_equal('startopt', g:sequence)
222 let g:sequence = ''
223 runtime PACK extra/xxx.vim
224 call assert_equal('xxxopt', g:sequence)
225
226 let g:sequence = ''
227 runtime ALL extra/bar.vim
228 call assert_equal('run', g:sequence)
229 let g:sequence = ''
230 runtime ALL extra/foo.vim
231 call assert_equal('foostart', g:sequence)
232 let g:sequence = ''
233 runtime! ALL extra/xxx.vim
234 call assert_equal('xxxopt', g:sequence)
235 let g:sequence = ''
236 runtime! ALL extra/bar.vim
237 call assert_equal('runstartopt', g:sequence)
238endfunc