diff --git a/assets/index_report.html.erb b/assets/index_report.html.erb
new file mode 100644
index 0000000..671cdda
--- /dev/null
+++ b/assets/index_report.html.erb
@@ -0,0 +1,134 @@
+
+
+ gcovinator Coverage Report
+
+
+
+ gcovinator Coverage Report
+
+
+ Line Coverage: |
+ <% if @total_lines > 0 %>
+ <%= @covered_lines %> / <%= @total_lines %> = <%= (100.0 * @covered_lines / @total_lines).to_i %>% |
+ <% else %>
+ - |
+ <% end %>
+
+
+ Branch Coverage: |
+ <% if @total_branches > 0 %>
+ <%= @covered_branches %> / <%= @total_branches %> = <%= (100.0 * @covered_branches / @total_branches).to_i %>% |
+ <% else %>
+ - |
+ <% end %>
+
+
+
+
+
+ BC |
+ LC |
+ File |
+
+ <% file_reports.sort_by(&:source_file_name).each_with_index do |file_report, i| %>
+ <% if file_report.total_lines > 0 %>
+ <% if file_report.covered_lines == file_report.total_lines %>
+ <% row_coverage_style = "covered" %>
+ <% else %>
+ <% row_coverage_style = "uncovered" %>
+ <% end %>
+ <% else %>
+ <% row_coverage_style = "normal" %>
+ <% end %>
+ <% evenodd = i & 1 == 0 ? 'even' : 'odd' %>
+
+ <% if file_report.total_branches > 0 %>
+ <% if file_report.covered_branches == file_report.total_branches %>
+ <% branch_coverage_style = "covered-#{evenodd}" %>
+ <% else %>
+ <% branch_coverage_style = "uncovered-#{evenodd}" %>
+ <% end %>
+ <% else %>
+ <% branch_coverage_style = nil %>
+ <% end %>
+
+ <% if file_report.total_branches > 0 %>
+ <%= file_report.covered_branches %> / <%= file_report.total_branches %> = <%= (100.0 * file_report.covered_branches / file_report.total_branches).to_i %>%
+ <% else %>
+ -
+ <% end %>
+ |
+
+ <% if file_report.total_lines > 0 %>
+ <%= file_report.covered_lines %> / <%= file_report.total_lines %> = <%= (100.0 * file_report.covered_lines / file_report.total_lines).to_i %>%
+ <% else %>
+ -
+ <% end %>
+ |
+ <%= file_report.source_file_name %> |
+
+ <% end %>
+
+
+
diff --git a/lib/gcovinator.rb b/lib/gcovinator.rb
index a7c9556..408851b 100644
--- a/lib/gcovinator.rb
+++ b/lib/gcovinator.rb
@@ -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
diff --git a/lib/gcovinator/file_report.rb b/lib/gcovinator/file_report.rb
index 113b8a2..1a14571 100644
--- a/lib/gcovinator/file_report.rb
+++ b/lib/gcovinator/file_report.rb
@@ -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
diff --git a/lib/gcovinator/index_report.rb b/lib/gcovinator/index_report.rb
new file mode 100644
index 0000000..e40d898
--- /dev/null
+++ b/lib/gcovinator/index_report.rb
@@ -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