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

Dump crash files into test failure messages #27

Closed
Closed
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
1 change: 1 addition & 0 deletions lib/assets/junit.xml.erb
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@
<testcase classname=<%= test[:test_group].encode(:xml => :attr) %> name=<%= test[:name].encode(:xml => :attr) %> time="<%= test[:duration] %>">
<% (test[:failures] || []).each do |failure| %>
<failure message=<%= failure[:failure_message].encode(:xml => :attr) %>>
<%= (failure[:failure_trace] || '').encode(:xml => :text) %>
</failure>
<% end %>
</testcase>
Expand Down
5 changes: 5 additions & 0 deletions lib/trainer/options.rb
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,11 @@ def self.available_options
env_name: "TRAINER_XCPRETTY_NAMING",
description: "Produces class name and test name identical to xcpretty naming in junit file",
is_string: false,
default_value: false),
FastlaneCore::ConfigItem.new(key: :include_crash_trace,
env_name: "TRAINER_INCLUDE_CRASH_TRACE",
description: "If there is a crash associated with a test failure, the contents of the .crash file will be included in the failure text",
is_string: false,
default_value: false)
]
end
Expand Down
13 changes: 11 additions & 2 deletions lib/trainer/test_parser.rb
Original file line number Diff line number Diff line change
Expand Up @@ -48,14 +48,15 @@ def self.auto_convert(config)

def initialize(path, config = {})
path = File.expand_path(path)
plist_dir = File.dirname path
UI.user_error!("File not found at path '#{path}'") unless File.exist?(path)

self.file_content = File.read(path)
self.raw_json = Plist.parse_xml(self.file_content)
return if self.raw_json["FormatVersion"].to_s.length.zero? # maybe that's a useless plist file

ensure_file_valid!
parse_content(config[:xcpretty_naming])
parse_content(plist_dir, config[:xcpretty_naming], config[:include_crash_trace])
end

# Returns the JUnit report as String
Expand Down Expand Up @@ -121,7 +122,7 @@ def test_group_and_name(testable_summary, test, xcpretty_naming)
end

# Convert the Hashes and Arrays in something more useful
def parse_content(xcpretty_naming)
def parse_content(plist_dir, xcpretty_naming, include_crash_trace)
self.data = self.raw_json["TestableSummaries"].collect do |testable_summary|
summary_row = {
project_path: testable_summary["ProjectPath"],
Expand Down Expand Up @@ -149,6 +150,14 @@ def parse_content(xcpretty_naming)
failure_message: "#{current_failure['Message']} (#{current_failure['FileName']}:#{current_failure['LineNumber']})"
}
end
if include_crash_trace
activity_summaries = current_test['ActivitySummaries'] || []
crash_attachment_file = activity_summaries.map { |a| a['DiagnosticReportFileName'] }.compact.find { |f| f.end_with? '.crash' }
unless crash_attachment_file.nil?
crash_attachment_path = File.join(plist_dir, 'Attachments', crash_attachment_file)
current_row[:failures].first[:failure_trace] = File.open(crash_attachment_path, &:read)
end
end
end
current_row
end
Expand Down

Large diffs are not rendered by default.

Loading