Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

go test coverprofile cannot find package

Tags:

go

When I try the following

go test -coverprofile=coverage.out

I get this coverage.out:

mode: set
_/Users/gert/Desktop/httx/auth.go:10.66,11.54 1 0
_/Users/gert/Desktop/httx/auth.go:11.54,13.89 2 0
_/Users/gert/Desktop/httx/auth.go:17.3,17.11 1 0
_/Users/gert/Desktop/httx/auth.go:13.89,16.4 2 0
_/Users/gert/Desktop/httx/auth.go:22.42,25.2 2 0
...

But when I then do

go tool cover -func=coverage.out

coverage.out doesn't seem to be correctly formatted?

cover: can't find "auth.go": cannot find package "_/Users/gert/Desktop/httx/" in any of:                                     
        /usr/local/Cellar/go/1.7.1/libexec/src/_/Users/gert/Desktop/httx (from $GOROOT)                                      
        /Users/gert/go/src/_/Users/gert/Desktop/httx (from $GOPATH)

EDIT: Note that go test -cover works.

PASS                                                                                                                         
coverage: 29.7% of statements                                                                                                
ok      _/Users/gert/Desktop/httx       0.015s
like image 605
Gert Cuykens Avatar asked Jan 05 '23 07:01

Gert Cuykens


1 Answers

Your package /Users/gert/Desktop/httx/ is outside of your $GOPATH which is /Users/gert/go. Move the httx package somewhere under your $GOPATH and it will work fine. You could move it to /Users/gert/go/src/httx or probably something like /Users/gert/go/src/github.com/your-github-name/httx (assuming you use GitHub).

like image 150
jcbwlkr Avatar answered Jan 13 '23 08:01

jcbwlkr