Skip to content

Commit e77feff

Browse files
committed
Added minimum coverage constraint feauture
1 parent 5818509 commit e77feff

File tree

2 files changed

+20
-1
lines changed

2 files changed

+20
-1
lines changed

src/luacov/defaults.lua

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,9 +17,13 @@ return {
1717
-- using `luacov.tick` module. Default: false.
1818
tick = false,
1919

20-
--- Include all files including untested ones in the report
20+
--- Include all files including untested ones in the report.
2121
includeuntested = false,
2222

23+
--- Minimum coverage requirement required to pass the coverage.
24+
--- Default is 0
25+
minimumcoverage = 0,
26+
2327
--- Stats file updating frequency for `luacov.tick`.
2428
-- The lower this value - the more frequently results will be written out to the stats file.
2529
-- You may want to reduce this value (to, for example, 2) to avoid losing coverage data in

src/luacov/reporter.lua

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -320,6 +320,16 @@ local function coverage_to_string(hits, missed)
320320
return ("%.2f%%"):format(hits/total*100.0)
321321
end
322322

323+
local function coverage_percentage(hits,missed)
324+
local total = hits + missed
325+
326+
if total == 0 then
327+
total = 1
328+
end
329+
330+
return (hits/total*100.0)
331+
end
332+
323333
function DefaultReporter:on_end()
324334
self:write(("="):rep(78), "\n")
325335
self:write("Summary\n")
@@ -384,6 +394,11 @@ function DefaultReporter:on_end()
384394
end
385395
end
386396
end
397+
398+
if (coverage_percentage(total_hits,total_missed)) < self:config().minimumcoverage then
399+
print("Failed to hit the required minimum coverage.")
400+
os.exit(1)
401+
end
387402
end
388403

389404
end

0 commit comments

Comments
 (0)