Skip to content

Commit 7489a46

Browse files
committed
Show the YARP AST if a parsing test fails
1 parent 6c791ef commit 7489a46

File tree

1 file changed

+10
-4
lines changed

1 file changed

+10
-4
lines changed

spec/truffle/parsing/parsing_spec.rb

Lines changed: 10 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -54,18 +54,21 @@
5454
require 'yaml'
5555

5656
filenames = Dir.glob("#{__dir__}/fixtures/**/*.yaml")
57-
# filenames = ["#{__dir__}/fixtures/ternary_if.yaml"] # to run a single one
57+
# filenames = ["#{__dir__}/fixtures/if/with_empty_then_branch.yaml"] # to run a single one
5858

5959
filenames.each do |filename|
6060
yaml = YAML.safe_load_file(filename)
6161
subject, description, focused_on_node, index, source_code, expected_ast = yaml.values_at("subject", "description", "focused_on_node", "index", "ruby", "ast")
62+
source_code.strip!
63+
expected_ast.strip!
64+
index = index.to_i
6265

6366
guard -> { Primitive.vm_single_context? && !TruffleRuby.jit? } do
6467
it "a #{subject} (#{description.strip}) case is parsed correctly" do
6568
if ENV['TRUFFLE_PARSING_USE_ORIGINAL_TRANSLATOR'] == 'true'
66-
actual_ast = Truffle::Debug.parse_and_dump_truffle_ast(source_code.strip, focused_on_node, index.to_i).strip
69+
actual_ast = Truffle::Debug.parse_and_dump_truffle_ast(source_code, focused_on_node, index).strip
6770
else
68-
actual_ast = Truffle::Debug.parse_with_yarp_and_dump_truffle_ast(source_code.strip, focused_on_node, index.to_i).strip
71+
actual_ast = Truffle::Debug.parse_with_yarp_and_dump_truffle_ast(source_code, focused_on_node, index).strip
6972
end
7073

7174
if overwrite
@@ -85,7 +88,10 @@
8588
end
8689
else
8790
# actual test check
88-
actual_ast.should == expected_ast.strip
91+
unless actual_ast == expected_ast
92+
$stderr.puts "\nYARP AST:", Truffle::Debug.yarp_parse(source_code)
93+
end
94+
actual_ast.should == expected_ast
8995
end
9096
end
9197
end

0 commit comments

Comments
 (0)