英文:
Codeclimate test coverage formatter for Golang
问题
在Codeclimate文档中没有写明如何指定覆盖率格式化程序。但是当我尝试将覆盖率发送到Codeclimate时:
./cc-test-reporter before-build
./cc-test-reporter after-build
它失败了:
> 错误:找不到任何可行的格式化程序。可用的格式化程序有:simplecov、lcov、coverage.py、clover、gocov、gcov、cobertura、jacoco
我已经安装了gocov
。我还使用goconv
生成了一个报告:
gocov test -coverprofile=out
我尝试以各种方式将报告文件指定给Codeclimate:
./cc-test-reporter after-build out
./cc-test-reporter after-build < out
但是没有成功...
我没有找到任何与格式化程序相关的.codeclimate.yml
文件指令。文档写得非常晦涩,所以没有帮助。如何在Codeclimate中启用/发送测试覆盖率?
英文:
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
得分: 4
导出变量:
CC_TEST_REPORTER_ID=...
运行:
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
英文:
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
得分: 2
Abby来自Code Climate支持团队。目前,test-reporter
尝试从一组默认路径中推断覆盖率数据的位置。这通常对于按照覆盖工具的默认设置进行操作的用户来说已经足够了。
但是,如果输出不位于这些路径之一,您可以使用test-reporter
的低级命令来指示覆盖率数据的类型和位置。在这种特殊情况下,您可以执行以下操作:
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
您可以通过使用--help
标志来查看如何使用test-reporter
命令的更多信息。例如,./cc-test-reporter format-coverage --help
。
这样应该能帮助您解决问题。如果不能,请通过hello@codeclimate.com或在这里告诉我们,我可以提供更多帮助。
英文:
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.
答案3
得分: 0
对于仍然遇到这个问题的人:
对我来说,问题是我错误地将输出覆盖文件命名为"cp.out",而不是cc-test-reporter
所期望的"c.out"。
这是我的工作脚本:
#!/bin/sh
inputFile=$1
while IFS="=" read -r repo reporterID
do
cd "$HOME/go/src/github.com/$repo" || exit
echo "performing code coverage upload for $repo"
git checkout master && git pull ##don't know if main is used
cp -f "$HOME/shellScripts/test-reporter-latest-darwin-amd64" .
chmod 755 test-reporter-latest-darwin-amd64
./test-reporter-latest-darwin-amd64 before-build
export CC_TEST_REPORTER_ID="$reporterID"
go test -coverprofile=c.out ./...
./test-reporter-latest-darwin-amd64 after-build --prefix "github.com/$repo"
echo
echo "======================="
echo
done < "$inputFile"
希望对你有帮助!
英文:
For those of you that still have this problem:
For me - the problem was that I had incorrectly named the output coverage file as "cp.out" instead of "c.out" which is what the cc-test-reporter
expects.
Here's my working script:
<!-- begin snippet: js hide: false console: true babel: false -->
<!-- language: lang-html -->
#!/bin/sh
inputFile=$1
while IFS="=" read -r repo reporterID
do
cd "$HOME""/go/src/github.com/""$repo" || exit
echo "performing code coverage upload for ""$repo"
git checkout master && git pull ##don't know if main is used
cp -f "$HOME"/shellScripts/test-reporter-latest-darwin-amd64 .
chmod 755 test-reporter-latest-darwin-amd64
./test-reporter-latest-darwin-amd64 before-build
export CC_TEST_REPORTER_ID="$reporterID"
go test -coverprofile=c.out ./...
./test-reporter-latest-darwin-amd64 after-build --prefix "github.com/""$repo"
echo
echo "======================="
echo
done < "$inputFile"
<!-- end snippet -->
通过集体智慧和协作来改善编程学习和解决问题的方式。致力于成为全球开发者共同参与的知识库,让每个人都能够通过互相帮助和分享经验来进步。
评论