blob: aec80efd844053fb02027ade76ec8a6abdb8ed74 [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\($\|,\)')
34endfunc
35
Bram Moolenaarf3654822016-03-04 22:12:23 +010036func Test_packadd_noload()
37 call mkdir(s:plugdir . '/plugin', 'p')
Bram Moolenaar91715872016-03-03 17:13:03 +010038 call mkdir(s:plugdir . '/syntax', 'p')
39 set rtp&
40 let rtp = &rtp
Bram Moolenaarf3654822016-03-04 22:12:23 +010041
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
Bram Moolenaar91715872016-03-03 17:13:03 +010049 call assert_true(len(&rtp) > len(rtp))
50 call assert_true(&rtp =~ 'testdir/Xdir/pack/mine/opt/mytest\($\|,\)')
Bram Moolenaarf3654822016-03-04 22:12:23 +010051 call assert_equal(0, g:plugin_works)
Bram Moolenaar91715872016-03-03 17:13:03 +010052
53 " check the path is not added twice
54 let new_rtp = &rtp
Bram Moolenaarf3654822016-03-04 22:12:23 +010055 packadd! mytest
Bram Moolenaar91715872016-03-03 17:13:03 +010056 call assert_equal(new_rtp, &rtp)
Bram Moolenaar863c1a92016-03-03 15:47:06 +010057endfunc