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