From e782ca865b3353870fd0fe5f45709c4997366d1a Mon Sep 17 00:00:00 2001 From: naruse Date: Mon, 13 Feb 2012 04:51:21 +0000 Subject: merge revision(s) 33935,33936,33987: [Backport #5702] * variable.c (set_const_visibility): Module#private_constant has changed the visibility of only the first argument. Now it changes all of them. [ruby-list:48558] * test/ruby/test_module.rb: add a test for above. * variable.c (set_const_visibility): print a warning when no argument is passwd to Module#private_constant. [ruby-list:48558] * vm_method.c (set_method_visibility): ditto for Module#private_class_method. * variable.c (set_const_visibility): clear inine-cache when constant's visibility is modified. [ruby-dev:44929] * test/ruby/test_module.rb (test_private_constants_clear_inlinecache): add test for it. git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/branches/ruby_1_9_3@34579 b2dd03c8-39d4-4d8f-98ff-823fe69b080e --- test/ruby/test_module.rb | 34 ++++++++++++++++++++++++++++++++++ 1 file changed, 34 insertions(+) (limited to 'test/ruby') diff --git a/test/ruby/test_module.rb b/test/ruby/test_module.rb index 198fcee978..6176f484bc 100644 --- a/test/ruby/test_module.rb +++ b/test/ruby/test_module.rb @@ -1077,6 +1077,19 @@ class TestModule < Test::Unit::TestCase assert_raise(NameError) { c::FOO } end + def test_private_constant2 + c = Class.new + c.const_set(:FOO, "foo") + c.const_set(:BAR, "bar") + assert_equal("foo", c::FOO) + assert_equal("bar", c::BAR) + c.private_constant(:FOO, :BAR) + assert_raise(NameError) { c::FOO } + assert_raise(NameError) { c::BAR } + assert_equal("foo", c.class_eval("FOO")) + assert_equal("bar", c.class_eval("BAR")) + end + class PrivateClass end private_constant :PrivateClass @@ -1124,6 +1137,27 @@ class TestModule < Test::Unit::TestCase assert_in_out_err([], src, %w(Object :ok), []) end + def test_private_constants_clear_inlinecache + bug5702 = '[ruby-dev:44929]' + src = <<-INPUT + class A + C = :Const + def self.get_C + A::C + end + # fill cache + A.get_C + private_constant :C, :D rescue nil + begin + A.get_C + rescue NameError + puts "A.get_C" + end + end + INPUT + assert_in_out_err([], src, %w(A.get_C), [], bug5702) + end + def test_constant_lookup_in_method_defined_by_class_eval src = <<-INPUT class A -- cgit v1.2.3