blob: 3ca8375fc903cfee266c1856ba4b402114334bbf [file] [log] [blame]
Bram Moolenaarf3654822016-03-04 22:12:23 +01001" Tests for 'packpath' and :packadd
Bram Moolenaar863c1a92016-03-03 15:47:06 +01002
Bram Moolenaar91715872016-03-03 17:13:03 +01003func 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
Bram Moolenaarf3654822016-03-04 22:12:23 +010013func Test_packadd()
Bram Moolenaar91715872016-03-03 17:13:03 +010014 call mkdir(s:plugdir . '/plugin', 'p')
15 call mkdir(s:plugdir . '/ftdetect', 'p')
16 set rtp&
17 let rtp = &rtp
Bram Moolenaar863c1a92016-03-03 15:47:06 +010018 filetype on
Bram Moolenaar863c1a92016-03-03 15:47:06 +010019
Bram Moolenaar91715872016-03-03 17:13:03 +010020 exe 'split ' . s:plugdir . '/plugin/test.vim'
21 call setline(1, 'let g:plugin_works = 42')
22 wq
Bram Moolenaar863c1a92016-03-03 15:47:06 +010023
Bram Moolenaar91715872016-03-03 17:13:03 +010024 exe 'split ' . s:plugdir . '/ftdetect/test.vim'
25 call setline(1, 'let g:ftdetect_works = 17')
26 wq
27
Bram Moolenaarf3654822016-03-04 22:12:23 +010028 packadd mytest
Bram Moolenaar91715872016-03-03 17:13:03 +010029
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\($\|,\)')
Bram Moolenaarbe82c252016-03-06 14:44:08 +010034
35 " Check exception
36 call assert_fails("packadd directorynotfound", 'E919:')
37 call assert_fails("packadd", 'E471:')
Bram Moolenaar91715872016-03-03 17:13:03 +010038endfunc
39
Bram Moolenaarf3654822016-03-04 22:12:23 +010040func Test_packadd_noload()
41 call mkdir(s:plugdir . '/plugin', 'p')
Bram Moolenaar91715872016-03-03 17:13:03 +010042 call mkdir(s:plugdir . '/syntax', 'p')
43 set rtp&
44 let rtp = &rtp
Bram Moolenaarf3654822016-03-04 22:12:23 +010045
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
Bram Moolenaar91715872016-03-03 17:13:03 +010053 call assert_true(len(&rtp) > len(rtp))
54 call assert_true(&rtp =~ 'testdir/Xdir/pack/mine/opt/mytest\($\|,\)')
Bram Moolenaarf3654822016-03-04 22:12:23 +010055 call assert_equal(0, g:plugin_works)
Bram Moolenaar91715872016-03-03 17:13:03 +010056
57 " check the path is not added twice
58 let new_rtp = &rtp
Bram Moolenaarf3654822016-03-04 22:12:23 +010059 packadd! mytest
Bram Moolenaar91715872016-03-03 17:13:03 +010060 call assert_equal(new_rtp, &rtp)
Bram Moolenaar863c1a92016-03-03 15:47:06 +010061endfunc
Bram Moolenaar35ca0e72016-03-05 17:41:49 +010062
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
Bram Moolenaar2d8f56a2016-03-12 20:34:27 +010083
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
Bram Moolenaar6bef5302016-03-12 21:28:26 +0100100
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
Bram Moolenaar7f8989d2016-03-12 22:11:39 +0100117
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