diff options
author | Benoit Daloze <eregontp@gmail.com> | 2024-03-21 20:49:50 +0100 |
---|---|---|
committer | Benoit Daloze <eregontp@gmail.com> | 2024-03-22 12:30:15 +0100 |
commit | 74995a1a772903c5247886da1105caa27a4afa2d (patch) | |
tree | da51d929377bf6ba863fcc5055a3b5b7de5eb88b /spec/ruby/core | |
parent | e2a9b87126d59e4766479a7aa12cf7a648f46506 (diff) |
[Feature #20275] Remove extra backtrace entries for rescue and ensure
Diffstat (limited to 'spec/ruby/core')
-rw-r--r-- | spec/ruby/core/exception/top_level_spec.rb | 29 |
1 files changed, 18 insertions, 11 deletions
diff --git a/spec/ruby/core/exception/top_level_spec.rb b/spec/ruby/core/exception/top_level_spec.rb index 6ef7539598..cc961d06d5 100644 --- a/spec/ruby/core/exception/top_level_spec.rb +++ b/spec/ruby/core/exception/top_level_spec.rb @@ -8,25 +8,32 @@ describe "An Exception reaching the top level" do it "the Exception#cause is printed to STDERR with backtraces" do code = <<-RUBY def raise_cause - raise "the cause" + raise "the cause" # 2 end def raise_wrapped - raise "wrapped" + raise "wrapped" # 5 end begin - raise_cause + raise_cause # 8 rescue - raise_wrapped + raise_wrapped # 10 end RUBY lines = ruby_exe(code, args: "2>&1", exit_status: 1).lines - lines.map! { |l| l.chomp[/:(in.+)/, 1] } - lines.size.should == 5 - lines[0].should =~ /\Ain [`'](?:Object#)?raise_wrapped': wrapped \(RuntimeError\)\z/ - lines[1].should =~ /\Ain [`'](?:rescue in )?<main>'\z/ - lines[2].should =~ /\Ain [`']<main>'\z/ - lines[3].should =~ /\Ain [`'](?:Object#)?raise_cause': the cause \(RuntimeError\)\z/ - lines[4].should =~ /\Ain [`']<main>'\z/ + + lines.map! { |l| l.chomp[/:(\d+:in.+)/, 1] } + lines[0].should =~ /\A5:in [`'](?:Object#)?raise_wrapped': wrapped \(RuntimeError\)\z/ + if lines[1].include? 'rescue in' + # CRuby < 3.4 has an extra 'rescue in' backtrace entry + lines[1].should =~ /\A10:in [`']rescue in <main>'\z/ + lines.delete_at 1 + lines[1].should =~ /\A7:in [`']<main>'\z/ + else + lines[1].should =~ /\A10:in [`']<main>'\z/ + end + lines[2].should =~ /\A2:in [`'](?:Object#)?raise_cause': the cause \(RuntimeError\)\z/ + lines[3].should =~ /\A8:in [`']<main>'\z/ + lines.size.should == 4 end describe "with a custom backtrace" do |