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

Fixes how profdata_coverage_dir is created. #145

Merged
merged 4 commits into from
Feb 23, 2016
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
4 changes: 4 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,10 @@

## master

* Fixes how `profdata_coverage_dir` is created.
[guidomb](https://github.com/guidomb)
[#145](https://github.com/SlatherOrg/slather/pull/145)

## v2.0.0
* Correct html rendering when using profdata format
[cutz](https://github.com/cutz)
Expand Down
17 changes: 14 additions & 3 deletions lib/slather/project.rb
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,7 @@ def slather_setup_for_coverage(format = :auto)
module Slather
class Project < Xcodeproj::Project

attr_accessor :build_directory, :ignore_list, :ci_service, :coverage_service, :coverage_access_token, :source_directory,
attr_accessor :build_directory, :ignore_list, :ci_service, :coverage_service, :coverage_access_token, :source_directory,
:output_directory, :xcodeproj, :show_html, :verbose_mode, :input_format, :scheme, :binary_file, :binary_basename

alias_method :setup_for_coverage, :slather_setup_for_coverage
Expand Down Expand Up @@ -100,13 +100,24 @@ def profdata_coverage_files
end
private :profdata_coverage_files

def remove_extension(path)
path.split(".")[0..-2].join(".")
end

def first_product_name
first_product = self.products.first
# If name is not available it computes it using
# the path by dropping the 'extension' of the path.
first_product.name || remove_extension(first_product.path)
end

def profdata_coverage_dir
raise StandardError, "The specified build directory (#{self.build_directory}) does not exist" unless File.exists?(self.build_directory)
dir = nil
if self.scheme
dir = Dir["#{build_directory}/**/CodeCoverage/#{self.scheme}"].first
dir = Dir[File.join("#{build_directory}","/**/CodeCoverage/#{self.scheme}")].first
else
dir = Dir["#{build_directory}/**/#{self.products.first.name}"].first
dir = Dir[File.join("#{build_directory}","/**/#{first_product_name}")].first
end

raise StandardError, "No coverage directory found. Are you sure your project is setup for generating coverage files? Try `slather setup your/project.xcodeproj`" unless dir != nil
Expand Down
8 changes: 4 additions & 4 deletions spec/slather/project_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -375,13 +375,13 @@ class SpecXcode7CoverageFile < Slather::ProfdataCoverageFile
expect(fixtures_project).to receive(:coverage_access_token=).with("abc123")
fixtures_project.configure_coverage_access_token
end

it "should set the coverage_access_token if it is in the ENV" do
stub_const('ENV', ENV.to_hash.merge('COVERAGE_ACCESS_TOKEN' => 'asdf456'))
expect(fixtures_project).to receive(:coverage_access_token=).with("asdf456")
fixtures_project.configure_coverage_access_token
end

end

describe "#coverage_service=" do
Expand Down Expand Up @@ -449,8 +449,8 @@ class SpecXcode7CoverageFile < Slather::ProfdataCoverageFile

project_root = Pathname("./").realpath

["\nProcessing coverage file: #{project_root}/spec/DerivedData/Build/Intermediates/CodeCoverage/fixtures/Coverage.profdata",
"Against binary file: #{project_root}/spec/DerivedData/Build/Intermediates/CodeCoverage/fixtures/Products/Debug/fixturesTests.xctest/Contents/MacOS/fixturesTests\n\n"
["\nProcessing coverage file: #{project_root}/spec/DerivedData/libfixtures/Build/Intermediates/CodeCoverage/fixtures/Coverage.profdata",
"Against binary file: #{project_root}/spec/DerivedData/libfixtures/Build/Intermediates/CodeCoverage/fixtures/Products/Debug/fixturesTests.xctest/Contents/MacOS/fixturesTests\n\n"
].each do |line|
expect(fixtures_project).to receive(:puts).with(line)
end
Expand Down
5 changes: 3 additions & 2 deletions spec/spec_helper.rb
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,8 @@
FIXTURES_HTML_FOLDER_PATH = File.join(File.dirname(__FILE__), 'fixtures/fixtures_html')
FIXTURES_PROJECT_PATH = File.join(File.dirname(__FILE__), 'fixtures/fixtures.xcodeproj')
FIXTURES_SWIFT_FILE_PATH = File.join(File.dirname(__FILE__), 'fixtures/fixtures/Fixtures.swift')
TEMP_DERIVED_DATA_PATH = File.join(File.dirname(__FILE__), 'DerivedData/')
TEMP_DERIVED_DATA_PATH = File.join(File.dirname(__FILE__), 'DerivedData')
TEMP_PROJECT_BUILD_PATH = File.join(TEMP_DERIVED_DATA_PATH, "libfixtures")
TEMP_OBJC_GCNO_PATH = File.join(File.dirname(__FILE__), 'fixtures/ObjectiveC.gcno')
TEMP_OBJC_GCDA_PATH = File.join(File.dirname(__FILE__), 'fixtures/ObjectiveC.gcda')

Expand All @@ -39,7 +40,7 @@ def self.delete_temp_gcov_files
config.before(:suite) do
FixtureHelpers.delete_derived_data
FixtureHelpers.delete_temp_gcov_files
`xcodebuild -project "#{FIXTURES_PROJECT_PATH}" -scheme fixtures -configuration Debug -derivedDataPath #{TEMP_DERIVED_DATA_PATH} -enableCodeCoverage YES clean test`
`xcodebuild -project "#{FIXTURES_PROJECT_PATH}" -scheme fixtures -configuration Debug -derivedDataPath #{TEMP_PROJECT_BUILD_PATH} -enableCodeCoverage YES clean test`
end

config.after(:suite) do
Expand Down