Skip to content

Commit a6dc1e0

Browse files
eregonandrykonchin
authored andcommitted
Adapt MRI tests to allow Prism error messages
* And exclude on missing SyntaxError.
1 parent 53953de commit a6dc1e0

File tree

6 files changed

+30
-25
lines changed

6 files changed

+30
-25
lines changed

test/mri/excludes/TestParse.rb

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -50,3 +50,5 @@
5050
exclude :test_magic_comment, "<#<Encoding:US-ASCII>> expected but was"
5151
exclude :test_if_after_class, "/home/eregon/code/truffleruby-ws/truffleruby/test/mri/tests/ruby/test_parse.rb:1365:in `test_if_after_class'."
5252
exclude :test_escaped_space, "/home/eregon/code/truffleruby-ws/truffleruby/test/mri/tests/ruby/test_parse.rb:1370:in `test_escaped_space'."
53+
exclude :test_dynamic_constant_assignment, "prism"
54+
exclude :test_serial_comparison, "prism"

test/mri/excludes/TestRegexp.rb

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -50,3 +50,5 @@
5050
exclude :test_s_timeout_corner_cases, "NoMethodError: private method `timeout' called for Regexp:Class"
5151
exclude :test_bug_19467, "NoMethodError: undefined method `timeout=' for Regexp:Class"
5252
exclude :test_s_timeout, "NoMethodError: undefined method `timeout=' for Regexp:Class"
53+
exclude :test_unicode, "prism missing regexp encoding flags"
54+
exclude :test_char_class, "prism missing regexp encoding flags"

test/mri/excludes/TestRubyLiteral.rb

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,3 +3,4 @@
33
exclude :test_hash_value_omission, "NameError: undefined local variable or method `FOO' for #<TestRubyLiteral:0x2914b8>"
44
exclude :test_hash_duplicated_key, "duplicated literal key."
55
exclude :test_float, "_1 inside eval, see https://github.com/ruby/prism/issues/2275"
6+
exclude :test_dregexp, "prism missing regexp encoding flags"

test/mri/tests/ruby/test_class.rb

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -308,7 +308,7 @@ def test_invalid_retry_from_class_definition
308308
end
309309

310310
def test_invalid_return_from_class_definition
311-
assert_syntax_error("class C; return; end", /Invalid return/)
311+
assert_syntax_error("class C; return; end", /Invalid return|invalid `return`/)
312312
end
313313

314314
def test_invalid_yield_from_class_definition

test/mri/tests/ruby/test_parse.rb

Lines changed: 22 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,7 @@ def test_else_without_rescue
2626
end
2727

2828
def test_alias_backref
29-
assert_syntax_error("#{<<~"begin;"}\n#{<<~'end;'}", /can't make alias/) do
29+
assert_syntax_error("#{<<~"begin;"}\n#{<<~'end;'}", /can't make alias|invalid argument being passed to `alias`/) do
3030
begin;
3131
alias $foo $1
3232
end;
@@ -84,7 +84,7 @@ class << o
8484
assert_equal([42, 42], [o.Foo, o.Bar])
8585
assert_equal([42, 42], [o::baz, o::qux])
8686

87-
assert_syntax_error("#{<<~"begin;"}\n#{<<~'end;'}", /Can't set variable/) do
87+
assert_syntax_error("#{<<~"begin;"}\n#{<<~'end;'}", /Can't set variable|immutable variable as a write target/) do
8888
begin;
8989
$1 ||= t.foo 42
9090
end;
@@ -192,13 +192,13 @@ def foo
192192
end
193193

194194
def test_class_module
195-
assert_syntax_error("#{<<~"begin;"}\n#{<<~'end;'}", /must be CONSTANT/) do
195+
assert_syntax_error("#{<<~"begin;"}\n#{<<~'end;'}", /must be CONSTANT|expected a constant name/) do
196196
begin;
197197
class foo; end
198198
end;
199199
end
200200

201-
assert_syntax_error("#{<<~"begin;"}\n#{<<~'end;'}", /in method body/) do
201+
assert_syntax_error("#{<<~"begin;"}\n#{<<~'end;'}", /in method body|unexpected class definition in a method definition/) do
202202
begin;
203203
def foo
204204
class Foo; end
@@ -294,7 +294,7 @@ def foo(@@foo); end
294294
end;
295295
end
296296

297-
assert_syntax_error("#{<<~"begin;"}\n#{<<~'end;'}", /cannot be an instance variable/) do
297+
assert_syntax_error("#{<<~"begin;"}\n#{<<~'end;'}", /cannot be an instance variable|expected a local variable name in the block parameters/) do
298298
begin;
299299
o.foo {|; @a| @a = 42 }
300300
end;
@@ -377,10 +377,10 @@ def test_dsym
377377

378378
def assert_disallowed_variable(type, noname, invalid)
379379
noname.each do |name|
380-
assert_syntax_error("proc{a = #{name} }", "`#{noname[0]}' without identifiers is not allowed as #{type} variable name")
380+
assert_syntax_error("proc{a = #{name} }", /`#{noname[0]}' without identifiers is not allowed as #{type} variable name|invalid global variable/)
381381
end
382382
invalid.each do |name|
383-
assert_syntax_error("proc {a = #{name} }", "`#{name}' is not allowed as #{type} variable name")
383+
assert_syntax_error("proc {a = #{name} }", /`#{name}' is not allowed as #{type} variable name|invalid global variable/)
384384
end
385385
end
386386

@@ -438,13 +438,13 @@ def test_duplicate_argument
438438
end;
439439
end
440440

441-
assert_syntax_error("#{<<~"begin;"}\n#{<<~'end;'}", /duplicated argument/) do
441+
assert_syntax_error("#{<<~"begin;"}\n#{<<~'end;'}", /duplicated argument|repeated parameter name/) do
442442
begin;
443443
1.times {|a, a|}
444444
end;
445445
end
446446

447-
assert_syntax_error("#{<<~"begin;"}\n#{<<~'end;'}", /duplicated argument/) do
447+
assert_syntax_error("#{<<~"begin;"}\n#{<<~'end;'}", /duplicated argument|repeated parameter name/) do
448448
begin;
449449
def foo(a, a); end
450450
end;
@@ -611,12 +611,12 @@ def test_question
611611

612612
def test_percent
613613
assert_equal(:foo, eval('%s(foo)'))
614-
assert_syntax_error('%s', /unterminated quoted string/)
615-
assert_syntax_error('%ss', /unknown type/)
616-
assert_syntax_error('%z()', /unknown type/)
617-
assert_syntax_error("%\u3042", /unknown type/)
618-
assert_syntax_error("%q\u3042", /unknown type/)
619-
assert_syntax_error("%", /unterminated quoted string/)
614+
assert_syntax_error('%s', /unterminated quoted string|expected a closing delimiter for the dynamic symbol/)
615+
assert_syntax_error('%ss', /unknown type|invalid `%` token/)
616+
assert_syntax_error('%z()', /unknown type|invalid `%` token/)
617+
assert_syntax_error("%\u3042", /unknown type|invalid `%` token/)
618+
assert_syntax_error("%q\u3042", /unknown type|invalid `%` token/)
619+
assert_syntax_error("%", /unterminated quoted string|invalid `%` token/)
620620
end
621621

622622
def test_symbol
@@ -643,7 +643,7 @@ def test_symbol
643643
end
644644

645645
def test_parse_string
646-
assert_syntax_error("/\n", /unterminated/)
646+
assert_syntax_error("/\n", /unterminated|expected a closing delimiter for the regular expression/)
647647
end
648648

649649
def test_here_document
@@ -817,7 +817,7 @@ def test_block_dup
817817
end
818818

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

823823
def test_arg_concat
@@ -1111,7 +1111,7 @@ def test_heredoc_interpolation
11111111
end
11121112

11131113
def test_unexpected_token_error
1114-
assert_syntax_error('"x"xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx', /unexpected/)
1114+
assert_syntax_error('"x"xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx', /unexpected|expected a newline or semicolon after the statement/)
11151115
end
11161116

11171117
def test_unexpected_token_after_numeric
@@ -1129,7 +1129,7 @@ def test_truncated_source_line
11291129
end
11301130

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

@@ -1161,9 +1161,9 @@ def test_eof
11611161
end
11621162

11631163
def test_eof_in_def
1164-
assert_syntax_error("def m\n\0""end", /unexpected/)
1165-
assert_syntax_error("def m\n\C-d""end", /unexpected/)
1166-
assert_syntax_error("def m\n\C-z""end", /unexpected/)
1164+
assert_syntax_error("def m\n\0""end", /unexpected|cannot parse the expression/)
1165+
assert_syntax_error("def m\n\C-d""end", /unexpected|cannot parse the expression/)
1166+
assert_syntax_error("def m\n\C-z""end", /unexpected|cannot parse the expression/)
11671167
end
11681168

11691169
def test_unexpected_eof

test/mri/tests/ruby/test_require.rb

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -204,7 +204,7 @@ def assert_syntax_error_backtrace
204204
Dir.mktmpdir do |tmp|
205205
req = File.join(tmp, "test.rb")
206206
File.write(req, ",\n")
207-
e = assert_raise_with_message(SyntaxError, /unexpected/) {
207+
e = assert_raise_with_message(SyntaxError, /unexpected|cannot parse the expression/) {
208208
yield req
209209
}
210210
assert_not_nil(bt = e.backtrace, "no backtrace")
@@ -219,7 +219,7 @@ def test_require_syntax_error
219219

220220
def test_require_syntax_error_rescued
221221
assert_syntax_error_backtrace do |req|
222-
assert_raise_with_message(SyntaxError, /unexpected/) {require req}
222+
assert_raise_with_message(SyntaxError, /unexpected|cannot parse the expression/) {require req}
223223
require req
224224
end
225225
end

0 commit comments

Comments
 (0)