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