blob: 33dcfe0f20503adf3d30df97447b058ecbd816b9 [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 Moolenaar6d91bcb2020-08-12 18:50:36 +02003source check.vim
Bram Moolenaarc3c766e2017-03-08 22:55:19 +01004
Bram Moolenaar91715872016-03-03 17:13:03 +01005func SetUp()
Bram Moolenaar3b0d70f2022-08-29 22:31:20 +01006 let s:topdir = getcwd() . '/Xppdir'
Bram Moolenaar91715872016-03-03 17:13:03 +01007 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 Moolenaar99396d42018-09-08 18:21:16 +020016 if !exists('s:plugdir')
17 echomsg 'when running this test manually, call SetUp() first'
18 return
19 endif
20
Bram Moolenaar71fb0c12016-04-02 22:44:16 +020021 call mkdir(s:plugdir . '/plugin/also', 'p')
Bram Moolenaar91715872016-03-03 17:13:03 +010022 call mkdir(s:plugdir . '/ftdetect', 'p')
Bram Moolenaara5702442016-05-24 19:37:29 +020023 call mkdir(s:plugdir . '/after', 'p')
zeertzjq39c9ec12023-04-01 13:52:03 +010024
25 " This used to crash Vim
26 let &rtp = 'nosuchdir,' . s:plugdir . '/after'
27 packadd mytest
28 " plugdir should be inserted before plugdir/after
29 call assert_match('^nosuchdir,' . s:plugdir . ',', &rtp)
30
Bram Moolenaar91715872016-03-03 17:13:03 +010031 set rtp&
32 let rtp = &rtp
Bram Moolenaar863c1a92016-03-03 15:47:06 +010033 filetype on
Bram Moolenaar863c1a92016-03-03 15:47:06 +010034
Bram Moolenaar99396d42018-09-08 18:21:16 +020035 let rtp_entries = split(rtp, ',')
36 for entry in rtp_entries
zeertzjqb0d45ec2023-01-25 15:04:22 +000037 if entry =~? '\<after\>'
Bram Moolenaar99396d42018-09-08 18:21:16 +020038 let first_after_entry = entry
39 break
40 endif
41 endfor
42
Bram Moolenaar91715872016-03-03 17:13:03 +010043 exe 'split ' . s:plugdir . '/plugin/test.vim'
44 call setline(1, 'let g:plugin_works = 42')
45 wq
Bram Moolenaar863c1a92016-03-03 15:47:06 +010046
Bram Moolenaar71fb0c12016-04-02 22:44:16 +020047 exe 'split ' . s:plugdir . '/plugin/also/loaded.vim'
48 call setline(1, 'let g:plugin_also_works = 77')
49 wq
50
Bram Moolenaar91715872016-03-03 17:13:03 +010051 exe 'split ' . s:plugdir . '/ftdetect/test.vim'
52 call setline(1, 'let g:ftdetect_works = 17')
53 wq
54
Bram Moolenaarf3654822016-03-04 22:12:23 +010055 packadd mytest
Bram Moolenaar91715872016-03-03 17:13:03 +010056
57 call assert_equal(42, g:plugin_works)
Bram Moolenaar71fb0c12016-04-02 22:44:16 +020058 call assert_equal(77, g:plugin_also_works)
Bram Moolenaar91715872016-03-03 17:13:03 +010059 call assert_equal(17, g:ftdetect_works)
60 call assert_true(len(&rtp) > len(rtp))
Bram Moolenaar3b0d70f2022-08-29 22:31:20 +010061 call assert_match('/testdir/Xppdir/pack/mine/opt/mytest\($\|,\)', &rtp)
Bram Moolenaar99396d42018-09-08 18:21:16 +020062
Bram Moolenaar3b0d70f2022-08-29 22:31:20 +010063 let new_after = match(&rtp, '/testdir/Xppdir/pack/mine/opt/mytest/after,')
Bram Moolenaar53c8a472018-09-08 19:12:12 +020064 let forwarded = substitute(first_after_entry, '\\', '[/\\\\]', 'g')
65 let old_after = match(&rtp, ',' . forwarded . '\>')
Bram Moolenaar99396d42018-09-08 18:21:16 +020066 call assert_true(new_after > 0, 'rtp is ' . &rtp)
Bram Moolenaar53c8a472018-09-08 19:12:12 +020067 call assert_true(old_after > 0, 'match ' . forwarded . ' in ' . &rtp)
Bram Moolenaar99396d42018-09-08 18:21:16 +020068 call assert_true(new_after < old_after, 'rtp is ' . &rtp)
Bram Moolenaarbe82c252016-03-06 14:44:08 +010069
Bram Moolenaarf98a39c2018-04-18 22:18:23 +020070 " NOTE: '/.../opt/myte' forwardly matches with '/.../opt/mytest'
71 call mkdir(fnamemodify(s:plugdir, ':h') . '/myte', 'p')
72 let rtp = &rtp
73 packadd myte
74
75 " Check the path of 'myte' is added
76 call assert_true(len(&rtp) > len(rtp))
Bram Moolenaar3b0d70f2022-08-29 22:31:20 +010077 call assert_match('/testdir/Xppdir/pack/mine/opt/myte\($\|,\)', &rtp)
Bram Moolenaarf98a39c2018-04-18 22:18:23 +020078
Bram Moolenaarbe82c252016-03-06 14:44:08 +010079 " Check exception
80 call assert_fails("packadd directorynotfound", 'E919:')
81 call assert_fails("packadd", 'E471:')
Bram Moolenaar91715872016-03-03 17:13:03 +010082endfunc
83
Bram Moolenaar9e1d3992017-12-17 14:26:46 +010084func Test_packadd_start()
85 let plugdir = s:topdir . '/pack/mine/start/other'
86 call mkdir(plugdir . '/plugin', 'p')
87 set rtp&
88 let rtp = &rtp
89 filetype on
90
91 exe 'split ' . plugdir . '/plugin/test.vim'
92 call setline(1, 'let g:plugin_works = 24')
93 wq
94
95 packadd other
96
97 call assert_equal(24, g:plugin_works)
98 call assert_true(len(&rtp) > len(rtp))
Bram Moolenaar3b0d70f2022-08-29 22:31:20 +010099 call assert_match('/testdir/Xppdir/pack/mine/start/other\($\|,\)', &rtp)
Bram Moolenaar9e1d3992017-12-17 14:26:46 +0100100endfunc
101
Bram Moolenaarf3654822016-03-04 22:12:23 +0100102func Test_packadd_noload()
103 call mkdir(s:plugdir . '/plugin', 'p')
Bram Moolenaar91715872016-03-03 17:13:03 +0100104 call mkdir(s:plugdir . '/syntax', 'p')
105 set rtp&
106 let rtp = &rtp
Bram Moolenaarf3654822016-03-04 22:12:23 +0100107
108 exe 'split ' . s:plugdir . '/plugin/test.vim'
109 call setline(1, 'let g:plugin_works = 42')
110 wq
111 let g:plugin_works = 0
112
113 packadd! mytest
114
Bram Moolenaar91715872016-03-03 17:13:03 +0100115 call assert_true(len(&rtp) > len(rtp))
Bram Moolenaar3b0d70f2022-08-29 22:31:20 +0100116 call assert_match('testdir/Xppdir/pack/mine/opt/mytest\($\|,\)', &rtp)
Bram Moolenaarf3654822016-03-04 22:12:23 +0100117 call assert_equal(0, g:plugin_works)
Bram Moolenaar91715872016-03-03 17:13:03 +0100118
119 " check the path is not added twice
120 let new_rtp = &rtp
Bram Moolenaarf3654822016-03-04 22:12:23 +0100121 packadd! mytest
Bram Moolenaar91715872016-03-03 17:13:03 +0100122 call assert_equal(new_rtp, &rtp)
Bram Moolenaar863c1a92016-03-03 15:47:06 +0100123endfunc
Bram Moolenaar35ca0e72016-03-05 17:41:49 +0100124
Bram Moolenaar2f9e5752017-02-05 16:07:54 +0100125func Test_packadd_symlink_dir()
Bram Moolenaar6d91bcb2020-08-12 18:50:36 +0200126 CheckUnix
Bram Moolenaar2f9e5752017-02-05 16:07:54 +0100127 let top2_dir = s:topdir . '/Xdir2'
128 let real_dir = s:topdir . '/Xsym'
Bram Moolenaar644df412017-03-09 13:58:02 +0100129 call mkdir(real_dir, 'p')
130 exec "silent !ln -s Xsym" top2_dir
Bram Moolenaar2f9e5752017-02-05 16:07:54 +0100131 let &rtp = top2_dir . ',' . top2_dir . '/after'
132 let &packpath = &rtp
133
134 let s:plugdir = top2_dir . '/pack/mine/opt/mytest'
135 call mkdir(s:plugdir . '/plugin', 'p')
136
137 exe 'split ' . s:plugdir . '/plugin/test.vim'
138 call setline(1, 'let g:plugin_works = 44')
139 wq
140 let g:plugin_works = 0
141
142 packadd mytest
143
144 " Must have been inserted in the middle, not at the end
Bram Moolenaar2374faa2018-02-04 17:47:42 +0100145 call assert_match('/pack/mine/opt/mytest,', &rtp)
Bram Moolenaar2f9e5752017-02-05 16:07:54 +0100146 call assert_equal(44, g:plugin_works)
147
148 " No change when doing it again.
149 let rtp_before = &rtp
150 packadd mytest
151 call assert_equal(rtp_before, &rtp)
152
153 set rtp&
154 let rtp = &rtp
Bram Moolenaar24f8f542017-02-11 23:00:36 +0100155 exec "silent !rm" top2_dir
Bram Moolenaar2f9e5752017-02-05 16:07:54 +0100156endfunc
157
Bram Moolenaar2374faa2018-02-04 17:47:42 +0100158func Test_packadd_symlink_dir2()
Bram Moolenaar6d91bcb2020-08-12 18:50:36 +0200159 CheckUnix
Bram Moolenaar2374faa2018-02-04 17:47:42 +0100160 let top2_dir = s:topdir . '/Xdir2'
161 let real_dir = s:topdir . '/Xsym/pack'
162 call mkdir(top2_dir, 'p')
163 call mkdir(real_dir, 'p')
164 let &rtp = top2_dir . ',' . top2_dir . '/after'
165 let &packpath = &rtp
166
167 exec "silent !ln -s ../Xsym/pack" top2_dir . '/pack'
168 let s:plugdir = top2_dir . '/pack/mine/opt/mytest'
169 call mkdir(s:plugdir . '/plugin', 'p')
170
171 exe 'split ' . s:plugdir . '/plugin/test.vim'
172 call setline(1, 'let g:plugin_works = 48')
173 wq
174 let g:plugin_works = 0
175
176 packadd mytest
177
178 " Must have been inserted in the middle, not at the end
179 call assert_match('/Xdir2/pack/mine/opt/mytest,', &rtp)
180 call assert_equal(48, g:plugin_works)
181
182 " No change when doing it again.
183 let rtp_before = &rtp
184 packadd mytest
185 call assert_equal(rtp_before, &rtp)
186
187 set rtp&
188 let rtp = &rtp
189 exec "silent !rm" top2_dir . '/pack'
190 exec "silent !rmdir" top2_dir
191endfunc
192
zeertzjqb0d45ec2023-01-25 15:04:22 +0000193" Check command-line completion for :packadd
Bram Moolenaar35ca0e72016-03-05 17:41:49 +0100194func Test_packadd_completion()
195 let optdir1 = &packpath . '/pack/mine/opt'
196 let optdir2 = &packpath . '/pack/candidate/opt'
197
198 call mkdir(optdir1 . '/pluginA', 'p')
199 call mkdir(optdir1 . '/pluginC', 'p')
zeertzjq3770f4c2023-01-22 18:38:51 +0000200 call writefile([], optdir1 . '/unrelated')
Bram Moolenaar35ca0e72016-03-05 17:41:49 +0100201 call mkdir(optdir2 . '/pluginB', 'p')
202 call mkdir(optdir2 . '/pluginC', 'p')
zeertzjq3770f4c2023-01-22 18:38:51 +0000203 call writefile([], optdir2 . '/unrelated')
Bram Moolenaar35ca0e72016-03-05 17:41:49 +0100204
205 let li = []
206 call feedkeys(":packadd \<Tab>')\<C-B>call add(li, '\<CR>", 't')
207 call feedkeys(":packadd " . repeat("\<Tab>", 2) . "')\<C-B>call add(li, '\<CR>", 't')
208 call feedkeys(":packadd " . repeat("\<Tab>", 3) . "')\<C-B>call add(li, '\<CR>", 't')
209 call feedkeys(":packadd " . repeat("\<Tab>", 4) . "')\<C-B>call add(li, '\<CR>", 'tx')
210 call assert_equal("packadd pluginA", li[0])
211 call assert_equal("packadd pluginB", li[1])
212 call assert_equal("packadd pluginC", li[2])
213 call assert_equal("packadd ", li[3])
214endfunc
Bram Moolenaar2d8f56a2016-03-12 20:34:27 +0100215
216func Test_packloadall()
Bram Moolenaar49b27322016-04-05 21:13:00 +0200217 " plugin foo with an autoload directory
218 let fooplugindir = &packpath . '/pack/mine/start/foo/plugin'
219 call mkdir(fooplugindir, 'p')
220 call writefile(['let g:plugin_foo_number = 1234',
221 \ 'let g:plugin_foo_auto = bbb#value',
222 \ 'let g:plugin_extra_auto = extra#value'], fooplugindir . '/bar.vim')
223 let fooautodir = &packpath . '/pack/mine/start/foo/autoload'
224 call mkdir(fooautodir, 'p')
225 call writefile(['let bar#value = 77'], fooautodir . '/bar.vim')
226
227 " plugin aaa with an autoload directory
228 let aaaplugindir = &packpath . '/pack/mine/start/aaa/plugin'
229 call mkdir(aaaplugindir, 'p')
230 call writefile(['let g:plugin_aaa_number = 333',
231 \ 'let g:plugin_aaa_auto = bar#value'], aaaplugindir . '/bbb.vim')
232 let aaaautodir = &packpath . '/pack/mine/start/aaa/autoload'
233 call mkdir(aaaautodir, 'p')
234 call writefile(['let bbb#value = 55'], aaaautodir . '/bbb.vim')
235
236 " plugin extra with only an autoload directory
237 let extraautodir = &packpath . '/pack/mine/start/extra/autoload'
238 call mkdir(extraautodir, 'p')
239 call writefile(['let extra#value = 99'], extraautodir . '/extra.vim')
240
Bram Moolenaar2d8f56a2016-03-12 20:34:27 +0100241 packloadall
242 call assert_equal(1234, g:plugin_foo_number)
Bram Moolenaar49b27322016-04-05 21:13:00 +0200243 call assert_equal(55, g:plugin_foo_auto)
244 call assert_equal(99, g:plugin_extra_auto)
245 call assert_equal(333, g:plugin_aaa_number)
246 call assert_equal(77, g:plugin_aaa_auto)
Bram Moolenaar2d8f56a2016-03-12 20:34:27 +0100247
248 " only works once
Bram Moolenaar49b27322016-04-05 21:13:00 +0200249 call writefile(['let g:plugin_bar_number = 4321'], fooplugindir . '/bar2.vim')
Bram Moolenaar2d8f56a2016-03-12 20:34:27 +0100250 packloadall
251 call assert_false(exists('g:plugin_bar_number'))
252
253 " works when ! used
254 packloadall!
255 call assert_equal(4321, g:plugin_bar_number)
256endfunc
Bram Moolenaar6bef5302016-03-12 21:28:26 +0100257
=?UTF-8?q?Bj=C3=B6rn=20Linse?=223a9502022-01-31 17:26:05 +0000258func Test_start_autoload()
259 " plugin foo with an autoload directory
260 let autodir = &packpath .. '/pack/mine/start/foo/autoload'
261 call mkdir(autodir, 'p')
262 let fname = autodir .. '/foobar.vim'
263 call writefile(['func foobar#test()',
264 \ ' return 1666',
265 \ 'endfunc'], fname)
266
267 call assert_equal(1666, foobar#test())
=?UTF-8?q?Bj=C3=B6rn=20Linse?=223a9502022-01-31 17:26:05 +0000268endfunc
269
Bram Moolenaar6bef5302016-03-12 21:28:26 +0100270func Test_helptags()
271 let docdir1 = &packpath . '/pack/mine/start/foo/doc'
272 let docdir2 = &packpath . '/pack/mine/start/bar/doc'
273 call mkdir(docdir1, 'p')
274 call mkdir(docdir2, 'p')
275 call writefile(['look here: *look-here*'], docdir1 . '/bar.txt')
276 call writefile(['look away: *look-away*'], docdir2 . '/foo.txt')
277 exe 'set rtp=' . &packpath . '/pack/mine/start/foo,' . &packpath . '/pack/mine/start/bar'
278
279 helptags ALL
280
zeertzjqb0d45ec2023-01-25 15:04:22 +0000281 let tags1 = readfile(docdir1 . '/tags')
Bram Moolenaar2374faa2018-02-04 17:47:42 +0100282 call assert_match('look-here', tags1[0])
zeertzjqb0d45ec2023-01-25 15:04:22 +0000283 let tags2 = readfile(docdir2 . '/tags')
Bram Moolenaar2374faa2018-02-04 17:47:42 +0100284 call assert_match('look-away', tags2[0])
Bram Moolenaar5d98dc22020-01-29 21:57:34 +0100285
286 call assert_fails('helptags abcxyz', 'E150:')
Bram Moolenaar6bef5302016-03-12 21:28:26 +0100287endfunc
Bram Moolenaar7f8989d2016-03-12 22:11:39 +0100288
289func Test_colorscheme()
290 let colordirrun = &packpath . '/runtime/colors'
291 let colordirstart = &packpath . '/pack/mine/start/foo/colors'
292 let colordiropt = &packpath . '/pack/mine/opt/bar/colors'
293 call mkdir(colordirrun, 'p')
294 call mkdir(colordirstart, 'p')
295 call mkdir(colordiropt, 'p')
296 call writefile(['let g:found_one = 1'], colordirrun . '/one.vim')
297 call writefile(['let g:found_two = 1'], colordirstart . '/two.vim')
298 call writefile(['let g:found_three = 1'], colordiropt . '/three.vim')
299 exe 'set rtp=' . &packpath . '/runtime'
300
301 colorscheme one
302 call assert_equal(1, g:found_one)
303 colorscheme two
304 call assert_equal(1, g:found_two)
305 colorscheme three
306 call assert_equal(1, g:found_three)
307endfunc
Bram Moolenaar8dcf2592016-03-12 22:47:14 +0100308
Bram Moolenaar52f9c192016-03-13 13:24:45 +0100309func Test_colorscheme_completion()
310 let colordirrun = &packpath . '/runtime/colors'
311 let colordirstart = &packpath . '/pack/mine/start/foo/colors'
312 let colordiropt = &packpath . '/pack/mine/opt/bar/colors'
313 call mkdir(colordirrun, 'p')
314 call mkdir(colordirstart, 'p')
315 call mkdir(colordiropt, 'p')
316 call writefile(['let g:found_one = 1'], colordirrun . '/one.vim')
317 call writefile(['let g:found_two = 1'], colordirstart . '/two.vim')
318 call writefile(['let g:found_three = 1'], colordiropt . '/three.vim')
319 exe 'set rtp=' . &packpath . '/runtime'
320
321 let li=[]
322 call feedkeys(":colorscheme " . repeat("\<Tab>", 1) . "')\<C-B>call add(li, '\<CR>", 't')
323 call feedkeys(":colorscheme " . repeat("\<Tab>", 2) . "')\<C-B>call add(li, '\<CR>", 't')
324 call feedkeys(":colorscheme " . repeat("\<Tab>", 3) . "')\<C-B>call add(li, '\<CR>", 't')
325 call feedkeys(":colorscheme " . repeat("\<Tab>", 4) . "')\<C-B>call add(li, '\<CR>", 'tx')
326 call assert_equal("colorscheme one", li[0])
327 call assert_equal("colorscheme three", li[1])
328 call assert_equal("colorscheme two", li[2])
329 call assert_equal("colorscheme ", li[3])
330endfunc
331
Bram Moolenaar8dcf2592016-03-12 22:47:14 +0100332func Test_runtime()
333 let rundir = &packpath . '/runtime/extra'
334 let startdir = &packpath . '/pack/mine/start/foo/extra'
335 let optdir = &packpath . '/pack/mine/opt/bar/extra'
336 call mkdir(rundir, 'p')
337 call mkdir(startdir, 'p')
338 call mkdir(optdir, 'p')
339 call writefile(['let g:sequence .= "run"'], rundir . '/bar.vim')
340 call writefile(['let g:sequence .= "start"'], startdir . '/bar.vim')
341 call writefile(['let g:sequence .= "foostart"'], startdir . '/foo.vim')
342 call writefile(['let g:sequence .= "opt"'], optdir . '/bar.vim')
343 call writefile(['let g:sequence .= "xxxopt"'], optdir . '/xxx.vim')
344 exe 'set rtp=' . &packpath . '/runtime'
345
346 let g:sequence = ''
347 runtime extra/bar.vim
348 call assert_equal('run', g:sequence)
349 let g:sequence = ''
zeertzjq008c9152023-08-17 23:08:53 +0200350 runtime NoSuchFile extra/bar.vim
351 call assert_equal('run', g:sequence)
352
353 let g:sequence = ''
Bram Moolenaar8dcf2592016-03-12 22:47:14 +0100354 runtime START extra/bar.vim
355 call assert_equal('start', g:sequence)
356 let g:sequence = ''
zeertzjq008c9152023-08-17 23:08:53 +0200357 runtime START NoSuchFile extra/bar.vim extra/foo.vim
358 call assert_equal('start', g:sequence)
359 let g:sequence = ''
360 runtime START NoSuchFile extra/foo.vim extra/bar.vim
361 call assert_equal('foostart', g:sequence)
362 let g:sequence = ''
363 runtime! START NoSuchFile extra/bar.vim extra/foo.vim
364 call assert_equal('startfoostart', g:sequence)
365
366 let g:sequence = ''
Bram Moolenaar8dcf2592016-03-12 22:47:14 +0100367 runtime OPT extra/bar.vim
368 call assert_equal('opt', g:sequence)
369 let g:sequence = ''
zeertzjq008c9152023-08-17 23:08:53 +0200370 runtime OPT NoSuchFile extra/bar.vim extra/xxx.vim
371 call assert_equal('opt', g:sequence)
372 let g:sequence = ''
373 runtime OPT NoSuchFile extra/xxx.vim extra/bar.vim
374 call assert_equal('xxxopt', g:sequence)
375 let g:sequence = ''
376 runtime! OPT NoSuchFile extra/bar.vim extra/xxx.vim
377 call assert_equal('optxxxopt', g:sequence)
378
379 let g:sequence = ''
Bram Moolenaar8dcf2592016-03-12 22:47:14 +0100380 runtime PACK extra/bar.vim
381 call assert_equal('start', g:sequence)
382 let g:sequence = ''
383 runtime! PACK extra/bar.vim
384 call assert_equal('startopt', g:sequence)
385 let g:sequence = ''
386 runtime PACK extra/xxx.vim
387 call assert_equal('xxxopt', g:sequence)
zeertzjq008c9152023-08-17 23:08:53 +0200388 let g:sequence = ''
389 runtime PACK extra/xxx.vim extra/foo.vim extra/bar.vim
390 call assert_equal('foostart', g:sequence)
391 let g:sequence = ''
392 runtime! PACK extra/bar.vim extra/xxx.vim extra/foo.vim
393 call assert_equal('startfoostartoptxxxopt', g:sequence)
Bram Moolenaar8dcf2592016-03-12 22:47:14 +0100394
395 let g:sequence = ''
396 runtime ALL extra/bar.vim
397 call assert_equal('run', g:sequence)
398 let g:sequence = ''
399 runtime ALL extra/foo.vim
400 call assert_equal('foostart', g:sequence)
401 let g:sequence = ''
402 runtime! ALL extra/xxx.vim
403 call assert_equal('xxxopt', g:sequence)
404 let g:sequence = ''
405 runtime! ALL extra/bar.vim
406 call assert_equal('runstartopt', g:sequence)
zeertzjq008c9152023-08-17 23:08:53 +0200407 let g:sequence = ''
408 runtime ALL extra/xxx.vim extra/foo.vim extra/bar.vim
409 call assert_equal('run', g:sequence)
410 let g:sequence = ''
411 runtime! ALL extra/bar.vim extra/xxx.vim extra/foo.vim
412 call assert_equal('runstartfoostartoptxxxopt', g:sequence)
Bram Moolenaar8dcf2592016-03-12 22:47:14 +0100413endfunc
Bram Moolenaar5d98dc22020-01-29 21:57:34 +0100414
zeertzjq3770f4c2023-01-22 18:38:51 +0000415func Test_runtime_completion()
zeertzjq5c8771b2023-01-24 12:34:03 +0000416 let rundir = &packpath . '/runtime/Aextra'
417 let startdir = &packpath . '/pack/mine/start/foo/Aextra'
418 let optdir = &packpath . '/pack/mine/opt/bar/Aextra'
419 call mkdir(rundir . '/Arunbaz', 'p')
420 call mkdir(startdir . '/Astartbaz', 'p')
421 call mkdir(optdir . '/Aoptbaz', 'p')
422 call writefile([], rundir . '/../Arunfoo.vim')
423 call writefile([], rundir . '/Arunbar.vim')
424 call writefile([], rundir . '/Aunrelated')
425 call writefile([], rundir . '/../Aunrelated')
426 call writefile([], startdir . '/../Astartfoo.vim')
427 call writefile([], startdir . '/Astartbar.vim')
428 call writefile([], startdir . '/Aunrelated')
429 call writefile([], startdir . '/../Aunrelated')
430 call writefile([], optdir . '/../Aoptfoo.vim')
431 call writefile([], optdir . '/Aoptbar.vim')
432 call writefile([], optdir . '/Aunrelated')
433 call writefile([], optdir . '/../Aunrelated')
zeertzjq3770f4c2023-01-22 18:38:51 +0000434 exe 'set rtp=' . &packpath . '/runtime'
435
436 func Check_runtime_completion(arg, arg1, res)
437 call feedkeys(':runtime ' .. a:arg .. "\<C-A>\<C-B>\"\<CR>", 'xt')
438 call assert_equal('"runtime ' .. a:arg1 .. join(a:res), @:)
439 call assert_equal(a:res, getcompletion(a:arg, 'runtime'))
zeertzjq3770f4c2023-01-22 18:38:51 +0000440 endfunc
441
442 call Check_runtime_completion('', '',
zeertzjq5c8771b2023-01-24 12:34:03 +0000443 \ ['Aextra/', 'Arunfoo.vim', 'START', 'OPT', 'PACK', 'ALL'])
444 call Check_runtime_completion('S', '',
445 \ ['START'])
446 call Check_runtime_completion('O', '',
447 \ ['OPT'])
448 call Check_runtime_completion('P', '',
449 \ ['PACK'])
450 call Check_runtime_completion('A', '',
451 \ ['Aextra/', 'Arunfoo.vim', 'ALL'])
452 call Check_runtime_completion('Aextra/', '',
453 \ ['Aextra/Arunbar.vim', 'Aextra/Arunbaz/'])
zeertzjq3770f4c2023-01-22 18:38:51 +0000454
455 call Check_runtime_completion('START ', 'START ',
zeertzjq5c8771b2023-01-24 12:34:03 +0000456 \ ['Aextra/', 'Astartfoo.vim'])
457 call Check_runtime_completion('START A', 'START ',
458 \ ['Aextra/', 'Astartfoo.vim'])
459 call Check_runtime_completion('START Aextra/', 'START ',
460 \ ['Aextra/Astartbar.vim', 'Aextra/Astartbaz/'])
zeertzjq3770f4c2023-01-22 18:38:51 +0000461
462 call Check_runtime_completion('OPT ', 'OPT ',
zeertzjq5c8771b2023-01-24 12:34:03 +0000463 \ ['Aextra/', 'Aoptfoo.vim'])
464 call Check_runtime_completion('OPT A', 'OPT ',
465 \ ['Aextra/', 'Aoptfoo.vim'])
466 call Check_runtime_completion('OPT Aextra/', 'OPT ',
467 \ ['Aextra/Aoptbar.vim', 'Aextra/Aoptbaz/'])
zeertzjq3770f4c2023-01-22 18:38:51 +0000468
469 call Check_runtime_completion('PACK ', 'PACK ',
zeertzjq5c8771b2023-01-24 12:34:03 +0000470 \ ['Aextra/', 'Aoptfoo.vim', 'Astartfoo.vim'])
471 call Check_runtime_completion('PACK A', 'PACK ',
472 \ ['Aextra/', 'Aoptfoo.vim', 'Astartfoo.vim'])
473 call Check_runtime_completion('PACK Aextra/', 'PACK ',
474 \ ['Aextra/Aoptbar.vim', 'Aextra/Aoptbaz/',
475 \ 'Aextra/Astartbar.vim', 'Aextra/Astartbaz/'])
zeertzjq3770f4c2023-01-22 18:38:51 +0000476
477 call Check_runtime_completion('ALL ', 'ALL ',
zeertzjq5c8771b2023-01-24 12:34:03 +0000478 \ ['Aextra/', 'Aoptfoo.vim', 'Arunfoo.vim', 'Astartfoo.vim'])
479 call Check_runtime_completion('ALL A', 'ALL ',
480 \ ['Aextra/', 'Aoptfoo.vim', 'Arunfoo.vim', 'Astartfoo.vim'])
481 call Check_runtime_completion('ALL Aextra/', 'ALL ',
482 \ ['Aextra/Aoptbar.vim', 'Aextra/Aoptbaz/',
483 \ 'Aextra/Arunbar.vim', 'Aextra/Arunbaz/',
484 \ 'Aextra/Astartbar.vim', 'Aextra/Astartbaz/'])
zeertzjq3770f4c2023-01-22 18:38:51 +0000485
486 delfunc Check_runtime_completion
487endfunc
488
Bram Moolenaar5d98dc22020-01-29 21:57:34 +0100489" vim: shiftwidth=2 sts=2 expandtab