summaryrefslogtreecommitdiff
path: root/test/ruby/test_module.rb
diff options
context:
space:
mode:
authorNobuyoshi Nakada <[email protected]>2020-07-26 11:52:19 +0900
committerNobuyoshi Nakada <[email protected]>2021-09-17 11:14:04 +0900
commit178ee1e801acb33d13b3e8a630f6ca4926c68fbc (patch)
treefbc3b2dd31c4a3007580959b79ad08c4dbf36029 /test/ruby/test_module.rb
parent8f41c791b19a47e2dfa39b0a6d12ef964098536a (diff)
Already initialized modules cannot be replaced [Bug #17048]
Notes
Notes: Merged: https://github.com/ruby/ruby/pull/4858
Diffstat (limited to 'test/ruby/test_module.rb')
-rw-r--r--test/ruby/test_module.rb40
1 files changed, 26 insertions, 14 deletions
diff --git a/test/ruby/test_module.rb b/test/ruby/test_module.rb
index 98c9128406..bbe84cd9ff 100644
--- a/test/ruby/test_module.rb
+++ b/test/ruby/test_module.rb
@@ -404,19 +404,20 @@ class TestModule < Test::Unit::TestCase
assert_equal([:MIXIN, :USER], User.constants.sort)
end
- def test_self_initialize_copy
- bug9535 = '[ruby-dev:47989] [Bug #9535]'
- m = Module.new do
- def foo
- :ok
- end
- initialize_copy(self)
+ def test_initialize_copy
+ mod = Module.new { define_method(:foo) {:first} }
+ klass = Class.new { include mod }
+ instance = klass.new
+ assert_equal(:first, instance.foo)
+ new_mod = Module.new { define_method(:foo) { :second } }
+ assert_raise(TypeError) do
+ mod.send(:initialize_copy, new_mod)
end
- assert_equal(:ok, Object.new.extend(m).foo, bug9535)
+ 4.times { GC.start }
+ assert_equal(:first, instance.foo) # [BUG] unreachable
end
def test_initialize_copy_empty
- bug9813 = '[ruby-dev:48182] [Bug #9813]'
m = Module.new do
def x
end
@@ -426,12 +427,11 @@ class TestModule < Test::Unit::TestCase
assert_equal([:x], m.instance_methods)
assert_equal([:@x], m.instance_variables)
assert_equal([:X], m.constants)
- m.module_eval do
- initialize_copy(Module.new)
+ assert_raise(TypeError) do
+ m.module_eval do
+ initialize_copy(Module.new)
+ end
end
- assert_empty(m.instance_methods, bug9813)
- assert_empty(m.instance_variables, bug9813)
- assert_empty(m.constants, bug9813)
end
def test_dup
@@ -3094,6 +3094,18 @@ class TestModule < Test::Unit::TestCase
assert_match(/::Foo$/, mod.name, '[Bug #14895]')
end
+ def test_include_allocated
+ assert_raise(ArgumentError) do
+ Module.new {include Module.allocate}
+ end
+ assert_raise(ArgumentError) do
+ Module.new {prepend Module.allocate}
+ end
+ assert_raise(ArgumentError) do
+ Object.new.extend Module.allocate
+ end
+ end
+
private
def assert_top_method_is_private(method)