项目作者: eckyputrady

项目描述 :
Small utility for validating whether HPC result is above defined thresholds
高级语言: Haskell
项目地址: git://github.com/eckyputrady/hpc-threshold.git
创建时间: 2018-04-22T15:48:34Z
项目社区:https://github.com/eckyputrady/hpc-threshold

开源协议:Other

下载


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

  1. stack install hpc-threshold

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

  1. [ Threshold
  2. { thresholdName = "Expressions used"
  3. , thresholdRegex = "(\\d+)% expressions used"
  4. , thresholdValue = 80.0
  5. }
  6. , Threshold
  7. { thresholdName = "Boolean coverage"
  8. , thresholdRegex = "(\\d+)% boolean coverage"
  9. , thresholdValue = 80.0
  10. }
  11. , Threshold
  12. { thresholdName = "Alternatives used"
  13. , thresholdRegex = "(\\d+)% alternatives used"
  14. , thresholdValue = 80.0
  15. }
  16. , Threshold
  17. { thresholdName = "Local declarations used"
  18. , thresholdRegex = "(\\d+)% local declarations used"
  19. , thresholdValue = 80.0
  20. }
  21. , Threshold
  22. { thresholdName = "Top-level declarations used"
  23. , thresholdRegex = "(\\d+)% top-level declarations used"
  24. , thresholdValue = 80.0
  25. }
  26. ]
  • 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:

  1. stack test --coverage

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

  1. 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:

  1. Code coverage threshold check: FAIL
  2. · Expressions used: 67.0% (< 80.0%)
  3. · Boolean coverage: 14.0% (< 80.0%)
  4. · Alternatives used: 42.0% (< 80.0%)
  5. Local declarations used: 88.0% (≥ 80.0%)
  6. 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:

  1. $ echo $?
  2. 1

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

  1. Code coverage threshold check: PASS
  2. Expressions used: 67.0% (≥ 60.0%)
  3. Boolean coverage: 14.0% (≥ 10.0%)
  4. Alternatives used: 42.0% (≥ 40.0%)
  5. Local declarations used: 88.0% (≥ 80.0%)
  6. Top-level declarations used: 80.0% (≥ 80.0%)

And the exit code is 0:

  1. $ echo $?
  2. 0

Developer Guide

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