Skip to content

Commit

Permalink
Skip re-setup when creating a child session
Browse files Browse the repository at this point in the history
  • Loading branch information
nunosilva800 committed Feb 1, 2024
1 parent a641746 commit c533865
Show file tree
Hide file tree
Showing 3 changed files with 45 additions and 3 deletions.
6 changes: 3 additions & 3 deletions lib/irb.rb
Original file line number Diff line number Diff line change
Expand Up @@ -1513,8 +1513,6 @@ 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: [])
# Create a new workspace using the current binding
workspace = IRB::WorkSpace.new(self)
# Print the code around the binding if show_code is true
Expand All @@ -1534,10 +1532,12 @@ def irb(show_code: true)
IRB::Debug.insert_debug_break
debugger_irb.debug_break
else
# Setup IRB with the current file's path and no command line arguments
IRB.setup(source_location[0], argv: []) unless IRB.initialized?
# If we're not in a debugger session, create a new IRB instance with the current workspace
binding_irb = IRB::Irb.new(workspace)
binding_irb.context.irb_path = irb_path
binding_irb.run(IRB.conf)
binding_irb.run()
binding_irb.debug_break
end
end
Expand Down
6 changes: 6 additions & 0 deletions lib/irb/init.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down Expand Up @@ -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)
Expand All @@ -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
Expand Down
36 changes: 36 additions & 0 deletions test/irb/yamatanooroti/test_rendering.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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'
Expand Down

0 comments on commit c533865

Please sign in to comment.