Skip to content

Commit bc9398c

Browse files
committed
Add spec for the precise report_on_exception output
1 parent f07f09b commit bc9398c

File tree

1 file changed

+30
-0
lines changed

1 file changed

+30
-0
lines changed

spec/ruby/core/thread/report_on_exception_spec.rb

Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -61,6 +61,36 @@
6161
}.should raise_error(RuntimeError, "Thread#report_on_exception specs")
6262
end
6363

64+
ruby_version_is "3.0" do
65+
it "prints a backtrace on $stderr in the regular backtrace order" do
66+
line_raise = __LINE__ + 2
67+
def foo
68+
raise RuntimeError, "Thread#report_on_exception specs backtrace order"
69+
end
70+
71+
line_call_foo = __LINE__ + 5
72+
go = false
73+
t = Thread.new {
74+
Thread.current.report_on_exception = true
75+
Thread.pass until go
76+
foo
77+
}
78+
79+
-> {
80+
go = true
81+
Thread.pass while t.alive?
82+
}.should output("", <<ERR)
83+
#{t.inspect} terminated with exception (report_on_exception is true):
84+
#{__FILE__}:#{line_raise}:in `foo': Thread#report_on_exception specs backtrace order (RuntimeError)
85+
\tfrom #{__FILE__}:#{line_call_foo}:in `block (5 levels) in <top (required)>'
86+
ERR
87+
88+
-> {
89+
t.join
90+
}.should raise_error(RuntimeError, "Thread#report_on_exception specs backtrace order")
91+
end
92+
end
93+
6494
it "prints the backtrace even if the thread was killed just after Thread#raise" do
6595
t = nil
6696
ready = false

0 commit comments

Comments
 (0)