workflow.vader 14 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531
  1. Execute (Initialize test environment):
  2. Save &rtp, g:plugs, g:plug_home, $MYVIMRC
  3. let vader = fnamemodify(globpath(&rtp, 'autoload/vader.vim'), ':h:h')
  4. let plug = fnamemodify(globpath(&rtp, 'autoload/plug.vim'), ':h:h')
  5. set rtp=$HOME/.vim,$VIM/vimfiles,$VIMRUNTIME,$VIM/vimfiles/after,$HOME/.vim/after
  6. execute 'set rtp^='.vader
  7. execute 'set rtp^='.plug
  8. let basertp = &rtp
  9. unlet! g:plugs
  10. unlet! g:plug_home
  11. set t_Co=256
  12. colo default
  13. pclose
  14. function! PlugStatusSorted()
  15. PlugStatus
  16. %y
  17. q
  18. normal! P
  19. %sort
  20. g/^$/d
  21. endfunction
  22. let g:vimrc_reloaded = 0
  23. let vimrc = tempname()
  24. call writefile(['let g:vimrc_reloaded += 1'], vimrc)
  25. let $MYVIMRC = vimrc
  26. Execute (plug#end() before plug#begin() should fail):
  27. try
  28. call plug#end()
  29. Assert 0, 'should not reach here'
  30. catch
  31. Assert stridx(v:exception, 'Call plug#begin() first') >= 0
  32. endtry
  33. Execute (plug#begin() without path argument):
  34. call plug#begin()
  35. AssertEqual split(&rtp, ',')[0].'/plugged', g:plug_home
  36. unlet g:plug_home
  37. Execute (plug#begin() without path argument with empty &rtp):
  38. let save_rtp = &rtp
  39. set rtp=
  40. try
  41. call plug#begin()
  42. Assert 0, 'should not reach here'
  43. catch
  44. Assert stridx(v:exception, 'Unable to determine plug home') >= 0, 'Got: '.v:exception
  45. endtry
  46. let &rtp = save_rtp
  47. Execute (plug#begin(path)):
  48. let temp_plugged = tempname()
  49. call plug#begin(temp_plugged.'/')
  50. Assert g:plug_home !~ '[/\\]$', 'Trailing / should be stripped from g:plug_home'
  51. AssertEqual 0, len(g:plugs)
  52. AssertEqual temp_plugged, g:plug_home
  53. AssertEqual basertp, &rtp
  54. Execute (Subsequent plug#begin() calls will reuse g:plug_home):
  55. call plug#begin()
  56. AssertEqual temp_plugged, g:plug_home
  57. Execute (Test Plug command):
  58. " Git repo with branch
  59. Plug 'junegunn/seoul256.vim', 'yes-t_co'
  60. AssertEqual 'https://git:@github.com/junegunn/seoul256.vim.git', g:plugs['seoul256.vim'].uri
  61. AssertEqual join([temp_plugged, 'seoul256.vim/'], '/'), g:plugs['seoul256.vim'].dir
  62. AssertEqual 'yes-t_co', g:plugs['seoul256.vim'].branch
  63. Plug 'junegunn/seoul256.vim', { 'branch': 'no-t_co' } " Using branch option
  64. AssertEqual 'no-t_co', g:plugs['seoul256.vim'].branch
  65. " Git repo with tag
  66. Plug 'junegunn/goyo.vim', '1.5.2'
  67. AssertEqual 'https://git:@github.com/junegunn/goyo.vim.git', g:plugs['goyo.vim'].uri
  68. AssertEqual join([temp_plugged, 'goyo.vim/'], '/'), g:plugs['goyo.vim'].dir
  69. AssertEqual '1.5.2', g:plugs['goyo.vim'].branch
  70. Plug 'junegunn/goyo.vim', { 'tag': '1.5.3' } " Using tag option
  71. AssertEqual '1.5.3', g:plugs['goyo.vim'].branch
  72. " Git URI
  73. Plug 'https://bitbucket.org/junegunn/vim-emoji.git'
  74. AssertEqual 'https://bitbucket.org/junegunn/vim-emoji.git', g:plugs['vim-emoji'].uri
  75. AssertEqual 'master', g:plugs['vim-emoji'].branch
  76. AssertEqual join([temp_plugged, 'vim-emoji/'], '/'), g:plugs['vim-emoji'].dir
  77. " vim-scripts/
  78. Plug 'beauty256'
  79. AssertEqual 'https://git:@github.com/vim-scripts/beauty256.git', g:plugs.beauty256.uri
  80. AssertEqual 'master', g:plugs.beauty256.branch
  81. AssertEqual 4, len(g:plugs)
  82. Execute (Plug command with dictionary option):
  83. Log string(g:plugs)
  84. Plug 'junegunn/seoul256.vim', { 'branch': 'no-t_co', 'rtp': '././' }
  85. AssertEqual join([temp_plugged, 'seoul256.vim/'], '/'), g:plugs['seoul256.vim'].dir
  86. AssertEqual '././', g:plugs['seoul256.vim'].rtp
  87. Log string(g:plugs)
  88. AssertEqual 4, len(g:plugs)
  89. Execute (PlugStatus before installation):
  90. PlugStatus
  91. AssertEqual 4, len(filter(getline(1, '$'), 'v:val =~ "Not found"'))
  92. q
  93. Execute (PlugClean before installation):
  94. PlugClean
  95. AssertEqual 1, len(filter(getline(1, '$'), 'v:val =~ "Already clean"'))
  96. q
  97. Execute (plug#end() updates &rtp):
  98. call plug#end()
  99. Assert len(&rtp) > len(basertp)
  100. Execute (Yet, plugins are not available):
  101. Assert empty(globpath(&rtp, 'autoload/emoji.vim'))
  102. Execute (PlugInstall):
  103. PlugInstall
  104. AssertEqual 1, g:vimrc_reloaded
  105. q
  106. Execute (Plugin available after installation):
  107. Assert !empty(globpath(&rtp, 'autoload/emoji.vim'))
  108. Execute (PlugClean after installation):
  109. PlugClean
  110. AssertEqual 1, len(filter(getline(1, '$'), 'v:val =~ "Already clean"'))
  111. q
  112. Execute (PlugStatus after installation):
  113. PlugStatus
  114. AssertEqual 4, len(filter(getline(1, '$'), 'v:val =~ "OK"'))
  115. q
  116. Execute (Change tag of goyo.vim):
  117. call plug#begin()
  118. Plug 'junegunn/goyo.vim'
  119. call plug#end()
  120. Execute (PlugStatus):
  121. call PlugStatusSorted()
  122. Expect:
  123. Invalid branch/tag: 1.5.3 (expected: master). Try PlugUpdate.
  124. Finished. 1 error(s).
  125. [=]
  126. x goyo.vim:
  127. Execute (PlugUpdate to set the right branch):
  128. PlugUpdate
  129. call PlugStatusSorted()
  130. AssertEqual 2, g:vimrc_reloaded
  131. Expect:
  132. - goyo.vim: OK
  133. Finished. 0 error(s).
  134. [=]
  135. Execute (Change branch of seoul256.vim):
  136. call plug#begin()
  137. Plug 'junegunn/seoul256.vim'
  138. Plug 'https://bitbucket.org/junegunn/vim-emoji.git'
  139. call plug#end()
  140. Execute (PlugStatus):
  141. call PlugStatusSorted()
  142. Expect:
  143. Invalid branch/tag: no-t_co (expected: master). Try PlugUpdate.
  144. - vim-emoji: OK
  145. Finished. 1 error(s).
  146. [==]
  147. x seoul256.vim:
  148. Execute (Change URI of seoul256.vim):
  149. call plug#begin()
  150. Plug 'junegunn.choi/seoul256.vim'
  151. Plug 'https://bitbucket.org/junegunn/vim-emoji.git'
  152. call plug#end()
  153. Execute (PlugStatus):
  154. call PlugStatusSorted()
  155. Expect:
  156. Expected: https://git:@github.com/junegunn.choi/seoul256.vim.git
  157. Invalid URI: https://git:@github.com/junegunn/seoul256.vim.git
  158. PlugClean required.
  159. - vim-emoji: OK
  160. Finished. 1 error(s).
  161. [==]
  162. x seoul256.vim:
  163. # TODO: does not work due to inputsave()
  164. # Do (PlugClean):
  165. # :PlugClean\<Enter>y\<Enter>
  166. # ggyG
  167. # q
  168. # PGdd
  169. Execute (PlugClean! to remove seoul256.vim):
  170. PlugClean!
  171. " Three removed, emoji left
  172. AssertEqual 3, len(filter(getline(1, '$'), 'v:val =~ "^- "'))
  173. AssertEqual 1, len(filter(getline(1, '$'), 'v:val =~ "Removed"'))
  174. Assert empty(globpath(&rtp, 'colors/seoul256.vim'))
  175. Assert !empty(globpath(&rtp, 'autoload/emoji.vim'))
  176. q
  177. Execute (Change GIT URI of vim-emoji):
  178. call plug#begin()
  179. Plug 'junegunn/seoul256.vim'
  180. Plug 'junegunn/vim-emoji'
  181. call plug#end()
  182. Execute (PlugStatus):
  183. call PlugStatusSorted()
  184. Expect:
  185. Expected: https://git:@github.com/junegunn/vim-emoji.git
  186. Invalid URI: https://bitbucket.org/junegunn/vim-emoji.git
  187. Not found. Try PlugInstall.
  188. PlugClean required.
  189. Finished. 2 error(s).
  190. [==]
  191. x seoul256.vim:
  192. x vim-emoji:
  193. Execute (PlugClean! to remove vim-emoji):
  194. PlugClean!
  195. AssertEqual 1, len(filter(getline(1, '$'), 'v:val =~ "^- "'))
  196. AssertEqual 1, len(filter(getline(1, '$'), 'v:val =~ "Removed"'))
  197. Assert empty(globpath(&rtp, 'colors/seoul256.vim'))
  198. Assert empty(globpath(&rtp, 'autoload/emoji.vim'))
  199. q
  200. Execute (PlugUpdate to install both again):
  201. PlugUpdate
  202. AssertEqual 2, len(filter(getline(1, '$'), 'v:val =~ "^- [^:]*:"'))
  203. AssertEqual 3, g:vimrc_reloaded
  204. Assert !empty(globpath(&rtp, 'colors/seoul256.vim')), 'seoul256.vim should be found'
  205. Assert !empty(globpath(&rtp, 'autoload/emoji.vim')), 'vim-emoji should be found'
  206. q
  207. Execute (PlugUpdate only to find out plugins are up-to-date, D key to check):
  208. PlugUpdate
  209. AssertEqual 2, len(filter(getline(1, '$'), 'v:val =~ "Already up-to-date"'))
  210. AssertEqual 4, g:vimrc_reloaded
  211. normal D
  212. AssertEqual 'No updates.', getline(1)
  213. q
  214. Execute (PlugDiff - 'No updates.'):
  215. PlugDiff
  216. AssertEqual 'No updates.', getline(1)
  217. q
  218. Execute (Rollback recent updates, PlugUpdate, then PlugDiff):
  219. for repo in ['seoul256.vim', 'vim-emoji']
  220. call system(printf('cd %s/%s && git reset HEAD^^ --hard', g:plug_home, repo))
  221. endfor
  222. PlugUpdate
  223. " Now we have updates
  224. normal D
  225. AssertEqual 'Last update:', getline(1)
  226. " Preview commit
  227. silent! wincmd P
  228. AssertEqual 0, &previewwindow
  229. " ]] motion
  230. execute 'normal ]]'
  231. let lnum = line('.')
  232. AssertEqual 3, col('.')
  233. " Open commit preview
  234. execute "normal j\<cr>"
  235. wincmd P
  236. AssertEqual 1, &previewwindow
  237. AssertEqual 'git', &filetype
  238. " Back to plug window
  239. wincmd p
  240. " ]] motion
  241. execute 'normal $]]'
  242. AssertEqual lnum + 4, line('.')
  243. AssertEqual 3, col('.')
  244. " [[ motion
  245. execute 'normal 0[['
  246. AssertEqual lnum, line('.')
  247. AssertEqual 3, col('.')
  248. " q will close preview window as well
  249. normal q
  250. " We no longer have preview window
  251. silent! wincmd P
  252. AssertEqual 0, &previewwindow
  253. " q should not close preview window if it's already open
  254. pedit
  255. PlugDiff
  256. execute "normal ]]j\<cr>"
  257. normal q
  258. silent! wincmd P
  259. AssertEqual 1, &previewwindow
  260. pclose
  261. Execute (Plug window in a new tab):
  262. PlugDiff
  263. tab new new-tab
  264. set buftype=nofile
  265. PlugUpdate
  266. normal D
  267. AssertEqual 'No updates.', getline(1)
  268. q
  269. AssertEqual 'new-tab', expand('%')
  270. q
  271. q
  272. **********************************************************************
  273. ~ On-demand loading / Partial installation/update ~
  274. **********************************************************************
  275. Execute (Trying to execute on-demand commands when plugin is not installed):
  276. call plug#begin()
  277. Plug 'junegunn/vim-easy-align', { 'on': ['EasyAlign', 'LiveEasyAlign'] }
  278. call plug#end()
  279. Assert exists(':EasyAlign')
  280. Assert exists(':LiveEasyAlign')
  281. AssertThrows EasyAlign
  282. AssertThrows LiveEasyAlign
  283. Assert !exists(':EasyAlign')
  284. Assert !exists(':LiveEasyAlign')
  285. Execute (New set of plugins):
  286. call plug#begin()
  287. Plug 'junegunn/vim-fnr' " Depends on vim-pseudocl
  288. Plug 'junegunn/vim-easy-align', { 'on': 'EasyAlign' }
  289. Plug 'junegunn/vim-redis', { 'for': 'redis' }
  290. call plug#end()
  291. Execute (Check commands):
  292. Assert !exists(':FNR'), 'FNR command should not be found'
  293. Assert !exists(':RedisExecute'), 'RedisExecute command should not be found'
  294. Execute (Partial PlugInstall):
  295. PlugInstall vim-fnr vim-easy-align
  296. AssertEqual 1, len(filter(getline(1, '$'), 'v:val =~ "vim-pseudocl"'))
  297. PlugInstall vim-fnr vim-easy-align 1
  298. AssertEqual 1, len(filter(getline(1, '$'), 'v:val =~ "vim-pseudocl"'))
  299. q
  300. Execute (Check dependent plugin):
  301. Assert &rtp =~ 'pseudocl', &rtp
  302. Given (Unaligned code):
  303. a=1
  304. aa=2
  305. Execute (Check installed plugins):
  306. Assert exists(':FNR'), 'FNR command should be found'
  307. Assert exists(':EasyAlign'), 'EasyAlign command should be found'
  308. Assert !exists(':RedisExecute'), 'RedisExecute command still should not be found'
  309. %EasyAlign=
  310. Expect (Aligned code):
  311. a = 1
  312. aa = 2
  313. Given (nothing):
  314. Execute (Partial PlugUpdate):
  315. PlugUpdate vim-redis
  316. q
  317. Execute (On-demand loading based on filetypes):
  318. Assert !exists(':RedisExecute'), 'RedisExecute command still should not be found'
  319. set ft=redis
  320. Assert exists(':RedisExecute'), 'RedisExecute command is now found'
  321. **********************************************************************
  322. ~ Local (unmanaged) plugins
  323. **********************************************************************
  324. Execute (Add unmanaged plugin):
  325. let fzf = fnamemodify(g:vader_file, ':h') . '/fzf'
  326. Log fzf
  327. call plug#begin()
  328. Plug fzf, { 'on': 'SomeCommand' }
  329. call plug#end()
  330. " Check uri field
  331. Assert !has_key(g:plugs.fzf, 'uri'), 'Should not have uri field'
  332. " Check dir field
  333. AssertEqual fzf.'/', g:plugs.fzf.dir
  334. " Trailing slashes and backslashes should be stripped
  335. for suffix in ['///', '/\/\/']
  336. call plug#begin()
  337. Plug fzf.suffix, { 'on': 'SomeCommand' }
  338. call plug#end()
  339. " Check dir field
  340. AssertEqual fzf.'/', g:plugs.fzf.dir
  341. endfor
  342. Execute (Plug block for following tests):
  343. call plug#begin()
  344. Plug 'junegunn/vim-easy-align'
  345. Plug fzf, { 'on': 'SomeCommand' }
  346. call plug#end()
  347. " Remove plugins from previous tests
  348. PlugClean!
  349. Execute (PlugInstall will only install vim-easy-align):
  350. PlugInstall
  351. Log getline(1, '$')
  352. AssertEqual 0, len(filter(getline(1, '$'), 'v:val =~ "fzf"'))
  353. q
  354. Execute (PlugUpdate will only update vim-easy-align):
  355. PlugUpdate
  356. Log getline(1, '$')
  357. AssertEqual 0, len(filter(getline(1, '$'), 'v:val =~ "fzf"'))
  358. q
  359. Execute (PlugClean should not care about unmanaged plugins):
  360. PlugClean
  361. Log getline(1, '$')
  362. AssertEqual 0, len(filter(getline(1, '$'), 'v:val =~ "fzf"'))
  363. q
  364. Execute (PlugStatus should point out that the plugin is missing):
  365. PlugStatus
  366. Log getline(1, '$')
  367. AssertEqual 1, len(filter(getline(1, '$'), 'v:val =~ "x fzf"'))
  368. AssertEqual 1, len(filter(getline(1, '$'), 'v:val =~ "Not found"'))
  369. q
  370. Execute (Deploy unmanaged plugin):
  371. Assert !exists(':FZF'), ':FZF command should not exist'
  372. call rename('fzf-staged', 'fzf')
  373. Execute (PlugUpdate still should not care):
  374. PlugUpdate
  375. Log getline(1, '$')
  376. AssertEqual 0, len(filter(getline(1, '$'), 'v:val =~ "fzf"'))
  377. q
  378. Execute (PlugStatus with no error):
  379. PlugStatus
  380. Log getline(1, '$')
  381. AssertEqual 0, len(filter(getline(1, '$'), 'v:val =~ "x fzf"'))
  382. AssertEqual 0, len(filter(getline(1, '$'), 'v:val =~ "Not found"'))
  383. q
  384. Execute (Check &rtp after SomeCommand):
  385. Log &rtp
  386. Assert &rtp !~ 'fzf'
  387. silent! SomeCommand
  388. Assert &rtp =~ 'fzf'
  389. Execute (Common parent):
  390. call plug#begin()
  391. Plug 'junegunn/vim-pseudocl'
  392. Plug 'junegunn/vim-fnr'
  393. Plug 'junegunn/vim-oblique'
  394. call plug#end()
  395. PlugInstall
  396. Log getline(1, '$')
  397. AssertEqual 1, len(filter(getline(1, '$'), 'v:val == "[===]"'))
  398. q
  399. **********************************************************************
  400. ~ Frozen plugins
  401. **********************************************************************
  402. Execute (Frozen plugin are not installed nor updated):
  403. call plug#begin()
  404. Plug 'junegunn/vim-easy-align', { 'frozen': 1 }
  405. call plug#end()
  406. redir => output
  407. silent PlugInstall
  408. redir END
  409. Assert output =~ 'No plugin to install'
  410. redir => output
  411. silent PlugUpdate
  412. redir END
  413. Assert output =~ 'No plugin to update'
  414. Execute (But you can still install it if the name is given as the argument):
  415. PlugInstall vim-easy-align
  416. Log getline(1, '$')
  417. AssertEqual 1, len(filter(getline(1, '$'), 'v:val =~ "vim-easy-align"'))
  418. q
  419. PlugUpdate vim-easy-align
  420. Log getline(1, '$')
  421. AssertEqual 1, len(filter(getline(1, '$'), 'v:val =~ "vim-easy-align"'))
  422. q
  423. Execute (Cleanup):
  424. call system('rm -rf '.temp_plugged)
  425. call rename('fzf', 'fzf-staged')
  426. unlet g:plugs
  427. unlet g:plug_home
  428. unlet g:vimrc_reloaded
  429. unlet temp_plugged vader plug basertp save_rtp repo lnum fzf
  430. delf PlugStatusSorted
  431. Restore