neovim

Neovim text editor
git clone https://git.dasho.dev/neovim.git
Log | Files | Refs | README

summarize.vim (1940B)


      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 
     17  let g:executed = 0
     18  let g:skipped = 0
     19  let g:failed = 0
     20  let g:skipped_output = []
     21  let g:failed_output = []
     22  let output = [""]
     23 
     24  if $TEST_FILTER != ''
     25    call extend(g:skipped_output, ["\tAll tests not matching $TEST_FILTER: '" .. $TEST_FILTER .. "'"])
     26  endif
     27 
     28  try
     29    " This uses the :s command to just fetch and process the output of the
     30    " tests, it doesn't actually replace anything.
     31    " And it uses "silent" to avoid reporting the number of matches.
     32    silent %s/Executed\s\+\zs\d\+\ze\s\+tests\?/\=Count(submatch(0),'executed')/egn
     33    silent %s/^SKIPPED \zs.*/\=Count(submatch(0), 'skipped')/egn
     34    silent %s/^\(\d\+\)\s\+FAILED:/\=Count(submatch(1), 'failed')/egn
     35 
     36    call extend(output, ["Skipped:"])
     37    call extend(output, skipped_output)
     38 
     39    call extend(output, [
     40          \ "",
     41          \ "-------------------------------",
     42          \ printf("Executed: %5d Tests", g:executed),
     43          \ printf(" Skipped: %5d Tests", g:skipped),
     44          \ printf("  %s: %5d Tests", g:failed == 0 ? 'Failed' : 'FAILED', g:failed),
     45          \ "",
     46          \ ])
     47    if filereadable('test.log')
     48      " outputs and indents the failed test result
     49      call extend(output, ["", "Failures: "])
     50      let failed_output = filter(readfile('test.log'), { v,k -> !empty(k)})
     51      call extend(output, map(failed_output, { v,k -> "\t".k}))
     52      " Add a final newline
     53      call extend(output, [""])
     54    endif
     55 
     56  catch  " Catch-all
     57  finally
     58    call writefile(output, 'test_result.log')  " overwrites an existing file
     59  endtry
     60 endif
     61 
     62 q!