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