Hacker Newsnew | past | comments | ask | show | jobs | submitlogin

This looks awesome. I haven't tried it yet, but the hopefully it supports writing test coverage files for multiple packages, i.e. I already split the code up into separate packages and put each package in a corresponding subfolder. Using go test ./... I want to collect coverage reports for all my packages while ignoring `vendor`

So my workaround is something like the following, where I generate a coverage report for each package to later concatenate them into a final coverage report

``` for i in $(go list ./... | grep -v 'vendor') do coverName="$(basename $i).coverraw" go test --ldflags '-extldflags "-static"' -v -race -coverprofile="${coverName}" "${i}" | tee -a "${test_outfile}" done```



I've recently done that in go-ipfs project for cross package coverage (where tests in one package are counted towards coverage in all the others). You can see the results here: https://github.com/ipfs/go-ipfs/blob/ce00f384dc244f04ec7d87e...

It is quite a bit of coverage and Makefile magic, but it generates coverage results. The same file also allows us to wire in sharness testing (cli tests) to generate coverage report. It is quite important for us as we don't test cli in unit tests just in the sharness.

-------

The magic happens here: https://github.com/ipfs/go-ipfs/blob/ce00f384dc244f04ec7d87e...

Each package has its one coverage target, for each package I collect dependencies that are in our testing scope and then I create go test cover call that includes those dependencies.


Just run "make cover" :)

It does exactly what you want, and it handles overlapping coverage blocks (if two packages have tests that run the same portion of code), which just concatenating will mess up. (It uses gocovmerge behind the scenes, but it will be hidden from you.)


Awesome!

It would be nice to include something like go2xunit so you can hook the results up to the Jenkins coverage reports.


For Jenkins compatible Junit test results you must run the concatenated stdout of your `go test` through:

  go2xunit -input "${test_outfile}" -output "${GO_TEST_JUNIT_FILENAME}"
For Jenkins compatible coverage reports you must concatenate all cover profiles and use `gocov` for conversion:

  echo "creating coverage report"
  all_coverage_rawfile=$(mktemp tmptest.XXX)

  # concatenate all raw report
  echo -e "mode: atomic\n$(cat *.coverraw | grep -v 'mode: atomic')" > "${all_coverage_rawfile}"
  go tool cover -html="${all_coverage_rawfile}" -o "${GO_COVERAGE_FILENAME_HTML}"
  gocov convert "${all_coverage_rawfile}" | gocov-xml > "${GO_COVERAGE_FILENAME_XML}"
Edit: fix typo


We do that on the Cloudflare CI, but I deemed it too specific for hellogopher. (I can be convinced otherwise.)

Instead, you run hellogopher with CI=1, and it drops logs and artifacts in fixed locations, that you can then post-process as you like.


Ah. OK. Yeah. That works as well for me. Thank you




Guidelines | FAQ | Lists | API | Security | Legal | Apply to YC | Contact

Search: