@@ -11,7 +11,7 @@ def setup
1111 @backup_env = %w[ HOME XDG_CONFIG_HOME IRBRC ] . each_with_object ( { } ) do |env , hash |
1212 hash [ env ] = ENV . delete ( env )
1313 end
14- ENV [ "HOME" ] = @tmpdir = Dir . mktmpdir ( "test_irb_init_#{ $$} " )
14+ ENV [ "HOME" ] = @tmpdir = File . realpath ( Dir . mktmpdir ( "test_irb_init_#{ $$} " ) )
1515 end
1616
1717 def teardown
@@ -35,35 +35,133 @@ def test_setup_with_minimum_argv_does_not_change_dollar0
3535 end
3636
3737 def test_rc_file
38+ verbose , $VERBOSE = $VERBOSE, nil
3839 tmpdir = @tmpdir
3940 Dir . chdir ( tmpdir ) do
4041 ENV [ "XDG_CONFIG_HOME" ] = "#{ tmpdir } /xdg"
4142 IRB . conf [ :RC_NAME_GENERATOR ] = nil
42- assert_equal ( tmpdir +"/.irb #{ IRB :: IRBRC_EXT } " , IRB . rc_file )
43+ assert_equal ( tmpdir +"/.irbrc " , IRB . rc_file )
4344 assert_equal ( tmpdir +"/.irb_history" , IRB . rc_file ( "_history" ) )
4445 assert_file . not_exist? ( tmpdir +"/xdg" )
4546 IRB . conf [ :RC_NAME_GENERATOR ] = nil
46- FileUtils . touch ( tmpdir +"/.irb #{ IRB :: IRBRC_EXT } " )
47- assert_equal ( tmpdir +"/.irb #{ IRB :: IRBRC_EXT } " , IRB . rc_file )
47+ FileUtils . touch ( tmpdir +"/.irbrc " )
48+ assert_equal ( tmpdir +"/.irbrc " , IRB . rc_file )
4849 assert_equal ( tmpdir +"/.irb_history" , IRB . rc_file ( "_history" ) )
4950 assert_file . not_exist? ( tmpdir +"/xdg" )
5051 end
52+ ensure
53+ $VERBOSE = verbose
5154 end
5255
5356 def test_rc_file_in_subdir
57+ verbose , $VERBOSE = $VERBOSE, nil
5458 tmpdir = @tmpdir
5559 Dir . chdir ( tmpdir ) do
5660 FileUtils . mkdir_p ( "#{ tmpdir } /mydir" )
5761 Dir . chdir ( "#{ tmpdir } /mydir" ) do
5862 IRB . conf [ :RC_NAME_GENERATOR ] = nil
59- assert_equal ( tmpdir +"/.irb #{ IRB :: IRBRC_EXT } " , IRB . rc_file )
63+ assert_equal ( tmpdir +"/.irbrc " , IRB . rc_file )
6064 assert_equal ( tmpdir +"/.irb_history" , IRB . rc_file ( "_history" ) )
6165 IRB . conf [ :RC_NAME_GENERATOR ] = nil
62- FileUtils . touch ( tmpdir +"/.irb #{ IRB :: IRBRC_EXT } " )
63- assert_equal ( tmpdir +"/.irb #{ IRB :: IRBRC_EXT } " , IRB . rc_file )
66+ FileUtils . touch ( tmpdir +"/.irbrc " )
67+ assert_equal ( tmpdir +"/.irbrc " , IRB . rc_file )
6468 assert_equal ( tmpdir +"/.irb_history" , IRB . rc_file ( "_history" ) )
6569 end
6670 end
71+ ensure
72+ $VERBOSE = verbose
73+ end
74+
75+ def test_rc_files
76+ tmpdir = @tmpdir
77+ Dir . chdir ( tmpdir ) do
78+ ENV [ "XDG_CONFIG_HOME" ] = "#{ tmpdir } /xdg"
79+ IRB . conf [ :RC_NAME_GENERATOR ] = nil
80+ assert_includes IRB . rc_files , tmpdir +"/.irbrc"
81+ assert_includes IRB . rc_files ( "_history" ) , tmpdir +"/.irb_history"
82+ assert_file . not_exist? ( tmpdir +"/xdg" )
83+ IRB . conf [ :RC_NAME_GENERATOR ] = nil
84+ FileUtils . touch ( tmpdir +"/.irbrc" )
85+ assert_includes IRB . rc_files , tmpdir +"/.irbrc"
86+ assert_includes IRB . rc_files ( "_history" ) , tmpdir +"/.irb_history"
87+ assert_file . not_exist? ( tmpdir +"/xdg" )
88+ end
89+ end
90+
91+ def test_rc_files_in_subdir
92+ tmpdir = @tmpdir
93+ Dir . chdir ( tmpdir ) do
94+ FileUtils . mkdir_p ( "#{ tmpdir } /mydir" )
95+ Dir . chdir ( "#{ tmpdir } /mydir" ) do
96+ IRB . conf [ :RC_NAME_GENERATOR ] = nil
97+ assert_includes IRB . rc_files , tmpdir +"/.irbrc"
98+ assert_includes IRB . rc_files ( "_history" ) , tmpdir +"/.irb_history"
99+ IRB . conf [ :RC_NAME_GENERATOR ] = nil
100+ FileUtils . touch ( tmpdir +"/.irbrc" )
101+ assert_includes IRB . rc_files , tmpdir +"/.irbrc"
102+ assert_includes IRB . rc_files ( "_history" ) , tmpdir +"/.irb_history"
103+ end
104+ end
105+ end
106+
107+ def test_rc_files_has_file_from_xdg_env
108+ tmpdir = @tmpdir
109+ ENV [ "XDG_CONFIG_HOME" ] = "#{ tmpdir } /xdg"
110+ xdg_config = ENV [ "XDG_CONFIG_HOME" ] +"/irb/irbrc"
111+
112+ FileUtils . mkdir_p ( xdg_config )
113+
114+ Dir . chdir ( tmpdir ) do
115+ IRB . conf [ :RC_NAME_GENERATOR ] = nil
116+ assert_includes IRB . rc_files , xdg_config
117+ end
118+ ensure
119+ ENV [ "XDG_CONFIG_HOME" ] = nil
120+ end
121+
122+ def test_rc_files_has_file_from_irbrc_env
123+ tmpdir = @tmpdir
124+ ENV [ "IRBRC" ] = "#{ tmpdir } /irb"
125+
126+ FileUtils . mkdir_p ( ENV [ "IRBRC" ] )
127+
128+ Dir . chdir ( tmpdir ) do
129+ IRB . conf [ :RC_NAME_GENERATOR ] = nil
130+ assert_includes IRB . rc_files , ENV [ "IRBRC" ]
131+ end
132+ ensure
133+ ENV [ "IRBRC" ] = nil
134+ end
135+
136+ def test_rc_files_has_file_from_home_env
137+ tmpdir = @tmpdir
138+ ENV [ "HOME" ] = "#{ tmpdir } /home"
139+
140+ FileUtils . mkdir_p ( ENV [ "HOME" ] )
141+
142+ Dir . chdir ( tmpdir ) do
143+ IRB . conf [ :RC_NAME_GENERATOR ] = nil
144+ assert_includes IRB . rc_files , ENV [ "HOME" ] +"/.irbrc"
145+ assert_includes IRB . rc_files , ENV [ "HOME" ] +"/.config/irb/irbrc"
146+ end
147+ ensure
148+ ENV [ "HOME" ] = nil
149+ end
150+
151+ def test_rc_files_contains_non_env_files
152+ tmpdir = @tmpdir
153+ FileUtils . mkdir_p ( "#{ tmpdir } /.irbrc" )
154+ FileUtils . mkdir_p ( "#{ tmpdir } /_irbrc" )
155+ FileUtils . mkdir_p ( "#{ tmpdir } /irb.rc" )
156+ FileUtils . mkdir_p ( "#{ tmpdir } /$irbrc" )
157+
158+ Dir . chdir ( tmpdir ) do
159+ IRB . conf [ :RC_NAME_GENERATOR ] = nil
160+ assert_includes IRB . rc_files , tmpdir +"/.irbrc"
161+ assert_includes IRB . rc_files , tmpdir +"/_irbrc"
162+ assert_includes IRB . rc_files , tmpdir +"/irb.rc"
163+ assert_includes IRB . rc_files , tmpdir +"/$irbrc"
164+ end
67165 end
68166
69167 def test_sigint_restore_default
0 commit comments