rillig / gobco

Measure branch coverage of golang tests
62 stars 12 forks source link

Fails with “argument must be inside $GOPATH/src” #17

Closed vfaronov closed 3 years ago

vfaronov commented 3 years ago

Trying to run gobco 0.9.4 on a module I’m developing (outside of $GOPATH), I get:

$ gobco
argument "." must be inside "/home/vasiliy/.cache/gopath/src"

If I set up a $GOPATH specially for gobco, it still doesn’t work:

$ go env GOPATH
/home/vasiliy/tmp/gunison/gopath

$ head -1 /home/vasiliy/tmp/gunison/gopath/src/github.com/vfaronov/gunison/go.mod 
module github.com/vfaronov/gunison

$ gobco github.com/vfaronov/gunison
argument "github.com/vfaronov/gunison" must be inside "/home/vasiliy/tmp/gunison/gopath/src"
rillig commented 3 years ago

Hi,

In your last command, the argument github.com/vfaronov/gunison looks misleading to me, as it could be either a relative directory name or a module name. Gobco always interprets it as a directory name, so it may help to just cd /home/vasiliy/tmp/gunison/gopath/src/ before running Gobco. Please try this and tell me whether it worked.

I know that gobco does not support modules. This is just because I never needed support for modules myself. Could you perhaps have a look how to implement them, your advantage is that you have a good test case at hand, which I don't.

I don't expect it to be any difficult. Have a look at the method gobco.rel in main.go, which generates the error you got. The idea of the methods gobco.rel and gobco.prepareTmp is to copy all code that will be instrumented into a temporary directory. If everything goes well, this is the only code you need to touch.

Roland

vfaronov commented 3 years ago

I got it to work by setting up an actual GOPATH with GO111MODULE=off and all my dependencies (via go get -t github.com/vfaronov/gunison). Now gobco works if I run it inside gunison or give it the path to that directory.

Could you perhaps have a look how to implement them

Not at the moment, sorry.

Thank you for help and for developing this tool.