Skip to content
/ go-bcov Public

go-bcov is a tool to calculate branch coverage from go coverage reports

License

Notifications You must be signed in to change notification settings

ALX99/go-bcov

Repository files navigation

go-bcov

go-bcov is a tool to calculate branch coverage from Go coverage reports.

It works by reading the coverage file generated by go to get the line coverage and then concurrently parses the package AST to understand which branches have been covered. Both if and switch statements are supported.

The coverage file is read from standard input and the report is generated to standard output.

Installation

Preferred

go install github.com/alx99/go-bcov@v1

Prebuilt binaries

You can download binaries from the releases page.
Note that this project has a runtime dependency on go, so you will need to have it installed.

Usage

Sonarqube coverage report

go test -coverprofile=coverage.out -covermode count ./...
go-bcov -format sonar-cover-report < coverage.out > coverage.xml

# and upload...
sonar-scanner-cli \
    -Dsonar.sources=. -Dsonar.exclusions=**/*_test.go,**/*_mock.go \
    -Dsonar.tests=. -Dsonar.test.inclusions=**/*_test.go \
    -Dsonar.coverageReportPaths=coverage.xml -Dsonar.go.coverage.reportPaths=coverage.txt

Supported output formats