Skip to content

Commit 06b2d00

Browse files
authored
Skip re-setup when creating a child session (#850)
1 parent bfafaa5 commit 06b2d00

File tree

3 files changed

+43
-1
lines changed

3 files changed

+43
-1
lines changed

lib/irb.rb

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1514,7 +1514,7 @@ class Binding
15141514
# See IRB for more information.
15151515
def irb(show_code: true)
15161516
# Setup IRB with the current file's path and no command line arguments
1517-
IRB.setup(source_location[0], argv: [])
1517+
IRB.setup(source_location[0], argv: []) unless IRB.initialized?
15181518
# Create a new workspace using the current binding
15191519
workspace = IRB::WorkSpace.new(self)
15201520
# Print the code around the binding if show_code is true

lib/irb/init.rb

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@
66

77
module IRB # :nodoc:
88
@CONF = {}
9+
@INITIALIZED = false
910
# Displays current configuration.
1011
#
1112
# Modifying the configuration is achieved by sending a message to IRB.conf.
@@ -41,6 +42,10 @@ def IRB.version
4142
format("irb %s (%s)", @RELEASE_VERSION, @LAST_UPDATE_DATE)
4243
end
4344

45+
def IRB.initialized?
46+
!!@INITIALIZED
47+
end
48+
4449
# initialize config
4550
def IRB.setup(ap_path, argv: ::ARGV)
4651
IRB.init_config(ap_path)
@@ -52,6 +57,7 @@ def IRB.setup(ap_path, argv: ::ARGV)
5257
unless @CONF[:PROMPT][@CONF[:PROMPT_MODE]]
5358
fail UndefinedPromptMode, @CONF[:PROMPT_MODE]
5459
end
60+
@INITIALIZED = true
5561
end
5662

5763
# @CONF default setting

test/irb/yamatanooroti/test_rendering.rb

Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -49,6 +49,42 @@ def test_launch
4949
EOC
5050
end
5151

52+
def test_configuration_file_is_skipped_with_dash_f
53+
write_irbrc <<~'LINES'
54+
puts '.irbrc file should be ignored when -f is used'
55+
LINES
56+
start_terminal(25, 80, %W{ruby -I#{@pwd}/lib #{@pwd}/exe/irb -f}, startup_message: '')
57+
write(<<~EOC)
58+
'Hello, World!'
59+
EOC
60+
close
61+
assert_screen(<<~EOC)
62+
irb(main):001> 'Hello, World!'
63+
=> "Hello, World!"
64+
irb(main):002>
65+
EOC
66+
end
67+
68+
def test_configuration_file_is_skipped_with_dash_f_for_nested_sessions
69+
write_irbrc <<~'LINES'
70+
puts '.irbrc file should be ignored when -f is used'
71+
LINES
72+
start_terminal(25, 80, %W{ruby -I#{@pwd}/lib #{@pwd}/exe/irb -f}, startup_message: '')
73+
write(<<~EOC)
74+
'Hello, World!'
75+
binding.irb
76+
exit!
77+
EOC
78+
close
79+
assert_screen(<<~EOC)
80+
irb(main):001> 'Hello, World!'
81+
=> "Hello, World!"
82+
irb(main):002> binding.irb
83+
irb(main):003> exit!
84+
irb(main):001>
85+
EOC
86+
end
87+
5288
def test_nomultiline
5389
write_irbrc <<~'LINES'
5490
puts 'start IRB'

0 commit comments

Comments
 (0)