Skip to content

Commit 53a573f

Browse files
Treat nil from any SimpleCov session as non-executable
SimpleCov's track_files placeholder uses a parser-based heuristic to mark executable lines in files no process loaded. Ruby's Coverage module is authoritative when the file was loaded. The previous merge combined nil and 0 into 0, which inflated total by counting heuristic "executable" lines that the real Coverage run had marked non-executable. Switch to nil-wins so the authoritative classification overrides the heuristic.
1 parent 4d7f8cf commit 53a573f

2 files changed

Lines changed: 21 additions & 2 deletions

File tree

.evergreen/lib/coverage_gate.rb

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -84,11 +84,15 @@ def parse_resultset(data)
8484
end
8585
end
8686

87+
# SimpleCov's track_files placeholder uses a heuristic to mark executable
88+
# lines in files no process actually loaded. Ruby's Coverage module is
89+
# authoritative when the file was loaded, so a nil from any session wins
90+
# over a heuristic 0 from another.
8791
def merge_lines(a, b)
8892
a.zip(b).map do |x, y|
89-
next nil if x.nil? && y.nil?
93+
next nil if x.nil? || y.nil?
9094

91-
(x.is_a?(Integer) ? x : 0) + (y.is_a?(Integer) ? y : 0)
95+
x + y
9296
end
9397
end
9498

spec/mongo/coverage_gate_spec.rb

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -135,6 +135,21 @@ def write_baseline(files)
135135
write_baseline('lib/mongo/foo.rb' => { 'covered' => 3, 'total' => 3 })
136136
expect(gate.check).to eq(0)
137137
end
138+
139+
it 'treats a nil from any session as non-executable' do
140+
# Session A loaded the file: Ruby Coverage marked lines 0, 4, 5 as
141+
# non-executable (nil). Session B used the track_files heuristic and
142+
# tagged those same lines as executable-not-hit (0). The merge must
143+
# not inflate total by counting heuristic 0s where a real run said nil.
144+
write_multi_session_resultset(
145+
[
146+
{ 'lib/mongo/foo.rb' => [ nil, 1, 1, 0, nil, nil ] },
147+
{ 'lib/mongo/foo.rb' => [ 0, 0, 0, 0, 0, 0 ] },
148+
]
149+
)
150+
write_baseline('lib/mongo/foo.rb' => { 'covered' => 2, 'total' => 3 })
151+
expect(gate.check).to eq(0)
152+
end
138153
end
139154
end
140155

0 commit comments

Comments
 (0)