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

Handle file not found error #23

Merged
merged 2 commits into from
Sep 4, 2014
Merged
Changes from 1 commit
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
18 changes: 13 additions & 5 deletions lib/slather/coverage_file.rb
Original file line number Diff line number Diff line change
Expand Up @@ -42,8 +42,12 @@ def gcov_data
# Sometimes gcov makes gcov files for Cocoa Touch classes, like NSRange. Ignore and delete later.
gcov_files_created = gcov_output.scan(/creating '(.+\..+\.gcov)'/)

gcov_file = File.new("./#{source_file_pathname.basename}.gcov")
gcov_data = gcov_file.read
gcov_data ||=begin
gcov_file = File.new("./#{source_file_pathname.basename}.gcov")
gcov_file.read
rescue
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Could you rescue the specific exception? Or, better yet, check if File.exist? before reading it instead of letting the exception happen.

nil
end

gcov_files_created.each { |file| FileUtils.rm(file) }

Expand All @@ -52,10 +56,14 @@ def gcov_data
end

def coverage_data
first_line_start = gcov_data =~ /^\s+(-|#+|[0-9+]):\s+1:/
if gcov_data
first_line_start = gcov_data =~ /^\s+(-|#+|[0-9+]):\s+1:/

gcov_data[first_line_start..-1].split("\n").map do |line|
coverage_for_line(line)
gcov_data[first_line_start..-1].split("\n").map do |line|
coverage_for_line(line)
end
else
[]
end
end

Expand Down