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 e3ece31
Show file tree
Hide file tree
Showing 3 changed files with 43 additions and 1 deletion.
2 changes: 1 addition & 1 deletion lib/irb.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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
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 e3ece31

Please sign in to comment.