class SimpleCov::Formatter::LcovFormatter
Custom Formatter
to generate lcov style coverage for simplecov
Public Class Methods
config() { |config| ... }
click to toggle source
# File lib/simplecov-lcov.rb, line 27 def config @config ||= SimpleCovLcov::Configuration.new yield @config if block_given? @config end
report_with_single_file=(value)
click to toggle source
# File lib/simplecov-lcov.rb, line 33 def report_with_single_file=(value) deprecation_message = \ "#{caller(1..1).first} " \ "`#{LcovFormatter}.report_with_single_file=` is deprecated. " \ "Use `#{LcovFormatter}.config.report_with_single_file=` instead" warn deprecation_message config.report_with_single_file = value end
Public Instance Methods
format(result)
click to toggle source
generate lcov style coverage.
Args¶ ↑
- result
- SimpleCov::Result
-
abcoverage result instance.
# File lib/simplecov-lcov.rb, line 14 def format(result) create_output_directory! if report_with_single_file? write_lcov_to_single_file!(result.files) else result.files.each { |file| write_lcov!(file) } end puts "Lcov style coverage report generated for #{result.command_name} to #{lcov_results_path}" end
Private Instance Methods
create_output_directory!()
click to toggle source
# File lib/simplecov-lcov.rb, line 62 def create_output_directory! return if Dir.exist?(output_directory) FileUtils.mkdir_p(output_directory) end
filtered_branches(file)
click to toggle source
# File lib/simplecov-lcov.rb, line 121 def filtered_branches(file) file.branches.reject(&:skipped?) end
filtered_lines(file)
click to toggle source
# File lib/simplecov-lcov.rb, line 117 def filtered_lines(file) file.lines.reject(&:never?).reject(&:skipped?) end
format_branch(branch, branch_idx)
click to toggle source
# File lib/simplecov-lcov.rb, line 125 def format_branch(branch, branch_idx) taken = branch.coverage == 0 ? '-' : branch.coverage "BRDA:#{branch.report_line},0,#{branch_idx},#{taken}" end
format_branches(file)
click to toggle source
# File lib/simplecov-lcov.rb, line 101 def format_branches(file) branch_idx = 0 filtered_branches(file) .map do |branch| branch_idx += 1 format_branch(branch, branch_idx) end .join("\n") end
format_file(file)
click to toggle source
# File lib/simplecov-lcov.rb, line 84 def format_file(file) filename = file.filename.gsub("#{SimpleCov.root}/", './') pieces = [] pieces << "SF:#{filename}" pieces << format_lines(file) if SimpleCov.branch_coverage? branch_data = format_branches(file) pieces << branch_data if branch_data.length > 0 pieces << "BRF:#{file.total_branches.length}" pieces << "BRH:#{file.covered_branches.length}" end pieces << "end_of_record" pieces << "" pieces.join("\n") end
format_line(line)
click to toggle source
# File lib/simplecov-lcov.rb, line 130 def format_line(line) "DA:#{line.number},#{line.coverage}" end
format_lines(file)
click to toggle source
# File lib/simplecov-lcov.rb, line 111 def format_lines(file) filtered_lines(file) .map { |line| format_line(line) } .join("\n") end
lcov_results_path()
click to toggle source
# File lib/simplecov-lcov.rb, line 50 def lcov_results_path report_with_single_file? ? single_report_path : output_directory end
output_directory()
click to toggle source
# File lib/simplecov-lcov.rb, line 46 def output_directory self.class.config.output_directory end
output_filename(filename)
click to toggle source
# File lib/simplecov-lcov.rb, line 79 def output_filename(filename) filename.gsub("#{SimpleCov.root}/", '').gsub('/', '-') .tap { |name| name << '.lcov' } end
report_with_single_file?()
click to toggle source
# File lib/simplecov-lcov.rb, line 54 def report_with_single_file? self.class.config.report_with_single_file? end
single_report_path()
click to toggle source
# File lib/simplecov-lcov.rb, line 58 def single_report_path self.class.config.single_report_path end
write_lcov!(file)
click to toggle source
# File lib/simplecov-lcov.rb, line 67 def write_lcov!(file) File.open(File.join(output_directory, output_filename(file.filename)), 'w') do |f| f.write format_file(file) end end
write_lcov_to_single_file!(files)
click to toggle source
# File lib/simplecov-lcov.rb, line 73 def write_lcov_to_single_file!(files) File.open(single_report_path, 'w') do |f| files.each { |file| f.write format_file(file) } end end