Skip to content

Commit

Permalink
TMP
Browse files Browse the repository at this point in the history
  • Loading branch information
Morriar committed Aug 20, 2024
1 parent bf94b90 commit 026c7ba
Show file tree
Hide file tree
Showing 29 changed files with 260 additions and 308 deletions.
16 changes: 16 additions & 0 deletions lib/spoom/cfg.rb
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ class << self

sig { params(node: Prism::Node).returns(Cluster) }
def from_node(node)
puts node.inspect
# puts node.inspect
walker = Walker.new
walker.visit(node)
Expand Down Expand Up @@ -452,6 +453,11 @@ def visit_case_node(node)
@current_block = merge_block
end

sig { override.params(node: Prism::ConstantReadNode).void }
def visit_constant_read_node(node)
@current_block.instructions << node
end

sig { override.params(node: Prism::ClassNode).void }
def visit_class_node(node)
@current_block.instructions << node
Expand Down Expand Up @@ -564,6 +570,11 @@ def visit_if_node(node)
end
end

sig { override.params(node: Prism::InstanceVariableTargetNode).void }
def visit_instance_variable_target_node(node)
@current_block.instructions << node
end

sig { override.params(node: Prism::LocalVariableReadNode).void }
def visit_local_variable_read_node(node)
@current_block.instructions << node
Expand Down Expand Up @@ -627,6 +638,11 @@ def visit_singleton_class_node(node)
@current_block.instructions << node
end

sig { override.params(node: Prism::SplatNode).void }
def visit_splat_node(node)
@current_block.instructions << node
end

sig { override.params(node: Prism::TrueNode).void }
def visit_true_node(node)
@current_block.instructions << node
Expand Down
1 change: 1 addition & 0 deletions sorbet/config
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
.
--ignore=vendor/
--ignore=test/spoom/cfg/fixtures
--ignore=test/spoom/cfg_sorbet
--enable-experimental-requires-ancestor
18 changes: 14 additions & 4 deletions test.rb
Original file line number Diff line number Diff line change
@@ -1,7 +1,17 @@
# typed: true
# frozen_string_literal: true
# typed: true

begin
rescue MyException.new.class => e
puts e
class C
def test(x)
begin
true
rescue
begin
false
rescue
raise if x
true
end
end
end
end
17 changes: 17 additions & 0 deletions test/spoom/cfg/fixtures/begin_rescue_call.cfg
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
cfg: <main>

bb#0
-> bb#2
-> bb#3

bb#2
<self>.puts("inside")
-> bb#1

bb#3
<self>.foo()
ex
<self>.puts("rescue")
-> bb#1

bb#1
5 changes: 5 additions & 0 deletions test/spoom/cfg/fixtures/begin_rescue_call.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
begin
puts "inside"
rescue foo => ex
puts "rescue"
end
16 changes: 16 additions & 0 deletions test/spoom/cfg/fixtures/begin_rescue_instance_var.cfg
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
cfg: <main>

bb#0
-> bb#2
-> bb#3

bb#2
<self>.puts("inside")
-> bb#1

bb#3
@ex
<self>.puts("rescue")
-> bb#1

bb#1
5 changes: 5 additions & 0 deletions test/spoom/cfg/fixtures/begin_rescue_instance_var.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
begin
puts "inside"
rescue => @ex
puts "rescue"
end
20 changes: 20 additions & 0 deletions test/spoom/cfg/fixtures/begin_rescue_return.cfg
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
cfg: <main>

bb#0
-> bb#2
-> bb#4
-> bb#6

bb#2
return
-> bb#1

bb#4
return
-> bb#1

bb#6
return
-> bb#1

bb#1
9 changes: 9 additions & 0 deletions test/spoom/cfg/fixtures/begin_rescue_return.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
begin
return
rescue
return
rescue
return
end

puts "after"
17 changes: 17 additions & 0 deletions test/spoom/cfg/fixtures/begin_rescue_splat.cfg
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
cfg: <main>

bb#0
-> bb#2
-> bb#3

bb#2
<self>.meth()
-> bb#1

bb#3
*untyped_exceptions
e
T.reveal_type(e)
-> bb#1

bb#1
5 changes: 5 additions & 0 deletions test/spoom/cfg/fixtures/begin_rescue_splat.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
begin
meth
rescue *untyped_exceptions => e
T.reveal_type(e) # error: Revealed type: `Exception`
end
16 changes: 16 additions & 0 deletions test/spoom/cfg/fixtures/begin_rescue_var.cfg
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
cfg: <main>

bb#0
-> bb#2
-> bb#3

bb#2
<self>.puts("inside")
-> bb#1

bb#3
ex
<self>.puts("rescue")
-> bb#1

bb#1
5 changes: 5 additions & 0 deletions test/spoom/cfg/fixtures/begin_rescue_var.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
begin
puts "inside"
rescue => ex
puts "rescue"
end
28 changes: 28 additions & 0 deletions test/spoom/cfg/fixtures/def_rescue.cfg
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
cfg: <main>

bb#0
def foo
-> bb#1

bb#1

cfg: foo

bb#0
-> bb#2
-> bb#3
-> bb#4

bb#2
<self>.puts("body")
-> bb#1

bb#3
<self>.puts("rescue1")
-> bb#1

bb#4
<self>.puts("rescue2")
-> bb#1

bb#1
7 changes: 7 additions & 0 deletions test/spoom/cfg/fixtures/def_rescue.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
def foo
puts "body"
rescue
puts "rescue1"
rescue
puts "rescue2"
end
26 changes: 26 additions & 0 deletions test/spoom/cfg/fixtures/def_rescue_multiple_classes.cfg
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
cfg: <main>

bb#0
def multiple_rescue_classes
-> bb#1

bb#1

cfg: multiple_rescue_classes

bb#0
-> bb#2
-> bb#3

bb#2
<self>.putts("body")
-> bb#1

bb#3
Foo
Bar
baz
<self>.putts("rescue")
-> bb#1

bb#1
5 changes: 5 additions & 0 deletions test/spoom/cfg/fixtures/def_rescue_multiple_classes.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
def multiple_rescue_classes
putts "body"
rescue Foo, Bar => baz
putts "rescue"
end
11 changes: 7 additions & 4 deletions test/spoom/cfg/fixtures_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -24,27 +24,30 @@ class CFGFixturesTest < Minitest::Test

actual_output = cfgs_cluster.inspect

if ENV["CFG_SHOW"]
if ENV["SHOW"]
puts file
puts
puts actual_output
cfgs_cluster.show_dot
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"]
if ENV["UPDATE"]
File.write(expected_path, actual_output)
else
assert(File.exist?(expected_path), "expectation file missing for #{file}")
expected_output = File.read(expected_path)

unless expected_output == actual_output
raise <<~MSG
CFG expectation failed
#{file}
#{diff(expected_output, actual_output)}
#{expected_path}
MSG
end
end
Expand Down
57 changes: 0 additions & 57 deletions test/spoom/cfg_sorbet/override_bang.rb

This file was deleted.

7 changes: 0 additions & 7 deletions test/spoom/cfg_sorbet/rescue_bad_class.rb

This file was deleted.

Loading

0 comments on commit 026c7ba

Please sign in to comment.