summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--lib/irb/inspector.rb16
-rw-r--r--test/irb/test_context.rb23
2 files changed, 22 insertions, 17 deletions
diff --git a/lib/irb/inspector.rb b/lib/irb/inspector.rb
index 66837f1390..92de2830bc 100644
--- a/lib/irb/inspector.rb
+++ b/lib/irb/inspector.rb
@@ -100,21 +100,19 @@ module IRB # :nodoc:
# Proc to call when the input is evaluated and output in irb.
def inspect_value(v)
@inspect.call(v)
+ rescue
+ puts "(Object doesn't support #inspect)"
+ ''
end
end
Inspector.def_inspector([false, :to_s, :raw]){|v| v.to_s}
Inspector.def_inspector([:p, :inspect]){|v|
- begin
- result = v.inspect
- if IRB.conf[:MAIN_CONTEXT]&.use_colorize? && Color.inspect_colorable?(v)
- result = Color.colorize_code(result)
- end
- result
- rescue NoMethodError
- puts "(Object doesn't support #inspect)"
- ''
+ result = v.inspect
+ if IRB.conf[:MAIN_CONTEXT]&.use_colorize? && Color.inspect_colorable?(v)
+ result = Color.colorize_code(result)
end
+ result
}
Inspector.def_inspector([true, :pp, :pretty_inspect], proc{require "irb/color_printer"}){|v|
if IRB.conf[:MAIN_CONTEXT]&.use_colorize?
diff --git a/test/irb/test_context.rb b/test/irb/test_context.rb
index a8ff64067b..d1c3ec67ac 100644
--- a/test/irb/test_context.rb
+++ b/test/irb/test_context.rb
@@ -106,15 +106,22 @@ module TestIRB
def test_eval_object_without_inspect_method
verbose, $VERBOSE = $VERBOSE, nil
- input = TestInputMethod.new([
- "BasicObject.new\n",
- ])
- irb = IRB::Irb.new(IRB::WorkSpace.new(Object.new), input)
- out, err = capture_output do
- irb.eval_input
+ all_assertions do |all|
+ IRB::Inspector::INSPECTORS.invert.each_value do |mode|
+ all.for(mode) do
+ input = TestInputMethod.new([
+ "[BasicObject.new, Class.new]\n",
+ ])
+ irb = IRB::Irb.new(IRB::WorkSpace.new(Object.new), input)
+ irb.context.inspect_mode = mode
+ out, err = capture_output do
+ irb.eval_input
+ end
+ assert_empty err
+ assert_match(/\(Object doesn't support #inspect\)\n(=> )?\n/, out)
+ end
+ end
end
- assert_empty err
- assert(/\(Object doesn't support #inspect\)\n(=> )?\n/, out)
ensure
$VERBOSE = verbose
end