Codeclimate test coverage formatter for Golang

只谈情不闲聊 提交于 2021-02-07 19:23:42

问题


Nowhere in Codeclimate docs written how to specify coverage formatter. But when I'm trying to send coverage to Codeclimate:

./cc-test-reporter before-build
./cc-test-reporter after-build

It is failing:

Error: could not find any viable formatter. available formatters: simplecov, lcov, coverage.py, clover, gocov, gcov, cobertura, jacoco

I have gocov installed. Also I generated a report with goconv:

gocov test -coverprofile=out

And I tried to specify the report file to Codeclimate in various ways:

./cc-test-reporter after-build out
./cc-test-reporter after-build < out

But had no luck...

I haven't found any formatter related directives for .codeclimate.yml file. The doc is written in super "you know" style so it didn't help. How to enable/send test coverage with Codeclimate?


回答1:


Export var:

CC_TEST_REPORTER_ID=...

Run:

for pkg in $(go list ./... | grep -v vendor); do
    go test -coverprofile=$(echo $pkg | tr / -).cover $pkg
done
echo "mode: set" > c.out
grep -h -v "^mode:" ./*.cover >> c.out
rm -f *.cover

./cc-test-reporter after-build



回答2:


Abby from Code Climate Support here. Currently, the test-reporter tries to infer where the coverage data could be from a set of default paths. This is usually enough for users following the default setup of the coverage tool.

But, in the case where the output is not located on one of those paths, you can use the test-reporter low-level commands to indicate the type of coverage data and where it is. In this particular case you would do something like:

export CC_TEST_REPORTER_ID=<repo-test-reporter-id>
./cc-test-reporter before-build
gocov test -coverprofile=out 
./cc-test-reporter format-coverage --input-type gocov out 
./cc-test-reporter upload-coverage

You can check more on how to use a test-reporter command by using the flag --help. For example, ./cc-test-reporter format-coverage --help.

That should get you in a good place. If not, let us know at hello@codeclimate.com or here, and I can get more insight. :)



来源:https://stackoverflow.com/questions/45776043/codeclimate-test-coverage-formatter-for-golang

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!