summaryrefslogtreecommitdiff
path: root/test
diff options
context:
space:
mode:
authorYusuke Endoh <mame@ruby-lang.org>2023-02-18 20:16:13 +0900
committergit <svn-admin@ruby-lang.org>2023-02-19 10:29:56 +0000
commit29f88b9feadee1417010dc6cd4f8e49c8c19720a (patch)
tree50a946927adc62adc6f2f15b85e3e104723c8212 /test
parentba1b9d31044cdf31b975b6583dd39552ac576113 (diff)
[ruby/error_highlight] Support the new message format of NameError in Ruby 3.3
https://bugs.ruby-lang.org/issues/18285 https://github.com/ruby/ruby/pull/6950 https://github.com/ruby/error_highlight/commit/a7c2da052e
Diffstat (limited to 'test')
-rw-r--r--test/error_highlight/test_error_highlight.rb132
1 files changed, 73 insertions, 59 deletions
diff --git a/test/error_highlight/test_error_highlight.rb b/test/error_highlight/test_error_highlight.rb
index 47c7a3dd00..006ecb05bf 100644
--- a/test/error_highlight/test_error_highlight.rb
+++ b/test/error_highlight/test_error_highlight.rb
@@ -37,9 +37,20 @@ class ErrorHighlightTest < Test::Unit::TestCase
end
end
+ if begin; 1.time; rescue; $!.message.end_with?("an instance of Integer"); end
+ # new message format
+ NEW_MESSAGE_FORMAT = true
+ NIL_RECV_MESSAGE = "nil"
+ ONE_RECV_MESSAGE = "an instance of Integer"
+ else
+ NEW_MESSAGE_FORMAT = false
+ NIL_RECV_MESSAGE = "nil:NilClass"
+ ONE_RECV_MESSAGE = "1:Integer"
+ end
+
def test_CALL_noarg_1
assert_error_message(NoMethodError, <<~END) do
-undefined method `foo' for nil:NilClass
+undefined method `foo' for #{ NIL_RECV_MESSAGE }
nil.foo + 1
^^^^
@@ -51,7 +62,7 @@ undefined method `foo' for nil:NilClass
def test_CALL_noarg_2
assert_error_message(NoMethodError, <<~END) do
-undefined method `foo' for nil:NilClass
+undefined method `foo' for #{ NIL_RECV_MESSAGE }
.foo + 1
^^^^
@@ -64,7 +75,7 @@ undefined method `foo' for nil:NilClass
def test_CALL_noarg_3
assert_error_message(NoMethodError, <<~END) do
-undefined method `foo' for nil:NilClass
+undefined method `foo' for #{ NIL_RECV_MESSAGE }
foo + 1
^^^
@@ -77,7 +88,7 @@ undefined method `foo' for nil:NilClass
def test_CALL_noarg_4
assert_error_message(NoMethodError, <<~END) do
-undefined method `foo' for nil:NilClass
+undefined method `foo' for #{ NIL_RECV_MESSAGE }
(nil).foo + 1
^^^^
@@ -89,7 +100,7 @@ undefined method `foo' for nil:NilClass
def test_CALL_arg_1
assert_error_message(NoMethodError, <<~END) do
-undefined method `foo' for nil:NilClass
+undefined method `foo' for #{ NIL_RECV_MESSAGE }
nil.foo (42)
^^^^
@@ -101,7 +112,7 @@ undefined method `foo' for nil:NilClass
def test_CALL_arg_2
assert_error_message(NoMethodError, <<~END) do
-undefined method `foo' for nil:NilClass
+undefined method `foo' for #{ NIL_RECV_MESSAGE }
.foo (
^^^^
@@ -116,7 +127,7 @@ undefined method `foo' for nil:NilClass
def test_CALL_arg_3
assert_error_message(NoMethodError, <<~END) do
-undefined method `foo' for nil:NilClass
+undefined method `foo' for #{ NIL_RECV_MESSAGE }
foo (
^^^
@@ -131,7 +142,7 @@ undefined method `foo' for nil:NilClass
def test_CALL_arg_4
assert_error_message(NoMethodError, <<~END) do
-undefined method `foo' for nil:NilClass
+undefined method `foo' for #{ NIL_RECV_MESSAGE }
nil.foo(42)
^^^^
@@ -143,7 +154,7 @@ undefined method `foo' for nil:NilClass
def test_CALL_arg_5
assert_error_message(NoMethodError, <<~END) do
-undefined method `foo' for nil:NilClass
+undefined method `foo' for #{ NIL_RECV_MESSAGE }
.foo(
^^^^
@@ -158,7 +169,7 @@ undefined method `foo' for nil:NilClass
def test_CALL_arg_6
assert_error_message(NoMethodError, <<~END) do
-undefined method `foo' for nil:NilClass
+undefined method `foo' for #{ NIL_RECV_MESSAGE }
foo(
^^^
@@ -173,7 +184,7 @@ undefined method `foo' for nil:NilClass
def test_QCALL_1
assert_error_message(NoMethodError, <<~END) do
-undefined method `foo' for 1:Integer
+undefined method `foo' for #{ ONE_RECV_MESSAGE }
1&.foo
^^^^^
@@ -185,7 +196,7 @@ undefined method `foo' for 1:Integer
def test_QCALL_2
assert_error_message(NoMethodError, <<~END) do
-undefined method `foo' for 1:Integer
+undefined method `foo' for #{ ONE_RECV_MESSAGE }
1&.foo(42)
^^^^^
@@ -197,7 +208,7 @@ undefined method `foo' for 1:Integer
def test_CALL_aref_1
assert_error_message(NoMethodError, <<~END) do
-undefined method `[]' for nil:NilClass
+undefined method `[]' for #{ NIL_RECV_MESSAGE }
nil [ ]
^^^
@@ -209,7 +220,7 @@ undefined method `[]' for nil:NilClass
def test_CALL_aref_2
assert_error_message(NoMethodError, <<~END) do
-undefined method `[]' for nil:NilClass
+undefined method `[]' for #{ NIL_RECV_MESSAGE }
nil [0]
^^^
@@ -221,7 +232,7 @@ undefined method `[]' for nil:NilClass
def test_CALL_aref_3
assert_error_message(NoMethodError, <<~END) do
-undefined method `[]' for nil:NilClass
+undefined method `[]' for #{ NIL_RECV_MESSAGE }
END
nil [
@@ -232,8 +243,9 @@ undefined method `[]' for nil:NilClass
def test_CALL_aref_4
v = Object.new
+ recv = NEW_MESSAGE_FORMAT ? "an instance of Object" : v.inspect
assert_error_message(NoMethodError, <<~END) do
-undefined method `[]' for #{ v.inspect }
+undefined method `[]' for #{ recv }
v &.[](0)
^^^^
@@ -245,7 +257,7 @@ undefined method `[]' for #{ v.inspect }
def test_CALL_aref_5
assert_error_message(NoMethodError, <<~END) do
-undefined method `[]' for nil:NilClass
+undefined method `[]' for #{ NIL_RECV_MESSAGE }
(nil)[ ]
^^^
@@ -257,7 +269,7 @@ undefined method `[]' for nil:NilClass
def test_CALL_aset
assert_error_message(NoMethodError, <<~END) do
-undefined method `[]=' for nil:NilClass
+undefined method `[]=' for #{ NIL_RECV_MESSAGE }
nil.[]=
^^^^
@@ -270,7 +282,7 @@ undefined method `[]=' for nil:NilClass
def test_CALL_op_asgn
v = nil
assert_error_message(NoMethodError, <<~END) do
-undefined method `+' for nil:NilClass
+undefined method `+' for #{ NIL_RECV_MESSAGE }
v += 42
^
@@ -282,7 +294,7 @@ undefined method `+' for nil:NilClass
def test_CALL_special_call_1
assert_error_message(NoMethodError, <<~END) do
-undefined method `call' for nil:NilClass
+undefined method `call' for #{ NIL_RECV_MESSAGE }
END
nil.()
@@ -291,7 +303,7 @@ undefined method `call' for nil:NilClass
def test_CALL_special_call_2
assert_error_message(NoMethodError, <<~END) do
-undefined method `call' for nil:NilClass
+undefined method `call' for #{ NIL_RECV_MESSAGE }
END
nil.(42)
@@ -300,7 +312,7 @@ undefined method `call' for nil:NilClass
def test_CALL_send
assert_error_message(NoMethodError, <<~END) do
-undefined method `foo' for nil:NilClass
+undefined method `foo' for #{ NIL_RECV_MESSAGE }
nil.send(:foo, 42)
^^^^^
@@ -312,7 +324,7 @@ undefined method `foo' for nil:NilClass
def test_ATTRASGN_1
assert_error_message(NoMethodError, <<~END) do
-undefined method `[]=' for nil:NilClass
+undefined method `[]=' for #{ NIL_RECV_MESSAGE }
nil [ ] = 42
^^^^^
@@ -324,7 +336,7 @@ undefined method `[]=' for nil:NilClass
def test_ATTRASGN_2
assert_error_message(NoMethodError, <<~END) do
-undefined method `[]=' for nil:NilClass
+undefined method `[]=' for #{ NIL_RECV_MESSAGE }
nil [0] = 42
^^^^^
@@ -336,7 +348,7 @@ undefined method `[]=' for nil:NilClass
def test_ATTRASGN_3
assert_error_message(NoMethodError, <<~END) do
-undefined method `foo=' for nil:NilClass
+undefined method `foo=' for #{ NIL_RECV_MESSAGE }
nil.foo = 42
^^^^^^
@@ -348,7 +360,7 @@ undefined method `foo=' for nil:NilClass
def test_ATTRASGN_4
assert_error_message(NoMethodError, <<~END) do
-undefined method `[]=' for nil:NilClass
+undefined method `[]=' for #{ NIL_RECV_MESSAGE }
(nil)[0] = 42
^^^^^
@@ -360,7 +372,7 @@ undefined method `[]=' for nil:NilClass
def test_ATTRASGN_5
assert_error_message(NoMethodError, <<~END) do
-undefined method `foo=' for nil:NilClass
+undefined method `foo=' for #{ NIL_RECV_MESSAGE }
(nil).foo = 42
^^^^^^
@@ -372,7 +384,7 @@ undefined method `foo=' for nil:NilClass
def test_OPCALL_binary_1
assert_error_message(NoMethodError, <<~END) do
-undefined method `+' for nil:NilClass
+undefined method `+' for #{ NIL_RECV_MESSAGE }
nil + 42
^
@@ -384,7 +396,7 @@ undefined method `+' for nil:NilClass
def test_OPCALL_binary_2
assert_error_message(NoMethodError, <<~END) do
-undefined method `+' for nil:NilClass
+undefined method `+' for #{ NIL_RECV_MESSAGE }
nil + # comment
^
@@ -397,7 +409,7 @@ undefined method `+' for nil:NilClass
def test_OPCALL_binary_3
assert_error_message(NoMethodError, <<~END) do
-undefined method `+' for nil:NilClass
+undefined method `+' for #{ NIL_RECV_MESSAGE }
(nil) + 42
^
@@ -409,7 +421,7 @@ undefined method `+' for nil:NilClass
def test_OPCALL_unary_1
assert_error_message(NoMethodError, <<~END) do
-undefined method `+@' for nil:NilClass
+undefined method `+@' for #{ NIL_RECV_MESSAGE }
+ nil
^
@@ -421,7 +433,7 @@ undefined method `+@' for nil:NilClass
def test_OPCALL_unary_2
assert_error_message(NoMethodError, <<~END) do
-undefined method `+@' for nil:NilClass
+undefined method `+@' for #{ NIL_RECV_MESSAGE }
+(nil)
^
@@ -433,7 +445,7 @@ undefined method `+@' for nil:NilClass
def test_FCALL_1
assert_error_message(NoMethodError, <<~END) do
-undefined method `foo' for nil:NilClass
+undefined method `foo' for #{ NIL_RECV_MESSAGE }
nil.instance_eval { foo() }
^^^
@@ -445,7 +457,7 @@ undefined method `foo' for nil:NilClass
def test_FCALL_2
assert_error_message(NoMethodError, <<~END) do
-undefined method `foo' for nil:NilClass
+undefined method `foo' for #{ NIL_RECV_MESSAGE }
nil.instance_eval { foo(42) }
^^^
@@ -457,7 +469,7 @@ undefined method `foo' for nil:NilClass
def test_VCALL_2
assert_error_message(NameError, <<~END) do
-undefined local variable or method `foo' for nil:NilClass
+undefined local variable or method `foo' for #{ NIL_RECV_MESSAGE }
nil.instance_eval { foo }
^^^
@@ -471,7 +483,7 @@ undefined local variable or method `foo' for nil:NilClass
v = nil
assert_error_message(NoMethodError, <<~END) do
-undefined method `[]' for nil:NilClass
+undefined method `[]' for #{ NIL_RECV_MESSAGE }
v [0] += 42
^^^
@@ -485,7 +497,7 @@ undefined method `[]' for nil:NilClass
v = nil
assert_error_message(NoMethodError, <<~END) do
-undefined method `[]' for nil:NilClass
+undefined method `[]' for #{ NIL_RECV_MESSAGE }
v [0] += # comment
^^^
@@ -500,7 +512,7 @@ undefined method `[]' for nil:NilClass
v = nil
assert_error_message(NoMethodError, <<~END) do
-undefined method `[]' for nil:NilClass
+undefined method `[]' for #{ NIL_RECV_MESSAGE }
END
v [
@@ -514,7 +526,7 @@ undefined method `[]' for nil:NilClass
v = nil
assert_error_message(NoMethodError, <<~END) do
-undefined method `[]' for nil:NilClass
+undefined method `[]' for #{ NIL_RECV_MESSAGE }
(v)[0] += 42
^^^
@@ -529,7 +541,7 @@ undefined method `[]' for nil:NilClass
def v.[](x); nil; end
assert_error_message(NoMethodError, <<~END) do
-undefined method `+' for nil:NilClass
+undefined method `+' for #{ NIL_RECV_MESSAGE }
v [0] += 42
^
@@ -544,7 +556,7 @@ undefined method `+' for nil:NilClass
def v.[](x); nil; end
assert_error_message(NoMethodError, <<~END) do
-undefined method `+' for nil:NilClass
+undefined method `+' for #{ NIL_RECV_MESSAGE }
v [0 ] += # comment
^
@@ -560,7 +572,7 @@ undefined method `+' for nil:NilClass
def v.[](x); nil; end
assert_error_message(NoMethodError, <<~END) do
-undefined method `+' for nil:NilClass
+undefined method `+' for #{ NIL_RECV_MESSAGE }
END
v [
@@ -575,7 +587,7 @@ undefined method `+' for nil:NilClass
def v.[](x); nil; end
assert_error_message(NoMethodError, <<~END) do
-undefined method `+' for nil:NilClass
+undefined method `+' for #{ NIL_RECV_MESSAGE }
(v)[0] += 42
^
@@ -650,7 +662,7 @@ undefined method `[]=' for #{ v.inspect }
v = nil
assert_error_message(NoMethodError, <<~END) do
-undefined method `foo' for nil:NilClass
+undefined method `foo' for #{ NIL_RECV_MESSAGE }
v.foo += 42
^^^^
@@ -664,7 +676,7 @@ undefined method `foo' for nil:NilClass
v = nil
assert_error_message(NoMethodError, <<~END) do
-undefined method `foo' for nil:NilClass
+undefined method `foo' for #{ NIL_RECV_MESSAGE }
v.foo += # comment
^^^^
@@ -679,7 +691,7 @@ undefined method `foo' for nil:NilClass
v = nil
assert_error_message(NoMethodError, <<~END) do
-undefined method `foo' for nil:NilClass
+undefined method `foo' for #{ NIL_RECV_MESSAGE }
(v).foo += 42
^^^^
@@ -694,7 +706,7 @@ undefined method `foo' for nil:NilClass
def v.foo; nil; end
assert_error_message(NoMethodError, <<~END) do
-undefined method `+' for nil:NilClass
+undefined method `+' for #{ NIL_RECV_MESSAGE }
v.foo += 42
^
@@ -709,7 +721,7 @@ undefined method `+' for nil:NilClass
def v.foo; nil; end
assert_error_message(NoMethodError, <<~END) do
-undefined method `+' for nil:NilClass
+undefined method `+' for #{ NIL_RECV_MESSAGE }
v.foo += # comment
^
@@ -725,7 +737,7 @@ undefined method `+' for nil:NilClass
def v.foo; nil; end
assert_error_message(NoMethodError, <<~END) do
-undefined method `+' for nil:NilClass
+undefined method `+' for #{ NIL_RECV_MESSAGE }
(v).foo += 42
^
@@ -919,7 +931,7 @@ uninitialized constant ErrorHighlightTest::OP_CDECL_TEST::NotDefined
def test_OP_CDECL_op_1
assert_error_message(NoMethodError, <<~END) do
-undefined method `+' for nil:NilClass
+undefined method `+' for #{ NIL_RECV_MESSAGE }
OP_CDECL_TEST::Nil += 1
^
@@ -931,7 +943,7 @@ undefined method `+' for nil:NilClass
def test_OP_CDECL_op_2
assert_error_message(NoMethodError, <<~END) do
-undefined method `+' for nil:NilClass
+undefined method `+' for #{ NIL_RECV_MESSAGE }
OP_CDECL_TEST::Nil += # comment
^
@@ -944,7 +956,7 @@ undefined method `+' for nil:NilClass
def test_OP_CDECL_op_3
assert_error_message(NoMethodError, <<~END) do
-undefined method `+' for nil:NilClass
+undefined method `+' for #{ NIL_RECV_MESSAGE }
Nil += 1
^
@@ -968,8 +980,9 @@ uninitialized constant NotDefined
end
def test_OP_CDECL_toplevel_2
+ recv = NEW_MESSAGE_FORMAT ? "class ErrorHighlightTest" : "ErrorHighlightTest:Class"
assert_error_message(NoMethodError, <<~END) do
-undefined method `+' for ErrorHighlightTest:Class
+undefined method `+' for #{ recv }
::ErrorHighlightTest += 1
^
@@ -1030,7 +1043,7 @@ local variable `foo' is not defined for #{ b.inspect }
def test_multibyte
assert_error_message(NoMethodError, <<~END) do
-undefined method `あいうえお' for nil:NilClass
+undefined method `あいうえお' for #{ NIL_RECV_MESSAGE }
END
nil.あいうえお
@@ -1202,7 +1215,7 @@ nil can't be coerced into Integer (TypeError)
original_formatter, ErrorHighlight.formatter = ErrorHighlight.formatter, custom_formatter
assert_error_message(NoMethodError, <<~END) do
-undefined method `time' for 1:Integer
+undefined method `time' for #{ ONE_RECV_MESSAGE }
{:first_lineno=>#{ __LINE__ + 3 }, :first_column=>7, :last_lineno=>#{ __LINE__ + 3 }, :last_column=>12, :snippet=>" 1.time {}\\n"}
END
@@ -1220,7 +1233,7 @@ undefined method `time' for 1:Integer
tmp.close
assert_error_message(NoMethodError, <<~END.gsub("_", "\t")) do
-undefined method `time' for 1:Integer
+undefined method `time' for #{ ONE_RECV_MESSAGE }
_ _1.time {}
_ _ ^^^^^
@@ -1237,7 +1250,7 @@ _ _ ^^^^^
tmp.close
assert_error_message(NoMethodError, <<~END) do
-undefined method `time' for 1:Integer
+undefined method `time' for #{ ONE_RECV_MESSAGE }
1.time {}
^^^^^
@@ -1250,7 +1263,7 @@ undefined method `time' for 1:Integer
def test_simulate_funcallv_from_embedded_ruby
assert_error_message(NoMethodError, <<~END) do
-undefined method `foo' for nil:NilClass
+undefined method `foo' for #{ NIL_RECV_MESSAGE }
END
nil.foo + 1
@@ -1265,8 +1278,9 @@ undefined method `foo' for nil:NilClass
tmp << "module Dummy\nend\n"
tmp.close
+ recv = NEW_MESSAGE_FORMAT ? "an instance of String" : '"dummy":String'
assert_error_message(NameError, <<~END) do
- undefined local variable or method `foo' for "dummy":String
+ undefined local variable or method `foo' for #{ recv }
END
"dummy".instance_eval do