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_runtime() 139 let rundir = &packpath . '/runtime/extra' 140 let startdir = &packpath . '/pack/mine/start/foo/extra' 141 let optdir = &packpath . '/pack/mine/opt/bar/extra' 142 call mkdir(rundir, 'p') 143 call mkdir(startdir, 'p') 144 call mkdir(optdir, 'p') 145 call writefile(['let g:sequence .= "run"'], rundir . '/bar.vim') 146 call writefile(['let g:sequence .= "start"'], startdir . '/bar.vim') 147 call writefile(['let g:sequence .= "foostart"'], startdir . '/foo.vim') 148 call writefile(['let g:sequence .= "opt"'], optdir . '/bar.vim') 149 call writefile(['let g:sequence .= "xxxopt"'], optdir . '/xxx.vim') 150 exe 'set rtp=' . &packpath . '/runtime' 151 152 let g:sequence = '' 153 runtime extra/bar.vim 154 call assert_equal('run', g:sequence) 155 let g:sequence = '' 156 runtime START extra/bar.vim 157 call assert_equal('start', g:sequence) 158 let g:sequence = '' 159 runtime OPT extra/bar.vim 160 call assert_equal('opt', g:sequence) 161 let g:sequence = '' 162 runtime PACK extra/bar.vim 163 call assert_equal('start', g:sequence) 164 let g:sequence = '' 165 runtime! PACK extra/bar.vim 166 call assert_equal('startopt', g:sequence) 167 let g:sequence = '' 168 runtime PACK extra/xxx.vim 169 call assert_equal('xxxopt', g:sequence) 170 171 let g:sequence = '' 172 runtime ALL extra/bar.vim 173 call assert_equal('run', g:sequence) 174 let g:sequence = '' 175 runtime ALL extra/foo.vim 176 call assert_equal('foostart', g:sequence) 177 let g:sequence = '' 178 runtime! ALL extra/xxx.vim 179 call assert_equal('xxxopt', g:sequence) 180 let g:sequence = '' 181 runtime! ALL extra/bar.vim 182 call assert_equal('runstartopt', g:sequence) 183endfunc 184