<commit_before>require 'simplecov'
require 'json'

class SimpleCov::Formatter::JSONFormatter
  # based on https://github.com/vicentllongo/simplecov-json

  def format(result)
    groups = {}
    result.groups.each do |name,file_list|
      groups[name] = {
        lines: {
            total: file_list.lines_of_code,
          covered: file_list.covered_lines,
           missed: file_list.missed_lines,
        },
        branches: {
            total: file_list.total_branches,
          covered: file_list.covered_branches,
           missed: file_list.missed_branches,
        }
      }
    end
    data = {
      timestamp: result.created_at.to_i,
      command_name: result.command_name,
      groups: groups,
    }
    File.open(output_filepath, "w+") do |file|
      file.print(JSON.pretty_generate(data))
    end
    puts output_message(result)
    data.to_json
  end

  def output_filepath
    File.join(output_path, output_filename)
  end

  def output_filename
    'coverage.json'
  end

  def output_message(result)
    "Coverage report generated for #{result.command_name} to #{output_filepath}. #{result.covered_lines} / #{result.total_lines} LOC (#{result.covered_percent.round(2)}%) covered."
  end

private

  def output_path
    SimpleCov.coverage_path
  end

end<commit_msg>Display SimpleCov version number in test log.<commit_after>require 'simplecov'
require 'json'

class SimpleCov::Formatter::JSONFormatter
  # based on https://github.com/vicentllongo/simplecov-json

  def format(result)
    groups = {}
    result.groups.each do |name,file_list|
      groups[name] = {
        lines: {
            total: file_list.lines_of_code,
          covered: file_list.covered_lines,
           missed: file_list.missed_lines,
        },
        branches: {
            total: file_list.total_branches,
          covered: file_list.covered_branches,
           missed: file_list.missed_branches,
        }
      }
    end
    data = {
      timestamp: result.created_at.to_i,
      command_name: result.command_name,
      groups: groups,
    }
    File.open(output_filepath, "w+") do |file|
      file.print(JSON.pretty_generate(data))
    end
    puts output_message(result)
    puts "SimpleCov version #{version}"
    data.to_json
  end

  def output_filepath
    File.join(output_path, output_filename)
  end

  def output_filename
    'coverage.json'
  end

  def output_message(result)
    "Coverage report generated for #{result.command_name} to #{output_filepath}. #{result.covered_lines} / #{result.total_lines} LOC (#{result.covered_percent.round(2)}%) covered."
  end

private

  def output_path
    SimpleCov.coverage_path
  end

  def version
    SimpleCov::VERSION
  end

end
{'fraction_non_alphanumeric': 0.09830007390983, 'fraction_numerical': 0.0007390983000739098, 'mean_word_length': 2.828854314002829, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 3, 'https://': 2, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '7028499', 'n_tokens_mistral': 875, 'n_tokens_neox': 864, 'n_words': 169}