diff --git a/lib/irb.rb b/lib/irb.rb index 6e3448d69..f3abed820 100644 --- a/lib/irb.rb +++ b/lib/irb.rb @@ -1514,7 +1514,7 @@ class Binding # See IRB for more information. def irb(show_code: true) # Setup IRB with the current file's path and no command line arguments - IRB.setup(source_location[0], argv: []) + IRB.setup(source_location[0], argv: []) unless IRB.initialized? # Create a new workspace using the current binding workspace = IRB::WorkSpace.new(self) # Print the code around the binding if show_code is true diff --git a/lib/irb/init.rb b/lib/irb/init.rb index 66e7b6146..a434ab23e 100644 --- a/lib/irb/init.rb +++ b/lib/irb/init.rb @@ -6,6 +6,7 @@ module IRB # :nodoc: @CONF = {} + @INITIALIZED = false # Displays current configuration. # # Modifying the configuration is achieved by sending a message to IRB.conf. @@ -41,6 +42,10 @@ def IRB.version format("irb %s (%s)", @RELEASE_VERSION, @LAST_UPDATE_DATE) end + def IRB.initialized? + !!@INITIALIZED + end + # initialize config def IRB.setup(ap_path, argv: ::ARGV) IRB.init_config(ap_path) @@ -52,6 +57,7 @@ def IRB.setup(ap_path, argv: ::ARGV) unless @CONF[:PROMPT][@CONF[:PROMPT_MODE]] fail UndefinedPromptMode, @CONF[:PROMPT_MODE] end + @INITIALIZED = true end # @CONF default setting diff --git a/test/irb/yamatanooroti/test_rendering.rb b/test/irb/yamatanooroti/test_rendering.rb index f698466e4..e121b302c 100644 --- a/test/irb/yamatanooroti/test_rendering.rb +++ b/test/irb/yamatanooroti/test_rendering.rb @@ -49,6 +49,42 @@ def test_launch EOC end + def test_configuration_file_is_skipped_with_dash_f + write_irbrc <<~'LINES' + puts '.irbrc file should be ignored when -f is used' + LINES + start_terminal(25, 80, %W{ruby -I#{@pwd}/lib #{@pwd}/exe/irb -f}, startup_message: '') + write(<<~EOC) + 'Hello, World!' + EOC + close + assert_screen(<<~EOC) + irb(main):001> 'Hello, World!' + => "Hello, World!" + irb(main):002> + EOC + end + + def test_configuration_file_is_skipped_with_dash_f_for_nested_sessions + write_irbrc <<~'LINES' + puts '.irbrc file should be ignored when -f is used' + LINES + start_terminal(25, 80, %W{ruby -I#{@pwd}/lib #{@pwd}/exe/irb -f}, startup_message: '') + write(<<~EOC) + 'Hello, World!' + binding.irb + exit! + EOC + close + assert_screen(<<~EOC) + irb(main):001> 'Hello, World!' + => "Hello, World!" + irb(main):002> binding.irb + irb(main):003> exit! + irb(main):001> + EOC + end + def test_nomultiline write_irbrc <<~'LINES' puts 'start IRB'