Created
June 23, 2019 10:55
-
-
Save digoreis/e72342640987752ceba77c6ec3c696cc to your computer and use it in GitHub Desktop.
xcresult.rb - a simple parse for XCResult
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
require 'plist' | |
require 'ostruct' | |
require 'base64' | |
require 'json' | |
fixedPath = "Test-NewDangerSnapshotting-2019.06.15_19-52-13-+0100.xcresult" | |
class XCResult | |
attr_reader :reference, :tests | |
def initialize(path, reference) | |
@path = path | |
@reference = reference | |
load() | |
end | |
def load() | |
Dir.glob("#{@path}/TestSummaries.plist").each do |filename| | |
result = Plist.parse_xml(filename) | |
@tests = tree_tests(result["TestableSummaries"][0]["Tests"][0]) | |
end | |
end | |
def tree_tests(root) | |
items = [] | |
if root["TestStatus"] | |
return [test_parser(root)] | |
else | |
root["Subtests"].each do |item| | |
items = items + tree_tests(item) | |
end | |
end | |
return items | |
end | |
def test_parser(test) | |
item = OpenStruct.new(test) | |
item.FailureSummaries = failure_summaries_parse(test["FailureSummaries"]) | |
item.ActivitySummaries = activity_summaries_parser(test["ActivitySummaries"]) | |
return item | |
end | |
def failure_summaries_parse(summary) | |
return unless summary | |
return summary.map! { |item| OpenStruct.new(item) } | |
end | |
def activity_summaries_parser(activities) | |
return unless activities | |
activities.map! do |item| | |
newItem = OpenStruct.new(item) | |
newItem.Attachments = attachments_parser(item["Attachments"]) | |
return newItem | |
end | |
end | |
def attachments_parser(attachments) | |
return unless attachments | |
attachments.map! do |item| | |
newItem = OpenStruct.new(item) | |
Dir.glob("#{@path}/Attachments/#{newItem.Filename}").each do |filename| | |
newItem.Data = Base64.encode64(open(filename).to_a.join) | |
end | |
return newItem | |
end | |
end | |
def to_json | |
return {:reference => @reference, :tests => @tests.map!{ |t| t.to_h }}.to_json | |
end | |
end | |
result = XCResult.new(fixedPath, "1") | |
puts result.tests.to_json |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment