Skip to content

Commit

Permalink
@wip Review patches in MRI tests
Browse files Browse the repository at this point in the history
  • Loading branch information
andrykonchin committed Oct 17, 2024
1 parent 6552878 commit 9db9994
Show file tree
Hide file tree
Showing 5 changed files with 40 additions and 45 deletions.
40 changes: 20 additions & 20 deletions test/mri/tests/ruby/test_parse.rb
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ def test_else_without_rescue
end

def test_alias_backref
assert_syntax_error("#{<<~"begin;"}\n#{<<~'end;'}", /can't make alias|invalid argument being passed to `alias`/) do
assert_syntax_error("#{<<~"begin;"}\n#{<<~'end;'}", /can't make alias/) do
begin;
alias $foo $1
end;
Expand Down Expand Up @@ -85,7 +85,7 @@ class << o
assert_equal([42, 42], [o.Foo, o.Bar])
assert_equal([42, 42], [o::baz, o::qux])

assert_syntax_error("#{<<~"begin;"}\n#{<<~'end;'}", /Can't set variable|immutable variable as a write target/) do
assert_syntax_error("#{<<~"begin;"}\n#{<<~'end;'}", /Can't set variable/) do
begin;
$1 ||= t.foo 42
end;
Expand Down Expand Up @@ -193,13 +193,13 @@ def foo
end

def test_class_module
assert_syntax_error("#{<<~"begin;"}\n#{<<~'end;'}", /must be CONSTANT|expected a constant name/) do
assert_syntax_error("#{<<~"begin;"}\n#{<<~'end;'}", /must be CONSTANT/) do
begin;
class foo; end
end;
end

assert_syntax_error("#{<<~"begin;"}\n#{<<~'end;'}", /in method body|unexpected class definition in a method definition/) do
assert_syntax_error("#{<<~"begin;"}\n#{<<~'end;'}", /in method body/) do
begin;
def foo
class Foo; end
Expand Down Expand Up @@ -295,7 +295,7 @@ def foo(@@foo); end
end;
end

assert_syntax_error("#{<<~"begin;"}\n#{<<~'end;'}", /cannot be an instance variable|expected a local variable name in the block parameters/) do
assert_syntax_error("#{<<~"begin;"}\n#{<<~'end;'}", /cannot be an instance variable/) do
begin;
o.foo {|; @a| @a = 42 }
end;
Expand Down Expand Up @@ -439,13 +439,13 @@ def test_duplicate_argument
end;
end

assert_syntax_error("#{<<~"begin;"}\n#{<<~'end;'}", /duplicated argument|repeated parameter name/) do
assert_syntax_error("#{<<~"begin;"}\n#{<<~'end;'}", /duplicated argument/) do
begin;
1.times {|a, a|}
end;
end

assert_syntax_error("#{<<~"begin;"}\n#{<<~'end;'}", /duplicated argument|repeated parameter name/) do
assert_syntax_error("#{<<~"begin;"}\n#{<<~'end;'}", /duplicated argument/) do
begin;
def foo(a, a); end
end;
Expand Down Expand Up @@ -652,12 +652,12 @@ def test_question

def test_percent
assert_equal(:foo, eval('%s(foo)'))
assert_syntax_error('%s', /unterminated quoted string|expected a closing delimiter for the dynamic symbol/)
assert_syntax_error('%ss', /unknown type|invalid `%` token/)
assert_syntax_error('%z()', /unknown type|invalid `%` token/)
assert_syntax_error("%\u3042", /unknown type|invalid `%` token/)
assert_syntax_error("%q\u3042", /unknown type|invalid `%` token/)
assert_syntax_error("%", /unterminated quoted string|invalid `%` token/)
assert_syntax_error('%s', /unterminated quoted string/)
assert_syntax_error('%ss', /unknown type/)
assert_syntax_error('%z()', /unknown type/)
assert_syntax_error("%\u3042", /unknown type/)
assert_syntax_error("%q\u3042", /unknown type/)
assert_syntax_error("%", /unterminated quoted string/)
end

def test_symbol
Expand Down Expand Up @@ -685,7 +685,7 @@ def test_symbol
end

def test_parse_string
assert_syntax_error("/\n", /unterminated|expected a closing delimiter for the regular expression/)
assert_syntax_error("/\n", /unterminated/)
end

def test_here_document
Expand Down Expand Up @@ -869,7 +869,7 @@ def test_block_dup
end

def test_set_backref
assert_syntax_error("$& = 1", /Can't set variable|immutable variable as a write target/)
assert_syntax_error("$& = 1", /Can't set variable/)
end

def test_arg_concat
Expand Down Expand Up @@ -1278,7 +1278,7 @@ def test_heredoc_unterminated_interpolation
end

def test_unexpected_token_error
assert_syntax_error('"x"xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx', /unexpected|expected a newline or semicolon after the statement/)
assert_syntax_error('"x"xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx', /unexpected/)
end

def test_unexpected_token_after_numeric
Expand All @@ -1298,7 +1298,7 @@ def test_truncated_source_line
end

def test_unterminated_regexp_error
e = assert_syntax_error("/x", /unterminated regexp meets end of file|expected a closing delimiter for the regular expression/)
e = assert_syntax_error("/x", /unterminated regexp meets end of file/)
assert_not_match(/unexpected tSTRING_END/, e.message)
end

Expand Down Expand Up @@ -1330,9 +1330,9 @@ def test_eof
end

def test_eof_in_def
assert_syntax_error("def m\n\0""end", /unexpected|cannot parse the expression/)
assert_syntax_error("def m\n\C-d""end", /unexpected|cannot parse the expression/)
assert_syntax_error("def m\n\C-z""end", /unexpected|cannot parse the expression/)
assert_syntax_error("def m\n\0""end", /unexpected/)
assert_syntax_error("def m\n\C-d""end", /unexpected/)
assert_syntax_error("def m\n\C-z""end", /unexpected/)
end

def test_unexpected_eof
Expand Down
7 changes: 3 additions & 4 deletions test/mri/tests/ruby/test_pattern_matching.rb
Original file line number Diff line number Diff line change
Expand Up @@ -1161,8 +1161,7 @@ def test_hash_pattern
end
end

bug18890 = self.then do # TruffleRuby: keep the test but do not check the warning
# bug18890 = assert_warning(/(?:.*:[47]: warning: possibly useless use of a literal in void context\n){2}/) do
bug18890 = assert_warning(/(?:.*:[47]: warning: possibly useless use of a literal in void context\n){2}/) do
eval("#{<<~';;;'}")
proc do |i|
case i
Expand Down Expand Up @@ -1248,13 +1247,13 @@ def test_hash_pattern
case _
in "#{a}": a
end
}, /symbol literal with interpolation is not allowed|expected a label as the key in the hash pattern/)
}, /symbol literal with interpolation is not allowed/)

assert_syntax_error(%q{
case _
in "#{a}":
end
}, /symbol literal with interpolation is not allowed|expected a label as the key in the hash pattern/)
}, /symbol literal with interpolation is not allowed/)
end

def test_paren
Expand Down
8 changes: 2 additions & 6 deletions test/mri/tests/ruby/test_refinement.rb
Original file line number Diff line number Diff line change
Expand Up @@ -2572,15 +2572,11 @@ def test_refine_array_min_max
class Bug17822
module Ext
refine(Bug17822) do
def foo
:refined
end
def foo = :refined
end
end

private def foo
:not_refined
end
private(def foo = :not_refined)

module Client
using Ext
Expand Down
4 changes: 2 additions & 2 deletions test/mri/tests/ruby/test_require.rb
Original file line number Diff line number Diff line change
Expand Up @@ -221,7 +221,7 @@ def assert_syntax_error_backtrace
Dir.mktmpdir do |tmp|
req = File.join(tmp, "test.rb")
File.write(req, ",\n")
e = assert_raise_with_message(SyntaxError, /unexpected|cannot parse the expression/) {
e = assert_raise_with_message(SyntaxError, /unexpected/) {
yield req
}
assert_not_nil(bt = e.backtrace, "no backtrace")
Expand All @@ -237,7 +237,7 @@ def test_require_syntax_error

def test_require_syntax_error_rescued
assert_syntax_error_backtrace do |req|
assert_raise_with_message(SyntaxError, /unexpected|cannot parse the expression/) {require req}
assert_raise_with_message(SyntaxError, /unexpected/) {require req}
require req
end
end
Expand Down
26 changes: 13 additions & 13 deletions test/mri/tests/ruby/test_syntax.rb
Original file line number Diff line number Diff line change
Expand Up @@ -600,28 +600,28 @@ def test_cmdarg_kwarg_lvar_clashing_method
end

def test_duplicated_arg
assert_syntax_error("def foo(a, a) end", /duplicated argument name|repeated parameter name/)
assert_syntax_error("def foo(a, a) end", /duplicated argument name/)
assert_valid_syntax("def foo(_, _) end")
(obj = Object.new).instance_eval("def foo(_, x, _) x end")
assert_equal(2, obj.foo(1, 2, 3))
end

def test_duplicated_rest
assert_syntax_error("def foo(a, *a) end", /duplicated argument name|repeated parameter name/)
assert_syntax_error("def foo(a, *a) end", /duplicated argument name/)
assert_valid_syntax("def foo(_, *_) end")
(obj = Object.new).instance_eval("def foo(_, x, *_) x end")
assert_equal(2, obj.foo(1, 2, 3))
end

def test_duplicated_opt
assert_syntax_error("def foo(a, a=1) end", /duplicated argument name|repeated parameter name/)
assert_syntax_error("def foo(a, a=1) end", /duplicated argument name/)
assert_valid_syntax("def foo(_, _=1) end")
(obj = Object.new).instance_eval("def foo(_, x, _=42) x end")
assert_equal(2, obj.foo(1, 2))
end

def test_duplicated_opt_rest
assert_syntax_error("def foo(a=1, *a) end", /duplicated argument name|repeated parameter name/)
assert_syntax_error("def foo(a=1, *a) end", /duplicated argument name/)
assert_valid_syntax("def foo(_=1, *_) end")
(obj = Object.new).instance_eval("def foo(_, x=42, *_) x end")
assert_equal(42, obj.foo(1))
Expand All @@ -633,7 +633,7 @@ def test_duplicated_rest_opt
end

def test_duplicated_rest_post
assert_syntax_error("def foo(*a, a) end", /duplicated argument name|repeated parameter name/)
assert_syntax_error("def foo(*a, a) end", /duplicated argument name/)
assert_valid_syntax("def foo(*_, _) end")
(obj = Object.new).instance_eval("def foo(*_, x, _) x end")
assert_equal(2, obj.foo(1, 2, 3))
Expand All @@ -644,7 +644,7 @@ def test_duplicated_rest_post
end

def test_duplicated_opt_post
assert_syntax_error("def foo(a=1, a) end", /duplicated argument name|repeated parameter name/)
assert_syntax_error("def foo(a=1, a) end", /duplicated argument name/)
assert_valid_syntax("def foo(_=1, _) end")
(obj = Object.new).instance_eval("def foo(_=1, x, _) x end")
assert_equal(2, obj.foo(1, 2, 3))
Expand All @@ -655,7 +655,7 @@ def test_duplicated_opt_post
end

def test_duplicated_kw
assert_syntax_error("def foo(a, a: 1) end", /duplicated argument name|repeated parameter name/)
assert_syntax_error("def foo(a, a: 1) end", /duplicated argument name/)
assert_valid_syntax("def foo(_, _: 1) end")
(obj = Object.new).instance_eval("def foo(_, x, _: 1) x end")
assert_equal(3, obj.foo(2, 3))
Expand All @@ -666,7 +666,7 @@ def test_duplicated_kw
end

def test_duplicated_rest_kw
assert_syntax_error("def foo(*a, a: 1) end", /duplicated argument name|repeated parameter name/)
assert_syntax_error("def foo(*a, a: 1) end", /duplicated argument name/)
assert_nothing_raised {def foo(*_, _: 1) end}
(obj = Object.new).instance_eval("def foo(*_, x: 42, _: 1) x end")
assert_equal(42, obj.foo(42))
Expand All @@ -677,15 +677,15 @@ def test_duplicated_rest_kw
end

def test_duplicated_opt_kw
assert_syntax_error("def foo(a=1, a: 1) end", /duplicated argument name|repeated parameter name/)
assert_syntax_error("def foo(a=1, a: 1) end", /duplicated argument name/)
assert_valid_syntax("def foo(_=1, _: 1) end")
(obj = Object.new).instance_eval("def foo(_=42, x, _: 1) x end")
assert_equal(0, obj.foo(0))
assert_equal(0, obj.foo(0, _: 3))
end

def test_duplicated_kw_kwrest
assert_syntax_error("def foo(a: 1, **a) end", /duplicated argument name|repeated parameter name/)
assert_syntax_error("def foo(a: 1, **a) end", /duplicated argument name/)
assert_valid_syntax("def foo(_: 1, **_) end")
(obj = Object.new).instance_eval("def foo(_: 1, x: 42, **_) x end")
assert_equal(42, obj.foo())
Expand All @@ -695,7 +695,7 @@ def test_duplicated_kw_kwrest
end

def test_duplicated_rest_kwrest
assert_syntax_error("def foo(*a, **a) end", /duplicated argument name|repeated parameter name/)
assert_syntax_error("def foo(*a, **a) end", /duplicated argument name/)
assert_valid_syntax("def foo(*_, **_) end")
(obj = Object.new).instance_eval("def foo(*_, x, **_) x end")
assert_equal(1, obj.foo(1))
Expand All @@ -704,7 +704,7 @@ def test_duplicated_rest_kwrest
end

def test_duplicated_opt_kwrest
assert_syntax_error("def foo(a=1, **a) end", /duplicated argument name|repeated parameter name/)
assert_syntax_error("def foo(a=1, **a) end", /duplicated argument name/)
assert_valid_syntax("def foo(_=1, **_) end")
(obj = Object.new).instance_eval("def foo(_=42, x, **_) x end")
assert_equal(1, obj.foo(1))
Expand Down Expand Up @@ -1792,7 +1792,7 @@ def test_numbered_parameter
assert_syntax_error('-> {-> {_1}; _2}', /numbered parameter is already used/)
assert_syntax_error('proc {_1; _1 = nil}', /Can't assign to numbered parameter _1/)
assert_syntax_error('proc {_1 = nil}', /_1 is reserved for numbered parameter/)
# assert_syntax_error('_2=1', /_2 is reserved for numbered parameter/) # GR-30031
assert_syntax_error('_2=1', /_2 is reserved for numbered parameter/)
assert_syntax_error('proc {|_3|}', /_3 is reserved for numbered parameter/)
assert_syntax_error('def x(_4) end', /_4 is reserved for numbered parameter/)
assert_syntax_error('def _5; end', /_5 is reserved for numbered parameter/)
Expand Down

0 comments on commit 9db9994

Please sign in to comment.