class Covered::Capture
def disable
def disable @trace&.disable super end
def enable
def enable super @trace&.enable end
def execute(path, source, binding: TOPLEVEL_BINDING)
def execute(path, source, binding: TOPLEVEL_BINDING) enable eval(source, binding, path) ensure disable end
def initialize(output)
def initialize(output) super(output) begin @trace = TracePoint.new(:line, :call, :c_call) do |trace| if trace.event == :call # Ruby doesn't always mark call-sites in sub-expressions, so we use this approach to compute a call site and mark it: if location = caller_locations(2, 1).first and path = location.path @output.mark(path, location.lineno, 1) end end if path = trace.path @output.mark(path, trace.lineno, 1) end end rescue warn "Line coverage disabled: #{$!}" @trace = nil end end