mirror of
https://github.com/ruby/ruby.git
synced 2025-09-15 16:44:01 +02:00
[ruby/irb] Make SourceFinder ignore binary sources
(https://github.com/ruby/irb/pull/836)
73b35bb7f4
This commit is contained in:
parent
41e2d180a3
commit
8f4eda5092
2 changed files with 21 additions and 1 deletions
|
@ -34,7 +34,8 @@ module IRB
|
||||||
return unless receiver.respond_to?(method, true)
|
return unless receiver.respond_to?(method, true)
|
||||||
file, line = method_target(receiver, super_level, method, "receiver")
|
file, line = method_target(receiver, super_level, method, "receiver")
|
||||||
end
|
end
|
||||||
if file && line && File.exist?(file)
|
# If the line is zero, it means that the target's source is probably in a binary file, which we should ignore.
|
||||||
|
if file && line && !line.zero? && File.exist?(file)
|
||||||
Source.new(file: file, first_line: line, last_line: find_end(file, line))
|
Source.new(file: file, first_line: line, last_line: find_end(file, line))
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
|
@ -300,5 +300,24 @@ module TestIRB
|
||||||
|
|
||||||
assert_match(%r[#{@ruby_file.to_path}:5\s+class Bar\r\n end], out)
|
assert_match(%r[#{@ruby_file.to_path}:5\s+class Bar\r\n end], out)
|
||||||
end
|
end
|
||||||
|
|
||||||
|
def test_show_source_ignores_binary_source_file
|
||||||
|
write_ruby <<~RUBY
|
||||||
|
# io-console is an indirect dependency of irb
|
||||||
|
require "io/console"
|
||||||
|
|
||||||
|
binding.irb
|
||||||
|
RUBY
|
||||||
|
|
||||||
|
out = run_ruby_file do
|
||||||
|
# IO::ConsoleMode is defined in io-console gem's C extension
|
||||||
|
type "show_source IO::ConsoleMode"
|
||||||
|
type "exit"
|
||||||
|
end
|
||||||
|
|
||||||
|
# A safeguard to make sure the test subject is actually defined
|
||||||
|
refute_match(/NameError/, out)
|
||||||
|
assert_match(%r[Error: Couldn't locate a definition for IO::ConsoleMode], out)
|
||||||
|
end
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue