Project

General

Profile

Bug #17302 ยป my_test.rb

 
require 'minitest/autorun'

describe "my_bug" do
it "traces two :line events in the same method" do
ScratchPad = []

trace1 = TracePoint.new(:line) do |tp|
ScratchPad << tp.lineno
end

trace2 = TracePoint.new(:line) do |tp|
ScratchPad << tp.lineno
end

target = -> {
x = 1 # <= this line is target1
y = 2
z = x + y # <= this line is target2
}
_, lineno = target.source_location
target_line1 = lineno + 1
target_line2 = lineno + 3

trace1.enable(target_line: target_line1, target: target)
trace2.enable(target_line: target_line2, target: target)

target.call

trace1.disable
trace2.disable

assert_equal [target_line1, target_line2], ScratchPad
end
end
    (1-1/1)