All Projects → rillig → gobco

rillig / gobco

Licence: other
Measure branch coverage of golang tests

Programming Languages

go
31211 projects - #10 most used programming language

Projects that are alternatives of or similar to gobco

react-testing-mocha-chai-enzyme
A solid test setup for React components with Mocha, Chai, Sinon, Enzyme in a Webpack/Babel application.
Stars: ✭ 48 (+33.33%)
Mutual labels:  coverage, coverage-testing
blanket
MOVED TO GITLAB
Stars: ✭ 16 (-55.56%)
Mutual labels:  coverage, coverage-testing
phpunit-travis-ci-coverage-example
phpUnit Testing on Travis-CI with Code Coverage on CodeCov
Stars: ✭ 30 (-16.67%)
Mutual labels:  coverage
cargo-llvm-cov
Cargo subcommand to easily use LLVM source-based code coverage (-C instrument-coverage).
Stars: ✭ 181 (+402.78%)
Mutual labels:  coverage
tikione-jacocoverage
NetBeans module that provides JaCoCo code coverage for Ant based Java SE, Java EE and NetBeans Module projects (JDK5,6,7,8 compatible).
Stars: ✭ 25 (-30.56%)
Mutual labels:  coverage
metal.test
Deprecated, superseded by https://github.com/metal-ci/test
Stars: ✭ 41 (+13.89%)
Mutual labels:  coverage
example-scala
Scala coverage example
Stars: ✭ 33 (-8.33%)
Mutual labels:  coverage
goverage
go test -coverprofile for multiple packages
Stars: ✭ 87 (+141.67%)
Mutual labels:  coverage
javacard-gradle-template
JavaCard project template for building CAP and running JCardSim with gradle + coverage
Stars: ✭ 27 (-25%)
Mutual labels:  coverage
rollup-plugin-istanbul
Seamless integration between Rollup and Istanbul
Stars: ✭ 39 (+8.33%)
Mutual labels:  coverage
example-node-and-browser-qunit-ci
Example project with continuous integration for linting and cross-browser testing of isomorphic JavaScript.
Stars: ✭ 18 (-50%)
Mutual labels:  coverage
react-unit-test-practice
No description or website provided.
Stars: ✭ 16 (-55.56%)
Mutual labels:  coverage
watson-personality-insights-php
Framework Agnostic Watson Personality Insights Client
Stars: ✭ 13 (-63.89%)
Mutual labels:  coverage
LocalCoverage.jl
Trivial functions for working with coverage for packages locally.
Stars: ✭ 55 (+52.78%)
Mutual labels:  coverage
urlredir
Educational URL redirector service in Go
Stars: ✭ 26 (-27.78%)
Mutual labels:  coverage
instrumentation
Assorted pintools
Stars: ✭ 24 (-33.33%)
Mutual labels:  coverage
chanjo
Chanjo provides a better way to analyze coverage data in clinical sequencing.
Stars: ✭ 46 (+27.78%)
Mutual labels:  coverage
pytest-coverage-comment
Comments a pull request with the pytest code coverage badge and full report
Stars: ✭ 32 (-11.11%)
Mutual labels:  coverage
mutant-swarm
Mutation testing framework and code coverage for Hive SQL
Stars: ✭ 20 (-44.44%)
Mutual labels:  coverage
libfuzzer-cov
Get actually nice HTML coverage overview on libfuzzer runs
Stars: ✭ 20 (-44.44%)
Mutual labels:  coverage

Build Status codecov

GOBCO - Golang Branch Coverage

Gobco measures branch coverage of Go code.

Gobco should be used in addition to go test -cover, rather than replacing it. For example, gobco does not detect functions or methods that are completely unused, it only notices them if they contain any conditions or branches. Gobco also doesn't cover select statements.

Installation

With go1.17 or later:

$ go install github.com/rillig/gobco@latest

With go1.16 or older:

$ go get github.com/rillig/gobco

Usage

To run gobco on a single package, run it in the package directory:

$ gobco

The output typically looks like the following example, taken from package netbsd.org/pkglint:

=== RUN   Test
OK: 756 passed
--- PASS: Test (16.56s)
PASS
Branch coverage: 5452/6046
alternatives.go:28:32: condition "G.Pkg.vars.Defined(\"ALTERNATIVES_SRC\")" was 11 times false but never true
autofix.go:98:6: condition "rawLine.Lineno != 0" was 245 times true but never false
autofix.go:390:12: condition "fix.line.firstLine >= 1" was 392 times true but never false
buildlink3.go:22:5: condition "trace.Tracing" was 19 times true but never false
...
substcontext.go:136:22: condition "(value == \"pre-configure\" || value == \"post-configure\")" was once true but never false
substcontext.go:136:23: condition "value == \"pre-configure\"" was once true but never false
substcontext.go:136:51: condition "value == \"post-configure\"" was never evaluated

Even if some tests still fail, gobco can compute the code coverage:

$ gobco sample/foo.go
--- FAIL: TestFoo (0.00s)
    foo_test.go:7: wrong
FAIL
FAIL    github.com/rillig/gobco/sample  0.315s
FAIL
exit status 1

Branch coverage: 5/6
sample\foo.go:10:5: condition "Bar(a) == 10" was once false but never true

Adding custom test conditions

If you want to ensure that a certain condition in your code is covered by the tests, you can insert the desired condition into the code and just assign it to the underscore:

func square(x int) int {
    _ = x > 50
    _ = x == 0
    _ = x < 0

    return x * x
}

The compiler will see that these conditions are side-effect-free and will thus optimize them away, so there is no runtime overhead.

Since the above conditions are syntactically recognizable as boolean expressions, gobco inserts its coverage code around them.

Note that for boolean expressions that don't clearly look like boolean expressions, you have to write cond == true instead of a simple cond since as of March 2021, gobco only analyzes the code at the syntactical level, without resolving any types.

Note that the project description data, including the texts, logos, images, and/or trademarks, for each open source project belongs to its rightful owner. If you wish to add or remove any projects, please contact us at [email protected].