From 35a1a0ff419ff9bdfe4ddaea0bd975316cc1a491 Mon Sep 17 00:00:00 2001 From: MAEDA Go Date: Sun, 16 Aug 2026 09:23:26 +0900 Subject: [PATCH 1/2] Use SimpleCov's built-in HTML formatter instead of Redmine's own one --- test/coverage/html_formatter.rb | 77 --------------------------------- test/coverage/views/index.erb | 61 -------------------------- test/coverage/views/source.erb | 41 ------------------ test/test_helper.rb | 2 - 4 files changed, 181 deletions(-) delete mode 100644 test/coverage/html_formatter.rb delete mode 100644 test/coverage/views/index.erb delete mode 100644 test/coverage/views/source.erb diff --git a/test/coverage/html_formatter.rb b/test/coverage/html_formatter.rb deleted file mode 100644 index 224f73fb6..000000000 --- a/test/coverage/html_formatter.rb +++ /dev/null @@ -1,77 +0,0 @@ -# frozen_string_literal: true - -# Redmine - project management software -# Copyright (C) 2006- Jean-Philippe Lang -# -# This program is free software; you can redistribute it and/or -# modify it under the terms of the GNU General Public License -# as published by the Free Software Foundation; either version 2 -# of the License, or (at your option) any later version. -# -# This program is distributed in the hope that it will be useful, -# but WITHOUT ANY WARRANTY; without even the implied warranty of -# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the -# GNU General Public License for more details. -# -# You should have received a copy of the GNU General Public License -# along with this program; if not, write to the Free Software -# Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. - -require 'erb' -require 'cgi' - -# A simple formatter for SimpleCov -module Redmine - module Coverage - class HtmlFormatter - def format(result) - File.open(File.join(output_path, "index.html"), "w") do |file| - file.puts template('index').result(binding) - end - result.source_files.each do |source_file| - File.open(File.join(output_path, source_file_result(source_file)), "w") do |file| - file.puts template('source').result(binding).force_encoding('utf-8') - end - end - puts output_message(result) - end - - def output_message(result) - "Coverage report generated for #{result.command_name} to #{output_path}. #{result.covered_lines} / #{result.total_lines} LOC (#{result.covered_percent.round(2)}%) covered." - end - - private - - def now - @now = Time.now.utc - end - - def output_path - SimpleCov.coverage_path - end - - def shortened_filename(source_file) - source_file.filename.gsub(SimpleCov.root, '.').delete_prefix('./') - end - - def link_to_source_file(source_file) - %(#{shortened_filename source_file}) - end - - def source_file_result(source_file) - shortened_filename(source_file).gsub('/', '__')+'.html' - end - - def revision_link - if revision = Redmine::VERSION.revision - %(r#{revision}) - end - end - - # Returns the an erb instance for the template of given name - def template(name) - ERB.new(File.read(File.join(File.dirname(__FILE__), 'views', "#{name}.erb"))) - end - end - end -end diff --git a/test/coverage/views/index.erb b/test/coverage/views/index.erb deleted file mode 100644 index 080e5f8cd..000000000 --- a/test/coverage/views/index.erb +++ /dev/null @@ -1,61 +0,0 @@ - - - -Redmine code coverage - - - -

Redmine code coverage

-

- Generated on <%= now %> (<%= revision_link %>). - More information about this environment at redmine.org. -

- - - - - - - - - - - - - <% result.source_files.each do |source_file| %> - - - - - - - - - <% end %> - -
File% coveredLinesRelevantCovered
<%= link_to_source_file(source_file) %><%= "%.1f" % source_file.covered_percent %> % -
-
-
-
-
<%= source_file.lines.count %><%= source_file.covered_lines.count + source_file.missed_lines.count %><%= source_file.covered_lines.count %>
- - diff --git a/test/coverage/views/source.erb b/test/coverage/views/source.erb deleted file mode 100644 index adef172af..000000000 --- a/test/coverage/views/source.erb +++ /dev/null @@ -1,41 +0,0 @@ - - - -Redmine code coverage - - - -

Redmine code coverage

-

- Generated on <%= now %> (<%= revision_link %>). - More information about this environment at redmine.org. -

-

<%= shortened_filename source_file %> (<%= "%.1f" % source_file.covered_percent %> %)

- -
-<% source_file.lines.each_with_index do |line, i| %> -
<%= i.to_s.rjust 4 %> <%= CGI.escapeHTML(line.src.chomp) %>
-<% end %> -
diff --git a/test/test_helper.rb b/test/test_helper.rb index f84265b33..92969980d 100644 --- a/test/test_helper.rb +++ b/test/test_helper.rb @@ -19,8 +19,6 @@ if ENV["COVERAGE"] require 'simplecov' - require_relative 'coverage/html_formatter' - SimpleCov.formatter = Redmine::Coverage::HtmlFormatter SimpleCov.start 'rails' end -- 2.50.1