File tree Expand file tree Collapse file tree 2 files changed +20
-1
lines changed
Expand file tree Collapse file tree 2 files changed +20
-1
lines changed Original file line number Diff line number Diff 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
Original file line number Diff line number Diff line change @@ -320,6 +320,16 @@ local function coverage_to_string(hits, missed)
320320 return (" %.2f%%" ):format (hits / total * 100.0 )
321321end
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+
323333function 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
387402end
388403
389404end
You can’t perform that action at this time.
0 commit comments