From 5e16857315bf55307c5fc887ca6f03bfa0630a93 Mon Sep 17 00:00:00 2001 From: Marc-Andre Lafortune Date: Tue, 1 Sep 2020 21:22:20 -0400 Subject: Fix constant names set using const_set on a singleton class Fixes [Bug #14895] --- test/ruby/test_module.rb | 10 ++++++++-- 1 file changed, 8 insertions(+), 2 deletions(-) (limited to 'test/ruby') diff --git a/test/ruby/test_module.rb b/test/ruby/test_module.rb index d2da384cbd..94e415b08c 100644 --- a/test/ruby/test_module.rb +++ b/test/ruby/test_module.rb @@ -767,13 +767,13 @@ class TestModule < Test::Unit::TestCase n = Module.new m.const_set(:N, n) assert_nil(m.name) - assert_nil(n.name) + assert_match(/::N$/, n.name) assert_equal([:N], m.constants) m.module_eval("module O end") assert_equal([:N, :O], m.constants.sort) m.module_eval("class C; end") assert_equal([:C, :N, :O], m.constants.sort) - assert_nil(m::N.name) + assert_match(/::N$/, m::N.name) assert_match(/\A#::O\z/, m::O.name) assert_match(/\A#::C\z/, m::C.name) self.class.const_set(:M, m) @@ -2724,6 +2724,12 @@ class TestModule < Test::Unit::TestCase assert_not_predicate m.clone(freeze: false), :frozen? end + def test_module_name_in_singleton_method + s = Object.new.singleton_class + mod = s.const_set(:Foo, Module.new) + assert_match(/::Foo$/, mod.name, '[Bug #14895]') + end + private def assert_top_method_is_private(method) -- cgit v1.2.3