go-bcov

command module
v1.0.4 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Sep 18, 2024 License: BSD-3-Clause Imports: 21 Imported by: 0

README

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 dependency on the go tool, so you will need to have it installed.

If you face an error like go/build: go list fork/exec /opt/hostedtoolcache/go/1.23.1/x64/bin/go: no such file or directory when executing the prebuilt binary, please use the preferred installation method or try the following workaround:

GOROOT="$(go env GOROOT)" ./go-bcov

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

Documentation

The Go Gopher

There is no documentation for this package.

Directories

Path Synopsis

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL