[ruby/error_highlight] Make backtrace_location keyword work
We had to keep backtrace_location before opts is overwritten. https://github.com/ruby/error_highlight/commit/2735e4681a
This commit is contained in:
parent
99e7fa5b37
commit
3a58009066
@ -26,9 +26,9 @@ module ErrorHighlight
|
|||||||
case obj
|
case obj
|
||||||
when Exception
|
when Exception
|
||||||
exc = obj
|
exc = obj
|
||||||
|
loc = opts[:backtrace_location]
|
||||||
opts = { point_type: opts.fetch(:point_type, :name) }
|
opts = { point_type: opts.fetch(:point_type, :name) }
|
||||||
|
|
||||||
loc = opts[:backtrace_location]
|
|
||||||
unless loc
|
unless loc
|
||||||
case exc
|
case exc
|
||||||
when TypeError, ArgumentError
|
when TypeError, ArgumentError
|
||||||
@ -44,6 +44,8 @@ module ErrorHighlight
|
|||||||
opts[:name] = exc.name if NameError === obj
|
opts[:name] = exc.name if NameError === obj
|
||||||
end
|
end
|
||||||
|
|
||||||
|
return nil unless Thread::Backtrace::Location === loc
|
||||||
|
|
||||||
node = RubyVM::AbstractSyntaxTree.of(loc, keep_script_lines: true)
|
node = RubyVM::AbstractSyntaxTree.of(loc, keep_script_lines: true)
|
||||||
|
|
||||||
Spotter.new(node, **opts).spot
|
Spotter.new(node, **opts).spot
|
||||||
|
@ -1231,4 +1231,30 @@ undefined method `foo' for nil:NilClass
|
|||||||
end
|
end
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
|
def raise_name_error
|
||||||
|
1.time
|
||||||
|
end
|
||||||
|
|
||||||
|
def test_spot_with_backtrace_location
|
||||||
|
lineno = __LINE__
|
||||||
|
begin
|
||||||
|
raise_name_error
|
||||||
|
rescue NameError => exc
|
||||||
|
end
|
||||||
|
|
||||||
|
spot = ErrorHighlight.spot(exc).except(:script_lines)
|
||||||
|
assert_equal(lineno - 4, spot[:first_lineno])
|
||||||
|
assert_equal(lineno - 4, spot[:last_lineno])
|
||||||
|
assert_equal(5, spot[:first_column])
|
||||||
|
assert_equal(10, spot[:last_column])
|
||||||
|
assert_equal(" 1.time\n", spot[:snippet])
|
||||||
|
|
||||||
|
spot = ErrorHighlight.spot(exc, backtrace_location: exc.backtrace_locations[1]).except(:script_lines)
|
||||||
|
assert_equal(lineno + 2, spot[:first_lineno])
|
||||||
|
assert_equal(lineno + 2, spot[:last_lineno])
|
||||||
|
assert_equal(6, spot[:first_column])
|
||||||
|
assert_equal(22, spot[:last_column])
|
||||||
|
assert_equal(" raise_name_error\n", spot[:snippet])
|
||||||
|
end
|
||||||
end
|
end
|
||||||
|
Loading…
x
Reference in New Issue
Block a user