Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

prepend test name to test errors #1578

Merged
merged 2 commits into from
Nov 23, 2017
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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