Files
mugitti9 22e4a75d67 [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.
2026-08-29 15:48:53 +09:00

20 lines
542 B
Ruby

require "coverage.so"
module Coverage
# call-seq:
# line_stub(file) -> array
#
# A simple helper function that creates the "stub" of line coverage
# from a given source code.
def self.line_stub(file)
lines = File.foreach(file).map { nil }
iseqs = [RubyVM::InstructionSequence.compile_file(file, coverage_enabled: false)]
until iseqs.empty?
iseq = iseqs.pop
iseq.trace_points.each {|n, type| lines[n - 1] = 0 if type == :line }
iseq.each_child {|child| iseqs << child }
end
lines
end
end