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