summaryrefslogtreecommitdiff
path: root/spec/ruby/core/thread
diff options
context:
space:
mode:
authorBenoit Daloze <eregontp@gmail.com>2022-04-25 14:53:54 +0200
committerBenoit Daloze <eregontp@gmail.com>2022-04-25 14:53:54 +0200
commit45cf4f218728a15eb36d14a6c9912086525f5e3f (patch)
tree2aa93fadcb904c226f722dde47827098b87a9846 /spec/ruby/core/thread
parent6ae81d49b52563a6720d666a6118ffa6e484f398 (diff)
Update to ruby/spec@3affe1e
Diffstat (limited to 'spec/ruby/core/thread')
-rw-r--r--spec/ruby/core/thread/backtrace_locations_spec.rb10
-rw-r--r--spec/ruby/core/thread/report_on_exception_spec.rb30
-rw-r--r--spec/ruby/core/thread/shared/to_s.rb4
3 files changed, 35 insertions, 9 deletions
diff --git a/spec/ruby/core/thread/backtrace_locations_spec.rb b/spec/ruby/core/thread/backtrace_locations_spec.rb
index 237941c214..c970ae023b 100644
--- a/spec/ruby/core/thread/backtrace_locations_spec.rb
+++ b/spec/ruby/core/thread/backtrace_locations_spec.rb
@@ -49,12 +49,10 @@ describe "Thread#backtrace_locations" do
locations2.map(&:to_s).should == locations1[2..-1].map(&:to_s)
end
- ruby_version_is "2.7" do
- it "can be called with an beginless range" do
- locations1 = Thread.current.backtrace_locations(0)
- locations2 = Thread.current.backtrace_locations(eval("(..5)"))
- locations2.map(&:to_s)[eval("(2..)")].should == locations1[eval("(..5)")].map(&:to_s)[eval("(2..)")]
- end
+ it "can be called with an beginless range" do
+ locations1 = Thread.current.backtrace_locations(0)
+ locations2 = Thread.current.backtrace_locations((..5))
+ locations2.map(&:to_s)[eval("(2..)")].should == locations1[(..5)].map(&:to_s)[eval("(2..)")]
end
it "returns nil if omitting more locations than available" do
diff --git a/spec/ruby/core/thread/report_on_exception_spec.rb b/spec/ruby/core/thread/report_on_exception_spec.rb
index e7f400819a..9279fa1da5 100644
--- a/spec/ruby/core/thread/report_on_exception_spec.rb
+++ b/spec/ruby/core/thread/report_on_exception_spec.rb
@@ -61,6 +61,36 @@ describe "Thread#report_on_exception=" do
}.should raise_error(RuntimeError, "Thread#report_on_exception specs")
end
+ ruby_version_is "3.0" do
+ it "prints a backtrace on $stderr in the regular backtrace order" do
+ line_raise = __LINE__ + 2
+ def foo
+ raise RuntimeError, "Thread#report_on_exception specs backtrace order"
+ end
+
+ line_call_foo = __LINE__ + 5
+ go = false
+ t = Thread.new {
+ Thread.current.report_on_exception = true
+ Thread.pass until go
+ foo
+ }
+
+ -> {
+ go = true
+ Thread.pass while t.alive?
+ }.should output("", <<ERR)
+#{t.inspect} terminated with exception (report_on_exception is true):
+#{__FILE__}:#{line_raise}:in `foo': Thread#report_on_exception specs backtrace order (RuntimeError)
+\tfrom #{__FILE__}:#{line_call_foo}:in `block (5 levels) in <top (required)>'
+ERR
+
+ -> {
+ t.join
+ }.should raise_error(RuntimeError, "Thread#report_on_exception specs backtrace order")
+ end
+ end
+
it "prints the backtrace even if the thread was killed just after Thread#raise" do
t = nil
ready = false
diff --git a/spec/ruby/core/thread/shared/to_s.rb b/spec/ruby/core/thread/shared/to_s.rb
index 45c04af627..43640deb33 100644
--- a/spec/ruby/core/thread/shared/to_s.rb
+++ b/spec/ruby/core/thread/shared/to_s.rb
@@ -1,12 +1,10 @@
require_relative '../fixtures/classes'
describe :thread_to_s, shared: true do
- sep = ruby_version_is("2.7") ? " " : "@"
-
it "returns a description including file and line number" do
thread, line = Thread.new { "hello" }, __LINE__
thread.join
- thread.send(@method).should =~ /^#<Thread:([^ ]*?)#{sep}#{Regexp.escape __FILE__}:#{line} \w+>$/
+ thread.send(@method).should =~ /^#<Thread:([^ ]*?) #{Regexp.escape __FILE__}:#{line} \w+>$/
end
it "has a binary encoding" do