Preview Ruby 4.1 is a preview. It can change before the final release. Switch to Ruby 4.0 →
class method
Coverage.line_stub
(::String) -> ::Array[::Integer?]
line_stub(file) → array
ext/coverage/lib/coverage.rb
View on GitHub ↗
# File tmp/rubies/ruby-4.1.0-preview1/ext/coverage/lib/coverage.rb, line 9
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
A simple helper function that creates the “stub” of line coverage from a given source code.