ruby-changes:62531
From: Nguy=E1=BB=85n <ko1@a...>
Date: Thu, 6 Aug 2020 11:56:47 +0900 (JST)
Subject: [ruby-changes:62531] 1819652578 (master): [Feature #16513] TracePoint#inspect returns "... file:line" (#3391)
https://git.ruby-lang.org/ruby.git/commit/?id=1819652578 From 1819652578e8f9fe3606f7a716ec4e427fc55f0a Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Nguy=E1=BB=85n=20Quang=20Minh?= <nguyenquangminh0711@g...> Date: Thu, 6 Aug 2020 09:56:24 +0700 Subject: [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 diff --git a/lib/debug.rb b/lib/debug.rb index 6f519c6..bf53eb8 100644 --- a/lib/debug.rb +++ b/lib/debug.rb @@ -1012,8 +1012,8 @@ EOHELP https://github.com/ruby/ruby/blob/trunk/lib/debug.rb#L1012 # # (rdb:1) DEBUGGER__.thread_list_all # +1 #<Thread:0x007fb2320c03f0 run> debug_me.rb.rb:3 - # 2 #<Thread:0x007fb23218a538@debug_me.rb.rb:3 sleep> - # 3 #<Thread:0x007fb23218b0f0@debug_me.rb.rb:3 sleep> + # 2 #<Thread:0x007fb23218a538 debug_me.rb.rb:3 sleep> + # 3 #<Thread:0x007fb23218b0f0 debug_me.rb.rb:3 sleep> # [1, 2, 3] # # Your current thread is indicated by a <b>+</b> @@ -1022,8 +1022,8 @@ EOHELP https://github.com/ruby/ruby/blob/trunk/lib/debug.rb#L1022 # # (rdb:1) th l # +1 #<Thread:0x007f99328c0410 run> debug_me.rb:3 - # 2 #<Thread:0x007f9932938230@debug_me.rb:3 sleep> debug_me.rb:3 - # 3 #<Thread:0x007f9932938e10@debug_me.rb:3 sleep> debug_me.rb:3 + # 2 #<Thread:0x007f9932938230 debug_me.rb:3 sleep> debug_me.rb:3 + # 3 #<Thread:0x007f9932938e10 debug_me.rb:3 sleep> debug_me.rb:3 # # See DEBUGGER__ for more usage. diff --git a/spec/ruby/core/tracepoint/enable_spec.rb b/spec/ruby/core/tracepoint/enable_spec.rb index aa0c3aa..13c7b82 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 https://github.com/ruby/ruby/blob/trunk/spec/ruby/core/tracepoint/enable_spec.rb#L123 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 https://github.com/ruby/ruby/blob/trunk/spec/ruby/core/tracepoint/enable_spec.rb#L158 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 1e48caa..80de965 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' https://github.com/ruby/ruby/blob/trunk/spec/ruby/core/tracepoint/inspect_spec.rb#L2 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 https://github.com/ruby/ruby/blob/trunk/spec/ruby/core/tracepoint/inspect_spec.rb#L28 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 https://github.com/ruby/ruby/blob/trunk/spec/ruby/core/tracepoint/inspect_spec.rb#L90 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 diff --git a/test/ruby/test_settracefunc.rb b/test/ruby/test_settracefunc.rb index f688e5a..9579974 100644 --- a/test/ruby/test_settracefunc.rb +++ b/test/ruby/test_settracefunc.rb @@ -937,9 +937,9 @@ class TestSetTraceFunc < Test::Unit::TestCase https://github.com/ruby/ruby/blob/trunk/test/ruby/test_settracefunc.rb#L937 when :line assert_match(/ in /, str) when :call, :c_call - assert_match(/call \`/, str) # #<TracePoint:c_call `inherited'@../trunk/test.rb:11> + assert_match(/call \`/, str) # #<TracePoint:c_call `inherited' ../trunk/test.rb:11> when :return, :c_return - assert_match(/return \`/, str) # #<TracePoint:return `m'@../trunk/test.rb:3> + assert_match(/return \`/, str) # #<TracePoint:return `m' ../trunk/test.rb:3> when /thread/ assert_match(/\#<Thread:/, str) # #<TracePoint:thread_end of #<Thread:0x87076c0>> else diff --git a/trace_point.rb b/trace_point.rb index 52272a0..d68eed4 100644 --- a/trace_point.rb +++ b/trace_point.rb @@ -183,7 +183,7 @@ class TracePoint https://github.com/ruby/ruby/blob/trunk/trace_point.rb#L183 # t.enable(target: method(:m1)) # # m1 - # # prints #<TracePoint:line@t...:4 in `m1'> + # # prints #<TracePoint:line test.rb:4 in `m1'> # m2 # # prints nothing # diff --git a/vm_trace.c b/vm_trace.c index c02ad87..7b39779 100644 --- a/vm_trace.c +++ b/vm_trace.c @@ -1456,7 +1456,7 @@ tracepoint_inspect(rb_execution_context_t *ec, VALUE self) https://github.com/ruby/ruby/blob/trunk/vm_trace.c#L1456 VALUE sym = rb_tracearg_method_id(trace_arg); if (NIL_P(sym)) break; - return rb_sprintf("#<TracePoint:%"PRIsVALUE"@%"PRIsVALUE":%d in `%"PRIsVALUE"'>", + return rb_sprintf("#<TracePoint:%"PRIsVALUE" %"PRIsVALUE":%d in `%"PRIsVALUE"'>", rb_tracearg_event(trace_arg), rb_tracearg_path(trace_arg), FIX2INT(rb_tracearg_lineno(trace_arg)), @@ -1466,7 +1466,7 @@ tracepoint_inspect(rb_execution_context_t *ec, VALUE self) https://github.com/ruby/ruby/blob/trunk/vm_trace.c#L1466 case RUBY_EVENT_C_CALL: case RUBY_EVENT_RETURN: case RUBY_EVENT_C_RETURN: - return rb_sprintf("#<TracePoint:%"PRIsVALUE" `%"PRIsVALUE"'@%"PRIsVALUE":%d>", + return rb_sprintf("#<TracePoint:%"PRIsVALUE" `%"PRIsVALUE"' %"PRIsVALUE":%d>", rb_tracearg_event(trace_arg), rb_tracearg_method_id(trace_arg), rb_tracearg_path(trace_arg), @@ -1479,7 +1479,7 @@ tracepoint_inspect(rb_execution_context_t *ec, VALUE self) https://github.com/ruby/ruby/blob/trunk/vm_trace.c#L1479 default: break; } - return rb_sprintf("#<TracePoint:%"PRIsVALUE"@%"PRIsVALUE":%d>", + return rb_sprintf("#<TracePoint:%"PRIsVALUE" %"PRIsVALUE":%d>", rb_tracearg_event(trace_arg), rb_tracearg_path(trace_arg), FIX2INT(rb_tracearg_lineno(trace_arg))); -- cgit v0.10.2 -- ML: ruby-changes@q... Info: http://www.atdot.net/~ko1/quickml/