brew vendor-gems: commit updates.

This commit is contained in:
BrewTestBot 2020-11-30 07:25:05 +00:00
parent 5b8d563122
commit 3eff3132e4
6 changed files with 170 additions and 1 deletions

View File

@ -19,7 +19,8 @@ $:.unshift "#{path}/../#{ruby_engine}/#{ruby_version}/extensions/universal-darwi
$:.unshift "#{path}/../#{ruby_engine}/#{ruby_version}/gems/json-2.3.1/lib"
$:.unshift "#{path}/../#{ruby_engine}/#{ruby_version}/gems/docile-1.3.2/lib"
$:.unshift "#{path}/../#{ruby_engine}/#{ruby_version}/gems/simplecov-html-0.12.3/lib"
$:.unshift "#{path}/../#{ruby_engine}/#{ruby_version}/gems/simplecov-0.19.1/lib"
$:.unshift "#{path}/../#{ruby_engine}/#{ruby_version}/gems/simplecov_json_formatter-0.1.2/lib"
$:.unshift "#{path}/../#{ruby_engine}/#{ruby_version}/gems/simplecov-0.20.0/lib"
$:.unshift "#{path}/../#{ruby_engine}/#{ruby_version}/gems/codecov-0.2.12/lib"
$:.unshift "#{path}/../#{ruby_engine}/#{ruby_version}/gems/coderay-1.1.3/lib"
$:.unshift "#{path}/../#{ruby_engine}/#{ruby_version}/gems/colorize-0.8.1/lib"

View File

@ -0,0 +1,36 @@
# frozen_string_literal: true
require 'simplecov_json_formatter/result_hash_formatter'
require 'simplecov_json_formatter/result_exporter'
require 'json'
module SimpleCov
module Formatter
class JSONFormatter
def format(result)
result_hash = format_result(result)
export_formatted_result(result_hash)
puts output_message(result)
end
private
def format_result(result)
result_hash_formater = SimpleCovJSONFormatter::ResultHashFormatter.new(result)
result_hash_formater.format
end
def export_formatted_result(result_hash)
result_exporter = SimpleCovJSONFormatter::ResultExporter.new(result_hash)
result_exporter.export
end
def output_message(result)
"JSON Coverage report generated for #{result.command_name} to #{SimpleCov.coverage_path}. \
#{result.covered_lines} / #{result.total_lines} LOC (#{result.covered_percent.round(2)}%) covered."
end
end
end
end

View File

@ -0,0 +1,27 @@
# frozen_string_literal: true
module SimpleCovJSONFormatter
class ResultExporter
FILENAME = 'coverage.json'
def initialize(result_hash)
@result = result_hash
end
def export
File.open(export_path, 'w') do |file|
file << json_result
end
end
private
def json_result
JSON.pretty_generate(@result)
end
def export_path
File.join(SimpleCov.coverage_path, FILENAME)
end
end
end

View File

@ -0,0 +1,36 @@
# frozen_string_literal: true
require 'simplecov_json_formatter/source_file_formatter'
module SimpleCovJSONFormatter
class ResultHashFormatter
def initialize(result)
@result = result
end
def format
@result.files.each do |source_file|
formatted_result[:coverage][source_file.filename] =
format_source_file(source_file)
end
formatted_result
end
private
def formatted_result
@formatted_result ||= {
meta: {
simplecov_version: SimpleCov::VERSION
},
coverage: {}
}
end
def format_source_file(source_file)
source_file_formatter = SourceFileFormatter.new(source_file)
source_file_formatter.format
end
end
end

View File

@ -0,0 +1,64 @@
# frozen_string_literal: true
module SimpleCovJSONFormatter
class SourceFileFormatter
def initialize(source_file)
@source_file = source_file
end
def format
if SimpleCov.branch_coverage?
line_coverage.merge(branch_coverage)
else
line_coverage
end
end
private
def line_coverage
@line_coverage || {
lines: lines
}
end
def branch_coverage
{
branches: branches
}
end
def lines
lines = []
@source_file.lines.each do |line|
lines << parse_line(line)
end
lines
end
def branches
branches = []
@source_file.branches.each do |branch|
branches << parse_branch(branch)
end
branches
end
def parse_line(line)
return line.coverage unless line.skipped?
'ignored'
end
def parse_branch(branch)
{
type: branch.type,
start_line: branch.start_line,
end_line: branch.end_line,
coverage: parse_line(branch)
}
end
end
end

View File

@ -0,0 +1,5 @@
# frozen_string_literal: true
module SimpleCovJSONFormatter
VERSION = '0.1.2'
end