From 7eb3fe87e52783d9ce2402bdeeea83fd9b6f43f7 Mon Sep 17 00:00:00 2001 From: Stan Lo Date: Tue, 22 Aug 2023 18:54:58 +0100 Subject: [PATCH] Print deprecation message for prompt_n methods They were removed in #685, but we should still keep them to avoid breaking changes to tools like Chef. https://github.com/chef/chef/blob/533ff089479763f29045e4e6ddf388b73fc99338/lib/chef/shell.rb#L138 --- lib/irb/context.rb | 13 +++++++++++++ test/irb/test_context.rb | 12 ++++++++++++ 2 files changed, 25 insertions(+) diff --git a/lib/irb/context.rb b/lib/irb/context.rb index 6d6261e60..a20510d73 100644 --- a/lib/irb/context.rb +++ b/lib/irb/context.rb @@ -229,6 +229,19 @@ def main # # See IRB@Customizing+the+IRB+Prompt for more information. attr_accessor :prompt_c + + # TODO: Remove this when developing v2.0 + def prompt_n + warn "IRB::Context#prompt_n is deprecated and will be removed in the next major release." + "" + end + + # TODO: Remove this when developing v2.0 + def prompt_n=(_) + warn "IRB::Context#prompt_n= is deprecated and will be removed in the next major release." + "" + end + # Can be either the default IRB.conf[:AUTO_INDENT], or the # mode set by #prompt_mode= # diff --git a/test/irb/test_context.rb b/test/irb/test_context.rb index 29c67392f..dae0f8f6e 100644 --- a/test/irb/test_context.rb +++ b/test/irb/test_context.rb @@ -90,6 +90,18 @@ def test_eval_input_raise2x ], out) end + def test_prompt_n_deprecation + irb = IRB::Irb.new(IRB::WorkSpace.new(Object.new)) + + out, err = capture_output do + irb.context.prompt_n = "foo" + irb.context.prompt_n + end + + assert_include err, "IRB::Context#prompt_n is deprecated" + assert_include err, "IRB::Context#prompt_n= is deprecated" + end + def test_output_to_pipe require 'stringio' input = TestInputMethod.new(["n=1"])