Code coverage is not working with Go 1.11 Modules
Golang 1.11 supports to place the src directory into a non-$GOPATH directory, e.g. ~/project in CircleCI.
The generated c.out files will look something like that:
mode: set
github.com/hipages/php-fpm_exporter/phpfpm/phpfpm.go:117.45,121.2 3 0
github.com/hipages/php-fpm_exporter/phpfpm/phpfpm.go:124.45,129.28 3 0
github.com/hipages/php-fpm_exporter/phpfpm/phpfpm.go:137.2,143.12 4 0
Now, cc-test-reporter reads the file with the following error message:
./cc-test-reporter format-coverage -t gocov .cover/c.out
ERRO[0000] failed to read file github.com/hipages/php-fpm_exporter/phpfpm/exporter.go
open github.com/hipages/php-fpm_exporter/phpfpm/exporter.go: no such file or directory
Error: open github.com/hipages/php-fpm_exporter/phpfpm/exporter.go: no such file or directory
I would guess cc-test-reporter should look up the module in go.mod and adjust the path for c.out accordingly.
@estahn thank you for writing! I'll add this to our backlog. We don't have an ETA yet on an update but we will be updating this issue as soon as we have some news.
Any updates on this?
@estahn 👋 looking back on this issue. I think using the --prefix would be enough to indicate test-reporter where the root of the project is.
I would suggest using ./cc-test-reporter format-coverage -t gocov --prefix github.com/hipages/php-fpm_exporter .cover/c.out
@codersbrew can you consider also trying something like the suggestion above?
Apologies on the late response! Thank you for writing.
Will try it out, thanks!
The --prefix workaround does not work. I've also tried symlinking the project to my GOPATH, but same result.
Nevermind, prefix works! Trailing slash is vital.
@efueger Is this fixed? Seems there's only a workaround so far, not an actual fix.
Ah! Sorry about that @Naatan. Reopening 👌
at Go Modules:
sudo: required
language: go
env:
global:
- GO111MODULE=on
go:
- 1.11.x
- 1.12.x
before_script:
- curl -L https://codeclimate.com/downloads/test-reporter/test-reporter-latest-linux-amd64 > ./test-reporter
- chmod +x ./test-reporter
- ./test-reporter before-build
script:
- make test
- go test -coverprofile c.out .
after_script:
- ./test-reporter format-coverage -t gocov --prefix phonedata
- ./test-reporter upload-coverage
file: .travis.yml
--prefix $(go list -m) works well at macOS, but doesn't work at Linux (in Travis CI), so, I fixed it by sed -i "s|$(go list -m)/||g" c.out: https://github.com/kamilsk/retry/commit/bc15a545043daef6794a0f83f844c45f13b03d82
env:
global:
- CODECLIMATE=https://codeclimate.com/downloads/test-reporter/test-reporter-latest-linux-amd64
- GO111MODULE=on
after_script:
- export EXIT_CODE=$TRAVIS_TEST_RESULT
- export PREFIX=$(basename $(go list -m))
- ./cc-test-reporter after-build -t gocov -p $PREFIX
$(basename $(go list -m)) doesn't work and $(go list -m) works for me.
So I wrote ./cc-test-reporter after-build -t gocov -p $(go list -m) as after build script.
CI: CircleCI Go: 1.3