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\($\|,\)') 34endfunc 35 36func Test_packadd_noload() 37 call mkdir(s:plugdir . '/plugin', 'p') 38 call mkdir(s:plugdir . '/syntax', 'p') 39 set rtp& 40 let rtp = &rtp 41 42 exe 'split ' . s:plugdir . '/plugin/test.vim' 43 call setline(1, 'let g:plugin_works = 42') 44 wq 45 let g:plugin_works = 0 46 47 packadd! mytest 48 49 call assert_true(len(&rtp) > len(rtp)) 50 call assert_true(&rtp =~ 'testdir/Xdir/pack/mine/opt/mytest\($\|,\)') 51 call assert_equal(0, g:plugin_works) 52 53 " check the path is not added twice 54 let new_rtp = &rtp 55 packadd! mytest 56 call assert_equal(new_rtp, &rtp) 57endfunc 58 59" Check command-line completion for 'packadd' 60func Test_packadd_completion() 61 let optdir1 = &packpath . '/pack/mine/opt' 62 let optdir2 = &packpath . '/pack/candidate/opt' 63 64 call mkdir(optdir1 . '/pluginA', 'p') 65 call mkdir(optdir1 . '/pluginC', 'p') 66 call mkdir(optdir2 . '/pluginB', 'p') 67 call mkdir(optdir2 . '/pluginC', 'p') 68 69 let li = [] 70 call feedkeys(":packadd \<Tab>')\<C-B>call add(li, '\<CR>", 't') 71 call feedkeys(":packadd " . repeat("\<Tab>", 2) . "')\<C-B>call add(li, '\<CR>", 't') 72 call feedkeys(":packadd " . repeat("\<Tab>", 3) . "')\<C-B>call add(li, '\<CR>", 't') 73 call feedkeys(":packadd " . repeat("\<Tab>", 4) . "')\<C-B>call add(li, '\<CR>", 'tx') 74 call assert_equal("packadd pluginA", li[0]) 75 call assert_equal("packadd pluginB", li[1]) 76 call assert_equal("packadd pluginC", li[2]) 77 call assert_equal("packadd ", li[3]) 78endfunc 79