[前][次][番号順一覧][スレッド一覧]

ruby-changes:52000

From: hsbt <ko1@a...>
Date: Tue, 7 Aug 2018 21:47:16 +0900 (JST)
Subject: [ruby-changes:52000] hsbt:r64215 (trunk): Support old versions of Ruby with FrozenError.

hsbt	2018-08-07 21:47:11 +0900 (Tue, 07 Aug 2018)

  New Revision: 64215

  https://svn.ruby-lang.org/cgi-bin/viewvc.cgi?view=revision&revision=64215

  Log:
    Support old versions of Ruby with FrozenError.
    
      They should work separatedly from Ruby core repository.

  Modified files:
    trunk/lib/ostruct.rb
    trunk/test/date/test_date_marshal.rb
    trunk/test/dbm/test_dbm.rb
    trunk/test/gdbm/test_gdbm.rb
    trunk/test/ostruct/test_ostruct.rb
    trunk/test/stringio/test_stringio.rb
Index: lib/ostruct.rb
===================================================================
--- lib/ostruct.rb	(revision 64214)
+++ lib/ostruct.rb	(revision 64215)
@@ -156,7 +156,8 @@ class OpenStruct https://github.com/ruby/ruby/blob/trunk/lib/ostruct.rb#L156
     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
Index: test/dbm/test_dbm.rb
===================================================================
--- test/dbm/test_dbm.rb	(revision 64214)
+++ test/dbm/test_dbm.rb	(revision 64215)
@@ -625,9 +625,10 @@ if defined? DBM https://github.com/ruby/ruby/blob/trunk/test/dbm/test_dbm.rb#L625
     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
Index: test/date/test_date_marshal.rb
===================================================================
--- test/date/test_date_marshal.rb	(revision 64214)
+++ test/date/test_date_marshal.rb	(revision 64215)
@@ -30,13 +30,15 @@ class TestDateMarshal < Test::Unit::Test https://github.com/ruby/ruby/blob/trunk/test/date/test_date_marshal.rb#L30
     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
Index: test/stringio/test_stringio.rb
===================================================================
--- test/stringio/test_stringio.rb	(revision 64214)
+++ test/stringio/test_stringio.rb	(revision 64215)
@@ -722,9 +722,10 @@ class TestStringIO < Test::Unit::TestCas https://github.com/ruby/ruby/blob/trunk/test/stringio/test_stringio.rb#L722
     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
Index: test/ostruct/test_ostruct.rb
===================================================================
--- test/ostruct/test_ostruct.rb	(revision 64214)
+++ test/ostruct/test_ostruct.rb	(revision 64215)
@@ -66,15 +66,16 @@ class TC_OpenStruct < Test::Unit::TestCa https://github.com/ruby/ruby/blob/trunk/test/ostruct/test_ostruct.rb#L66
     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
Index: test/gdbm/test_gdbm.rb
===================================================================
--- test/gdbm/test_gdbm.rb	(revision 64214)
+++ test/gdbm/test_gdbm.rb	(revision 64215)
@@ -726,7 +726,8 @@ if defined? GDBM https://github.com/ruby/ruby/blob/trunk/test/gdbm/test_gdbm.rb#L726
     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

--
ML: ruby-changes@q...
Info: http://www.atdot.net/~ko1/quickml/

[前][次][番号順一覧][スレッド一覧]