Skip to content

Commit

Permalink
prepend test name to test errors
Browse files Browse the repository at this point in the history
Add an option to prepend the test name to test errors and log messages.

Fixes #1262
  • Loading branch information
bhcleek committed Nov 21, 2017
1 parent ca8ef8a commit 945701a
Show file tree
Hide file tree
Showing 2 changed files with 25 additions and 3 deletions.
20 changes: 17 additions & 3 deletions autoload/go/test.vim
Original file line number Diff line number Diff line change
Expand Up @@ -258,6 +258,7 @@ endfunction
function! s:parse_errors(lines) abort
let errors = []
let paniced = 0 " signals whether all remaining lines should be included in errors.
let test = ''

" NOTE(arslan): once we get JSON output everything will be easier :)
" https://github.com/golang/go/issues/2981
Expand All @@ -269,10 +270,23 @@ function! s:parse_errors(lines) abort
continue
endif

if !paniced
" Matches failure lines. These lines always have zero or more leading spaces followed by '-- FAIL: ', following by the test name followed by a space the duration of the test in parentheses
" e.g.:
" '--- FAIL: TestSomething (0.00s)'
let failure = matchlist(line, '^ *--- FAIL: \(.*\) (.*)$')
if get(g:, 'go_test_prepend_name', 0)
if !empty(failure)
let test = failure[1] . ': '
continue
endif
endif
endif

let tokens = []
if paniced
" Matches lines in stacktraces produced by panic. The lines always have
" one ore more leading tabs, followed by the path to the file. The file
" one or more leading tabs, followed by the path to the file. The file
" path is followed by a colon and then the line number within the file
" where the panic occurred. After that there's a space and hexadecimal
" number.
Expand Down Expand Up @@ -308,14 +322,14 @@ function! s:parse_errors(lines) abort
" 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})
call add(errors, {"text": test . line})
continue
endif

call add(errors, {
\ "filename" : file,
\ "lnum" : tokens[2],
\ "text" : out,
\ "text" : test . out,
\ })
elseif paniced
call add(errors, {"text": line})
Expand Down
8 changes: 8 additions & 0 deletions doc/vim-go.txt
Original file line number Diff line number Diff line change
Expand Up @@ -1091,6 +1091,14 @@ into the statusline. This function is also used for |'g:go_auto_type_info'|.
==============================================================================
SETTINGS *go-settings*

*'g:go_test_prepend_name'*

Prepend the name of the failed test to each test message generated by a failed
test. By default it is disabled.
>
let g:go_test_prepend_name = 0
<

*'g:go_test_timeout'*

Use this option to change the test timeout of |:GoTest|. By default it is
Expand Down

0 comments on commit 945701a

Please sign in to comment.