summaryrefslogtreecommitdiff
path: root/spec/ruby/core/tracepoint
diff options
context:
space:
mode:
authorNguyễn Quang Minh <nguyenquangminh0711@gmail.com>2020-08-06 09:56:24 +0700
committerGitHub <noreply@github.com>2020-08-06 11:56:24 +0900
commit1819652578e8f9fe3606f7a716ec4e427fc55f0a (patch)
tree4b1fc8e695a0de3823f0c8542c71e886442404b6 /spec/ruby/core/tracepoint
parentbbbec4b87c1e66909f5bee9acd3e460b8c1ad663 (diff)
[Feature #16513] TracePoint#inspect returns "... file:line" (#3391)
* Fix debug documents to match Thread#to_s change (Feature #16412 ticket) * TracePoint#inspect returns "... file:line" (Feature #16513) * Guard older version of Ruby in Tracepoint inspection tests * Focus on current thread only when running TracePoint inspection test
Notes
Notes: Merged-By: ko1 <ko1@atdot.net>
Diffstat (limited to 'spec/ruby/core/tracepoint')
-rw-r--r--spec/ruby/core/tracepoint/enable_spec.rb14
-rw-r--r--spec/ruby/core/tracepoint/inspect_spec.rb95
2 files changed, 106 insertions, 3 deletions
diff --git a/spec/ruby/core/tracepoint/enable_spec.rb b/spec/ruby/core/tracepoint/enable_spec.rb
index aa0c3aa0dc..13c7b82b54 100644
--- a/spec/ruby/core/tracepoint/enable_spec.rb
+++ b/spec/ruby/core/tracepoint/enable_spec.rb
@@ -123,6 +123,18 @@ describe 'TracePoint#enable' do
end
describe "when nested" do
+ 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
+
it "enables both TracePoints but only calls the respective callbacks" do
called = false
first = TracePoint.new(:line) do |tp|
@@ -146,7 +158,7 @@ describe 'TracePoint#enable' do
end
all.uniq.should == [second]
- inspects.uniq.should == ["#<TracePoint:line@#{__FILE__}:#{line}>"]
+ inspects.uniq.should == ["#<TracePoint:line#{@path_prefix}#{__FILE__}:#{line}>"]
called.should == true
end
end
diff --git a/spec/ruby/core/tracepoint/inspect_spec.rb b/spec/ruby/core/tracepoint/inspect_spec.rb
index 1e48caa215..80de965337 100644
--- a/spec/ruby/core/tracepoint/inspect_spec.rb
+++ b/spec/ruby/core/tracepoint/inspect_spec.rb
@@ -2,6 +2,18 @@ require_relative '../../spec_helper'
require_relative 'fixtures/classes'
describe 'TracePoint#inspect' do
+ 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
+
it 'returns a string containing a human-readable TracePoint status' do
TracePoint.new(:line) {}.inspect.should == '#<TracePoint:disabled>'
end
@@ -16,7 +28,54 @@ describe 'TracePoint#inspect' do
line = __LINE__
end
- inspect.should == "#<TracePoint:line@#{__FILE__}:#{line}>"
+ 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}>"
end
it 'returns a String showing the event, path and line for a :class event' do
@@ -31,6 +90,38 @@ describe 'TracePoint#inspect' do
end
end
- inspect.should == "#<TracePoint:class@#{__FILE__}:#{line}>"
+ 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}>"
end
end