workflow.vader 23 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865
  1. Execute (Initialize test environment):
  2. Save &rtp, g:plugs, g:plug_home
  3. let first_rtp = split(&rtp, ',')[0]
  4. let last_rtp = split(&rtp, ',')[-1]
  5. let vader = fnamemodify(globpath(&rtp, 'autoload/vader.vim'), ':h:h')
  6. let plug = fnamemodify(globpath(&rtp, 'autoload/plug.vim'), ':h:h')
  7. set rtp=$HOME/.vim,$VIM/vimfiles,$VIMRUNTIME,$VIM/vimfiles/after,$HOME/.vim/after
  8. execute 'set rtp^='.vader
  9. execute 'set rtp^='.plug
  10. let basertp = &rtp
  11. unlet! g:plugs
  12. unlet! g:plug_home
  13. set t_Co=256
  14. colo default
  15. pclose
  16. function! PlugStatusSorted()
  17. PlugStatus
  18. %y
  19. q
  20. normal! P
  21. %sort
  22. g/^$/d
  23. endfunction
  24. function! AssertExpect(bang, pat, cnt)
  25. let op = a:bang ? '==' : '=~'
  26. AssertEqual a:cnt, len(filter(getline(1, '$'), "v:val ".op." '".a:pat."'"))
  27. endfunction
  28. command! -nargs=+ -bang AssertExpect call AssertExpect('<bang>' == '!', <args>)
  29. Execute (Print Ruby version):
  30. redir => out
  31. silent ruby puts RUBY_VERSION
  32. redir END
  33. Log substitute(out, '\n', '', 'g')
  34. Execute (plug#end() before plug#begin() should fail):
  35. redir => out
  36. AssertEqual 0, plug#end()
  37. redir END
  38. Assert stridx(out, 'Call plug#begin() first') >= 0
  39. Execute (plug#begin() without path argument):
  40. call plug#begin()
  41. AssertEqual split(&rtp, ',')[0].'/plugged', g:plug_home
  42. unlet g:plug_home
  43. Execute (plug#begin() without path argument with empty &rtp):
  44. let save_rtp = &rtp
  45. set rtp=
  46. redir => out
  47. AssertEqual 0, plug#begin()
  48. redir END
  49. Assert stridx(out, 'Unable to determine plug home') >= 0
  50. let &rtp = save_rtp
  51. Execute (plug#begin(path)):
  52. let temp_plugged = tempname()
  53. call plug#begin(temp_plugged.'/')
  54. Assert g:plug_home !~ '[/\\]$', 'Trailing / should be stripped from g:plug_home'
  55. AssertEqual 0, len(g:plugs)
  56. AssertEqual temp_plugged, g:plug_home
  57. AssertEqual basertp, &rtp
  58. Execute (Subsequent plug#begin() calls will reuse g:plug_home):
  59. call plug#begin()
  60. AssertEqual temp_plugged, g:plug_home
  61. Execute (Test Plug command):
  62. " Git repo with branch
  63. Plug 'junegunn/seoul256.vim', 'yes-t_co'
  64. AssertEqual 'https://git::@github.com/junegunn/seoul256.vim.git', g:plugs['seoul256.vim'].uri
  65. AssertEqual join([temp_plugged, 'seoul256.vim/'], '/'), g:plugs['seoul256.vim'].dir
  66. AssertEqual 'yes-t_co', g:plugs['seoul256.vim'].branch
  67. Plug 'junegunn/seoul256.vim', { 'branch': 'no-t_co' } " Using branch option
  68. AssertEqual 'no-t_co', g:plugs['seoul256.vim'].branch
  69. " Git repo with tag
  70. Plug 'junegunn/goyo.vim', '1.5.2'
  71. AssertEqual 'https://git::@github.com/junegunn/goyo.vim.git', g:plugs['goyo.vim'].uri
  72. AssertEqual join([temp_plugged, 'goyo.vim/'], '/'), g:plugs['goyo.vim'].dir
  73. AssertEqual '1.5.2', g:plugs['goyo.vim'].branch
  74. Plug 'junegunn/goyo.vim', { 'tag': '1.5.3' } " Using tag option
  75. AssertEqual '1.5.3', g:plugs['goyo.vim'].branch
  76. " Git URI
  77. Plug 'https://bitbucket.org/junegunn/vim-emoji.git'
  78. AssertEqual 'https://bitbucket.org/junegunn/vim-emoji.git', g:plugs['vim-emoji'].uri
  79. AssertEqual 'master', g:plugs['vim-emoji'].branch
  80. AssertEqual join([temp_plugged, 'vim-emoji/'], '/'), g:plugs['vim-emoji'].dir
  81. " vim-scripts/
  82. Plug 'beauty256'
  83. AssertEqual 'https://git::@github.com/vim-scripts/beauty256.git', g:plugs.beauty256.uri
  84. AssertEqual 'master', g:plugs.beauty256.branch
  85. AssertEqual 4, len(g:plugs)
  86. Execute (Plug command with dictionary option):
  87. Log string(g:plugs)
  88. Plug 'junegunn/seoul256.vim', { 'branch': 'no-t_co', 'rtp': '././' }
  89. AssertEqual join([temp_plugged, 'seoul256.vim/'], '/'), g:plugs['seoul256.vim'].dir
  90. AssertEqual '././', g:plugs['seoul256.vim'].rtp
  91. Log string(g:plugs)
  92. AssertEqual 4, len(g:plugs)
  93. Execute (PlugStatus before installation):
  94. PlugStatus
  95. AssertExpect 'Not found', 4
  96. q
  97. Execute (PlugClean before installation):
  98. PlugClean
  99. AssertExpect 'Already clean', 1
  100. q
  101. Execute (plug#end() updates &rtp):
  102. call plug#end()
  103. Assert len(&rtp) > len(basertp)
  104. AssertEqual first_rtp, split(&rtp, ',')[0]
  105. AssertEqual last_rtp, split(&rtp, ',')[-1]
  106. Execute (Yet, plugins are not available):
  107. Assert empty(globpath(&rtp, 'autoload/emoji.vim'))
  108. Execute (PlugInstall):
  109. PlugInstall
  110. q
  111. Execute (Plugin available after installation):
  112. Assert !empty(globpath(&rtp, 'autoload/emoji.vim'))
  113. Execute (PlugClean after installation):
  114. PlugClean
  115. AssertExpect 'Already clean', 1
  116. q
  117. Execute (PlugStatus after installation):
  118. PlugStatus
  119. Log getline(1, '$')
  120. AssertExpect 'OK', 4
  121. q
  122. Execute (Change tag of goyo.vim):
  123. call plug#begin()
  124. Plug 'junegunn/goyo.vim'
  125. call plug#end()
  126. Execute (PlugStatus):
  127. call PlugStatusSorted()
  128. Expect:
  129. Invalid branch/tag: 1.5.3 (expected: master). Try PlugUpdate.
  130. Finished. 1 error(s).
  131. [=]
  132. x goyo.vim:
  133. Execute (PlugUpdate to set the right branch):
  134. PlugUpdate
  135. call PlugStatusSorted()
  136. Expect:
  137. - goyo.vim: OK
  138. Finished. 0 error(s).
  139. [=]
  140. Execute (Change branch of seoul256.vim):
  141. call plug#begin()
  142. Plug 'junegunn/seoul256.vim'
  143. Plug 'https://bitbucket.org/junegunn/vim-emoji.git'
  144. call plug#end()
  145. Execute (PlugStatus):
  146. call PlugStatusSorted()
  147. Expect:
  148. Invalid branch/tag: no-t_co (expected: master). Try PlugUpdate.
  149. - vim-emoji: OK
  150. Finished. 1 error(s).
  151. [==]
  152. x seoul256.vim:
  153. Execute (Change URI of seoul256.vim):
  154. call plug#begin()
  155. Plug 'junegunn.choi/seoul256.vim'
  156. Plug 'https://bitbucket.org/junegunn/vim-emoji.git'
  157. call plug#end()
  158. Execute (PlugStatus):
  159. call PlugStatusSorted()
  160. Expect:
  161. Expected: https://git::@github.com/junegunn.choi/seoul256.vim.git
  162. Invalid URI: https://git::@github.com/junegunn/seoul256.vim.git
  163. PlugClean required.
  164. - vim-emoji: OK
  165. Finished. 1 error(s).
  166. [==]
  167. x seoul256.vim:
  168. # TODO: does not work due to inputsave()
  169. # Do (PlugClean):
  170. # :PlugClean\<Enter>y\<Enter>
  171. # ggyG
  172. # q
  173. # PGdd
  174. Execute (PlugClean! to remove seoul256.vim):
  175. PlugClean!
  176. " Three removed, emoji left
  177. AssertExpect '^- ', 3
  178. AssertExpect 'Removed', 1
  179. Assert empty(globpath(&rtp, 'colors/seoul256.vim'))
  180. Assert !empty(globpath(&rtp, 'autoload/emoji.vim'))
  181. q
  182. Execute (Change GIT URI of vim-emoji):
  183. call plug#begin()
  184. Plug 'junegunn/seoul256.vim'
  185. Plug 'junegunn/vim-emoji'
  186. call plug#end()
  187. Execute (PlugStatus):
  188. call PlugStatusSorted()
  189. Expect:
  190. Expected: https://git::@github.com/junegunn/vim-emoji.git
  191. Invalid URI: https://bitbucket.org/junegunn/vim-emoji.git
  192. Not found. Try PlugInstall.
  193. PlugClean required.
  194. Finished. 2 error(s).
  195. [==]
  196. x seoul256.vim:
  197. x vim-emoji:
  198. Execute (PlugClean! to remove vim-emoji):
  199. PlugClean!
  200. AssertExpect '^- ', 1
  201. AssertExpect 'Removed', 1
  202. Assert empty(globpath(&rtp, 'colors/seoul256.vim'))
  203. Assert empty(globpath(&rtp, 'autoload/emoji.vim'))
  204. q
  205. Execute (PlugUpdate to install both again):
  206. PlugUpdate
  207. AssertExpect '^- [^:]*:', 2
  208. Assert !empty(globpath(&rtp, 'colors/seoul256.vim')), 'seoul256.vim should be found'
  209. Assert !empty(globpath(&rtp, 'autoload/emoji.vim')), 'vim-emoji should be found'
  210. q
  211. Execute (PlugUpdate only to find out plugins are up-to-date, D key to check):
  212. PlugUpdate
  213. AssertExpect 'Already up-to-date', 2
  214. normal D
  215. AssertEqual 'No updates.', getline(1)
  216. q
  217. Execute (PlugDiff - 'No updates.'):
  218. PlugDiff
  219. AssertEqual 'No updates.', getline(1)
  220. q
  221. Execute (Rollback recent updates, PlugUpdate, then PlugDiff):
  222. for repo in ['seoul256.vim', 'vim-emoji']
  223. call system(printf('cd %s/%s && git reset HEAD^^ --hard', g:plug_home, repo))
  224. endfor
  225. PlugUpdate
  226. " Now we have updates
  227. normal D
  228. AssertEqual 'Last update:', getline(1)
  229. " Preview commit
  230. silent! wincmd P
  231. AssertEqual 0, &previewwindow
  232. " ]] motion
  233. execute 'normal ]]'
  234. let lnum = line('.')
  235. AssertEqual 3, col('.')
  236. " Open commit preview
  237. execute "normal j\<cr>"
  238. wincmd P
  239. AssertEqual 1, &previewwindow
  240. AssertEqual 'git', &filetype
  241. " Back to plug window
  242. wincmd p
  243. " ]] motion
  244. execute 'normal $]]'
  245. AssertEqual lnum + 4, line('.')
  246. AssertEqual 3, col('.')
  247. " [[ motion
  248. execute 'normal 0[['
  249. AssertEqual lnum, line('.')
  250. AssertEqual 3, col('.')
  251. " X key to revert the update
  252. AssertExpect '^- ', 2
  253. execute "normal Xn\<cr>"
  254. AssertExpect '^- ', 2
  255. execute "normal Xy\<cr>"
  256. AssertExpect '^- ', 1
  257. " q will close preview window as well
  258. normal q
  259. " We no longer have preview window
  260. silent! wincmd P
  261. AssertEqual 0, &previewwindow
  262. " q should not close preview window if it's already open
  263. pedit
  264. PlugDiff
  265. AssertExpect '^- ', 1
  266. execute "normal ]]j\<cr>"
  267. normal q
  268. silent! wincmd P
  269. AssertEqual 1, &previewwindow
  270. pclose
  271. Execute (Plug window in a new tab):
  272. PlugDiff
  273. tab new new-tab
  274. set buftype=nofile
  275. PlugUpdate
  276. normal D
  277. AssertExpect '^- ', 1
  278. normal q
  279. AssertEqual 'new-tab', expand('%')
  280. q
  281. q
  282. **********************************************************************
  283. ~ On-demand loading / Partial installation/update ~
  284. **********************************************************************
  285. Execute (Trying to execute on-demand commands when plugin is not installed):
  286. call plug#begin()
  287. Plug 'junegunn/vim-easy-align', { 'on': ['EasyAlign', 'LiveEasyAlign'] }
  288. call plug#end()
  289. Assert exists(':EasyAlign')
  290. Assert exists(':LiveEasyAlign')
  291. AssertThrows EasyAlign
  292. AssertThrows LiveEasyAlign
  293. Assert !exists(':EasyAlign')
  294. Assert !exists(':LiveEasyAlign')
  295. Execute (New set of plugins):
  296. call plug#begin()
  297. Plug 'junegunn/vim-fnr'
  298. Plug 'junegunn/vim-pseudocl'
  299. Plug 'junegunn/vim-easy-align', { 'on': 'EasyAlign' }
  300. Plug 'junegunn/vim-redis', { 'for': 'redis' }
  301. call plug#end()
  302. Execute (Check commands):
  303. Assert !exists(':FNR'), 'FNR command should not be found'
  304. Assert !exists(':RedisExecute'), 'RedisExecute command should not be found'
  305. Execute (Partial PlugInstall):
  306. PlugInstall vim-fnr vim-easy-align
  307. AssertExpect 'vim-fnr', 1
  308. q
  309. PlugInstall vim-fnr vim-easy-align 1
  310. AssertExpect 'vim-fnr', 1
  311. AssertExpect 'vim-easy-align', 1
  312. AssertEqual first_rtp, split(&rtp, ',')[0]
  313. AssertEqual last_rtp, split(&rtp, ',')[-1]
  314. q
  315. Given (Unaligned code):
  316. a=1
  317. aa=2
  318. Execute (Check installed plugins):
  319. if has('vim_starting')
  320. Log 'Vader is run from commandline'
  321. runtime! plugin/**/*.vim
  322. endif
  323. Assert exists(':FNR'), 'FNR command should be found'
  324. Assert !exists(':RedisExecute'), 'RedisExecute command still should not be found'
  325. Assert exists(':EasyAlign'), 'EasyAlign command should be found'
  326. %EasyAlign=
  327. Expect (Aligned code):
  328. a = 1
  329. aa = 2
  330. Given:
  331. Execute (Partial PlugUpdate):
  332. PlugUpdate vim-redis
  333. q
  334. Execute (On-demand loading based on filetypes):
  335. Assert !exists(':RedisExecute'), 'RedisExecute command still should not be found'
  336. set ft=redis
  337. Assert exists(':RedisExecute'), 'RedisExecute command is now found'
  338. **********************************************************************
  339. ~ Local (unmanaged) plugins
  340. **********************************************************************
  341. Execute (Add unmanaged plugin):
  342. let fzf = fnamemodify(g:vader_file, ':h') . '/fzf'
  343. Log fzf
  344. call plug#begin()
  345. Plug fzf, { 'on': 'SomeCommand' }
  346. call plug#end()
  347. " Check uri field
  348. Assert !has_key(g:plugs.fzf, 'uri'), 'Should not have uri field'
  349. " Check dir field
  350. AssertEqual fzf.'/', g:plugs.fzf.dir
  351. " Trailing slashes and backslashes should be stripped
  352. for suffix in ['///', '/\/\/']
  353. call plug#begin()
  354. Plug fzf.suffix, { 'on': 'SomeCommand' }
  355. call plug#end()
  356. " Check dir field
  357. AssertEqual fzf.'/', g:plugs.fzf.dir
  358. endfor
  359. Execute (Plug block for following tests):
  360. call plug#begin()
  361. Plug 'junegunn/vim-easy-align'
  362. Plug fzf, { 'on': 'SomeCommand' }
  363. call plug#end()
  364. " Remove plugins from previous tests
  365. PlugClean!
  366. Execute (PlugInstall will only install vim-easy-align):
  367. PlugInstall
  368. Log getline(1, '$')
  369. AssertExpect 'fzf', 0
  370. q
  371. Execute (PlugUpdate will only update vim-easy-align):
  372. PlugUpdate
  373. Log getline(1, '$')
  374. AssertExpect 'fzf', 0
  375. q
  376. Execute (PlugClean should not care about unmanaged plugins):
  377. PlugClean
  378. Log getline(1, '$')
  379. AssertExpect 'fzf', 0
  380. q
  381. Execute (PlugStatus should point out that the plugin is missing):
  382. PlugStatus
  383. Log getline(1, '$')
  384. AssertExpect 'x fzf', 1
  385. AssertExpect 'Not found', 1
  386. q
  387. Execute (Deploy unmanaged plugin):
  388. Assert !exists(':FZF'), ':FZF command should not exist'
  389. call rename('fzf-staged', 'fzf')
  390. Execute (PlugUpdate still should not care):
  391. PlugUpdate
  392. Log getline(1, '$')
  393. AssertExpect 'fzf', 0
  394. q
  395. Execute (PlugStatus with no error):
  396. PlugStatus
  397. Log getline(1, '$')
  398. AssertExpect 'x fzf', 0
  399. AssertExpect 'Not found', 0
  400. q
  401. Execute (Check &rtp after SomeCommand):
  402. Log &rtp
  403. Assert &rtp !~ 'fzf'
  404. silent! SomeCommand
  405. Assert &rtp =~ 'fzf'
  406. AssertEqual first_rtp, split(&rtp, ',')[0]
  407. AssertEqual last_rtp, split(&rtp, ',')[-1]
  408. Execute (Common parent):
  409. call plug#begin()
  410. Plug 'junegunn/vim-pseudocl'
  411. Plug 'junegunn/vim-fnr'
  412. Plug 'junegunn/vim-oblique'
  413. call plug#end()
  414. PlugInstall
  415. Log getline(1, '$')
  416. AssertExpect! '[===]', 1
  417. q
  418. **********************************************************************
  419. ~ Frozen plugins
  420. **********************************************************************
  421. Execute (Frozen plugin are not installed nor updated):
  422. call plug#begin()
  423. Plug 'junegunn/vim-easy-align', { 'frozen': 1 }
  424. call plug#end()
  425. redir => out
  426. silent PlugInstall
  427. redir END
  428. Assert out =~ 'No plugin to install'
  429. redir => out
  430. silent PlugUpdate
  431. redir END
  432. Assert out =~ 'No plugin to update'
  433. Execute (But you can still install it if the name is given as the argument):
  434. PlugInstall vim-easy-align
  435. Log getline(1, '$')
  436. AssertEqual 1, len(filter(getline(1, '$'), 'v:val =~ "vim-easy-align"'))
  437. q
  438. PlugUpdate vim-easy-align
  439. Log getline(1, '$')
  440. AssertEqual 1, len(filter(getline(1, '$'), 'v:val =~ "vim-easy-align"'))
  441. q
  442. **********************************************************************
  443. ~ Retry
  444. **********************************************************************
  445. Execute (Retry failed tasks):
  446. call plug#begin()
  447. Plug 'junegunn/vim-easy-align'
  448. Plug 'junegunn/aaaaaaaaaaaaaa'
  449. call plug#end()
  450. PlugInstall
  451. Log getline(1, '$')
  452. AssertExpect 'x aaa', 1
  453. AssertExpect '- vim-easy-align', 1
  454. normal R
  455. Log getline(1, '$')
  456. AssertExpect 'x aaa', 1
  457. AssertExpect '- vim-easy-align', 0
  458. AssertExpect! '[x]', 1
  459. q
  460. call plug#begin()
  461. Plug 'junegunn/vim-easy-align'
  462. Plug 'junegunn/aaaaaaaaaaaaaa'
  463. Plug 'junegunn/bbbbbbbbbbbbbb'
  464. Plug 'junegunn/cccccccccccccc'
  465. call plug#end()
  466. " Ruby installer
  467. PlugUpdate
  468. normal R
  469. AssertExpect '- vim-easy-align', 0
  470. AssertExpect! '[xxx]', 1
  471. q
  472. " Vim installer
  473. PlugUpdate 1
  474. normal R
  475. AssertExpect '- vim-easy-align', 0
  476. AssertExpect! '[xxx]', 1
  477. q
  478. **********************************************************************
  479. ~ Post-update hook (`do` option)
  480. **********************************************************************
  481. Execute (Cleanup):
  482. call plug#begin()
  483. call plug#end()
  484. PlugClean!
  485. Execute (On install):
  486. call plug#begin()
  487. Plug 'junegunn/vim-easy-align', { 'do': 'touch installed' }
  488. Plug 'junegunn/vim-pseudocl'
  489. call plug#end()
  490. PlugInstall
  491. q
  492. Assert filereadable(g:plugs['vim-easy-align'].dir.'/installed'),
  493. \ 'vim-easy-align/installed should exist'
  494. Assert !filereadable(g:plugs['vim-pseudocl'].dir.'/installed'),
  495. \ 'vim-pseudocl/installed should not exist'
  496. Execute (On update):
  497. call plug#begin()
  498. Plug 'junegunn/vim-easy-align', { 'do': 'touch updated' }
  499. Plug 'junegunn/vim-pseudocl', { 'do': 'touch updated' }
  500. call plug#end()
  501. " Reset for updates
  502. call system('cd '.g:plugs['vim-pseudocl'].dir.' && git reset --hard HEAD^')
  503. PlugUpdate
  504. Log getline(1, '$')
  505. q
  506. Assert !filereadable(g:plugs['vim-easy-align'].dir.'/updated'),
  507. \ 'vim-easy-align/updated should not exist'
  508. Assert filereadable(g:plugs['vim-pseudocl'].dir.'/updated'),
  509. \ 'vim-pseudocl/updated should exist'
  510. Execute (When already installed):
  511. call plug#begin()
  512. Plug 'junegunn/vim-easy-align', { 'do': 'touch installed2' }
  513. Plug 'junegunn/vim-pseudocl', { 'do': 'touch installed2' }
  514. call plug#end()
  515. PlugInstall
  516. q
  517. Assert !filereadable(g:plugs['vim-easy-align'].dir.'/installed2'),
  518. \ 'vim-easy-align/installed2 should not exist'
  519. Assert !filereadable(g:plugs['vim-pseudocl'].dir.'/installed2'),
  520. \ 'vim-pseudocl/installed2 should not exist'
  521. Execute (PlugInstall!):
  522. PlugInstall!
  523. q
  524. Assert filereadable(g:plugs['vim-easy-align'].dir.'/installed2'),
  525. \ 'vim-easy-align/installed2 should exist'
  526. Assert filereadable(g:plugs['vim-pseudocl'].dir.'/installed2'),
  527. \ 'vim-pseudocl/installed2 should exist'
  528. Execute (When already updated):
  529. call plug#begin()
  530. Plug 'junegunn/vim-easy-align', { 'do': 'touch updated2' }
  531. Plug 'junegunn/vim-pseudocl', { 'do': 'touch updated2' }
  532. call plug#end()
  533. PlugUpdate
  534. q
  535. Assert !filereadable(g:plugs['vim-easy-align'].dir.'/updated2'),
  536. \ 'vim-easy-align/updated2 should not exist'
  537. Assert !filereadable(g:plugs['vim-pseudocl'].dir.'/updated2'),
  538. \ 'vim-pseudocl/updated2 should not exist'
  539. Execute (PlugUpdate!):
  540. PlugUpdate!
  541. q
  542. Assert filereadable(g:plugs['vim-easy-align'].dir.'/updated2'),
  543. \ 'vim-easy-align/updated2 should exist'
  544. Assert filereadable(g:plugs['vim-pseudocl'].dir.'/updated2'),
  545. \ 'vim-pseudocl/updated2 should exist'
  546. Execute (Using Funcref):
  547. function! PlugUpdated(info)
  548. call system('touch '. a:info.name . a:info.status . a:info.force . len(a:info))
  549. endfunction
  550. call plug#begin()
  551. Plug 'junegunn/vim-easy-align', { 'do': function('PlugUpdated') }
  552. Plug 'junegunn/vim-pseudocl', { 'do': function('PlugUpdated') }
  553. call plug#end()
  554. call system('cd '.g:plugs['vim-easy-align'].dir.' && git reset --hard HEAD^')
  555. call system('rm -rf '.g:plugs['vim-pseudocl'].dir)
  556. PlugUpdate
  557. Log getline(1, '$')
  558. q
  559. Assert filereadable(g:plugs['vim-easy-align'].dir.'/vim-easy-alignupdated03'),
  560. \ 'vim-easy-align/vim-easy-alignupdated03 should exist'
  561. Assert filereadable(g:plugs['vim-pseudocl'].dir.'/vim-pseudoclinstalled03'),
  562. \ 'vim-pseudocl/vim-pseudoclinstalled03 should exist'
  563. call system('rm -rf '.g:plugs['vim-pseudocl'].dir)
  564. PlugInstall!
  565. q
  566. Assert filereadable(g:plugs['vim-easy-align'].dir.'/vim-easy-alignunchanged13'),
  567. \ 'vim-easy-align/vim-easy-alignunchanged13 should exist'
  568. Assert filereadable(g:plugs['vim-pseudocl'].dir.'/vim-pseudoclinstalled13'),
  569. \ 'vim-pseudocl/vim-pseudoclinstalled13 should exist'
  570. call system('cd '.g:plugs['vim-easy-align'].dir.' && git reset --hard HEAD^')
  571. PlugUpdate!
  572. q
  573. Assert filereadable(g:plugs['vim-easy-align'].dir.'/vim-easy-alignupdated13'),
  574. \ 'vim-easy-align/vim-easy-alignupdated13 should exist'
  575. Assert filereadable(g:plugs['vim-pseudocl'].dir.'/vim-pseudoclunchanged13'),
  576. \ 'vim-pseudocl/vim-pseudoclunchanged13 should exist'
  577. **********************************************************************
  578. ~ Overriding `dir`
  579. **********************************************************************
  580. Execute (Using custom dir):
  581. Assert isdirectory(g:plugs['vim-easy-align'].dir)
  582. call system('rm -rf '.$TMPDIR.'easy-align')
  583. call plug#begin()
  584. Plug 'junegunn/vim-easy-align', { 'dir': $TMPDIR.'easy-align' }
  585. call plug#end()
  586. AssertEqual $TMPDIR.'easy-align/', g:plugs['vim-easy-align'].dir
  587. PlugClean!
  588. Assert !isdirectory(g:plugs['vim-easy-align'].dir)
  589. q
  590. PlugInstall
  591. q
  592. Assert isdirectory(g:plugs['vim-easy-align'].dir)
  593. **********************************************************************
  594. ~ On-demand loading load order
  595. **********************************************************************
  596. Before (Clear global vars):
  597. let g:xxx = []
  598. set rtp-=$PWD/xxx/
  599. set rtp-=$PWD/xxx/after
  600. Execute (Immediate loading):
  601. call plug#begin()
  602. Plug '$PWD/xxx'
  603. call plug#end()
  604. " FIXME:
  605. " Different result when Vader is run from commandline with `-c` option
  606. Log g:xxx
  607. if has('vim_starting')
  608. AssertEqual ['/ftdetect', 'after/ftdetect'], g:xxx
  609. else
  610. AssertEqual ['/plugin', 'after/plugin', '/ftdetect', 'after/ftdetect'], g:xxx
  611. endif
  612. Execute (Command-based on-demand loading):
  613. call plug#begin()
  614. Plug '$PWD/xxx', { 'on': 'XXX' }
  615. call plug#end()
  616. AssertEqual [], g:xxx
  617. silent! XXX
  618. AssertEqual ['/ftdetect', 'after/ftdetect', '/plugin', 'after/plugin'], g:xxx
  619. setf xxx
  620. AssertEqual ['/ftdetect', 'after/ftdetect', '/plugin', 'after/plugin', '/ftplugin', 'after/ftplugin', '/indent', 'after/indent', '/syntax', 'after/syntax'], g:xxx
  621. Execute (Filetype-based on-demand loading):
  622. call plug#begin()
  623. Plug '$PWD/xxx', { 'for': 'xxx' }
  624. call plug#end()
  625. AssertEqual ['/ftdetect', 'after/ftdetect'], g:xxx
  626. setf xxx
  627. AssertEqual ['/ftdetect', 'after/ftdetect', '/plugin', 'after/plugin', '/ftplugin', 'after/ftplugin', '/indent', 'after/indent', '/syntax', 'after/syntax'], g:xxx
  628. Before:
  629. **********************************************************************
  630. ~ plug#helptags()
  631. **********************************************************************
  632. Execute (plug#helptags):
  633. silent! call delete(expand('$PWD/xxx/doc/tags'))
  634. Assert !filereadable(expand('$PWD/xxx/doc/tags'))
  635. AssertEqual 1, plug#helptags()
  636. Assert filereadable(expand('$PWD/xxx/doc/tags'))
  637. **********************************************************************
  638. ~ Manual loading
  639. **********************************************************************
  640. Execute (plug#load - invalid arguments):
  641. AssertEqual 0, plug#load()
  642. AssertEqual 0, plug#load('non-existent-plugin')
  643. AssertEqual 0, plug#load('non-existent-plugin', 'another-non-existent-plugin')
  644. AssertEqual 1, plug#load('xxx')
  645. AssertEqual 0, plug#load('xxx', 'non-existent-plugin')
  646. AssertEqual 0, plug#load('non-existent-plugin', 'xxx')
  647. Execute (on: []):
  648. call plug#begin()
  649. Plug 'junegunn/rust.vim', { 'on': [] }
  650. call plug#end()
  651. PlugInstall
  652. q
  653. Execute (PlugStatus reports (not loaded)):
  654. PlugStatus
  655. AssertExpect 'not loaded', 1
  656. q
  657. Execute (plug#load to load it):
  658. tabnew test.rs
  659. " Vader will switch tab to [Vader-workbench] after Log
  660. " Log &filetype
  661. AssertEqual 1, plug#load('rust.vim')
  662. AssertEqual 'rust', &filetype
  663. q
  664. Execute (PlugStatus should not contain (not loaded)):
  665. PlugStatus
  666. AssertExpect 'not loaded', 0
  667. q
  668. Execute (Load plugin from PlugStatus screen with L key in normal mode):
  669. call plug#begin()
  670. Plug '$PWD/yyy', { 'on': [] }
  671. call plug#end()
  672. PlugStatus
  673. AssertExpect 'not loaded', 1
  674. Assert !exists('g:yyy'), 'yyy not loaded'
  675. /not loaded
  676. normal L
  677. AssertExpect 'not loaded', 0
  678. Assert exists('g:yyy'), 'yyy loaded'
  679. q
  680. Execute (Load plugin from PlugStatus screen with L key in visual mode):
  681. call plug#begin()
  682. Plug '$PWD/z1', { 'on': [] }
  683. Plug '$PWD/z2', { 'for': [] }
  684. call plug#end()
  685. PlugStatus
  686. AssertExpect 'not loaded', 2
  687. Assert !exists('g:z1'), 'z1 not loaded'
  688. Assert !exists('g:z2'), 'z2 not loaded'
  689. normal ggVGL
  690. AssertExpect 'not loaded', 0
  691. Assert exists('g:z1'), 'z1 loaded'
  692. Assert exists('g:z2'), 'z2 loaded'
  693. q
  694. Execute (Cleanup):
  695. silent! call system('rm -rf '.temp_plugged)
  696. silent! call rename('fzf', 'fzf-staged')
  697. silent! unlet g:plugs
  698. silent! unlet g:plug_home
  699. silent! unlet temp_plugged vader plug basertp save_rtp repo lnum fzf out
  700. silent! delf PlugStatusSorted
  701. silent! delf AssertExpect
  702. silent! delf PlugUpdated
  703. silent! delc AssertExpect
  704. silent! unmap /
  705. silent! unmap ?
  706. Restore