зеркало из https://github.com/github/ruby.git
Support old versions of Ruby with FrozenError.
They should work separatedly from Ruby core repository. git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@64215 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
This commit is contained in:
Родитель
d59fc41fba
Коммит
1380aa04a6
|
@ -156,7 +156,8 @@ class OpenStruct
|
|||
begin
|
||||
@modifiable = true
|
||||
rescue
|
||||
raise FrozenError, "can't modify frozen #{self.class}", caller(3)
|
||||
exception_class = defined?(FrozenError) ? FrozenError : RuntimeError
|
||||
raise exception_class, "can't modify frozen #{self.class}", caller(3)
|
||||
end
|
||||
@table
|
||||
end
|
||||
|
|
|
@ -30,13 +30,15 @@ class TestDateMarshal < Test::Unit::TestCase
|
|||
a = d.marshal_dump
|
||||
d.freeze
|
||||
assert(d.frozen?)
|
||||
assert_raise(FrozenError){d.marshal_load(a)}
|
||||
expected_error = defined?(FrozenError) ? FrozenError : RuntimeError
|
||||
assert_raise(expected_error){d.marshal_load(a)}
|
||||
|
||||
d = DateTime.now
|
||||
a = d.marshal_dump
|
||||
d.freeze
|
||||
assert(d.frozen?)
|
||||
assert_raise(FrozenError){d.marshal_load(a)}
|
||||
expected_error = defined?(FrozenError) ? FrozenError : RuntimeError
|
||||
assert_raise(expected_error){d.marshal_load(a)}
|
||||
end
|
||||
|
||||
end
|
||||
|
|
|
@ -625,9 +625,10 @@ if defined? DBM
|
|||
end
|
||||
|
||||
def test_freeze
|
||||
expected_error = defined?(FrozenError) ? FrozenError : RuntimeError
|
||||
DBM.open("#{@tmproot}/a") {|d|
|
||||
d.freeze
|
||||
assert_raise(FrozenError) { d["k"] = "v" }
|
||||
assert_raise(expected_error) { d["k"] = "v" }
|
||||
}
|
||||
end
|
||||
end
|
||||
|
|
|
@ -726,7 +726,8 @@ if defined? GDBM
|
|||
def test_freeze
|
||||
GDBM.open("#{@tmproot}/a.dbm") {|d|
|
||||
d.freeze
|
||||
assert_raise(FrozenError) { d["k"] = "v" }
|
||||
expected_error = defined?(FrozenError) ? FrozenError : RuntimeError
|
||||
assert_raise(expected_error) { d["k"] = "v" }
|
||||
}
|
||||
end
|
||||
end
|
||||
|
|
|
@ -66,15 +66,16 @@ class TC_OpenStruct < Test::Unit::TestCase
|
|||
o = OpenStruct.new(foo: 42)
|
||||
o.a = 'a'
|
||||
o.freeze
|
||||
assert_raise(FrozenError) {o.b = 'b'}
|
||||
expected_error = defined?(FrozenError) ? FrozenError : RuntimeError
|
||||
assert_raise(expected_error) {o.b = 'b'}
|
||||
assert_not_respond_to(o, :b)
|
||||
assert_raise(FrozenError) {o.a = 'z'}
|
||||
assert_raise(expected_error) {o.a = 'z'}
|
||||
assert_equal('a', o.a)
|
||||
assert_equal(42, o.foo)
|
||||
o = OpenStruct.new :a => 42
|
||||
def o.frozen?; nil end
|
||||
o.freeze
|
||||
assert_raise(FrozenError, '[ruby-core:22559]') {o.a = 1764}
|
||||
assert_raise(expected_error, '[ruby-core:22559]') {o.a = 1764}
|
||||
end
|
||||
|
||||
def test_delete_field
|
||||
|
|
|
@ -722,9 +722,10 @@ class TestStringIO < Test::Unit::TestCase
|
|||
s = StringIO.new
|
||||
s.freeze
|
||||
bug = '[ruby-core:33648]'
|
||||
assert_raise(FrozenError, bug) {s.puts("foo")}
|
||||
assert_raise(FrozenError, bug) {s.string = "foo"}
|
||||
assert_raise(FrozenError, bug) {s.reopen("")}
|
||||
exception_class = defined?(FrozenError) ? FrozenError : RuntimeError
|
||||
assert_raise(exception_class, bug) {s.puts("foo")}
|
||||
assert_raise(exception_class, bug) {s.string = "foo"}
|
||||
assert_raise(exception_class, bug) {s.reopen("")}
|
||||
end
|
||||
|
||||
def test_frozen_string
|
||||
|
|
Загрузка…
Ссылка в новой задаче