Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
…nto update_run_method

# Conflicts:
#	lib/xcov/version.rb
  • Loading branch information
lonnyantunes committed Apr 15, 2020
2 parents 0aecaf0 + e513842 commit 360953f
Show file tree
Hide file tree
Showing 7 changed files with 69 additions and 24 deletions.
Binary file modified lib/xcov-core/bin/xcov-core
Binary file not shown.
2 changes: 1 addition & 1 deletion lib/xcov-core/version.rb
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
module Xcov
module Core
VERSION = "0.7"
VERSION = "0.8"
end
end
69 changes: 54 additions & 15 deletions lib/xcov/manager.rb
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,11 @@ def run
end

def parse_xccoverage
xccoverage_files = []

# xcresults to parse and export after collecting
xcresults_to_parse_and_export = []

# Find .xccoverage file
# If no xccov direct path, use the old derived data path method
if xccov_file_direct_paths.nil?
Expand All @@ -50,17 +55,36 @@ def parse_xccoverage
if xccoverage_files.empty?
xcresult_paths = Dir["#{test_logs_path}*.xcresult"].sort_by { |filename| File.mtime(filename) }.reverse
xcresult_paths.each do |xcresult_path|
xccoverage_files += export_paths_from_xcresult!(xcresult_path)
xcresults_to_parse_and_export << xcresult_path
end
end

unless test_logs_path.directory? && !xccoverage_files.empty?
unless test_logs_path.directory?
ErrorHandler.handle_error("XccoverageFileNotFound")
end
else
xccoverage_files = xccov_file_direct_paths
# Iterate over direct paths and find .xcresult files
# that need to be processed before getting coverage
xccov_file_direct_paths.each do |path|
if File.extname(path) == '.xcresult'
xcresults_to_parse_and_export << path
else
xccoverage_files << path
end
end
end

# Iterates over xcresults
# Exports .xccovarchives
# Exports .xccovreports and collects the paths
unless xcresults_to_parse_and_export.empty?
xccoverage_files = process_xcresults!(xcresults_to_parse_and_export)
end

# Errors if no coverage files were found
if xccoverage_files.empty?
ErrorHandler.handle_error("XccoverageFileNotFound")
end

# Convert .xccoverage file to json
ide_foundation_path = Xcov.config[:legacy_support] ? nil : Xcov.config[:ideFoundationPath]
Expand Down Expand Up @@ -174,21 +198,36 @@ def xccov_file_direct_paths
end

path = Xcov.config[:xccov_file_direct_path]
if File.extname(path) == '.xcresult'
return export_paths_from_xcresult!(path)
end

return [Pathname.new(path).to_s]
end

def export_paths_from_xcresult!(path)
parser = XCResult::Parser.new(path: path)
return parser.export_xccovreports(destination: Dir.mktmpdir)
rescue
UI.error("Error occured while exporting xccovreport from xcresult '#{path}'")
UI.error("Make sure you have both Xcode 11 selected and pointing to the correct xcresult file")
UI.crash!("Failed to export xccovreport from xcresult'")
end
def process_xcresults!(xcresult_paths)
output_path = Xcov.config[:output_directory]
FileUtils.mkdir_p(output_path)

return xcresult_paths.flat_map do |xcresult_path|
begin
parser = XCResult::Parser.new(path: xcresult_path)

# Exporting to same directory as xcresult
archive_paths = parser.export_xccovarchives(destination: output_path)
report_paths = parser.export_xccovreports(destination: output_path)

# Informating user of export paths
archive_paths.each do |path|
UI.important("Copying .xccovarchive to #{path}")
end
report_paths.each do |path|
UI.important("Copying .xccovreport to #{path}")
end

report_paths
rescue
UI.error("Error occured while exporting xccovreport from xcresult '#{xcresult_path}'")
UI.error("Make sure you have both Xcode 11 selected and pointing to the correct xcresult file")
UI.crash!("Failed to export xccovreport from xcresult'")
end
end
end
end
end
7 changes: 3 additions & 4 deletions lib/xcov/model/target.rb
Original file line number Diff line number Diff line change
Expand Up @@ -7,10 +7,10 @@ class Target < Xcov::Base
attr_accessor :files
attr_accessor :file_templates

def initialize(name, coverage, files)
def initialize(name, files)
@name = CGI::escapeHTML(name)
@files = files
@coverage = coverage
@coverage = files.count == 0 ? 0.0 : files.reduce(0) { |acc, file| acc + file.coverage.to_f } / files.count
@displayable_coverage = self.create_displayable_coverage
@coverage_color = self.create_coverage_color
@id = Target.create_id(name)
Expand Down Expand Up @@ -53,12 +53,11 @@ def json_value

def self.map(dictionary)
name = dictionary["name"]
coverage = dictionary["coverage"]
files = dictionary["files"].map { |file| Source.map(file)}
files = files.sort &by_coverage_with_ignored_at_the_end
non_ignored_files = Target.select_non_ignored_files(files)

Target.new(name, coverage, non_ignored_files)
Target.new(name, non_ignored_files)
end

def self.by_coverage_with_ignored_at_the_end
Expand Down
8 changes: 8 additions & 0 deletions lib/xcov/options.rb
Original file line number Diff line number Diff line change
Expand Up @@ -93,6 +93,14 @@ def self.available_options
default_value: File.join(containing, "xcov_report"),
default_value_dynamic: true
),
FastlaneCore::ConfigItem.new(
key: :cloned_source_packages_path,
short_option: "-C",
env_name: "XCOV_CLONED_SOURCE_PACKAGES_PATH",
description: "Sets a custom path for Swift Package Manager dependencies",
type: String,
optional: true
),

# Report options
FastlaneCore::ConfigItem.new(
Expand Down
3 changes: 1 addition & 2 deletions lib/xcov/version.rb
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
module Xcov

VERSION = "1.6.1"

VERSION = "1.7.3"
DESCRIPTION = "xcov is a friendly visualizer for Xcode's code coverage files"

end
4 changes: 2 additions & 2 deletions xcov.gemspec
Original file line number Diff line number Diff line change
Expand Up @@ -21,12 +21,12 @@ Gem::Specification.new do |spec|
spec.test_files = spec.files.grep(%r{^(test|spec|features)/})
spec.require_paths = ["lib"]

spec.add_dependency 'fastlane', '>= 2.82.0', '< 3.0.0'
spec.add_dependency 'fastlane', '>= 2.141.0', '< 3.0.0'
spec.add_dependency 'slack-notifier'
spec.add_dependency 'xcodeproj'
spec.add_dependency 'terminal-table'
spec.add_dependency 'multipart-post'
spec.add_dependency 'xcresult', '~> 0.1.1'
spec.add_dependency 'xcresult', '~> 0.2.0'

# Development only
spec.add_development_dependency "bundler"
Expand Down

0 comments on commit 360953f

Please sign in to comment.