diff options
Diffstat (limited to 'test/functional/legacy/packadd_spec.lua')
-rw-r--r-- | test/functional/legacy/packadd_spec.lua | 214 |
1 files changed, 178 insertions, 36 deletions
diff --git a/test/functional/legacy/packadd_spec.lua b/test/functional/legacy/packadd_spec.lua index b2ed39f288..609f825177 100644 --- a/test/functional/legacy/packadd_spec.lua +++ b/test/functional/legacy/packadd_spec.lua @@ -1,7 +1,7 @@ -- Tests for 'packpath' and :packadd local helpers = require('test.functional.helpers')(after_each) -local clear, source, execute = helpers.clear, helpers.source, helpers.execute +local clear, source, command = helpers.clear, helpers.source, helpers.command local call, eq, nvim = helpers.call, helpers.eq, helpers.meths local feed = helpers.feed @@ -14,10 +14,14 @@ describe('packadd', function() clear() source([=[ + func Escape(s) + return escape(a:s, '\~') + endfunc + func SetUp() - let s:topdir = expand('%:p:h') . '/Xdir' + let s:topdir = expand(getcwd() . '/Xdir') exe 'set packpath=' . s:topdir - let s:plugdir = s:topdir . '/pack/mine/opt/mytest' + let s:plugdir = expand(s:topdir . '/pack/mine/opt/mytest') endfunc func TearDown() @@ -25,17 +29,34 @@ describe('packadd', function() endfunc func Test_packadd() - call mkdir(s:plugdir . '/plugin', 'p') + if !exists('s:plugdir') + echomsg 'when running this test manually, call SetUp() first' + return + endif + + call mkdir(s:plugdir . '/plugin/also', 'p') call mkdir(s:plugdir . '/ftdetect', 'p') call mkdir(s:plugdir . '/after', 'p') set rtp& let rtp = &rtp filetype on + let rtp_entries = split(rtp, ',') + for entry in rtp_entries + if entry =~? '\<after\>' + let first_after_entry = entry + break + endif + endfor + exe 'split ' . s:plugdir . '/plugin/test.vim' call setline(1, 'let g:plugin_works = 42') wq + exe 'split ' . s:plugdir . '/plugin/also/loaded.vim' + call setline(1, 'let g:plugin_also_works = 77') + wq + exe 'split ' . s:plugdir . '/ftdetect/test.vim' call setline(1, 'let g:ftdetect_works = 17') wq @@ -43,16 +64,50 @@ describe('packadd', function() packadd mytest call assert_true(42, g:plugin_works) + call assert_equal(77, g:plugin_also_works) call assert_true(17, g:ftdetect_works) call assert_true(len(&rtp) > len(rtp)) - call assert_true(&rtp =~ (s:plugdir . '\($\|,\)')) - call assert_true(&rtp =~ (s:plugdir . '/after$')) + call assert_match(Escape(s:plugdir) . '\($\|,\)', &rtp) + + let new_after = match(&rtp, Escape(expand(s:plugdir . '/after') . ',')) + let forwarded = substitute(first_after_entry, '\\', '[/\\\\]', 'g') + let old_after = match(&rtp, ',' . escape(forwarded, '~') . '\>') + call assert_true(new_after > 0, 'rtp is ' . &rtp) + call assert_true(old_after > 0, 'match ' . forwarded . ' in ' . &rtp) + call assert_true(new_after < old_after, 'rtp is ' . &rtp) + + " NOTE: '/.../opt/myte' forwardly matches with '/.../opt/mytest' + call mkdir(fnamemodify(s:plugdir, ':h') . '/myte', 'p') + let rtp = &rtp + packadd myte + + " Check the path of 'myte' is added + call assert_true(len(&rtp) > len(rtp)) + call assert_match(Escape(s:plugdir) . '\($\|,\)', &rtp) " Check exception call assert_fails("packadd directorynotfound", 'E919:') call assert_fails("packadd", 'E471:') endfunc + func Test_packadd_start() + let plugdir = expand(s:topdir . '/pack/mine/start/other') + call mkdir(plugdir . '/plugin', 'p') + set rtp& + let rtp = &rtp + filetype on + + exe 'split ' . plugdir . '/plugin/test.vim' + call setline(1, 'let g:plugin_works = 24') + wq + + packadd other + + call assert_equal(24, g:plugin_works) + call assert_true(len(&rtp) > len(rtp)) + call assert_match(Escape(plugdir) . '\($\|,\)', &rtp) + endfunc + func Test_packadd_noload() call mkdir(s:plugdir . '/plugin', 'p') call mkdir(s:plugdir . '/syntax', 'p') @@ -67,7 +122,7 @@ describe('packadd', function() packadd! mytest call assert_true(len(&rtp) > len(rtp)) - call assert_true(&rtp =~ (s:plugdir . '\($\|,\)')) + call assert_match(Escape(s:plugdir) . '\($\|,\)', &rtp) call assert_equal(0, g:plugin_works) " check the path is not added twice @@ -76,6 +131,84 @@ describe('packadd', function() call assert_equal(new_rtp, &rtp) endfunc + func Test_packadd_symlink_dir() + let top2_dir = expand(s:topdir . '/Xdir2') + let real_dir = expand(s:topdir . '/Xsym') + call mkdir(real_dir, 'p') + if has('win32') + exec "silent! !mklink /d" top2_dir "Xsym" + else + exec "silent! !ln -s Xsym" top2_dir + endif + let &rtp = top2_dir . ',' . expand(top2_dir . '/after') + let &packpath = &rtp + + let s:plugdir = expand(top2_dir . '/pack/mine/opt/mytest') + call mkdir(s:plugdir . '/plugin', 'p') + + exe 'split ' . s:plugdir . '/plugin/test.vim' + call setline(1, 'let g:plugin_works = 44') + wq + let g:plugin_works = 0 + + packadd mytest + + " Must have been inserted in the middle, not at the end + call assert_match(Escape(expand('/pack/mine/opt/mytest').','), &rtp) + call assert_equal(44, g:plugin_works) + + " No change when doing it again. + let rtp_before = &rtp + packadd mytest + call assert_equal(rtp_before, &rtp) + + set rtp& + let rtp = &rtp + exec "silent !" (has('win32') ? "rd /q/s" : "rm") top2_dir + endfunc + + func Test_packadd_symlink_dir2() + let top2_dir = expand(s:topdir . '/Xdir2') + let real_dir = expand(s:topdir . '/Xsym/pack') + call mkdir(top2_dir, 'p') + call mkdir(real_dir, 'p') + let &rtp = top2_dir . ',' . top2_dir . '/after' + let &packpath = &rtp + + if has('win32') + exec "silent! !mklink /d" top2_dir "Xsym" + else + exec "silent !ln -s ../Xsym/pack" top2_dir . '/pack' + endif + let s:plugdir = expand(top2_dir . '/pack/mine/opt/mytest') + call mkdir(s:plugdir . '/plugin', 'p') + + exe 'split ' . s:plugdir . '/plugin/test.vim' + call setline(1, 'let g:plugin_works = 48') + wq + let g:plugin_works = 0 + + packadd mytest + + " Must have been inserted in the middle, not at the end + call assert_match(Escape(expand('/Xdir2/pack/mine/opt/mytest').','), &rtp) + call assert_equal(48, g:plugin_works) + + " No change when doing it again. + let rtp_before = &rtp + packadd mytest + call assert_equal(rtp_before, &rtp) + + set rtp& + let rtp = &rtp + if has('win32') + exec "silent !rd /q/s" top2_dir + else + exec "silent !rm" top2_dir . '/pack' + exec "silent !rmdir" top2_dir + endif + endfunc + func Test_packloadall() " plugin foo with an autoload directory let fooplugindir = &packpath . '/pack/mine/start/foo/plugin' @@ -130,10 +263,10 @@ describe('packadd', function() helptags ALL - let tags1 = readfile(docdir1 . '/tags') - call assert_true(tags1[0] =~ 'look-here') - let tags2 = readfile(docdir2 . '/tags') - call assert_true(tags2[0] =~ 'look-away') + let tags1 = readfile(docdir1 . '/tags') + call assert_match('look-here', tags1[0]) + let tags2 = readfile(docdir2 . '/tags') + call assert_match('look-away', tags2[0]) endfunc func Test_colorscheme() @@ -220,6 +353,11 @@ describe('packadd', function() expected_empty() end) + it('works with symlinks', function() + call('Test_packadd_symlink_dir') + expected_empty() + end) + it('works with :packloadall', function() call('Test_packloadall') expected_empty() @@ -240,6 +378,11 @@ describe('packadd', function() expected_empty() end) + it('loads packages from "start" directory', function() + call('Test_packadd_start') + expected_empty() + end) + describe('command line completion', function() local Screen = require('test.functional.ui.screen') local screen @@ -248,53 +391,52 @@ describe('packadd', function() screen = Screen.new(30, 5) screen:attach() screen:set_default_attr_ids({ + [0] = {bold=true, foreground=Screen.colors.Blue}, [1] = { foreground = Screen.colors.Black, background = Screen.colors.Yellow, }, [2] = {bold = true, reverse = true} }) - local NonText = Screen.colors.Blue - screen:set_default_attr_ignore({{}, {bold=true, foreground=NonText}}) - - execute([[let optdir1 = &packpath . '/pack/mine/opt']]) - execute([[let optdir2 = &packpath . '/pack/candidate/opt']]) - execute([[call mkdir(optdir1 . '/pluginA', 'p')]]) - execute([[call mkdir(optdir1 . '/pluginC', 'p')]]) - execute([[call mkdir(optdir2 . '/pluginB', 'p')]]) - execute([[call mkdir(optdir2 . '/pluginC', 'p')]]) + + command([[let optdir1 = &packpath . '/pack/mine/opt']]) + command([[let optdir2 = &packpath . '/pack/candidate/opt']]) + command([[call mkdir(optdir1 . '/pluginA', 'p')]]) + command([[call mkdir(optdir1 . '/pluginC', 'p')]]) + command([[call mkdir(optdir2 . '/pluginB', 'p')]]) + command([[call mkdir(optdir2 . '/pluginC', 'p')]]) end) it('works', function() feed(':packadd <Tab>') screen:expect([=[ | - ~ | - ~ | + {0:~ }| + {0:~ }| {1:pluginA}{2: pluginB pluginC }| :packadd pluginA^ | ]=]) feed('<Tab>') screen:expect([=[ | - ~ | - ~ | + {0:~ }| + {0:~ }| {2:pluginA }{1:pluginB}{2: pluginC }| :packadd pluginB^ | ]=]) feed('<Tab>') screen:expect([=[ | - ~ | - ~ | + {0:~ }| + {0:~ }| {2:pluginA pluginB }{1:pluginC}{2: }| :packadd pluginC^ | ]=]) feed('<Tab>') screen:expect([=[ | - ~ | - ~ | + {0:~ }| + {0:~ }| {2:pluginA pluginB pluginC }| :packadd ^ | ]=]) @@ -316,32 +458,32 @@ describe('packadd', function() feed(':colorscheme <Tab>') screen:expect([=[ | - ~ | - ~ | + {0:~ }| + {0:~ }| {1:one}{2: three two }| :colorscheme one^ | ]=]) feed('<Tab>') screen:expect([=[ | - ~ | - ~ | + {0:~ }| + {0:~ }| {2:one }{1:three}{2: two }| :colorscheme three^ | ]=]) feed('<Tab>') screen:expect([=[ | - ~ | - ~ | + {0:~ }| + {0:~ }| {2:one three }{1:two}{2: }| :colorscheme two^ | ]=]) feed('<Tab>') screen:expect([=[ | - ~ | - ~ | + {0:~ }| + {0:~ }| {2:one three two }| :colorscheme ^ | ]=]) |