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

Refactor to prepare for supporting duplicate gcno files. #14

Merged
merged 2 commits into from
Jun 28, 2014
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
22 changes: 21 additions & 1 deletion lib/slather/coverage_file.rb
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,14 @@ def gcov_data
end
end

def coverage_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)
end
end

def coverage_for_line(line)
line =~ /^(.+?):/

Expand All @@ -65,11 +73,23 @@ def coverage_for_line(line)
end
end

def num_lines_tested
coverage_data.compact.select { |cd| cd > 0 }.count
end

def num_lines_testable
coverage_data.compact.count
end

def percentage_lines_tested
(num_lines_tested / num_lines_testable.to_f) * 100.0
end

def ignored?
project.ignore_list.any? do |ignore|
File.fnmatch(ignore, source_file_pathname_relative_to_repo_root)
end
end

end
end
end
11 changes: 5 additions & 6 deletions lib/slather/coverage_service/simple_output.rb
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ module CoverageService
module SimpleOutput

def coverage_file_class
Slather::CoverallsCoverageFile
Slather::CoverageFile
end
private :coverage_file_class

Expand All @@ -12,11 +12,10 @@ def post
total_project_lines_tested = 0
coverage_files.each do |coverage_file|
# ignore lines that don't count towards coverage (comments, whitespace, etc). These are nil in the array.
coverage_data = coverage_file.coverage_data.compact

lines_tested = coverage_data.select { |cd| cd > 0 }.count
total_lines = coverage_data.count
percentage = '%.2f' % [(lines_tested / total_lines.to_f) * 100.0]
lines_tested = coverage_file.num_lines_tested
total_lines = coverage_file.num_lines_testable
percentage = '%.2f' % [coverage_file.percentage_lines_tested]

total_project_lines_tested += lines_tested
total_project_lines += total_lines
Expand All @@ -29,4 +28,4 @@ def post

end
end
end
end
10 changes: 1 addition & 9 deletions lib/slather/coveralls_coverage_file.rb
Original file line number Diff line number Diff line change
@@ -1,14 +1,6 @@
module Slather
class CoverallsCoverageFile < CoverageFile

def coverage_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)
end
end

def as_json
{
:name => source_file_pathname_relative_to_repo_root.to_s,
Expand All @@ -18,4 +10,4 @@ def as_json
end

end
end
end
20 changes: 19 additions & 1 deletion spec/slather/coverage_file_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -114,5 +114,23 @@
end
end

describe "num_lines_tested" do
it "should return the correct number of lines tested" do
expect(coverage_file.num_lines_tested).to eq(2)
end
end

describe "num_lines_testable" do
it "should return the correct number of lines that are testable" do
expect(coverage_file.num_lines_testable).to eq(4)
end
end

describe "percentage_lines_tested" do
it "should return the correct percentage of lines that are tested" do
expect(coverage_file.percentage_lines_tested).to eq(50)
end
end

end
end
end
6 changes: 3 additions & 3 deletions spec/slather/coverage_service/simple_output_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -8,8 +8,8 @@
end

describe '#coverage_file_class' do
it "should return CoverallsCoverageFile" do
expect(fixtures_project.send(:coverage_file_class)).to eq(Slather::CoverallsCoverageFile)
it "should return CoverageFile" do
expect(fixtures_project.send(:coverage_file_class)).to eq(Slather::CoverageFile)
end
end

Expand All @@ -23,4 +23,4 @@
fixtures_project.post
end
end
end
end