ruby-changes:59569
From: Nobuyoshi <ko1@a...>
Date: Tue, 31 Dec 2019 20:09:19 +0900 (JST)
Subject: [ruby-changes:59569] a580a3757b (master): Split test_name_error.rb
https://git.ruby-lang.org/ruby.git/commit/?id=a580a3757b From a580a3757b162b8d1b2b19d91f5c246c7fc5dca8 Mon Sep 17 00:00:00 2001 From: Nobuyoshi Nakada <nobu@r...> Date: Tue, 31 Dec 2019 14:33:03 +0900 Subject: Split test_name_error.rb diff --git a/test/ruby/test_exception.rb b/test/ruby/test_exception.rb index 8a60faf..44867d2 100644 --- a/test/ruby/test_exception.rb +++ b/test/ruby/test_exception.rb @@ -828,47 +828,6 @@ end.join https://github.com/ruby/ruby/blob/trunk/test/ruby/test_exception.rb#L828 assert_in_out_err([], "raise Class.new(RuntimeError), 'foo'", [], /foo\n/) end - PrettyObject = - Class.new(BasicObject) do - alias object_id __id__ - def pretty_inspect; "`obj'"; end - alias inspect pretty_inspect - end - - def test_name_error_new_default - error = NameError.new - assert_equal("NameError", error.message) - end - - def test_name_error_new_message - error = NameError.new("Message") - assert_equal("Message", error.message) - end - - def test_name_error_new_name - error = NameError.new("Message") - assert_nil(error.name) - - error = NameError.new("Message", :foo) - assert_equal(:foo, error.name) - end - - def test_name_error_new_receiver - receiver = Object.new - - error = NameError.new - assert_raise(ArgumentError) {error.receiver} - assert_equal("NameError", error.message) - - error = NameError.new(receiver: receiver) - assert_equal(["NameError", receiver], - [error.message, error.receiver]) - - error = NameError.new("Message", :foo, receiver: receiver) - assert_equal(["Message", receiver, :foo], - [error.message, error.receiver, error.name]) - end - def test_nomethod_error_new_default error = NoMethodError.new assert_equal("NoMethodError", error.message) @@ -945,92 +904,6 @@ end.join https://github.com/ruby/ruby/blob/trunk/test/ruby/test_exception.rb#L904 [error.name, error.args, error.private_call?, error.receiver]) end - def test_name_error_info_const - obj = PrettyObject.new - - e = assert_raise(NameError) { - obj.instance_eval("Object") - } - assert_equal(:Object, e.name) - - e = assert_raise(NameError) { - BasicObject::X - } - assert_same(BasicObject, e.receiver) - assert_equal(:X, e.name) - end - - def test_name_error_info_method - obj = PrettyObject.new - - e = assert_raise(NameError) { - obj.instance_eval {foo} - } - assert_equal(:foo, e.name) - assert_same(obj, e.receiver) - - e = assert_raise(NoMethodError) { - obj.foo(1, 2) - } - assert_equal(:foo, e.name) - assert_equal([1, 2], e.args) - assert_same(obj, e.receiver) - assert_not_predicate(e, :private_call?) - - e = assert_raise(NoMethodError) { - obj.instance_eval {foo(1, 2)} - } - assert_equal(:foo, e.name) - assert_equal([1, 2], e.args) - assert_same(obj, e.receiver) - assert_predicate(e, :private_call?) - end - - def test_name_error_info_local_variables - obj = PrettyObject.new - def obj.test(a, b=nil, *c, &d) - e = a - 1.times {|f| g = foo; g} - e - end - - e = assert_raise(NameError) { - obj.test(3) - } - assert_equal(:foo, e.name) - assert_same(obj, e.receiver) - assert_equal(%i[a b c d e f g], e.local_variables.sort) - end - - def test_name_error_info_method_missing - obj = PrettyObject.new - def obj.method_missing(*) - super - end - - e = assert_raise(NoMethodError) { - obj.foo(1, 2) - } - assert_equal(:foo, e.name) - assert_equal([1, 2], e.args) - assert_same(obj, e.receiver) - assert_not_predicate(e, :private_call?) - - e = assert_raise(NoMethodError) { - obj.instance_eval {foo(1, 2)} - } - assert_equal(:foo, e.name) - assert_equal([1, 2], e.args) - assert_same(obj, e.receiver) - assert_predicate(e, :private_call?) - end - - def test_name_error_info_parent_iseq_mark - assert_separately(['-', File.join(__dir__, 'bug-11928.rb')], <<-'end;') - -> {require ARGV[0]}.call - end; - end - def test_output_string_encoding # "\x82\xa0" in cp932 is "\u3042" (Japanese hiragana 'a') # change $stderr to force calling rb_io_write() instead of fwrite() diff --git a/test/ruby/test_name_error.rb b/test/ruby/test_name_error.rb new file mode 100644 index 0000000..102a4a6 --- /dev/null +++ b/test/ruby/test_name_error.rb @@ -0,0 +1,130 @@ https://github.com/ruby/ruby/blob/trunk/test/ruby/test_name_error.rb#L1 +require 'test/unit' + +class TestNameError < Test::Unit::TestCase + def test_new_default + error = NameError.new + assert_equal("NameError", error.message) + end + + def test_new_message + error = NameError.new("Message") + assert_equal("Message", error.message) + end + + def test_new_name + error = NameError.new("Message") + assert_nil(error.name) + + error = NameError.new("Message", :foo) + assert_equal(:foo, error.name) + end + + def test_new_receiver + receiver = Object.new + + error = NameError.new + assert_raise(ArgumentError) {error.receiver} + assert_equal("NameError", error.message) + + error = NameError.new(receiver: receiver) + assert_equal(["NameError", receiver], + [error.message, error.receiver]) + + error = NameError.new("Message", :foo, receiver: receiver) + assert_equal(["Message", receiver, :foo], + [error.message, error.receiver, error.name]) + end + + PrettyObject = + Class.new(BasicObject) do + alias object_id __id__ + def pretty_inspect; "`obj'"; end + alias inspect pretty_inspect + end + + def test_info_const + obj = PrettyObject.new + + e = assert_raise(NameError) { + obj.instance_eval("Object") + } + assert_equal(:Object, e.name) + + e = assert_raise(NameError) { + BasicObject::X + } + assert_same(BasicObject, e.receiver) + assert_equal(:X, e.name) + end + + def test_info_method + obj = PrettyObject.new + + e = assert_raise(NameError) { + obj.instance_eval {foo} + } + assert_equal(:foo, e.name) + assert_same(obj, e.receiver) + + e = assert_raise(NoMethodError) { + obj.foo(1, 2) + } + assert_equal(:foo, e.name) + assert_equal([1, 2], e.args) + assert_same(obj, e.receiver) + assert_not_predicate(e, :private_call?) + + e = assert_raise(NoMethodError) { + obj.instance_eval {foo(1, 2)} + } + assert_equal(:foo, e.name) + assert_equal([1, 2], e.args) + assert_same(obj, e.receiver) + assert_predicate(e, :private_call?) + end + + def test_info_local_variables + obj = PrettyObject.new + def obj.test(a, b=nil, *c, &d) + e = a + 1.times {|f| g = foo; g} + e + end + + e = assert_raise(NameError) { + obj.test(3) + } + assert_equal(:foo, e.name) + assert_same(obj, e.receiver) + assert_equal(%i[a b c d e f g], e.local_variables.sort) + end + + def test_info_method_missing + obj = PrettyObject.new + def obj.method_missing(*) + super + end + + e = assert_raise(NoMethodError) { + obj.foo(1, 2) + } + assert_equal(:foo, e.name) + assert_equal([1, 2], e.args) + assert_same(obj, e.receiver) + assert_not_predicate(e, :private_call?) + + e = assert_raise(NoMethodError) { + obj.instance_eval {foo(1, 2)} + } + assert_equal(:foo, e.name) + assert_equal([1, 2], e.args) + assert_same(obj, e.receiver) + assert_predicate(e, :private_call?) + end + + def test_info_parent_iseq_mark + assert_separately(['-', File.join(__dir__, 'bug-11928.rb')], <<-'end;') + -> {require ARGV[0]}.call + end; + end +end -- cgit v0.10.2 -- ML: ruby-changes@q... Info: http://www.atdot.net/~ko1/quickml/