writing a (very ugly) file coverage report

This commit is contained in:
josh committed 2017-01-15 14:19:45 -05:00
1 parent 0422f6f573
commit 1fe35ea23d
3 files changed
+82 -4

No files matched your search

+4 -1
View File
@@ -1,6 +1,9 @@
module Gcovinator
class FileCoverage
attr_reader :line_counts
attr_reader :branches
def initialize
@line_counts = {}
@branches = {}
@@ -25,7 +28,7 @@ module Gcovinator
@branches[line_number][branch_id][:branch_info] = branch_info
end
def get_branch(line_number)
def get_branches(line_number)
@branches[line_number]
end
+18 -3
View File
@@ -8,7 +8,7 @@ module Gcovinator
@covered_lines = 0
@total_branches = 0
@covered_branches = 0
run(source_file_name, File.join(output_dir, report_file_name))
run(source_file_name, File.join(output_dir, report_file_name), file_coverage)
end
private
@@ -23,18 +23,33 @@ module Gcovinator
source_file_name
end
def run(source_file_name, output_file_name)
def run(source_file_name, output_file_name, file_coverage)
analyze(file_coverage)
require "cgi"
require "erb"
source_file = read_source_file(source_file_name)
source_file_lines = source_file.lines.to_a
file_report_template = File.read(File.join(File.dirname(__FILE__), "../../assets/file_report.html.erb"))
erb = ERB.new(file_report_template, nil, "<>")
report = erb.run(binding.clone)
report = erb.result(binding.clone)
File.open(output_file_name, "w") do |fh|
fh.write(report)
end
end
def analyze(file_coverage)
file_coverage.line_counts.each do |line_number, count|
@total_lines += 1
@covered_lines += 1 if count > 0
end
file_coverage.branches.each do |line_number, branches|
branches.each do |branch_id, branch_coverage|
@total_branches += 1
@covered_branches += 1 if branch_coverage[:taken_count] > 0
end
end
end
def read_source_file(source_file_name)
begin
File.read(source_file_name)