workflow.vader 14 KB

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