add index page
This commit is contained in:
1 parent
90bda65e24
commit
571a5d0d30
4 files changed
+179
No files matched your search
@@ -1,6 +1,7 @@
|
||||
require_relative "gcovinator/file_coverage"
|
||||
require_relative "gcovinator/file_report"
|
||||
require_relative "gcovinator/gcov_parser"
|
||||
require_relative "gcovinator/index_report"
|
||||
require_relative "gcovinator/version"
|
||||
require "fileutils"
|
||||
require "open3"
|
||||
@@ -39,6 +40,7 @@ module Gcovinator
|
||||
file_reports = file_coverages.each_with_index.map do |(source_file_name, file_coverage), i|
|
||||
FileReport.new(source_file_name, file_coverage, source_dirs, output_dir, sprintf("s%04d.html", i))
|
||||
end
|
||||
IndexReport.new(output_dir, file_reports)
|
||||
end
|
||||
|
||||
end
|
||||
|
||||
@@ -1,6 +1,13 @@
|
||||
module Gcovinator
|
||||
class FileReport
|
||||
|
||||
attr_reader :total_lines
|
||||
attr_reader :covered_lines
|
||||
attr_reader :total_branches
|
||||
attr_reader :covered_branches
|
||||
attr_reader :source_file_name
|
||||
attr_reader :report_file_name
|
||||
|
||||
def initialize(source_file_name, file_coverage, source_dirs, output_dir, report_file_name)
|
||||
@source_file_name = clean_source_file_name(source_file_name, source_dirs)
|
||||
@report_file_name = report_file_name
|
||||
|
||||
@@ -0,0 +1,36 @@
|
||||
module Gcovinator
|
||||
class IndexReport
|
||||
|
||||
def initialize(output_dir, file_reports)
|
||||
@total_lines = 0
|
||||
@covered_lines = 0
|
||||
@total_branches = 0
|
||||
@covered_branches = 0
|
||||
run(File.join(output_dir, "index.html"), file_reports)
|
||||
end
|
||||
|
||||
private
|
||||
|
||||
def run(output_file_name, file_reports)
|
||||
analyze(file_reports)
|
||||
require "cgi"
|
||||
require "erb"
|
||||
index_report_template = File.read(File.join(File.dirname(__FILE__), "../../assets/index_report.html.erb"))
|
||||
erb = ERB.new(index_report_template, nil, "<>")
|
||||
report = erb.result(binding.clone)
|
||||
File.open(output_file_name, "w") do |fh|
|
||||
fh.write(report)
|
||||
end
|
||||
end
|
||||
|
||||
def analyze(file_reports)
|
||||
file_reports.each do |file_report|
|
||||
@total_lines += file_report.total_lines
|
||||
@covered_lines += file_report.covered_lines
|
||||
@total_branches += file_report.total_branches
|
||||
@covered_branches += file_report.covered_branches
|
||||
end
|
||||
end
|
||||
|
||||
end
|
||||
end
|
||||
Reference in new issue
Block a user