Module: SimpleCov::Combine::LinesCombiner
- Defined in:
- lib/simplecov/combine/lines_combiner.rb
Overview
Combine two different lines coverage results on same file
Should be called through ‘SimpleCov.combine`.
Class Method Summary collapse
-
.combine(coverage_a, coverage_b) ⇒ Object
Build a fresh array sized to the longer input.
-
.merge_line_coverage(first_val, second_val) ⇒ Integer || nil
Two runs of the same source file should agree on which lines are coverage-relevant (‘nil` for comments / whitespace, `0`+ for executable).
Class Method Details
.combine(coverage_a, coverage_b) ⇒ Object
Build a fresh array sized to the longer input. The previous implementation mutated whichever input was longer in place, which could surprise callers holding a reference to that array (e.g. the parsed ‘coverage` key of a resultset hash being passed into a second merge).
17 18 19 20 |
# File 'lib/simplecov/combine/lines_combiner.rb', line 17 def combine(coverage_a, coverage_b) size = [coverage_a.size, coverage_b.size].max Array.new(size) { |i| merge_line_coverage(coverage_a[i], coverage_b[i]) } end |
.merge_line_coverage(first_val, second_val) ⇒ Integer || nil
Two runs of the same source file should agree on which lines are coverage-relevant (‘nil` for comments / whitespace, `0`+ for executable). When they don’t, treat “relevant on either side” as relevant rather than masking a real ‘0` as `nil`, which would silently drop an uncovered line from the denominator and inflate the percentage.
Logic:
> nil + nil = nil
> nil + int = int (preserves a relevant-but-uncovered 0)
> int + int = int (sum)
38 39 40 41 42 |
# File 'lib/simplecov/combine/lines_combiner.rb', line 38 def merge_line_coverage(first_val, second_val) return nil if first_val.nil? && second_val.nil? first_val.to_i + second_val.to_i end |