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 let plugindir = &packpath . '/pack/mine/start/foo/plugin' 91 call mkdir(plugindir, 'p') 92 call writefile(['let g:plugin_foo_number = 1234'], plugindir . '/bar.vim') 93 packloadall 94 call assert_equal(1234, g:plugin_foo_number) 95 96 " only works once 97 call writefile(['let g:plugin_bar_number = 4321'], plugindir . '/bar2.vim') 98 packloadall 99 call assert_false(exists('g:plugin_bar_number')) 100 101 " works when ! used 102 packloadall! 103 call assert_equal(4321, g:plugin_bar_number) 104endfunc 105 106func Test_helptags() 107 let docdir1 = &packpath . '/pack/mine/start/foo/doc' 108 let docdir2 = &packpath . '/pack/mine/start/bar/doc' 109 call mkdir(docdir1, 'p') 110 call mkdir(docdir2, 'p') 111 call writefile(['look here: *look-here*'], docdir1 . '/bar.txt') 112 call writefile(['look away: *look-away*'], docdir2 . '/foo.txt') 113 exe 'set rtp=' . &packpath . '/pack/mine/start/foo,' . &packpath . '/pack/mine/start/bar' 114 115 helptags ALL 116 117 let tags1 = readfile(docdir1 . '/tags') 118 call assert_true(tags1[0] =~ 'look-here') 119 let tags2 = readfile(docdir2 . '/tags') 120 call assert_true(tags2[0] =~ 'look-away') 121endfunc 122 123func Test_colorscheme() 124 let colordirrun = &packpath . '/runtime/colors' 125 let colordirstart = &packpath . '/pack/mine/start/foo/colors' 126 let colordiropt = &packpath . '/pack/mine/opt/bar/colors' 127 call mkdir(colordirrun, 'p') 128 call mkdir(colordirstart, 'p') 129 call mkdir(colordiropt, 'p') 130 call writefile(['let g:found_one = 1'], colordirrun . '/one.vim') 131 call writefile(['let g:found_two = 1'], colordirstart . '/two.vim') 132 call writefile(['let g:found_three = 1'], colordiropt . '/three.vim') 133 exe 'set rtp=' . &packpath . '/runtime' 134 135 colorscheme one 136 call assert_equal(1, g:found_one) 137 colorscheme two 138 call assert_equal(1, g:found_two) 139 colorscheme three 140 call assert_equal(1, g:found_three) 141endfunc 142 143func Test_colorscheme_completion() 144 let colordirrun = &packpath . '/runtime/colors' 145 let colordirstart = &packpath . '/pack/mine/start/foo/colors' 146 let colordiropt = &packpath . '/pack/mine/opt/bar/colors' 147 call mkdir(colordirrun, 'p') 148 call mkdir(colordirstart, 'p') 149 call mkdir(colordiropt, 'p') 150 call writefile(['let g:found_one = 1'], colordirrun . '/one.vim') 151 call writefile(['let g:found_two = 1'], colordirstart . '/two.vim') 152 call writefile(['let g:found_three = 1'], colordiropt . '/three.vim') 153 exe 'set rtp=' . &packpath . '/runtime' 154 155 let li=[] 156 call feedkeys(":colorscheme " . repeat("\<Tab>", 1) . "')\<C-B>call add(li, '\<CR>", 't') 157 call feedkeys(":colorscheme " . repeat("\<Tab>", 2) . "')\<C-B>call add(li, '\<CR>", 't') 158 call feedkeys(":colorscheme " . repeat("\<Tab>", 3) . "')\<C-B>call add(li, '\<CR>", 't') 159 call feedkeys(":colorscheme " . repeat("\<Tab>", 4) . "')\<C-B>call add(li, '\<CR>", 'tx') 160 call assert_equal("colorscheme one", li[0]) 161 call assert_equal("colorscheme three", li[1]) 162 call assert_equal("colorscheme two", li[2]) 163 call assert_equal("colorscheme ", li[3]) 164endfunc 165 166func Test_runtime() 167 let rundir = &packpath . '/runtime/extra' 168 let startdir = &packpath . '/pack/mine/start/foo/extra' 169 let optdir = &packpath . '/pack/mine/opt/bar/extra' 170 call mkdir(rundir, 'p') 171 call mkdir(startdir, 'p') 172 call mkdir(optdir, 'p') 173 call writefile(['let g:sequence .= "run"'], rundir . '/bar.vim') 174 call writefile(['let g:sequence .= "start"'], startdir . '/bar.vim') 175 call writefile(['let g:sequence .= "foostart"'], startdir . '/foo.vim') 176 call writefile(['let g:sequence .= "opt"'], optdir . '/bar.vim') 177 call writefile(['let g:sequence .= "xxxopt"'], optdir . '/xxx.vim') 178 exe 'set rtp=' . &packpath . '/runtime' 179 180 let g:sequence = '' 181 runtime extra/bar.vim 182 call assert_equal('run', g:sequence) 183 let g:sequence = '' 184 runtime START extra/bar.vim 185 call assert_equal('start', g:sequence) 186 let g:sequence = '' 187 runtime OPT extra/bar.vim 188 call assert_equal('opt', g:sequence) 189 let g:sequence = '' 190 runtime PACK extra/bar.vim 191 call assert_equal('start', g:sequence) 192 let g:sequence = '' 193 runtime! PACK extra/bar.vim 194 call assert_equal('startopt', g:sequence) 195 let g:sequence = '' 196 runtime PACK extra/xxx.vim 197 call assert_equal('xxxopt', g:sequence) 198 199 let g:sequence = '' 200 runtime ALL extra/bar.vim 201 call assert_equal('run', g:sequence) 202 let g:sequence = '' 203 runtime ALL extra/foo.vim 204 call assert_equal('foostart', g:sequence) 205 let g:sequence = '' 206 runtime! ALL extra/xxx.vim 207 call assert_equal('xxxopt', g:sequence) 208 let g:sequence = '' 209 runtime! ALL extra/bar.vim 210 call assert_equal('runstartopt', g:sequence) 211endfunc 212