Print error message when unable to determine plug home

This commit is contained in:
Junegunn Choi 2014-01-19 00:06:23 +09:00
parent b9174c366f
commit a3cf17a2b3
2 changed files with 33 additions and 6 deletions

View file

@ -61,9 +61,17 @@ let s:is_win = has('win32') || has('win64')
let s:me = expand('<sfile>:p') let s:me = expand('<sfile>:p')
function! plug#begin(...) function! plug#begin(...)
let home = s:path( if a:0 > 0
\ a:0 > 0 ? fnamemodify(a:1, ':p') : let home = s:path(fnamemodify(a:1, ':p'))
\ get(g:, 'plug_home', split(&rtp, ',')[0].'/plugged')) elseif exists('g:plug_home')
let home = s:path(g:plug_home)
elseif !empty(&rtp)
let home = s:path(split(&rtp, ',')[0]) . '/plugged'
else
echoerr "Unable to determine plug home. Try calling plug#begin() with a path argument."
return
endif
if !isdirectory(home) if !isdirectory(home)
try try
call mkdir(home, 'p') call mkdir(home, 'p')

View file

@ -8,8 +8,8 @@ Execute (Initialize test environment):
execute 'set rtp^='.plug execute 'set rtp^='.plug
let basertp = &rtp let basertp = &rtp
silent! unlet g:plugs unlet! g:plugs
silent! unlet g:plug_home unlet! g:plug_home
set t_Co=256 set t_Co=256
colo default colo default
@ -19,11 +19,30 @@ Execute (Initialize test environment):
call writefile(['let g:vimrc_reloaded += 1'], vimrc) call writefile(['let g:vimrc_reloaded += 1'], vimrc)
let $MYVIMRC = vimrc let $MYVIMRC = vimrc
Execute (plug#end() before plug#begin() should fail):
try
call plug#end()
Assert 0, 'should not reach here'
catch
Assert stridx(v:exception, 'Call plug#begin() first') >= 0
endtry
Execute (plug#begin() without path argument): Execute (plug#begin() without path argument):
call plug#begin() call plug#begin()
AssertEqual split(&rtp, ',')[0].'/plugged', g:plug_home AssertEqual split(&rtp, ',')[0].'/plugged', g:plug_home
unlet g:plug_home unlet g:plug_home
Execute (plug#begin() without path argument with empty &rtp):
let save_rtp = &rtp
set rtp=
try
call plug#begin()
Assert 0, 'should not reach here'
catch
Assert stridx(v:exception, 'Unable to determine plug home') >= 0, 'Got: '.v:exception
endtry
let &rtp = save_rtp
Execute (plug#begin(path)): Execute (plug#begin(path)):
let temp_plugged = tempname() let temp_plugged = tempname()
call plug#begin(temp_plugged.'/') call plug#begin(temp_plugged.'/')
@ -205,7 +224,7 @@ Execute (Cleanup):
unlet g:plugs unlet g:plugs
unlet g:plug_home unlet g:plug_home
unlet g:vimrc_reloaded unlet g:vimrc_reloaded
unlet temp_plugged vader plug basertp unlet temp_plugged vader plug basertp save_rtp
Restore Restore
source $MYVIMRC source $MYVIMRC