:Plug throws error for invalid option

This commit is contained in:
Jan Edmund Lazo 2020-04-26 15:59:48 -04:00
parent 71c41fccf5
commit 4fc2faf697
No known key found for this signature in database
GPG Key ID: 64915E6E9F735B15
2 changed files with 38 additions and 1 deletions

View File

@ -632,17 +632,34 @@ function! plug#(repo, ...)
let g:plugs[name] = spec let g:plugs[name] = spec
let s:loaded[name] = get(s:loaded, name, 0) let s:loaded[name] = get(s:loaded, name, 0)
catch catch
return s:err(v:exception) return s:err(repo . ' ' . v:exception)
endtry endtry
endfunction endfunction
function! s:parse_options(arg) function! s:parse_options(arg)
let opts = copy(s:base_spec) let opts = copy(s:base_spec)
let type = type(a:arg) let type = type(a:arg)
let opt_errfmt = 'Invalid argument for "%s" option of :Plug (expected: %s)'
if type == s:TYPE.string if type == s:TYPE.string
if empty(a:arg)
throw printf(opt_errfmt, 'tag', 'string')
endif
let opts.tag = a:arg let opts.tag = a:arg
elseif type == s:TYPE.dict elseif type == s:TYPE.dict
call extend(opts, a:arg) call extend(opts, a:arg)
for opt in ['branch', 'tag', 'commit', 'rtp', 'dir', 'as']
if has_key(opts, opt)
\ && (type(opts[opt]) != s:TYPE.string || empty(opts[opt]))
throw printf(opt_errfmt, opt, 'string')
endif
endfor
for opt in ['on', 'for']
if has_key(opts, opt)
\ && type(opts[opt]) != s:TYPE.list
\ && (type(opts[opt]) != s:TYPE.string || empty(opts[opt]))
throw printf(opt_errfmt, opt, 'string or list')
endif
endfor
if has_key(opts, 'dir') if has_key(opts, 'dir')
let opts.dir = s:dirpath(s:plug_expand(opts.dir)) let opts.dir = s:dirpath(s:plug_expand(opts.dir))
endif endif

View File

@ -49,11 +49,19 @@ Execute (Test Plug command):
AssertEqual 'no-t_co', g:plugs['seoul256.vim'].branch AssertEqual 'no-t_co', g:plugs['seoul256.vim'].branch
^ Git repo with tag (DEPRECATED. USE TAG OPTION) ^ Git repo with tag (DEPRECATED. USE TAG OPTION)
redir => out
Plug 'foo/bar.vim', ''
redir END
Assert out =~ 'Invalid argument for "tag" option of :Plug (expected: string)'
Plug 'junegunn/goyo.vim', '1.5.2' Plug 'junegunn/goyo.vim', '1.5.2'
AssertEqual 'file:///tmp/vim-plug-test/junegunn/goyo.vim', g:plugs['goyo.vim'].uri AssertEqual 'file:///tmp/vim-plug-test/junegunn/goyo.vim', g:plugs['goyo.vim'].uri
AssertEqual join([g:temp_plugged, 'goyo.vim/'], '/'), g:plugs['goyo.vim'].dir AssertEqual join([g:temp_plugged, 'goyo.vim/'], '/'), g:plugs['goyo.vim'].dir
AssertEqual '1.5.2', g:plugs['goyo.vim'].tag AssertEqual '1.5.2', g:plugs['goyo.vim'].tag
redir => out
Plug 'foo/bar.vim', {'tag': ''}
redir END
Assert out =~ 'Invalid argument for "tag" option of :Plug (expected: string)'
Plug 'junegunn/goyo.vim', { 'tag': '1.5.3' } " Using tag option Plug 'junegunn/goyo.vim', { 'tag': '1.5.3' } " Using tag option
AssertEqual '1.5.3', g:plugs['goyo.vim'].tag AssertEqual '1.5.3', g:plugs['goyo.vim'].tag
@ -77,6 +85,18 @@ Execute (Test Plug command):
Execute (Plug command with dictionary option): Execute (Plug command with dictionary option):
Log string(g:plugs) Log string(g:plugs)
for opt in ['branch', 'tag', 'commit', 'rtp', 'dir', 'as']
redir => out
Plug 'foo/bar.vim', {opt: ''}
redir END
Assert out =~ 'Invalid argument for "'.opt.'" option of :Plug (expected: string)'
endfor
for opt in ['on', 'for']
redir => out
Plug 'foo/bar.vim', {opt: ''}
redir END
Assert out =~ 'Invalid argument for "'.opt.'" option of :Plug (expected: string or list)'
endfor
Plug 'junegunn/seoul256.vim', { 'branch': 'no-t_co', 'rtp': '././' } Plug 'junegunn/seoul256.vim', { 'branch': 'no-t_co', 'rtp': '././' }
AssertEqual join([g:temp_plugged, 'seoul256.vim/'], '/'), g:plugs['seoul256.vim'].dir AssertEqual join([g:temp_plugged, 'seoul256.vim/'], '/'), g:plugs['seoul256.vim'].dir
AssertEqual '././', g:plugs['seoul256.vim'].rtp AssertEqual '././', g:plugs['seoul256.vim'].rtp