diff --git a/src/luacov/defaults.lua b/src/luacov/defaults.lua index 81bc82a..92c790f 100644 --- a/src/luacov/defaults.lua +++ b/src/luacov/defaults.lua @@ -17,9 +17,13 @@ return { -- using `luacov.tick` module. Default: false. tick = false, - --- Include all files including untested ones in the report + --- Include all files including untested ones in the report. includeuntested = false, + --- Minimum coverage requirement required to pass the coverage. + --- Default is 0 + minimumcoverage = 0, + --- Stats file updating frequency for `luacov.tick`. -- The lower this value - the more frequently results will be written out to the stats file. -- You may want to reduce this value (to, for example, 2) to avoid losing coverage data in diff --git a/src/luacov/reporter.lua b/src/luacov/reporter.lua index be82105..f5bebb0 100644 --- a/src/luacov/reporter.lua +++ b/src/luacov/reporter.lua @@ -320,6 +320,16 @@ local function coverage_to_string(hits, missed) return ("%.2f%%"):format(hits/total*100.0) end +local function coverage_percentage(hits,missed) + local total = hits + missed + + if total == 0 then + total = 1 + end + + return (hits/total*100.0) +end + function DefaultReporter:on_end() self:write(("="):rep(78), "\n") self:write("Summary\n") @@ -384,6 +394,11 @@ function DefaultReporter:on_end() end end end + + if (coverage_percentage(total_hits,total_missed)) < self:config().minimumcoverage then + print("Failed to hit the required minimum coverage.") + os.exit(1) + end end end