diff options
author | nobu <nobu@b2dd03c8-39d4-4d8f-98ff-823fe69b080e> | 2018-06-19 08:15:52 +0000 |
---|---|---|
committer | nobu <nobu@b2dd03c8-39d4-4d8f-98ff-823fe69b080e> | 2018-06-19 08:15:52 +0000 |
commit | 1b474b869ccc3e93335e5b7ad01513d58f1fe1a3 (patch) | |
tree | 49762010329fab953fa6561020a14cfcf3e5e5e1 /test | |
parent | b3f56c6be05cf5f4a15c58d54aea49d780fcaa3c (diff) |
variable.c: fix receiver on private constant
* variable.c (rb_const_search): fix NameError :receiver attribute
on private constant, should raise with the included module, not
the ICLASS.
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@63696 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
Diffstat (limited to 'test')
-rw-r--r-- | test/ruby/test_module.rb | 42 |
1 files changed, 38 insertions, 4 deletions
diff --git a/test/ruby/test_module.rb b/test/ruby/test_module.rb index 570241a683..78b285157f 100644 --- a/test/ruby/test_module.rb +++ b/test/ruby/test_module.rb @@ -1349,21 +1349,55 @@ class TestModule < Test::Unit::TestCase assert_raise(ArgumentError, bug8540) { c.new.send :foo= } end - def test_private_constant + def test_private_constant_in_class c = Class.new c.const_set(:FOO, "foo") assert_equal("foo", c::FOO) c.private_constant(:FOO) - assert_raise(NameError) { c::FOO } + e = assert_raise(NameError) {c::FOO} + assert_equal(c, e.receiver) + assert_equal(:FOO, e.name) assert_equal("foo", c.class_eval("FOO")) assert_equal("foo", c.const_get("FOO")) $VERBOSE, verbose = nil, $VERBOSE c.const_set(:FOO, "foo") $VERBOSE = verbose - assert_raise(NameError) { c::FOO } - assert_raise_with_message(NameError, /#{c}::FOO/) do + e = assert_raise(NameError) {c::FOO} + assert_equal(c, e.receiver) + assert_equal(:FOO, e.name) + e = assert_raise_with_message(NameError, /#{c}::FOO/) do Class.new(c)::FOO end + assert_equal(c, e.receiver) + assert_equal(:FOO, e.name) + end + + def test_private_constant_in_module + m = Module.new + m.const_set(:FOO, "foo") + assert_equal("foo", m::FOO) + m.private_constant(:FOO) + e = assert_raise(NameError) {m::FOO} + assert_equal(m, e.receiver) + assert_equal(:FOO, e.name) + assert_equal("foo", m.class_eval("FOO")) + assert_equal("foo", m.const_get("FOO")) + $VERBOSE, verbose = nil, $VERBOSE + m.const_set(:FOO, "foo") + $VERBOSE = verbose + e = assert_raise(NameError) {m::FOO} + assert_equal(m, e.receiver) + assert_equal(:FOO, e.name) + e = assert_raise(NameError, /#{m}::FOO/) do + Module.new {include m}::FOO + end + assert_equal(m, e.receiver) + assert_equal(:FOO, e.name) + e = assert_raise(NameError, /#{m}::FOO/) do + Class.new {include m}::FOO + end + assert_equal(m, e.receiver) + assert_equal(:FOO, e.name) end def test_private_constant2 |