Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Code coverage is not working with Go 1.11 Modules #378

Open
estahn opened this issue Dec 5, 2018 · 11 comments
Open

Code coverage is not working with Go 1.11 Modules #378

estahn opened this issue Dec 5, 2018 · 11 comments
Assignees

Comments

@estahn
Copy link

estahn commented Dec 5, 2018

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.

@ale7714
Copy link
Contributor

ale7714 commented Dec 21, 2018

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

etiennedi added a commit to weaviate/weaviate that referenced this issue Feb 6, 2019
it is deactivated anyway, i.e. we don't see the results, however it also
seems to be problematic around go 1.11 modules, see:
codeclimate/test-reporter#378
@codersbrew
Copy link

Any updates on this?

@ale7714
Copy link
Contributor

ale7714 commented Mar 31, 2019

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

@codersbrew
Copy link

Will try it out, thanks!

@Naatan
Copy link

Naatan commented Apr 5, 2019

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

@Naatan
Copy link

Naatan commented Apr 5, 2019

Nevermind, prefix works! Trailing slash is vital.

@efueger efueger closed this as completed May 1, 2019
@Naatan
Copy link

Naatan commented May 1, 2019

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

@efueger
Copy link
Member

efueger commented May 2, 2019

Ah! Sorry about that @Naatan. Reopening 👌

@efueger efueger reopened this May 2, 2019
@dingdayu
Copy link

dingdayu commented Aug 1, 2019

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

@kamilsk
Copy link

kamilsk commented Aug 8, 2019

--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: kamilsk/retry@bc15a54

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

@sawadashota
Copy link

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

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

9 participants