From 927308108cced69cae478798004524b9a5d2f252 Mon Sep 17 00:00:00 2001 From: Nobuyoshi Nakada Date: Tue, 7 Apr 2020 21:35:28 +0900 Subject: Fix source location of autoloaded constant [Bug #16764] --- test/ruby/test_autoload.rb | 13 +++++++++++++ 1 file changed, 13 insertions(+) (limited to 'test/ruby/test_autoload.rb') diff --git a/test/ruby/test_autoload.rb b/test/ruby/test_autoload.rb index b3ccf183ec..d3470d59d4 100644 --- a/test/ruby/test_autoload.rb +++ b/test/ruby/test_autoload.rb @@ -427,6 +427,19 @@ p Foo::Bar end end + def test_source_location + klass = self.class + bug = "Bug16764" + Dir.mktmpdir('autoload') do |tmpdir| + path = "#{tmpdir}/test-#{bug}.rb" + File.write(path, "#{klass}::#{bug} = __FILE__\n") + klass.autoload(:Bug16764, path) + assert_equal [__FILE__, __LINE__-1], klass.const_source_location(bug) + assert_equal path, klass.const_get(bug) + assert_equal [path, 1], klass.const_source_location(bug) + end + end + def test_no_leak assert_no_memory_leak([], '', <<~'end;', 'many autoloads', timeout: 60) 200000.times do |i| -- cgit v1.2.3