Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/dlespiau/covertool
Having fun with go coverage reports
https://github.com/dlespiau/covertool
Last synced: 20 days ago
JSON representation
Having fun with go coverage reports
- Host: GitHub
- URL: https://github.com/dlespiau/covertool
- Owner: dlespiau
- License: apache-2.0
- Created: 2017-05-27T21:29:21.000Z (over 7 years ago)
- Default Branch: master
- Last Pushed: 2021-06-24T10:54:18.000Z (over 3 years ago)
- Last Synced: 2024-06-19T02:04:34.167Z (5 months ago)
- Language: Go
- Homepage:
- Size: 83 KB
- Stars: 4
- Watchers: 2
- Forks: 6
- Open Issues: 1
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
[![Build Status](https://travis-ci.org/dlespiau/covertool.svg?branch=master)](https://travis-ci.org/dlespiau/covertool)
# `covertool`
`covertool` is a command line utility to manipulate go coverage reports. It can:
- **Merge** reports together into one single report. This is useful to gather
reports produced by different runs and consolidate the results.# Coverage beyond unit tests
Code coverage shouldn't be for unit tests only. There are many interesting
things to say about getting coverage data for integration (end to end) tests.
One may even want to gather coverage for a running service in production to get
hot paths or detect unused part of an application.I call this coverage-instrumented go binaries. The full story can be read in
this [blog post](http://damien.lespiau.name/2017/05/building-and-using-coverage.html).This repository contains support packages and tools to produce
and use coverage-instrumented Go programs.Package [cover](https://github.com/dlespiau/covertool/tree/master/pkg/cover)
can be used to build instrumented programs.Package [exit](https://github.com/dlespiau/covertool/tree/master/pkg/exit)
is an atexit implementation.The `covertool` utility can merge profiles produced by different runs of the
same binary and display the resulting code coverage:```
$ go install github.com/dlespiau/covertool
$ covertool merge -o all.go unit-tests.cov usecase1.cov usecase2.cov error1.cov error2.cov ...
$ covertool report all.go
coverage: 92.9% of statements
```Finally, the `example/calc` directory contains a fully working example:
```
$ cd $GOPATH/src/github.com/dlespiau/covertool/examples/calc
$ ./run-tests.sh
• Build the coverage-instrumented version of calc• Run the unit tests
PASS
coverage: 7.1% of statements
ok github.com/dlespiau/covertool/examples/calc 0.003s• Cover the sub() function
• Result: coverage: 57.1% of statements• Cover the error path taken when not enough arguments are provided
expected 3 arguments, got 1
• Result: coverage: 21.4% of statements• Cover the error path taken when providing an unknown operation
unknown operation: mul
• Result: coverage: 50.0% of statements• Merge all coverage profiles and report the total coverage
coverage: 92.9% of statements
```