diff --git a/lib/spoom/cfg.rb b/lib/spoom/cfg.rb index 0374c096..61089ce3 100644 --- a/lib/spoom/cfg.rb +++ b/lib/spoom/cfg.rb @@ -605,6 +605,9 @@ def visit_or_node(node) sig { override.params(node: Prism::RescueNode).void } def visit_rescue_node(node) + puts node.inspect + visit_all(node.exceptions) + visit(node.reference) visit(node.statements) end diff --git a/sorbet/config b/sorbet/config index e4cd62a3..5b6ebc58 100644 --- a/sorbet/config +++ b/sorbet/config @@ -1,4 +1,4 @@ . --ignore=vendor/ ---ignore=test/spoom/cfg/ +--ignore=test/spoom/cfg/fixtures --enable-experimental-requires-ancestor diff --git a/test.rb b/test.rb index c83a4983..08246587 100644 --- a/test.rb +++ b/test.rb @@ -2,20 +2,6 @@ # frozen_string_literal: true begin - x = 1 - puts "inside" - if foo? - return - puts "dead" - else - return - puts "dead" - end - - puts "dead" -rescue - puts x - puts "rescue" - return - puts "dead" +rescue MyException.new.class => e + puts e end diff --git a/test/spoom/cfg/fixtures/and.cfg.exp b/test/spoom/cfg/fixtures/and.cfg similarity index 100% rename from test/spoom/cfg/fixtures/and.cfg.exp rename to test/spoom/cfg/fixtures/and.cfg diff --git a/test/spoom/cfg/fixtures/begin.cfg.exp b/test/spoom/cfg/fixtures/begin.cfg similarity index 100% rename from test/spoom/cfg/fixtures/begin.cfg.exp rename to test/spoom/cfg/fixtures/begin.cfg diff --git a/test/spoom/cfg/fixtures/begin_ensure.cfg.exp b/test/spoom/cfg/fixtures/begin_ensure.cfg similarity index 100% rename from test/spoom/cfg/fixtures/begin_ensure.cfg.exp rename to test/spoom/cfg/fixtures/begin_ensure.cfg diff --git a/test/spoom/cfg/fixtures/begin_rescue.cfg.exp b/test/spoom/cfg/fixtures/begin_rescue.cfg similarity index 100% rename from test/spoom/cfg/fixtures/begin_rescue.cfg.exp rename to test/spoom/cfg/fixtures/begin_rescue.cfg diff --git a/test/spoom/cfg/fixtures/begin_rescue_args.cfg b/test/spoom/cfg/fixtures/begin_rescue_args.cfg new file mode 100644 index 00000000..9c27e364 --- /dev/null +++ b/test/spoom/cfg/fixtures/begin_rescue_args.cfg @@ -0,0 +1,13 @@ +cfg:
+ + bb#0 + -> bb#3 + -> bb#1 + + bb#3 + MyException.new.class() + e + .puts(e) + -> bb#1 + + bb#1 diff --git a/test/spoom/cfg/fixtures/begin_rescue_args.rb b/test/spoom/cfg/fixtures/begin_rescue_args.rb new file mode 100644 index 00000000..712548df --- /dev/null +++ b/test/spoom/cfg/fixtures/begin_rescue_args.rb @@ -0,0 +1,4 @@ +begin +rescue MyException.new.class => e + puts e +end diff --git a/test/spoom/cfg/fixtures/begin_rescue_else.cfg.exp b/test/spoom/cfg/fixtures/begin_rescue_else.cfg similarity index 100% rename from test/spoom/cfg/fixtures/begin_rescue_else.cfg.exp rename to test/spoom/cfg/fixtures/begin_rescue_else.cfg diff --git a/test/spoom/cfg/fixtures/begin_rescue_else_ensure.cfg.exp b/test/spoom/cfg/fixtures/begin_rescue_else_ensure.cfg similarity index 100% rename from test/spoom/cfg/fixtures/begin_rescue_else_ensure.cfg.exp rename to test/spoom/cfg/fixtures/begin_rescue_else_ensure.cfg diff --git a/test/spoom/cfg/fixtures/begin_rescue_ensure.cfg.exp b/test/spoom/cfg/fixtures/begin_rescue_ensure.cfg similarity index 100% rename from test/spoom/cfg/fixtures/begin_rescue_ensure.cfg.exp rename to test/spoom/cfg/fixtures/begin_rescue_ensure.cfg diff --git a/test/spoom/cfg/fixtures/begin_until.cfg.exp b/test/spoom/cfg/fixtures/begin_until.cfg similarity index 100% rename from test/spoom/cfg/fixtures/begin_until.cfg.exp rename to test/spoom/cfg/fixtures/begin_until.cfg diff --git a/test/spoom/cfg/fixtures/begin_until_assign.cfg.exp b/test/spoom/cfg/fixtures/begin_until_assign.cfg similarity index 100% rename from test/spoom/cfg/fixtures/begin_until_assign.cfg.exp rename to test/spoom/cfg/fixtures/begin_until_assign.cfg diff --git a/test/spoom/cfg/fixtures/begin_while.cfg.exp b/test/spoom/cfg/fixtures/begin_while.cfg similarity index 100% rename from test/spoom/cfg/fixtures/begin_while.cfg.exp rename to test/spoom/cfg/fixtures/begin_while.cfg diff --git a/test/spoom/cfg/fixtures/begin_while_assign.cfg.exp b/test/spoom/cfg/fixtures/begin_while_assign.cfg similarity index 100% rename from test/spoom/cfg/fixtures/begin_while_assign.cfg.exp rename to test/spoom/cfg/fixtures/begin_while_assign.cfg diff --git a/test/spoom/cfg/fixtures/break_dead.cfg.exp b/test/spoom/cfg/fixtures/break_dead.cfg similarity index 100% rename from test/spoom/cfg/fixtures/break_dead.cfg.exp rename to test/spoom/cfg/fixtures/break_dead.cfg diff --git a/test/spoom/cfg/fixtures/break_for.cfg.exp b/test/spoom/cfg/fixtures/break_for.cfg similarity index 100% rename from test/spoom/cfg/fixtures/break_for.cfg.exp rename to test/spoom/cfg/fixtures/break_for.cfg diff --git a/test/spoom/cfg/fixtures/break_until.cfg.exp b/test/spoom/cfg/fixtures/break_until.cfg similarity index 100% rename from test/spoom/cfg/fixtures/break_until.cfg.exp rename to test/spoom/cfg/fixtures/break_until.cfg diff --git a/test/spoom/cfg/fixtures/break_while.cfg.exp b/test/spoom/cfg/fixtures/break_while.cfg similarity index 100% rename from test/spoom/cfg/fixtures/break_while.cfg.exp rename to test/spoom/cfg/fixtures/break_while.cfg diff --git a/test/spoom/cfg/fixtures/call_block.cfg.exp b/test/spoom/cfg/fixtures/call_block.cfg similarity index 100% rename from test/spoom/cfg/fixtures/call_block.cfg.exp rename to test/spoom/cfg/fixtures/call_block.cfg diff --git a/test/spoom/cfg/fixtures/call_block_break.cfg.exp b/test/spoom/cfg/fixtures/call_block_break.cfg similarity index 100% rename from test/spoom/cfg/fixtures/call_block_break.cfg.exp rename to test/spoom/cfg/fixtures/call_block_break.cfg diff --git a/test/spoom/cfg/fixtures/call_block_break_if.cfg.exp b/test/spoom/cfg/fixtures/call_block_break_if.cfg similarity index 100% rename from test/spoom/cfg/fixtures/call_block_break_if.cfg.exp rename to test/spoom/cfg/fixtures/call_block_break_if.cfg diff --git a/test/spoom/cfg/fixtures/call_block_next.cfg.exp b/test/spoom/cfg/fixtures/call_block_next.cfg similarity index 100% rename from test/spoom/cfg/fixtures/call_block_next.cfg.exp rename to test/spoom/cfg/fixtures/call_block_next.cfg diff --git a/test/spoom/cfg/fixtures/call_block_return.cfg.exp b/test/spoom/cfg/fixtures/call_block_return.cfg similarity index 100% rename from test/spoom/cfg/fixtures/call_block_return.cfg.exp rename to test/spoom/cfg/fixtures/call_block_return.cfg diff --git a/test/spoom/cfg/fixtures/call_block_return_if.cfg.exp b/test/spoom/cfg/fixtures/call_block_return_if.cfg similarity index 100% rename from test/spoom/cfg/fixtures/call_block_return_if.cfg.exp rename to test/spoom/cfg/fixtures/call_block_return_if.cfg diff --git a/test/spoom/cfg/fixtures/case_else.cfg.exp b/test/spoom/cfg/fixtures/case_else.cfg similarity index 100% rename from test/spoom/cfg/fixtures/case_else.cfg.exp rename to test/spoom/cfg/fixtures/case_else.cfg diff --git a/test/spoom/cfg/fixtures/case_when.cfg.exp b/test/spoom/cfg/fixtures/case_when.cfg similarity index 100% rename from test/spoom/cfg/fixtures/case_when.cfg.exp rename to test/spoom/cfg/fixtures/case_when.cfg diff --git a/test/spoom/cfg/fixtures/def.cfg.exp b/test/spoom/cfg/fixtures/def.cfg similarity index 100% rename from test/spoom/cfg/fixtures/def.cfg.exp rename to test/spoom/cfg/fixtures/def.cfg diff --git a/test/spoom/cfg/fixtures/empty.cfg.exp b/test/spoom/cfg/fixtures/empty.cfg similarity index 100% rename from test/spoom/cfg/fixtures/empty.cfg.exp rename to test/spoom/cfg/fixtures/empty.cfg diff --git a/test/spoom/cfg/fixtures/for.cfg.exp b/test/spoom/cfg/fixtures/for.cfg similarity index 100% rename from test/spoom/cfg/fixtures/for.cfg.exp rename to test/spoom/cfg/fixtures/for.cfg diff --git a/test/spoom/cfg/fixtures/if.cfg.exp b/test/spoom/cfg/fixtures/if.cfg similarity index 100% rename from test/spoom/cfg/fixtures/if.cfg.exp rename to test/spoom/cfg/fixtures/if.cfg diff --git a/test/spoom/cfg/fixtures/if_else.cfg.exp b/test/spoom/cfg/fixtures/if_else.cfg similarity index 100% rename from test/spoom/cfg/fixtures/if_else.cfg.exp rename to test/spoom/cfg/fixtures/if_else.cfg diff --git a/test/spoom/cfg/fixtures/if_elsif.cfg.exp b/test/spoom/cfg/fixtures/if_elsif.cfg similarity index 100% rename from test/spoom/cfg/fixtures/if_elsif.cfg.exp rename to test/spoom/cfg/fixtures/if_elsif.cfg diff --git a/test/spoom/cfg/fixtures/if_elsif_else.cfg.exp b/test/spoom/cfg/fixtures/if_elsif_else.cfg similarity index 100% rename from test/spoom/cfg/fixtures/if_elsif_else.cfg.exp rename to test/spoom/cfg/fixtures/if_elsif_else.cfg diff --git a/test/spoom/cfg/fixtures/if_inline.cfg.exp b/test/spoom/cfg/fixtures/if_inline.cfg similarity index 100% rename from test/spoom/cfg/fixtures/if_inline.cfg.exp rename to test/spoom/cfg/fixtures/if_inline.cfg diff --git a/test/spoom/cfg/fixtures/next_for.cfg.exp b/test/spoom/cfg/fixtures/next_for.cfg similarity index 100% rename from test/spoom/cfg/fixtures/next_for.cfg.exp rename to test/spoom/cfg/fixtures/next_for.cfg diff --git a/test/spoom/cfg/fixtures/next_until.cfg.exp b/test/spoom/cfg/fixtures/next_until.cfg similarity index 100% rename from test/spoom/cfg/fixtures/next_until.cfg.exp rename to test/spoom/cfg/fixtures/next_until.cfg diff --git a/test/spoom/cfg/fixtures/next_while.cfg.exp b/test/spoom/cfg/fixtures/next_while.cfg similarity index 100% rename from test/spoom/cfg/fixtures/next_while.cfg.exp rename to test/spoom/cfg/fixtures/next_while.cfg diff --git a/test/spoom/cfg/fixtures/or.cfg.exp b/test/spoom/cfg/fixtures/or.cfg similarity index 100% rename from test/spoom/cfg/fixtures/or.cfg.exp rename to test/spoom/cfg/fixtures/or.cfg diff --git a/test/spoom/cfg/fixtures/return.cfg.exp b/test/spoom/cfg/fixtures/return.cfg similarity index 100% rename from test/spoom/cfg/fixtures/return.cfg.exp rename to test/spoom/cfg/fixtures/return.cfg diff --git a/test/spoom/cfg/fixtures/return_case.cfg.exp b/test/spoom/cfg/fixtures/return_case.cfg similarity index 100% rename from test/spoom/cfg/fixtures/return_case.cfg.exp rename to test/spoom/cfg/fixtures/return_case.cfg diff --git a/test/spoom/cfg/fixtures/return_if.cfg.exp b/test/spoom/cfg/fixtures/return_if.cfg similarity index 100% rename from test/spoom/cfg/fixtures/return_if.cfg.exp rename to test/spoom/cfg/fixtures/return_if.cfg diff --git a/test/spoom/cfg/fixtures/return_if_else.cfg.exp b/test/spoom/cfg/fixtures/return_if_else.cfg similarity index 100% rename from test/spoom/cfg/fixtures/return_if_else.cfg.exp rename to test/spoom/cfg/fixtures/return_if_else.cfg diff --git a/test/spoom/cfg/fixtures/return_until.cfg.exp b/test/spoom/cfg/fixtures/return_until.cfg similarity index 100% rename from test/spoom/cfg/fixtures/return_until.cfg.exp rename to test/spoom/cfg/fixtures/return_until.cfg diff --git a/test/spoom/cfg/fixtures/return_while.cfg.exp b/test/spoom/cfg/fixtures/return_while.cfg similarity index 100% rename from test/spoom/cfg/fixtures/return_while.cfg.exp rename to test/spoom/cfg/fixtures/return_while.cfg diff --git a/test/spoom/cfg/fixtures/static_init.cfg.exp b/test/spoom/cfg/fixtures/static_init.cfg similarity index 100% rename from test/spoom/cfg/fixtures/static_init.cfg.exp rename to test/spoom/cfg/fixtures/static_init.cfg diff --git a/test/spoom/cfg/fixtures/top_level_instructions.cfg.exp b/test/spoom/cfg/fixtures/top_level_instructions.cfg similarity index 100% rename from test/spoom/cfg/fixtures/top_level_instructions.cfg.exp rename to test/spoom/cfg/fixtures/top_level_instructions.cfg diff --git a/test/spoom/cfg/fixtures/unless.cfg.exp b/test/spoom/cfg/fixtures/unless.cfg similarity index 100% rename from test/spoom/cfg/fixtures/unless.cfg.exp rename to test/spoom/cfg/fixtures/unless.cfg diff --git a/test/spoom/cfg/fixtures/unless_else.cfg.exp b/test/spoom/cfg/fixtures/unless_else.cfg similarity index 100% rename from test/spoom/cfg/fixtures/unless_else.cfg.exp rename to test/spoom/cfg/fixtures/unless_else.cfg diff --git a/test/spoom/cfg/fixtures/unless_inline.cfg.exp b/test/spoom/cfg/fixtures/unless_inline.cfg similarity index 100% rename from test/spoom/cfg/fixtures/unless_inline.cfg.exp rename to test/spoom/cfg/fixtures/unless_inline.cfg diff --git a/test/spoom/cfg/fixtures/until.cfg.exp b/test/spoom/cfg/fixtures/until.cfg similarity index 100% rename from test/spoom/cfg/fixtures/until.cfg.exp rename to test/spoom/cfg/fixtures/until.cfg diff --git a/test/spoom/cfg/fixtures/while.cfg.exp b/test/spoom/cfg/fixtures/while.cfg similarity index 100% rename from test/spoom/cfg/fixtures/while.cfg.exp rename to test/spoom/cfg/fixtures/while.cfg diff --git a/test/spoom/cfg/fixtures/yield.cfg.exp b/test/spoom/cfg/fixtures/yield.cfg similarity index 100% rename from test/spoom/cfg/fixtures/yield.cfg.exp rename to test/spoom/cfg/fixtures/yield.cfg diff --git a/test/spoom/cfg/fixtures_test.rb b/test/spoom/cfg/fixtures_test.rb index 58677ea9..9c617049 100644 --- a/test/spoom/cfg/fixtures_test.rb +++ b/test/spoom/cfg/fixtures_test.rb @@ -16,9 +16,7 @@ class CFGFixturesTest < Minitest::Test test_name = "test_#{name}" define_method(test_name) do - expected_path = File.join(dir, "#{name}.cfg.exp") - assert(File.exist?(expected_path), "expectation file missing for #{file}") - expected_output = File.read(expected_path) + T.bind(self, Minitest::Test) node = Spoom.parse_ruby(File.read(file), file: file) cfgs_cluster = Spoom::CFG.from_node(node) @@ -31,7 +29,13 @@ class CFGFixturesTest < Minitest::Test puts puts actual_output cfgs_cluster.show_dot - elsif ENV["CFG_UPDATE_FIXTURES"] + end + + expected_path = File.join(dir, "#{name}.cfg") + assert(File.exist?(expected_path), "expectation file missing for #{file}") + expected_output = File.read(expected_path) + + if ENV["CFG_UPDATE_FIXTURES"] File.write(expected_path, actual_output) else unless expected_output == actual_output