summaryrefslogtreecommitdiff
path: root/spec
diff options
context:
space:
mode:
authorJeremy Evans <code@jeremyevans.net>2021-12-27 12:52:04 -0800
committerJeremy Evans <code@jeremyevans.net>2022-03-29 18:14:33 -0700
commit9c1d32a7ada794ecd0356d56f7be3cdf3982d8ac (patch)
tree5b7cbe2b28d0c627b19d32108241bfa013670852 /spec
parent6d3f447aecfb56f7d3edbdf9cc68e748e150d7d8 (diff)
Make TracePoint#enable with block target current thread by default
If TracePoint#enable is passed a block, it previously started the trace on all threads. This changes it to trace only the current thread by default. To limit the scope of the change, the current thread is only used by default if target and target_line are both nil. You can pass target_thread: nil to enable tracing on all threads, to get the previous default behavior. Fixes [Bug #16889]
Notes
Notes: Merged: https://github.com/ruby/ruby/pull/5359
Diffstat (limited to 'spec')
-rw-r--r--spec/ruby/core/tracepoint/enable_spec.rb55
-rw-r--r--spec/ruby/core/tracepoint/inspect_spec.rb4
2 files changed, 42 insertions, 17 deletions
diff --git a/spec/ruby/core/tracepoint/enable_spec.rb b/spec/ruby/core/tracepoint/enable_spec.rb
index ab392c7583..4d9cfa1448 100644
--- a/spec/ruby/core/tracepoint/enable_spec.rb
+++ b/spec/ruby/core/tracepoint/enable_spec.rb
@@ -57,25 +57,50 @@ describe 'TracePoint#enable' do
end.enable { event_name.should equal(:line) }
end
- it 'enables the trace object for any thread' do
- threads = []
- trace = TracePoint.new(:line) do |tp|
- # Runs on purpose on any Thread
- threads << Thread.current
- end
+ ruby_version_is '3.2' do
+ it 'enables the trace object for any thread' do
+ threads = []
+ trace = TracePoint.new(:line) do |tp|
+ # Runs on purpose on any Thread
+ threads << Thread.current
+ end
- thread = nil
- trace.enable do
- line_event = true
- thread = Thread.new do
- event_in_other_thread = true
+ thread = nil
+ trace.enable do
+ line_event = true
+ thread = Thread.new do
+ event_in_other_thread = true
+ end
+ thread.join
end
- thread.join
+
+ threads = threads.uniq
+ threads.should.include?(Thread.current)
+ threads.should_not.include?(thread)
end
+ end
- threads = threads.uniq
- threads.should.include?(Thread.current)
- threads.should.include?(thread)
+ ruby_version_is ''...'3.2' do
+ it 'enables the trace object for any thread' do
+ threads = []
+ trace = TracePoint.new(:line) do |tp|
+ # Runs on purpose on any Thread
+ threads << Thread.current
+ end
+
+ thread = nil
+ trace.enable do
+ line_event = true
+ thread = Thread.new do
+ event_in_other_thread = true
+ end
+ thread.join
+ end
+
+ threads = threads.uniq
+ threads.should.include?(Thread.current)
+ threads.should.include?(thread)
+ end
end
it 'can accept arguments within a block but it should not yield arguments' do
diff --git a/spec/ruby/core/tracepoint/inspect_spec.rb b/spec/ruby/core/tracepoint/inspect_spec.rb
index b9d7f35c32..a07b626212 100644
--- a/spec/ruby/core/tracepoint/inspect_spec.rb
+++ b/spec/ruby/core/tracepoint/inspect_spec.rb
@@ -98,7 +98,7 @@ describe 'TracePoint#inspect' do
TracePoint.new(:thread_begin) { |tp|
next unless Thread.current == thread
inspect ||= tp.inspect
- }.enable do
+ }.enable(target_thread: nil) do
thread = Thread.new {}
thread_inspection = thread.inspect
thread.join
@@ -114,7 +114,7 @@ describe 'TracePoint#inspect' do
TracePoint.new(:thread_end) { |tp|
next unless Thread.current == thread
inspect ||= tp.inspect
- }.enable do
+ }.enable(target_thread: nil) do
thread = Thread.new {}
thread_inspection = thread.inspect
thread.join