Skip to content

Commit

Permalink
[html] Add working profdata support
Browse files Browse the repository at this point in the history
  • Loading branch information
viteinfinite committed Dec 15, 2015
1 parent 644db09 commit 173e822
Show file tree
Hide file tree
Showing 4 changed files with 62 additions and 2 deletions.
4 changes: 4 additions & 0 deletions lib/slather/coverage_file.rb
Original file line number Diff line number Diff line change
Expand Up @@ -130,6 +130,10 @@ def source_file_basename
File.basename(source_file_pathname, '.m')
end

def line_number_separator
":"
end

def supported_file_extensions
["cpp", "mm", "m"]
end
Expand Down
10 changes: 8 additions & 2 deletions lib/slather/coverage_service/html_output.rb
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,11 @@ module CoverageService
module HtmlOutput

def coverage_file_class
Slather::CoverageFile
if input_format == "profdata"
Slather::ProfdataCoverageFile
else
Slather::CoverageFile
end
end
private :coverage_file_class

Expand Down Expand Up @@ -141,9 +145,11 @@ def create_html_from_file(coverage_file)
next
end

line_number_separator = coverage_file.line_number_separator

cov.table(:class => "source_code") {
cleaned_gcov_lines.each do |line|
data = line.split(':', 3)
data = line.split(line_number_separator, 3)

line_number = data[1].to_i
next unless line_number > 0
Expand Down
8 changes: 8 additions & 0 deletions lib/slather/profdata_coverage_file.rb
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,10 @@ def all_lines
@all_lines
end

def cleaned_gcov_data
source_data
end

def raw_data
self.source
end
Expand Down Expand Up @@ -96,6 +100,10 @@ def source_file_basename
File.basename(source_file_pathname, '.swift')
end

def line_number_separator
"|"
end

def supported_file_extensions
["swift"]
end
Expand Down
42 changes: 42 additions & 0 deletions spec/slather/coverage_service/html_output_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -177,5 +177,47 @@ def extract_cov_data(doc)
expect(Dir.exist?(OUTPUT_DIR_PATH)).to be_truthy
end

it "should create a valid report when using profdata format" do

def extract_filepath(doc)
(path = doc.at_css('h4.cov_filepath'))? path.text : ""
end

fixtures_project.stub(:input_format).and_return("profdata")
fixtures_project.stub(:profdata_llvm_cov_output).and_return("/Users/civetta/Works/Personal/slather/viteinfinite-slather/spec/fixtures/fixtures/other_fixtures.m:
| 1|//
| 2|// other_fixtures.m
| 3|// fixtures
| 4|//
| 5|// Created by Mark Larsen on 6/24/14.
| 6|// Copyright (c) 2014 marklarr. All rights reserved.
| 7|//
| 8|
| 9|#import \"other_fixtures.h\"
| 10|
| 11|@implementation other_fixtures
| 12|
| 13|- (void)testedMethod
1| 14|{
1| 15| NSLog(@\"tested\");
1| 16|}
| 17|
| 18|- (void)untestedMethod
0| 19|{
0| 20| NSLog(@\"untested\");
0| 21|}
| 22|
| 23|@end
")
fixtures_project.post

file = File.open(File.join(OUTPUT_DIR_PATH, "other_fixtures.m.html"))
doc = Nokogiri::HTML(file)
file.close

expect(extract_header_title(doc)).to eq("other_fixtures.m - Slather")
expect(extract_filepath(doc)).to eq("spec/fixtures/fixtures/other_fixtures.m")
end

end
end

0 comments on commit 173e822

Please sign in to comment.