1" Tests for 'packpath' and :packadd 2 3 4func SetUp() 5 let s:topdir = getcwd() . '/Xdir' 6 exe 'set packpath=' . s:topdir 7 let s:plugdir = s:topdir . '/pack/mine/opt/mytest' 8endfunc 9 10func TearDown() 11 call delete(s:topdir, 'rf') 12endfunc 13 14func Test_packadd() 15 call mkdir(s:plugdir . '/plugin/also', 'p') 16 call mkdir(s:plugdir . '/ftdetect', 'p') 17 call mkdir(s:plugdir . '/after', 'p') 18 set rtp& 19 let rtp = &rtp 20 filetype on 21 22 exe 'split ' . s:plugdir . '/plugin/test.vim' 23 call setline(1, 'let g:plugin_works = 42') 24 wq 25 26 exe 'split ' . s:plugdir . '/plugin/also/loaded.vim' 27 call setline(1, 'let g:plugin_also_works = 77') 28 wq 29 30 exe 'split ' . s:plugdir . '/ftdetect/test.vim' 31 call setline(1, 'let g:ftdetect_works = 17') 32 wq 33 34 packadd mytest 35 36 call assert_equal(42, g:plugin_works) 37 call assert_equal(77, g:plugin_also_works) 38 call assert_equal(17, g:ftdetect_works) 39 call assert_true(len(&rtp) > len(rtp)) 40 call assert_match('/testdir/Xdir/pack/mine/opt/mytest\($\|,\)', &rtp) 41 call assert_match('/testdir/Xdir/pack/mine/opt/mytest/after$', &rtp) 42 43 " NOTE: '/.../opt/myte' forwardly matches with '/.../opt/mytest' 44 call mkdir(fnamemodify(s:plugdir, ':h') . '/myte', 'p') 45 let rtp = &rtp 46 packadd myte 47 48 " Check the path of 'myte' is added 49 call assert_true(len(&rtp) > len(rtp)) 50 call assert_match('/testdir/Xdir/pack/mine/opt/myte\($\|,\)', &rtp) 51 52 " Check exception 53 call assert_fails("packadd directorynotfound", 'E919:') 54 call assert_fails("packadd", 'E471:') 55endfunc 56 57func Test_packadd_start() 58 let plugdir = s:topdir . '/pack/mine/start/other' 59 call mkdir(plugdir . '/plugin', 'p') 60 set rtp& 61 let rtp = &rtp 62 filetype on 63 64 exe 'split ' . plugdir . '/plugin/test.vim' 65 call setline(1, 'let g:plugin_works = 24') 66 wq 67 68 packadd other 69 70 call assert_equal(24, g:plugin_works) 71 call assert_true(len(&rtp) > len(rtp)) 72 call assert_match('/testdir/Xdir/pack/mine/start/other\($\|,\)', &rtp) 73endfunc 74 75func Test_packadd_noload() 76 call mkdir(s:plugdir . '/plugin', 'p') 77 call mkdir(s:plugdir . '/syntax', 'p') 78 set rtp& 79 let rtp = &rtp 80 81 exe 'split ' . s:plugdir . '/plugin/test.vim' 82 call setline(1, 'let g:plugin_works = 42') 83 wq 84 let g:plugin_works = 0 85 86 packadd! mytest 87 88 call assert_true(len(&rtp) > len(rtp)) 89 call assert_match('testdir/Xdir/pack/mine/opt/mytest\($\|,\)', &rtp) 90 call assert_equal(0, g:plugin_works) 91 92 " check the path is not added twice 93 let new_rtp = &rtp 94 packadd! mytest 95 call assert_equal(new_rtp, &rtp) 96endfunc 97 98func Test_packadd_symlink_dir() 99 if !has('unix') 100 return 101 endif 102 let top2_dir = s:topdir . '/Xdir2' 103 let real_dir = s:topdir . '/Xsym' 104 call mkdir(real_dir, 'p') 105 exec "silent !ln -s Xsym" top2_dir 106 let &rtp = top2_dir . ',' . top2_dir . '/after' 107 let &packpath = &rtp 108 109 let s:plugdir = top2_dir . '/pack/mine/opt/mytest' 110 call mkdir(s:plugdir . '/plugin', 'p') 111 112 exe 'split ' . s:plugdir . '/plugin/test.vim' 113 call setline(1, 'let g:plugin_works = 44') 114 wq 115 let g:plugin_works = 0 116 117 packadd mytest 118 119 " Must have been inserted in the middle, not at the end 120 call assert_match('/pack/mine/opt/mytest,', &rtp) 121 call assert_equal(44, g:plugin_works) 122 123 " No change when doing it again. 124 let rtp_before = &rtp 125 packadd mytest 126 call assert_equal(rtp_before, &rtp) 127 128 set rtp& 129 let rtp = &rtp 130 exec "silent !rm" top2_dir 131endfunc 132 133func Test_packadd_symlink_dir2() 134 if !has('unix') 135 return 136 endif 137 let top2_dir = s:topdir . '/Xdir2' 138 let real_dir = s:topdir . '/Xsym/pack' 139 call mkdir(top2_dir, 'p') 140 call mkdir(real_dir, 'p') 141 let &rtp = top2_dir . ',' . top2_dir . '/after' 142 let &packpath = &rtp 143 144 exec "silent !ln -s ../Xsym/pack" top2_dir . '/pack' 145 let s:plugdir = top2_dir . '/pack/mine/opt/mytest' 146 call mkdir(s:plugdir . '/plugin', 'p') 147 148 exe 'split ' . s:plugdir . '/plugin/test.vim' 149 call setline(1, 'let g:plugin_works = 48') 150 wq 151 let g:plugin_works = 0 152 153 packadd mytest 154 155 " Must have been inserted in the middle, not at the end 156 call assert_match('/Xdir2/pack/mine/opt/mytest,', &rtp) 157 call assert_equal(48, g:plugin_works) 158 159 " No change when doing it again. 160 let rtp_before = &rtp 161 packadd mytest 162 call assert_equal(rtp_before, &rtp) 163 164 set rtp& 165 let rtp = &rtp 166 exec "silent !rm" top2_dir . '/pack' 167 exec "silent !rmdir" top2_dir 168endfunc 169 170" Check command-line completion for 'packadd' 171func Test_packadd_completion() 172 let optdir1 = &packpath . '/pack/mine/opt' 173 let optdir2 = &packpath . '/pack/candidate/opt' 174 175 call mkdir(optdir1 . '/pluginA', 'p') 176 call mkdir(optdir1 . '/pluginC', 'p') 177 call mkdir(optdir2 . '/pluginB', 'p') 178 call mkdir(optdir2 . '/pluginC', 'p') 179 180 let li = [] 181 call feedkeys(":packadd \<Tab>')\<C-B>call add(li, '\<CR>", 't') 182 call feedkeys(":packadd " . repeat("\<Tab>", 2) . "')\<C-B>call add(li, '\<CR>", 't') 183 call feedkeys(":packadd " . repeat("\<Tab>", 3) . "')\<C-B>call add(li, '\<CR>", 't') 184 call feedkeys(":packadd " . repeat("\<Tab>", 4) . "')\<C-B>call add(li, '\<CR>", 'tx') 185 call assert_equal("packadd pluginA", li[0]) 186 call assert_equal("packadd pluginB", li[1]) 187 call assert_equal("packadd pluginC", li[2]) 188 call assert_equal("packadd ", li[3]) 189endfunc 190 191func Test_packloadall() 192 " plugin foo with an autoload directory 193 let fooplugindir = &packpath . '/pack/mine/start/foo/plugin' 194 call mkdir(fooplugindir, 'p') 195 call writefile(['let g:plugin_foo_number = 1234', 196 \ 'let g:plugin_foo_auto = bbb#value', 197 \ 'let g:plugin_extra_auto = extra#value'], fooplugindir . '/bar.vim') 198 let fooautodir = &packpath . '/pack/mine/start/foo/autoload' 199 call mkdir(fooautodir, 'p') 200 call writefile(['let bar#value = 77'], fooautodir . '/bar.vim') 201 202 " plugin aaa with an autoload directory 203 let aaaplugindir = &packpath . '/pack/mine/start/aaa/plugin' 204 call mkdir(aaaplugindir, 'p') 205 call writefile(['let g:plugin_aaa_number = 333', 206 \ 'let g:plugin_aaa_auto = bar#value'], aaaplugindir . '/bbb.vim') 207 let aaaautodir = &packpath . '/pack/mine/start/aaa/autoload' 208 call mkdir(aaaautodir, 'p') 209 call writefile(['let bbb#value = 55'], aaaautodir . '/bbb.vim') 210 211 " plugin extra with only an autoload directory 212 let extraautodir = &packpath . '/pack/mine/start/extra/autoload' 213 call mkdir(extraautodir, 'p') 214 call writefile(['let extra#value = 99'], extraautodir . '/extra.vim') 215 216 packloadall 217 call assert_equal(1234, g:plugin_foo_number) 218 call assert_equal(55, g:plugin_foo_auto) 219 call assert_equal(99, g:plugin_extra_auto) 220 call assert_equal(333, g:plugin_aaa_number) 221 call assert_equal(77, g:plugin_aaa_auto) 222 223 " only works once 224 call writefile(['let g:plugin_bar_number = 4321'], fooplugindir . '/bar2.vim') 225 packloadall 226 call assert_false(exists('g:plugin_bar_number')) 227 228 " works when ! used 229 packloadall! 230 call assert_equal(4321, g:plugin_bar_number) 231endfunc 232 233func Test_helptags() 234 let docdir1 = &packpath . '/pack/mine/start/foo/doc' 235 let docdir2 = &packpath . '/pack/mine/start/bar/doc' 236 call mkdir(docdir1, 'p') 237 call mkdir(docdir2, 'p') 238 call writefile(['look here: *look-here*'], docdir1 . '/bar.txt') 239 call writefile(['look away: *look-away*'], docdir2 . '/foo.txt') 240 exe 'set rtp=' . &packpath . '/pack/mine/start/foo,' . &packpath . '/pack/mine/start/bar' 241 242 helptags ALL 243 244 let tags1 = readfile(docdir1 . '/tags') 245 call assert_match('look-here', tags1[0]) 246 let tags2 = readfile(docdir2 . '/tags') 247 call assert_match('look-away', tags2[0]) 248endfunc 249 250func Test_colorscheme() 251 let colordirrun = &packpath . '/runtime/colors' 252 let colordirstart = &packpath . '/pack/mine/start/foo/colors' 253 let colordiropt = &packpath . '/pack/mine/opt/bar/colors' 254 call mkdir(colordirrun, 'p') 255 call mkdir(colordirstart, 'p') 256 call mkdir(colordiropt, 'p') 257 call writefile(['let g:found_one = 1'], colordirrun . '/one.vim') 258 call writefile(['let g:found_two = 1'], colordirstart . '/two.vim') 259 call writefile(['let g:found_three = 1'], colordiropt . '/three.vim') 260 exe 'set rtp=' . &packpath . '/runtime' 261 262 colorscheme one 263 call assert_equal(1, g:found_one) 264 colorscheme two 265 call assert_equal(1, g:found_two) 266 colorscheme three 267 call assert_equal(1, g:found_three) 268endfunc 269 270func Test_colorscheme_completion() 271 let colordirrun = &packpath . '/runtime/colors' 272 let colordirstart = &packpath . '/pack/mine/start/foo/colors' 273 let colordiropt = &packpath . '/pack/mine/opt/bar/colors' 274 call mkdir(colordirrun, 'p') 275 call mkdir(colordirstart, 'p') 276 call mkdir(colordiropt, 'p') 277 call writefile(['let g:found_one = 1'], colordirrun . '/one.vim') 278 call writefile(['let g:found_two = 1'], colordirstart . '/two.vim') 279 call writefile(['let g:found_three = 1'], colordiropt . '/three.vim') 280 exe 'set rtp=' . &packpath . '/runtime' 281 282 let li=[] 283 call feedkeys(":colorscheme " . repeat("\<Tab>", 1) . "')\<C-B>call add(li, '\<CR>", 't') 284 call feedkeys(":colorscheme " . repeat("\<Tab>", 2) . "')\<C-B>call add(li, '\<CR>", 't') 285 call feedkeys(":colorscheme " . repeat("\<Tab>", 3) . "')\<C-B>call add(li, '\<CR>", 't') 286 call feedkeys(":colorscheme " . repeat("\<Tab>", 4) . "')\<C-B>call add(li, '\<CR>", 'tx') 287 call assert_equal("colorscheme one", li[0]) 288 call assert_equal("colorscheme three", li[1]) 289 call assert_equal("colorscheme two", li[2]) 290 call assert_equal("colorscheme ", li[3]) 291endfunc 292 293func Test_runtime() 294 let rundir = &packpath . '/runtime/extra' 295 let startdir = &packpath . '/pack/mine/start/foo/extra' 296 let optdir = &packpath . '/pack/mine/opt/bar/extra' 297 call mkdir(rundir, 'p') 298 call mkdir(startdir, 'p') 299 call mkdir(optdir, 'p') 300 call writefile(['let g:sequence .= "run"'], rundir . '/bar.vim') 301 call writefile(['let g:sequence .= "start"'], startdir . '/bar.vim') 302 call writefile(['let g:sequence .= "foostart"'], startdir . '/foo.vim') 303 call writefile(['let g:sequence .= "opt"'], optdir . '/bar.vim') 304 call writefile(['let g:sequence .= "xxxopt"'], optdir . '/xxx.vim') 305 exe 'set rtp=' . &packpath . '/runtime' 306 307 let g:sequence = '' 308 runtime extra/bar.vim 309 call assert_equal('run', g:sequence) 310 let g:sequence = '' 311 runtime START extra/bar.vim 312 call assert_equal('start', g:sequence) 313 let g:sequence = '' 314 runtime OPT extra/bar.vim 315 call assert_equal('opt', g:sequence) 316 let g:sequence = '' 317 runtime PACK extra/bar.vim 318 call assert_equal('start', g:sequence) 319 let g:sequence = '' 320 runtime! PACK extra/bar.vim 321 call assert_equal('startopt', g:sequence) 322 let g:sequence = '' 323 runtime PACK extra/xxx.vim 324 call assert_equal('xxxopt', g:sequence) 325 326 let g:sequence = '' 327 runtime ALL extra/bar.vim 328 call assert_equal('run', g:sequence) 329 let g:sequence = '' 330 runtime ALL extra/foo.vim 331 call assert_equal('foostart', g:sequence) 332 let g:sequence = '' 333 runtime! ALL extra/xxx.vim 334 call assert_equal('xxxopt', g:sequence) 335 let g:sequence = '' 336 runtime! ALL extra/bar.vim 337 call assert_equal('runstartopt', g:sequence) 338endfunc 339