fatih / vim-go

Go development plugin for Vim
https://www.patreon.com/bhcleek
Other
16.01k stars 1.45k forks source link

GoCoverage not working #3489

Closed mpiexec closed 1 year ago

mpiexec commented 1 year ago

What did you do? (required: The issue will be closed when not provided)

Running :GoCoverage shows message vim-go: no test files available, at the same time :GoTest complete successfully with :GoTest. However :GoCoverageBrowser working correctly.

What did you expect to happen?

vim-go tutorial:

It parses the lines from the profile and then dynamically changes the syntax of your source code to reflect the coverage.

What happened instead?

Screenshot 2023-01-18 at 09 53 53

Configuration (MUST fill this out):

vim-go settings:

function! s:build_go_files()
  let l:file = expand('%')
  if l:file =~# '^\f\+_test\.go$'
    call go#test#Test(0, 1)
  elseif l:file =~# '^\f\+\.go$'
    call go#cmd#Build(0)
  endif
endfunction
set autowrite " Write the content of the file automatically if you call ':make'
map <C-n> :cnext<CR>
map <C-m> :cprevious<CR>
nnoremap <leader>a :cclose<CR>
autocmd FileType go nmap <leader>b :<C-u>call <SID>build_go_files()<CR>
autocmd FileType go nmap <leader>r <Plug>(go-run)
autocmd FileType go nmap <leader>t <Plug>(go-test)
autocmd FileType go nmap <Leader>c <Plug>(go-coverage-toggle)
autocmd FileType go nmap <Leader>i <Plug>(go-info)
autocmd Filetype go command! -bang A call go#alternate#Switch(<bang>0, 'edit')
autocmd Filetype go command! -bang AV call go#alternate#Switch(<bang>0, 'vsplit')
autocmd Filetype go command! -bang AS call go#alternate#Switch(<bang>0, 'split')
let g:go_list_type = "quickfix"
let g:go_addtags_transform = "camelcase"
let g:go_highlight_types = 1
let g:go_highlight_fields = 1
let g:go_highlight_functions = 1
let g:go_highlight_function_calls = 1
let g:go_highlight_operators = 1
let g:go_highlight_extra_types = 1
let g:go_highlight_build_constraints = 1
let g:go_highlight_generate_tags = 1
autocmd BufNewFile,BufRead *.go setlocal noexpandtab tabstop=4 shiftwidth=4

vim-go version:

The latest stable release, v1.28

vimrc you used to reproduce:

set nocompatible
filetype off
set rtp+=~/.vim/bundle/Vundle.vim
call vundle#begin()
Plugin 'VundleVim/Vundle.vim'
Plugin 'fatih/vim-go'
Plugin 'fatih/molokai'
Plugin 'AndrewRadev/splitjoin.vim'
Plugin 'SirVer/ultisnips'
call vundle#end()
filetype plugin indent on

let mapleader = "\<Space>"
set history=999
set showcmd
set colorcolumn=78
highlight ColorColumn ctermbg=lightgrey

" fatih/molokai
let g:rehash256 = 1
let g:molokai_original = 1
colorscheme molokai

" vim-go
function! s:build_go_files()
  let l:file = expand('%')
  if l:file =~# '^\f\+_test\.go$'
    call go#test#Test(0, 1)
  elseif l:file =~# '^\f\+\.go$'
    call go#cmd#Build(0)
  endif
endfunction
set autowrite " Write the content of the file automatically if you call ':make'
map <C-n> :cnext<CR>
map <C-m> :cprevious<CR>
nnoremap <leader>a :cclose<CR>
autocmd FileType go nmap <leader>b :<C-u>call <SID>build_go_files()<CR>
autocmd FileType go nmap <leader>r <Plug>(go-run)
autocmd FileType go nmap <leader>t <Plug>(go-test)
autocmd FileType go nmap <Leader>c <Plug>(go-coverage-toggle)
autocmd FileType go nmap <Leader>i <Plug>(go-info)
autocmd Filetype go command! -bang A call go#alternate#Switch(<bang>0, 'edit')
autocmd Filetype go command! -bang AV call go#alternate#Switch(<bang>0, 'vsplit')
autocmd Filetype go command! -bang AS call go#alternate#Switch(<bang>0, 'split')
let g:go_list_type = "quickfix"
let g:go_addtags_transform = "camelcase"
let g:go_highlight_types = 1
let g:go_highlight_fields = 1
let g:go_highlight_functions = 1
let g:go_highlight_function_calls = 1
let g:go_highlight_operators = 1
let g:go_highlight_extra_types = 1
let g:go_highlight_build_constraints = 1
let g:go_highlight_generate_tags = 1
autocmd BufNewFile,BufRead *.go setlocal noexpandtab tabstop=4 shiftwidth=4

set hidden
set switchbuf=useopen
set splitbelow splitright

nmap <leader>T :enew<cr>
nmap <leader>l :bnext<CR>
nmap <leader>h :bprevious<CR>
nmap <leader>bq :bp <BAR> bd #<CR>
nmap <leader>bl :ls<CR>

set report=0
set clipboard=unnamed
set t_Co=256
set backspace=indent,eol,start
syntax on
set modeline
set ignorecase
set incsearch
set smartcase
set scrolloff=3
set sidescrolloff=4
set wildmenu
set wildmode=list:longest,full
set wildignore+=*/tmp/*,*.so,*.swp,*.zip
set completeopt+=longest
set number
set numberwidth=5
set mouse=a
set listchars=eol:⏎,tab:\ \ ┊,trail:●,space:·
let &showbreak = '↳ '
set laststatus=2
set statusline=%<\ %t\ %m%r%y%w%=Lin:\ \%l\/\%L\ Col:\ \%c
au BufRead,BufNewFile *.libsonnet,*.jsonnet set syntax=jsonnet

Vim version (first three lines from :version):

VIM - Vi IMproved 9.0 (2022 Jun 28, compiled Dec 26 2022 13:51:26)
macOS version - arm64
Included patches: 1-1100
Compiled by Homebrew
Huge version without GUI.  Features included (+) or not (-):
+acl               +comments          +find_in_path      +lispindent        +multi_byte        +rightleft         +terminal          +wildignore
+arabic            +conceal           +float             +listcmds          +multi_lang        +ruby              +terminfo          +wildmenu
+autocmd           +cryptv            +folding           +localmap          -mzscheme          +scrollbind        +termresponse      +windows
+autochdir         +cscope            -footer            +lua               +netbeans_intg     +signs             +textobjects       +writebackup
-autoservername    +cursorbind        +fork()            +menu              +num64             +smartindent       +textprop          -X11
-balloon_eval      +cursorshape       +gettext           +mksession         +packages          -sodium            +timers            -xfontset
+balloon_eval_term +dialog_con        -hangul_input      +modify_fname      +path_extra        +sound             +title             -xim
-browse            +diff              +iconv             +mouse             +perl              +spell             -toolbar           -xpm
++builtin_terms    +digraphs          +insert_expand     -mouseshape        +persistent_undo   +startuptime       +user_commands     -xsmp
+byte_offset       -dnd               +ipv6              +mouse_dec         +popupwin          +statusline        +vartabs           -xterm_clipboard
+channel           -ebcdic            +job               -mouse_gpm         +postscript        -sun_workshop      +vertsplit         -xterm_save
+cindent           +emacs_tags        +jumplist          -mouse_jsbterm     +printer           +syntax            +vim9script
-clientserver      +eval              +keymap            +mouse_netterm     +profile           +tag_binary        +viminfo
+clipboard         +ex_extra          +lambda            +mouse_sgr         -python            -tag_old_static    +virtualedit
+cmdline_compl     +extra_search      +langmap           -mouse_sysmouse    +python3           -tag_any_white     +visual
+cmdline_hist      -farsi             +libcall           +mouse_urxvt       +quickfix          -tcl               +visualextra
+cmdline_info      +file_in_path      +linebreak         +mouse_xterm       +reltime           +termguicolors     +vreplace
   system vimrc file: "$VIM/vimrc"
     user vimrc file: "$HOME/.vimrc"
 2nd user vimrc file: "~/.vim/vimrc"
      user exrc file: "$HOME/.exrc"
       defaults file: "$VIMRUNTIME/defaults.vim"
  fall-back for $VIM: "/opt/homebrew/share/vim"
Compilation: clang -c -I. -Iproto -DHAVE_CONFIG_H -DMACOS_X -DMACOS_X_DARWIN -g -O2 -D_REENTRANT -U_FORTIFY_SOURCE -D_FORTIFY_SOURCE=1
Linking: clang -o vim -lm -lncurses -liconv -lintl -framework AppKit -L/opt/homebrew/opt/lua/lib -llua5.4 -mmacosx-version-min=12.6 -fstack-protector-strong
-L/opt/homebrew/opt/perl/lib/perl5/5.36/darwin-thread-multi-2level/CORE -lperl -L/opt/homebrew/opt/python@3.11/Frameworks/Python.framework/Versions/3.11/lib/
python3.11/config-3.11-darwin -lpython3.11 -framework CoreFoundation -lruby.3.1 -L/opt/homebrew/Cellar/ruby/3.1.3/lib

Go version (go version):

go version go1.19.4 darwin/arm64

Go environment

GO111MODULE="auto"
GOARCH="arm64"
GOBIN=""
GOCACHE="/Users/grant/Library/Caches/go-build"
GOENV="/Users/grant/Library/Application Support/go/env"
GOEXE=""
GOEXPERIMENT=""
GOFLAGS=""
GOHOSTARCH="arm64"
GOHOSTOS="darwin"
GOINSECURE=""
GOMODCACHE="/Users/grant/.go/pkg/mod"
GONOPROXY=""
GONOSUMDB=""
GOOS="darwin"
GOPATH="/Users/grant/.go"
GOPRIVATE=""
GOPROXY=""
GOROOT="/opt/homebrew/Cellar/go/1.19.4/libexec"
GOSUMDB="off"
GOTMPDIR=""
GOTOOLDIR="/opt/homebrew/Cellar/go/1.19.4/libexec/pkg/tool/darwin_arm64"
GOVCS=""
GOVERSION="go1.19.4"
GCCGO="gccgo"
AR="ar"
CC="clang"
CXX="clang++"
CGO_ENABLED="1"
GOMOD="/Users/grant/tmp/go/go.mod"
GOWORK=""
CGO_CFLAGS="-g -O2"
CGO_CPPFLAGS=""
CGO_CXXFLAGS="-g -O2"
CGO_FFLAGS="-g -O2"
CGO_LDFLAGS="-g -O2"
PKG_CONFIG="pkg-config"
GOGCCFLAGS="-fPIC -arch arm64 -pthread -fno-caret-diagnostics -Qunused-arguments -fmessage-length=0 -fdebug-prefix-map=/var/folders/dp/dzm2_jq173b43mpx9yjthgs00000gq/T/go-build527353106=/tmp/go-build -gno-record-gcc-switches -fno-common"

gopls version

golang.org/x/tools/gopls v0.11.0
    golang.org/x/tools/gopls@v0.11.0 h1:/nvKHdTtePQmrv9XN3gIUN9MOdUrKzO/dcqgbG6x8EY=
bhcleek commented 1 year ago

That message indicates that there are no test files in your package.

mpiexec commented 1 year ago

@bhcleek Ok, but test file main_test.go is there. These commands complete successfully:

:GoTest
:GoTestCompile
:GoCoverageBrowser

Results:

vim-go: [test] SUCCESS
vim-go: [compile test] SUCCESS

Manually running tests:

~> go test -v
=== RUN   Test__sum
--- PASS: Test__sum (0.00s)
PASS
ok      mymod   0.258s
bhcleek commented 1 year ago

Can you run :lcd expand('%:p:h')? After that, I'd like to know the output of these two commands: :echo glob('*_test.go') and :!ls *_test.go

mpiexec commented 1 year ago

Yep,

:echo glob('*_test.go')
" empty
:!ls *_test.go
" main_test.go
mpiexec commented 1 year ago

Maybe you mean that:

:echo ('*_test.go')
" *_test.go
bhcleek commented 1 year ago

The problem seems to be that Vim's glob function is not matching your test file, but I'm not sure why.

What's the full path to your main_test.go file?

mpiexec commented 1 year ago
~> pwd
/Users/grant/tmp/go
~> ll *go
-rw-r--r-- 1 grant staff 712 2023-01-17 17:24 main.go
-rw-r--r-- 1 grant staff 166 2023-01-17 16:11 main_test.go

But it works when I move my project into /Users/grant/go, strange things

bhcleek commented 1 year ago

That makes sense. It's because your wildignore is causing vim's glob() to ignore everything below a tmp directory.

mpiexec commented 1 year ago

It's because your wildignore is causing vim's glob() to ignore everything below a tmp directory.

Bingo! Big thanks