From eca31d24d606a73def3674938112dc3c5b79c445 Mon Sep 17 00:00:00 2001 From: Jean Boussier Date: Sat, 18 Jun 2022 10:29:52 +0200 Subject: [Bug #18813] Warn when autoload has to lookup in parent namespace This is a verbose mode only warning. --- test/ruby/test_autoload.rb | 17 +++++++++++++++++ 1 file changed, 17 insertions(+) (limited to 'test/ruby/test_autoload.rb') diff --git a/test/ruby/test_autoload.rb b/test/ruby/test_autoload.rb index bd875ec008..2e1a6ef2b9 100644 --- a/test/ruby/test_autoload.rb +++ b/test/ruby/test_autoload.rb @@ -479,6 +479,7 @@ p Foo::Bar File.write(autoload_path, '') assert_separately(%W[-I #{tmpdir}], <<-RUBY) + $VERBOSE = nil path = #{File.realpath(autoload_path).inspect} autoload :X, path assert_equal(path, Object.autoload?(:X)) @@ -557,4 +558,20 @@ p Foo::Bar RUBY end end + + def test_autoload_parent_namespace + Dir.mktmpdir('autoload') do |tmpdir| + autoload_path = File.join(tmpdir, "some_const.rb") + File.write(autoload_path, 'class SomeConst; end') + + assert_separately(%W[-I #{tmpdir}], <<-RUBY) + module SomeNamespace + autoload :SomeConst, #{File.realpath(autoload_path).inspect} + assert_warning(%r{/some_const\.rb to define SomeNamespace::SomeConst but it didn't}) do + assert_not_nil SomeConst + end + end + RUBY + end + end end -- cgit v1.2.3