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

Prevent divisions by zero #128

Merged
merged 1 commit into from
May 10, 2012
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
1 change: 1 addition & 0 deletions lib/simplecov/result.rb
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,7 @@ def covered_percent

# The multiple of coverage for this result
def covered_strength
return 0 if total_lines.zero?
return @covered_strength if @covered_strength
m = 0
@files.each do |file|
Expand Down
5 changes: 4 additions & 1 deletion lib/simplecov/source_file.rb
Original file line number Diff line number Diff line change
Expand Up @@ -109,7 +109,9 @@ def line(number)
# The coverage for this file in percent. 0 if the file has no relevant lines
def covered_percent
return 100.0 if lines.length == 0 or lines.length == never_lines.count
(covered_lines.count) * 100 / (lines.count - never_lines.count - skipped_lines.count).to_f
relevant_lines = lines.count - never_lines.count - skipped_lines.count
return 0 if relevant_lines == 0
(covered_lines.count) * 100 / relevant_lines.to_f
end

def covered_strength
Expand All @@ -119,6 +121,7 @@ def covered_strength
lines_strength += c.coverage if c.coverage
end
effective_lines_count = (lines.count - never_lines.count - skipped_lines.count).to_f
return 0 if effective_lines_count == 0
strength = lines_strength / effective_lines_count
round_float(strength, 1)
end
Expand Down