diff --git a/lib/irb/init.rb b/lib/irb/init.rb index 7a16d922a..3c52d016d 100644 --- a/lib/irb/init.rb +++ b/lib/irb/init.rb @@ -347,6 +347,7 @@ def IRB.parse_opts(argv: ::ARGV) @CONF[:COMPLETOR] = :type when /^--prompt-mode(?:=(.+))?/, /^--prompt(?:=(.+))?/ opt = $1 || argv.shift + fail UndefinedPromptMode, opt unless opt prompt_mode = opt.upcase.tr("-", "_").intern @CONF[:PROMPT_MODE] = prompt_mode when "--nobanner" diff --git a/test/irb/test_init.rb b/test/irb/test_init.rb index 1e2e63d0a..601a712fc 100644 --- a/test/irb/test_init.rb +++ b/test/irb/test_init.rb @@ -290,6 +290,23 @@ def test_nobanner assert_equal(false, IRB.conf[:SHOW_BANNER]) end + def test_prompt_option + orig_prompt_mode = IRB.conf[:PROMPT_MODE] + IRB.setup(eval("__FILE__"), argv: %w[--prompt simple]) + assert_equal(:SIMPLE, IRB.conf[:PROMPT_MODE]) + + IRB.setup(eval("__FILE__"), argv: %w[--prompt-mode=inf-ruby]) + assert_equal(:INF_RUBY, IRB.conf[:PROMPT_MODE]) + + %w[--prompt --prompt-mode].each do |opt| + assert_raise(IRB::UndefinedPromptMode) do + IRB.setup(eval("__FILE__"), argv: [opt]) + end + end + ensure + IRB.conf[:PROMPT_MODE] = orig_prompt_mode + end + def test_measure_when_exception_occurs out, err = execute_lines( "measure\n",