Module: SimpleCov::Combine::MethodsCombiner
- Defined in:
- lib/simplecov/combine/methods_combiner.rb
Overview
Combine different method coverage results on a single file.
Should be called through SimpleCov.combine.
Class Method Summary collapse
-
.combine(coverage_a, coverage_b) ⇒ Hash
Return merged methods or the existing methods if other is missing.
- .source_identity(key) ⇒ Object
Class Method Details
.combine(coverage_a, coverage_b) ⇒ Hash
Return merged methods or the existing methods if other is missing.
Method coverage maps [class, name, start_line, start_col, end_line, end_col] keys to hit counts. Keys are matched on their SOURCE
identity — (name, location), ignoring the class element — because
Ruby records one entry per receiver: the same define_method block
defined onto different classes in different processes arrives with
different (normalized) receivers for the same source method, and
matching on the full key would keep both, letting a never-called
receiver's 0 shadow a covered method after merge (issue #1234).
Combining sums the hit counts for matching methods and preserves
methods that only appear in one result.
30 31 32 33 34 35 36 37 38 39 40 41 |
# File 'lib/simplecov/combine/methods_combiner.rb', line 30 def combine(coverage_a, coverage_b) merged = {} #: Hash[untyped, [untyped, Integer]] [coverage_a, coverage_b].each_with_object(merged) do |coverage, memo| coverage.each do |key, count| method_key = source_identity(key) retained_key, existing = memo[method_key] || [key, 0] memo[method_key] = [retained_key, existing + count] end end merged.values.to_h end |
.source_identity(key) ⇒ Object
43 44 45 46 |
# File 'lib/simplecov/combine/methods_combiner.rb', line 43 def source_identity(key) _class_name, *identity = SourceFile::RubyDataParser.call(key) identity end |