4

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?

I159
  • 29,741
  • 31
  • 97
  • 132

3 Answers3

4

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
avelino
  • 253
  • 1
  • 7
  • Your solution works perfectly. Explain please this magic `c.out` file. Does `cc-test-reporter after-build` expect a file with `c.out` name and concrete syntax? – I159 Aug 20 '17 at 09:21
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. :)

0

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:

#!/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"