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