Skip to content

Commit

Permalink
[PRISM] Enable test_methoddef_endless_command
Browse files Browse the repository at this point in the history
  • Loading branch information
kddnewton committed May 7, 2024
1 parent 2bfc487 commit b4b39a6
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 3 deletions.
4 changes: 2 additions & 2 deletions test/ruby/test_syntax.rb
Expand Up @@ -1755,8 +1755,8 @@ def test_methoddef_endless_command
assert_equal("instance ok", k.new.rescued("ok"))

# Current technical limitation: cannot prepend "private" or something for command endless def
error = /syntax error, unexpected string literal/
error2 = /syntax error, unexpected local variable or method/
error = /(syntax error,|\^~*) unexpected string literal/
error2 = /(syntax error,|\^~*) unexpected local variable or method/
assert_syntax_error('private def foo = puts "Hello"', error)
assert_syntax_error('private def foo() = puts "Hello"', error)
assert_syntax_error('private def foo(x) = puts x', error2)
Expand Down
9 changes: 8 additions & 1 deletion tool/lib/test/unit/assertions.rb
Expand Up @@ -768,7 +768,14 @@ def assert_syntax_error(code, error, *args, **opt)
e = assert_raise(SyntaxError, mesg) do
syntax_check(src, fname, line)
end
assert_match(error, e.message, mesg)

# Prism adds ANSI escape sequences to syntax error messages to
# colorize and format them. We strip them out here to make them easier
# to match against in tests.
message = e.message
message.gsub!(/\e\[.*?m/, "")

assert_match(error, message, mesg)
e
end
end
Expand Down

0 comments on commit b4b39a6

Please sign in to comment.