summarize.vim 1.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263
  1. set cpo&vim
  2. if 1
  3. " This is executed only with the eval feature
  4. set nocompatible
  5. set viminfo=
  6. func Count(match, type)
  7. if a:type ==# 'executed'
  8. let g:executed += (a:match+0)
  9. elseif a:type ==# 'failed'
  10. let g:failed += a:match+0
  11. elseif a:type ==# 'skipped'
  12. let g:skipped += 1
  13. call extend(g:skipped_output, ["\t" .. a:match])
  14. endif
  15. endfunc
  16. let g:executed = 0
  17. let g:skipped = 0
  18. let g:failed = 0
  19. let g:skipped_output = []
  20. let g:failed_output = []
  21. let output = [""]
  22. if $TEST_FILTER != ''
  23. call extend(g:skipped_output, ["\tAll tests not matching $TEST_FILTER: '" .. $TEST_FILTER .. "'"])
  24. endif
  25. try
  26. " This uses the :s command to just fetch and process the output of the
  27. " tests, it doesn't actually replace anything.
  28. " And it uses "silent" to avoid reporting the number of matches.
  29. silent %s/Executed\s\+\zs\d\+\ze\s\+tests\?/\=Count(submatch(0),'executed')/egn
  30. silent %s/^SKIPPED \zs.*/\=Count(submatch(0), 'skipped')/egn
  31. silent %s/^\(\d\+\)\s\+FAILED:/\=Count(submatch(1), 'failed')/egn
  32. call extend(output, ["Skipped:"])
  33. call extend(output, skipped_output)
  34. call extend(output, [
  35. \ "",
  36. \ "-------------------------------",
  37. \ printf("Executed: %5d Tests", g:executed),
  38. \ printf(" Skipped: %5d Tests", g:skipped),
  39. \ printf(" %s: %5d Tests", g:failed == 0 ? 'Failed' : 'FAILED', g:failed),
  40. \ "",
  41. \ ])
  42. if filereadable('test.log')
  43. " outputs and indents the failed test result
  44. call extend(output, ["", "Failures: "])
  45. let failed_output = filter(readfile('test.log'), { v,k -> !empty(k)})
  46. call extend(output, map(failed_output, { v,k -> "\t".k}))
  47. " Add a final newline
  48. call extend(output, [""])
  49. endif
  50. catch " Catch-all
  51. finally
  52. call writefile(output, 'test_result.log') " overwrites an existing file
  53. endtry
  54. endif
  55. q!