diff --git a/lib/irb/command/load.rb b/lib/irb/command/load.rb index 983eeba61..1efe23243 100644 --- a/lib/irb/command/load.rb +++ b/lib/irb/command/load.rb @@ -58,15 +58,15 @@ def execute_internal(file_name = nil) rescue LoadError end when /\.(so|o|sl)$/ - return ruby_require(file_name) + return require(file_name) end begin irb_load(f = file_name + ".rb") $".push f - return true + true rescue LoadError - return ruby_require(file_name) + require(file_name) end end end diff --git a/lib/irb/ext/loader.rb b/lib/irb/ext/loader.rb index df5aaa8e5..0955b4acf 100644 --- a/lib/irb/ext/loader.rb +++ b/lib/irb/ext/loader.rb @@ -13,9 +13,6 @@ class LoadAbort < Exception;end # See ExtendCommandBundle for more information. module IrbLoader - alias ruby_load load - alias ruby_require require - # Loads the given file similarly to Kernel#load def irb_load(fn, priv = nil) path = search_file_from_ruby_path(fn) diff --git a/test/irb/test_command.rb b/test/irb/test_command.rb index 73905e66c..1a99bc7eb 100644 --- a/test/irb/test_command.rb +++ b/test/irb/test_command.rb @@ -494,6 +494,22 @@ def test_irb_require_skips_file_already_loaded_by_require assert_match(/probe_loaded/, out) assert_match(/prefix_loaded/, out) end + + def test_irb_require_falls_back_to_kernel_require_when_not_in_load_path + code = <<~RUBY + p 'fallback_loaded' + 'fallback_path_should_not_print_return_value'.itself + RUBY + File.write("#{@tmpdir}/irb_require_fallback.rb", code) + + out, err = execute_lines( + "irb_require './irb_require_fallback'\n", + ) + + assert_empty(err) + assert_include(out, 'fallback_loaded') + assert_not_include(out, 'fallback_path_should_not_print_return_value') + end end class WorkspaceCommandTestCase < CommandTestCase @@ -592,6 +608,7 @@ def test_workspaces_various_truncation '1234567891234567891...', 'aaaaaaaaaaaaaaaaaaa...' ] + assert_empty(err) assert_include(out, "[#{expected_truncations.join(", ")}]") end end