2018-03-04 10:09:32 -05:00
|
|
|
require_relative '../../spec_helper'
|
2019-02-21 10:38:59 -05:00
|
|
|
require_relative 'fixtures/classes'
|
2017-12-01 10:41:50 -05:00
|
|
|
|
|
|
|
describe 'TracePoint#inspect' do
|
2020-08-05 22:56:24 -04:00
|
|
|
before do
|
|
|
|
ruby_version_is ""..."2.8" do
|
|
|
|
# Old behavior for Ruby < 2.8
|
|
|
|
@path_prefix = '@'
|
|
|
|
end
|
|
|
|
|
|
|
|
ruby_version_is "2.8" do
|
|
|
|
# New behavior for Ruby >= 2.8
|
|
|
|
@path_prefix = ' '
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
2017-12-01 10:41:50 -05:00
|
|
|
it 'returns a string containing a human-readable TracePoint status' do
|
2020-05-02 10:03:14 -04:00
|
|
|
TracePoint.new(:line) {}.inspect.should == '#<TracePoint:disabled>'
|
2017-12-01 10:41:50 -05:00
|
|
|
end
|
2019-02-21 10:38:59 -05:00
|
|
|
|
|
|
|
it 'returns a String showing the event, path and line' do
|
|
|
|
inspect = nil
|
2020-05-02 10:03:14 -04:00
|
|
|
line = nil
|
|
|
|
TracePoint.new(:line) { |tp|
|
2020-05-31 12:22:49 -04:00
|
|
|
next unless TracePointSpec.target_thread?
|
2020-05-02 10:03:14 -04:00
|
|
|
inspect ||= tp.inspect
|
|
|
|
}.enable do
|
|
|
|
line = __LINE__
|
2019-02-21 10:38:59 -05:00
|
|
|
end
|
2020-05-02 10:03:14 -04:00
|
|
|
|
2020-08-05 22:56:24 -04:00
|
|
|
inspect.should == "#<TracePoint:line#{@path_prefix}#{__FILE__}:#{line}>"
|
|
|
|
end
|
|
|
|
|
|
|
|
it 'returns a String showing the event, method, path and line for a :call event' do
|
|
|
|
inspect = nil
|
|
|
|
line = nil
|
|
|
|
TracePoint.new(:call) { |tp|
|
|
|
|
next unless TracePointSpec.target_thread?
|
|
|
|
inspect ||= tp.inspect
|
|
|
|
}.enable do
|
|
|
|
line = __LINE__ + 1
|
|
|
|
def trace_point_spec_test_call; end
|
|
|
|
trace_point_spec_test_call
|
|
|
|
end
|
|
|
|
|
|
|
|
inspect.should == "#<TracePoint:call `trace_point_spec_test_call'#{@path_prefix}#{__FILE__}:#{line}>"
|
|
|
|
end
|
|
|
|
|
|
|
|
it 'returns a String showing the event, method, path and line for a :return event' do
|
|
|
|
inspect = nil
|
|
|
|
line = nil
|
|
|
|
TracePoint.new(:return) { |tp|
|
|
|
|
next unless TracePointSpec.target_thread?
|
|
|
|
inspect ||= tp.inspect
|
|
|
|
}.enable do
|
|
|
|
line = __LINE__ + 4
|
|
|
|
def trace_point_spec_test_return
|
|
|
|
a = 1
|
|
|
|
return a
|
|
|
|
end
|
|
|
|
trace_point_spec_test_return
|
|
|
|
end
|
|
|
|
|
|
|
|
inspect.should == "#<TracePoint:return `trace_point_spec_test_return'#{@path_prefix}#{__FILE__}:#{line}>"
|
|
|
|
end
|
|
|
|
|
|
|
|
it 'returns a String showing the event, method, path and line for a :c_call event' do
|
|
|
|
inspect = nil
|
|
|
|
line = nil
|
|
|
|
TracePoint.new(:c_call) { |tp|
|
|
|
|
next unless TracePointSpec.target_thread?
|
|
|
|
inspect ||= tp.inspect
|
|
|
|
}.enable do
|
|
|
|
line = __LINE__ + 1
|
|
|
|
[0, 1].max
|
|
|
|
end
|
|
|
|
|
|
|
|
inspect.should == "#<TracePoint:c_call `max'#{@path_prefix}#{__FILE__}:#{line}>"
|
2019-02-21 10:38:59 -05:00
|
|
|
end
|
|
|
|
|
|
|
|
it 'returns a String showing the event, path and line for a :class event' do
|
|
|
|
inspect = nil
|
2020-05-02 10:03:14 -04:00
|
|
|
line = nil
|
|
|
|
TracePoint.new(:class) { |tp|
|
2020-05-31 12:22:49 -04:00
|
|
|
next unless TracePointSpec.target_thread?
|
2020-05-02 10:03:14 -04:00
|
|
|
inspect ||= tp.inspect
|
|
|
|
}.enable do
|
|
|
|
line = __LINE__ + 1
|
2019-02-21 10:38:59 -05:00
|
|
|
class TracePointSpec::C
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
2020-08-05 22:56:24 -04:00
|
|
|
inspect.should == "#<TracePoint:class#{@path_prefix}#{__FILE__}:#{line}>"
|
|
|
|
end
|
|
|
|
|
|
|
|
it 'returns a String showing the event and thread for :thread_begin event' do
|
|
|
|
inspect = nil
|
|
|
|
thread = nil
|
|
|
|
thread_inspection = nil
|
|
|
|
TracePoint.new(:thread_begin) { |tp|
|
|
|
|
next unless Thread.current == thread
|
|
|
|
inspect ||= tp.inspect
|
|
|
|
}.enable do
|
|
|
|
thread = Thread.new {}
|
|
|
|
thread_inspection = thread.inspect
|
|
|
|
thread.join
|
|
|
|
end
|
|
|
|
|
|
|
|
inspect.should == "#<TracePoint:thread_begin #{thread_inspection}>"
|
|
|
|
end
|
|
|
|
|
|
|
|
it 'returns a String showing the event and thread for :thread_end event' do
|
|
|
|
inspect = nil
|
|
|
|
thread = nil
|
|
|
|
thread_inspection = nil
|
|
|
|
TracePoint.new(:thread_end) { |tp|
|
|
|
|
next unless Thread.current == thread
|
|
|
|
inspect ||= tp.inspect
|
|
|
|
}.enable do
|
|
|
|
thread = Thread.new {}
|
|
|
|
thread_inspection = thread.inspect
|
|
|
|
thread.join
|
|
|
|
end
|
|
|
|
|
|
|
|
inspect.should == "#<TracePoint:thread_end #{thread_inspection}>"
|
2019-02-21 10:38:59 -05:00
|
|
|
end
|
2017-12-01 10:41:50 -05:00
|
|
|
end
|