From 432dc7f7f89f49c141503a28c5840e83edffbeed Mon Sep 17 00:00:00 2001 From: Billie Cleek Date: Thu, 23 Nov 2017 07:23:24 -0800 Subject: [PATCH] prepend test name to test errors (#1578) prepend test name to test errors Add an option to prepend the test name to test errors and log messages. Fixes #1262 --- CHANGELOG.md | 7 +++++-- autoload/go/test.vim | 20 +++++++++++++++++--- doc/vim-go.txt | 8 ++++++++ 3 files changed, 30 insertions(+), 5 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 6105d05eb3..fce348d045 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -31,13 +31,16 @@ IMPROVEMENTS: In addition `:GoRename ` 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) diff --git a/autoload/go/test.vim b/autoload/go/test.vim index bd8c8c70ae..945a639982 100644 --- a/autoload/go/test.vim +++ b/autoload/go/test.vim @@ -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 @@ -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. @@ -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}) diff --git a/doc/vim-go.txt b/doc/vim-go.txt index befce4fcdb..616bb1c32f 100644 --- a/doc/vim-go.txt +++ b/doc/vim-go.txt @@ -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