add index page

This commit is contained in:
Josh Holtrop 2017-01-15 15:39:53 -05:00
parent 90bda65e24
commit 571a5d0d30
4 changed files with 179 additions and 0 deletions

View File

@ -0,0 +1,134 @@
<html>
<head>
<title>gcovinator Coverage Report</title>
<style>
body {
margin-left: 0px;
margin-right: 0px;
padding: 0px;
}
h2 {
text-align: center;
}
#overall_table {
margin-left: auto;
margin-right: auto;
}
#overall_table th {
text-align: right;
}
#overall_table td {
padding-left: 1ex;
}
#code_table {
border-collapse: collapse;
margin-left: auto;
margin-right: auto;
}
#code_table th, #code_table td {
margin: 0px;
padding: 0px;
}
#code_table .padded {
padding: 0px 0.5ex;
}
#code_table th {
border-bottom: 1px solid black;
}
table th, table td {
vertical-align: top;
}
.alignright {
text-align: right;
}
.borderright {
border-right: 1px solid black;
}
.normal-odd {
background-color: #bbffff;
}
.normal-even {
background-color: #99ffff;
}
.covered-odd {
background-color: #bbffbb;
}
.covered-even {
background-color: #99ff99;
}
.uncovered-odd {
background-color: #ffbbbb;
}
.uncovered-even {
background-color: #ff9999;
}
</style>
</head>
<body>
<h2>gcovinator Coverage Report</h2>
<table id="overall_table">
<tr>
<th>Line Coverage:</th>
<% if @total_lines > 0 %>
<td><%= @covered_lines %> / <%= @total_lines %> = <%= (100.0 * @covered_lines / @total_lines).to_i %>%</td>
<% else %>
<td>-</td>
<% end %>
</tr>
<tr>
<th>Branch Coverage:</th>
<% if @total_branches > 0 %>
<td><%= @covered_branches %> / <%= @total_branches %> = <%= (100.0 * @covered_branches / @total_branches).to_i %>%</td>
<% else %>
<td>-</td>
<% end %>
</tr>
</table>
<br/>
<table id="code_table">
<tr>
<th><span title="Branch Coverage">BC</span></th>
<th><span title="Line Coverage">LC</th></th>
<th>File</th>
</tr>
<% 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' %>
<tr class="<%= row_coverage_style %>-<%= evenodd %>">
<% 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 %>
<td class="padded alignright borderright <%= branch_coverage_style %>">
<% 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 %>
</td>
<td class="padded alignright borderright">
<% 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 %>
</td>
<td class="padded"><a href="<%= file_report.report_file_name %>"><%= file_report.source_file_name %></a></td>
</tr>
<% end %>
</table>
</body>
</html>

View File

@ -1,6 +1,7 @@
require_relative "gcovinator/file_coverage" require_relative "gcovinator/file_coverage"
require_relative "gcovinator/file_report" require_relative "gcovinator/file_report"
require_relative "gcovinator/gcov_parser" require_relative "gcovinator/gcov_parser"
require_relative "gcovinator/index_report"
require_relative "gcovinator/version" require_relative "gcovinator/version"
require "fileutils" require "fileutils"
require "open3" require "open3"
@ -39,6 +40,7 @@ module Gcovinator
file_reports = file_coverages.each_with_index.map do |(source_file_name, file_coverage), i| 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)) FileReport.new(source_file_name, file_coverage, source_dirs, output_dir, sprintf("s%04d.html", i))
end end
IndexReport.new(output_dir, file_reports)
end end
end end

View File

@ -1,6 +1,13 @@
module Gcovinator module Gcovinator
class FileReport 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) 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) @source_file_name = clean_source_file_name(source_file_name, source_dirs)
@report_file_name = report_file_name @report_file_name = report_file_name

View File

@ -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