Skip to content

Commit adde5da

Browse files
authored
Merge pull request #321 from eregon/fix-truffleruby-ci
Fix CI for TruffleRuby
2 parents ff9094a + d3410ff commit adde5da

File tree

2 files changed

+39
-34
lines changed

2 files changed

+39
-34
lines changed

lib/syntax_tree/reflection.rb

+2-1
Original file line numberDiff line numberDiff line change
@@ -176,7 +176,8 @@ def parse_comments(statements, index)
176176
program =
177177
SyntaxTree.parse(SyntaxTree.read(File.expand_path("node.rb", __dir__)))
178178

179-
main_statements = program.statements.body.last.bodystmt.statements.body
179+
program_statements = program.statements
180+
main_statements = program_statements.body.last.bodystmt.statements.body
180181
main_statements.each_with_index do |main_statement, main_statement_index|
181182
# Ensure we are only looking at class declarations.
182183
next unless main_statement.is_a?(SyntaxTree::ClassDeclaration)

test/test_helper.rb

+37-33
Original file line numberDiff line numberDiff line change
@@ -1,46 +1,50 @@
11
# frozen_string_literal: true
22

3-
require "simplecov"
4-
SimpleCov.start do
5-
add_filter("idempotency_test.rb") unless ENV["CI"]
6-
add_group("lib", "lib")
7-
add_group("test", "test")
3+
unless RUBY_ENGINE == "truffleruby"
4+
require "simplecov"
5+
SimpleCov.start do
6+
add_filter("idempotency_test.rb") unless ENV["CI"]
7+
add_group("lib", "lib")
8+
add_group("test", "test")
9+
end
810
end
911

1012
$LOAD_PATH.unshift(File.expand_path("../lib", __dir__))
1113
require "syntax_tree"
1214
require "syntax_tree/cli"
1315

14-
# Here we are going to establish type verification whenever a new node is
15-
# created. We do this through the reflection module, which in turn parses the
16-
# source code of the node classes.
17-
require "syntax_tree/reflection"
18-
SyntaxTree::Reflection.nodes.each do |name, node|
19-
next if name == :Statements
20-
21-
clazz = SyntaxTree.const_get(name)
22-
parameters = clazz.instance_method(:initialize).parameters
23-
24-
# First, verify that all of the parameters listed in the list of attributes.
25-
# If there are any parameters that aren't listed in the attributes, then
26-
# something went wrong with the parsing in the reflection module.
27-
raise unless (parameters.map(&:last) - node.attributes.keys).empty?
28-
29-
# Now we're going to use an alias chain to redefine the initialize method to
30-
# include type checking.
31-
clazz.alias_method(:initialize_without_verify, :initialize)
32-
clazz.define_method(:initialize) do |**kwargs|
33-
kwargs.each do |kwarg, value|
34-
attribute = node.attributes.fetch(kwarg)
35-
36-
unless attribute.type === value
37-
raise TypeError,
38-
"invalid type for #{name}##{kwarg}, expected " \
39-
"#{attribute.type.inspect}, got #{value.inspect}"
16+
unless RUBY_ENGINE == "truffleruby"
17+
# Here we are going to establish type verification whenever a new node is
18+
# created. We do this through the reflection module, which in turn parses the
19+
# source code of the node classes.
20+
require "syntax_tree/reflection"
21+
SyntaxTree::Reflection.nodes.each do |name, node|
22+
next if name == :Statements
23+
24+
clazz = SyntaxTree.const_get(name)
25+
parameters = clazz.instance_method(:initialize).parameters
26+
27+
# First, verify that all of the parameters listed in the list of attributes.
28+
# If there are any parameters that aren't listed in the attributes, then
29+
# something went wrong with the parsing in the reflection module.
30+
raise unless (parameters.map(&:last) - node.attributes.keys).empty?
31+
32+
# Now we're going to use an alias chain to redefine the initialize method to
33+
# include type checking.
34+
clazz.alias_method(:initialize_without_verify, :initialize)
35+
clazz.define_method(:initialize) do |**kwargs|
36+
kwargs.each do |kwarg, value|
37+
attribute = node.attributes.fetch(kwarg)
38+
39+
unless attribute.type === value
40+
raise TypeError,
41+
"invalid type for #{name}##{kwarg}, expected " \
42+
"#{attribute.type.inspect}, got #{value.inspect}"
43+
end
4044
end
41-
end
4245

43-
initialize_without_verify(**kwargs)
46+
initialize_without_verify(**kwargs)
47+
end
4448
end
4549
end
4650

0 commit comments

Comments
 (0)