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

gocov + Jenkins setup: no such file or directory

Open severedsea opened this issue 7 years ago • 2 comments

Just want to share my experience of setting up code climate test reporter with golang on Jenkins.

Following this example:

  1. Downloaded cc-test-reporter into the project root (i.e. GOPATH/src/github/org/project)
  2. Executed go test -coverprofile and generated c.out on project root
  3. Executed ./cc-test-reporter after-build without --prefix flag, since I'm assuming --prefix is for some custom use case.
  4. Encountered no such file or directory error on a source file, where source file will look like github/org/project/file.go as per standard go test -coverprofile. Noticed that the error is encountered whenafter-build is trying to upload coverage here

As a workaround, I had to add --prefix github/org/project on after-build because:

  1. cc-test-reporter is on the project root, and when it tries to open the source files, the path has to be relative to where cc-test-reporter is.
  2. I tried placing cc-test-reporter in the GOPATH/src directory so that I don't need to add --prefix, but encountered some issues here because GOPATH/src is not a git repository.

Noticed that it's stated here the need to add --prefix.

But just feel that the steps I followed is not out of the norm (idiomatic) for Golang and maybe the trimming of prefix has to be handled in gocov formatter or if not, maybe documented this behaviour in go examples?

severedsea avatar Feb 27 '18 02:02 severedsea

Thanks @severedsea! I had the same problem until you pointed out the --prefix.

A question, do you have a loop to test all your packages and append the coverage result to a file? And then did you need to remove all the rows with "mode: set" lines?

flemay avatar Apr 19 '18 03:04 flemay

Using Go 1.10, you can output coverage result even if you’re testing multiple packages like so:

go test -coverprofile=c.out ./...

Didn't need to manually sanitise c.out

severedsea avatar Apr 19 '18 11:04 severedsea