From 3e816bfe722899b04abfe106d89e1fec74042957 Mon Sep 17 00:00:00 2001 From: Maxime Lapointe Date: Mon, 17 Jun 2024 09:43:28 -0400 Subject: [PATCH] Fixes tests with nested exception backtraces on Ruby master Ruby master did the following changes (and probably more) https://bugs.ruby-lang.org/issues/16495 https://bugs.ruby-lang.org/issues/20275 --- .../test/dispatch/debug_exceptions_test.rb | 109 +++++++++++++----- 1 file changed, 79 insertions(+), 30 deletions(-) diff --git a/actionpack/test/dispatch/debug_exceptions_test.rb b/actionpack/test/dispatch/debug_exceptions_test.rb index 5dea74bc74..2186362c98 100644 --- a/actionpack/test/dispatch/debug_exceptions_test.rb +++ b/actionpack/test/dispatch/debug_exceptions_test.rb @@ -45,15 +45,26 @@ def method_that_raises end def raise_nested_exceptions - raise "First error" - rescue - begin - raise "Second error" - rescue - raise "Third error" - end + raise_nested_exceptions_third end + def raise_nested_exceptions_first + raise "First error" + end + + def raise_nested_exceptions_second + raise_nested_exceptions_first + rescue + raise "Second error" + end + + def raise_nested_exceptions_third + raise_nested_exceptions_second + rescue + raise "Third error" + end + + def call(env) env["action_dispatch.show_detailed_exceptions"] = @detailed req = ActionDispatch::Request.new(env) @@ -641,29 +652,67 @@ def self.build_app(app, *args) Information for: RuntimeError (Third error): MSG - assert_match Regexp.new(<<~REGEX.strip), paragraphs[2].lines[0..2].join - \\A.*in `rescue in rescue in raise_nested_exceptions' - .*in `rescue in raise_nested_exceptions' - .*in `raise_nested_exceptions' - REGEX + if RUBY_VERSION >= "3.4" + # Changes to the format of exception backtraces + # https://bugs.ruby-lang.org/issues/16495 (use single quote instead of backtrace) + # https://bugs.ruby-lang.org/issues/20275 (don't have entry for rescue in) + # And probably more, they now show the class too + assert_match Regexp.new(<<~REGEX.strip), paragraphs[2] + \\A.*in '.*raise_nested_exceptions_third' + .*in '.*raise_nested_exceptions' + REGEX - assert_includes(paragraphs[3], <<~MSG.strip) - Information for cause: RuntimeError (Second error): - MSG + assert_includes(paragraphs[3], <<~MSG.strip) + Information for cause: RuntimeError (Second error): + MSG - assert_match Regexp.new(<<~REGEX.strip), paragraphs[4].lines[0..1].join - \\A.*in `rescue in raise_nested_exceptions' - .*in `raise_nested_exceptions' - REGEX + assert_match Regexp.new(<<~REGEX.strip), paragraphs[4] + \\A.*in '.*raise_nested_exceptions_second' + .*in '.*raise_nested_exceptions_third' + .*in '.*raise_nested_exceptions' + REGEX - assert_includes(paragraphs[5], <<~MSG.strip) - Information for cause: RuntimeError (First error): - MSG + assert_includes(paragraphs[5], <<~MSG.strip) + Information for cause: RuntimeError (First error): + MSG - assert_match Regexp.new(<<~REGEX.strip), paragraphs[6].lines[0] - \\A.*in `raise_nested_exceptions' - REGEX + assert_match Regexp.new(<<~REGEX.strip), paragraphs[6] + \\A.*in '.*raise_nested_exceptions_first' + .*in '.*raise_nested_exceptions_second' + .*in '.*raise_nested_exceptions_third' + .*in '.*raise_nested_exceptions' + REGEX + else + assert_match Regexp.new(<<~REGEX.strip), paragraphs[2] + \\A.*in `rescue in raise_nested_exceptions_third' + .*in `raise_nested_exceptions_third' + .*in `raise_nested_exceptions' + REGEX + + assert_includes(paragraphs[3], <<~MSG.strip) + Information for cause: RuntimeError (Second error): + MSG + + assert_match Regexp.new(<<~REGEX.strip), paragraphs[4] + \\A.*in `rescue in raise_nested_exceptions_second' + .*in `raise_nested_exceptions_second' + .*in `raise_nested_exceptions_third' + .*in `raise_nested_exceptions' + REGEX + + + assert_includes(paragraphs[5], <<~MSG.strip) + Information for cause: RuntimeError (First error): + MSG + + assert_match Regexp.new(<<~REGEX.strip), paragraphs[6] + \\A.*in `raise_nested_exceptions_first' + .*in `raise_nested_exceptions_second' + .*in `raise_nested_exceptions_third' + .*in `raise_nested_exceptions' + REGEX + end end test "display backtrace when error type is SyntaxError" do @@ -783,28 +832,28 @@ def self.build_app(app, *args) # Possible Ruby 3.4-dev bug: https://bugs.ruby-lang.org/issues/19117#note-45 # assert application trace refers to line that raises the last exception assert_select "#Application-Trace-0" do - assert_select "code a:first", %r{in '.*raise_nested_exceptions'} + assert_select "code a:first", %r{in '.*raise_nested_exceptions_third'} end # assert the second application trace refers to the line that raises the second exception assert_select "#Application-Trace-1" do - assert_select "code a:first", %r{in '.*raise_nested_exceptions'} + assert_select "code a:first", %r{in '.*raise_nested_exceptions_second'} end else # assert application trace refers to line that raises the last exception assert_select "#Application-Trace-0" do - assert_select "code a:first", %r{in [`']rescue in rescue in .*raise_nested_exceptions'} + assert_select "code a:first", %r{in [`']rescue in .*raise_nested_exceptions_third'} end # assert the second application trace refers to the line that raises the second exception assert_select "#Application-Trace-1" do - assert_select "code a:first", %r{in [`']rescue in .*raise_nested_exceptions'} + assert_select "code a:first", %r{in [`']rescue in .*raise_nested_exceptions_second'} end end # assert the third application trace refers to the line that raises the first exception assert_select "#Application-Trace-2" do - assert_select "code a:first", %r{in [`'].*raise_nested_exceptions'} + assert_select "code a:first", %r{in [`'].*raise_nested_exceptions_first'} end end end