Skip to content

Commit

Permalink
Merge branch 'feature-temp-profdata' of https://github.com/viteinfini…
Browse files Browse the repository at this point in the history
…te/slather into feature-temp-profdata

* 'feature-temp-profdata' of https://github.com/viteinfinite/slather:
  Remove useless file
  Fix tests
  Remove useless files
  Fix unit tests
  Add more precise path handling
  Add scheme and ignore
  Export coverage base info into modules
  Fix coveralls_spec
  Minor fixes in spec_helper
  Re-add coveralls support
  Re-add coveralls support
  Add tests
  [WIP] Refactor interface of coverage_file
  [WIP] Add unit tests
  [WIP] Add experimental support to swift
  • Loading branch information
viteinfinite committed Jun 21, 2015
1 parent b1de838 commit 0c7877a
Show file tree
Hide file tree
Showing 13 changed files with 69 additions and 40 deletions.
14 changes: 9 additions & 5 deletions lib/slather/coverage_file.rb
Original file line number Diff line number Diff line change
Expand Up @@ -68,8 +68,13 @@ def all_lines
end
end

def line_number_in_line(line)
line.split(':')[1].strip.to_i
def cleaned_gcov_data
data = gcov_data.encode('UTF-8', 'binary', invalid: :replace, undef: :replace, replace: '').gsub(/^function(.*) called [0-9]+ returned [0-9]+% blocks executed(.*)$\r?\n/, '')
data.gsub(/^branch(.*)$\r?\n/, '')
end

def raw_data
self.gcov_data
end

def line_coverage_data
Expand All @@ -84,9 +89,8 @@ def line_coverage_data
end
end

def cleaned_gcov_data
data = gcov_data.encode('UTF-8', 'binary', invalid: :replace, undef: :replace, replace: '').gsub(/^function(.*) called [0-9]+ returned [0-9]+% blocks executed(.*)$\r?\n/, '')
data.gsub(/^branch(.*)$\r?\n/, '')
def line_number_in_line(line)
line.split(':')[1].strip.to_i
end

def coverage_for_line(line)
Expand Down
12 changes: 6 additions & 6 deletions lib/slather/coverage_service/gutter_json_output.rb
Original file line number Diff line number Diff line change
Expand Up @@ -16,24 +16,24 @@ def post
symbols = {}

coverage_files.each do |coverage_file|
next unless coverage_file.gcov_data
next unless coverage_file.raw_data

filename = coverage_file.source_file_pathname.to_s
filename = filename.sub(Pathname.pwd.to_s, '').reverse.chomp("/").reverse

coverage_file.all_lines.each do |line|
data = line.split(':')

line_number = data[1].to_i
line_number = coverage_file.line_number_in_line(line)
next unless line_number > 0

coverage = data[0].strip
coverage = coverage_file.coverage_for_line(line)
short_text = coverage != nil ? coverage.to_s : "-"

symbol = { 'line' => line_number,
'long_text' => '',
'short_text' => coverage }
'short_text' => short_text }

if coverage != '-'
if coverage != nil
symbol['background_color'] = coverage.to_i > 0 ? '0x35CC4B' : '0xFC635E'
end

Expand Down
2 changes: 1 addition & 1 deletion lib/slather/coverage_service/hardcover.rb
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ module CoverageService
module Hardcover

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

Expand Down
4 changes: 4 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 raw_data
self.source
end

def line_number_in_line(line)
line =~ /^(\s*)(\d*)\|(\s*)(\d+)\|/
if $4 != nil
Expand Down
2 changes: 1 addition & 1 deletion lib/slather/project.rb
Original file line number Diff line number Diff line change
Expand Up @@ -68,7 +68,7 @@ def profdata_coverage_files
files.map do |source|
coverage_file = coverage_file_class.new(self, source)
!coverage_file.ignored? ? coverage_file : nil
end
end.compact
end
private :profdata_coverage_files

Expand Down
8 changes: 3 additions & 5 deletions spec/fixtures/cobertura.xml
Original file line number Diff line number Diff line change
@@ -1,16 +1,15 @@
<?xml version="1.0"?>
<!DOCTYPE coverage SYSTEM "http://cobertura.sourceforge.net/xml/coverage-04.dtd">
<coverage line-rate="0.6603773584905660" branch-rate="0.1190476190476190" lines-covered="35" lines-valid="53" branches-covered="5" branches-valid="42" complexity="0.0" timestamp="1428118535" version="Slather 1.6.0">
<coverage line-rate="0.6666666666666666" branch-rate="0.1190476190476190" lines-covered="34" lines-valid="51" branches-covered="5" branches-valid="42" complexity="0.0" timestamp="1428118535" version="Slather 1.6.0">
<sources>
<source>/Users/marklarsen/programming/slather</source>
</sources>
<packages>
<package name="spec.fixtures.fixtures.more_files" line-rate="0.3846153846153846" branch-rate="0.3333333333333333" complexity="0.0">
<package name="spec.fixtures.fixtures.more_files" line-rate="0.3750000000000000" branch-rate="0.3333333333333333" complexity="0.0">
<classes>
<class name="Branches" filename="spec/fixtures/fixtures/more_files/Branches.m" line-rate="0.5000000000000000" branch-rate="0.4000000000000000" complexity="0.0">
<class name="Branches" filename="spec/fixtures/fixtures/more_files/Branches.m" line-rate="0.4736842105263158" branch-rate="0.4000000000000000" complexity="0.0">
<methods/>
<lines>
<line number="13" branch="false" hits="2"/>
<line number="15" branch="true" hits="2" condition-coverage="100% (2/2)">
<conditions>
<condition number="0" type="jump" coverage="100%"/>
Expand Down Expand Up @@ -55,7 +54,6 @@
<class name="peekaview" filename="spec/fixtures/fixtures/more_files/peekaview.m" line-rate="0.0000000000000000" branch-rate="0.0000000000000000" complexity="0.0">
<methods/>
<lines>
<line number="13" branch="false" hits="0"/>
<line number="15" branch="false" hits="0"/>
<line number="16" branch="true" hits="0" condition-coverage="0% (0/2)">
<conditions>
Expand Down
15 changes: 15 additions & 0 deletions spec/fixtures/fixtures/Fixtures.swift
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@

import UIKit

@UIApplicationMain
class AppDelegate: UIResponder, UIApplicationDelegate {

var window: UIWindow?

func application(application: UIApplication, didFinishLaunchingWithOptions launchOptions: [NSObject: AnyObject]?) -> Bool {
return true
}

func applicationWillResignActive(application: UIApplication) {
}
}
2 changes: 1 addition & 1 deletion spec/fixtures/gutter.json

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion spec/slather/coverage_service/coveralls_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@

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

Expand Down
2 changes: 1 addition & 1 deletion spec/slather/coverage_service/hardcover_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@

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

Expand Down
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 @@ -16,16 +16,16 @@
describe '#post' do
it "should print out the coverage for each file, and then total coverage" do
["spec/fixtures/fixtures/fixtures.m: 2 of 4 lines (50.00%)",
"spec/fixtures/fixtures/more_files/peekaview.m: 0 of 6 lines (0.00%)",
"spec/fixtures/fixtures/more_files/peekaview.m: 0 of 5 lines (0.00%)",
"spec/fixtures/fixtures/fixtures_cpp.cpp: 0 of 0 lines (100.00%)",
"spec/fixtures/fixtures/fixtures_mm.mm: 0 of 0 lines (100.00%)",
"spec/fixtures/fixtures/fixtures_m.m: 0 of 0 lines (100.00%)",
"spec/fixtures/fixtures/more_files/Branches.m: 10 of 20 lines (50.00%)",
"spec/fixtures/fixtures/more_files/Branches.m: 9 of 19 lines (47.37%)",
"spec/fixtures/fixtures/more_files/Empty.m: 0 of 0 lines (100.00%)",
"spec/fixtures/fixturesTests/fixturesTests.m: 7 of 7 lines (100.00%)",
"spec/fixtures/fixturesTests/peekaviewTests.m: 6 of 6 lines (100.00%)",
"spec/fixtures/fixturesTests/BranchesTests.m: 10 of 10 lines (100.00%)",
"Test Coverage: 66.04%"].each do |line|
"Test Coverage: 66.67%"].each do |line|
expect(fixtures_project).to receive(:puts).with(line)
end

Expand Down
39 changes: 23 additions & 16 deletions spec/slather/project_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -89,29 +89,36 @@ class SpecXcode7CoverageFile < Slather::ProfdataCoverageFile
before(:each) do
Dir.stub(:[]).and_call_original
Dir.stub(:[]).with("#{fixtures_project.build_directory}/**/Coverage.profdata").and_return(["/some/path/Coverage.profdata"])
fixtures_project.stub(:profdata_llvm_cov_output).and_return("/Users/venmo/ExampleProject/AppDelegate.swift:
| 8|
| 9|import UIKit
| 10|
| 11|@UIApplicationMain
| 12|class AppDelegate: UIResponder, UIApplicationDelegate {
| 13|
| 14| var window: UIWindow?
| 16|
1| 17| func application(application: UIApplication, didFinishLaunchingWithOptions launchOptions: [NSObject: AnyObject]?) -> Bool {
1| 19| return true
1| 20| }
| 21|
0| 22| func applicationWillResignActive(application: UIApplication) {
0| 25| }")
fixtures_project.stub(:profdata_llvm_cov_output).and_return("#{FIXTURES_SWIFT_FILE_PATH}:
| 0|
| 1|import UIKit
| 2|
| 3|@UIApplicationMain
| 4|class AppDelegate: UIResponder, UIApplicationDelegate {
| 5|
| 6| var window: UIWindow?
| 7|
1| 8| func application(application: UIApplication, didFinishLaunchingWithOptions launchOptions: [NSObject: AnyObject]?) -> Bool {
1| 9| return true
1| 10| }
| 11|
0| 12| func applicationWillResignActive(application: UIApplication) {
0| 13| }
0| 14|}")
fixtures_project.stub(:coverage_file_class).and_return(SpecXcode7CoverageFile)
fixtures_project.stub(:ignore_list).and_return([])
end

it "should return Coverage.profdata file objects" do
profdata_coverage_files = fixtures_project.send(:profdata_coverage_files)
profdata_coverage_files.each { |cf| expect(cf.kind_of?(SpecXcode7CoverageFile)).to be_truthy }
expect(profdata_coverage_files.map { |cf| cf.source_file_pathname.basename.to_s }).to eq(["AppDelegate.swift"])
expect(profdata_coverage_files.map { |cf| cf.source_file_pathname.basename.to_s }).to eq(["Fixtures.swift"])
end

it "should ignore files from the ignore list" do
fixtures_project.stub(:ignore_list).and_return(["**/Fixtures.swift"])
profdata_coverage_files = fixtures_project.send(:profdata_coverage_files)
expect(profdata_coverage_files.count).to eq(0)
end
end

Expand Down
1 change: 1 addition & 0 deletions spec/spec_helper.rb
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@
FIXTURES_XML_PATH = File.join(File.dirname(__FILE__), 'fixtures/cobertura.xml')
FIXTURES_JSON_PATH = File.join(File.dirname(__FILE__), 'fixtures/gutter.json')
FIXTURES_PROJECT_PATH = File.join(File.dirname(__FILE__), 'fixtures/fixtures.xcodeproj')
FIXTURES_SWIFT_FILE_PATH = File.join(File.dirname(__FILE__), 'fixtures/fixtures/Fixtures.swift')

RSpec.configure do |config|
config.before(:suite) do
Expand Down

0 comments on commit 0c7877a

Please sign in to comment.