test-reporter icon indicating copy to clipboard operation
test-reporter copied to clipboard

Code coverage is not working with Go 1.11 Modules

Open estahn opened this issue 7 years ago • 11 comments

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 avatar Dec 05 '18 04:12 estahn

@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.

ale7714 avatar Dec 21 '18 15:12 ale7714

Any updates on this?

codersbrew avatar Mar 29 '19 03:03 codersbrew

@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.

ale7714 avatar Mar 31 '19 18:03 ale7714

Will try it out, thanks!

codersbrew avatar Apr 01 '19 18:04 codersbrew

The --prefix workaround does not work. I've also tried symlinking the project to my GOPATH, but same result.

Naatan avatar Apr 05 '19 18:04 Naatan

Nevermind, prefix works! Trailing slash is vital.

Naatan avatar Apr 05 '19 18:04 Naatan

@efueger Is this fixed? Seems there's only a workaround so far, not an actual fix.

Naatan avatar May 01 '19 16:05 Naatan

Ah! Sorry about that @Naatan. Reopening 👌

efueger avatar May 02 '19 19:05 efueger

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

dingdayu avatar Aug 01 '19 14:08 dingdayu

--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

kamilsk avatar Aug 08 '19 18:08 kamilsk

$(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

sawadashota avatar Dec 27 '19 07:12 sawadashota