blob: 66a344b0dcc61930eb01142ce66a5c86ebc6f2a0 [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')
16 set rtp&
17 let rtp = &rtp
Bram Moolenaar863c1a92016-03-03 15:47:06 +010018 filetype on
Bram Moolenaar863c1a92016-03-03 15:47:06 +010019
Bram Moolenaar91715872016-03-03 17:13:03 +010020 exe 'split ' . s:plugdir . '/plugin/test.vim'
21 call setline(1, 'let g:plugin_works = 42')
22 wq
Bram Moolenaar863c1a92016-03-03 15:47:06 +010023
Bram Moolenaar71fb0c12016-04-02 22:44:16 +020024 exe 'split ' . s:plugdir . '/plugin/also/loaded.vim'
25 call setline(1, 'let g:plugin_also_works = 77')
26 wq
27
Bram Moolenaar91715872016-03-03 17:13:03 +010028 exe 'split ' . s:plugdir . '/ftdetect/test.vim'
29 call setline(1, 'let g:ftdetect_works = 17')
30 wq
31
Bram Moolenaarf3654822016-03-04 22:12:23 +010032 packadd mytest
Bram Moolenaar91715872016-03-03 17:13:03 +010033
34 call assert_equal(42, g:plugin_works)
Bram Moolenaar71fb0c12016-04-02 22:44:16 +020035 call assert_equal(77, g:plugin_also_works)
Bram Moolenaar91715872016-03-03 17:13:03 +010036 call assert_equal(17, g:ftdetect_works)
37 call assert_true(len(&rtp) > len(rtp))
38 call assert_true(&rtp =~ 'testdir/Xdir/pack/mine/opt/mytest\($\|,\)')
Bram Moolenaarbe82c252016-03-06 14:44:08 +010039
40 " Check exception
41 call assert_fails("packadd directorynotfound", 'E919:')
42 call assert_fails("packadd", 'E471:')
Bram Moolenaar91715872016-03-03 17:13:03 +010043endfunc
44
Bram Moolenaarf3654822016-03-04 22:12:23 +010045func Test_packadd_noload()
46 call mkdir(s:plugdir . '/plugin', 'p')
Bram Moolenaar91715872016-03-03 17:13:03 +010047 call mkdir(s:plugdir . '/syntax', 'p')
48 set rtp&
49 let rtp = &rtp
Bram Moolenaarf3654822016-03-04 22:12:23 +010050
51 exe 'split ' . s:plugdir . '/plugin/test.vim'
52 call setline(1, 'let g:plugin_works = 42')
53 wq
54 let g:plugin_works = 0
55
56 packadd! mytest
57
Bram Moolenaar91715872016-03-03 17:13:03 +010058 call assert_true(len(&rtp) > len(rtp))
59 call assert_true(&rtp =~ 'testdir/Xdir/pack/mine/opt/mytest\($\|,\)')
Bram Moolenaarf3654822016-03-04 22:12:23 +010060 call assert_equal(0, g:plugin_works)
Bram Moolenaar91715872016-03-03 17:13:03 +010061
62 " check the path is not added twice
63 let new_rtp = &rtp
Bram Moolenaarf3654822016-03-04 22:12:23 +010064 packadd! mytest
Bram Moolenaar91715872016-03-03 17:13:03 +010065 call assert_equal(new_rtp, &rtp)
Bram Moolenaar863c1a92016-03-03 15:47:06 +010066endfunc
Bram Moolenaar35ca0e72016-03-05 17:41:49 +010067
68" Check command-line completion for 'packadd'
69func Test_packadd_completion()
70 let optdir1 = &packpath . '/pack/mine/opt'
71 let optdir2 = &packpath . '/pack/candidate/opt'
72
73 call mkdir(optdir1 . '/pluginA', 'p')
74 call mkdir(optdir1 . '/pluginC', 'p')
75 call mkdir(optdir2 . '/pluginB', 'p')
76 call mkdir(optdir2 . '/pluginC', 'p')
77
78 let li = []
79 call feedkeys(":packadd \<Tab>')\<C-B>call add(li, '\<CR>", 't')
80 call feedkeys(":packadd " . repeat("\<Tab>", 2) . "')\<C-B>call add(li, '\<CR>", 't')
81 call feedkeys(":packadd " . repeat("\<Tab>", 3) . "')\<C-B>call add(li, '\<CR>", 't')
82 call feedkeys(":packadd " . repeat("\<Tab>", 4) . "')\<C-B>call add(li, '\<CR>", 'tx')
83 call assert_equal("packadd pluginA", li[0])
84 call assert_equal("packadd pluginB", li[1])
85 call assert_equal("packadd pluginC", li[2])
86 call assert_equal("packadd ", li[3])
87endfunc
Bram Moolenaar2d8f56a2016-03-12 20:34:27 +010088
89func Test_packloadall()
Bram Moolenaar49b27322016-04-05 21:13:00 +020090 " plugin foo with an autoload directory
91 let fooplugindir = &packpath . '/pack/mine/start/foo/plugin'
92 call mkdir(fooplugindir, 'p')
93 call writefile(['let g:plugin_foo_number = 1234',
94 \ 'let g:plugin_foo_auto = bbb#value',
95 \ 'let g:plugin_extra_auto = extra#value'], fooplugindir . '/bar.vim')
96 let fooautodir = &packpath . '/pack/mine/start/foo/autoload'
97 call mkdir(fooautodir, 'p')
98 call writefile(['let bar#value = 77'], fooautodir . '/bar.vim')
99
100 " plugin aaa with an autoload directory
101 let aaaplugindir = &packpath . '/pack/mine/start/aaa/plugin'
102 call mkdir(aaaplugindir, 'p')
103 call writefile(['let g:plugin_aaa_number = 333',
104 \ 'let g:plugin_aaa_auto = bar#value'], aaaplugindir . '/bbb.vim')
105 let aaaautodir = &packpath . '/pack/mine/start/aaa/autoload'
106 call mkdir(aaaautodir, 'p')
107 call writefile(['let bbb#value = 55'], aaaautodir . '/bbb.vim')
108
109 " plugin extra with only an autoload directory
110 let extraautodir = &packpath . '/pack/mine/start/extra/autoload'
111 call mkdir(extraautodir, 'p')
112 call writefile(['let extra#value = 99'], extraautodir . '/extra.vim')
113
Bram Moolenaar2d8f56a2016-03-12 20:34:27 +0100114 packloadall
115 call assert_equal(1234, g:plugin_foo_number)
Bram Moolenaar49b27322016-04-05 21:13:00 +0200116 call assert_equal(55, g:plugin_foo_auto)
117 call assert_equal(99, g:plugin_extra_auto)
118 call assert_equal(333, g:plugin_aaa_number)
119 call assert_equal(77, g:plugin_aaa_auto)
Bram Moolenaar2d8f56a2016-03-12 20:34:27 +0100120
121 " only works once
Bram Moolenaar49b27322016-04-05 21:13:00 +0200122 call writefile(['let g:plugin_bar_number = 4321'], fooplugindir . '/bar2.vim')
Bram Moolenaar2d8f56a2016-03-12 20:34:27 +0100123 packloadall
124 call assert_false(exists('g:plugin_bar_number'))
125
126 " works when ! used
127 packloadall!
128 call assert_equal(4321, g:plugin_bar_number)
129endfunc
Bram Moolenaar6bef5302016-03-12 21:28:26 +0100130
131func Test_helptags()
132 let docdir1 = &packpath . '/pack/mine/start/foo/doc'
133 let docdir2 = &packpath . '/pack/mine/start/bar/doc'
134 call mkdir(docdir1, 'p')
135 call mkdir(docdir2, 'p')
136 call writefile(['look here: *look-here*'], docdir1 . '/bar.txt')
137 call writefile(['look away: *look-away*'], docdir2 . '/foo.txt')
138 exe 'set rtp=' . &packpath . '/pack/mine/start/foo,' . &packpath . '/pack/mine/start/bar'
139
140 helptags ALL
141
142 let tags1 = readfile(docdir1 . '/tags')
143 call assert_true(tags1[0] =~ 'look-here')
144 let tags2 = readfile(docdir2 . '/tags')
145 call assert_true(tags2[0] =~ 'look-away')
146endfunc
Bram Moolenaar7f8989d2016-03-12 22:11:39 +0100147
148func Test_colorscheme()
149 let colordirrun = &packpath . '/runtime/colors'
150 let colordirstart = &packpath . '/pack/mine/start/foo/colors'
151 let colordiropt = &packpath . '/pack/mine/opt/bar/colors'
152 call mkdir(colordirrun, 'p')
153 call mkdir(colordirstart, 'p')
154 call mkdir(colordiropt, 'p')
155 call writefile(['let g:found_one = 1'], colordirrun . '/one.vim')
156 call writefile(['let g:found_two = 1'], colordirstart . '/two.vim')
157 call writefile(['let g:found_three = 1'], colordiropt . '/three.vim')
158 exe 'set rtp=' . &packpath . '/runtime'
159
160 colorscheme one
161 call assert_equal(1, g:found_one)
162 colorscheme two
163 call assert_equal(1, g:found_two)
164 colorscheme three
165 call assert_equal(1, g:found_three)
166endfunc
Bram Moolenaar8dcf2592016-03-12 22:47:14 +0100167
Bram Moolenaar52f9c192016-03-13 13:24:45 +0100168func Test_colorscheme_completion()
169 let colordirrun = &packpath . '/runtime/colors'
170 let colordirstart = &packpath . '/pack/mine/start/foo/colors'
171 let colordiropt = &packpath . '/pack/mine/opt/bar/colors'
172 call mkdir(colordirrun, 'p')
173 call mkdir(colordirstart, 'p')
174 call mkdir(colordiropt, 'p')
175 call writefile(['let g:found_one = 1'], colordirrun . '/one.vim')
176 call writefile(['let g:found_two = 1'], colordirstart . '/two.vim')
177 call writefile(['let g:found_three = 1'], colordiropt . '/three.vim')
178 exe 'set rtp=' . &packpath . '/runtime'
179
180 let li=[]
181 call feedkeys(":colorscheme " . repeat("\<Tab>", 1) . "')\<C-B>call add(li, '\<CR>", 't')
182 call feedkeys(":colorscheme " . repeat("\<Tab>", 2) . "')\<C-B>call add(li, '\<CR>", 't')
183 call feedkeys(":colorscheme " . repeat("\<Tab>", 3) . "')\<C-B>call add(li, '\<CR>", 't')
184 call feedkeys(":colorscheme " . repeat("\<Tab>", 4) . "')\<C-B>call add(li, '\<CR>", 'tx')
185 call assert_equal("colorscheme one", li[0])
186 call assert_equal("colorscheme three", li[1])
187 call assert_equal("colorscheme two", li[2])
188 call assert_equal("colorscheme ", li[3])
189endfunc
190
Bram Moolenaar8dcf2592016-03-12 22:47:14 +0100191func Test_runtime()
192 let rundir = &packpath . '/runtime/extra'
193 let startdir = &packpath . '/pack/mine/start/foo/extra'
194 let optdir = &packpath . '/pack/mine/opt/bar/extra'
195 call mkdir(rundir, 'p')
196 call mkdir(startdir, 'p')
197 call mkdir(optdir, 'p')
198 call writefile(['let g:sequence .= "run"'], rundir . '/bar.vim')
199 call writefile(['let g:sequence .= "start"'], startdir . '/bar.vim')
200 call writefile(['let g:sequence .= "foostart"'], startdir . '/foo.vim')
201 call writefile(['let g:sequence .= "opt"'], optdir . '/bar.vim')
202 call writefile(['let g:sequence .= "xxxopt"'], optdir . '/xxx.vim')
203 exe 'set rtp=' . &packpath . '/runtime'
204
205 let g:sequence = ''
206 runtime extra/bar.vim
207 call assert_equal('run', g:sequence)
208 let g:sequence = ''
209 runtime START extra/bar.vim
210 call assert_equal('start', g:sequence)
211 let g:sequence = ''
212 runtime OPT extra/bar.vim
213 call assert_equal('opt', g:sequence)
214 let g:sequence = ''
215 runtime PACK extra/bar.vim
216 call assert_equal('start', g:sequence)
217 let g:sequence = ''
218 runtime! PACK extra/bar.vim
219 call assert_equal('startopt', g:sequence)
220 let g:sequence = ''
221 runtime PACK extra/xxx.vim
222 call assert_equal('xxxopt', g:sequence)
223
224 let g:sequence = ''
225 runtime ALL extra/bar.vim
226 call assert_equal('run', g:sequence)
227 let g:sequence = ''
228 runtime ALL extra/foo.vim
229 call assert_equal('foostart', g:sequence)
230 let g:sequence = ''
231 runtime! ALL extra/xxx.vim
232 call assert_equal('xxxopt', g:sequence)
233 let g:sequence = ''
234 runtime! ALL extra/bar.vim
235 call assert_equal('runstartopt', g:sequence)
236endfunc