From a3cf17a2b328906397bd122d19d541fd8b23266e Mon Sep 17 00:00:00 2001 From: Junegunn Choi Date: Sun, 19 Jan 2014 00:06:23 +0900 Subject: [PATCH] Print error message when unable to determine plug home --- plug.vim | 14 +++++++++++--- test/workflow.vader | 25 ++++++++++++++++++++++--- 2 files changed, 33 insertions(+), 6 deletions(-) diff --git a/plug.vim b/plug.vim index 8903e30..aac03ba 100644 --- a/plug.vim +++ b/plug.vim @@ -61,9 +61,17 @@ let s:is_win = has('win32') || has('win64') let s:me = expand(':p') function! plug#begin(...) - let home = s:path( - \ a:0 > 0 ? fnamemodify(a:1, ':p') : - \ get(g:, 'plug_home', split(&rtp, ',')[0].'/plugged')) + if a:0 > 0 + let home = s:path(fnamemodify(a:1, ':p')) + 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) try call mkdir(home, 'p') diff --git a/test/workflow.vader b/test/workflow.vader index c0a5bbf..5e7398f 100644 --- a/test/workflow.vader +++ b/test/workflow.vader @@ -8,8 +8,8 @@ Execute (Initialize test environment): execute 'set rtp^='.plug let basertp = &rtp - silent! unlet g:plugs - silent! unlet g:plug_home + unlet! g:plugs + unlet! g:plug_home set t_Co=256 colo default @@ -19,11 +19,30 @@ Execute (Initialize test environment): call writefile(['let g:vimrc_reloaded += 1'], 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): call plug#begin() AssertEqual split(&rtp, ',')[0].'/plugged', 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)): let temp_plugged = tempname() call plug#begin(temp_plugged.'/') @@ -205,7 +224,7 @@ Execute (Cleanup): unlet g:plugs unlet g:plug_home unlet g:vimrc_reloaded - unlet temp_plugged vader plug basertp + unlet temp_plugged vader plug basertp save_rtp Restore source $MYVIMRC