view src/testdir/summarize.vim @ 16976:7160dcd5c1d2 v8.1.1488

patch 8.1.1488: summary of tests has incorrect failed count commit https://github.com/vim/vim/commit/150f0550f45b836200a189e4d34417f4d3467455 Author: Bram Moolenaar <Bram@vim.org> Date: Fri Jun 7 21:29:50 2019 +0200 patch 8.1.1488: summary of tests has incorrect failed count Problem: Summary of tests has incorrect failed count. Solution: Add to the failed count instead of setting it. (Christian Brabandt)
author Bram Moolenaar <Bram@vim.org>
date Fri, 07 Jun 2019 21:30:05 +0200
parents 54c2fe0eff03
children 7f95fa061abc
line wrap: on
line source

set nocp
if 1
  " This is executed with the eval feature
  set nocp
  func Count(match, type)
    if a:type ==# 'executed'
      let g:executed += (a:match+0)
    elseif a:type ==# 'failed'
      let g:failed += a:match+0
    elseif a:type ==# 'skipped'
      let g:skipped += 1
      call extend(g:skipped_output, ["\t".a:match])
    endif
  endfunc

  let g:executed = 0
  let g:skipped = 0
  let g:failed = 0
  let g:skipped_output = []
  let g:failed_output = []
  let output = [""]

  try
    " This uses the :s command to just fetch and process the output of the
    " tests, it doesn't acutally replay anything
    %s/^Executed\s\+\zs\d\+\ze\s\+tests/\=Count(submatch(0),'executed')/egn
    %s/^SKIPPED \zs.*/\=Count(submatch(0), 'skipped')/egn
    %s/^\(\d\+\)\s\+FAILED:/\=Count(submatch(1), 'failed')/egn

    call extend(output, ["Skipped:"]) 
    call extend(output, skipped_output)

    call extend(output, [
          \ "",
          \ "-------------------------------",
          \ printf("Executed: %5d Tests", g:executed),
          \ printf(" Skipped: %5d Tests", g:skipped),
          \ printf("  %s: %5d Tests", g:failed == 0 ? 'Failed' : 'FAILED', g:failed),
          \ "",
          \ ]) 
    if filereadable('test.log')
      " outputs and indents the failed test result
      call extend(output, ["", "Failures: "])
      let failed_output = filter(readfile('test.log'), { v,k -> !empty(k)})
      call extend(output, map(failed_output, { v,k -> "\t".k}))
      " Add a final newline
      call extend(output, [""])
    endif

  catch  " Catch-all
  finally
    call writefile(output, 'test_result.log')  " overwrites an existing file
  endtry
endif

q!