ruby-changes:59568
From: Nobuyoshi <ko1@a...>
Date: Tue, 31 Dec 2019 19:44:03 +0900 (JST)
Subject: [ruby-changes:59568] ee4ead8098 (master): Split test_frozen_error.rb
https://git.ruby-lang.org/ruby.git/commit/?id=ee4ead8098 From ee4ead8098703959353cb81647e4d23bc62fa51b Mon Sep 17 00:00:00 2001 From: Nobuyoshi Nakada <nobu@r...> Date: Tue, 31 Dec 2019 14:28:57 +0900 Subject: Split test_frozen_error.rb diff --git a/test/ruby/test_exception.rb b/test/ruby/test_exception.rb index 8445f85..8a60faf 100644 --- a/test/ruby/test_exception.rb +++ b/test/ruby/test_exception.rb @@ -835,56 +835,6 @@ end.join https://github.com/ruby/ruby/blob/trunk/test/ruby/test_exception.rb#L835 alias inspect pretty_inspect end - def test_frozen_error_receiver - obj = Object.new.freeze - e = assert_raise(FrozenError) {def obj.foo; end} - assert_same(obj, e.receiver) - e = assert_raise(FrozenError) {obj.singleton_class.const_set(:A, 2)} - assert_same(obj.singleton_class, e.receiver) - end - - def test_frozen_error_initialize - obj = Object.new - exc = FrozenError.new("bar", receiver: obj) - assert_equal("bar", exc.message) - assert_same(obj, exc.receiver) - - exc = FrozenError.new("bar") - assert_equal("bar", exc.message) - assert_raise_with_message(ArgumentError, "no receiver is available") { - exc.receiver - } - - exc = FrozenError.new - assert_equal("FrozenError", exc.message) - assert_raise_with_message(ArgumentError, "no receiver is available") { - exc.receiver - } - end - - def test_frozen_error_message - obj = Object.new.freeze - e = assert_raise_with_message(FrozenError, /can't modify frozen #{obj.class}/) { - obj.instance_variable_set(:@test, true) - } - assert_include(e.message, obj.inspect) - - klass = Class.new do - def init - @x = true - end - def inspect - init - super - end - end - obj = klass.new.freeze - e = assert_raise_with_message(FrozenError, /can't modify frozen #{obj.class}/) { - obj.init - } - assert_include(e.message, klass.inspect) - end - def test_name_error_new_default error = NameError.new assert_equal("NameError", error.message) diff --git a/test/ruby/test_frozen_error.rb b/test/ruby/test_frozen_error.rb new file mode 100644 index 0000000..ace1e4c --- /dev/null +++ b/test/ruby/test_frozen_error.rb @@ -0,0 +1,57 @@ https://github.com/ruby/ruby/blob/trunk/test/ruby/test_frozen_error.rb#L1 +require 'test/unit' + +class TestFrozenError < Test::Unit::TestCase + def test_new_default + exc = FrozenError.new + assert_equal("FrozenError", exc.message) + assert_raise_with_message(ArgumentError, "no receiver is available") { + exc.receiver + } + end + + def test_new_message + exc = FrozenError.new("bar") + assert_equal("bar", exc.message) + assert_raise_with_message(ArgumentError, "no receiver is available") { + exc.receiver + } + end + + def test_new_receiver + obj = Object.new + exc = FrozenError.new("bar", receiver: obj) + assert_equal("bar", exc.message) + assert_same(obj, exc.receiver) + end + + def test_message + obj = Object.new.freeze + e = assert_raise_with_message(FrozenError, /can't modify frozen #{obj.class}/) { + obj.instance_variable_set(:@test, true) + } + assert_include(e.message, obj.inspect) + + klass = Class.new do + def init + @x = true + end + def inspect + init + super + end + end + obj = klass.new.freeze + e = assert_raise_with_message(FrozenError, /can't modify frozen #{obj.class}/) { + obj.init + } + assert_include(e.message, klass.inspect) + end + + def test_receiver + obj = Object.new.freeze + e = assert_raise(FrozenError) {def obj.foo; end} + assert_same(obj, e.receiver) + e = assert_raise(FrozenError) {obj.singleton_class.const_set(:A, 2)} + assert_same(obj.singleton_class, e.receiver) + end +end -- cgit v0.10.2 -- ML: ruby-changes@q... Info: http://www.atdot.net/~ko1/quickml/