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 exec "silent !ln -s" real_dir top2_dir 79 let &rtp = top2_dir . ',' . top2_dir . '/after' 80 let &packpath = &rtp 81 82 let s:plugdir = top2_dir . '/pack/mine/opt/mytest' 83 call mkdir(s:plugdir . '/plugin', 'p') 84 85 exe 'split ' . s:plugdir . '/plugin/test.vim' 86 call setline(1, 'let g:plugin_works = 44') 87 wq 88 let g:plugin_works = 0 89 90 packadd mytest 91 92 " Must have been inserted in the middle, not at the end 93 call assert_true(&rtp =~ '/pack/mine/opt/mytest,') 94 call assert_equal(44, g:plugin_works) 95 96 " No change when doing it again. 97 let rtp_before = &rtp 98 packadd mytest 99 call assert_equal(rtp_before, &rtp) 100 101 set rtp& 102 let rtp = &rtp 103 exec "silent !rm" top2_dir 104endfunc 105 106" Check command-line completion for 'packadd' 107func Test_packadd_completion() 108 let optdir1 = &packpath . '/pack/mine/opt' 109 let optdir2 = &packpath . '/pack/candidate/opt' 110 111 call mkdir(optdir1 . '/pluginA', 'p') 112 call mkdir(optdir1 . '/pluginC', 'p') 113 call mkdir(optdir2 . '/pluginB', 'p') 114 call mkdir(optdir2 . '/pluginC', 'p') 115 116 let li = [] 117 call feedkeys(":packadd \<Tab>')\<C-B>call add(li, '\<CR>", 't') 118 call feedkeys(":packadd " . repeat("\<Tab>", 2) . "')\<C-B>call add(li, '\<CR>", 't') 119 call feedkeys(":packadd " . repeat("\<Tab>", 3) . "')\<C-B>call add(li, '\<CR>", 't') 120 call feedkeys(":packadd " . repeat("\<Tab>", 4) . "')\<C-B>call add(li, '\<CR>", 'tx') 121 call assert_equal("packadd pluginA", li[0]) 122 call assert_equal("packadd pluginB", li[1]) 123 call assert_equal("packadd pluginC", li[2]) 124 call assert_equal("packadd ", li[3]) 125endfunc 126 127func Test_packloadall() 128 " plugin foo with an autoload directory 129 let fooplugindir = &packpath . '/pack/mine/start/foo/plugin' 130 call mkdir(fooplugindir, 'p') 131 call writefile(['let g:plugin_foo_number = 1234', 132 \ 'let g:plugin_foo_auto = bbb#value', 133 \ 'let g:plugin_extra_auto = extra#value'], fooplugindir . '/bar.vim') 134 let fooautodir = &packpath . '/pack/mine/start/foo/autoload' 135 call mkdir(fooautodir, 'p') 136 call writefile(['let bar#value = 77'], fooautodir . '/bar.vim') 137 138 " plugin aaa with an autoload directory 139 let aaaplugindir = &packpath . '/pack/mine/start/aaa/plugin' 140 call mkdir(aaaplugindir, 'p') 141 call writefile(['let g:plugin_aaa_number = 333', 142 \ 'let g:plugin_aaa_auto = bar#value'], aaaplugindir . '/bbb.vim') 143 let aaaautodir = &packpath . '/pack/mine/start/aaa/autoload' 144 call mkdir(aaaautodir, 'p') 145 call writefile(['let bbb#value = 55'], aaaautodir . '/bbb.vim') 146 147 " plugin extra with only an autoload directory 148 let extraautodir = &packpath . '/pack/mine/start/extra/autoload' 149 call mkdir(extraautodir, 'p') 150 call writefile(['let extra#value = 99'], extraautodir . '/extra.vim') 151 152 packloadall 153 call assert_equal(1234, g:plugin_foo_number) 154 call assert_equal(55, g:plugin_foo_auto) 155 call assert_equal(99, g:plugin_extra_auto) 156 call assert_equal(333, g:plugin_aaa_number) 157 call assert_equal(77, g:plugin_aaa_auto) 158 159 " only works once 160 call writefile(['let g:plugin_bar_number = 4321'], fooplugindir . '/bar2.vim') 161 packloadall 162 call assert_false(exists('g:plugin_bar_number')) 163 164 " works when ! used 165 packloadall! 166 call assert_equal(4321, g:plugin_bar_number) 167endfunc 168 169func Test_helptags() 170 let docdir1 = &packpath . '/pack/mine/start/foo/doc' 171 let docdir2 = &packpath . '/pack/mine/start/bar/doc' 172 call mkdir(docdir1, 'p') 173 call mkdir(docdir2, 'p') 174 call writefile(['look here: *look-here*'], docdir1 . '/bar.txt') 175 call writefile(['look away: *look-away*'], docdir2 . '/foo.txt') 176 exe 'set rtp=' . &packpath . '/pack/mine/start/foo,' . &packpath . '/pack/mine/start/bar' 177 178 helptags ALL 179 180 let tags1 = readfile(docdir1 . '/tags') 181 call assert_true(tags1[0] =~ 'look-here') 182 let tags2 = readfile(docdir2 . '/tags') 183 call assert_true(tags2[0] =~ 'look-away') 184endfunc 185 186func Test_colorscheme() 187 let colordirrun = &packpath . '/runtime/colors' 188 let colordirstart = &packpath . '/pack/mine/start/foo/colors' 189 let colordiropt = &packpath . '/pack/mine/opt/bar/colors' 190 call mkdir(colordirrun, 'p') 191 call mkdir(colordirstart, 'p') 192 call mkdir(colordiropt, 'p') 193 call writefile(['let g:found_one = 1'], colordirrun . '/one.vim') 194 call writefile(['let g:found_two = 1'], colordirstart . '/two.vim') 195 call writefile(['let g:found_three = 1'], colordiropt . '/three.vim') 196 exe 'set rtp=' . &packpath . '/runtime' 197 198 colorscheme one 199 call assert_equal(1, g:found_one) 200 colorscheme two 201 call assert_equal(1, g:found_two) 202 colorscheme three 203 call assert_equal(1, g:found_three) 204endfunc 205 206func Test_colorscheme_completion() 207 let colordirrun = &packpath . '/runtime/colors' 208 let colordirstart = &packpath . '/pack/mine/start/foo/colors' 209 let colordiropt = &packpath . '/pack/mine/opt/bar/colors' 210 call mkdir(colordirrun, 'p') 211 call mkdir(colordirstart, 'p') 212 call mkdir(colordiropt, 'p') 213 call writefile(['let g:found_one = 1'], colordirrun . '/one.vim') 214 call writefile(['let g:found_two = 1'], colordirstart . '/two.vim') 215 call writefile(['let g:found_three = 1'], colordiropt . '/three.vim') 216 exe 'set rtp=' . &packpath . '/runtime' 217 218 let li=[] 219 call feedkeys(":colorscheme " . repeat("\<Tab>", 1) . "')\<C-B>call add(li, '\<CR>", 't') 220 call feedkeys(":colorscheme " . repeat("\<Tab>", 2) . "')\<C-B>call add(li, '\<CR>", 't') 221 call feedkeys(":colorscheme " . repeat("\<Tab>", 3) . "')\<C-B>call add(li, '\<CR>", 't') 222 call feedkeys(":colorscheme " . repeat("\<Tab>", 4) . "')\<C-B>call add(li, '\<CR>", 'tx') 223 call assert_equal("colorscheme one", li[0]) 224 call assert_equal("colorscheme three", li[1]) 225 call assert_equal("colorscheme two", li[2]) 226 call assert_equal("colorscheme ", li[3]) 227endfunc 228 229func Test_runtime() 230 let rundir = &packpath . '/runtime/extra' 231 let startdir = &packpath . '/pack/mine/start/foo/extra' 232 let optdir = &packpath . '/pack/mine/opt/bar/extra' 233 call mkdir(rundir, 'p') 234 call mkdir(startdir, 'p') 235 call mkdir(optdir, 'p') 236 call writefile(['let g:sequence .= "run"'], rundir . '/bar.vim') 237 call writefile(['let g:sequence .= "start"'], startdir . '/bar.vim') 238 call writefile(['let g:sequence .= "foostart"'], startdir . '/foo.vim') 239 call writefile(['let g:sequence .= "opt"'], optdir . '/bar.vim') 240 call writefile(['let g:sequence .= "xxxopt"'], optdir . '/xxx.vim') 241 exe 'set rtp=' . &packpath . '/runtime' 242 243 let g:sequence = '' 244 runtime extra/bar.vim 245 call assert_equal('run', g:sequence) 246 let g:sequence = '' 247 runtime START extra/bar.vim 248 call assert_equal('start', g:sequence) 249 let g:sequence = '' 250 runtime OPT extra/bar.vim 251 call assert_equal('opt', g:sequence) 252 let g:sequence = '' 253 runtime PACK extra/bar.vim 254 call assert_equal('start', g:sequence) 255 let g:sequence = '' 256 runtime! PACK extra/bar.vim 257 call assert_equal('startopt', g:sequence) 258 let g:sequence = '' 259 runtime PACK extra/xxx.vim 260 call assert_equal('xxxopt', g:sequence) 261 262 let g:sequence = '' 263 runtime ALL extra/bar.vim 264 call assert_equal('run', g:sequence) 265 let g:sequence = '' 266 runtime ALL extra/foo.vim 267 call assert_equal('foostart', g:sequence) 268 let g:sequence = '' 269 runtime! ALL extra/xxx.vim 270 call assert_equal('xxxopt', g:sequence) 271 let g:sequence = '' 272 runtime! ALL extra/bar.vim 273 call assert_equal('runstartopt', g:sequence) 274endfunc 275