<commit_before>require 'pty'
require 'open3'
require 'fileutils'
require 'terminal-table'

module Xcov
  class Runner
    def run
      parse_xccoverage
      generate_report
    end

    def parse_xccoverage
      command = ""
      prefix_hash = [
        {
          prefix: "Parsing .xccoverage file: "
        }
      ]
      FastlaneCore::CommandExecutor.execute(command: command,
                                          print_all: true,
                                      print_command: true,
                                             prefix: prefix_hash,
                                            loading: "Loading...",
                                              error: proc do |error_output|
                                                begin
                                                  ErrorHandler.handle_build_error(error_output)
                                                rescue => ex
                                                  SlackPoster.new.run({
                                                    build_errors: 1
                                                  })
                                                  raise ex
                                                end
                                              end)
    end<commit_msg>xccoverage file parsing<commit_after>require 'pty'
require 'open3'
require 'fileutils'
require 'tempfile'
require 'terminal-table'
require 'xcov-core'
require 'pathname'

module Xcov
  class Runner
    def run
      parse_xccoverage
      generate_report
    end

    def parse_xccoverage
      product_builds_path = Pathname.new(Xcov.project.default_build_settings(key: "SYMROOT"))
      test_logs_path = product_builds_path.parent.parent + "Logs/Test/"
      xccoverage_files = Dir["#{test_logs_path}*.xccoverage"].sort_by { |filename| File.mtime(filename) }

      unless test_logs_path.directory? && !xccoverage_files.empty?
        ErrorHandler.handle_error("CoverageNotFound")
      end

      report_output = Tempfile.new("report.json")
      command = "#{ENV['XCOV_CORE_LIBRARY_PATH']} -s #{xccoverage_files.first} -o #{report_output.path}"
      prefix_hash = [{ prefix: "Parsing .xccoverage file: " }]

      FastlaneCore::CommandExecutor.execute(command: command,
                                          print_all: true,
                                      print_command: true,
                                             prefix: prefix_hash,
                                            loading: "Loading...",
                                              error: proc do |error_output|
                                                begin
                                                  ErrorHandler.handle_error(error_output)
                                                rescue => ex
                                                  SlackPoster.new.run({
                                                    build_errors: 1
                                                  })
                                                  raise ex
                                                end
                                              end)
    end
{'fraction_non_alphanumeric': 0.06313131313131314, 'fraction_numerical': 0.0012626262626262627, 'mean_word_length': 0.8784825133372851, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 5, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 54, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '4395799', 'n_tokens_mistral': 634, 'n_tokens_neox': 623, 'n_words': 131}