Skip to content

Commit

Permalink
Support Ruby 3.4's new error message format (#237)
Browse files Browse the repository at this point in the history
Ruby 3.4 will use a single quote instead of a backtrick as an open
quote.

https://bugs.ruby-lang.org/issues/16495

Also, the backtrace line will have not only a method name but also its
receiver class.

https://bugs.ruby-lang.org/issues/19117
  • Loading branch information
mame committed Feb 15, 2024
1 parent b8f0b30 commit 6be3324
Show file tree
Hide file tree
Showing 3 changed files with 11 additions and 11 deletions.
2 changes: 1 addition & 1 deletion lib/test/unit/fault-location-detector.rb
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ def split_backtrace_entry(entry)
return nil if match_data.nil?
file, line_number, context = match_data.to_a[1..-1]
line_number = line_number.to_i
if /\Ain `(.+?)'/ =~ context
if /\Ain [`'](.+?)'/ =~ context
method_name = $1
if /\Ablock (?:\(.+?\) )?in / =~ method_name
method_name = $POSTMATCH
Expand Down
18 changes: 9 additions & 9 deletions test/test-test-case.rb
Original file line number Diff line number Diff line change
Expand Up @@ -72,7 +72,7 @@ def normalize_location(location)
internal_backtrace_entry?(entry)
end
filtered_location.collect do |entry|
entry.sub(/:\d+:/, ":0:")
entry.sub(/:\d+:in [`'](?:[^']+?[#.])?/, ":0:in '")
end
end

Expand Down Expand Up @@ -105,8 +105,8 @@ def test_add_failed_assertion
:message => "failure",
:test_name => "test_failure(TC_FailureError)",
:location => [
"#{__FILE__}:0:in `test_failure'",
"#{__FILE__}:0:in `#{__method__}'",
"#{__FILE__}:0:in 'test_failure'",
"#{__FILE__}:0:in '#{__method__}'",
],
},
],
Expand Down Expand Up @@ -151,9 +151,9 @@ def test_add_failure_nested
:message => "nested",
:test_name => "test_nested_failure(TC_FailureError)",
:location => [
"#{__FILE__}:0:in `nested'",
"#{__FILE__}:0:in `test_nested_failure'",
"#{__FILE__}:0:in `#{__method__}'",
"#{__FILE__}:0:in 'nested'",
"#{__FILE__}:0:in 'test_nested_failure'",
"#{__FILE__}:0:in '#{__method__}'",
],
},
],
Expand Down Expand Up @@ -198,9 +198,9 @@ def test_add_error
}
end
location = []
location << "#{__FILE__}:0:in `/'" if cruby?
location << "#{__FILE__}:0:in `test_error'"
location << "#{__FILE__}:0:in `#{__method__}'"
location << "#{__FILE__}:0:in '/'" if cruby?
location << "#{__FILE__}:0:in 'test_error'"
location << "#{__FILE__}:0:in '#{__method__}'"
assert_equal([
{
:class => Error,
Expand Down
2 changes: 1 addition & 1 deletion test/util/test_backtracefilter.rb
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ def test_nil_backtrace

def test_power_assert_backtrace
omit('test for power_assert') unless defined?(PowerAssert)
blk = Proc.new {caller.find {|i| /power_assert.*in \`start\'/ =~ i}}
blk = Proc.new {caller.find {|i| /power_assert.*in [`'](?:PowerAssert\.)?start\'/ =~ i}}
PowerAssert.start(blk) do |pa|
backtrace = [pa.yield,
%q{tc_thing.rb:4:in 'a'},
Expand Down

0 comments on commit 6be3324

Please sign in to comment.