Skip to content

Commit

Permalink
Mark methods called by MiniTest.setup as alive
Browse files Browse the repository at this point in the history
Signed-off-by: Alexandre Terrasa <alexandre.terrasa@shopify.com>
  • Loading branch information
Morriar committed Sep 20, 2023
1 parent 2ed242f commit 799cfc5
Show file tree
Hide file tree
Showing 2 changed files with 27 additions and 0 deletions.
9 changes: 9 additions & 0 deletions lib/spoom/deadcode/plugins/minitest.rb
Expand Up @@ -22,6 +22,15 @@ class Minitest < Base
def on_define_method(indexer, definition)
definition.ignored! if indexer.path.match?(%r{test/.*test\.rb$}) && definition.name.match?(/^test_/)
end

sig { override.params(indexer: Indexer, send: Send).void }
def on_send(indexer, send)
return unless send.recv.nil? && send.name == "setup"

send.each_arg(SyntaxTree::SymbolLiteral) do |arg|
indexer.reference_method(indexer.node_string(arg.value), send.node)
end
end
end
end
end
Expand Down
18 changes: 18 additions & 0 deletions test/spoom/deadcode/plugins/minitest_test.rb
Expand Up @@ -57,6 +57,24 @@ def some_other_test; end
refute_ignored(index, "some_other_test")
end

def test_ignore_minitest_setup_with_symbol
@project.write!("test/foo_test.rb", <<~RB)
class FooTest
setup(:alive1)
setup(:alive2)
def alive1; end
def alive2; end
def dead; 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 799cfc5

Please sign in to comment.