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

respect a changed g:go_test_show_name #1641

Merged
merged 1 commit into from
Jan 13, 2018
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
11 changes: 11 additions & 0 deletions autoload/go/test-fixtures/test/src/showname/showname_test.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
package main

import "testing"

func TestHelloWorld(t *testing.T) {
t.Error("so long")

t.Run("sub", func(t *testing.T) {
t.Error("thanks for all the fish")
})
}
17 changes: 10 additions & 7 deletions autoload/go/test.vim
Original file line number Diff line number Diff line change
Expand Up @@ -257,6 +257,7 @@ endfunction


let s:efm= ""
let s:go_test_show_name=0

function! s:errorformat() abort
" NOTE(arslan): once we get JSON output everything will be easier :).
Expand All @@ -265,14 +266,16 @@ function! s:errorformat() abort
" https://github.com/golang/go/issues/2981.
let goroot = go#util#goroot()

if s:efm != ""
let show_name=get(g:, 'go_test_show_name', 0)
if s:efm != "" && s:go_test_show_name == show_name
return s:efm
endif
let s:go_test_show_name = show_name

" each level of test indents the test output 4 spaces.
" TODO(bc): figure out how to use 0 or more groups of four spaces for the
" indentation. '%\\( %\\)%#' should work, but doesn't.
let indent = " %#"
" each level of test indents the test output 4 spaces. Capturing groups
" (e.g. \(\)) cannot be used in an errorformat, but non-capturing groups can
" (e.g. \%(\)).
let indent = '%\\%( %\\)%#'

" match compiler errors
let format = "%f:%l:%c: %m"
Expand All @@ -289,8 +292,8 @@ function! s:errorformat() abort
"
" e.g.:
" '--- FAIL: TestSomething (0.00s)'
if get(g:, 'go_test_show_name', 0)
let format .= ",%+G" . indent . "--- FAIL: %.%#"
if show_name
let format .= ",%G" . indent . "--- FAIL: %m (%.%#)"
else
let format .= ",%-G" . indent . "--- FAIL: %.%#"
endif
Expand Down
24 changes: 13 additions & 11 deletions autoload/go/test_test.vim
Original file line number Diff line number Diff line change
Expand Up @@ -57,6 +57,19 @@ func! Test_GoTestTimeout() abort
unlet g:go_test_timeout
endfunc

func! Test_GoTestShowName() abort
let expected = [
\ {'lnum': 0, 'bufnr': 0, 'col': 0, 'valid': 1, 'vcol': 0, 'nr': -1, 'type': '', 'pattern': '', 'text': 'TestHelloWorld'},
\ {'lnum': 6, 'bufnr': 9, 'col': 0, 'valid': 1, 'vcol': 0, 'nr': -1, 'type': '', 'pattern': '', 'text': 'so long'},
\ {'lnum': 0, 'bufnr': 0, 'col': 0, 'valid': 1, 'vcol': 0, 'nr': -1, 'type': '', 'pattern': '', 'text': 'TestHelloWorld/sub'},
\ {'lnum': 9, 'bufnr': 9, 'col': 0, 'valid': 1, 'vcol': 0, 'nr': -1, 'type': '', 'pattern': '', 'text': 'thanks for all the fish'},
\ ]

let g:go_test_show_name=1
call s:test('showname/showname_test.go', expected)
let g:go_test_show_name=0
endfunc

func! s:test(file, expected, ...) abort
if has('nvim')
" nvim mostly shows test errors correctly, but the the expected errors are
Expand Down Expand Up @@ -88,17 +101,6 @@ func! s:test(file, expected, ...) abort
let actual = getqflist()
endwhile

" for some reason, when run headless, the quickfix lists includes a line
" that should have been filtered out; remove it manually. The line is not
" present when run manually.
let i = 0
while i < len(actual)
if actual[i].text =~# '^=== RUN .*'
call remove(actual, i)
endif
let i += 1
endwhile

call assert_equal(len(a:expected), len(actual), "number of errors")
if len(a:expected) != len(actual)
return
Expand Down