Skip to content

Commit

Permalink
Added minimum coverage constraint feauture
Browse files Browse the repository at this point in the history
  • Loading branch information
InEdited committed Apr 8, 2019
1 parent 5818509 commit e77feff
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 1 deletion.
6 changes: 5 additions & 1 deletion src/luacov/defaults.lua
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
15 changes: 15 additions & 0 deletions src/luacov/reporter.lua
Original file line number Diff line number Diff line change
Expand Up @@ -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")
Expand Down Expand Up @@ -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
Expand Down

0 comments on commit e77feff

Please sign in to comment.