Skip to content

Commit

Permalink
Mark methods used in Minitest predicates as alive
Browse files Browse the repository at this point in the history
Signed-off-by: Alexandre Terrasa <[email protected]>
  • Loading branch information
Morriar committed Jul 11, 2024
1 parent ab11ed7 commit b0f50e1
Show file tree
Hide file tree
Showing 2 changed files with 30 additions and 0 deletions.
10 changes: 10 additions & 0 deletions lib/spoom/deadcode/plugins/minitest.rb
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,16 @@ def on_define_method(definition)

@index.ignore(definition) if ignored_subclass?(owner)
end

sig { override.params(send: Send).void }
def on_send(send)
case send.name
when "assert_predicate", "refute_predicate"
name = send.args[1]&.slice
return unless name

@index.reference_method(name.delete_prefix(":"), send.location)
end
end
end
end
Expand Down
20 changes: 20 additions & 0 deletions test/spoom/deadcode/plugins/minitest_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -84,6 +84,26 @@ def some_other_test; end
refute_ignored(index, "some_other_test")
end

def test_ignore_minitest_predicates
@project.write!("test/foo_test.rb", <<~RB)
class FooTest
def alive1; end
def alive2; end
def dead; end
def test_something
assert_predicate(foo, :alive1)
refute_predicate(foo, :alive2)
end
end
RB

index = index_with_plugins
assert_alive(index, "alive1")
assert_alive(index, "alive2")
assert_dead(index, "dead")
end

private

sig { returns(Deadcode::Index) }
Expand Down

0 comments on commit b0f50e1

Please sign in to comment.