hpc-threshold: Ensure the code coverage is above configured thresholds

[ bsd3, development, library, program ] [ Propose Tags ] [ Report a vulnerability ]

Downloads

Maintainer's Corner

Package maintainers

For package maintainers and hackage trustees

Candidates

  • No Candidates
Versions [RSS] 0.1.0.0, 0.1.0.1, 0.1.0.2, 0.1.0.3
Change log ChangeLog.md
Dependencies base (>=4.7 && <5), bytestring, hpc-threshold, interpolate, pcre-heavy [details]
License BSD-3-Clause
Copyright 2018 Ecky Putrady
Author Ecky Putrady
Maintainer eckyputrady@gmail.com
Category Development
Home page https://github.com/eckyputrady/hpc-threshold#readme
Bug tracker https://github.com/eckyputrady/hpc-threshold/issues
Source repo head: git clone https://github.com/eckyputrady/hpc-threshold
Uploaded by eckyputrady at 2018-04-25T12:26:11Z
Distributions NixOS:0.1.0.3
Executables hpc-threshold
Downloads 2278 total (14 in the last 30 days)
Rating (no votes yet) [estimated by Bayesian average]
Your Rating
  • λ
  • λ
  • λ
Status Docs uploaded by user
Build status unknown [no reports yet]

Readme for hpc-threshold-0.1.0.2

[back to package description]

hpc-threshold

Build Status Hackage version

hpc-threshold ensures the code coverage of your Haskell project is above configured thresholds. This program is meant to be used within a CI pipeline, in which the build will fail if the code coverage falls below the configured thresholds.

The program reads a configuration file named .hpc-threshold and parse Haskell Program Coverage (HPC) text from stdin. The program outputs a report and will terminate with exit code 1 if the coverage falls below the configured threshold, and exit code 0 otherwise.

User Guide

Install the program by using stack

stack install hpc-threshold

Then, create a configuration file named .hpc-threshold:

[ Threshold 
    { thresholdName = "Expressions used"
    , thresholdRegex = "(\\d+)% expressions used"
    , thresholdValue = 80.0
    }
, Threshold 
    { thresholdName = "Boolean coverage"
    , thresholdRegex = "(\\d+)% boolean coverage"
    , thresholdValue = 80.0
    }
, Threshold 
    { thresholdName = "Alternatives used"
    , thresholdRegex = "(\\d+)% alternatives used"
    , thresholdValue = 80.0
    }
, Threshold 
    { thresholdName = "Local declarations used"
    , thresholdRegex = "(\\d+)% local declarations used"
    , thresholdValue = 80.0
    }
, Threshold 
    { thresholdName = "Top-level declarations used"
    , thresholdRegex = "(\\d+)% top-level declarations used"
    , thresholdValue = 80.0
    }
]
  • thresholdRegex is the regex to be used for extracting the coverage from HPC report. There should be one (\\d+) in the regex.
  • thresholdValue is the threshold for the code coverage.
  • thresholdName will be used for the threshold report.

Then, build the coverage report:

stack test --coverage

Then, generate a text report and feed that into hpc-threshold:

stack hpc report --all 2>&1 | hpc-threshold

The stderr -> stdout redirection is necessary there because stack hpc report outputs the result in stderr, but we want to pipe that into hpc-threshold.

Then, you'll get an output similar to the following:

Code coverage threshold check: FAIL
· Expressions used: 67.0% (< 80.0%)
· Boolean coverage: 14.0% (< 80.0%)
· Alternatives used: 42.0% (< 80.0%)
✓ Local declarations used: 88.0% (≥ 80.0%)
✓ Top-level declarations used: 80.0% (≥ 80.0%)

If we check the exit code of the last process, we'll get 1 since some code coverage areas are below the configured threshold:

$ echo $?
1

For successful scenario, the output that you'll get is as follows:

Code coverage threshold check: PASS
✓ Expressions used: 67.0% (≥ 60.0%)
✓ Boolean coverage: 14.0% (≥ 10.0%)
✓ Alternatives used: 42.0% (≥ 40.0%)
✓ Local declarations used: 88.0% (≥ 80.0%)
✓ Top-level declarations used: 80.0% (≥ 80.0%)

And the exit code is 0:

$ echo $?
0

Developer Guide

See .travis.yml, under scripts section to see how to build the application