coverage-printer 0.1.0
Sign up to get free protection for your applications and to get access to all the features.
- data/Gemfile +6 -0
- data/Gemfile.lock +16 -0
- data/README +27 -0
- data/Rakefile +28 -0
- data/VERSION +1 -0
- data/coverage-printer.gemspec +62 -0
- data/data/javascripts/coverage.js +0 -0
- data/data/stylesheets/coverage.css +58 -0
- data/data/stylesheets/reset.css +102 -0
- data/data/templates/detail.html.erb +53 -0
- data/data/templates/index.html.erb +43 -0
- data/lib/coverage/html_printer.rb +248 -0
- data/lib/coverage/statistics.rb +31 -0
- data/lib/coverage/utility.rb +5 -0
- data/test/coverage/statistics_test.rb +32 -0
- data/test/test_helper.rb +3 -0
- metadata +93 -0
data/Gemfile
ADDED
data/Gemfile.lock
ADDED
data/README
ADDED
@@ -0,0 +1,27 @@
|
|
1
|
+
= CoveragePrinter
|
2
|
+
|
3
|
+
* https://github.com/okkez/coverage-printer
|
4
|
+
|
5
|
+
== Description
|
6
|
+
|
7
|
+
CoveragePrinter - Format Coverage.result.
|
8
|
+
|
9
|
+
== Install
|
10
|
+
|
11
|
+
$ gem install coverage-printer
|
12
|
+
|
13
|
+
== Usage
|
14
|
+
|
15
|
+
use with test-unit-2.3.0.
|
16
|
+
|
17
|
+
require 'test/unit/coverage'
|
18
|
+
require 'coverage/html_printer'
|
19
|
+
Test::Unit::Coverage.printer = Coverage::HTMLPrinter.new
|
20
|
+
|
21
|
+
== License
|
22
|
+
LGPLv2.1 or later.
|
23
|
+
|
24
|
+
== Authors
|
25
|
+
|
26
|
+
* okkez
|
27
|
+
|
data/Rakefile
ADDED
@@ -0,0 +1,28 @@
|
|
1
|
+
require 'rubygems'
|
2
|
+
require 'bundler'
|
3
|
+
begin
|
4
|
+
Bundler.setup(:default, :development)
|
5
|
+
rescue Bundler::BundlerError => e
|
6
|
+
$stderr.puts e.message
|
7
|
+
$stderr.puts "Run `bundle install` to install missing gems"
|
8
|
+
exit e.status_code
|
9
|
+
end
|
10
|
+
require 'rake'
|
11
|
+
|
12
|
+
require 'jeweler'
|
13
|
+
Jeweler::Tasks.new do |gem|
|
14
|
+
# gem is a Gem::Specification... see http://docs.rubygems.org/read/chapter/20 for more options
|
15
|
+
gem.name = "coverage-printer"
|
16
|
+
gem.homepage = "http://github.com/okkez/coverage-printer"
|
17
|
+
gem.license = "MIT"
|
18
|
+
gem.summary = %Q{This library provides the ability to visualize code coverage for Ruby1.9.}
|
19
|
+
gem.description = %Q{This library provides the ability to visualize code coverage for Ruby1.9.}
|
20
|
+
gem.email = "okkez000@gmail.com"
|
21
|
+
gem.authors = ["okkez"]
|
22
|
+
# Include your dependencies below. Runtime dependencies are required when using your gem,
|
23
|
+
# and development dependencies are only needed for development (ie running rake tasks, tests, etc)
|
24
|
+
# gem.add_runtime_dependency 'jabber4r', '> 0.1'
|
25
|
+
# gem.add_development_dependency 'rspec', '> 1.2.3'
|
26
|
+
gem.required_ruby_version = Gem::Requirement.new(">= 1.9.1")
|
27
|
+
end
|
28
|
+
Jeweler::RubygemsDotOrgTasks.new
|
data/VERSION
ADDED
@@ -0,0 +1 @@
|
|
1
|
+
0.1.0
|
@@ -0,0 +1,62 @@
|
|
1
|
+
# Generated by jeweler
|
2
|
+
# DO NOT EDIT THIS FILE DIRECTLY
|
3
|
+
# Instead, edit Jeweler::Tasks in Rakefile, and run 'rake gemspec'
|
4
|
+
# -*- encoding: utf-8 -*-
|
5
|
+
|
6
|
+
Gem::Specification.new do |s|
|
7
|
+
s.name = %q{coverage-printer}
|
8
|
+
s.version = "0.1.0"
|
9
|
+
|
10
|
+
s.required_rubygems_version = Gem::Requirement.new(">= 0") if s.respond_to? :required_rubygems_version=
|
11
|
+
s.authors = ["okkez"]
|
12
|
+
s.date = %q{2011-04-27}
|
13
|
+
s.description = %q{This library provides the ability to visualize code coverage for Ruby1.9.}
|
14
|
+
s.email = %q{okkez000@gmail.com}
|
15
|
+
s.extra_rdoc_files = [
|
16
|
+
"README"
|
17
|
+
]
|
18
|
+
s.files = [
|
19
|
+
"Gemfile",
|
20
|
+
"Gemfile.lock",
|
21
|
+
"README",
|
22
|
+
"Rakefile",
|
23
|
+
"VERSION",
|
24
|
+
"coverage-printer.gemspec",
|
25
|
+
"data/javascripts/coverage.js",
|
26
|
+
"data/stylesheets/coverage.css",
|
27
|
+
"data/stylesheets/reset.css",
|
28
|
+
"data/templates/detail.html.erb",
|
29
|
+
"data/templates/index.html.erb",
|
30
|
+
"lib/coverage/html_printer.rb",
|
31
|
+
"lib/coverage/statistics.rb",
|
32
|
+
"lib/coverage/utility.rb",
|
33
|
+
"test/coverage/statistics_test.rb",
|
34
|
+
"test/test_helper.rb"
|
35
|
+
]
|
36
|
+
s.homepage = %q{http://github.com/okkez/coverage-printer}
|
37
|
+
s.licenses = ["MIT"]
|
38
|
+
s.require_paths = ["lib"]
|
39
|
+
s.required_ruby_version = Gem::Requirement.new(">= 1.9.1")
|
40
|
+
s.rubygems_version = %q{1.5.2}
|
41
|
+
s.summary = %q{This library provides the ability to visualize code coverage for Ruby1.9.}
|
42
|
+
s.test_files = [
|
43
|
+
"test/coverage/statistics_test.rb",
|
44
|
+
"test/test_helper.rb"
|
45
|
+
]
|
46
|
+
|
47
|
+
if s.respond_to? :specification_version then
|
48
|
+
s.specification_version = 3
|
49
|
+
|
50
|
+
if Gem::Version.new(Gem::VERSION) >= Gem::Version.new('1.2.0') then
|
51
|
+
s.add_development_dependency(%q<bundler>, ["~> 1.0.0"])
|
52
|
+
s.add_development_dependency(%q<jeweler>, ["~> 1.5.2"])
|
53
|
+
else
|
54
|
+
s.add_dependency(%q<bundler>, ["~> 1.0.0"])
|
55
|
+
s.add_dependency(%q<jeweler>, ["~> 1.5.2"])
|
56
|
+
end
|
57
|
+
else
|
58
|
+
s.add_dependency(%q<bundler>, ["~> 1.0.0"])
|
59
|
+
s.add_dependency(%q<jeweler>, ["~> 1.5.2"])
|
60
|
+
end
|
61
|
+
end
|
62
|
+
|
File without changes
|
@@ -0,0 +1,58 @@
|
|
1
|
+
body{font:13px/1.5 'Helvetica Neue',Arial,'Liberation Sans',FreeSans,sans-serif}a:focus{outline:1px dotted}hr{border:0 #ccc solid;border-top-width:1px;clear:both;height:0}h1{font-size:25px}h2{font-size:23px}h3{font-size:21px}h4{font-size:19px}h5{font-size:17px}h6{font-size:15px}ol{list-style:decimal}ul{list-style:disc}li{margin-left:30px}p,dl,hr,h1,h2,h3,h4,h5,h6,ol,ul,pre,table,address,fieldset{margin-bottom:20px}
|
2
|
+
|
3
|
+
body {
|
4
|
+
background-color: #F4F2ED;
|
5
|
+
}
|
6
|
+
|
7
|
+
h1, h2, h3, h4 {
|
8
|
+
margin-left: 2%;
|
9
|
+
}
|
10
|
+
|
11
|
+
table {
|
12
|
+
border: 1px solid #666666;
|
13
|
+
border-collapse: collapse;
|
14
|
+
margin-top: 1em;
|
15
|
+
margin-left: 5%;
|
16
|
+
margin-right: 5%;
|
17
|
+
width: 90%;
|
18
|
+
}
|
19
|
+
|
20
|
+
th, td {
|
21
|
+
border: 1px solid #666666;
|
22
|
+
}
|
23
|
+
|
24
|
+
.covered {
|
25
|
+
background-color: #BED2BE;
|
26
|
+
}
|
27
|
+
|
28
|
+
.not-code {
|
29
|
+
background-color: #E0DEDB;
|
30
|
+
}
|
31
|
+
|
32
|
+
.uncovered {
|
33
|
+
background-color: #CD8A8B;
|
34
|
+
}
|
35
|
+
|
36
|
+
div.code {
|
37
|
+
margin: 2.5% 5% 2.5% 5%;
|
38
|
+
border: 1px solid #666666;
|
39
|
+
}
|
40
|
+
|
41
|
+
div.code > ol {
|
42
|
+
margin: 0% 0% 0% 1%;
|
43
|
+
}
|
44
|
+
|
45
|
+
div.bar-container {
|
46
|
+
border: 1px solid #ccc;
|
47
|
+
width: 100px;
|
48
|
+
margin: 2px 5px 2px 0;
|
49
|
+
padding: 0;
|
50
|
+
float: right;
|
51
|
+
background: #A92730;
|
52
|
+
}
|
53
|
+
|
54
|
+
div.bar-container > div {
|
55
|
+
background-color: #649632;
|
56
|
+
height: 12px;
|
57
|
+
}
|
58
|
+
|
@@ -0,0 +1,102 @@
|
|
1
|
+
/*
|
2
|
+
html5doctor.com Reset Stylesheet
|
3
|
+
v1.6.1
|
4
|
+
Last Updated: 2010-09-17
|
5
|
+
Author: Richard Clark - http://richclarkdesign.com
|
6
|
+
Twitter: @rich_clark
|
7
|
+
*/
|
8
|
+
|
9
|
+
html, body, div, span, object, iframe,
|
10
|
+
h1, h2, h3, h4, h5, h6, p, blockquote, pre,
|
11
|
+
abbr, address, cite, code,
|
12
|
+
del, dfn, em, img, ins, kbd, q, samp,
|
13
|
+
small, strong, sub, sup, var,
|
14
|
+
b, i,
|
15
|
+
dl, dt, dd, ol, ul, li,
|
16
|
+
fieldset, form, label, legend,
|
17
|
+
table, caption, tbody, tfoot, thead, tr, th, td,
|
18
|
+
article, aside, canvas, details, figcaption, figure,
|
19
|
+
footer, header, hgroup, menu, nav, section, summary,
|
20
|
+
time, mark, audio, video {
|
21
|
+
margin:0;
|
22
|
+
padding:0;
|
23
|
+
border:0;
|
24
|
+
outline:0;
|
25
|
+
font-size:100%;
|
26
|
+
vertical-align:baseline;
|
27
|
+
background:transparent;
|
28
|
+
}
|
29
|
+
|
30
|
+
body {
|
31
|
+
line-height:1;
|
32
|
+
}
|
33
|
+
|
34
|
+
article,aside,details,figcaption,figure,
|
35
|
+
footer,header,hgroup,menu,nav,section {
|
36
|
+
display:block;
|
37
|
+
}
|
38
|
+
|
39
|
+
nav ul {
|
40
|
+
list-style:none;
|
41
|
+
}
|
42
|
+
|
43
|
+
blockquote, q {
|
44
|
+
quotes:none;
|
45
|
+
}
|
46
|
+
|
47
|
+
blockquote:before, blockquote:after,
|
48
|
+
q:before, q:after {
|
49
|
+
content:'';
|
50
|
+
content:none;
|
51
|
+
}
|
52
|
+
|
53
|
+
a {
|
54
|
+
margin:0;
|
55
|
+
padding:0;
|
56
|
+
font-size:100%;
|
57
|
+
vertical-align:baseline;
|
58
|
+
background:transparent;
|
59
|
+
}
|
60
|
+
|
61
|
+
/* change colours to suit your needs */
|
62
|
+
ins {
|
63
|
+
background-color:#ff9;
|
64
|
+
color:#000;
|
65
|
+
text-decoration:none;
|
66
|
+
}
|
67
|
+
|
68
|
+
/* change colours to suit your needs */
|
69
|
+
mark {
|
70
|
+
background-color:#ff9;
|
71
|
+
color:#000;
|
72
|
+
font-style:italic;
|
73
|
+
font-weight:bold;
|
74
|
+
}
|
75
|
+
|
76
|
+
del {
|
77
|
+
text-decoration: line-through;
|
78
|
+
}
|
79
|
+
|
80
|
+
abbr[title], dfn[title] {
|
81
|
+
border-bottom:1px dotted;
|
82
|
+
cursor:help;
|
83
|
+
}
|
84
|
+
|
85
|
+
table {
|
86
|
+
border-collapse:collapse;
|
87
|
+
border-spacing:0;
|
88
|
+
}
|
89
|
+
|
90
|
+
/* change border colour to suit your needs */
|
91
|
+
hr {
|
92
|
+
display:block;
|
93
|
+
height:1px;
|
94
|
+
border:0;
|
95
|
+
border-top:1px solid #cccccc;
|
96
|
+
margin:1em 0;
|
97
|
+
padding:0;
|
98
|
+
}
|
99
|
+
|
100
|
+
input, select {
|
101
|
+
vertical-align:middle;
|
102
|
+
}
|
@@ -0,0 +1,53 @@
|
|
1
|
+
<!DOCTYPE html>
|
2
|
+
<html lang="ja">
|
3
|
+
<head>
|
4
|
+
<meta content="text/html; charset=utf-8" http-equiv="Content-Type">
|
5
|
+
<%= stylesheet("reset", erb.filename) %>
|
6
|
+
<%= stylesheet("coverage", erb.filename) %>
|
7
|
+
<title><%= page_title %></title>
|
8
|
+
</head>
|
9
|
+
<body>
|
10
|
+
<h1><%= project_name %> C0 Coverage Information</h1>
|
11
|
+
<h2><%= page_title %></h2>
|
12
|
+
<table>
|
13
|
+
<thead>
|
14
|
+
<tr>
|
15
|
+
<th>Name</th>
|
16
|
+
<th>Total Lines</th>
|
17
|
+
<th>Lines of Code</th>
|
18
|
+
<th>Total Coverage</th>
|
19
|
+
<th>Code Coverage</th>
|
20
|
+
</tr>
|
21
|
+
</thead>
|
22
|
+
<tbody>
|
23
|
+
<tr>
|
24
|
+
<td><%= label %></td>
|
25
|
+
<td><%= total %></td>
|
26
|
+
<td><%= lines_of_code %></td>
|
27
|
+
<td><%= total_coverage %></td>
|
28
|
+
<td><%= code_coverage %></td>
|
29
|
+
</tr>
|
30
|
+
</tbody>
|
31
|
+
</table>
|
32
|
+
|
33
|
+
<h3>Key</h3>
|
34
|
+
|
35
|
+
<div id="key" class="code">
|
36
|
+
<ol>
|
37
|
+
<li class="covered">covered code...</li>
|
38
|
+
<li class="not-code">not code...</li>
|
39
|
+
<li class="uncovered">uncovered code...</li>
|
40
|
+
</ol>
|
41
|
+
</div>
|
42
|
+
|
43
|
+
<h3>Coverage Details</h3>
|
44
|
+
|
45
|
+
<div id="coverage-details" class="code">
|
46
|
+
<ol>
|
47
|
+
<%- each_line do |line| -%>
|
48
|
+
<li class="<%= line.class_name%>"><code><%= line.line %></code></li>
|
49
|
+
<%- end -%>
|
50
|
+
</ol>
|
51
|
+
</div>
|
52
|
+
</body>
|
53
|
+
</html>
|
@@ -0,0 +1,43 @@
|
|
1
|
+
<!DOCTYPE html>
|
2
|
+
<html lang="ja">
|
3
|
+
<head>
|
4
|
+
<meta content="text/html; charset=utf-8" http-equiv="Content-Type">
|
5
|
+
<%= stylesheet("reset", erb.filename) %>
|
6
|
+
<%= stylesheet("coverage", erb.filename) %>
|
7
|
+
<title>C0 Coverage</title>
|
8
|
+
</head>
|
9
|
+
<body>
|
10
|
+
<h1><%= project_name %> C0 Coverage Information</h1>
|
11
|
+
<table>
|
12
|
+
<thead>
|
13
|
+
<tr>
|
14
|
+
<th>Name</th>
|
15
|
+
<th>Total Lines</th>
|
16
|
+
<th>Lines of Code</th>
|
17
|
+
<th>Total Coverage</th>
|
18
|
+
<th>Code Coverage</th>
|
19
|
+
</tr>
|
20
|
+
</thead>
|
21
|
+
<tbody>
|
22
|
+
<%- @files.each do |detail| -%>
|
23
|
+
<tr>
|
24
|
+
<td><%= detail.link %></td>
|
25
|
+
<td><%= detail.total %></td>
|
26
|
+
<td><%= detail.lines_of_code %></td>
|
27
|
+
<td><%= detail.total_coverage %></td>
|
28
|
+
<td><%= detail.code_coverage %></td>
|
29
|
+
</tr>
|
30
|
+
<%- end -%>
|
31
|
+
</tbody>
|
32
|
+
<tfooter>
|
33
|
+
<tr>
|
34
|
+
<td>Total</td>
|
35
|
+
<td><%= total %></td>
|
36
|
+
<td><%= lines_of_code %></td>
|
37
|
+
<td><%= total_coverage %></td>
|
38
|
+
<td><%= code_coverage %></td>
|
39
|
+
</tr>
|
40
|
+
</tfooter>
|
41
|
+
</table>
|
42
|
+
</body>
|
43
|
+
</html>
|
@@ -0,0 +1,248 @@
|
|
1
|
+
require 'coverage'
|
2
|
+
require 'coverage/statistics'
|
3
|
+
require 'fileutils'
|
4
|
+
require 'erb'
|
5
|
+
require 'forwardable'
|
6
|
+
|
7
|
+
module Coverage
|
8
|
+
class HTMLPrinter
|
9
|
+
|
10
|
+
module Utility
|
11
|
+
def stylesheet(name, html_filename)
|
12
|
+
css = output_directory + "#{name}.css"
|
13
|
+
path = css.relative_path_from(Pathname(html_filename).dirname)
|
14
|
+
%Q!<link rel="stylesheet" type="text/css" href="#{path.to_s}"/>!
|
15
|
+
end
|
16
|
+
|
17
|
+
def javascript(name, html_filename)
|
18
|
+
js = output_directory + "#{name}.js"
|
19
|
+
path = js.relative_path_from(Pathname(html_filename).dirname)
|
20
|
+
%Q!<script src="#{path.to_s}"></script>!
|
21
|
+
end
|
22
|
+
|
23
|
+
def coverage_bar(coverage)
|
24
|
+
%Q!<div class="bar-container"><div style="width: #{coverage}%"></div></div>#{coverage}%!
|
25
|
+
end
|
26
|
+
end
|
27
|
+
|
28
|
+
class PathSettings
|
29
|
+
|
30
|
+
attr_reader :output_directory
|
31
|
+
|
32
|
+
def initialize(output_directory)
|
33
|
+
@output_directory = output_directory
|
34
|
+
end
|
35
|
+
|
36
|
+
def base_directory
|
37
|
+
@base_directory ||= Pathname.pwd
|
38
|
+
end
|
39
|
+
|
40
|
+
def lib_base_directory
|
41
|
+
@lib_base_directory ||= Pathname(__FILE__).dirname.parent.parent
|
42
|
+
end
|
43
|
+
|
44
|
+
def templates_directory
|
45
|
+
lib_base_directory + "data/templates"
|
46
|
+
end
|
47
|
+
|
48
|
+
def javascripts_directory
|
49
|
+
lib_base_directory + "data/javascripts"
|
50
|
+
end
|
51
|
+
|
52
|
+
def stylesheets_directory
|
53
|
+
lib_base_directory + "data/stylesheets"
|
54
|
+
end
|
55
|
+
end
|
56
|
+
|
57
|
+
extend Forwardable
|
58
|
+
|
59
|
+
attr_accessor :output_directory, :project_name
|
60
|
+
def_delegators(:@path_settings, :base_directory, :lib_base_directory, :output_directory,
|
61
|
+
:templates_directory, :javascripts_directory, :stylesheets_directory)
|
62
|
+
|
63
|
+
def initialize
|
64
|
+
yield self if block_given?
|
65
|
+
output_directory ||= Pathname.pwd + "coverage"
|
66
|
+
@path_settings = PathSettings.new(output_directory)
|
67
|
+
FileUtils.mkdir_p(output_directory)
|
68
|
+
@project_name ||= base_directory.basename
|
69
|
+
end
|
70
|
+
|
71
|
+
def print(result)
|
72
|
+
target_files = Dir.glob("#{base_directory}/**/*.rb")
|
73
|
+
statistics_list = []
|
74
|
+
files = []
|
75
|
+
result.each do |path, counts|
|
76
|
+
next unless target_files.include?(path)
|
77
|
+
next if Regexp.new("#{base_directory}/(?:test|spec|vendor)") =~ path
|
78
|
+
files << Detail.new(@path_settings, @project_name, path, counts)
|
79
|
+
end
|
80
|
+
files.sort_by!{|detail| detail.path }
|
81
|
+
files.each(&:print)
|
82
|
+
index = Index.new(@path_settings, @project_name, files)
|
83
|
+
index.print
|
84
|
+
install_files
|
85
|
+
end
|
86
|
+
|
87
|
+
def install_files
|
88
|
+
stylesheets_directory.each_child do |path|
|
89
|
+
FileUtils.install(path, output_directory)
|
90
|
+
end
|
91
|
+
javascripts_directory.each_child do |path|
|
92
|
+
FileUtils.install(path, output_directory)
|
93
|
+
end
|
94
|
+
end
|
95
|
+
|
96
|
+
class Index
|
97
|
+
include Utility
|
98
|
+
|
99
|
+
attr_reader :project_name, :files
|
100
|
+
|
101
|
+
def initialize(path_settings, project_name, files)
|
102
|
+
@path_settings = path_settings
|
103
|
+
@project_name = project_name
|
104
|
+
@files = files
|
105
|
+
end
|
106
|
+
|
107
|
+
def print
|
108
|
+
erb = ERB.new(File.read(template_path), nil, '-')
|
109
|
+
index_path = @path_settings.output_directory + "index.html"
|
110
|
+
erb.filename = index_path.to_s
|
111
|
+
File.open(index_path, "wb+") do |html|
|
112
|
+
html.puts(erb.result(binding))
|
113
|
+
end
|
114
|
+
end
|
115
|
+
|
116
|
+
def total
|
117
|
+
@total ||= @files.inject(0){|memo, detail| memo + detail.total }
|
118
|
+
end
|
119
|
+
|
120
|
+
def lines_of_code
|
121
|
+
@lines_of_code ||= @files.inject(0){|memo, detail| memo + detail.lines_of_code }
|
122
|
+
end
|
123
|
+
|
124
|
+
def lines_of_covered_code
|
125
|
+
@lines_of_covered_code ||= @files.inject(0){|memo, detail| memo + detail.lines_of_covered_code }
|
126
|
+
end
|
127
|
+
|
128
|
+
def total_coverage
|
129
|
+
coverage = "%0.2f" % [(lines_of_covered_code / total.to_f) * 100]
|
130
|
+
coverage_bar(coverage)
|
131
|
+
end
|
132
|
+
|
133
|
+
def code_coverage
|
134
|
+
coverage = "%0.2f" % [(lines_of_covered_code / lines_of_code.to_f) * 100]
|
135
|
+
coverage_bar(coverage)
|
136
|
+
end
|
137
|
+
|
138
|
+
private
|
139
|
+
def template_path
|
140
|
+
@path_settings.templates_directory + "index.html.erb"
|
141
|
+
end
|
142
|
+
|
143
|
+
def output_directory
|
144
|
+
@path_settings.output_directory
|
145
|
+
end
|
146
|
+
end
|
147
|
+
|
148
|
+
class Detail
|
149
|
+
extend Forwardable
|
150
|
+
include Utility
|
151
|
+
|
152
|
+
def_delegators(:@statistics, :total, :lines_of_code, :lines_of_covered_code)
|
153
|
+
attr_reader :project_name, :page_title, :path
|
154
|
+
|
155
|
+
def initialize(path_settings, project_name, path, counts)
|
156
|
+
@path_settings = path_settings
|
157
|
+
@project_name = project_name
|
158
|
+
@path = path
|
159
|
+
@counts = counts
|
160
|
+
@statistics = Coverage::Statistics.new(path, counts)
|
161
|
+
@source = Pathname(path)
|
162
|
+
@page_title = @source.basename
|
163
|
+
@sources = []
|
164
|
+
@source.each_line.with_index.zip(@counts) do |(line, index), count|
|
165
|
+
@sources << Line.new(index + 1, line, count)
|
166
|
+
end
|
167
|
+
end
|
168
|
+
|
169
|
+
def print
|
170
|
+
erb = ERB.new(File.read(template_path), nil, '-')
|
171
|
+
path = @path_settings.output_directory + html_filename
|
172
|
+
erb.filename = path.to_s
|
173
|
+
FileUtils.mkdir_p(path.dirname)
|
174
|
+
File.open(path, "wb+") do |file|
|
175
|
+
file.puts(erb.result(binding))
|
176
|
+
end
|
177
|
+
end
|
178
|
+
|
179
|
+
def each_line
|
180
|
+
@sources.each do |line|
|
181
|
+
yield line
|
182
|
+
end
|
183
|
+
end
|
184
|
+
|
185
|
+
def label
|
186
|
+
@label ||= @source.relative_path_from(@path_settings.output_directory).to_s.sub(/\A\.\.\//, '')
|
187
|
+
end
|
188
|
+
|
189
|
+
def link
|
190
|
+
%Q!<a href="#{html_filename}">#{label}</a>!
|
191
|
+
end
|
192
|
+
|
193
|
+
def html_filename
|
194
|
+
dir = @source.sub(Regexp.new(@path_settings.base_directory.to_s), '.').dirname
|
195
|
+
file = @source.basename.sub(/\.rb/, "_rb.html")
|
196
|
+
dir + file
|
197
|
+
end
|
198
|
+
|
199
|
+
def total_coverage
|
200
|
+
coverage_bar(@statistics.total_coverage)
|
201
|
+
end
|
202
|
+
|
203
|
+
def code_coverage
|
204
|
+
coverage_bar(@statistics.code_coverage)
|
205
|
+
end
|
206
|
+
|
207
|
+
private
|
208
|
+
def template_path
|
209
|
+
@path_settings.templates_directory + "detail.html.erb"
|
210
|
+
end
|
211
|
+
|
212
|
+
def output_directory
|
213
|
+
@path_settings.output_directory
|
214
|
+
end
|
215
|
+
end
|
216
|
+
|
217
|
+
class Line
|
218
|
+
include ERB::Util
|
219
|
+
|
220
|
+
attr_accessor :lineno, :count
|
221
|
+
|
222
|
+
def initialize(lineno, line, count)
|
223
|
+
@lineno = lineno
|
224
|
+
@line = line
|
225
|
+
@count = count
|
226
|
+
end
|
227
|
+
|
228
|
+
def line
|
229
|
+
return "‌\n" if @line.chomp.size == 0
|
230
|
+
h(@line).gsub(/ /, ' ')
|
231
|
+
end
|
232
|
+
|
233
|
+
def class_name
|
234
|
+
case
|
235
|
+
when @count.nil?
|
236
|
+
'not-code'
|
237
|
+
when @count > 0
|
238
|
+
'covered'
|
239
|
+
when @count == 0
|
240
|
+
'uncovered'
|
241
|
+
else
|
242
|
+
raise "must not happen! count=<#{@count}>"
|
243
|
+
end
|
244
|
+
end
|
245
|
+
end
|
246
|
+
end
|
247
|
+
end
|
248
|
+
|
@@ -0,0 +1,31 @@
|
|
1
|
+
module Coverage
|
2
|
+
class Statistics
|
3
|
+
|
4
|
+
attr_reader :path, :counts
|
5
|
+
|
6
|
+
def initialize(path, counts)
|
7
|
+
@path = path
|
8
|
+
@counts = counts
|
9
|
+
end
|
10
|
+
|
11
|
+
def total
|
12
|
+
counts.size
|
13
|
+
end
|
14
|
+
|
15
|
+
def lines_of_code
|
16
|
+
counts.compact.size
|
17
|
+
end
|
18
|
+
|
19
|
+
def total_coverage
|
20
|
+
"%.2f" % [(lines_of_covered_code / total.to_f) * 100]
|
21
|
+
end
|
22
|
+
|
23
|
+
def code_coverage
|
24
|
+
"%.2f" % [(lines_of_covered_code / lines_of_code.to_f) * 100]
|
25
|
+
end
|
26
|
+
|
27
|
+
def lines_of_covered_code
|
28
|
+
counts.select{|count| count && count > 0 }.size
|
29
|
+
end
|
30
|
+
end
|
31
|
+
end
|
@@ -0,0 +1,32 @@
|
|
1
|
+
require 'test_helper'
|
2
|
+
require 'coverage/statistics'
|
3
|
+
|
4
|
+
module Coverage
|
5
|
+
class StatisticsTest < Test::Unit::TestCase
|
6
|
+
|
7
|
+
def setup
|
8
|
+
@statistics = Statistics.new('test.rb',
|
9
|
+
[nil, 1, 0, 1, nil, 0, 1, 0, nil, nil])
|
10
|
+
end
|
11
|
+
|
12
|
+
def test_total
|
13
|
+
assert_equal(10, @statistics.total)
|
14
|
+
end
|
15
|
+
|
16
|
+
def test_lines_of_code
|
17
|
+
assert_equal(6, @statistics.lines_of_code)
|
18
|
+
end
|
19
|
+
|
20
|
+
def test_lines_of_covered_code
|
21
|
+
assert_equal(3, @statistics.lines_of_covered_code)
|
22
|
+
end
|
23
|
+
|
24
|
+
def test_total_coverage
|
25
|
+
assert_equal("30.00", @statistics.total_coverage)
|
26
|
+
end
|
27
|
+
|
28
|
+
def test_code_coverage
|
29
|
+
assert_equal("50.00", @statistics.code_coverage)
|
30
|
+
end
|
31
|
+
end
|
32
|
+
end
|
data/test/test_helper.rb
ADDED
metadata
ADDED
@@ -0,0 +1,93 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: coverage-printer
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
prerelease:
|
5
|
+
version: 0.1.0
|
6
|
+
platform: ruby
|
7
|
+
authors:
|
8
|
+
- okkez
|
9
|
+
autorequire:
|
10
|
+
bindir: bin
|
11
|
+
cert_chain: []
|
12
|
+
|
13
|
+
date: 2011-04-27 00:00:00 +09:00
|
14
|
+
default_executable:
|
15
|
+
dependencies:
|
16
|
+
- !ruby/object:Gem::Dependency
|
17
|
+
name: bundler
|
18
|
+
requirement: &id001 !ruby/object:Gem::Requirement
|
19
|
+
none: false
|
20
|
+
requirements:
|
21
|
+
- - ~>
|
22
|
+
- !ruby/object:Gem::Version
|
23
|
+
version: 1.0.0
|
24
|
+
type: :development
|
25
|
+
prerelease: false
|
26
|
+
version_requirements: *id001
|
27
|
+
- !ruby/object:Gem::Dependency
|
28
|
+
name: jeweler
|
29
|
+
requirement: &id002 !ruby/object:Gem::Requirement
|
30
|
+
none: false
|
31
|
+
requirements:
|
32
|
+
- - ~>
|
33
|
+
- !ruby/object:Gem::Version
|
34
|
+
version: 1.5.2
|
35
|
+
type: :development
|
36
|
+
prerelease: false
|
37
|
+
version_requirements: *id002
|
38
|
+
description: This library provides the ability to visualize code coverage for Ruby1.9.
|
39
|
+
email: okkez000@gmail.com
|
40
|
+
executables: []
|
41
|
+
|
42
|
+
extensions: []
|
43
|
+
|
44
|
+
extra_rdoc_files:
|
45
|
+
- README
|
46
|
+
files:
|
47
|
+
- Gemfile
|
48
|
+
- Gemfile.lock
|
49
|
+
- README
|
50
|
+
- Rakefile
|
51
|
+
- VERSION
|
52
|
+
- coverage-printer.gemspec
|
53
|
+
- data/javascripts/coverage.js
|
54
|
+
- data/stylesheets/coverage.css
|
55
|
+
- data/stylesheets/reset.css
|
56
|
+
- data/templates/detail.html.erb
|
57
|
+
- data/templates/index.html.erb
|
58
|
+
- lib/coverage/html_printer.rb
|
59
|
+
- lib/coverage/statistics.rb
|
60
|
+
- lib/coverage/utility.rb
|
61
|
+
- test/coverage/statistics_test.rb
|
62
|
+
- test/test_helper.rb
|
63
|
+
has_rdoc: true
|
64
|
+
homepage: http://github.com/okkez/coverage-printer
|
65
|
+
licenses:
|
66
|
+
- MIT
|
67
|
+
post_install_message:
|
68
|
+
rdoc_options: []
|
69
|
+
|
70
|
+
require_paths:
|
71
|
+
- lib
|
72
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
73
|
+
none: false
|
74
|
+
requirements:
|
75
|
+
- - ">="
|
76
|
+
- !ruby/object:Gem::Version
|
77
|
+
version: 1.9.1
|
78
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
79
|
+
none: false
|
80
|
+
requirements:
|
81
|
+
- - ">="
|
82
|
+
- !ruby/object:Gem::Version
|
83
|
+
version: "0"
|
84
|
+
requirements: []
|
85
|
+
|
86
|
+
rubyforge_project:
|
87
|
+
rubygems_version: 1.5.2
|
88
|
+
signing_key:
|
89
|
+
specification_version: 3
|
90
|
+
summary: This library provides the ability to visualize code coverage for Ruby1.9.
|
91
|
+
test_files:
|
92
|
+
- test/coverage/statistics_test.rb
|
93
|
+
- test/test_helper.rb
|