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