diff options
author | tomoya ishida <[email protected]> | 2024-07-18 19:56:14 +0900 |
---|---|---|
committer | git <[email protected]> | 2024-07-18 10:56:19 +0000 |
commit | c304bf13b55a30b9982f9c9e6187f5b56fc731b0 (patch) | |
tree | f36434e298a438c6d48c1bf890709cc6a864a359 /test | |
parent | b61e3a6218fc60485e7ea33985f0d4b46dad80ce (diff) |
[ruby/irb] Clear ENV["XDG_CONFIG_HOME"] to avoid loading
user-defined irbrc in TestIRB::ConfigValidationTest
(https://github.com/ruby/irb/pull/982)
https://github.com/ruby/irb/commit/632da0ff29
Diffstat (limited to 'test')
-rw-r--r-- | test/irb/helper.rb | 13 | ||||
-rw-r--r-- | test/irb/test_command.rb | 7 | ||||
-rw-r--r-- | test/irb/test_history.rb | 9 | ||||
-rw-r--r-- | test/irb/test_init.rb | 8 |
4 files changed, 20 insertions, 17 deletions
diff --git a/test/irb/helper.rb b/test/irb/helper.rb index acaf6277f3..ea2c6ef16a 100644 --- a/test/irb/helper.rb +++ b/test/irb/helper.rb @@ -49,6 +49,19 @@ module TestIRB !Pathname(__dir__).join("../../", "irb.gemspec").exist? end + def setup_envs(home:) + @backup_home = ENV["HOME"] + ENV["HOME"] = home + @backup_xdg_config_home = ENV.delete("XDG_CONFIG_HOME") + @backup_irbrc = ENV.delete("IRBRC") + end + + def teardown_envs + ENV["HOME"] = @backup_home + ENV["XDG_CONFIG_HOME"] = @backup_xdg_config_home + ENV["IRBRC"] = @backup_irbrc + end + def save_encodings @default_encoding = [Encoding.default_external, Encoding.default_internal] @stdio_encodings = [STDIN, STDOUT, STDERR].map {|io| [io.external_encoding, io.internal_encoding] } diff --git a/test/irb/test_command.rb b/test/irb/test_command.rb index 30c3f5ca2c..567c3216cc 100644 --- a/test/irb/test_command.rb +++ b/test/irb/test_command.rb @@ -15,9 +15,7 @@ module TestIRB Dir.mkdir(@tmpdir) end Dir.chdir(@tmpdir) - @home_backup = ENV["HOME"] - ENV["HOME"] = @tmpdir - @xdg_config_home_backup = ENV.delete("XDG_CONFIG_HOME") + setup_envs(home: @tmpdir) save_encodings IRB.instance_variable_get(:@CONF).clear IRB.instance_variable_set(:@existing_rc_name_generators, nil) @@ -25,8 +23,7 @@ module TestIRB end def teardown - ENV["XDG_CONFIG_HOME"] = @xdg_config_home_backup - ENV["HOME"] = @home_backup + teardown_envs Dir.chdir(@pwd) FileUtils.rm_rf(@tmpdir) restore_encodings diff --git a/test/irb/test_history.rb b/test/irb/test_history.rb index 63be35fdaa..84f0438929 100644 --- a/test/irb/test_history.rb +++ b/test/irb/test_history.rb @@ -12,19 +12,14 @@ module TestIRB def setup @original_verbose, $VERBOSE = $VERBOSE, nil @tmpdir = Dir.mktmpdir("test_irb_history_") - @backup_home = ENV["HOME"] - @backup_xdg_config_home = ENV.delete("XDG_CONFIG_HOME") - @backup_irbrc = ENV.delete("IRBRC") + setup_envs(home: @tmpdir) @backup_default_external = Encoding.default_external - ENV["HOME"] = @tmpdir IRB.instance_variable_set(:@existing_rc_name_generators, nil) end def teardown IRB.instance_variable_set(:@existing_rc_name_generators, nil) - ENV["HOME"] = @backup_home - ENV["XDG_CONFIG_HOME"] = @backup_xdg_config_home - ENV["IRBRC"] = @backup_irbrc + teardown_envs Encoding.default_external = @backup_default_external $VERBOSE = @original_verbose FileUtils.rm_rf(@tmpdir) diff --git a/test/irb/test_init.rb b/test/irb/test_init.rb index c423fa112e..3e8d01c5ce 100644 --- a/test/irb/test_init.rb +++ b/test/irb/test_init.rb @@ -270,17 +270,15 @@ module TestIRB class ConfigValidationTest < TestCase def setup - @original_home = ENV["HOME"] - @original_irbrc = ENV["IRBRC"] # To prevent the test from using the user's .irbrc file - ENV["HOME"] = @home = Dir.mktmpdir + @home = Dir.mktmpdir + setup_envs(home: @home) super end def teardown super - ENV["IRBRC"] = @original_irbrc - ENV["HOME"] = @original_home + teardown_envs File.unlink(@irbrc) Dir.rmdir(@home) IRB.instance_variable_set(:@existing_rc_name_generators, nil) |