##// END OF EJS Templates
Use simplecov for code coverage, rcov does not support ruby>=1.9....
Jean-Philippe Lang -
r13309:c3ba302f0de6
parent child
Show More
@@ -0,0 +1,70
1 # Redmine - project management software
2 # Copyright (C) 2006-2014 Jean-Philippe Lang
3 #
4 # This program is free software; you can redistribute it and/or
5 # modify it under the terms of the GNU General Public License
6 # as published by the Free Software Foundation; either version 2
7 # of the License, or (at your option) any later version.
8 #
9 # This program is distributed in the hope that it will be useful,
10 # but WITHOUT ANY WARRANTY; without even the implied warranty of
11 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 # GNU General Public License for more details.
13 #
14 # You should have received a copy of the GNU General Public License
15 # along with this program; if not, write to the Free Software
16 # Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
17
18 require 'erb'
19 require 'cgi'
20
21 # A simple formatter for SimpleCov
22 module Redmine
23 module Coverage
24 class HtmlFormatter
25 def format(result)
26 File.open(File.join(output_path, "index.html"), "w") do |file|
27 file.puts template('index').result(binding)
28 end
29 result.source_files.each do |source_file|
30 File.open(File.join(output_path, source_file_result(source_file)), "w") do |file|
31 file.puts template('source').result(binding)
32 end
33 end
34 end
35
36 private
37
38 def now
39 @now = Time.now.utc
40 end
41
42 def output_path
43 SimpleCov.coverage_path
44 end
45
46 def shortened_filename(source_file)
47 source_file.filename.gsub(SimpleCov.root, '.').gsub(/^\.\//, '')
48 end
49
50 def link_to_source_file(source_file)
51 %(<a href="#{source_file_result source_file}">#{shortened_filename source_file}</a>)
52 end
53
54 def source_file_result(source_file)
55 shortened_filename(source_file).gsub('/', '__')+'.html'
56 end
57
58 def revision_link
59 if revision = Redmine::VERSION.revision
60 %(<a href="http://www.redmine.org/projects/redmine/repository/revisions/#{revision}">r#{revision}</a>)
61 end
62 end
63
64 # Returns the an erb instance for the template of given name
65 def template(name)
66 ERB.new(File.read(File.join(File.dirname(__FILE__), 'views', "#{name}.erb")))
67 end
68 end
69 end
70 end
@@ -0,0 +1,60
1 <!DOCTYPE html>
2 <head>
3 <meta http-equiv="content-type" content="text/html; charset=utf-8" />
4 <title>Redmine code coverage</title>
5 <style>
6 html {overflow-y:scroll;}
7 body {font-family:"Lucida Grande","Lucida Sans",Verdana,Helvetica,Arial,sans-serif; font-size:80%;}
8 h1 {color:#777; margin-bottom:0.2em;}
9 h2 {color:#aaa;margin-top:1em;font-size:18px;}
10 table {width:100%; border-collapse:collapse;}
11 th, td {border:1px solid #e2e2e2;}
12 td {text-align:right; font-family:"Bitstream Vera Sans Mono","Monaco","Courier New",monospace;}
13 td.filename {text-align:left; font-family:"Lucida Grande","Lucida Sans",Verdana,Helvetica,Arial,sans-serif;}
14 th {background:#e2e2e2;}
15 #generation {color:#777; font-size:90%;}
16 a, a:link, a:visited {color:#169; text-decoration:none;}
17 a:hover, a:active {color:#c61a1a; text-decoration:underline;}
18 div.percent {height:1em; empty-cells:show; padding:0px; border-collapse:collapse; width:100px !important; float:left; margin:0 0.5em 0 0.5em;}
19 div.percent div {float:left; height:1em; padding:0px !important;}
20 div.percent div.covered {background:#8c7;}
21 div.percent div.uncovered {background:#d76;}
22 </style>
23 </head>
24 <body>
25 <h1>Redmine code coverage</h1>
26 <p id='generation'>
27 Generated on <%= now %> (<%= revision_link %>).
28 More information about this environment at <a href='http://www.redmine.org/projects/redmine/wiki/Continuous_integration'>redmine.org</a>.
29 </p>
30
31 <table class="file_list">
32 <thead>
33 <tr>
34 <th>File</th>
35 <th colspan="2">% covered</th>
36 <th>Lines</th>
37 <th>Relevant</th>
38 <th>Covered</th>
39 </tr>
40 </thead>
41 <tbody>
42 <% result.source_files.each do |source_file| %>
43 <tr>
44 <td class="filename"><%= link_to_source_file(source_file) %></td>
45 <td><%= "%.1f" % source_file.covered_percent %> %</td>
46 <td>
47 <div class="percent">
48 <div class="covered" style="width:<%= source_file.covered_percent.to_i %>px"></div>
49 <div class="uncovered" style="width:<%= 100 - source_file.covered_percent.to_i %>px"></div>
50 </div>
51 </td>
52 <td><%= source_file.lines.count %></td>
53 <td><%= source_file.covered_lines.count + source_file.missed_lines.count %></td>
54 <td><%= source_file.covered_lines.count %></td>
55 </tr>
56 <% end %>
57 </tbody>
58 </table>
59 </body>
60 </html>
@@ -0,0 +1,41
1 <!DOCTYPE html>
2 <head>
3 <meta http-equiv="content-type" content="text/html; charset=utf-8" />
4 <title>Redmine code coverage</title>
5 <style>
6 html {overflow-y:scroll;}
7 body {font-family:"Lucida Grande","Lucida Sans",Verdana,Helvetica,Arial,sans-serif; font-size:80%;}
8 h1 {color:#777; margin-bottom:0.2em;}
9 h2 {color:#aaa; margin-top:1em; font-size:18px;}
10 #generation {color:#777; font-size:90%;}
11 a, a:link, a:visited {color:#169; text-decoration:none;}
12 a:hover, a:active {color:#c61a1a; text-decoration:underline;}
13 pre, code {
14 color: #000000;
15 font-family: "Bitstream Vera Sans Mono","Monaco","Courier New",monospace;
16 font-size: 95%;
17 line-height: 1.3em;
18 margin-top: 0;
19 margin-bottom: 0;
20 padding: 0;
21 }
22 div.source {border:1px solid #e2e2e2;}
23 .covered {background:#bed2be;}
24 .missed {background:#fba;}
25 .never {background:#eee;}
26 </style>
27 </head>
28 <body>
29 <h1>Redmine code coverage</h1>
30 <p id='generation'>
31 Generated on <%= now %> (<%= revision_link %>).
32 More information about this environment at <a href='http://www.redmine.org/projects/redmine/wiki/Continuous_integration'>redmine.org</a>.
33 </p>
34 <h2><%= shortened_filename source_file %> (<%= "%.1f" % source_file.covered_percent %> %)</h2>
35
36 <div class="source">
37 <% source_file.lines.each_with_index do |line, i| %>
38 <pre class="<%= line.status %>" data-hits="<%= line.coverage ? line.coverage : '' %>" data-linenumber="<%= line.number %>"
39 ><code class="ruby"><%= i.to_s.rjust 4 %> <%= CGI.escapeHTML(line.src.chomp) %></code></pre>
40 <% end %>
41 </div>
@@ -87,6 +87,7 end
87 group :test do
87 group :test do
88 gem "minitest"
88 gem "minitest"
89 gem "mocha", "~> 1.0.0", :require => 'mocha/api'
89 gem "mocha", "~> 1.0.0", :require => 'mocha/api'
90 gem "simplecov", "~> 0.9.1", :require => false
90 # For running UI tests
91 # For running UI tests
91 gem "capybara", "~> 2.1.0"
92 gem "capybara", "~> 2.1.0"
92 gem "selenium-webdriver"
93 gem "selenium-webdriver"
@@ -1,13 +1,9
1 ### From http://svn.geekdaily.org/public/rails/plugins/generally_useful/tasks/coverage_via_rcov.rake
2
3 namespace :test do
1 namespace :test do
4 desc 'Measures test coverage'
2 desc 'Measures test coverage'
5 task :coverage do
3 task :coverage do
6 rm_f "coverage"
4 rm_f "coverage"
7 rm_f "coverage.data"
5 ENV["COVERAGE"] = "1"
8 rcov = "rcov --rails --aggregate coverage.data --text-summary -Ilib --html --exclude gems/"
6 Rake::Task["test"].invoke
9 files = %w(unit functional integration).map {|dir| Dir.glob("test/#{dir}/**/*_test.rb")}.flatten.join(" ")
10 system("#{rcov} #{files}")
11 end
7 end
12
8
13 desc 'Run unit and functional scm tests'
9 desc 'Run unit and functional scm tests'
@@ -15,6 +15,13
15 # along with this program; if not, write to the Free Software
15 # along with this program; if not, write to the Free Software
16 # Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
16 # Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
17
17
18 if ENV["COVERAGE"]
19 require 'simplecov'
20 require File.expand_path(File.dirname(__FILE__) + "/coverage/html_formatter")
21 SimpleCov.formatter = Redmine::Coverage::HtmlFormatter
22 SimpleCov.start 'rails'
23 end
24
18 ENV["RAILS_ENV"] = "test"
25 ENV["RAILS_ENV"] = "test"
19 require File.expand_path(File.dirname(__FILE__) + "/../config/environment")
26 require File.expand_path(File.dirname(__FILE__) + "/../config/environment")
20 require 'rails/test_help'
27 require 'rails/test_help'
General Comments 0
You need to be logged in to leave comments. Login now