hpc-threshold 0.1.0.2 → 0.1.0.3
raw patch · 3 files changed
+21/−5 lines, 3 files
Files
- ChangeLog.md +4/−0
- hpc-threshold.cabal +2/−2
- src/HPCThreshold.hs +15/−3
ChangeLog.md view
@@ -1,5 +1,9 @@ # Changelog for hpc-threshold +## 0.1.0.3++Add documentation to HPCThreshold.+ ## 0.1.0.2 Change the module name to HPCThreshold.
hpc-threshold.cabal view
@@ -2,10 +2,10 @@ -- -- see: https://github.com/sol/hpack ----- hash: da7496f9be2296b4dff3d2e626512cf322514acefdbf3e55fa9cb287d4322641+-- hash: 253eeafac618ebe072d4acd3afa728e381503d01f7b2c00473f8e3a6ee720ec7 name: hpc-threshold-version: 0.1.0.2+version: 0.1.0.3 synopsis: Ensure the code coverage is above configured thresholds description: Please see the README on Github at <https://github.com/eckyputrady/hpc-threshold#readme> category: Development
src/HPCThreshold.hs view
@@ -4,6 +4,7 @@ import Data.ByteString (ByteString) import Data.String.Interpolate +-- | Data structure for a single threshold configuration. data Threshold = Threshold { thresholdName :: String , thresholdRegex :: ByteString@@ -11,9 +12,15 @@ } deriving (Read, Show, Eq) type Coverage = Double++-- | The result of evaluation. The _3 indicates whether the coverage passes the threshold or not. type ThresholdEvaluationResult = (Threshold, Coverage, Bool) -extractCoverage :: String -> ByteString -> Coverage+-- | Extract the coverage from input string using a regex string+extractCoverage + :: String -- ^ The input string+ -> ByteString -- ^ The regex to extract the coverage. The regex should contain `(\\d+)` capture otherwise the coverage is always be 0.+ -> Coverage -- ^ The extracted coverage extractCoverage src regexStr = case compileM regexStr [] of Left e ->@@ -25,6 +32,7 @@ _ -> 0 +-- | Evaluate the given string against the given threshold, producing an evaluation result evaluate :: String -> Threshold -> ThresholdEvaluationResult evaluate src threshold = let @@ -35,6 +43,7 @@ in (threshold, coverage, isPass) +-- | Produce a human-friendly output of the evaluation result reportThreshold :: ThresholdEvaluationResult -> String reportThreshold (Threshold tName _ tValue, coverage, isPass) = let@@ -43,7 +52,11 @@ in [i|#{remark} #{tName}: #{coverage}% (#{sign} #{tValue}%)|] -evaluateAndReport :: String -> [Threshold] -> (String, Bool)+-- | Evaluate a string against a list of thresholds configuration and produce a report+evaluateAndReport+ :: String -- ^ The input string+ -> [Threshold] -- ^ The list of thresholds+ -> (String, Bool) -- ^ Pair of report and whether there is any coverage under thresholds evaluateAndReport src thresholds = let evalResults = map (evaluate src) thresholds@@ -55,4 +68,3 @@ report = unlines $ reportSummary : map reportThreshold evalResults in (report, isAllThresholdPass)-