Skip to content

Commit 632da0f

Browse files
authored
Clear ENV["XDG_CONFIG_HOME"] to avoid loading user-defined irbrc in TestIRB::ConfigValidationTest (#982)
1 parent cdaa356 commit 632da0f

File tree

4 files changed

+20
-17
lines changed

4 files changed

+20
-17
lines changed

test/irb/helper.rb

+13
Original file line numberDiff line numberDiff line change
@@ -49,6 +49,19 @@ def ruby_core?
4949
!Pathname(__dir__).join("../../", "irb.gemspec").exist?
5050
end
5151

52+
def setup_envs(home:)
53+
@backup_home = ENV["HOME"]
54+
ENV["HOME"] = home
55+
@backup_xdg_config_home = ENV.delete("XDG_CONFIG_HOME")
56+
@backup_irbrc = ENV.delete("IRBRC")
57+
end
58+
59+
def teardown_envs
60+
ENV["HOME"] = @backup_home
61+
ENV["XDG_CONFIG_HOME"] = @backup_xdg_config_home
62+
ENV["IRBRC"] = @backup_irbrc
63+
end
64+
5265
def save_encodings
5366
@default_encoding = [Encoding.default_external, Encoding.default_internal]
5467
@stdio_encodings = [STDIN, STDOUT, STDERR].map {|io| [io.external_encoding, io.internal_encoding] }

test/irb/test_command.rb

+2-5
Original file line numberDiff line numberDiff line change
@@ -15,18 +15,15 @@ def setup
1515
Dir.mkdir(@tmpdir)
1616
end
1717
Dir.chdir(@tmpdir)
18-
@home_backup = ENV["HOME"]
19-
ENV["HOME"] = @tmpdir
20-
@xdg_config_home_backup = ENV.delete("XDG_CONFIG_HOME")
18+
setup_envs(home: @tmpdir)
2119
save_encodings
2220
IRB.instance_variable_get(:@CONF).clear
2321
IRB.instance_variable_set(:@existing_rc_name_generators, nil)
2422
@is_win = (RbConfig::CONFIG['host_os'] =~ /mswin|msys|mingw|cygwin|bccwin|wince|emc/)
2523
end
2624

2725
def teardown
28-
ENV["XDG_CONFIG_HOME"] = @xdg_config_home_backup
29-
ENV["HOME"] = @home_backup
26+
teardown_envs
3027
Dir.chdir(@pwd)
3128
FileUtils.rm_rf(@tmpdir)
3229
restore_encodings

test/irb/test_history.rb

+2-7
Original file line numberDiff line numberDiff line change
@@ -12,19 +12,14 @@ class HistoryTest < TestCase
1212
def setup
1313
@original_verbose, $VERBOSE = $VERBOSE, nil
1414
@tmpdir = Dir.mktmpdir("test_irb_history_")
15-
@backup_home = ENV["HOME"]
16-
@backup_xdg_config_home = ENV.delete("XDG_CONFIG_HOME")
17-
@backup_irbrc = ENV.delete("IRBRC")
15+
setup_envs(home: @tmpdir)
1816
@backup_default_external = Encoding.default_external
19-
ENV["HOME"] = @tmpdir
2017
IRB.instance_variable_set(:@existing_rc_name_generators, nil)
2118
end
2219

2320
def teardown
2421
IRB.instance_variable_set(:@existing_rc_name_generators, nil)
25-
ENV["HOME"] = @backup_home
26-
ENV["XDG_CONFIG_HOME"] = @backup_xdg_config_home
27-
ENV["IRBRC"] = @backup_irbrc
22+
teardown_envs
2823
Encoding.default_external = @backup_default_external
2924
$VERBOSE = @original_verbose
3025
FileUtils.rm_rf(@tmpdir)

test/irb/test_init.rb

+3-5
Original file line numberDiff line numberDiff line change
@@ -270,17 +270,15 @@ def with_argv(argv)
270270

271271
class ConfigValidationTest < TestCase
272272
def setup
273-
@original_home = ENV["HOME"]
274-
@original_irbrc = ENV["IRBRC"]
275273
# To prevent the test from using the user's .irbrc file
276-
ENV["HOME"] = @home = Dir.mktmpdir
274+
@home = Dir.mktmpdir
275+
setup_envs(home: @home)
277276
super
278277
end
279278

280279
def teardown
281280
super
282-
ENV["IRBRC"] = @original_irbrc
283-
ENV["HOME"] = @original_home
281+
teardown_envs
284282
File.unlink(@irbrc)
285283
Dir.rmdir(@home)
286284
IRB.instance_variable_set(:@existing_rc_name_generators, nil)

0 commit comments

Comments
 (0)