Skip to content

Commit

Permalink
Add option to opt into crash trace collection
Browse files Browse the repository at this point in the history
  • Loading branch information
benasher44 committed Jan 20, 2019
1 parent 6267223 commit 102475d
Show file tree
Hide file tree
Showing 3 changed files with 19 additions and 9 deletions.
7 changes: 6 additions & 1 deletion lib/trainer/options.rb
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,12 @@ def self.available_options
env_name: "TRAINER_FAIL_BUILD",
description: "Should this step stop the build if the tests fail? Set this to false if you're handling this with a test reporter",
is_string: false,
default_value: true)
default_value: true),
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
end
Expand Down
19 changes: 12 additions & 7 deletions lib/trainer/test_parser.rb
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,8 @@ class TestParser

attr_accessor :plist_dir

attr_accessor :include_crash_trace

# Returns a hash with the path being the key, and the value
# defining if the tests were successful
def self.auto_convert(config)
Expand Down Expand Up @@ -39,7 +41,7 @@ def self.auto_convert(config)
to_path = path.gsub(".plist", config[:extension])
end

tp = Trainer::TestParser.new(path)
tp = Trainer::TestParser.new(path, config[:include_crash_trace])
File.write(to_path, tp.to_junit)
puts "Successfully generated '#{to_path}'"

Expand All @@ -48,9 +50,10 @@ def self.auto_convert(config)
return_hash
end

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

self.file_content = File.read(path)
Expand Down Expand Up @@ -138,11 +141,13 @@ def parse_content
failure_message: "#{current_failure['Message']} (#{current_failure['FileName']}:#{current_failure['LineNumber']})"
}
end
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(self.plist_dir, 'Attachments', crash_attachment_file)
current_row[:failures].first[:failure_trace] = File.open(crash_attachment_path, &:read)
if self.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(self.plist_dir, 'Attachments', crash_attachment_file)
current_row[:failures].first[:failure_trace] = File.open(crash_attachment_path, &:read)
end
end
end
current_row
Expand Down
2 changes: 1 addition & 1 deletion spec/junit_generator_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@
end

it "includes .crash test attachments" do
tp = Trainer::TestParser.new("spec/fixtures/Test-ShapeSwift.xcresult/TestSummaries.plist")
tp = Trainer::TestParser.new("spec/fixtures/Test-ShapeSwift.xcresult/TestSummaries.plist", true)
junit = File.read("spec/fixtures/Test-ShapeSwift.xcresult/TestSummaries.xml")
expect(tp.to_junit).to eq(junit)
end
Expand Down

0 comments on commit 102475d

Please sign in to comment.