Module: Trainer::LegacyXCResult::Parser

Defined in:
trainer/lib/trainer/legacy_xcresult.rb

Class Method Summary collapse

Class Method Details

.parse_xcresult(path:, output_remove_retry_attempts: false) ⇒ Object



405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
# File 'trainer/lib/trainer/legacy_xcresult.rb', line 405

def parse_xcresult(path:, output_remove_retry_attempts: false)
  require 'json'

  # Executes xcresulttool to get JSON format of the result bundle object
  # Hotfix: From Xcode 16 beta 3 'xcresulttool get --format json' has been deprecated; '--legacy' flag required to keep on using the command
  xcresulttool_cmd = generate_cmd_parse_xcresult(path)

  result_bundle_object_raw = execute_cmd(xcresulttool_cmd)
  result_bundle_object = JSON.parse(result_bundle_object_raw)

  # Parses JSON into ActionsInvocationRecord to find a list of all ids for ActionTestPlanRunSummaries
  actions_invocation_record = Trainer::LegacyXCResult::ActionsInvocationRecord.new(result_bundle_object)
  test_refs = actions_invocation_record.actions.map do |action|
    action.action_result.tests_ref
  end.compact
  ids = test_refs.map(&:id)

  # Maps ids into ActionTestPlanRunSummaries by executing xcresulttool to get JSON
  # containing specific information for each test summary,
  summaries = ids.map do |id|
    raw = execute_cmd([*xcresulttool_cmd, '--id', id])
    json = JSON.parse(raw)
    Trainer::LegacyXCResult::ActionTestPlanRunSummaries.new(json)
  end

  # Converts the ActionTestPlanRunSummaries to data for junit generator
  failures = actions_invocation_record.issues.test_failure_summaries || []
  summaries_to_data(summaries, failures, output_remove_retry_attempts: output_remove_retry_attempts)
end