Suppress warnings when testing RubyVM::AbstractSyntaxTree

This commit is contained in:
Étienne Barrié 2025-08-22 10:38:37 +02:00 committed by Jean Boussier
parent 1902c42b1f
commit af210467b5

View File

@ -48,7 +48,7 @@ class TestAst < Test::Unit::TestCase
@path = path
@errors = []
@debug = false
@ast = RubyVM::AbstractSyntaxTree.parse(src) if src
@ast = EnvUtil.suppress_warning { RubyVM::AbstractSyntaxTree.parse(src) } if src
end
def validate_range
@ -67,7 +67,7 @@ class TestAst < Test::Unit::TestCase
def ast
return @ast if defined?(@ast)
@ast = RubyVM::AbstractSyntaxTree.parse_file(@path)
@ast = EnvUtil.suppress_warning { RubyVM::AbstractSyntaxTree.parse_file(@path) }
end
private
@ -135,7 +135,7 @@ class TestAst < Test::Unit::TestCase
Dir.glob("test/**/*.rb", base: SRCDIR).each do |path|
define_method("test_all_tokens:#{path}") do
node = RubyVM::AbstractSyntaxTree.parse_file("#{SRCDIR}/#{path}", keep_tokens: true)
node = EnvUtil.suppress_warning { RubyVM::AbstractSyntaxTree.parse_file("#{SRCDIR}/#{path}", keep_tokens: true) }
tokens = node.all_tokens.sort_by { [_1.last[0], _1.last[1]] }
tokens_bytes = tokens.map { _1[2]}.join.bytes
source_bytes = File.read("#{SRCDIR}/#{path}").bytes