summaryrefslogtreecommitdiff
path: root/test/ruby/test_marshal.rb
diff options
context:
space:
mode:
Diffstat (limited to 'test/ruby/test_marshal.rb')
-rw-r--r--test/ruby/test_marshal.rb28
1 files changed, 26 insertions, 2 deletions
diff --git a/test/ruby/test_marshal.rb b/test/ruby/test_marshal.rb
index a642385a8e..d7afec3f66 100644
--- a/test/ruby/test_marshal.rb
+++ b/test/ruby/test_marshal.rb
@@ -538,16 +538,23 @@ class TestMarshal < Test::Unit::TestCase
assert_nil(loaded.foo, bug7627)
end
- class Bug8276
+ class LoadData
attr_reader :data
def initialize(data)
@data = data
- freeze
end
alias marshal_dump data
alias marshal_load initialize
end
+ class Bug8276 < LoadData
+ def initialize(*)
+ super
+ freeze
+ end
+ alias marshal_load initialize
+ end
+
def test_marshal_dump_excess_encoding
bug8276 = '[ruby-core:54334] [Bug #8276]'
t = Bug8276.new(bug8276)
@@ -564,6 +571,23 @@ class TestMarshal < Test::Unit::TestCase
assert_raise(RuntimeError) {Marshal.load(s)}
end
+ def test_marshal_load_ivar
+ s = "data with ivar"
+ s.instance_variable_set(:@t, 42)
+ t = LoadData.new(s)
+ s = Marshal.dump(t)
+ hook = ->(v) {
+ if LoadData === v
+ assert_send([v, :instance_variable_defined?, :@t])
+ assert_equal(42, v.instance_variable_get(:@t))
+ end
+ v
+ }
+ v = Marshal.load(s, hook)
+ assert_send([v, :instance_variable_defined?, :@t])
+ assert_equal(42, v.instance_variable_get(:@t))
+ end
+
def test_class_ivar
assert_raise(TypeError) {Marshal.load("\x04\x08Ic\x1bTestMarshal::TestClass\x06:\x0e@ivar_bug\"\x08bug")}
assert_raise(TypeError) {Marshal.load("\x04\x08IM\x1bTestMarshal::TestClass\x06:\x0e@ivar_bug\"\x08bug")}