Skip to content

Commit

Permalink
improve test output handling
Browse files Browse the repository at this point in the history
* Use stricter regular expression to correctly identify potential file
  references in test output. When `go test` outputs a test failure file
  location, the file is preceded with at least one tab. If there is
  leading space on the line, then it's a subtest that failed. Use that
  to more accurately disregard lines that will not refer to files.

* Preserve multi-line test failure output by similarly checking for at
  least one tab ahead of the output.

* Preserve output that seemingly *should* refer to a file, but for
  whatever does not, but don't make it a file reference for the purposes
  of quickfix and location lists.

* Preserve all lines of stack traces.

* Correctly recognize file locations in stack traces.
  • Loading branch information
bhcleek committed Oct 15, 2017
1 parent f6196ad commit 69a176f
Showing 1 changed file with 31 additions and 9 deletions.
40 changes: 31 additions & 9 deletions autoload/go/test.vim
Original file line number Diff line number Diff line change
Expand Up @@ -253,28 +253,50 @@ endfunction

function! s:parse_errors(lines) abort
let errors = []
let paniced = 0 " signals whether all remaining lines should be included in errors.

" NOTE(arslan): once we get JSON output everything will be easier :)
" https://github.com/golang/go/issues/2981
for line in a:lines
let fatalerrors = matchlist(line, '^\(fatal error:.*\)$')
let tokens = matchlist(line, '^\s*\(.\{-}\.go\):\(\d\+\):\s*\(.*\)')

let fatalerrors = matchlist(line, '^\(\(fatal error\|panic\):.*\)$')
if !empty(fatalerrors)
call add(errors, {"text": fatalerrors[1]})
elseif !empty(tokens)
let paniced = 1
call add(errors, {"text": line})
continue
endif

let tokens = []
if paniced
let tokens = matchlist(line, '^\t\+\(.\{-}\.go\):\(\d\+\) \(+0x.*\)')
else
let tokens = matchlist(line, '^ *\t\+\(.\{-}\.go\):\(\d\+\):\s*\(.*\)')
endif

if !empty(tokens) " Check whether the line may refer to a file.
" strip endlines of form ^M
let out = substitute(tokens[3], '\r$', '', '')
let file = fnamemodify(tokens[1], ':p')

" Preserve the line when the filename is not readable. This is an
" unusual case, but possible; any test that produces lines that match
" the pattern used in the matchlist assigned to tokens is a potential
" source of this condition. For instance, github.com/golang/mock/gomock
" will sometimes produce lines that satisfy this condition.
if !filereadable(file)
call add(errors, {"text": line})
continue
endif

call add(errors, {
\ "filename" : fnamemodify(tokens[1], ':p'),
\ "filename" : file,
\ "lnum" : tokens[2],
\ "text" : out,
\ })
elseif paniced
call add(errors, {"text": line})
elseif !empty(errors)
" Preserve indented lines.
" This comes up especially with multi-line test output.
if match(line, '^\s') >= 0
" Preserve indented lines. This comes up especially with multi-line test output.
if match(line, '^ *\t\+') >= 0
call add(errors, {"text": line})
endif
endif
Expand Down

0 comments on commit 69a176f

Please sign in to comment.