Просмотр исходного кода

Print error message when unable to determine plug home

Junegunn Choi 12 лет назад
Родитель
Сommit
a3cf17a2b3
2 измененных файлов с 33 добавлено и 6 удалено
  1. 11 3
      plug.vim
  2. 22 3
      test/workflow.vader

+ 11 - 3
plug.vim

@@ -61,9 +61,17 @@ let s:is_win = has('win32') || has('win64')
 let s:me = expand('<sfile>: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')

+ 22 - 3
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