test.vader 2.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899
  1. Execute (Initialize test environment):
  2. Save &rtp, g:plugs, g:plug_home, g:plug_window
  3. unlet! g:plugs g:plug_home g:plug_window
  4. let g:plug_url_format = 'file:///tmp/vim-plug-test/%s'
  5. let g:base_rtp = &rtp
  6. let g:first_rtp = split(&rtp, ',')[0]
  7. let g:last_rtp = split(&rtp, ',')[-1]
  8. let g:temp_plugged = tempname()
  9. if !exists('$PLUG_SRC')
  10. let $PLUG_SRC = globpath(&rtp, 'autoload/plug.vim')
  11. endif
  12. let $PLUG_TMP = fnamemodify(tempname(), ':h').'/plug.vim'
  13. " Temporarily patch plug.vim
  14. call system('cp "$PLUG_SRC" "$PLUG_TMP"')
  15. call writefile(extend(readfile($PLUG_TMP),
  16. \ ['function! ResetPlug()', 'let s:loaded = {}', 'endfunction']), $PLUG_TMP)
  17. set t_Co=256
  18. colo default
  19. pclose
  20. function! PlugStatusSorted()
  21. PlugStatus
  22. %y
  23. q
  24. normal! P
  25. %sort
  26. g/^$/d
  27. endfunction
  28. function! AssertExpect(bang, pat, cnt)
  29. let op = a:bang ? '==#' : '=~#'
  30. AssertEqual a:cnt, len(filter(getline(1, '$'), "v:val ".op." '".a:pat."'"))
  31. endfunction
  32. command! -nargs=+ -bang AssertExpect call AssertExpect('<bang>' == '!', <args>)
  33. function! EnsureLoaded()
  34. if has('vim_starting')
  35. runtime! plugin/**/*.vim
  36. endif
  37. endfunction
  38. function! RmRf(file)
  39. call system(printf('rm -rf "%s"', a:file))
  40. endfunction
  41. function! ReloadPlug()
  42. call ResetPlug()
  43. source $PLUG_TMP
  44. let &rtp = g:base_rtp
  45. endfunction
  46. function! GitBranch(repo)
  47. return system(printf('cd %s && git rev-parse --abbrev-ref HEAD', g:plugs[a:repo].dir))[:-2]
  48. endfunction
  49. function! GitTag(repo)
  50. return system(printf('cd %s && git describe --tags', g:plugs[a:repo].dir))[:-2]
  51. endfunction
  52. function! GitCommit(repo)
  53. return system(printf('cd %s && git rev-parse HEAD', g:plugs[a:repo].dir))[:-2]
  54. endfunction
  55. source $PLUG_TMP
  56. Execute (Print Interpreter Version):
  57. redir => out
  58. if has('ruby')
  59. silent ruby puts 'Ruby: ' + RUBY_VERSION
  60. elseif has('python')
  61. silent python import sys; svi = sys.version_info; print 'Python: {}.{}.{}'.format(svi[0], svi[1], svi[2])
  62. elseif has('python3')
  63. silent python3 import sys; svi = sys.version_info; print('Python: {}.{}.{}'.format(svi[0], svi[1], svi[2]))
  64. endif
  65. redir END
  66. Log substitute(out, '\n', '', 'g')
  67. Include: workflow.vader
  68. Include: regressions.vader
  69. Execute (Cleanup):
  70. silent! call RmRf(g:temp_plugged)
  71. silent! unlet g:plugs g:plug_home g:plug_url_format
  72. silent! unlet g:temp_plugged g:first_rtp g:last_rtp g:base_rtp out
  73. silent! delf PlugStatusSorted
  74. silent! delf AssertExpect
  75. silent! delf PlugUpdated
  76. silent! delf EnsureLoaded
  77. silent! delf ReloadPlug
  78. silent! delc AssertExpect
  79. silent! unmap /
  80. silent! unmap ?
  81. call delete($PLUG_TMP)
  82. Restore