test.vader 2.8 KB

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