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