Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Consider eager loaded code too when detecting dead methods #565

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 5 additions & 1 deletion lib/coverband/utils/dead_methods.rb
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,11 @@ def self.scan(file_path:, coverage:)
end

def self.scan_all
coverage = Coverband.configuration.store.coverage
# If the file was loaded during eager loading and then its code is never executed
# during runtime, then it will not have any runtime coverage. When reporting
# dead methods, we need to look at all the files discovered during the eager loading
# and runtime phases.
coverage = Coverband.configuration.store.get_coverage_report[Coverband::MERGED_TYPE]
coverage.flat_map do |file_path, coverage|
scan(file_path: file_path, coverage: coverage["data"])
end
Expand Down
12 changes: 12 additions & 0 deletions test/coverband/utils/dead_methods_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,18 @@ def test_all_dead_methods
assert_equal(6, dead_method.last_line_number)
end

def test_all_dead_methods_on_runtime
@coverband.eager_loading!
require_unique_file
@coverband.report_coverage
@coverband.runtime!
dead_methods = DeadMethods.scan_all
dead_method = dead_methods.find { |method| method.class_name == :Dog }
assert(dead_method)
assert_equal(4, dead_method.first_line_number)
assert_equal(6, dead_method.last_line_number)
end

def test_output_all
require_unique_file
@coverband.report_coverage
Expand Down