Project

General

Profile

Actions

Bug #22269

closed

`Coverage.line_stub` clobbers already-collected coverage data

Bug #22269: `Coverage.line_stub` clobbers already-collected coverage data

Added by mugikurash (Shuta Mugikura) about 1 month ago. Updated 26 days ago.

Status:
Closed
Assignee:
-
Target version:
-
ruby -v:
ruby 4.1.0dev (2026-08-27T01:47:31Z master 5ee95de080) +PRISM [arm64-darwin25]
[ruby-core:126513]

Description

Coverage.line_stub compiles the file with compile_file only to read the ISeq's trace_points. Since https://bugs.ruby-lang.org/issues/22018 compile_file registers the file into the coverage table, so calling line_stub while Coverage is running resets the file's already-collected counters.

This also reproduces on 3.4 and 4.0, so I would like it backported.

Reproduction:

require "coverage"

f = File.expand_path("m.rb")
File.write(f, "def m\n  :ok\nend\n")

Coverage.start
require f
m
p Coverage.peek_result[f]

Coverage.line_stub(f)
p Coverage.peek_result[f]

m
p Coverage.result[f]

Expected:

[1, 1, nil]
[1, 1, nil]
[1, 2, nil]

Actual:

[1, 1, nil]
[0, 0, nil]
[0, 0, nil]

Updated by mugikurash (Shuta Mugikura) about 1 month ago Actions #2

  • Status changed from Open to Closed

Applied in changeset git|22e4a75d67d1e25deed4dce5b801397713dbdefa.


[Bug #22269] Make coverage_enabled: false effective for compile/compile_file

Use it in Coverage.line_stub so compiling the stub does not overwrite already-collected coverage data.

Updated by nagachika (Tomoyuki Chikanaga) 26 days ago Actions #3 [ruby-core:126578]

  • Backport changed from 3.3: UNKNOWN, 3.4: UNKNOWN, 4.0: UNKNOWN to 3.3: UNKNOWN, 3.4: DONE, 4.0: DONE
Actions

Also available in: PDF Atom