summaryrefslogtreecommitdiff
path: root/test/ruby/test_autoload.rb
diff options
context:
space:
mode:
authorJean Boussier <[email protected]>2022-06-18 10:29:52 +0200
committerJean Boussier <[email protected]>2022-06-18 14:49:02 +0200
commiteca31d24d606a73def3674938112dc3c5b79c445 (patch)
treeaa713097baa398f55af41319f6fe1d5c2c583730 /test/ruby/test_autoload.rb
parente7117115399981e1258ca6301e76cc3a24c509e7 (diff)
[Bug #18813] Warn when autoload has to lookup in parent namespace
This is a verbose mode only warning.
Notes
Notes: Merged: https://github.com/ruby/ruby/pull/6038
Diffstat (limited to 'test/ruby/test_autoload.rb')
-rw-r--r--test/ruby/test_autoload.rb17
1 files changed, 17 insertions, 0 deletions
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