Skip to content

Commit

Permalink
prepend test name to test errors (#1578)
Browse files Browse the repository at this point in the history
prepend test name to test errors

Add an option to prepend the test name to test errors and log messages.

Fixes #1262
  • Loading branch information
bhcleek authored and arp242 committed Nov 23, 2017
1 parent e2559cb commit 432dc7f
Show file tree
Hide file tree
Showing 3 changed files with 30 additions and 5 deletions.
7 changes: 5 additions & 2 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -31,13 +31,16 @@ IMPROVEMENTS:
In addition `:GoRename <Tab>` now lists some common options.
[[GH-1465]](https://github.com/fatih/vim-go/pull/1465).
* Disable `g:go_autodetect_gopath` by default. [[GH-1461]](https://github.com/fatih/vim-go/pull/1461).
* Add support for 'g:go_build_tags' to the `:GoTest` family of functions.
* Add support for `g:go_build_tags` to the `:GoTest` family of functions.
[[GH-1562]](https://github.com/fatih/vim-go/pull/1562).
* Pass `--tests` to gometalinter when autosaving and when a custom gometalinter
command has not been set.
[[GH-1563]](https://github.com/fatih/vim-go/pull/1563).
* Do not spam messages when command is run in a directory that does not exist.
[[GH-1527]](https://github.com/fatih/vim-go/pull/1527)
[[GH-1527]](https://github.com/fatih/vim-go/pull/1527).
* New setting `g:go_test_prepend_name` (off by default) to add the failing test
name to the output of `:GoTest`
[[GH-1578]](https://github.com/fatih/vim-go/pull/1578).

## 1.15 - (October 3, 2017)

Expand Down
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 432dc7f

Please sign in to comment.