@@ -203,6 +203,20 @@ def test_reload_preserves_loaded_features
203203 assert_equal 2 , output . scan ( "=> true" ) . count
204204 end
205205
206+ def test_require_native_extension
207+ write_ruby <<~'RUBY'
208+ binding.irb
209+ RUBY
210+
211+ output = run_ruby_file do
212+ type "require 'etc'"
213+ type "Etc.getlogin"
214+ type "exit!"
215+ end
216+
217+ assert_include output , "=> true"
218+ end
219+
206220 def test_require_does_not_modify_load_path
207221 write_ruby <<~'RUBY'
208222 binding.irb
@@ -267,9 +281,11 @@ def create_pwd_file(name, content)
267281 end
268282 end
269283
270- class ReloadCommandTest < TestCase
284+ class BoxReloadCommandTest < TestCase
271285 def setup
272286 super
287+ omit "BoxReload requires Ruby::Box" if !defined? ( Ruby ::Box ) || !Ruby ::Box . enabled?
288+
273289 @tmpdir = Dir . mktmpdir
274290 @valid_file = File . join ( @tmpdir , "valid.rb" )
275291 File . write ( @valid_file , "VALID = true\n " )
@@ -279,25 +295,28 @@ def setup
279295 require "irb/command/reload"
280296 IRB . setup ( __FILE__ , argv : [ ] )
281297 @original_reloadable = IRB . conf [ :RELOADABLE_REQUIRE ]
282- @original_files = IRB . conf [ :__RELOADABLE_FILES__ ]
283298 IRB . conf [ :RELOADABLE_REQUIRE ] = true
284- IRB . conf [ :__RELOADABLE_FILES__ ] = Set . new
299+
300+ @saved_files = IRB ::ReloadableRequire . reloadable_files . dup
301+ IRB ::ReloadableRequire . reloadable_files . clear
285302 end
286303
287304 def teardown
288305 super
289- FileUtils . rm_rf ( @tmpdir )
290- IRB . conf [ :RELOADABLE_REQUIRE ] = @original_reloadable
291- IRB . conf [ :__RELOADABLE_FILES__ ] = @original_files
306+ FileUtils . rm_rf ( @tmpdir ) if @tmpdir
307+ if defined? ( IRB ::ReloadableRequire ) && @saved_files
308+ IRB . conf [ :RELOADABLE_REQUIRE ] = @original_reloadable
309+ IRB ::ReloadableRequire . reloadable_files . replace ( @saved_files )
310+ end
292311 end
293312
294313 def test_reload_file_preserves_loaded_features_on_syntax_error
295314 $LOADED_FEATURES << @valid_file
296315
297316 File . write ( @valid_file , "def broken(" )
298317
299- cmd = IRB ::Command ::Reload . new ( nil )
300- IRB . conf [ :__RELOADABLE_FILES__ ] << @valid_file
318+ cmd = IRB ::Command ::BoxReload . new ( nil )
319+ IRB :: ReloadableRequire . reloadable_files << @valid_file
301320 cmd . execute ( nil )
302321
303322 assert_equal true , $LOADED_FEATURES. include? ( @valid_file )
@@ -309,8 +328,8 @@ def test_reload_file_preserves_loaded_features_on_load_error
309328 missing_file = File . join ( @tmpdir , "missing.rb" )
310329 $LOADED_FEATURES << missing_file
311330
312- cmd = IRB ::Command ::Reload . new ( nil )
313- IRB . conf [ :__RELOADABLE_FILES__ ] << missing_file
331+ cmd = IRB ::Command ::BoxReload . new ( nil )
332+ IRB :: ReloadableRequire . reloadable_files << missing_file
314333 cmd . execute ( nil )
315334
316335 assert_equal true , $LOADED_FEATURES. include? ( missing_file )
@@ -319,33 +338,6 @@ def test_reload_file_preserves_loaded_features_on_load_error
319338 end
320339 end
321340
322- class ReloadableRequireMonkeyPatchTest < TestCase
323- def setup
324- super
325- omit "ReloadableRequire requires Ruby::Box" if !defined? ( Ruby ::Box ) || !Ruby ::Box . enabled?
326- require "irb/reloadable_require"
327- @saved_original_require = Ruby ::Box . instance_method ( :__irb_original_require__ )
328- end
329-
330- def teardown
331- super
332- saved = @saved_original_require
333- if saved
334- Ruby ::Box . define_method ( :__irb_original_require__ , saved )
335- end
336- end
337-
338- def test_original_require_alias_preserved_on_double_load
339- IRB ::ReloadableRequire . apply_autoload_hook
340-
341- # Double-loading the file should not overwrite __irb_original_require__
342- # with the already-patched require method.
343- load File . expand_path ( "../../lib/irb/reloadable_require.rb" , __dir__ )
344-
345- assert_equal @saved_original_require , Ruby ::Box . instance_method ( :__irb_original_require__ )
346- end
347- end
348-
349341 class ReloadableRequireDisabledTest < IntegrationTestCase
350342 def setup
351343 super
0 commit comments