Skip to content

Command line tool for coverage reporting and validation

License

Notifications You must be signed in to change notification settings

mcubik/goverreport

Repository files navigation

goverreport

Command line tool for coverage reporting and validation.

travis-c Coverage Status Maintainability

Installation

go get -u github.com/mcubik/goverreport

Usage

goverreport reads a coverage profile and prints a report on the terminal. Optionally, it can also validate a coverage threshold.

Usage: goverreport [flags] -coverprofile=coverprofile.out

Flags:
  -coverprofile string
        Coverage output file (default "coverage.out")
  -metric string
        Use a specific metric for the threshold: block, stmt (default "block")
  -order string
        Sort order: asc, desc (default "asc")
  -packages
        Report coverage per package instead of per file
  -sort string
        Column to sort by: filename, package, block, stmt, missing-blocks, missing-stmts (default "filename")
  -threshold float
        Return an error code of 1 if the coverage is below a threshold

Example

$ goverreport -sort=block -order=desc -threshold=85
+------------------+--------+---------+-------+---------+---------------+--------------+
|       FILE       | BLOCKS | MISSING | STMTS | MISSING | BLOCK COVER % | STMT COVER % |
+------------------+--------+---------+-------+---------+---------------+--------------+
| report/view.go   |      4 |       0 |     7 |       0 |        100.00 |       100.00 |
| report/report.go |     47 |       5 |    60 |       5 |         89.36 |        91.67 |
| main.go          |     30 |      10 |    44 |      15 |         66.67 |        65.91 |
+------------------+--------+---------+-------+---------+---------------+--------------+
|      TOTAL       |   81   |   15    |  111  |   20    |     81 48     |    81 98     |
+------------------+--------+---------+-------+---------+---------------+--------------+
exit status 1

Configuration

You can use a fixed threshold by configuring it in the .goverreport.yml configuration file. This file also lets you configure the root path of the project, so that it gets stripped from the names of the files, and a set of path prefixes to be excluded from the report.

Here's an example:

threshold: 85
thresholdType: stmt
root: "github.com/mcubik/goverreport"
exclusions: [test/it] # Exclude packages prefixed with "test/it"