ruby-changes:65968
From: Nobuyoshi <ko1@a...>
Date: Mon, 26 Apr 2021 21:15:17 +0900 (JST)
Subject: [ruby-changes:65968] 5219b4ddb4 (master): [ruby/irb] Added setup and teardown to TestIRB::TestInit
https://git.ruby-lang.org/ruby.git/commit/?id=5219b4ddb4 From 5219b4ddb4b89dfe8a951da75f5ab78431781d7f Mon Sep 17 00:00:00 2001 From: Nobuyoshi Nakada <nobu@r...> Date: Thu, 15 Apr 2021 22:24:02 +0900 Subject: [ruby/irb] Added setup and teardown to TestIRB::TestInit Not to be affected by existing rc files in all tests. https://github.com/ruby/irb/commit/bf434892b4 --- test/irb/test_init.rb | 37 +++++++++++++++++-------------------- 1 file changed, 17 insertions(+), 20 deletions(-) diff --git a/test/irb/test_init.rb b/test/irb/test_init.rb index 2c50b5d..d57f075 100644 --- a/test/irb/test_init.rb +++ b/test/irb/test_init.rb @@ -5,6 +5,19 @@ require "fileutils" https://github.com/ruby/ruby/blob/trunk/test/irb/test_init.rb#L5 module TestIRB class TestInit < Test::Unit::TestCase + def setup + # IRBRC is for RVM... + @backup_env = %w[HOME XDG_CONFIG_HOME IRBRC].each_with_object({}) do |env, hash| + hash[env] = ENV.delete(env) + end + ENV["HOME"] = @tmpdir = Dir.mktmpdir("test_irb_init_#{$$}") + end + + def teardown + ENV.update(@backup_env) + FileUtils.rm_rf(@tmpdir) + end + def test_setup_with_argv_preserves_global_argv argv = ["foo", "bar"] with_argv(argv) do @@ -20,12 +33,8 @@ module TestIRB https://github.com/ruby/ruby/blob/trunk/test/irb/test_init.rb#L33 end def test_rc_file - backup_irbrc = ENV.delete("IRBRC") # This is for RVM... - backup_xdg_config_home = ENV.delete("XDG_CONFIG_HOME") - backup_home = ENV["HOME"] - Dir.mktmpdir("test_irb_init_#{$$}") do |tmpdir| - ENV["HOME"] = tmpdir - + tmpdir = @tmpdir + Dir.chdir(tmpdir) do IRB.conf[:RC_NAME_GENERATOR] = nil assert_equal(tmpdir+"/.irb#{IRB::IRBRC_EXT}", IRB.rc_file) assert_equal(tmpdir+"/.irb_history", IRB.rc_file("_history")) @@ -34,19 +43,11 @@ module TestIRB https://github.com/ruby/ruby/blob/trunk/test/irb/test_init.rb#L43 assert_equal(tmpdir+"/.irb#{IRB::IRBRC_EXT}", IRB.rc_file) assert_equal(tmpdir+"/.irb_history", IRB.rc_file("_history")) end - ensure - ENV["HOME"] = backup_home - ENV["XDG_CONFIG_HOME"] = backup_xdg_config_home - ENV["IRBRC"] = backup_irbrc end def test_rc_file_in_subdir - backup_irbrc = ENV.delete("IRBRC") # This is for RVM... - backup_xdg_config_home = ENV.delete("XDG_CONFIG_HOME") - backup_home = ENV["HOME"] - Dir.mktmpdir("test_irb_init_#{$$}") do |tmpdir| - ENV["HOME"] = tmpdir - + tmpdir = @tmpdir + Dir.chdir(tmpdir) do FileUtils.mkdir_p("#{tmpdir}/mydir") Dir.chdir("#{tmpdir}/mydir") do IRB.conf[:RC_NAME_GENERATOR] = nil @@ -58,10 +59,6 @@ module TestIRB https://github.com/ruby/ruby/blob/trunk/test/irb/test_init.rb#L59 assert_equal(tmpdir+"/.irb_history", IRB.rc_file("_history")) end end - ensure - ENV["HOME"] = backup_home - ENV["XDG_CONFIG_HOME"] = backup_xdg_config_home - ENV["IRBRC"] = backup_irbrc end def test_recovery_sigint -- cgit v1.1 -- ML: ruby-changes@q... Info: http://www.atdot.net/~ko1/quickml/