Module: SimpleCov::Combine::LinesCombiner
| Relationships & Source Files | |
| Defined in: | lib/simplecov/combine/lines_combiner.rb |
Overview
::SimpleCov::Combine two different lines coverage results on same file
Should be called through SimpleCov.combine.
Class Method Summary
-
.combine(coverage_a, coverage_b)
mod_func
Build a fresh array sized to the longer input.
-
.merge_line_coverage(first_val, second_val) ⇒ Integer || nil
mod_func
Two runs of the same source file should agree on which lines are coverage-relevant (
nilfor comments / whitespace,0+ for executable).
Class Method Details
.combine(coverage_a, coverage_b) (mod_func)
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).
# 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 (mod_func)
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)
# 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